summaryrefslogtreecommitdiffhomepage
path: root/packages/ui/src/components/toast.stories.tsx
blob: ef9cbb68ef283f6e6e4c58fcc8b6a0200ba2920b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
// @ts-nocheck
import * as mod from "./toast"
import { Button } from "./button"

const docs = `### Overview
Toast notifications with optional icons, actions, and progress.

Use brief titles/descriptions; limit actions to 1-2.

### API
- Use \`showToast\` or \`showPromiseToast\` to trigger toasts.
- Render \`Toast.Region\` once per page.
- \`Toast\` subcomponents compose the structure.

### Variants and states
- Variants: default, success, error, loading.
- Optional actions and persistent toasts.

### Behavior
- Toasts render in a portal and auto-dismiss unless persistent.

### Accessibility
- TODO: confirm aria-live behavior from Kobalte Toast.

### Theming/tokens
- Uses \`data-component="toast"\` and slot data attributes.

`

export default {
  title: "UI/Toast",
  id: "components-toast",
  component: mod.Toast,
  tags: ["autodocs"],
  parameters: {
    docs: {
      description: {
        component: docs,
      },
    },
  },
}

export const Basic = {
  render: () => (
    <div style={{ display: "grid", gap: "12px" }}>
      <mod.Toast.Region />
      <Button
        variant="primary"
        onClick={() =>
          mod.showToast({
            title: "Saved",
            description: "Your changes are stored.",
            variant: "success",
            icon: "check",
          })
        }
      >
        Show success toast
      </Button>
      <Button
        variant="secondary"
        onClick={() =>
          mod.showToast({
            description: "This action needs attention.",
            variant: "error",
            icon: "warning",
          })
        }
      >
        Show error toast
      </Button>
    </div>
  ),
}

export const Actions = {
  render: () => (
    <div style={{ display: "grid", gap: "12px" }}>
      <mod.Toast.Region />
      <Button
        variant="secondary"
        onClick={() =>
          mod.showToast({
            title: "Update available",
            description: "Restart to apply the update.",
            actions: [
              { label: "Restart", onClick: "dismiss" },
              { label: "Later", onClick: "dismiss" },
            ],
          })
        }
      >
        Show action toast
      </Button>
    </div>
  ),
}

export const Promise = {
  render: () => (
    <div style={{ display: "grid", gap: "12px" }}>
      <mod.Toast.Region />
      <Button
        variant="secondary"
        onClick={() =>
          mod.showPromiseToast(() => new Promise((resolve) => setTimeout(() => resolve(true), 800)), {
            loading: "Saving...",
            success: () => "Saved",
            error: () => "Failed",
          })
        }
      >
        Show promise toast
      </Button>
    </div>
  ),
}

export const Loading = {
  render: () => (
    <div style={{ display: "grid", gap: "12px" }}>
      <mod.Toast.Region />
      <Button
        variant="secondary"
        onClick={() =>
          mod.showToast({
            description: "Syncing...",
            variant: "loading",
            persistent: true,
          })
        }
      >
        Show loading toast
      </Button>
    </div>
  ),
}