11import * as React from 'react' ;
2- import { Portal , UnstablePortal } from '@radix-ui/react-portal' ;
2+ import { Portal } from '@radix-ui/react-portal' ;
33
44export default { title : 'Components/Portal' } ;
55
@@ -19,7 +19,7 @@ export const Base = () => (
1919 necessitatibus eius pariatur.
2020 </ p >
2121
22- < Portal style = { { position : 'relative' } } >
22+ < Portal >
2323 < h1 > This content is rendered in a portal (another DOM tree)</ h1 >
2424 < p >
2525 Because of the portal, it can appear in a different DOM tree from the main one (by default a
@@ -30,13 +30,13 @@ export const Base = () => (
3030) ;
3131
3232export const CustomContainer = ( ) => {
33- const portalContainerRef = React . useRef < HTMLDivElement > ( null ) ;
33+ const [ portalContainer , setPortalContainer ] = React . useState < HTMLDivElement | null > ( null ) ;
3434
3535 return (
3636 < >
3737 < div style = { { maxWidth : 300 , padding : 10 , margin : 10 , border : '1px solid' } } >
3838 < h1 > Container A</ h1 >
39- < Portal containerRef = { portalContainerRef } >
39+ < Portal asChild container = { portalContainer } >
4040 < p >
4141 This content is rendered in a portal inside Container A but appears inside Container B
4242 because we have used Container B as a container element for the Portal.
@@ -45,7 +45,7 @@ export const CustomContainer = () => {
4545 </ div >
4646
4747 < div
48- ref = { portalContainerRef }
48+ ref = { setPortalContainer }
4949 style = { { maxWidth : 300 , padding : 10 , margin : 10 , border : '1px solid' } }
5050 >
5151 < h1 > Container B</ h1 >
@@ -55,63 +55,6 @@ export const CustomContainer = () => {
5555} ;
5656
5757export const Chromatic = ( ) => {
58- const portalContainerRef = React . useRef < HTMLDivElement > ( null ) ;
59-
60- return (
61- < div style = { { padding : 150 } } >
62- < h1 > Default (append to body)</ h1 >
63- < div style = { { padding : 10 , margin : 10 , border : '1px solid blue' } } >
64- < p > Container A</ p >
65-
66- < Portal >
67- < div style = { { padding : 10 , margin : 10 , border : '1px solid blue' } } >
68- < p > This content is rendered in a portal (another DOM tree)</ p >
69- < p >
70- Because of the portal, it can appear in a different DOM tree from the main one (by
71- default a new element inside the body), even though it is part of the same React tree.
72- </ p >
73- </ div >
74- </ Portal >
75- </ div >
76-
77- < h1 > Custom container</ h1 >
78- < div style = { { padding : 10 , margin : 10 , border : '1px solid green' } } >
79- < p > Container B</ p >
80- < Portal containerRef = { portalContainerRef } >
81- < div style = { { padding : 10 , margin : 10 , border : '1px solid green' } } >
82- < p >
83- This content is rendered in a portal inside Container B but appears inside Container C
84- because we have used Container C as a container element for the Portal.
85- </ p >
86- </ div >
87- </ Portal >
88- </ div >
89-
90- < div ref = { portalContainerRef } style = { { padding : 10 , margin : 10 , border : '1px solid' } } >
91- < p > Container C</ p >
92- </ div >
93-
94- < h1 > zIndex and order</ h1 >
95- < p > See squares in the top-left</ p >
96- < Portal >
97- < div style = { { width : 20 , height : 20 , backgroundColor : 'red' } } />
98- </ Portal >
99- < Portal >
100- < div
101- style = { { width : 20 , height : 20 , backgroundColor : 'green' , marginLeft : 10 , marginTop : 10 } }
102- />
103- </ Portal >
104- < Portal >
105- < div
106- style = { { width : 20 , height : 20 , backgroundColor : 'blue' , marginLeft : 20 , marginTop : 20 } }
107- />
108- </ Portal >
109- </ div >
110- ) ;
111- } ;
112- Chromatic . parameters = { chromatic : { disable : false } } ;
113-
114- export const ChromaticUnstablePortal = ( ) => {
11558 const [ portalContainer , setPortalContainer ] = React . useState < HTMLDivElement | null > ( null ) ;
11659
11760 return (
@@ -120,7 +63,7 @@ export const ChromaticUnstablePortal = () => {
12063 < div style = { { padding : 10 , margin : 10 , border : '1px solid blue' } } >
12164 < p > Container A</ p >
12265
123- < UnstablePortal >
66+ < Portal asChild >
12467 < div
12568 style = { {
12669 padding : 10 ,
@@ -138,20 +81,20 @@ export const ChromaticUnstablePortal = () => {
13881 default a new element inside the body), even though it is part of the same React tree.
13982 </ p >
14083 </ div >
141- </ UnstablePortal >
84+ </ Portal >
14285 </ div >
14386
14487 < h1 > Custom container</ h1 >
14588 < div style = { { padding : 10 , margin : 10 , border : '1px solid green' } } >
14689 < p > Container B</ p >
147- < UnstablePortal container = { portalContainer } >
90+ < Portal asChild container = { portalContainer } >
14891 < div style = { { padding : 10 , margin : 10 , border : '1px solid green' } } >
14992 < p >
15093 This content is rendered in a portal inside Container B but appears inside Container C
15194 because we have used Container C as a container element for the Portal.
15295 </ p >
15396 </ div >
154- </ UnstablePortal >
97+ </ Portal >
15598 </ div >
15699
157100 < div ref = { setPortalContainer } style = { { padding : 10 , margin : 10 , border : '1px solid' } } >
@@ -160,7 +103,7 @@ export const ChromaticUnstablePortal = () => {
160103
161104 < h1 > zIndex and order</ h1 >
162105 < p > See squares in the top-left</ p >
163- < UnstablePortal >
106+ < Portal asChild >
164107 < div
165108 style = { {
166109 width : 20 ,
@@ -172,8 +115,8 @@ export const ChromaticUnstablePortal = () => {
172115 zIndex : 9999999 ,
173116 } }
174117 />
175- </ UnstablePortal >
176- < UnstablePortal >
118+ </ Portal >
119+ < Portal asChild >
177120 < div
178121 style = { {
179122 width : 20 ,
@@ -187,8 +130,8 @@ export const ChromaticUnstablePortal = () => {
187130 zIndex : 9999999 ,
188131 } }
189132 />
190- </ UnstablePortal >
191- < UnstablePortal >
133+ </ Portal >
134+ < Portal asChild >
192135 < div
193136 style = { {
194137 width : 20 ,
@@ -202,8 +145,8 @@ export const ChromaticUnstablePortal = () => {
202145 zIndex : 9999999 ,
203146 } }
204147 />
205- </ UnstablePortal >
148+ </ Portal >
206149 </ div >
207150 ) ;
208151} ;
209- ChromaticUnstablePortal . parameters = { chromatic : { disable : false } } ;
152+ Chromatic . parameters = { chromatic : { disable : false } } ;
0 commit comments