@duro-app/ui 0.17.1 → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/ActionBar/ActionBar.d.ts +1 -1
- package/dist/components/ActionBar/ActionBar.d.ts.map +1 -1
- package/dist/components/ActionBar/ActionBarProvider.d.ts +12 -0
- package/dist/components/ActionBar/ActionBarProvider.d.ts.map +1 -0
- package/dist/components/Checkbox/Checkbox.meta.d.ts.map +1 -1
- package/dist/components/Cluster/Cluster.meta.d.ts.map +1 -1
- package/dist/components/Dialog/Dialog.d.ts +58 -0
- package/dist/components/Dialog/Dialog.d.ts.map +1 -0
- package/dist/components/Dialog/Dialog.stories.d.ts +13 -0
- package/dist/components/Dialog/Dialog.stories.d.ts.map +1 -0
- package/dist/components/Dialog/styles.css.d.ts +140 -0
- package/dist/components/Dialog/styles.css.d.ts.map +1 -0
- package/dist/components/Drawer/Drawer.d.ts +62 -0
- package/dist/components/Drawer/Drawer.d.ts.map +1 -0
- package/dist/components/Drawer/Drawer.stories.d.ts +15 -0
- package/dist/components/Drawer/Drawer.stories.d.ts.map +1 -0
- package/dist/components/Drawer/styles.css.d.ts +184 -0
- package/dist/components/Drawer/styles.css.d.ts.map +1 -0
- package/dist/components/Drawer/useSwipeDismiss.d.ts +17 -0
- package/dist/components/Drawer/useSwipeDismiss.d.ts.map +1 -0
- package/dist/components/Field/Field.meta.d.ts.map +1 -1
- package/dist/components/Fieldset/Fieldset.meta.d.ts.map +1 -1
- package/dist/components/Form/Form.meta.d.ts.map +1 -1
- package/dist/components/Grid/Grid.meta.d.ts.map +1 -1
- package/dist/components/Inline/Inline.meta.d.ts.map +1 -1
- package/dist/components/Input/Input.meta.d.ts.map +1 -1
- package/dist/components/LinkButton/LinkButton.meta.d.ts.map +1 -1
- package/dist/components/Menu/Menu.meta.d.ts.map +1 -1
- package/dist/components/SideNav/SideNav.meta.d.ts.map +1 -1
- package/dist/components/Stack/Stack.meta.d.ts.map +1 -1
- package/dist/components/Switch/Switch.meta.d.ts.map +1 -1
- package/dist/components/Table/Table.d.ts.map +1 -1
- package/dist/components/Table/Table.stories.d.ts +1 -0
- package/dist/components/Table/Table.stories.d.ts.map +1 -1
- package/dist/components/Textarea/Textarea.meta.d.ts.map +1 -1
- package/dist/components/ThemeProvider/ThemeProvider.d.ts +0 -2
- package/dist/components/ThemeProvider/ThemeProvider.d.ts.map +1 -1
- package/dist/index.css +1 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2869 -1904
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/components/ActionBar/ActionBar.tsx +28 -12
- package/src/components/ActionBar/ActionBarProvider.tsx +100 -0
- package/src/components/Checkbox/Checkbox.meta.ts +4 -1
- package/src/components/Cluster/Cluster.meta.ts +2 -6
- package/src/components/Dialog/Dialog.stories.tsx +325 -0
- package/src/components/Dialog/Dialog.tsx +310 -0
- package/src/components/Dialog/styles.css.ts +197 -0
- package/src/components/Drawer/Drawer.stories.tsx +364 -0
- package/src/components/Drawer/Drawer.tsx +370 -0
- package/src/components/Drawer/styles.css.ts +242 -0
- package/src/components/Drawer/useSwipeDismiss.ts +295 -0
- package/src/components/Field/Field.meta.ts +1 -3
- package/src/components/Fieldset/Fieldset.meta.ts +1 -3
- package/src/components/Form/Form.meta.ts +1 -4
- package/src/components/Grid/Grid.meta.ts +1 -3
- package/src/components/Inline/Inline.meta.ts +1 -2
- package/src/components/Input/Input.meta.ts +2 -7
- package/src/components/LinkButton/LinkButton.meta.ts +1 -3
- package/src/components/Menu/Menu.meta.ts +1 -4
- package/src/components/SideNav/SideNav.meta.ts +1 -4
- package/src/components/Stack/Stack.meta.ts +1 -2
- package/src/components/Switch/Switch.meta.ts +4 -1
- package/src/components/Table/Table.stories.tsx +107 -0
- package/src/components/Table/Table.tsx +0 -1
- package/src/components/Textarea/Textarea.meta.ts +2 -6
- package/src/components/ThemeProvider/ThemeProvider.tsx +2 -19
- package/src/index.ts +4 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@duro-app/ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
}
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@duro-app/tokens": "^0.
|
|
55
|
+
"@duro-app/tokens": "^0.19.0"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"@babel/preset-typescript": "^7.28.0",
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import {createPortal} from 'react-dom'
|
|
1
|
+
import {useEffect, useCallback, type ReactNode} from 'react'
|
|
3
2
|
import {html} from 'react-strict-dom'
|
|
4
|
-
import {
|
|
3
|
+
import {useActionBarStack} from './ActionBarProvider'
|
|
5
4
|
import {styles} from './styles.css'
|
|
6
5
|
|
|
7
6
|
export interface ActionBarProps {
|
|
@@ -19,7 +18,7 @@ export interface ActionBarProps {
|
|
|
19
18
|
children: ReactNode
|
|
20
19
|
}
|
|
21
20
|
|
|
22
|
-
function
|
|
21
|
+
function ActionBarContent({
|
|
23
22
|
selectedItemCount,
|
|
24
23
|
selectedLabel,
|
|
25
24
|
isEmphasized = false,
|
|
@@ -27,14 +26,10 @@ function ActionBarInner({
|
|
|
27
26
|
dismissible = true,
|
|
28
27
|
children,
|
|
29
28
|
}: ActionBarProps) {
|
|
30
|
-
const container = useOverlayContainer()
|
|
31
|
-
|
|
32
|
-
if (selectedItemCount === 0) return null
|
|
33
|
-
|
|
34
29
|
const countStr = selectedItemCount === 'all' ? 'All' : `${selectedItemCount}`
|
|
35
30
|
const label = selectedLabel ? selectedLabel(countStr) : `${countStr} selected`
|
|
36
31
|
|
|
37
|
-
|
|
32
|
+
return (
|
|
38
33
|
<html.div
|
|
39
34
|
role="toolbar"
|
|
40
35
|
aria-label={label}
|
|
@@ -64,12 +59,33 @@ function ActionBarInner({
|
|
|
64
59
|
)}
|
|
65
60
|
</html.div>
|
|
66
61
|
)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function ActionBarInner(props: ActionBarProps) {
|
|
65
|
+
const {selectedItemCount} = props
|
|
66
|
+
const stack = useActionBarStack()
|
|
67
|
+
const isActive = selectedItemCount !== 0
|
|
68
|
+
|
|
69
|
+
const renderBar = useCallback(() => <ActionBarContent {...props} />, [props])
|
|
70
|
+
|
|
71
|
+
useEffect(() => {
|
|
72
|
+
if (!stack.managed) return
|
|
73
|
+
if (isActive) {
|
|
74
|
+
stack.register(renderBar)
|
|
75
|
+
} else {
|
|
76
|
+
stack.unregister()
|
|
77
|
+
}
|
|
78
|
+
return () => stack.unregister()
|
|
79
|
+
}, [stack, isActive, renderBar])
|
|
67
80
|
|
|
68
|
-
|
|
69
|
-
|
|
81
|
+
// If no provider, fall back to standalone rendering
|
|
82
|
+
if (!stack.managed) {
|
|
83
|
+
if (!isActive) return null
|
|
84
|
+
return <ActionBarContent {...props} />
|
|
70
85
|
}
|
|
71
86
|
|
|
72
|
-
|
|
87
|
+
// Managed by provider — rendering happens there
|
|
88
|
+
return null
|
|
73
89
|
}
|
|
74
90
|
|
|
75
91
|
export const ActionBar = ActionBarInner
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createContext,
|
|
3
|
+
useCallback,
|
|
4
|
+
useContext,
|
|
5
|
+
useId,
|
|
6
|
+
useMemo,
|
|
7
|
+
useRef,
|
|
8
|
+
useSyncExternalStore,
|
|
9
|
+
type ReactNode,
|
|
10
|
+
} from 'react'
|
|
11
|
+
|
|
12
|
+
interface ActionBarEntry {
|
|
13
|
+
id: string
|
|
14
|
+
render: () => ReactNode
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
interface ActionBarStore {
|
|
18
|
+
subscribe: (cb: () => void) => () => void
|
|
19
|
+
getSnapshot: () => readonly ActionBarEntry[]
|
|
20
|
+
push: (id: string, render: () => ReactNode) => void
|
|
21
|
+
update: (id: string, render: () => ReactNode) => void
|
|
22
|
+
remove: (id: string) => void
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function createActionBarStore(): ActionBarStore {
|
|
26
|
+
let entries: ActionBarEntry[] = []
|
|
27
|
+
const listeners = new Set<() => void>()
|
|
28
|
+
|
|
29
|
+
const notify = () => listeners.forEach((l) => l())
|
|
30
|
+
|
|
31
|
+
return {
|
|
32
|
+
subscribe: (cb) => {
|
|
33
|
+
listeners.add(cb)
|
|
34
|
+
return () => listeners.delete(cb)
|
|
35
|
+
},
|
|
36
|
+
getSnapshot: () => entries,
|
|
37
|
+
push: (id, render) => {
|
|
38
|
+
entries = [...entries, {id, render}]
|
|
39
|
+
notify()
|
|
40
|
+
},
|
|
41
|
+
update: (id, render) => {
|
|
42
|
+
entries = entries.map((e) => (e.id === id ? {id, render} : e))
|
|
43
|
+
notify()
|
|
44
|
+
},
|
|
45
|
+
remove: (id) => {
|
|
46
|
+
entries = entries.filter((e) => e.id !== id)
|
|
47
|
+
notify()
|
|
48
|
+
},
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const ActionBarContext = createContext<ActionBarStore | null>(null)
|
|
53
|
+
|
|
54
|
+
export function ActionBarProvider({children}: {children: ReactNode}) {
|
|
55
|
+
const storeRef = useRef<ActionBarStore>(null)
|
|
56
|
+
if (storeRef.current === null) {
|
|
57
|
+
storeRef.current = createActionBarStore()
|
|
58
|
+
}
|
|
59
|
+
const store = storeRef.current
|
|
60
|
+
|
|
61
|
+
const entries = useSyncExternalStore(store.subscribe, store.getSnapshot, store.getSnapshot)
|
|
62
|
+
const topEntry = entries.length > 0 ? entries[entries.length - 1] : null
|
|
63
|
+
|
|
64
|
+
return (
|
|
65
|
+
<ActionBarContext.Provider value={store}>
|
|
66
|
+
{children}
|
|
67
|
+
{topEntry?.render()}
|
|
68
|
+
</ActionBarContext.Provider>
|
|
69
|
+
)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function useActionBarStack() {
|
|
73
|
+
const store = useContext(ActionBarContext)
|
|
74
|
+
const id = useId()
|
|
75
|
+
|
|
76
|
+
const register = useCallback(
|
|
77
|
+
(render: () => ReactNode) => {
|
|
78
|
+
if (!store) return
|
|
79
|
+
const entries = store.getSnapshot()
|
|
80
|
+
if (entries.some((e) => e.id === id)) {
|
|
81
|
+
store.update(id, render)
|
|
82
|
+
} else {
|
|
83
|
+
store.push(id, render)
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
[store, id],
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
const unregister = useCallback(() => {
|
|
90
|
+
store?.remove(id)
|
|
91
|
+
}, [store, id])
|
|
92
|
+
|
|
93
|
+
const isTop = useMemo(() => {
|
|
94
|
+
if (!store) return false
|
|
95
|
+
const entries = store.getSnapshot()
|
|
96
|
+
return entries.length > 0 && entries[entries.length - 1].id === id
|
|
97
|
+
}, [store, id])
|
|
98
|
+
|
|
99
|
+
return {id, register, unregister, managed: store !== null, isTop}
|
|
100
|
+
}
|
|
@@ -12,7 +12,10 @@ export const meta: ComponentMeta = {
|
|
|
12
12
|
'Selecting one of several options — use Select or ToggleGroup',
|
|
13
13
|
],
|
|
14
14
|
relatedTo: [
|
|
15
|
-
{
|
|
15
|
+
{
|
|
16
|
+
component: 'Switch',
|
|
17
|
+
relationship: 'Switch for on/off settings; Checkbox for opt-in/selection',
|
|
18
|
+
},
|
|
16
19
|
{component: 'Toggle', relationship: 'Toggle for toolbar actions; Checkbox for form input'},
|
|
17
20
|
],
|
|
18
21
|
example: `<Checkbox name="terms" onChange={(e) => console.log(e.target.checked)}>
|
|
@@ -1,17 +1,13 @@
|
|
|
1
1
|
import type {ComponentMeta} from '../component-meta'
|
|
2
2
|
|
|
3
3
|
export const meta: ComponentMeta = {
|
|
4
|
-
description:
|
|
5
|
-
'Horizontal flex layout that WRAPS to the next line when items overflow.',
|
|
4
|
+
description: 'Horizontal flex layout that WRAPS to the next line when items overflow.',
|
|
6
5
|
whenToUse: [
|
|
7
6
|
'Tags, badges, or chips that should wrap when they exceed the container width',
|
|
8
7
|
'Any set of inline elements with unknown/dynamic count',
|
|
9
8
|
'Filter pills, keyword lists, avatar groups',
|
|
10
9
|
],
|
|
11
|
-
whenNotToUse: [
|
|
12
|
-
'Items that must stay on one line — use Inline',
|
|
13
|
-
'Vertical stacking — use Stack',
|
|
14
|
-
],
|
|
10
|
+
whenNotToUse: ['Items that must stay on one line — use Inline', 'Vertical stacking — use Stack'],
|
|
15
11
|
relatedTo: [
|
|
16
12
|
{component: 'Inline', relationship: 'Same but does NOT wrap (nowrap)'},
|
|
17
13
|
{component: 'Stack', relationship: 'Vertical equivalent'},
|
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
import type {Meta, StoryObj} from '@storybook/react'
|
|
2
|
+
import {expect, within, userEvent} from 'storybook/test'
|
|
3
|
+
import {css, html} from 'react-strict-dom'
|
|
4
|
+
import {useState} from 'react'
|
|
5
|
+
import {Dialog} from './Dialog'
|
|
6
|
+
import {Button} from '../Button/Button'
|
|
7
|
+
import {Text} from '../Text/Text'
|
|
8
|
+
import {Inline} from '../Inline/Inline'
|
|
9
|
+
import {Stack} from '../Stack/Stack'
|
|
10
|
+
import {Input} from '../Input/Input'
|
|
11
|
+
import {Field} from '../Field/Field'
|
|
12
|
+
import {Heading} from '../Heading/Heading'
|
|
13
|
+
|
|
14
|
+
const meta: Meta = {
|
|
15
|
+
title: 'Components/Dialog',
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export default meta
|
|
19
|
+
type Story = StoryObj
|
|
20
|
+
|
|
21
|
+
// --- Default ---
|
|
22
|
+
|
|
23
|
+
export const Default: Story = {
|
|
24
|
+
render: () => (
|
|
25
|
+
<Dialog.Root>
|
|
26
|
+
<Dialog.Trigger>
|
|
27
|
+
<Button>Open dialog</Button>
|
|
28
|
+
</Dialog.Trigger>
|
|
29
|
+
<Dialog.Portal>
|
|
30
|
+
<Dialog.Header>
|
|
31
|
+
<Dialog.Title>Confirm action</Dialog.Title>
|
|
32
|
+
<Dialog.Close />
|
|
33
|
+
</Dialog.Header>
|
|
34
|
+
<Dialog.Body>
|
|
35
|
+
<Text>Are you sure you want to proceed? This action cannot be undone.</Text>
|
|
36
|
+
</Dialog.Body>
|
|
37
|
+
<Dialog.Footer>
|
|
38
|
+
<Dialog.Close>
|
|
39
|
+
<Button variant="secondary">Cancel</Button>
|
|
40
|
+
</Dialog.Close>
|
|
41
|
+
<Button variant="primary">Confirm</Button>
|
|
42
|
+
</Dialog.Footer>
|
|
43
|
+
</Dialog.Portal>
|
|
44
|
+
</Dialog.Root>
|
|
45
|
+
),
|
|
46
|
+
play: async ({canvasElement}) => {
|
|
47
|
+
const canvas = within(canvasElement)
|
|
48
|
+
const trigger = canvas.getByText('Open dialog')
|
|
49
|
+
await expect(trigger).toBeInTheDocument()
|
|
50
|
+
|
|
51
|
+
// Dialog should not be visible initially
|
|
52
|
+
expect(canvasElement.ownerDocument.querySelector('[role="dialog"]')).toBeNull()
|
|
53
|
+
},
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// --- WithDescription ---
|
|
57
|
+
|
|
58
|
+
export const WithDescription: Story = {
|
|
59
|
+
render: () => (
|
|
60
|
+
<Dialog.Root>
|
|
61
|
+
<Dialog.Trigger>
|
|
62
|
+
<Button variant="danger">Delete account</Button>
|
|
63
|
+
</Dialog.Trigger>
|
|
64
|
+
<Dialog.Portal size="sm">
|
|
65
|
+
<Dialog.Header>
|
|
66
|
+
<Dialog.Title>Delete account</Dialog.Title>
|
|
67
|
+
<Dialog.Close />
|
|
68
|
+
</Dialog.Header>
|
|
69
|
+
<Dialog.Description>
|
|
70
|
+
This will permanently delete your account and all associated data.
|
|
71
|
+
</Dialog.Description>
|
|
72
|
+
<Dialog.Body>
|
|
73
|
+
<Text>Please type "DELETE" to confirm.</Text>
|
|
74
|
+
</Dialog.Body>
|
|
75
|
+
<Dialog.Footer>
|
|
76
|
+
<Dialog.Close>
|
|
77
|
+
<Button variant="secondary">Cancel</Button>
|
|
78
|
+
</Dialog.Close>
|
|
79
|
+
<Button variant="danger">Delete</Button>
|
|
80
|
+
</Dialog.Footer>
|
|
81
|
+
</Dialog.Portal>
|
|
82
|
+
</Dialog.Root>
|
|
83
|
+
),
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// --- Sizes ---
|
|
87
|
+
|
|
88
|
+
function SizeDemo() {
|
|
89
|
+
const [size, setSize] = useState<'sm' | 'md' | 'lg' | null>(null)
|
|
90
|
+
|
|
91
|
+
return (
|
|
92
|
+
<Inline gap="sm">
|
|
93
|
+
{(['sm', 'md', 'lg'] as const).map((s) => (
|
|
94
|
+
<Dialog.Root key={s} open={size === s} onOpenChange={(open) => setSize(open ? s : null)}>
|
|
95
|
+
<Dialog.Trigger>
|
|
96
|
+
<Button variant="secondary">{s.toUpperCase()}</Button>
|
|
97
|
+
</Dialog.Trigger>
|
|
98
|
+
<Dialog.Portal size={s}>
|
|
99
|
+
<Dialog.Header>
|
|
100
|
+
<Dialog.Title>Size: {s}</Dialog.Title>
|
|
101
|
+
<Dialog.Close />
|
|
102
|
+
</Dialog.Header>
|
|
103
|
+
<Dialog.Body>
|
|
104
|
+
<Text>
|
|
105
|
+
This dialog uses the <html.strong>{s}</html.strong> size preset.
|
|
106
|
+
</Text>
|
|
107
|
+
</Dialog.Body>
|
|
108
|
+
<Dialog.Footer>
|
|
109
|
+
<Dialog.Close>
|
|
110
|
+
<Button variant="secondary">Close</Button>
|
|
111
|
+
</Dialog.Close>
|
|
112
|
+
</Dialog.Footer>
|
|
113
|
+
</Dialog.Portal>
|
|
114
|
+
</Dialog.Root>
|
|
115
|
+
))}
|
|
116
|
+
</Inline>
|
|
117
|
+
)
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export const Sizes: Story = {
|
|
121
|
+
render: () => <SizeDemo />,
|
|
122
|
+
play: async ({canvasElement}) => {
|
|
123
|
+
const canvas = within(canvasElement)
|
|
124
|
+
await expect(canvas.getByText('SM')).toBeInTheDocument()
|
|
125
|
+
await expect(canvas.getByText('MD')).toBeInTheDocument()
|
|
126
|
+
await expect(canvas.getByText('LG')).toBeInTheDocument()
|
|
127
|
+
},
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// --- Controlled ---
|
|
131
|
+
|
|
132
|
+
function ControlledDemo() {
|
|
133
|
+
const [open, setOpen] = useState(false)
|
|
134
|
+
|
|
135
|
+
return (
|
|
136
|
+
<Stack gap="md">
|
|
137
|
+
<Inline gap="sm">
|
|
138
|
+
<Button onClick={() => setOpen(true)}>Open</Button>
|
|
139
|
+
<Text variant="caption">Status: {open ? 'Open' : 'Closed'}</Text>
|
|
140
|
+
</Inline>
|
|
141
|
+
<Dialog.Root open={open} onOpenChange={setOpen}>
|
|
142
|
+
<Dialog.Portal>
|
|
143
|
+
<Dialog.Header>
|
|
144
|
+
<Dialog.Title>Controlled dialog</Dialog.Title>
|
|
145
|
+
<Dialog.Close />
|
|
146
|
+
</Dialog.Header>
|
|
147
|
+
<Dialog.Body>
|
|
148
|
+
<Text>This dialog is controlled via the open prop.</Text>
|
|
149
|
+
</Dialog.Body>
|
|
150
|
+
<Dialog.Footer>
|
|
151
|
+
<Button variant="secondary" onClick={() => setOpen(false)}>
|
|
152
|
+
Close programmatically
|
|
153
|
+
</Button>
|
|
154
|
+
</Dialog.Footer>
|
|
155
|
+
</Dialog.Portal>
|
|
156
|
+
</Dialog.Root>
|
|
157
|
+
</Stack>
|
|
158
|
+
)
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export const Controlled: Story = {
|
|
162
|
+
render: () => <ControlledDemo />,
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// --- WithForm ---
|
|
166
|
+
|
|
167
|
+
function FormDialogDemo() {
|
|
168
|
+
const [open, setOpen] = useState(false)
|
|
169
|
+
|
|
170
|
+
return (
|
|
171
|
+
<Dialog.Root open={open} onOpenChange={setOpen}>
|
|
172
|
+
<Dialog.Trigger>
|
|
173
|
+
<Button>Edit profile</Button>
|
|
174
|
+
</Dialog.Trigger>
|
|
175
|
+
<Dialog.Portal size="md">
|
|
176
|
+
<Dialog.Header>
|
|
177
|
+
<Dialog.Title>Edit profile</Dialog.Title>
|
|
178
|
+
<Dialog.Close />
|
|
179
|
+
</Dialog.Header>
|
|
180
|
+
<Dialog.Description>
|
|
181
|
+
Update your display name and email address.
|
|
182
|
+
</Dialog.Description>
|
|
183
|
+
<Dialog.Body>
|
|
184
|
+
<Stack gap="md">
|
|
185
|
+
<Field.Root>
|
|
186
|
+
<Field.Label>Display name</Field.Label>
|
|
187
|
+
<Input placeholder="Enter your name" />
|
|
188
|
+
</Field.Root>
|
|
189
|
+
<Field.Root>
|
|
190
|
+
<Field.Label>Email</Field.Label>
|
|
191
|
+
<Input type="email" placeholder="you@example.com" />
|
|
192
|
+
</Field.Root>
|
|
193
|
+
</Stack>
|
|
194
|
+
</Dialog.Body>
|
|
195
|
+
<Dialog.Footer>
|
|
196
|
+
<Dialog.Close>
|
|
197
|
+
<Button variant="secondary">Cancel</Button>
|
|
198
|
+
</Dialog.Close>
|
|
199
|
+
<Button onClick={() => setOpen(false)}>Save changes</Button>
|
|
200
|
+
</Dialog.Footer>
|
|
201
|
+
</Dialog.Portal>
|
|
202
|
+
</Dialog.Root>
|
|
203
|
+
)
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
export const WithForm: Story = {
|
|
207
|
+
render: () => <FormDialogDemo />,
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// --- Danger confirmation ---
|
|
211
|
+
|
|
212
|
+
function DangerDialogDemo() {
|
|
213
|
+
const [open, setOpen] = useState(false)
|
|
214
|
+
const [confirmed, setConfirmed] = useState(false)
|
|
215
|
+
|
|
216
|
+
return (
|
|
217
|
+
<Stack gap="md">
|
|
218
|
+
<Dialog.Root open={open} onOpenChange={setOpen}>
|
|
219
|
+
<Dialog.Trigger>
|
|
220
|
+
<Button variant="danger">Revoke certificate</Button>
|
|
221
|
+
</Dialog.Trigger>
|
|
222
|
+
<Dialog.Portal size="sm">
|
|
223
|
+
<Dialog.Header>
|
|
224
|
+
<Dialog.Title>Revoke certificate</Dialog.Title>
|
|
225
|
+
<Dialog.Close />
|
|
226
|
+
</Dialog.Header>
|
|
227
|
+
<Dialog.Description>
|
|
228
|
+
This will immediately invalidate the certificate. Connected devices will lose access.
|
|
229
|
+
</Dialog.Description>
|
|
230
|
+
<Dialog.Body>
|
|
231
|
+
<Text variant="bodySm">Certificate: web-server-prod-2024.pem</Text>
|
|
232
|
+
</Dialog.Body>
|
|
233
|
+
<Dialog.Footer>
|
|
234
|
+
<Dialog.Close>
|
|
235
|
+
<Button variant="secondary">Cancel</Button>
|
|
236
|
+
</Dialog.Close>
|
|
237
|
+
<Button
|
|
238
|
+
variant="danger"
|
|
239
|
+
onClick={() => {
|
|
240
|
+
setConfirmed(true)
|
|
241
|
+
setOpen(false)
|
|
242
|
+
}}
|
|
243
|
+
>
|
|
244
|
+
Revoke
|
|
245
|
+
</Button>
|
|
246
|
+
</Dialog.Footer>
|
|
247
|
+
</Dialog.Portal>
|
|
248
|
+
</Dialog.Root>
|
|
249
|
+
{confirmed && <Text variant="bodySm">Certificate revoked.</Text>}
|
|
250
|
+
</Stack>
|
|
251
|
+
)
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
export const DangerConfirmation: Story = {
|
|
255
|
+
render: () => <DangerDialogDemo />,
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// --- Non-dismissable (modal) ---
|
|
259
|
+
|
|
260
|
+
export const NonDismissable: Story = {
|
|
261
|
+
render: () => (
|
|
262
|
+
<Dialog.Root dismissable={false}>
|
|
263
|
+
<Dialog.Trigger>
|
|
264
|
+
<Button>Open non-dismissable</Button>
|
|
265
|
+
</Dialog.Trigger>
|
|
266
|
+
<Dialog.Portal size="sm">
|
|
267
|
+
<Dialog.Header>
|
|
268
|
+
<Dialog.Title>Terms of service</Dialog.Title>
|
|
269
|
+
</Dialog.Header>
|
|
270
|
+
<Dialog.Body>
|
|
271
|
+
<Stack gap="md">
|
|
272
|
+
<Text>
|
|
273
|
+
You must accept the terms of service to continue. This dialog cannot be
|
|
274
|
+
dismissed by clicking outside or pressing Escape.
|
|
275
|
+
</Text>
|
|
276
|
+
<Text variant="bodySm" color="muted">
|
|
277
|
+
Try clicking the backdrop or pressing Escape — the dialog stays open.
|
|
278
|
+
</Text>
|
|
279
|
+
</Stack>
|
|
280
|
+
</Dialog.Body>
|
|
281
|
+
<Dialog.Footer>
|
|
282
|
+
<Dialog.Close>
|
|
283
|
+
<Button variant="secondary">Decline</Button>
|
|
284
|
+
</Dialog.Close>
|
|
285
|
+
<Dialog.Close>
|
|
286
|
+
<Button>Accept</Button>
|
|
287
|
+
</Dialog.Close>
|
|
288
|
+
</Dialog.Footer>
|
|
289
|
+
</Dialog.Portal>
|
|
290
|
+
</Dialog.Root>
|
|
291
|
+
),
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
// --- Backdrop dismiss ---
|
|
295
|
+
|
|
296
|
+
function BackdropDismissDemo() {
|
|
297
|
+
const [lastAction, setLastAction] = useState('')
|
|
298
|
+
|
|
299
|
+
return (
|
|
300
|
+
<Stack gap="md">
|
|
301
|
+
<Dialog.Root onOpenChange={(open) => !open && setLastAction('Dismissed')}>
|
|
302
|
+
<Dialog.Trigger>
|
|
303
|
+
<Button variant="secondary">Open dialog</Button>
|
|
304
|
+
</Dialog.Trigger>
|
|
305
|
+
<Dialog.Portal size="sm">
|
|
306
|
+
<Dialog.Header>
|
|
307
|
+
<Dialog.Title>Click outside to close</Dialog.Title>
|
|
308
|
+
<Dialog.Close />
|
|
309
|
+
</Dialog.Header>
|
|
310
|
+
<Dialog.Body>
|
|
311
|
+
<Text>
|
|
312
|
+
Click the dark backdrop behind this dialog to dismiss it.
|
|
313
|
+
You can also press Escape or use the close button.
|
|
314
|
+
</Text>
|
|
315
|
+
</Dialog.Body>
|
|
316
|
+
</Dialog.Portal>
|
|
317
|
+
</Dialog.Root>
|
|
318
|
+
{lastAction && <Text variant="bodySm">Last action: {lastAction}</Text>}
|
|
319
|
+
</Stack>
|
|
320
|
+
)
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
export const BackdropDismiss: Story = {
|
|
324
|
+
render: () => <BackdropDismissDemo />,
|
|
325
|
+
}
|