Skip to content

Commit f0ad8c0

Browse files
committed
docs(portal): add examples
1 parent d73570d commit f0ad8c0

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<script>
2+
import { Portal } from "carbon-components-svelte";
3+
import Preview from "../../components/Preview.svelte";
4+
</script>
5+
6+
The `Portal` component renders its content into a fixed container appended to `document.body`, allowing you to escape parent overflow constraints and z-index stacking contexts.
7+
8+
## Default Portal
9+
10+
Render content in a portal container. This is useful for modals, tooltips, and menus that need to escape parent containers.
11+
12+
<FileSource src="/framed/Portal/BasicPortal" />
13+
14+
## Multiple Portals
15+
16+
Multiple portal instances share the same container, which is automatically cleaned up when all instances are removed.
17+
18+
<FileSource src="/framed/Portal/MultiplePortals" />
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<script>
2+
import { Portal } from "carbon-components-svelte";
3+
</script>
4+
5+
<Portal>Hello world</Portal>
6+
<Portal>Another portal</Portal>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<script>
2+
import { Button, Portal } from "carbon-components-svelte";
3+
</script>
4+
5+
<Button>Button 1</Button>
6+
<Portal>
7+
<div style="position: absolute; top: 100px; left: 20px; padding: 1rem; background: var(--cds-layer-01); border: 1px solid var(--cds-border-subtle-01);">
8+
Portal content 1
9+
</div>
10+
</Portal>
11+
12+
<Button>Button 2</Button>
13+
<Portal>
14+
<div style="position: absolute; top: 150px; left: 20px; padding: 1rem; background: var(--cds-layer-01); border: 1px solid var(--cds-border-subtle-01);">
15+
Portal content 2
16+
</div>
17+
</Portal>
18+

0 commit comments

Comments
 (0)