@duro-app/ui 5.1.0 → 5.3.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/Table-Cm5cCnZD.js +1524 -0
- package/dist/Table-Cm5cCnZD.js.map +1 -0
- package/dist/components/ActionBar/styles.css.d.ts +1 -1
- package/dist/components/ActionBar/styles.css.d.ts.map +1 -1
- package/dist/components/Badge/Badge.d.ts +1 -1
- package/dist/components/Badge/Badge.d.ts.map +1 -1
- package/dist/components/Badge/Badge.stories.d.ts +3 -0
- package/dist/components/Badge/Badge.stories.d.ts.map +1 -1
- package/dist/components/Badge/styles.css.d.ts +4 -0
- package/dist/components/Badge/styles.css.d.ts.map +1 -1
- package/dist/components/Button/Button.d.ts +11 -2
- package/dist/components/Button/Button.d.ts.map +1 -1
- package/dist/components/Button/Button.stories.d.ts +1 -0
- package/dist/components/Button/Button.stories.d.ts.map +1 -1
- package/dist/components/ButtonGroup/ButtonGroup.d.ts +9 -2
- package/dist/components/ButtonGroup/ButtonGroup.d.ts.map +1 -1
- package/dist/components/ButtonGroup/ButtonGroup.meta.d.ts.map +1 -1
- package/dist/components/ButtonGroup/ButtonGroup.stories.d.ts +19 -0
- package/dist/components/ButtonGroup/ButtonGroup.stories.d.ts.map +1 -1
- package/dist/components/ButtonGroup/ButtonGroupContext.d.ts +13 -0
- package/dist/components/ButtonGroup/ButtonGroupContext.d.ts.map +1 -0
- package/dist/components/ButtonGroup/attached.css.d.ts +34 -0
- package/dist/components/ButtonGroup/attached.css.d.ts.map +1 -0
- package/dist/components/ButtonGroup/styles.css.d.ts +7 -0
- package/dist/components/ButtonGroup/styles.css.d.ts.map +1 -1
- package/dist/components/ButtonGroup/useGroupedControl.d.ts +25 -0
- package/dist/components/ButtonGroup/useGroupedControl.d.ts.map +1 -0
- package/dist/components/Combobox/Combobox.d.ts +1 -1
- package/dist/components/Combobox/Combobox.d.ts.map +1 -1
- package/dist/components/Combobox/styles.css.d.ts +0 -64
- package/dist/components/Combobox/styles.css.d.ts.map +1 -1
- package/dist/components/Dialog/Dialog.d.ts +11 -3
- package/dist/components/Dialog/Dialog.d.ts.map +1 -1
- package/dist/components/Dialog/Dialog.stories.d.ts +4 -0
- package/dist/components/Dialog/Dialog.stories.d.ts.map +1 -1
- package/dist/components/Dialog/styles.css.d.ts +3 -2
- package/dist/components/Dialog/styles.css.d.ts.map +1 -1
- package/dist/components/DragDrop/DragDrop.d.ts.map +1 -1
- package/dist/components/DragDrop/styles.css.d.ts +11 -3
- package/dist/components/DragDrop/styles.css.d.ts.map +1 -1
- package/dist/components/Drawer/Drawer.d.ts.map +1 -1
- package/dist/components/Drawer/styles.css.d.ts +2 -2
- package/dist/components/Drawer/styles.css.d.ts.map +1 -1
- package/dist/components/Grid/Grid.d.ts +11 -2
- package/dist/components/Grid/Grid.d.ts.map +1 -1
- package/dist/components/Grid/Grid.stories.d.ts +2 -0
- package/dist/components/Grid/Grid.stories.d.ts.map +1 -1
- package/dist/components/Input/Input.d.ts +6 -1
- package/dist/components/Input/Input.d.ts.map +1 -1
- package/dist/components/Input/Input.meta.d.ts.map +1 -1
- package/dist/components/Input/Input.stories.d.ts +1 -0
- package/dist/components/Input/Input.stories.d.ts.map +1 -1
- package/dist/components/Input/styles.css.d.ts +18 -0
- package/dist/components/Input/styles.css.d.ts.map +1 -1
- package/dist/components/InputGroup/InputGroup.d.ts +6 -1
- package/dist/components/InputGroup/InputGroup.d.ts.map +1 -1
- package/dist/components/InputGroup/InputGroup.stories.d.ts +1 -0
- package/dist/components/InputGroup/InputGroup.stories.d.ts.map +1 -1
- package/dist/components/Listbox/Listbox.d.ts +75 -0
- package/dist/components/Listbox/Listbox.d.ts.map +1 -0
- package/dist/components/Listbox/Listbox.meta.d.ts +3 -0
- package/dist/components/Listbox/Listbox.meta.d.ts.map +1 -0
- package/dist/components/Listbox/Listbox.stories.d.ts +7 -0
- package/dist/components/Listbox/Listbox.stories.d.ts.map +1 -0
- package/dist/components/Listbox/styles.css.d.ts +75 -0
- package/dist/components/Listbox/styles.css.d.ts.map +1 -0
- package/dist/components/Menu/Menu.d.ts +18 -5
- package/dist/components/Menu/Menu.d.ts.map +1 -1
- package/dist/components/Menu/Menu.meta.d.ts.map +1 -1
- package/dist/components/Menu/Menu.stories.d.ts +7 -0
- package/dist/components/Menu/Menu.stories.d.ts.map +1 -1
- package/dist/components/Menu/MenuContext.d.ts +3 -0
- package/dist/components/Menu/MenuContext.d.ts.map +1 -1
- package/dist/components/Menu/styles.css.d.ts +24 -15
- package/dist/components/Menu/styles.css.d.ts.map +1 -1
- package/dist/components/Menu/useMenuRoot.d.ts +14 -1
- package/dist/components/Menu/useMenuRoot.d.ts.map +1 -1
- package/dist/components/Popover/Popover.d.ts +7 -2
- package/dist/components/Popover/Popover.d.ts.map +1 -1
- package/dist/components/Popover/styles.css.d.ts +4 -1
- package/dist/components/Popover/styles.css.d.ts.map +1 -1
- package/dist/components/ScrollArea/styles.css.d.ts +1 -1
- package/dist/components/ScrollArea/styles.css.d.ts.map +1 -1
- package/dist/components/Select/Select.d.ts.map +1 -1
- package/dist/components/Select/Select.stories.d.ts +2 -0
- package/dist/components/Select/Select.stories.d.ts.map +1 -1
- package/dist/components/Select/styles.css.d.ts +2 -2
- package/dist/components/Select/styles.css.d.ts.map +1 -1
- package/dist/components/Select/useSelectRoot.d.ts.map +1 -1
- package/dist/components/TextLink/TextLink.d.ts +24 -0
- package/dist/components/TextLink/TextLink.d.ts.map +1 -0
- package/dist/components/TextLink/TextLink.meta.d.ts +3 -0
- package/dist/components/TextLink/TextLink.meta.d.ts.map +1 -0
- package/dist/components/TextLink/TextLink.stories.d.ts +9 -0
- package/dist/components/TextLink/TextLink.stories.d.ts.map +1 -0
- package/dist/components/TextLink/styles.css.d.ts +28 -0
- package/dist/components/TextLink/styles.css.d.ts.map +1 -0
- package/dist/components/ThemeProvider/Layers.stories.d.ts +24 -0
- package/dist/components/ThemeProvider/Layers.stories.d.ts.map +1 -0
- package/dist/components/ThemeProvider/ThemeProvider.d.ts.map +1 -1
- package/dist/components/ThemeProvider/ThemeProvider.stories.d.ts +1 -0
- package/dist/components/ThemeProvider/ThemeProvider.stories.d.ts.map +1 -1
- package/dist/components/Toast/styles.css.d.ts +1 -0
- package/dist/components/Toast/styles.css.d.ts.map +1 -1
- package/dist/components/Toggle/Toggle.d.ts.map +1 -1
- package/dist/components/Toggle/styles.css.d.ts +3 -0
- package/dist/components/Toggle/styles.css.d.ts.map +1 -1
- package/dist/components/ToggleGroup/ToggleGroup.d.ts.map +1 -1
- package/dist/components/ToggleGroup/styles.css.d.ts +5 -0
- package/dist/components/ToggleGroup/styles.css.d.ts.map +1 -1
- package/dist/components/Toolbar/ControlContextBoundary.d.ts +10 -0
- package/dist/components/Toolbar/ControlContextBoundary.d.ts.map +1 -0
- package/dist/components/Toolbar/Toolbar.d.ts +22 -0
- package/dist/components/Toolbar/Toolbar.d.ts.map +1 -0
- package/dist/components/Toolbar/Toolbar.meta.d.ts +3 -0
- package/dist/components/Toolbar/Toolbar.meta.d.ts.map +1 -0
- package/dist/components/Toolbar/Toolbar.stories.d.ts +28 -0
- package/dist/components/Toolbar/Toolbar.stories.d.ts.map +1 -0
- package/dist/components/Toolbar/ToolbarContext.d.ts +10 -0
- package/dist/components/Toolbar/ToolbarContext.d.ts.map +1 -0
- package/dist/components/Toolbar/styles.css.d.ts +16 -0
- package/dist/components/Toolbar/styles.css.d.ts.map +1 -0
- package/dist/components/Tooltip/styles.css.d.ts +1 -1
- package/dist/components/Tooltip/styles.css.d.ts.map +1 -1
- package/dist/components/VirtualTable/styles.css.d.ts +1 -1
- package/dist/components/VirtualTable/styles.css.d.ts.map +1 -1
- package/dist/components/VisuallyHidden/VisuallyHidden.d.ts +14 -0
- package/dist/components/VisuallyHidden/VisuallyHidden.d.ts.map +1 -0
- package/dist/components/VisuallyHidden/VisuallyHidden.meta.d.ts +3 -0
- package/dist/components/VisuallyHidden/VisuallyHidden.meta.d.ts.map +1 -0
- package/dist/components/VisuallyHidden/VisuallyHidden.stories.d.ts +7 -0
- package/dist/components/VisuallyHidden/VisuallyHidden.stories.d.ts.map +1 -0
- package/dist/docs/FlexGrow.stories.d.ts +7 -0
- package/dist/docs/FlexGrow.stories.d.ts.map +1 -0
- package/dist/index.css +1 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3768 -3356
- package/dist/index.js.map +1 -1
- package/dist/index.native.d.ts +1 -0
- package/dist/index.native.d.ts.map +1 -1
- package/dist/shared/ModalContext.d.ts +14 -0
- package/dist/shared/ModalContext.d.ts.map +1 -0
- package/dist/shared/mergeRefs.d.ts +4 -0
- package/dist/shared/mergeRefs.d.ts.map +1 -0
- package/dist/shared/useOrderedRegistry.d.ts +26 -0
- package/dist/shared/useOrderedRegistry.d.ts.map +1 -0
- package/dist/styles/visually-hidden.css.d.ts +6 -0
- package/dist/styles/visually-hidden.css.d.ts.map +1 -1
- package/dist/table.js +45 -45
- package/dist/table.js.map +1 -1
- package/package.json +2 -2
- package/src/components/ActionBar/styles.css.ts +2 -1
- package/src/components/Badge/Badge.stories.tsx +62 -1
- package/src/components/Badge/Badge.tsx +1 -1
- package/src/components/Badge/styles.css.ts +5 -0
- package/src/components/Button/Button.stories.tsx +41 -0
- package/src/components/Button/Button.tsx +22 -1
- package/src/components/ButtonGroup/ButtonGroup.meta.ts +14 -1
- package/src/components/ButtonGroup/ButtonGroup.stories.tsx +271 -1
- package/src/components/ButtonGroup/ButtonGroup.tsx +46 -14
- package/src/components/ButtonGroup/ButtonGroupContext.ts +19 -0
- package/src/components/ButtonGroup/attached.css.ts +44 -0
- package/src/components/ButtonGroup/styles.css.ts +8 -0
- package/src/components/ButtonGroup/useGroupedControl.ts +75 -0
- package/src/components/Combobox/Combobox.tsx +25 -79
- package/src/components/Combobox/styles.css.ts +0 -74
- package/src/components/Dialog/Dialog.meta.ts +1 -1
- package/src/components/Dialog/Dialog.stories.tsx +109 -3
- package/src/components/Dialog/Dialog.tsx +68 -10
- package/src/components/Dialog/styles.css.ts +5 -2
- package/src/components/DragDrop/DragDrop.tsx +15 -8
- package/src/components/DragDrop/styles.css.ts +20 -4
- package/src/components/Drawer/Drawer.tsx +5 -1
- package/src/components/Drawer/styles.css.ts +3 -2
- package/src/components/Grid/Grid.meta.ts +1 -1
- package/src/components/Grid/Grid.stories.tsx +53 -1
- package/src/components/Grid/Grid.tsx +23 -11
- package/src/components/Input/Input.meta.ts +10 -3
- package/src/components/Input/Input.stories.tsx +52 -2
- package/src/components/Input/Input.tsx +12 -3
- package/src/components/Input/styles.css.ts +29 -0
- package/src/components/InputGroup/InputGroup.stories.tsx +20 -0
- package/src/components/InputGroup/InputGroup.tsx +20 -2
- package/src/components/Listbox/Listbox.meta.ts +52 -0
- package/src/components/Listbox/Listbox.stories.tsx +170 -0
- package/src/components/Listbox/Listbox.tsx +278 -0
- package/src/components/Listbox/styles.css.ts +90 -0
- package/src/components/Menu/Menu.meta.ts +2 -1
- package/src/components/Menu/Menu.stories.tsx +289 -8
- package/src/components/Menu/Menu.tsx +107 -29
- package/src/components/Menu/MenuContext.ts +3 -0
- package/src/components/Menu/styles.css.ts +32 -15
- package/src/components/Menu/useMenuRoot.ts +105 -48
- package/src/components/Popover/Popover.tsx +26 -5
- package/src/components/Popover/styles.css.ts +9 -1
- package/src/components/ScrollArea/styles.css.ts +2 -1
- package/src/components/Select/Select.stories.tsx +20 -1
- package/src/components/Select/Select.tsx +9 -3
- package/src/components/Select/styles.css.ts +3 -2
- package/src/components/Select/useSelectRoot.ts +17 -0
- package/src/components/TextLink/TextLink.meta.ts +33 -0
- package/src/components/TextLink/TextLink.stories.tsx +63 -0
- package/src/components/TextLink/TextLink.tsx +46 -0
- package/src/components/TextLink/styles.css.ts +58 -0
- package/src/components/ThemeProvider/Layers.stories.tsx +379 -0
- package/src/components/ThemeProvider/ThemeProvider.stories.tsx +50 -0
- package/src/components/ThemeProvider/ThemeProvider.tsx +4 -2
- package/src/components/Toast/styles.css.ts +3 -0
- package/src/components/Toggle/Toggle.tsx +20 -4
- package/src/components/Toggle/styles.css.ts +6 -0
- package/src/components/ToggleGroup/ToggleGroup.tsx +16 -4
- package/src/components/ToggleGroup/styles.css.ts +7 -0
- package/src/components/Toolbar/ControlContextBoundary.tsx +16 -0
- package/src/components/Toolbar/Toolbar.meta.ts +48 -0
- package/src/components/Toolbar/Toolbar.stories.tsx +468 -0
- package/src/components/Toolbar/Toolbar.tsx +113 -0
- package/src/components/Toolbar/ToolbarContext.ts +15 -0
- package/src/components/Toolbar/styles.css.ts +17 -0
- package/src/components/Tooltip/styles.css.ts +2 -1
- package/src/components/VirtualTable/styles.css.ts +2 -1
- package/src/components/VisuallyHidden/VisuallyHidden.meta.ts +19 -0
- package/src/components/VisuallyHidden/VisuallyHidden.stories.tsx +30 -0
- package/src/components/VisuallyHidden/VisuallyHidden.tsx +22 -0
- package/src/docs/FlexGrow.stories.tsx +83 -0
- package/src/index.native.ts +1 -0
- package/src/index.ts +7 -1
- package/src/shared/ModalContext.ts +18 -0
- package/src/shared/mergeRefs.ts +11 -0
- package/src/shared/useOrderedRegistry.ts +57 -0
- package/src/styles/visually-hidden.css.ts +8 -0
- package/dist/Table-BkrgH0jb.js +0 -1199
- package/dist/Table-BkrgH0jb.js.map +0 -1
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import {type ReactNode, useRef, useId, useEffect,
|
|
2
|
-
import {createPortal} from 'react-dom'
|
|
1
|
+
import {type ReactNode, useCallback, useRef, useId, useEffect, useState} from 'react'
|
|
3
2
|
import {html} from 'react-strict-dom'
|
|
4
3
|
import {styles} from './styles.css'
|
|
5
4
|
import {ComboboxContext, useCombobox} from './ComboboxContext'
|
|
6
5
|
import {useComboboxRoot} from './useComboboxRoot'
|
|
7
|
-
import {
|
|
8
|
-
import {usePopoverLayer} from '../Popover/PopoverLayerContext'
|
|
6
|
+
import {Listbox, getAnchorProps} from '../Listbox/Listbox'
|
|
9
7
|
|
|
10
8
|
// --- Root ---
|
|
11
9
|
interface RootProps {
|
|
@@ -54,6 +52,7 @@ function Input({placeholder, children}: {placeholder?: string; children?: ReactN
|
|
|
54
52
|
useCombobox()
|
|
55
53
|
const localRef = useRef<HTMLInputElement>(null)
|
|
56
54
|
const [focused, setFocused] = useState(false)
|
|
55
|
+
const anchor = getAnchorProps({id: listboxId, open, highlightedId})
|
|
57
56
|
|
|
58
57
|
useEffect(() => {
|
|
59
58
|
inputRef.current = localRef.current
|
|
@@ -67,10 +66,10 @@ function Input({placeholder, children}: {placeholder?: string; children?: ReactN
|
|
|
67
66
|
role={'combobox' as 'listbox'}
|
|
68
67
|
value={inputValue}
|
|
69
68
|
placeholder={placeholder}
|
|
70
|
-
aria-expanded={
|
|
69
|
+
aria-expanded={anchor['aria-expanded']}
|
|
71
70
|
aria-haspopup="listbox"
|
|
72
|
-
aria-controls={
|
|
73
|
-
aria-activedescendant={
|
|
71
|
+
aria-controls={anchor['aria-controls']}
|
|
72
|
+
aria-activedescendant={anchor['aria-activedescendant']}
|
|
74
73
|
aria-autocomplete={'list' as 'none'}
|
|
75
74
|
autoComplete="off"
|
|
76
75
|
style={styles.input}
|
|
@@ -132,58 +131,27 @@ function Trigger({children}: {children?: ReactNode}) {
|
|
|
132
131
|
}
|
|
133
132
|
|
|
134
133
|
// --- Popup ---
|
|
135
|
-
//
|
|
136
|
-
//
|
|
137
|
-
// containing blocks (notably Dialog and Drawer).
|
|
134
|
+
// A Listbox placed under the input, as wide as the field: rendered into the
|
|
135
|
+
// ThemeProvider portal mount so it escapes ancestor `overflow: hidden` /
|
|
136
|
+
// `transform` containing blocks (notably Dialog and Drawer).
|
|
138
137
|
function Popup({children}: {children: ReactNode}) {
|
|
139
|
-
const {open, listboxId, rootRef} = useCombobox()
|
|
140
|
-
const
|
|
141
|
-
const listboxRef = useRef<HTMLDivElement>(null)
|
|
142
|
-
const [coords, setCoords] = useState<{top: number; left: number; width: number} | null>(null)
|
|
138
|
+
const {open, listboxId, rootRef, highlightedId, setHighlightedId, setValue} = useCombobox()
|
|
139
|
+
const anchor = useCallback(() => rootRef.current?.getBoundingClientRect(), [rootRef])
|
|
143
140
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
// scroll on any ancestor (e.g. Dialog body).
|
|
147
|
-
useLayoutEffect(() => {
|
|
148
|
-
if (!open) {
|
|
149
|
-
setCoords(null)
|
|
150
|
-
return
|
|
151
|
-
}
|
|
152
|
-
const update = () => {
|
|
153
|
-
const el = rootRef.current
|
|
154
|
-
if (!el) return
|
|
155
|
-
const rect = el.getBoundingClientRect()
|
|
156
|
-
// Position immediately below the input with a small gap. `xs` token = 4px.
|
|
157
|
-
setCoords({top: rect.bottom + 4, left: rect.left, width: rect.width})
|
|
158
|
-
}
|
|
159
|
-
update()
|
|
160
|
-
window.addEventListener('resize', update)
|
|
161
|
-
window.addEventListener('scroll', update, true)
|
|
162
|
-
return () => {
|
|
163
|
-
window.removeEventListener('resize', update)
|
|
164
|
-
window.removeEventListener('scroll', update, true)
|
|
165
|
-
}
|
|
166
|
-
}, [open, rootRef])
|
|
167
|
-
|
|
168
|
-
usePopoverLayer(listboxRef, {active: open && coords !== null})
|
|
169
|
-
|
|
170
|
-
if (!open || !coords) return null
|
|
171
|
-
|
|
172
|
-
const node = (
|
|
173
|
-
<html.div
|
|
174
|
-
ref={listboxRef}
|
|
141
|
+
return (
|
|
142
|
+
<Listbox.Root
|
|
175
143
|
id={listboxId}
|
|
176
|
-
|
|
177
|
-
|
|
144
|
+
open={open}
|
|
145
|
+
anchor={anchor}
|
|
146
|
+
matchAnchorWidth
|
|
147
|
+
highlightedId={highlightedId}
|
|
148
|
+
onHighlight={setHighlightedId}
|
|
149
|
+
onSelect={setValue}
|
|
150
|
+
maxHeight="listMaxHSm"
|
|
178
151
|
>
|
|
179
152
|
{children}
|
|
180
|
-
</
|
|
153
|
+
</Listbox.Root>
|
|
181
154
|
)
|
|
182
|
-
|
|
183
|
-
// SSR / pre-mount fallback: render inline (will be invisible under
|
|
184
|
-
// overflow:hidden parents but won't crash). Once the mount is available,
|
|
185
|
-
// portal into it.
|
|
186
|
-
return mount ? createPortal(node, mount) : node
|
|
187
155
|
}
|
|
188
156
|
|
|
189
157
|
// --- Item ---
|
|
@@ -193,20 +161,10 @@ interface ItemProps {
|
|
|
193
161
|
}
|
|
194
162
|
|
|
195
163
|
function Item({value: itemValue, children}: ItemProps) {
|
|
196
|
-
const {
|
|
197
|
-
value: selectedValue,
|
|
198
|
-
setValue,
|
|
199
|
-
inputValue,
|
|
200
|
-
labels,
|
|
201
|
-
registerLabel,
|
|
202
|
-
highlightedId,
|
|
203
|
-
setHighlightedId,
|
|
204
|
-
registerItem,
|
|
205
|
-
} = useCombobox()
|
|
164
|
+
const {value: selectedValue, inputValue, labels, registerLabel, registerItem} = useCombobox()
|
|
206
165
|
const id = useId()
|
|
207
166
|
const ref = useRef<HTMLDivElement>(null)
|
|
208
167
|
const isSelected = selectedValue === itemValue
|
|
209
|
-
const isHighlighted = highlightedId === id
|
|
210
168
|
|
|
211
169
|
// Filter: check if this item matches the input
|
|
212
170
|
const label = labels[itemValue] ?? itemValue
|
|
@@ -229,21 +187,9 @@ function Item({value: itemValue, children}: ItemProps) {
|
|
|
229
187
|
if (!isVisible) return null
|
|
230
188
|
|
|
231
189
|
return (
|
|
232
|
-
<
|
|
233
|
-
ref={ref}
|
|
234
|
-
id={id}
|
|
235
|
-
role="option"
|
|
236
|
-
aria-selected={isSelected}
|
|
237
|
-
onClick={() => setValue(itemValue)}
|
|
238
|
-
onPointerEnter={() => setHighlightedId(id)}
|
|
239
|
-
style={[
|
|
240
|
-
styles.item,
|
|
241
|
-
isSelected && styles.itemSelected,
|
|
242
|
-
isHighlighted && styles.itemHighlighted,
|
|
243
|
-
]}
|
|
244
|
-
>
|
|
190
|
+
<Listbox.Option ref={ref} id={id} value={itemValue} selected={isSelected}>
|
|
245
191
|
{children}
|
|
246
|
-
</
|
|
192
|
+
</Listbox.Option>
|
|
247
193
|
)
|
|
248
194
|
}
|
|
249
195
|
|
|
@@ -266,7 +212,7 @@ function Empty({children}: {children: ReactNode}) {
|
|
|
266
212
|
|
|
267
213
|
if (hasVisibleItems) return null
|
|
268
214
|
|
|
269
|
-
return <
|
|
215
|
+
return <Listbox.Empty>{children}</Listbox.Empty>
|
|
270
216
|
}
|
|
271
217
|
|
|
272
218
|
export const Combobox = {
|
|
@@ -2,9 +2,7 @@ import {css} from 'react-strict-dom'
|
|
|
2
2
|
import {colors} from '@duro-app/tokens/tokens/colors.css'
|
|
3
3
|
import {spacing, radii} from '@duro-app/tokens/tokens/spacing.css'
|
|
4
4
|
import {typography} from '@duro-app/tokens/tokens/typography.css'
|
|
5
|
-
import {shadows} from '@duro-app/tokens/tokens/shadows.css'
|
|
6
5
|
import {duration} from '@duro-app/tokens/tokens/motion.css'
|
|
7
|
-
import {sizes} from '@duro-app/tokens/tokens/sizes.css'
|
|
8
6
|
import {borders} from '@duro-app/tokens/tokens/borders.css'
|
|
9
7
|
|
|
10
8
|
export const styles = css.create({
|
|
@@ -57,76 +55,4 @@ export const styles = css.create({
|
|
|
57
55
|
color: colors.textMuted,
|
|
58
56
|
cursor: 'pointer',
|
|
59
57
|
},
|
|
60
|
-
backdrop: {
|
|
61
|
-
position: 'fixed',
|
|
62
|
-
top: 0,
|
|
63
|
-
left: 0,
|
|
64
|
-
right: 0,
|
|
65
|
-
bottom: 0,
|
|
66
|
-
// Above Dialog/Drawer (1000/1001): they portal into the same mount, so a
|
|
67
|
-
// popup opened from inside a dialog must out-rank the dialog itself.
|
|
68
|
-
zIndex: 1049,
|
|
69
|
-
},
|
|
70
|
-
popup: {
|
|
71
|
-
// Position is `fixed` and the top/left/width are applied inline by Popup
|
|
72
|
-
// (computed from the root's bounding rect) so the dropdown can escape any
|
|
73
|
-
// ancestor with `overflow: hidden` or `transform` (e.g. inside a Dialog).
|
|
74
|
-
position: 'fixed',
|
|
75
|
-
backgroundColor: colors.bgCard,
|
|
76
|
-
borderWidth: borders.hairline,
|
|
77
|
-
borderStyle: 'solid',
|
|
78
|
-
borderColor: colors.border,
|
|
79
|
-
borderRadius: radii.sm,
|
|
80
|
-
boxShadow: shadows.md,
|
|
81
|
-
paddingTop: spacing.xs,
|
|
82
|
-
paddingBottom: spacing.xs,
|
|
83
|
-
maxHeight: sizes.listMaxHSm,
|
|
84
|
-
overflowY: 'auto',
|
|
85
|
-
zIndex: 1050,
|
|
86
|
-
// Re-enable pointer events: the portal mount is pointer-events: none so
|
|
87
|
-
// clicks fall through except on the popup itself.
|
|
88
|
-
pointerEvents: 'auto',
|
|
89
|
-
},
|
|
90
|
-
item: {
|
|
91
|
-
display: 'flex',
|
|
92
|
-
alignItems: 'center',
|
|
93
|
-
paddingTop: spacing.sm,
|
|
94
|
-
paddingBottom: spacing.sm,
|
|
95
|
-
paddingLeft: spacing.md,
|
|
96
|
-
paddingRight: spacing.md,
|
|
97
|
-
fontSize: typography.fontSizeSm,
|
|
98
|
-
fontFamily: typography.fontFamily,
|
|
99
|
-
color: colors.text,
|
|
100
|
-
cursor: 'pointer',
|
|
101
|
-
backgroundColor: 'transparent',
|
|
102
|
-
transitionProperty: 'background-color',
|
|
103
|
-
transitionDuration: duration.fast,
|
|
104
|
-
},
|
|
105
|
-
itemSelected: {
|
|
106
|
-
color: colors.accent,
|
|
107
|
-
fontWeight: typography.fontWeightMedium,
|
|
108
|
-
},
|
|
109
|
-
itemHighlighted: {
|
|
110
|
-
backgroundColor: colors.bgCardHover,
|
|
111
|
-
},
|
|
112
|
-
itemHidden: {
|
|
113
|
-
display: 'none',
|
|
114
|
-
},
|
|
115
|
-
empty: {
|
|
116
|
-
paddingTop: spacing.sm,
|
|
117
|
-
paddingBottom: spacing.sm,
|
|
118
|
-
paddingLeft: spacing.md,
|
|
119
|
-
paddingRight: spacing.md,
|
|
120
|
-
fontSize: typography.fontSizeSm,
|
|
121
|
-
color: colors.textMuted,
|
|
122
|
-
},
|
|
123
|
-
hidden: {
|
|
124
|
-
display: 'none',
|
|
125
|
-
},
|
|
126
|
-
// Dynamic position — applied at runtime from the input's bounding rect.
|
|
127
|
-
popupPosition: (top: number, left: number, width: number) => ({
|
|
128
|
-
top,
|
|
129
|
-
left,
|
|
130
|
-
width,
|
|
131
|
-
}),
|
|
132
58
|
})
|
|
@@ -2,7 +2,7 @@ import type {ComponentMeta} from '../component-meta'
|
|
|
2
2
|
|
|
3
3
|
export const meta: ComponentMeta = {
|
|
4
4
|
description:
|
|
5
|
-
'Modal dialog with backdrop overlay. Centered on screen with scale+fade animation.
|
|
5
|
+
'Modal dialog with backdrop overlay. Centered on screen with scale+fade animation. Moves focus in on open (initialFocus, else the first focusable element, else the dialog) and back on close; dismisses on backdrop click (dismissable) or Escape (closeOnEscape, independent of dismissable). Use for confirmations, forms, or content that requires user attention before continuing.',
|
|
6
6
|
whenToUse: [
|
|
7
7
|
'Confirmation prompts (delete, revoke, destructive actions)',
|
|
8
8
|
'Short forms or data entry that blocks the main flow',
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type {Meta, StoryObj} from '@storybook/react'
|
|
2
|
-
import {expect, within, userEvent} from 'storybook/test'
|
|
2
|
+
import {expect, screen, waitFor, within, userEvent} from 'storybook/test'
|
|
3
3
|
import {css, html} from 'react-strict-dom'
|
|
4
|
-
import {useState} from 'react'
|
|
4
|
+
import {useRef, useState} from 'react'
|
|
5
5
|
import {Dialog} from './Dialog'
|
|
6
6
|
import {Button} from '../Button/Button'
|
|
7
7
|
import {Text} from '../Text/Text'
|
|
@@ -260,7 +260,7 @@ export const DangerConfirmation: Story = {
|
|
|
260
260
|
|
|
261
261
|
export const NonDismissable: Story = {
|
|
262
262
|
render: () => (
|
|
263
|
-
<Dialog.Root dismissable={false}>
|
|
263
|
+
<Dialog.Root dismissable={false} closeOnEscape={false}>
|
|
264
264
|
<Dialog.Trigger>
|
|
265
265
|
<Button>Open non-dismissable</Button>
|
|
266
266
|
</Dialog.Trigger>
|
|
@@ -454,3 +454,109 @@ export const BackdropClickDismisses: Story = {
|
|
|
454
454
|
await expect(await canvas.findByText('Last action: Dismissed')).toBeInTheDocument()
|
|
455
455
|
},
|
|
456
456
|
}
|
|
457
|
+
|
|
458
|
+
// --- Focus and Escape (5.2) ---
|
|
459
|
+
|
|
460
|
+
// dismissable only governs the backdrop: Escape still closes.
|
|
461
|
+
export const EscapeClosesNonDismissable: Story = {
|
|
462
|
+
render: () => (
|
|
463
|
+
<Dialog.Root dismissable={false}>
|
|
464
|
+
<Dialog.Trigger>
|
|
465
|
+
<Button>Open terms</Button>
|
|
466
|
+
</Dialog.Trigger>
|
|
467
|
+
<Dialog.Portal size="sm">
|
|
468
|
+
<Dialog.Header>
|
|
469
|
+
<Dialog.Title>Terms</Dialog.Title>
|
|
470
|
+
</Dialog.Header>
|
|
471
|
+
<Dialog.Body>
|
|
472
|
+
<Text>Read before continuing.</Text>
|
|
473
|
+
</Dialog.Body>
|
|
474
|
+
</Dialog.Portal>
|
|
475
|
+
</Dialog.Root>
|
|
476
|
+
),
|
|
477
|
+
play: async ({canvas, userEvent}) => {
|
|
478
|
+
const opener = canvas.getByRole('button', {name: 'Open terms'})
|
|
479
|
+
await userEvent.click(opener)
|
|
480
|
+
const dialog = await screen.findByRole('dialog', {name: 'Terms'})
|
|
481
|
+
// Nothing focusable inside: the dialog itself takes focus.
|
|
482
|
+
await waitFor(() => expect(dialog).toHaveFocus())
|
|
483
|
+
await userEvent.keyboard('{Escape}')
|
|
484
|
+
await waitFor(() => expect(screen.queryByRole('dialog')).not.toBeInTheDocument())
|
|
485
|
+
await waitFor(() => expect(opener).toHaveFocus())
|
|
486
|
+
},
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
function InitialFocusDemo() {
|
|
490
|
+
const nameRef = useRef<HTMLInputElement>(null)
|
|
491
|
+
return (
|
|
492
|
+
<Dialog.Root initialFocus={nameRef}>
|
|
493
|
+
<Dialog.Trigger>
|
|
494
|
+
<Button>Rename</Button>
|
|
495
|
+
</Dialog.Trigger>
|
|
496
|
+
<Dialog.Portal size="sm">
|
|
497
|
+
<Dialog.Header>
|
|
498
|
+
<Dialog.Title>Rename file</Dialog.Title>
|
|
499
|
+
<Dialog.Close />
|
|
500
|
+
</Dialog.Header>
|
|
501
|
+
<Dialog.Body>
|
|
502
|
+
<Field.Root>
|
|
503
|
+
<Field.Label>Name</Field.Label>
|
|
504
|
+
<Input ref={nameRef} defaultValue="notes.md" />
|
|
505
|
+
</Field.Root>
|
|
506
|
+
</Dialog.Body>
|
|
507
|
+
</Dialog.Portal>
|
|
508
|
+
</Dialog.Root>
|
|
509
|
+
)
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
export const InitialFocus: Story = {
|
|
513
|
+
render: () => <InitialFocusDemo />,
|
|
514
|
+
play: async ({canvas, userEvent}) => {
|
|
515
|
+
await userEvent.click(canvas.getByRole('button', {name: 'Rename'}))
|
|
516
|
+
const input = await screen.findByRole('textbox', {name: 'Name'})
|
|
517
|
+
await waitFor(() => expect(input).toHaveFocus())
|
|
518
|
+
},
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
export const FirstFocusableByDefault: Story = {
|
|
522
|
+
render: () => (
|
|
523
|
+
<Dialog.Root>
|
|
524
|
+
<Dialog.Trigger>
|
|
525
|
+
<Button>Open</Button>
|
|
526
|
+
</Dialog.Trigger>
|
|
527
|
+
<Dialog.Portal size="sm">
|
|
528
|
+
<Dialog.Header>
|
|
529
|
+
<Dialog.Title>Share</Dialog.Title>
|
|
530
|
+
<Dialog.Close aria-label="Close share" />
|
|
531
|
+
</Dialog.Header>
|
|
532
|
+
</Dialog.Portal>
|
|
533
|
+
</Dialog.Root>
|
|
534
|
+
),
|
|
535
|
+
play: async ({canvas, userEvent}) => {
|
|
536
|
+
await userEvent.click(canvas.getByRole('button', {name: 'Open'}))
|
|
537
|
+
const close = await screen.findByRole('button', {name: 'Close share'})
|
|
538
|
+
await waitFor(() => expect(close).toHaveFocus())
|
|
539
|
+
},
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
export const CloseOnEscapeOff: Story = {
|
|
543
|
+
render: () => (
|
|
544
|
+
<Dialog.Root defaultOpen closeOnEscape={false}>
|
|
545
|
+
<Dialog.Portal size="sm">
|
|
546
|
+
<Dialog.Header>
|
|
547
|
+
<Dialog.Title>Required step</Dialog.Title>
|
|
548
|
+
</Dialog.Header>
|
|
549
|
+
<Dialog.Footer>
|
|
550
|
+
<Dialog.Close>
|
|
551
|
+
<Button>Done</Button>
|
|
552
|
+
</Dialog.Close>
|
|
553
|
+
</Dialog.Footer>
|
|
554
|
+
</Dialog.Portal>
|
|
555
|
+
</Dialog.Root>
|
|
556
|
+
),
|
|
557
|
+
play: async ({userEvent}) => {
|
|
558
|
+
await screen.findByRole('dialog', {name: 'Required step'})
|
|
559
|
+
await userEvent.keyboard('{Escape}')
|
|
560
|
+
await expect(screen.getByRole('dialog', {name: 'Required step'})).toBeInTheDocument()
|
|
561
|
+
},
|
|
562
|
+
}
|
|
@@ -14,9 +14,15 @@ import {html} from 'react-strict-dom'
|
|
|
14
14
|
import {DURATION_MS, type DurationToken} from '@duro-app/tokens/keys'
|
|
15
15
|
import {styles} from './styles.css'
|
|
16
16
|
import {usePortalMount} from '../ThemeProvider/ThemeProvider'
|
|
17
|
+
import {ControlContextBoundary} from '../Toolbar/ControlContextBoundary'
|
|
18
|
+
import {ModalContext} from '../../shared/ModalContext'
|
|
19
|
+
import {devWarnOnce} from '../../shared/devWarnOnce'
|
|
17
20
|
|
|
18
21
|
// --- Types ---
|
|
19
22
|
|
|
23
|
+
const FOCUSABLE =
|
|
24
|
+
'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])'
|
|
25
|
+
|
|
20
26
|
export type DialogSize = 'sm' | 'md' | 'lg'
|
|
21
27
|
|
|
22
28
|
const closeDurationMap = {
|
|
@@ -41,6 +47,8 @@ interface DialogContextValue {
|
|
|
41
47
|
titleId: string
|
|
42
48
|
descriptionId: string
|
|
43
49
|
popupRef: RefObject<HTMLDivElement | null>
|
|
50
|
+
/** Dialog.Close parts currently rendered (for the closeOnEscape dev warning). */
|
|
51
|
+
registerClose: () => () => void
|
|
44
52
|
}
|
|
45
53
|
|
|
46
54
|
const DialogContext = createContext<DialogContextValue | null>(null)
|
|
@@ -61,8 +69,16 @@ interface RootProps {
|
|
|
61
69
|
defaultOpen?: boolean
|
|
62
70
|
/** Called when dialog open state changes */
|
|
63
71
|
onOpenChange?: (open: boolean) => void
|
|
64
|
-
/** Whether clicking backdrop closes the dialog. Default: true */
|
|
72
|
+
/** Whether clicking the backdrop closes the dialog. Default: true */
|
|
65
73
|
dismissable?: boolean
|
|
74
|
+
/**
|
|
75
|
+
* Whether Escape closes the dialog. Default: true, also when `dismissable`
|
|
76
|
+
* is false. Turning it off leaves the keyboard no way out but a
|
|
77
|
+
* Dialog.Close, so render one.
|
|
78
|
+
*/
|
|
79
|
+
closeOnEscape?: boolean
|
|
80
|
+
/** Element to focus on open. Default: the first focusable element, else the dialog itself. */
|
|
81
|
+
initialFocus?: RefObject<HTMLElement | null>
|
|
66
82
|
/** Motion token for the close animation. Default: 'fast' (150ms) */
|
|
67
83
|
closeAnimationDuration?: DurationToken
|
|
68
84
|
}
|
|
@@ -73,6 +89,8 @@ function Root({
|
|
|
73
89
|
defaultOpen = false,
|
|
74
90
|
onOpenChange,
|
|
75
91
|
dismissable = true,
|
|
92
|
+
closeOnEscape = true,
|
|
93
|
+
initialFocus,
|
|
76
94
|
closeAnimationDuration = 'fast',
|
|
77
95
|
}: RootProps) {
|
|
78
96
|
const isControlled = controlledOpen !== undefined
|
|
@@ -120,20 +138,55 @@ function Root({
|
|
|
120
138
|
}
|
|
121
139
|
}, [])
|
|
122
140
|
|
|
123
|
-
// Handle Escape key
|
|
141
|
+
// Handle Escape key. A layer inside the dialog (a Menu, a Select) that
|
|
142
|
+
// already handled it marks the event, and the dialog stays open.
|
|
124
143
|
useEffect(() => {
|
|
125
144
|
if (!isOpen && !closing) return
|
|
126
|
-
if (!
|
|
145
|
+
if (!closeOnEscape) return
|
|
127
146
|
|
|
128
147
|
function onKeyDown(e: KeyboardEvent) {
|
|
129
|
-
if (e.key
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
}
|
|
148
|
+
if (e.key !== 'Escape' || e.defaultPrevented) return
|
|
149
|
+
e.stopPropagation()
|
|
150
|
+
requestClose()
|
|
133
151
|
}
|
|
134
152
|
document.addEventListener('keydown', onKeyDown)
|
|
135
153
|
return () => document.removeEventListener('keydown', onKeyDown)
|
|
136
|
-
}, [isOpen, closing,
|
|
154
|
+
}, [isOpen, closing, closeOnEscape, requestClose])
|
|
155
|
+
|
|
156
|
+
// Focus: into the dialog on open (initialFocus, else the first focusable
|
|
157
|
+
// element, else the dialog itself), back to what had it on close. The
|
|
158
|
+
// Portal is a descendant, so its popup is mounted when this effect runs.
|
|
159
|
+
const closeCountRef = useRef(0)
|
|
160
|
+
const registerClose = useCallback(() => {
|
|
161
|
+
closeCountRef.current += 1
|
|
162
|
+
return () => {
|
|
163
|
+
closeCountRef.current -= 1
|
|
164
|
+
}
|
|
165
|
+
}, [])
|
|
166
|
+
const previousFocusRef = useRef<HTMLElement | null>(null)
|
|
167
|
+
const wasOpenRef = useRef(false)
|
|
168
|
+
useEffect(() => {
|
|
169
|
+
if (isOpen && !wasOpenRef.current) {
|
|
170
|
+
previousFocusRef.current = document.activeElement as HTMLElement | null
|
|
171
|
+
const popup = popupRef.current
|
|
172
|
+
if (popup) {
|
|
173
|
+
const target = initialFocus?.current ?? popup.querySelector<HTMLElement>(FOCUSABLE) ?? popup
|
|
174
|
+
target.focus({preventScroll: true})
|
|
175
|
+
}
|
|
176
|
+
if (!closeOnEscape && closeCountRef.current === 0) {
|
|
177
|
+
devWarnOnce(
|
|
178
|
+
'Dialog',
|
|
179
|
+
'no-escape-no-close',
|
|
180
|
+
'Dialog.Root has closeOnEscape={false} and no Dialog.Close: a keyboard user cannot leave this dialog. Render a Dialog.Close, or keep Escape.',
|
|
181
|
+
)
|
|
182
|
+
}
|
|
183
|
+
} else if (!isOpen && !closing && wasOpenRef.current) {
|
|
184
|
+
const target = previousFocusRef.current
|
|
185
|
+
previousFocusRef.current = null
|
|
186
|
+
if (target?.isConnected) target.focus({preventScroll: true})
|
|
187
|
+
}
|
|
188
|
+
wasOpenRef.current = isOpen || closing
|
|
189
|
+
}, [isOpen, closing, initialFocus, closeOnEscape])
|
|
137
190
|
|
|
138
191
|
// Lock body scroll when open
|
|
139
192
|
useEffect(() => {
|
|
@@ -158,6 +211,7 @@ function Root({
|
|
|
158
211
|
titleId,
|
|
159
212
|
descriptionId,
|
|
160
213
|
popupRef,
|
|
214
|
+
registerClose,
|
|
161
215
|
}}
|
|
162
216
|
>
|
|
163
217
|
{children}
|
|
@@ -229,6 +283,7 @@ function Portal({children, size = 'md'}: PortalProps) {
|
|
|
229
283
|
ref={popupRef}
|
|
230
284
|
role="dialog"
|
|
231
285
|
aria-modal={true}
|
|
286
|
+
tabIndex={-1}
|
|
232
287
|
aria-labelledby={titleId}
|
|
233
288
|
aria-describedby={descriptionId}
|
|
234
289
|
style={[
|
|
@@ -239,7 +294,9 @@ function Portal({children, size = 'md'}: PortalProps) {
|
|
|
239
294
|
!closing && styles.popupOpen,
|
|
240
295
|
]}
|
|
241
296
|
>
|
|
242
|
-
{
|
|
297
|
+
<ModalContext.Provider value={true}>
|
|
298
|
+
<ControlContextBoundary>{children}</ControlContextBoundary>
|
|
299
|
+
</ModalContext.Provider>
|
|
243
300
|
</html.div>
|
|
244
301
|
</html.div>
|
|
245
302
|
</>
|
|
@@ -301,7 +358,8 @@ interface CloseProps {
|
|
|
301
358
|
}
|
|
302
359
|
|
|
303
360
|
function Close({children, 'aria-label': ariaLabel = 'Close'}: CloseProps) {
|
|
304
|
-
const {requestClose} = useDialog()
|
|
361
|
+
const {requestClose, registerClose} = useDialog()
|
|
362
|
+
useEffect(() => registerClose(), [registerClose])
|
|
305
363
|
|
|
306
364
|
if (children) {
|
|
307
365
|
return (
|
|
@@ -6,6 +6,7 @@ import {shadows} from '@duro-app/tokens/tokens/shadows.css'
|
|
|
6
6
|
import {duration, easing} from '@duro-app/tokens/tokens/motion.css'
|
|
7
7
|
import {sizes} from '@duro-app/tokens/tokens/sizes.css'
|
|
8
8
|
import {borders} from '@duro-app/tokens/tokens/borders.css'
|
|
9
|
+
import {layers} from '@duro-app/tokens/tokens/layers.css'
|
|
9
10
|
|
|
10
11
|
export const styles = css.create({
|
|
11
12
|
// --- Backdrop ---
|
|
@@ -13,7 +14,7 @@ export const styles = css.create({
|
|
|
13
14
|
position: 'fixed',
|
|
14
15
|
inset: 0,
|
|
15
16
|
backgroundColor: colors.scrim,
|
|
16
|
-
zIndex:
|
|
17
|
+
zIndex: layers.overlay,
|
|
17
18
|
// Portaled into the ThemeProvider mount, which is pointer-events: none:
|
|
18
19
|
// the backdrop must take clicks back (outside click dismisses).
|
|
19
20
|
pointerEvents: 'auto',
|
|
@@ -43,7 +44,7 @@ export const styles = css.create({
|
|
|
43
44
|
viewport: {
|
|
44
45
|
position: 'fixed',
|
|
45
46
|
inset: 0,
|
|
46
|
-
zIndex:
|
|
47
|
+
zIndex: layers.modal,
|
|
47
48
|
display: 'flex',
|
|
48
49
|
alignItems: 'center',
|
|
49
50
|
justifyContent: 'center',
|
|
@@ -64,6 +65,8 @@ export const styles = css.create({
|
|
|
64
65
|
flexDirection: 'column',
|
|
65
66
|
overflow: 'hidden',
|
|
66
67
|
pointerEvents: 'auto',
|
|
68
|
+
// Focused only as the fallback when it holds nothing focusable.
|
|
69
|
+
outlineStyle: 'none',
|
|
67
70
|
borderWidth: borders.hairline,
|
|
68
71
|
borderStyle: 'solid',
|
|
69
72
|
borderColor: colors.border,
|
|
@@ -8,8 +8,10 @@ import {
|
|
|
8
8
|
useState,
|
|
9
9
|
type ReactNode,
|
|
10
10
|
} from 'react'
|
|
11
|
+
import {createPortal} from 'react-dom'
|
|
11
12
|
import {html} from 'react-strict-dom'
|
|
12
13
|
import {styles} from './styles.css'
|
|
14
|
+
import {usePortalMount} from '../ThemeProvider/ThemeProvider'
|
|
13
15
|
import {isNative} from '../../platform'
|
|
14
16
|
import {visuallyHidden} from '../../styles/visually-hidden.css'
|
|
15
17
|
|
|
@@ -343,6 +345,18 @@ function Root<T = unknown>({onDrop, announce, children}: DragDropRootProps<T>) {
|
|
|
343
345
|
}
|
|
344
346
|
}, [activate, finish, locate])
|
|
345
347
|
|
|
348
|
+
// The ghost renders in the ThemeProvider mount: inline, a Dialog's
|
|
349
|
+
// transformed, overflow-clipped panel would clip and offset it.
|
|
350
|
+
const mount = usePortalMount()
|
|
351
|
+
const ghost = drag && (
|
|
352
|
+
<html.div
|
|
353
|
+
aria-hidden
|
|
354
|
+
style={[styles.ghost, styles.ghostAt(drag.x, drag.y, drag.width, drag.height)]}
|
|
355
|
+
>
|
|
356
|
+
{drag.preview}
|
|
357
|
+
</html.div>
|
|
358
|
+
)
|
|
359
|
+
|
|
346
360
|
const value = useMemo<RootContextValue>(
|
|
347
361
|
() => ({registerZone, registerItem, begin, drag}),
|
|
348
362
|
[registerZone, registerItem, begin, drag],
|
|
@@ -351,14 +365,7 @@ function Root<T = unknown>({onDrop, announce, children}: DragDropRootProps<T>) {
|
|
|
351
365
|
return (
|
|
352
366
|
<RootContext.Provider value={value}>
|
|
353
367
|
{children}
|
|
354
|
-
{
|
|
355
|
-
<html.div
|
|
356
|
-
aria-hidden
|
|
357
|
-
style={[styles.ghost, styles.ghostAt(drag.x, drag.y, drag.width, drag.height)]}
|
|
358
|
-
>
|
|
359
|
-
{drag.preview}
|
|
360
|
-
</html.div>
|
|
361
|
-
)}
|
|
368
|
+
{ghost && (mount ? createPortal(ghost, mount) : ghost)}
|
|
362
369
|
<html.div role="status" aria-live="polite" aria-atomic style={visuallyHidden.base}>
|
|
363
370
|
{announcement}
|
|
364
371
|
</html.div>
|
|
@@ -2,6 +2,9 @@ import {css} from 'react-strict-dom'
|
|
|
2
2
|
import {colors} from '@duro-app/tokens/tokens/colors.css'
|
|
3
3
|
import {radii} from '@duro-app/tokens/tokens/spacing.css'
|
|
4
4
|
import {duration, easing} from '@duro-app/tokens/tokens/motion.css'
|
|
5
|
+
import {shadows} from '@duro-app/tokens/tokens/shadows.css'
|
|
6
|
+
import {borders} from '@duro-app/tokens/tokens/borders.css'
|
|
7
|
+
import {layers} from '@duro-app/tokens/tokens/layers.css'
|
|
5
8
|
|
|
6
9
|
export const styles = css.create({
|
|
7
10
|
// The item is the drag handle: no browser panning starts on it, so a touch
|
|
@@ -30,20 +33,33 @@ export const styles = css.create({
|
|
|
30
33
|
transitionTimingFunction: easing.standard,
|
|
31
34
|
},
|
|
32
35
|
// Every zone shows it can receive while something is in the air; the one
|
|
33
|
-
// under the pointer lights up.
|
|
36
|
+
// under the pointer lights up. Drop-target rings, not focus: keyboard focus
|
|
37
|
+
// stays on outlines, which survive forced-colors mode.
|
|
38
|
+
// Forced-colors mode drops box-shadows and fills; the transparent outline
|
|
39
|
+
// is what it paints instead (in a system colour), so the rings survive.
|
|
34
40
|
zoneReady: {
|
|
35
|
-
boxShadow:
|
|
41
|
+
boxShadow: shadows.dropReady,
|
|
42
|
+
outlineStyle: 'solid',
|
|
43
|
+
outlineWidth: borders.hairline,
|
|
44
|
+
outlineColor: 'transparent',
|
|
45
|
+
outlineOffset: `calc(-1 * ${borders.hairline})`,
|
|
36
46
|
},
|
|
37
47
|
zoneOver: {
|
|
38
|
-
boxShadow:
|
|
48
|
+
boxShadow: shadows.dropOver,
|
|
39
49
|
backgroundColor: colors.infoBg,
|
|
50
|
+
outlineStyle: 'solid',
|
|
51
|
+
outlineWidth: borders.strong,
|
|
52
|
+
outlineColor: 'transparent',
|
|
53
|
+
outlineOffset: `calc(-1 * ${borders.strong})`,
|
|
40
54
|
},
|
|
41
55
|
ghost: {
|
|
42
56
|
position: 'fixed',
|
|
43
57
|
top: 0,
|
|
44
58
|
left: 0,
|
|
45
59
|
pointerEvents: 'none',
|
|
46
|
-
|
|
60
|
+
// Portalled into the ThemeProvider mount, where it must clear a Dialog
|
|
61
|
+
// or Drawer the drag happens in.
|
|
62
|
+
zIndex: layers.popup,
|
|
47
63
|
opacity: 0.9,
|
|
48
64
|
cursor: 'grabbing',
|
|
49
65
|
},
|