Skip to content

Commit 41e4db7

Browse files
author
Luka Jeran
authored
Merge pull request #59 from oasisprotocol/lw/scroll-dialog
Make long dialogs scrollable in landscape
2 parents 318edb9 + a648c26 commit 41e4db7

2 files changed

Lines changed: 45 additions & 16 deletions

File tree

src/components/ui/dialog.tsx

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function DialogOverlay({ className, ...props }: React.ComponentProps<typeof Dial
2525
<DialogPrimitive.Overlay
2626
data-slot="dialog-overlay"
2727
className={cn(
28-
'data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50',
28+
'data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50 grid place-items-center overflow-y-auto p-4',
2929
className
3030
)}
3131
{...props}
@@ -40,21 +40,22 @@ function DialogContent({
4040
}: React.ComponentProps<typeof DialogPrimitive.Content>) {
4141
return (
4242
<DialogPortal data-slot="dialog-portal">
43-
<DialogOverlay />
44-
<DialogPrimitive.Content
45-
data-slot="dialog-content"
46-
className={cn(
47-
'bg-background data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border p-6 shadow-lg duration-200 sm:max-w-lg',
48-
className
49-
)}
50-
{...props}
51-
>
52-
{children}
53-
<DialogPrimitive.Close className="ring-offset-background focus:ring-ring data-[state=open]:bg-accent data-[state=open]:text-muted-foreground absolute top-4 right-4 rounded-xs opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4">
54-
<XIcon />
55-
<span className="sr-only">Close</span>
56-
</DialogPrimitive.Close>
57-
</DialogPrimitive.Content>
43+
<DialogOverlay>
44+
<DialogPrimitive.Content
45+
data-slot="dialog-content"
46+
className={cn(
47+
'bg-background data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 relative z-50 grid w-full max-w-[calc(100%-2rem)] gap-4 rounded-lg border p-6 shadow-lg duration-200 sm:max-w-lg',
48+
className
49+
)}
50+
{...props}
51+
>
52+
{children}
53+
<DialogPrimitive.Close className="ring-offset-background focus:ring-ring data-[state=open]:bg-accent data-[state=open]:text-muted-foreground absolute top-4 right-4 rounded-xs opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4">
54+
<XIcon />
55+
<span className="sr-only">Close</span>
56+
</DialogPrimitive.Close>
57+
</DialogPrimitive.Content>
58+
</DialogOverlay>
5859
</DialogPortal>
5960
)
6061
}

src/stories/Dialog/Dialog.stories.tsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,34 @@ export const AlertDialog: Story = {
122122
},
123123
}
124124

125+
export const LongDialog: Story = {
126+
render: function LongDialogExample() {
127+
return (
128+
<Dialog>
129+
<DialogTrigger>
130+
<Button variant="outline">Open Long Dialog</Button>
131+
</DialogTrigger>
132+
<DialogContent className="sm:max-w-[425px]">
133+
<DialogHeader>
134+
<DialogTitle>Sample Dialog</DialogTitle>
135+
<DialogDescription>
136+
{Array.from({length: 100}).map((_v, i) =>
137+
<p key={i}>Sample description text goes here.</p>
138+
)}
139+
</DialogDescription>
140+
</DialogHeader>
141+
<DialogFooter>
142+
<DialogClose>
143+
<Button variant="outline">Close</Button>
144+
</DialogClose>
145+
<Button type="submit">Ok</Button>
146+
</DialogFooter>
147+
</DialogContent>
148+
</Dialog>
149+
)
150+
},
151+
}
152+
125153
export const ImagePreview: Story = {
126154
render: function ImagePreviewDialogExample() {
127155
const [open, setOpen] = useState(false)

0 commit comments

Comments
 (0)