Skip to content

Commit

Permalink
Add loading prop
Browse files Browse the repository at this point in the history
  • Loading branch information
josepjaume committed Jul 16, 2024
1 parent 8d05269 commit faebe0f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
7 changes: 7 additions & 0 deletions lib/components/Overlays/Dialog/index.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,10 @@ export const Overflow: Story = {
),
},
}

export const Loading: Story = {
args: {
...WithActions.args,
loading: true,
},
}
15 changes: 13 additions & 2 deletions lib/components/Overlays/Dialog/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
DialogIcon,
DialogTitle,
} from "@/ui/dialog"
import { Skeleton } from "@/ui/skeleton"
import { LucideIcon } from "lucide-react"
import { forwardRef, ReactNode, useCallback, useState } from "react"

Expand All @@ -27,13 +28,14 @@ type DialogProps = {
primary: Action
secondary?: Action
}
loading?: boolean
children: ReactNode
open?: boolean
onClose?: () => void
}

const OneDialog = forwardRef<HTMLDivElement, DialogProps>(
({ header, children, actions, open, onClose }, ref) => {
({ header, children, loading, actions, open, onClose }, ref) => {
// We do this in order to give the illusion of a controlled state via `open`, but in reality
// we're taking control and closing the dialog after a few milliseconds to give the closing
// animation time to play out.
Expand Down Expand Up @@ -67,7 +69,16 @@ const OneDialog = forwardRef<HTMLDivElement, DialogProps>(
<DialogDescription>{header.description}</DialogDescription>
</DialogHeader>
)}
<Stack grow>{children}</Stack>
<Stack grow>
{loading ? (
<Stack gap="4">
<Skeleton className="h-6 w-full rounded-full" />
<Skeleton className="h-6 w-full rounded-full" />
</Stack>
) : (
children
)}
</Stack>
{actions && (
<DialogFooter>
{actions.secondary && (
Expand Down

0 comments on commit faebe0f

Please sign in to comment.