Skip to content

Commit fe88af7

Browse files
committed
docs: dialog example
1 parent 12133ab commit fe88af7

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { Button, CloseButton, Dialog, Portal } from "@chakra-ui/react"
2+
3+
export const DialogWithResponsiveSize = () => {
4+
return (
5+
<Dialog.Root size={{ mdDown: "full", md: "lg" }}>
6+
<Dialog.Trigger asChild>
7+
<Button variant="outline" size="sm">
8+
Open Dialog
9+
</Button>
10+
</Dialog.Trigger>
11+
<Portal>
12+
<Dialog.Backdrop />
13+
<Dialog.Positioner>
14+
<Dialog.Content>
15+
<Dialog.Header>
16+
<Dialog.Title>Dialog Title</Dialog.Title>
17+
</Dialog.Header>
18+
<Dialog.Body>
19+
<p>
20+
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do
21+
eiusmod tempor incididunt ut labore et dolore magna aliqua.
22+
</p>
23+
</Dialog.Body>
24+
<Dialog.Footer>
25+
<Dialog.ActionTrigger asChild>
26+
<Button variant="outline">Cancel</Button>
27+
</Dialog.ActionTrigger>
28+
<Button>Save</Button>
29+
</Dialog.Footer>
30+
<Dialog.CloseTrigger asChild>
31+
<CloseButton size="sm" />
32+
</Dialog.CloseTrigger>
33+
</Dialog.Content>
34+
</Dialog.Positioner>
35+
</Portal>
36+
</Dialog.Root>
37+
)
38+
}

apps/www/content/docs/components/dialog.mdx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,24 @@ screen.
5555

5656
<ExampleTabs name="dialog-with-fullscreen" />
5757

58+
### Responsive Size
59+
60+
Use responsive values for the `size` prop to make the dialog adapt to different
61+
screen sizes.
62+
63+
We recommend using exact breakpoints values instead of using a `base` to ensure
64+
styles are properly contained.
65+
66+
```tsx
67+
// ❌ Might cause a style leak between the breakpoints
68+
<Dialog.Root size={{ base: "full", md: "lg" }}>{/* ... */}</Dialog.Root>
69+
70+
// Works ✅
71+
<Dialog.Root size={{ mdDown: "full", md: "lg" }}>{/* ... */}</Dialog.Root>
72+
```
73+
74+
<ExampleTabs name="dialog-with-responsive-size" />
75+
5876
### Placement
5977

6078
Use the `placement` prop to change the placement of the dialog component.

packages/react/__stories__/dialog.stories.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export { DialogWithInitialFocus as InitialFocus } from "compositions/examples/di
2626
export { DialogWithInsideScroll as InsideScroll } from "compositions/examples/dialog-with-inside-scroll"
2727
export { DialogWithOutsideScroll as OutsideScroll } from "compositions/examples/dialog-with-outside-scroll"
2828
export { DialogWithPlacement as Placement } from "compositions/examples/dialog-with-placement"
29+
export { DialogWithResponsiveSize as ResponsiveSize } from "compositions/examples/dialog-with-responsive-size"
2930
export { DialogWithRole as Role } from "compositions/examples/dialog-with-role"
3031
export { DialogWithSizes as Sizes } from "compositions/examples/dialog-with-sizes"
3132
export { DialogWithStore as Store } from "compositions/examples/dialog-with-store"

0 commit comments

Comments
 (0)