1 import type { Meta, StoryObj } from "@storybook/react"
2 import * as React from "react"
3
4 import { Button } from "@/components/button"
5 import { Badge } from "../../components/badge"
6 import { Text } from "../../components/text"
7 import { usePrompt } from "./use-prompt"
8
9 type DemoProps = {
10 verificationText?: string
11 }
12
13 const Demo = ({ verificationText }: DemoProps) => {
14 const [status, setStatus] = React.useState(false)
15 const dialog = usePrompt()
16
17 const handleDangerousAction = async () => {
18 const confirmed = await dialog({
19 title: "Delete Product",
20 description:
21 "Are you sure you want to delete this product? This action cannot be undone.",
22 verificationText,
23 variant: "danger",
24 })
25
26 setStatus(confirmed)
27 }
28
29 return (
30 <div className="flex flex-col items-center gap-y-2">
31 <Button variant="danger" onClick={handleDangerousAction}>
32 Delete Product
33 </Button>
34 <Text>
35 Status: <Badge>{status ? "Confirmed" : "Unconfirmed"}</Badge>
36 </Text>
37 </div>
38 )
39 }
40
41 const meta: Meta<typeof usePrompt> = {
42 title: "Hooks/usePrompt",
43 component: Demo,
44 parameters: {
45 layout: "centered",
46 },
47 }
48
49 export default meta
50
51 type Story = StoryObj<typeof Demo>
52
53 export const Default: Story = {}
54
55 export const WithVerificationText: Story = {
56 args: {
57 verificationText: "product",
58 },
59 }