33
44import * as React from 'react' ;
55import * as ReactDOM from 'react-dom' ;
6- import { Omit } from '../declarations/omit' ;
76import * as dom from '../utils/dom' ;
87
98const DEBUG = false ;
@@ -12,14 +11,7 @@ export const CHILDREN_TO_APPEND_PROP = 'children-to-append';
1211/**
1312 * Props that can be passed to `ReactContent` from users.
1413 */
15- export type ReactContentProps = Omit < AllReactContentProps , typeof CHILDREN_TO_APPEND_PROP > ;
16-
17- /**
18- * @internal
19- */
20- export interface AllReactContentProps {
21- readonly [ CHILDREN_TO_APPEND_PROP ] : HTMLElement [ ] ;
22-
14+ export interface ReactContentProps {
2315 /**
2416 * Experimental rendering mode.
2517 * Uses a similar approach to `router-outlet`, where the child elements are added to the parent, instead of this node, and this is hidden.
@@ -28,14 +20,34 @@ export interface AllReactContentProps {
2820 legacyRenderMode ?: boolean ;
2921}
3022
23+ /**
24+ * Creates a new `ReactContent` element.
25+ * @param children The children to append to the `ReactContent` element.
26+ * @param additionalProps _Optional_. @see `ReactContentProps`
27+ * @returns
28+ */
29+ export function createReactContentElement ( children : ReadonlyArray < HTMLElement > , additionalProps ?: ReactContentProps ) {
30+ return React . createElement ( ReactContent , {
31+ ...additionalProps ,
32+ [ CHILDREN_TO_APPEND_PROP ] : children ,
33+ } ) ;
34+ }
35+
36+ /**
37+ * @internal
38+ */
39+ export interface InternalReactContentProps extends ReactContentProps {
40+ readonly [ CHILDREN_TO_APPEND_PROP ] : ReadonlyArray < HTMLElement > ;
41+ }
42+
3143/**
3244 * Render any `HTMLElement`s (including Angular components) as a child of React components.
3345 * Supports two rendering modes:
3446 * 1. `legacy` - append `<react-content>` as the root, and nest the `children-to-append` underneath it.
3547 * 2. `new` (**default**) - append the `children-to-append` to the parent of this component, and hide the `<react-content>` element.
3648 * (similar to how `router-outlet` behaves in Angular).
3749 */
38- export class ReactContent extends React . PureComponent < AllReactContentProps > {
50+ export class ReactContent extends React . PureComponent < InternalReactContentProps > {
3951 componentDidMount ( ) {
4052 const element = ReactDOM . findDOMNode ( this ) ;
4153 if ( this . props [ CHILDREN_TO_APPEND_PROP ] ) {
0 commit comments