@@ -34,7 +34,8 @@ interface InPortalProps {
3434 children : React . ReactNode ;
3535}
3636
37- export const createPortalNode = < C extends Component < any > > ( elementType : PortalNodeElementType ) : PortalNode < C > => {
37+ // This is the internal implementation: the public entry points set elementType to an appropriate value
38+ const createPortalNode = < C extends Component < any > > ( elementType : PortalNodeElementType ) : PortalNode < C > => {
3839 let initialProps = { } as ComponentProps < C > ;
3940
4041 let parent : Node | undefined ;
@@ -70,7 +71,6 @@ export const createPortalNode = <C extends Component<any>>(elementType: PortalNo
7071 // To support SVG and other non-html elements, the portalNode's elementType needs to match
7172 // the elementType it's being rendered into
7273 if ( newParent !== parent ) {
73- console . log ( 'newParent: ' , newParent )
7474 if ( ( isHtmlPortal && ! ( newParent instanceof HTMLElement ) ) ||
7575 ( isSvgPortal && ! ( newParent instanceof SVGElement ) ) ) {
7676 throw new Error ( `Invalid element type for portal: "${ elementType } " portalNodes must be used with ${ elementType } elements.` )
@@ -107,7 +107,7 @@ export const createPortalNode = <C extends Component<any>>(elementType: PortalNo
107107 return portalNode ;
108108} ;
109109
110- export class InPortal extends React . PureComponent < InPortalProps , { nodeProps : { } } > {
110+ class InPortal extends React . PureComponent < InPortalProps , { nodeProps : { } } > {
111111
112112 constructor ( props : InPortalProps ) {
113113 super ( props ) ;
@@ -150,7 +150,7 @@ type OutPortalProps<C extends Component<any>> = {
150150 node : PortalNode < C >
151151} & Partial < ComponentProps < C > > ;
152152
153- export class OutPortal < C extends Component < any > > extends React . PureComponent < OutPortalProps < C > > {
153+ class OutPortal < C extends Component < any > > extends React . PureComponent < OutPortalProps < C > > {
154154
155155 private placeholderNode = React . createRef < HTMLDivElement > ( ) ;
156156 private currentPortalNode ?: PortalNode < C > ;
@@ -203,5 +203,27 @@ export class OutPortal<C extends Component<any>> extends React.PureComponent<Out
203203 // A <div> placeholder works fine even for SVG.
204204 return < div ref = { this . placeholderNode } /> ;
205205 }
206+ }
207+
208+ const createHtmlPortalNode = createPortalNode . bind ( null , 'html' ) ;
209+ const createSvgPortalNode = createPortalNode . bind ( null , 'svg' )
210+
211+ // Option A: Export a self-contained namespace for each type, including Portal components
212+ export const html = {
213+ createPortalNode : createHtmlPortalNode ,
214+ InPortal,
215+ OutPortal,
216+ } ;
217+ export const svg = {
218+ createPortalNode : createSvgPortalNode ,
219+ InPortal,
220+ OutPortal,
221+ } ;
206222
223+ // Option B: Export a createPortalNode for each type, with shared Portal components
224+ export {
225+ createHtmlPortalNode ,
226+ createSvgPortalNode ,
227+ InPortal ,
228+ OutPortal ,
207229}
0 commit comments