Skip to content

Commit 7697547

Browse files
authored
docs: add responsive modal example (#1608)
1 parent 2405e90 commit 7697547

File tree

4 files changed

+108
-0
lines changed

4 files changed

+108
-0
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<script setup lang="ts">
2+
import { useMediaQuery } from '@vueuse/core'
3+
import { Button } from '@/registry/new-york-v4/ui/button'
4+
import {
5+
Dialog,
6+
DialogClose,
7+
DialogContent,
8+
DialogDescription,
9+
DialogFooter,
10+
DialogHeader,
11+
DialogTitle,
12+
DialogTrigger,
13+
} from '@/registry/new-york-v4/ui/dialog'
14+
import {
15+
Drawer,
16+
DrawerClose,
17+
DrawerContent,
18+
DrawerDescription,
19+
DrawerFooter,
20+
DrawerHeader,
21+
DrawerTitle,
22+
DrawerTrigger,
23+
} from '@/registry/new-york-v4/ui/drawer'
24+
import { Input } from '@/registry/new-york-v4/ui/input'
25+
import { Label } from '@/registry/new-york-v4/ui/label'
26+
27+
const isDesktop = useMediaQuery('(min-width: 640px)')
28+
29+
const Modal = computed(() => ({
30+
Root: isDesktop.value ? Dialog : Drawer,
31+
Trigger: isDesktop.value ? DialogTrigger : DrawerTrigger,
32+
Content: isDesktop.value ? DialogContent : DrawerContent,
33+
Header: isDesktop.value ? DialogHeader : DrawerHeader,
34+
Title: isDesktop.value ? DialogTitle : DrawerTitle,
35+
Description: isDesktop.value ? DialogDescription : DrawerDescription,
36+
Footer: isDesktop.value ? DialogFooter : DrawerFooter,
37+
Close: isDesktop.value ? DialogClose : DrawerClose,
38+
}))
39+
</script>
40+
41+
<template>
42+
<component :is="Modal.Root">
43+
<component :is="Modal.Trigger" as-child>
44+
<Button variant="outline">
45+
Open Dialog
46+
</Button>
47+
</component>
48+
<component
49+
:is="Modal.Content"
50+
class="sm:max-w-md" :class="[
51+
{ 'px-2 pb-8 *:px-4': !isDesktop },
52+
]"
53+
>
54+
<component :is="Modal.Header">
55+
<component :is="Modal.Title">
56+
Share Link
57+
</component>
58+
<component :is="Modal.Description">
59+
Anyone who has this link will be able to view this.
60+
</component>
61+
</component>
62+
63+
<div class="flex items-center gap-2">
64+
<div class="grid flex-1 gap-2">
65+
<Label for="link" class="sr-only">
66+
Link
67+
</Label>
68+
<Input
69+
id="link"
70+
default-value="https://www.shadcn-vue.com/docs/installation"
71+
read-only
72+
/>
73+
</div>
74+
</div>
75+
76+
<component :is="Modal.Footer" class="pt-4">
77+
<component :is="Modal.Close" as-child>
78+
<Button variant="outline">
79+
Close
80+
</Button>
81+
</component>
82+
</component>
83+
</component>
84+
</component>
85+
</template>

apps/v4/components/demo/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export { default as CollapsibleDemo } from './CollapsibleDemo.vue'
4444
export { default as ComboboxDemo } from './ComboboxDemo.vue'
4545
// Dialog demos
4646
export { default as DialogDemo } from './DialogDemo.vue'
47+
export { default as DialogResponsive } from './DialogResponsive.vue'
4748

4849
// Hover Card demos
4950
export { default as HoverCardDemo } from './HoverCardDemo.vue'

apps/v4/content/docs/components/dialog.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,16 @@ name: DialogForm
111111
---
112112
::
113113

114+
### Responsive Modal (Dialog & Drawer)
115+
116+
Use a `Drawer` component for smaller viewport sizes and a `Dialog` component otherwise. This can be further made reusable by using slots for various parts of the modal.
117+
118+
::component-preview
119+
---
120+
name: DialogResponsive
121+
---
122+
::
123+
114124
## Notes
115125

116126
To use the `Dialog` component from within a `Context Menu` or `Dropdown Menu`, you must encase the `Context Menu` or

apps/v4/content/docs/components/drawer.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,15 @@ import {
9898
</Drawer>
9999
</template>
100100
```
101+
102+
## Example
103+
104+
### Responsive Modal (Dialog & Drawer)
105+
106+
Use a `Drawer` component for smaller viewport sizes and a `Dialog` component otherwise. This can be further made reusable by using slots for various parts of the modal.
107+
108+
::component-preview
109+
---
110+
name: DialogResponsive
111+
---
112+
::

0 commit comments

Comments
 (0)