@mrpelz/uikit-ish 7.8.0 → 7.10.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/accordion/main.d.ts +12 -0
- package/dist/components/accordion/main.d.ts.map +1 -0
- package/dist/components/accordion/main.js +20 -0
- package/dist/components/accordion/main.js.map +1 -0
- package/dist/components/accordion/style.css +23 -0
- package/dist/components/action-sheet/main.d.ts +22 -16
- package/dist/components/action-sheet/main.d.ts.map +1 -1
- package/dist/components/action-sheet/main.js +89 -19
- package/dist/components/action-sheet/main.js.map +1 -1
- package/dist/components/action-sheet/props.d.ts +17 -5
- package/dist/components/action-sheet/props.d.ts.map +1 -1
- package/dist/components/action-sheet/style.css +24 -0
- package/dist/components/activity-view/main.d.ts +15 -4
- package/dist/components/activity-view/main.d.ts.map +1 -1
- package/dist/components/activity-view/main.js +27 -14
- package/dist/components/activity-view/main.js.map +1 -1
- package/dist/components/activity-view/props.d.ts +2 -10
- package/dist/components/activity-view/props.d.ts.map +1 -1
- package/dist/components/activity-view/style.css +29 -67
- package/dist/components/alert/main.d.ts +8 -7
- package/dist/components/alert/main.d.ts.map +1 -1
- package/dist/components/alert/main.js +32 -19
- package/dist/components/alert/main.js.map +1 -1
- package/dist/components/alert/props.d.ts +13 -2
- package/dist/components/alert/props.d.ts.map +1 -1
- package/dist/components/alert/style.css +36 -50
- package/dist/components/avatar/main.d.ts +5 -3
- package/dist/components/avatar/main.d.ts.map +1 -1
- package/dist/components/avatar/main.js +10 -8
- package/dist/components/avatar/main.js.map +1 -1
- package/dist/components/avatar/props.d.ts +4 -0
- package/dist/components/avatar/props.d.ts.map +1 -1
- package/dist/components/avatar/style.css +1 -7
- package/dist/components/badge/main.d.ts +3 -3
- package/dist/components/badge/main.d.ts.map +1 -1
- package/dist/components/badge/main.js +9 -9
- package/dist/components/badge/main.js.map +1 -1
- package/dist/components/badge/props.d.ts +4 -3
- package/dist/components/badge/props.d.ts.map +1 -1
- package/dist/components/badge/style.css +10 -4
- package/dist/components/button/main.d.ts.map +1 -1
- package/dist/components/button/main.js +15 -15
- package/dist/components/button/main.js.map +1 -1
- package/dist/components/button/props.d.ts +8 -8
- package/dist/components/button/props.d.ts.map +1 -1
- package/dist/components/button/style.css +37 -55
- package/dist/components/checkbox/main.d.ts.map +1 -1
- package/dist/components/checkbox/main.js +5 -7
- package/dist/components/checkbox/main.js.map +1 -1
- package/dist/components/checkbox/style.css +5 -8
- package/dist/components/collapsible/main.d.ts +9 -0
- package/dist/components/collapsible/main.d.ts.map +1 -0
- package/dist/components/collapsible/main.js +19 -0
- package/dist/components/collapsible/main.js.map +1 -0
- package/dist/components/collapsible/style.css +23 -0
- package/dist/components/color-picker/main.d.ts +27 -4
- package/dist/components/color-picker/main.d.ts.map +1 -1
- package/dist/components/color-picker/main.js +292 -110
- package/dist/components/color-picker/main.js.map +1 -1
- package/dist/components/color-picker/props.d.ts +64 -15
- package/dist/components/color-picker/props.d.ts.map +1 -1
- package/dist/components/color-picker/style.css +133 -65
- package/dist/components/contextual-menu/main.d.ts +11 -7
- package/dist/components/contextual-menu/main.d.ts.map +1 -1
- package/dist/components/contextual-menu/main.js +207 -202
- package/dist/components/contextual-menu/main.js.map +1 -1
- package/dist/components/contextual-menu/props.d.ts +21 -34
- package/dist/components/contextual-menu/props.d.ts.map +1 -1
- package/dist/components/contextual-menu/style.css +63 -34
- package/dist/components/date-picker/handle.d.ts +41 -0
- package/dist/components/date-picker/handle.d.ts.map +1 -0
- package/dist/components/date-picker/handle.js +47 -0
- package/dist/components/date-picker/handle.js.map +1 -0
- package/dist/components/date-picker/main.d.ts +31 -49
- package/dist/components/date-picker/main.d.ts.map +1 -1
- package/dist/components/date-picker/main.js +373 -178
- package/dist/components/date-picker/main.js.map +1 -1
- package/dist/components/date-picker/pager.d.ts +24 -0
- package/dist/components/date-picker/pager.d.ts.map +1 -0
- package/dist/components/date-picker/pager.js +307 -0
- package/dist/components/date-picker/pager.js.map +1 -0
- package/dist/components/date-picker/props.d.ts +98 -27
- package/dist/components/date-picker/props.d.ts.map +1 -1
- package/dist/components/date-picker/style.css +110 -118
- package/dist/components/drawer/main.d.ts +31 -0
- package/dist/components/drawer/main.d.ts.map +1 -0
- package/dist/components/drawer/main.js +119 -0
- package/dist/components/drawer/main.js.map +1 -0
- package/dist/components/drawer/props.d.ts +39 -0
- package/dist/components/drawer/props.d.ts.map +1 -0
- package/dist/components/drawer/props.js +2 -0
- package/dist/components/drawer/props.js.map +1 -0
- package/dist/components/drawer/style.css +135 -0
- package/dist/components/edit-menu/main.d.ts +7 -7
- package/dist/components/edit-menu/main.d.ts.map +1 -1
- package/dist/components/edit-menu/main.js +57 -40
- package/dist/components/edit-menu/main.js.map +1 -1
- package/dist/components/edit-menu/props.d.ts +14 -1
- package/dist/components/edit-menu/props.d.ts.map +1 -1
- package/dist/components/edit-menu/style.css +15 -8
- package/dist/components/form/main.d.ts +8 -0
- package/dist/components/form/main.d.ts.map +1 -1
- package/dist/components/form/main.js +18 -5
- package/dist/components/form/main.js.map +1 -1
- package/dist/components/form/props.d.ts +1 -2
- package/dist/components/form/props.d.ts.map +1 -1
- package/dist/components/glass/main.d.ts +1 -1
- package/dist/components/glass/main.js +4 -4
- package/dist/components/glass/main.js.map +1 -1
- package/dist/components/glass/props.d.ts +5 -5
- package/dist/components/glass/props.d.ts.map +1 -1
- package/dist/components/glass/style.css +176 -161
- package/dist/components/header/main.d.ts +5 -4
- package/dist/components/header/main.d.ts.map +1 -1
- package/dist/components/header/main.js +64 -34
- package/dist/components/header/main.js.map +1 -1
- package/dist/components/header/props.d.ts +2 -3
- package/dist/components/header/props.d.ts.map +1 -1
- package/dist/components/header/style.css +46 -65
- package/dist/components/index.d.ts +27 -23
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +17 -13
- package/dist/components/index.js.map +1 -1
- package/dist/components/layout/main.d.ts +2 -2
- package/dist/components/layout/main.d.ts.map +1 -1
- package/dist/components/layout/main.js +63 -167
- package/dist/components/layout/main.js.map +1 -1
- package/dist/components/layout/props.d.ts +2 -20
- package/dist/components/layout/props.d.ts.map +1 -1
- package/dist/components/layout/style.css +20 -91
- package/dist/components/list/main.d.ts +58 -10
- package/dist/components/list/main.d.ts.map +1 -1
- package/dist/components/list/main.js +1022 -465
- package/dist/components/list/main.js.map +1 -1
- package/dist/components/list/props.d.ts +211 -21
- package/dist/components/list/props.d.ts.map +1 -1
- package/dist/components/list/reorder.d.ts +146 -0
- package/dist/components/list/reorder.d.ts.map +1 -0
- package/dist/components/list/reorder.js +819 -0
- package/dist/components/list/reorder.js.map +1 -0
- package/dist/components/list/select.d.ts +6 -0
- package/dist/components/list/select.d.ts.map +1 -0
- package/dist/components/list/select.js +141 -0
- package/dist/components/list/select.js.map +1 -0
- package/dist/components/list/style.css +492 -507
- package/dist/components/list/swipe-actions-handle.d.ts +40 -0
- package/dist/components/list/swipe-actions-handle.d.ts.map +1 -0
- package/dist/components/list/swipe-actions-handle.js +51 -0
- package/dist/components/list/swipe-actions-handle.js.map +1 -0
- package/dist/components/menu/main.d.ts +102 -32
- package/dist/components/menu/main.d.ts.map +1 -1
- package/dist/components/menu/main.js +510 -99
- package/dist/components/menu/main.js.map +1 -1
- package/dist/components/menu/props.d.ts +5 -5
- package/dist/components/menu/props.d.ts.map +1 -1
- package/dist/components/menu/style.css +35 -43
- package/dist/components/navigation/main.d.ts +14 -2
- package/dist/components/navigation/main.d.ts.map +1 -1
- package/dist/components/navigation/main.js +437 -119
- package/dist/components/navigation/main.js.map +1 -1
- package/dist/components/navigation/props.d.ts +53 -3
- package/dist/components/navigation/props.d.ts.map +1 -1
- package/dist/components/navigation/style.css +56 -9
- package/dist/components/page/main.d.ts.map +1 -1
- package/dist/components/page/main.js +13 -8
- package/dist/components/page/main.js.map +1 -1
- package/dist/components/page/props.d.ts +8 -0
- package/dist/components/page/props.d.ts.map +1 -1
- package/dist/components/page/style.css +39 -4
- package/dist/components/page-control/main.d.ts +2 -2
- package/dist/components/page-control/main.d.ts.map +1 -1
- package/dist/components/page-control/main.js +66 -32
- package/dist/components/page-control/main.js.map +1 -1
- package/dist/components/page-control/props.d.ts +10 -2
- package/dist/components/page-control/props.d.ts.map +1 -1
- package/dist/components/page-control/style.css +7 -2
- package/dist/components/popover/main.d.ts +11 -6
- package/dist/components/popover/main.d.ts.map +1 -1
- package/dist/components/popover/main.js +63 -38
- package/dist/components/popover/main.js.map +1 -1
- package/dist/components/popover/props.d.ts +7 -6
- package/dist/components/popover/props.d.ts.map +1 -1
- package/dist/components/popover/style.css +54 -4
- package/dist/components/progress/main.d.ts +2 -3
- package/dist/components/progress/main.d.ts.map +1 -1
- package/dist/components/progress/main.js +148 -29
- package/dist/components/progress/main.js.map +1 -1
- package/dist/components/progress/props.d.ts +43 -9
- package/dist/components/progress/props.d.ts.map +1 -1
- package/dist/components/progress/style.css +82 -50
- package/dist/components/roll/main.d.ts +1 -1
- package/dist/components/roll/main.d.ts.map +1 -1
- package/dist/components/roll/main.js +90 -34
- package/dist/components/roll/main.js.map +1 -1
- package/dist/components/roll/props.d.ts +25 -8
- package/dist/components/roll/props.d.ts.map +1 -1
- package/dist/components/roll/style.css +12 -24
- package/dist/components/segmented/main.d.ts.map +1 -1
- package/dist/components/segmented/main.js +47 -30
- package/dist/components/segmented/main.js.map +1 -1
- package/dist/components/segmented/style.css +16 -23
- package/dist/components/sheet/main.d.ts +25 -15
- package/dist/components/sheet/main.d.ts.map +1 -1
- package/dist/components/sheet/main.js +66 -78
- package/dist/components/sheet/main.js.map +1 -1
- package/dist/components/sheet/props.d.ts +37 -3
- package/dist/components/sheet/props.d.ts.map +1 -1
- package/dist/components/sheet/style.css +183 -45
- package/dist/components/sidebar/main.d.ts.map +1 -1
- package/dist/components/sidebar/main.js +9 -13
- package/dist/components/sidebar/main.js.map +1 -1
- package/dist/components/sidebar/style.css +20 -14
- package/dist/components/slider/main.d.ts.map +1 -1
- package/dist/components/slider/main.js +23 -22
- package/dist/components/slider/main.js.map +1 -1
- package/dist/components/slider/props.d.ts +1 -2
- package/dist/components/slider/props.d.ts.map +1 -1
- package/dist/components/slider/style.css +27 -53
- package/dist/components/stepper/main.d.ts +4 -6
- package/dist/components/stepper/main.d.ts.map +1 -1
- package/dist/components/stepper/main.js +29 -25
- package/dist/components/stepper/main.js.map +1 -1
- package/dist/components/stepper/style.css +12 -16
- package/dist/components/switch/main.d.ts.map +1 -1
- package/dist/components/switch/main.js +40 -28
- package/dist/components/switch/main.js.map +1 -1
- package/dist/components/switch/props.d.ts +7 -5
- package/dist/components/switch/props.d.ts.map +1 -1
- package/dist/components/switch/style.css +40 -17
- package/dist/components/symbol/main.d.ts +2 -2
- package/dist/components/symbol/main.d.ts.map +1 -1
- package/dist/components/symbol/main.js +36 -28
- package/dist/components/symbol/main.js.map +1 -1
- package/dist/components/symbol/props.d.ts +39 -4
- package/dist/components/symbol/props.d.ts.map +1 -1
- package/dist/components/symbol/style.css +26 -5
- package/dist/components/tab-bar/main.d.ts +2 -2
- package/dist/components/tab-bar/main.d.ts.map +1 -1
- package/dist/components/tab-bar/main.js +133 -101
- package/dist/components/tab-bar/main.js.map +1 -1
- package/dist/components/tab-bar/props.d.ts +6 -6
- package/dist/components/tab-bar/props.d.ts.map +1 -1
- package/dist/components/tab-bar/style.css +113 -99
- package/dist/components/text-field/main.d.ts +3 -2
- package/dist/components/text-field/main.d.ts.map +1 -1
- package/dist/components/text-field/main.js +29 -30
- package/dist/components/text-field/main.js.map +1 -1
- package/dist/components/text-field/props.d.ts +23 -1
- package/dist/components/text-field/props.d.ts.map +1 -1
- package/dist/components/text-field/style.css +122 -82
- package/dist/components/toolbar/main.js +27 -27
- package/dist/components/toolbar/main.js.map +1 -1
- package/dist/components/toolbar/props.d.ts +10 -4
- package/dist/components/toolbar/props.d.ts.map +1 -1
- package/dist/components/toolbar/style.css +39 -33
- package/dist/components/tooltip/main.d.ts +10 -9
- package/dist/components/tooltip/main.d.ts.map +1 -1
- package/dist/components/tooltip/main.js +39 -10
- package/dist/components/tooltip/main.js.map +1 -1
- package/dist/components/tooltip/props.d.ts +2 -0
- package/dist/components/tooltip/props.d.ts.map +1 -1
- package/dist/components/tooltip/style.css +16 -16
- package/dist/components/typography/main.d.ts +2 -2
- package/dist/components/typography/main.d.ts.map +1 -1
- package/dist/components/typography/main.js +24 -16
- package/dist/components/typography/main.js.map +1 -1
- package/dist/components/typography/props.d.ts +11 -18
- package/dist/components/typography/props.d.ts.map +1 -1
- package/dist/components/typography/style.css +503 -623
- package/dist/components/utils/main.d.ts +78 -8
- package/dist/components/utils/main.d.ts.map +1 -1
- package/dist/components/utils/main.js +235 -16
- package/dist/components/utils/main.js.map +1 -1
- package/dist/components/utils/props.d.ts +27 -4
- package/dist/components/utils/props.d.ts.map +1 -1
- package/dist/components/utils/style.css +31 -18
- package/dist/components/viewport/edge-effect.d.ts +10 -0
- package/dist/components/viewport/edge-effect.d.ts.map +1 -0
- package/dist/components/viewport/edge-effect.js +100 -0
- package/dist/components/viewport/edge-effect.js.map +1 -0
- package/dist/components/viewport/edge.d.ts +39 -0
- package/dist/components/viewport/edge.d.ts.map +1 -0
- package/dist/components/viewport/edge.js +151 -0
- package/dist/components/viewport/edge.js.map +1 -0
- package/dist/components/viewport/input.d.ts +39 -0
- package/dist/components/viewport/input.d.ts.map +1 -0
- package/dist/components/viewport/input.js +280 -0
- package/dist/components/viewport/input.js.map +1 -0
- package/dist/components/viewport/main.d.ts +47 -9
- package/dist/components/viewport/main.d.ts.map +1 -1
- package/dist/components/viewport/main.js +745 -86
- package/dist/components/viewport/main.js.map +1 -1
- package/dist/components/viewport/padding.d.ts +78 -0
- package/dist/components/viewport/padding.d.ts.map +1 -0
- package/dist/components/viewport/padding.js +321 -0
- package/dist/components/viewport/padding.js.map +1 -0
- package/dist/components/viewport/props.d.ts +220 -11
- package/dist/components/viewport/props.d.ts.map +1 -1
- package/dist/components/viewport/style.css +377 -6
- package/dist/main.d.ts +0 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js.map +1 -1
- package/dist/styles.css +318 -302
- package/dist/styles.d.ts +2 -1
- package/dist/styles.d.ts.map +1 -1
- package/dist/styles.js +2 -1
- package/dist/styles.js.map +1 -1
- package/package.json +8 -16
|
@@ -3,25 +3,29 @@ import '../checkbox/style.css';
|
|
|
3
3
|
import '../typography/style.css';
|
|
4
4
|
import './style.css';
|
|
5
5
|
import { useRender } from '@base-ui/react/use-render';
|
|
6
|
-
import { createContext, forwardRef, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState, } from 'react';
|
|
6
|
+
import { createContext, forwardRef, useCallback, useContext, useEffect, useId, useLayoutEffect, useMemo, useRef, useState, } from 'react';
|
|
7
7
|
import { createPortal } from 'react-dom';
|
|
8
8
|
import { Check, Checkbox as CheckboxBase, Radio as RadioBase, } from '../checkbox/main.js';
|
|
9
|
-
import { cn,
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
//
|
|
16
|
-
//
|
|
17
|
-
//
|
|
18
|
-
//
|
|
19
|
-
//
|
|
20
|
-
//
|
|
21
|
-
//
|
|
22
|
-
//
|
|
23
|
-
// -
|
|
24
|
-
//
|
|
9
|
+
import { cn, useForwardedRef, usePointerDrag, useSecondaryClick, withStyle, } from '../utils/main.js';
|
|
10
|
+
import { createReorderHandle, ListReorderHandle, reorder, reorderByKey, setItemEntry, startReorderDrag, } from './reorder.js';
|
|
11
|
+
import { dragToSelect } from './select.js';
|
|
12
|
+
import { createSwipeActionsHandle } from './swipe-actions-handle.js';
|
|
13
|
+
export { ListReorderHandle, useCreateReorderHandle, } from './reorder.js';
|
|
14
|
+
export { ListSwipeActionsHandle, useCreateSwipeActionsHandle, } from './swipe-actions-handle.js';
|
|
15
|
+
// Rows (regular and tall), images, trailing accessories, edit buttons,
|
|
16
|
+
// grabbers, separators, button rows, swipe actions, headers (with trailing
|
|
17
|
+
// accessories), section titles, grouped footers and an index bar, in the
|
|
18
|
+
// semantic colors (the tint, the label colors, `systemRed`,
|
|
19
|
+
// `systemGray2`/`3`/`5`); the separator is a token in `styles.css`. Behavior
|
|
20
|
+
// after Framework7 (`list.less`, `list-ios.less`, `list-vars.less`,
|
|
21
|
+
// `swipeout.less`, `swipeout-ios.less`, `swipeout.js`, `list-index.less`,
|
|
22
|
+
// `block.less`):
|
|
23
|
+
// - list styles: `insetGrouped` (the default: 16px inset, 24px corners),
|
|
24
|
+
// `grouped`, `plain` (Framework7 `.list`, `.list.inset`); 35px between
|
|
25
|
+
// sections (none at the list's ends: its neighbors' and container's
|
|
26
|
+
// spacing); optionally outlined (`.list-outline`)
|
|
27
|
+
// - pressed rows (`systemGray4`), hiding the separators around pressed and
|
|
28
|
+
// swiped rows
|
|
25
29
|
// - swiping: the row follows the pointer (rubber-banding past its actions) over
|
|
26
30
|
// its actions, pinned to the list's edge, which scale in one after another
|
|
27
31
|
// from the edge; it opens on releasing past half the actions, or on a quick
|
|
@@ -30,63 +34,68 @@ import { cn, edgeScrollDelta, frameElapsed, useForwardedRef, usePointerDrag, use
|
|
|
30
34
|
// others, which follow the row, and arms overswiping (see `armDistance`;
|
|
31
35
|
// Framework7: past 1.2 times the actions), triggering it on release; armed,
|
|
32
36
|
// its symbol moves to the row's end, its label hides (150ms)
|
|
33
|
-
// - reordering rows by their grabbers (`sortable.js`, see `
|
|
37
|
+
// - reordering rows by their grabbers (`sortable.js`, see `reorder.ts`),
|
|
34
38
|
// independent of the leading edit controls (`Checkbox`, `Radio`,
|
|
35
|
-
// `EditButton`)
|
|
36
|
-
//
|
|
39
|
+
// `EditButton`); entering and leaving edit mode (`Root` `editing`), they
|
|
40
|
+
// slide in and out from the rows' edges (300ms), the rows' content making
|
|
41
|
+
// room
|
|
42
|
+
// - media rows, as in a mail app (`.media-list`: a `Text` part)
|
|
37
43
|
// - the Content Block (`Block`)
|
|
38
44
|
//
|
|
39
45
|
// Titles, subtitles and details are in the Body and Subheadline text styles,
|
|
40
46
|
// prominent headers in Title 3 Emphasized, index letters in Caption 1
|
|
41
|
-
// Emphasized;
|
|
47
|
+
// Emphasized; nested and extra prominent headers, header subtitles and
|
|
42
48
|
// details, footers and swipe action labels differ from the text styles in
|
|
43
|
-
// tracking
|
|
49
|
+
// tracking.
|
|
44
50
|
//
|
|
45
51
|
// Rows are grids: [edit control] [image] title/subtitle [trailing …], where
|
|
46
52
|
// everything that is not a leading part, a title or a subtitle is trailing
|
|
47
|
-
// (
|
|
48
|
-
//
|
|
49
|
-
//
|
|
50
|
-
//
|
|
51
|
-
//
|
|
52
|
-
//
|
|
53
|
-
// trailing controls.
|
|
53
|
+
// (16px apart), e.g. a `Switch` or a `Menu` trigger; up to 36px high (e.g. a
|
|
54
|
+
// `Stepper` or `Segmented`), they fit regular rows (8px from their edges).
|
|
55
|
+
// Rows with a subtitle are tall (68px); others are regular (52px). Both are
|
|
56
|
+
// minimum heights, growing with wrapping text. A row is pressable when its
|
|
57
|
+
// `Title` (or `Button`) is a link or button (`render`): its hit area covers
|
|
58
|
+
// the row, beneath the trailing controls.
|
|
54
59
|
//
|
|
55
|
-
//
|
|
56
|
-
// - Focusing a swipe action opens the actions
|
|
57
|
-
// the
|
|
58
|
-
//
|
|
59
|
-
//
|
|
60
|
-
// - Sticky section titles (plain lists) are opaque (Framework7 contacts
|
|
61
|
-
//
|
|
62
|
-
//
|
|
63
|
-
// - Images keep their regular size (one line's height) in tall rows
|
|
64
|
-
//
|
|
65
|
-
//
|
|
66
|
-
// (Figma: a capsule, which would cut into their content).
|
|
60
|
+
// Also:
|
|
61
|
+
// - Focusing a swipe action opens the actions. A trigger opens them
|
|
62
|
+
// (`SwipeActionsTrigger`: in the row, or by a handle; e.g. rendering the
|
|
63
|
+
// delete edit button), not the edit button itself.
|
|
64
|
+
// - Header and footer text is aligned with the rows' text.
|
|
65
|
+
// - Sticky section titles (plain lists) are opaque (Framework7 contacts
|
|
66
|
+
// list), and sections snap to the top of a scroll container with
|
|
67
|
+
// `scroll-snap-type` (Framework7: none).
|
|
68
|
+
// - Images keep their regular size (one line's height) in tall rows.
|
|
69
|
+
// - Swiped rows taller than tall rows (e.g. a mail app's) get 34px corners (a
|
|
70
|
+
// capsule would cut into their content).
|
|
67
71
|
// - Swiped rows keep a round end at their place's edge, their content sliding
|
|
68
|
-
// away beneath it
|
|
69
|
-
// - Swipe actions are 44px circles, 4px from a regular row's edges
|
|
70
|
-
//
|
|
71
|
-
//
|
|
72
|
-
//
|
|
73
|
-
//
|
|
74
|
-
//
|
|
75
|
-
// -
|
|
76
|
-
//
|
|
77
|
-
// - Rounded and circular images size their symbol to the image (Figma: none
|
|
78
|
-
// given); header buttons are round (Figma PNG; CSS: 10px corners).
|
|
72
|
+
// away beneath it.
|
|
73
|
+
// - Swipe actions are 44px circles, 4px from a regular row's edges, or
|
|
74
|
+
// rounded rectangles as high as the row (as notifications'), by action;
|
|
75
|
+
// labels are optional (for multi-line rows), 4px below the shapes, in 13px.
|
|
76
|
+
// Symbols can be text, in capitals (regular weight).
|
|
77
|
+
// - Actions fade in as they scale in, and the others fade out while
|
|
78
|
+
// overswiping.
|
|
79
|
+
// - Rounded and circular images size their symbol to the image; header
|
|
80
|
+
// buttons are round.
|
|
79
81
|
// - Separators, chevrons and the checkmarks are drawn as CSS borders and SVG
|
|
80
|
-
// strokes
|
|
81
|
-
// Glyphs (
|
|
82
|
+
// strokes.
|
|
83
|
+
// Glyphs (SVG strokes at the current font size).
|
|
82
84
|
const Chevron = () => (_jsx("svg", { "aria-hidden": "true", fill: "none", height: "0.75em", stroke: "currentcolor", strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: "2", viewBox: "0 0 8 14", width: "0.43em", children: _jsx("path", { d: "M1.5 1.5L6.5 7l-5 5.5" }) }));
|
|
83
|
-
//
|
|
85
|
+
// 15.2 × 14.5px of ink at 17px (590).
|
|
84
86
|
const Lines = () => (_jsx("svg", { "aria-hidden": "true", fill: "none", height: "0.7em", stroke: "currentcolor", strokeLinecap: "round", strokeWidth: "1.5", viewBox: "0 0 18 12", width: "1.06em", children: _jsx("path", { d: "M1 1h16M1 6h16M1 11h16" }) }));
|
|
85
|
-
const Sign = ({ plus }) => (_jsx("svg", { "aria-hidden": "true", fill: "none", height: "0.8em", stroke: "currentcolor", strokeLinecap: "round", strokeWidth: "1.8", viewBox: "0 0 12 12", width: "0.8em", children: _jsx("path", { d: plus ? 'M2 6h8M6 2v8' : 'M2 6h8' }) }));
|
|
86
87
|
// Root: the list's style, as custom properties for its parts (their
|
|
87
88
|
// fallbacks are `insetGrouped`'s, for parts outside of a root).
|
|
88
|
-
|
|
89
|
-
|
|
89
|
+
// Edit modes: the root's, its sections' (unless their own), their groups'
|
|
90
|
+
// (unless their own), their rows' (unless their own); each row marks its
|
|
91
|
+
// sides (see `Item`), its parts
|
|
92
|
+
// reacting by their `whileEditing` (see style.css).
|
|
93
|
+
const EditingContext = createContext('ignore');
|
|
94
|
+
/** A part's `whileEditing`, as its attribute (see style.css). */
|
|
95
|
+
const whileEditingOf = (whileEditing) => ({
|
|
96
|
+
'data-while-editing': whileEditing,
|
|
97
|
+
});
|
|
98
|
+
const StyledRoot = forwardRef(({ className, listStyle, outline, render, ...props }, ref) => useRender({
|
|
90
99
|
defaultTagName: 'div',
|
|
91
100
|
props: {
|
|
92
101
|
'data-list-part': 'root',
|
|
@@ -98,8 +107,11 @@ const Root = forwardRef(({ className, listStyle, outline, render, ...props }, re
|
|
|
98
107
|
ref,
|
|
99
108
|
render,
|
|
100
109
|
}));
|
|
101
|
-
|
|
102
|
-
const
|
|
110
|
+
// Dragging to select (see `select.ts`): the root's, for its checkboxes.
|
|
111
|
+
const DragToSelectContext = createContext(true);
|
|
112
|
+
/** A list: sections of rows, headers and footers. */
|
|
113
|
+
const Root = forwardRef(({ dragToSelect: isDragToSelect = true, editing = 'ignore', ...props }, ref) => (_jsx(DragToSelectContext.Provider, { value: isDragToSelect, children: _jsx(EditingContext.Provider, { value: editing, children: _jsx(StyledRoot, { ref: ref, ...props }) }) })));
|
|
114
|
+
const StyledSection = forwardRef(({ className, render, ...props }, ref) => useRender({
|
|
103
115
|
defaultTagName: 'section',
|
|
104
116
|
props: {
|
|
105
117
|
'data-list-part': 'section',
|
|
@@ -109,202 +121,59 @@ const Section = forwardRef(({ className, render, ...props }, ref) => useRender({
|
|
|
109
121
|
ref,
|
|
110
122
|
render,
|
|
111
123
|
}));
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
const scrollContainerOf = (element) => {
|
|
123
|
-
for (let current = element.parentElement; current; current = current.parentElement) {
|
|
124
|
-
const { overflowY } = getComputedStyle(current);
|
|
125
|
-
if ((overflowY === 'auto' || overflowY === 'scroll') &&
|
|
126
|
-
current.scrollHeight > current.clientHeight) {
|
|
127
|
-
return current;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
return element.ownerDocument.scrollingElement ?? element.ownerDocument.body;
|
|
124
|
+
/** A section: an optional `Header`, a `Group` or `Block`, a `Footer`. */
|
|
125
|
+
const Section = forwardRef(({ editing, ...props }, ref) => {
|
|
126
|
+
const inherited = useContext(EditingContext);
|
|
127
|
+
return (_jsx(EditingContext.Provider, { value: editing ?? inherited, children: _jsx(StyledSection, { ref: ref, ...props }) }));
|
|
128
|
+
});
|
|
129
|
+
const RangeContext = createContext(undefined);
|
|
130
|
+
const handlesOf = (handle) => {
|
|
131
|
+
if (handle === undefined)
|
|
132
|
+
return [];
|
|
133
|
+
return handle instanceof ListReorderHandle ? [handle] : handle;
|
|
131
134
|
};
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
+
/**
|
|
136
|
+
* Keeps an entry in its handles' sets (`pick`: which), as they change, until
|
|
137
|
+
* unmounted.
|
|
138
|
+
*/
|
|
139
|
+
const useHandleEntry = (entry, handles, pick) => {
|
|
140
|
+
const registered = useRef([]);
|
|
141
|
+
useLayoutEffect(() => {
|
|
142
|
+
for (const handle of registered.current) {
|
|
143
|
+
if (!handles.includes(handle))
|
|
144
|
+
pick(handle).delete(entry);
|
|
145
|
+
}
|
|
146
|
+
for (const handle of handles)
|
|
147
|
+
pick(handle).add(entry);
|
|
148
|
+
registered.current = handles;
|
|
149
|
+
});
|
|
150
|
+
useLayoutEffect(() => () => {
|
|
151
|
+
for (const handle of registered.current)
|
|
152
|
+
pick(handle).delete(entry);
|
|
153
|
+
registered.current = [];
|
|
154
|
+
}, [entry, pick]);
|
|
135
155
|
};
|
|
136
|
-
|
|
137
|
-
const
|
|
138
|
-
|
|
156
|
+
const targetsOf = (handle) => handle.targets;
|
|
157
|
+
const itemsOf = (handle) => handle.items;
|
|
158
|
+
/**
|
|
159
|
+
* A range's gaps as targets of its handles (see `DropGroup`, `Group`): its
|
|
160
|
+
* rows' set, for them to register with.
|
|
161
|
+
*/
|
|
162
|
+
const useRange = (part, reorderHandle, dropName, ref) => {
|
|
163
|
+
const latest = useRef({ dropName, reorderHandle });
|
|
139
164
|
useLayoutEffect(() => {
|
|
140
|
-
|
|
165
|
+
latest.current = { dropName, reorderHandle };
|
|
141
166
|
});
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
? { grabber, item }
|
|
153
|
-
: undefined;
|
|
154
|
-
};
|
|
155
|
-
// Clears the rows' offsets once their order changed, or slides them
|
|
156
|
-
// back if it doesn't.
|
|
157
|
-
const commit = (items, from, to) => {
|
|
158
|
-
const settle = { observer: undefined };
|
|
159
|
-
let timeout;
|
|
160
|
-
const clearOffsets = (animate) => {
|
|
161
|
-
settle.observer?.disconnect();
|
|
162
|
-
clearTimeout(timeout);
|
|
163
|
-
for (const element of items) {
|
|
164
|
-
setOffset(element, 0, animate);
|
|
165
|
-
delete element.dataset.reordering;
|
|
166
|
-
delete element.dataset.reorderEdge;
|
|
167
|
-
}
|
|
168
|
-
};
|
|
169
|
-
settle.observer = new MutationObserver(() => clearOffsets(false));
|
|
170
|
-
settle.observer.observe(group, { childList: true });
|
|
171
|
-
timeout = setTimeout(() => clearOffsets(true), reorderDuration);
|
|
172
|
-
if (from === to) {
|
|
173
|
-
clearOffsets(true);
|
|
174
|
-
return;
|
|
175
|
-
}
|
|
176
|
-
onReorderRef.current?.(from, to);
|
|
177
|
-
};
|
|
178
|
-
const onPointerDown = (event) => {
|
|
179
|
-
if (event.button !== 0)
|
|
180
|
-
return;
|
|
181
|
-
const target = grabberOf(event.target);
|
|
182
|
-
if (!target)
|
|
183
|
-
return;
|
|
184
|
-
const { grabber, item } = target;
|
|
185
|
-
const items = [...group.children].filter(isItem);
|
|
186
|
-
const from = items.indexOf(item);
|
|
187
|
-
const origin = group.getBoundingClientRect().top;
|
|
188
|
-
// Relative to the group, which may scroll.
|
|
189
|
-
const tops = items.map((element) => element.getBoundingClientRect().top - origin);
|
|
190
|
-
const heights = items.map((element) => element.offsetHeight);
|
|
191
|
-
const height = heights[from] ?? 0;
|
|
192
|
-
const top = tops[from] ?? 0;
|
|
193
|
-
const bottomLimit = (tops.at(-1) ?? 0) + (heights.at(-1) ?? 0) - top - height;
|
|
194
|
-
const startY = event.clientY - origin;
|
|
195
|
-
let clientY = event.clientY;
|
|
196
|
-
let to = from;
|
|
197
|
-
event.preventDefault();
|
|
198
|
-
grabber.setPointerCapture(event.pointerId);
|
|
199
|
-
item.dataset.reordering = '';
|
|
200
|
-
const scroller = scrollContainerOf(group);
|
|
201
|
-
// The rows' corners and separators follow their order on screen.
|
|
202
|
-
const markEdges = (place) => {
|
|
203
|
-
const order = items.filter((element) => element !== item);
|
|
204
|
-
order.splice(place, 0, item);
|
|
205
|
-
for (const [index, element] of order.entries()) {
|
|
206
|
-
element.dataset.reorderEdge = [
|
|
207
|
-
index === 0 ? 'first' : '',
|
|
208
|
-
index === order.length - 1 ? 'last' : '',
|
|
209
|
-
order[index - 1] === item ? 'after' : '',
|
|
210
|
-
]
|
|
211
|
-
.filter(Boolean)
|
|
212
|
-
.join(' ');
|
|
213
|
-
}
|
|
214
|
-
};
|
|
215
|
-
markEdges(from);
|
|
216
|
-
const update = () => {
|
|
217
|
-
const groupTop = group.getBoundingClientRect().top;
|
|
218
|
-
const offset = Math.min(Math.max(clientY - groupTop - startY, -top), bottomLimit);
|
|
219
|
-
setOffset(item, offset, false);
|
|
220
|
-
// The row's place: its leading edge past the middle of the rows
|
|
221
|
-
// it's moved over (so it reaches the group's ends at any heights).
|
|
222
|
-
to = from;
|
|
223
|
-
for (const [index, rowTop] of tops.entries()) {
|
|
224
|
-
const middle = rowTop + (heights[index] ?? 0) / 2;
|
|
225
|
-
if (index < from && top + offset <= middle)
|
|
226
|
-
to = Math.min(to, index);
|
|
227
|
-
if (index > from && top + height + offset >= middle) {
|
|
228
|
-
to = Math.max(to, index);
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
for (const [index, element] of items.entries()) {
|
|
232
|
-
if (index === from)
|
|
233
|
-
continue;
|
|
234
|
-
const below = index > from && index <= to;
|
|
235
|
-
const above = index < from && index >= to;
|
|
236
|
-
setOffset(element, (above ? height : 0) - (below ? height : 0), true);
|
|
237
|
-
}
|
|
238
|
-
markEdges(to);
|
|
239
|
-
};
|
|
240
|
-
const elapsedOf = frameElapsed();
|
|
241
|
-
let frame = requestAnimationFrame(function scroll(time) {
|
|
242
|
-
frame = requestAnimationFrame(scroll);
|
|
243
|
-
const elapsed = elapsedOf(time);
|
|
244
|
-
const { bottom, top: scrollerTop } = scroller === scroller.ownerDocument.scrollingElement
|
|
245
|
-
? { bottom: window.innerHeight, top: 0 }
|
|
246
|
-
: scroller.getBoundingClientRect();
|
|
247
|
-
const delta = edgeScrollDelta(clientY, scrollerTop, bottom, elapsed);
|
|
248
|
-
if (delta === 0)
|
|
249
|
-
return;
|
|
250
|
-
const before = scroller.scrollTop;
|
|
251
|
-
scroller.scrollTop += delta;
|
|
252
|
-
if (scroller.scrollTop !== before)
|
|
253
|
-
update();
|
|
254
|
-
});
|
|
255
|
-
const onMove = (moveEvent) => {
|
|
256
|
-
if (moveEvent.pointerId !== event.pointerId)
|
|
257
|
-
return;
|
|
258
|
-
clientY = moveEvent.clientY;
|
|
259
|
-
update();
|
|
260
|
-
};
|
|
261
|
-
const onEnd = (endEvent) => {
|
|
262
|
-
if (endEvent.pointerId !== event.pointerId)
|
|
263
|
-
return;
|
|
264
|
-
cancelAnimationFrame(frame);
|
|
265
|
-
grabber.removeEventListener('pointermove', onMove);
|
|
266
|
-
grabber.removeEventListener('pointerup', onEnd);
|
|
267
|
-
grabber.removeEventListener('pointercancel', onEnd);
|
|
268
|
-
// Settles into its place, then commits.
|
|
269
|
-
const place = to > from
|
|
270
|
-
? (tops[to] ?? 0) + (heights[to] ?? 0) - top - height
|
|
271
|
-
: (tops[to] ?? 0) - top;
|
|
272
|
-
const committed = endEvent.type === 'pointercancel' ? from : to;
|
|
273
|
-
if (committed === from) {
|
|
274
|
-
for (const element of items)
|
|
275
|
-
setOffset(element, 0, true);
|
|
276
|
-
}
|
|
277
|
-
else {
|
|
278
|
-
setOffset(item, place, true);
|
|
279
|
-
}
|
|
280
|
-
markEdges(committed);
|
|
281
|
-
setTimeout(() => commit(items, from, committed), reorderDuration);
|
|
282
|
-
};
|
|
283
|
-
grabber.addEventListener('pointermove', onMove);
|
|
284
|
-
grabber.addEventListener('pointerup', onEnd);
|
|
285
|
-
grabber.addEventListener('pointercancel', onEnd);
|
|
286
|
-
};
|
|
287
|
-
const onKeyDown = (event) => {
|
|
288
|
-
if (event.key !== 'ArrowUp' && event.key !== 'ArrowDown')
|
|
289
|
-
return;
|
|
290
|
-
const target = grabberOf(event.target);
|
|
291
|
-
if (!target)
|
|
292
|
-
return;
|
|
293
|
-
const items = [...group.children].filter(isItem);
|
|
294
|
-
const from = items.indexOf(target.item);
|
|
295
|
-
const to = from + (event.key === 'ArrowUp' ? -1 : 1);
|
|
296
|
-
if (to < 0 || to >= items.length)
|
|
297
|
-
return;
|
|
298
|
-
event.preventDefault();
|
|
299
|
-
onReorderRef.current?.(from, to);
|
|
300
|
-
};
|
|
301
|
-
group.addEventListener('pointerdown', onPointerDown);
|
|
302
|
-
group.addEventListener('keydown', onKeyDown);
|
|
303
|
-
return () => {
|
|
304
|
-
group.removeEventListener('pointerdown', onPointerDown);
|
|
305
|
-
group.removeEventListener('keydown', onKeyDown);
|
|
306
|
-
};
|
|
307
|
-
}, [groupRef]);
|
|
167
|
+
const [entry] = useState(() => ({
|
|
168
|
+
handles: () => handlesOf(latest.current.reorderHandle),
|
|
169
|
+
members: new Set(),
|
|
170
|
+
name: () => latest.current.dropName,
|
|
171
|
+
part,
|
|
172
|
+
ref,
|
|
173
|
+
}));
|
|
174
|
+
const handles = handlesOf(reorderHandle);
|
|
175
|
+
useHandleEntry(entry, handles, targetsOf);
|
|
176
|
+
return handles.length === 0 ? undefined : entry.members;
|
|
308
177
|
};
|
|
309
178
|
/** The rows of a section, on the list's background (inset: a card). */
|
|
310
179
|
// Clips swiped rows sideways only (and reordered rows' shadows).
|
|
@@ -318,14 +187,56 @@ const StyledGroup = forwardRef(({ className, render, ...props }, ref) => useRend
|
|
|
318
187
|
ref,
|
|
319
188
|
render,
|
|
320
189
|
}));
|
|
321
|
-
const Group = forwardRef(({
|
|
190
|
+
const Group = forwardRef(({ dropName, editing, reorderHandle, ...props }, ref) => {
|
|
322
191
|
const groupRef = useForwardedRef(ref);
|
|
323
|
-
|
|
324
|
-
|
|
192
|
+
const inherited = useContext(EditingContext);
|
|
193
|
+
const range = useRange('Group', reorderHandle, dropName, groupRef);
|
|
194
|
+
return (_jsx(EditingContext.Provider, { value: editing ?? inherited, children: _jsx(RangeContext.Provider, { value: range, children: _jsx(StyledGroup, { ref: groupRef, ...props }) }) }));
|
|
195
|
+
});
|
|
196
|
+
/**
|
|
197
|
+
* A range of rows' gaps, targets of its handles (as a `Group` given a
|
|
198
|
+
* `reorderHandle`: before, between and after its rows), with no element of
|
|
199
|
+
* its own (only an empty, hidden one marking where it is, its gap once
|
|
200
|
+
* emptied): its rows stay its group's.
|
|
201
|
+
*/
|
|
202
|
+
const DropGroup = ({ children, dropName, reorderHandle, }) => {
|
|
203
|
+
// Where it is, emptied: an empty, hidden element (as a `DropTarget`'s).
|
|
204
|
+
const markerRef = useRef(null);
|
|
205
|
+
const range = useRange('DropGroup', reorderHandle, dropName, markerRef);
|
|
206
|
+
return (_jsxs(RangeContext.Provider, { value: range, children: [_jsx("li", { ref: markerRef, "aria-hidden": true, className: "uikit-list-drop-target", "data-list-part": "drop-target" }), children] }));
|
|
207
|
+
};
|
|
208
|
+
/**
|
|
209
|
+
* A gap rows of its handles can be dropped into, where it's placed among a
|
|
210
|
+
* group's rows: an empty, hidden element (no height), only marking it.
|
|
211
|
+
*/
|
|
212
|
+
const DropTarget = forwardRef(({ className, dropName, render, reorderHandle, ...props }, ref) => {
|
|
213
|
+
const targetRef = useForwardedRef(ref);
|
|
214
|
+
const latest = useRef({ dropName, reorderHandle });
|
|
215
|
+
useLayoutEffect(() => {
|
|
216
|
+
latest.current = { dropName, reorderHandle };
|
|
217
|
+
});
|
|
218
|
+
const [entry] = useState(() => ({
|
|
219
|
+
handles: () => handlesOf(latest.current.reorderHandle),
|
|
220
|
+
name: () => latest.current.dropName,
|
|
221
|
+
part: 'DropTarget',
|
|
222
|
+
ref: targetRef,
|
|
223
|
+
}));
|
|
224
|
+
useHandleEntry(entry, handlesOf(reorderHandle), targetsOf);
|
|
225
|
+
return useRender({
|
|
226
|
+
defaultTagName: 'li',
|
|
227
|
+
props: {
|
|
228
|
+
'aria-hidden': true,
|
|
229
|
+
'data-list-part': 'drop-target',
|
|
230
|
+
className: cn('uikit-list-drop-target', className),
|
|
231
|
+
...props,
|
|
232
|
+
},
|
|
233
|
+
ref: targetRef,
|
|
234
|
+
render,
|
|
235
|
+
});
|
|
325
236
|
});
|
|
326
237
|
// Rows.
|
|
327
238
|
/**
|
|
328
|
-
* A swiped row's corners: a capsule up to
|
|
239
|
+
* A swiped row's corners: a capsule up to tall rows (68px), taller
|
|
329
240
|
* rows (e.g. Mail's) get rounded corners.
|
|
330
241
|
*/
|
|
331
242
|
const swipeRadius = 34;
|
|
@@ -346,12 +257,89 @@ const StyledItem = forwardRef(({ className, render, ...props }, ref) => useRende
|
|
|
346
257
|
render,
|
|
347
258
|
}));
|
|
348
259
|
const ItemContext = createContext(undefined);
|
|
260
|
+
/** A row's side in an edit mode: editing, not, or not managed. */
|
|
261
|
+
const editSide = (editing, side) => {
|
|
262
|
+
if (editing === 'ignore')
|
|
263
|
+
return undefined;
|
|
264
|
+
return editing === side || editing === 'both' ? 'on' : 'off';
|
|
265
|
+
};
|
|
266
|
+
// The slots sliding in or out by their width (see style.css).
|
|
267
|
+
const sizedParts = ':scope > [data-list-part="row"] > :is([data-list-part="leading"], [data-list-part="trailing"])';
|
|
268
|
+
// A row's slots: its only children (see style.css).
|
|
269
|
+
const slots = new Set(['below', 'content', 'leading', 'span', 'trailing']);
|
|
270
|
+
// Rows already told about their foreign elements (see `useStrictSlots`).
|
|
271
|
+
const toldRows = new WeakSet();
|
|
272
|
+
/**
|
|
273
|
+
* Warns (once per row) about elements of other components placed in a row
|
|
274
|
+
* directly, not in one of its slots (`Leading`, `Content`, `Trailing`,
|
|
275
|
+
* `Span`, `Below`): the row places only its own parts.
|
|
276
|
+
*/
|
|
277
|
+
const useStrictSlots = (itemRef) => {
|
|
278
|
+
useLayoutEffect(() => {
|
|
279
|
+
const row = itemRef.current?.querySelector(':scope > [data-list-part="track"] > [data-list-part="row"]');
|
|
280
|
+
if (!row || toldRows.has(row))
|
|
281
|
+
return;
|
|
282
|
+
const foreign = [...row.children].filter((child) => !(child instanceof HTMLElement &&
|
|
283
|
+
slots.has(child.dataset.listPart ?? '')));
|
|
284
|
+
if (foreign.length === 0)
|
|
285
|
+
return;
|
|
286
|
+
toldRows.add(row);
|
|
287
|
+
// eslint-disable-next-line no-console -- a misuse, told to the developer
|
|
288
|
+
console.warn('List.Item: a row holds only slots (List.Leading, List.Content, List.Trailing, List.Span, List.Below); parts and other elements go in them:', foreign);
|
|
289
|
+
});
|
|
290
|
+
};
|
|
291
|
+
/**
|
|
292
|
+
* A managed row's slots sliding in or out in edit mode, their widths as
|
|
293
|
+
* `--uikit-list-slot-size` (taking no room while out, see style.css):
|
|
294
|
+
* measured before it's first shown, sliding only after (`data-sized` on
|
|
295
|
+
* its track; not sliding out from where they'd be unmeasured).
|
|
296
|
+
*/
|
|
297
|
+
const useEditingSizes = (itemRef, isManaged) => {
|
|
298
|
+
useLayoutEffect(() => {
|
|
299
|
+
const track = itemRef.current?.querySelector(':scope > [data-list-part="track"]');
|
|
300
|
+
if (!isManaged || !(track instanceof HTMLElement))
|
|
301
|
+
return undefined;
|
|
302
|
+
const size = (target) => {
|
|
303
|
+
if (!(target instanceof HTMLElement))
|
|
304
|
+
return;
|
|
305
|
+
target.style.setProperty('--uikit-list-slot-size', `${String(target.offsetWidth)}px`);
|
|
306
|
+
};
|
|
307
|
+
const resizeObserver = new ResizeObserver((entries) => {
|
|
308
|
+
for (const { target } of entries)
|
|
309
|
+
size(target);
|
|
310
|
+
});
|
|
311
|
+
const observe = () => {
|
|
312
|
+
resizeObserver.disconnect();
|
|
313
|
+
for (const part of track.querySelectorAll(sizedParts)) {
|
|
314
|
+
size(part);
|
|
315
|
+
resizeObserver.observe(part);
|
|
316
|
+
}
|
|
317
|
+
};
|
|
318
|
+
observe();
|
|
319
|
+
const row = track.querySelector('[data-list-part="row"]');
|
|
320
|
+
const mutationObserver = new MutationObserver(observe);
|
|
321
|
+
if (row)
|
|
322
|
+
mutationObserver.observe(row, { childList: true });
|
|
323
|
+
// (Sliding from the next frame on: the first shown as measured.)
|
|
324
|
+
const frame = requestAnimationFrame(() => {
|
|
325
|
+
track.dataset.sized = '';
|
|
326
|
+
});
|
|
327
|
+
return () => {
|
|
328
|
+
cancelAnimationFrame(frame);
|
|
329
|
+
resizeObserver.disconnect();
|
|
330
|
+
mutationObserver.disconnect();
|
|
331
|
+
};
|
|
332
|
+
}, [itemRef, isManaged]);
|
|
333
|
+
};
|
|
349
334
|
/** Closes the item whose swipe actions are open (one at a time). */
|
|
350
335
|
let closeOpenItem;
|
|
351
336
|
const swipeDuration = 300;
|
|
352
337
|
const swipeThreshold = 8;
|
|
353
338
|
/** A sideways scroll swiping a row ends after this long without scrolling. */
|
|
354
339
|
const scrollEndDelay = 150;
|
|
340
|
+
// How long a wheel (or a trackpad's momentum) is quiet before a row it
|
|
341
|
+
// scrolled open is at rest there (see `settle`).
|
|
342
|
+
const wheelQuiet = 300;
|
|
355
343
|
/**
|
|
356
344
|
* How far a row arms overswiping, with any actions (also fewer, or
|
|
357
345
|
* labelled ones): past 5 circles (5 × (44 + 10) + 16 + 10 + 8px;
|
|
@@ -364,14 +352,14 @@ const overswipeArm = 304;
|
|
|
364
352
|
const armDuration = 150;
|
|
365
353
|
/**
|
|
366
354
|
* Actions fade in from this opacity as they scale in, and the others fade
|
|
367
|
-
* to it while overswiping, until armed (
|
|
355
|
+
* to it while overswiping, until armed (measured: shapes, symbols and
|
|
368
356
|
* labels each at 36%).
|
|
369
357
|
*/
|
|
370
358
|
const actionFade = 0.36;
|
|
371
359
|
const sides = ['leading', 'trailing'];
|
|
372
360
|
const isRtl = (element) => getComputedStyle(element).direction === 'rtl';
|
|
373
361
|
/**
|
|
374
|
-
* Overswipe (Framework7 iOS): widens the outermost action's shape by
|
|
362
|
+
* Overswipe (Framework7's iOS theme): widens the outermost action's shape by
|
|
375
363
|
* `extra` px towards the row (`towardsRow`, physical), from the edge (its
|
|
376
364
|
* negative margin keeps the action's size), its symbol and label centered in
|
|
377
365
|
* it, as the row moves (`transition`).
|
|
@@ -428,12 +416,12 @@ const rowPath = (width, height, offset) => {
|
|
|
428
416
|
const revealRanges = (container, side, lead) => {
|
|
429
417
|
const width = container.offsetWidth;
|
|
430
418
|
// Whether the row is on the container's left (the edge on its right).
|
|
431
|
-
const
|
|
419
|
+
const isRowOnLeft = (side === 'trailing') === !isRtl(container);
|
|
432
420
|
for (const button of container.children) {
|
|
433
421
|
if (!(button instanceof HTMLElement))
|
|
434
422
|
continue;
|
|
435
423
|
// From the edge, uncovered from `start` to `start` + its width.
|
|
436
|
-
const start =
|
|
424
|
+
const start = isRowOnLeft
|
|
437
425
|
? width - button.offsetLeft - button.offsetWidth
|
|
438
426
|
: button.offsetLeft;
|
|
439
427
|
const end = start + button.offsetWidth;
|
|
@@ -455,15 +443,21 @@ const revealRanges = (container, side, lead) => {
|
|
|
455
443
|
* actions stay in place by themselves (see `Pin`) and scale in with the
|
|
456
444
|
* scroll (see `StyledSwipeAction`).
|
|
457
445
|
*/
|
|
458
|
-
const placeRow = (item, actions, offset,
|
|
446
|
+
const placeRow = (item, actions, offset, isAnimated, overswipes) => {
|
|
459
447
|
const direction = isRtl(item) ? -1 : 1;
|
|
460
448
|
const transition = (...properties) => properties
|
|
461
|
-
.map((property) => `${property} ${
|
|
449
|
+
.map((property) => `${property} ${isAnimated ? swipeDuration : 0}ms`)
|
|
462
450
|
.join(', ');
|
|
463
|
-
// Rounded at the side the content leaves (changing with the side only)
|
|
464
|
-
|
|
465
|
-
if (
|
|
466
|
-
item.style.
|
|
451
|
+
// Rounded at the side the content leaves (changing with the side only); at
|
|
452
|
+
// rest, none (the row's own corners, e.g. pressed, see `resetRow`).
|
|
453
|
+
if (offset === 0) {
|
|
454
|
+
item.style.removeProperty('clip-path');
|
|
455
|
+
}
|
|
456
|
+
else {
|
|
457
|
+
const clipPath = rowPath(item.offsetWidth, item.offsetHeight, offset * direction);
|
|
458
|
+
if (item.style.clipPath !== clipPath)
|
|
459
|
+
item.style.clipPath = clipPath;
|
|
460
|
+
}
|
|
467
461
|
for (const side of sides) {
|
|
468
462
|
const container = actions[side];
|
|
469
463
|
if (!container)
|
|
@@ -472,8 +466,8 @@ const placeRow = (item, actions, offset, animate, overswipes) => {
|
|
|
472
466
|
const revealed = Math.max(0, side === 'leading' ? offset : -offset);
|
|
473
467
|
const extra = overswipes(side) ? Math.max(0, revealed - width) : 0;
|
|
474
468
|
const outermost = outermostAction(container, side);
|
|
475
|
-
const
|
|
476
|
-
const towardsRow =
|
|
469
|
+
const isRowOnLeft = (side === 'trailing') === (direction === 1);
|
|
470
|
+
const towardsRow = isRowOnLeft ? -1 : 1;
|
|
477
471
|
const arm = armDistance(item, container, side, width);
|
|
478
472
|
const arming = Math.min(extra / (arm - width), 1);
|
|
479
473
|
// Past the armed place, on across the whole row (see `snapPlaces`): the
|
|
@@ -565,9 +559,285 @@ const snapPlaces = (swipe, lead, overswipes) => {
|
|
|
565
559
|
return places;
|
|
566
560
|
};
|
|
567
561
|
/** Whether the browser fires `scrollend` (else: a pause in scrolling). */
|
|
568
|
-
const
|
|
562
|
+
const hasScrollEnd = typeof window !== 'undefined' && 'onscrollend' in window;
|
|
569
563
|
/**
|
|
570
|
-
*
|
|
564
|
+
* Whether a row dragged to `offset` (towards `side`) opens its actions
|
|
565
|
+
* there when released: flicked towards them, or past half their `width`.
|
|
566
|
+
*/
|
|
567
|
+
const opensOnRelease = (drag, offset, side, width) => {
|
|
568
|
+
const distance = Math.abs(offset);
|
|
569
|
+
if (width === undefined || distance < 1)
|
|
570
|
+
return false;
|
|
571
|
+
const moved = offset - drag.base;
|
|
572
|
+
const isQuick = performance.now() - drag.time < 300;
|
|
573
|
+
const isMovedTowards = side === 'leading' ? moved > 10 : moved < -10;
|
|
574
|
+
return isQuick ? isMovedTowards : distance > width / 2;
|
|
575
|
+
};
|
|
576
|
+
/** How long a collapsible row opens or closes (as swiping). */
|
|
577
|
+
const expandDuration = 300;
|
|
578
|
+
// Rows opening and closing in place, as Base UI's Collapsible and Accordion
|
|
579
|
+
// (without elements of their own: a group's rows stay its children, a list
|
|
580
|
+
// having no other elements among them). A `CollapsibleRoot` (or an
|
|
581
|
+
// `AccordionItem`, its `AccordionRoot` holding which are open) holds the
|
|
582
|
+
// state, its `CollapsibleTrigger` (e.g. a row's title, `render`) toggles
|
|
583
|
+
// it, its `CollapsiblePanel` shows its rows.
|
|
584
|
+
const CollapsibleContext = createContext(undefined);
|
|
585
|
+
// A collapsible's rows' ids (see `useExpandedRow`), in mounting order: its
|
|
586
|
+
// trigger's `aria-controls`.
|
|
587
|
+
const useControls = () => {
|
|
588
|
+
const [ids, setIds] = useState([]);
|
|
589
|
+
const register = useCallback((id) => {
|
|
590
|
+
setIds((current) => [...current, id]);
|
|
591
|
+
return () => setIds((current) => current.filter((other) => other !== id));
|
|
592
|
+
}, []);
|
|
593
|
+
return [ids.join(' ') || undefined, register];
|
|
594
|
+
};
|
|
595
|
+
/**
|
|
596
|
+
* Rows' state (Base UI `Collapsible.Root`), for their trigger and them; no
|
|
597
|
+
* element of its own.
|
|
598
|
+
*/
|
|
599
|
+
const CollapsibleRoot = ({ children, defaultOpen = false, disabled = false, onOpenChange, open: openProp, }) => {
|
|
600
|
+
const [isUncontrolled, setIsUncontrolled] = useState(defaultOpen);
|
|
601
|
+
const isOpen = openProp ?? isUncontrolled;
|
|
602
|
+
const [controls, register] = useControls();
|
|
603
|
+
const context = useMemo(() => ({
|
|
604
|
+
controls,
|
|
605
|
+
disabled,
|
|
606
|
+
isOpen,
|
|
607
|
+
register,
|
|
608
|
+
setOpen: (isNextOpen, eventDetails) => {
|
|
609
|
+
onOpenChange?.(isNextOpen, eventDetails);
|
|
610
|
+
if (openProp === undefined)
|
|
611
|
+
setIsUncontrolled(isNextOpen);
|
|
612
|
+
},
|
|
613
|
+
}), [controls, disabled, isOpen, onOpenChange, openProp, register]);
|
|
614
|
+
return (_jsx(CollapsibleContext.Provider, { value: context, children: children }));
|
|
615
|
+
};
|
|
616
|
+
/**
|
|
617
|
+
* Toggles its collapsible's rows (Base UI `Collapsible.Trigger`,
|
|
618
|
+
* `Accordion.Trigger`): a button (e.g. rendered by a row's `Title`, making
|
|
619
|
+
* the row pressable), with `aria-expanded` and `aria-controls`.
|
|
620
|
+
*/
|
|
621
|
+
const CollapsibleTrigger = forwardRef(({ onClick, render, ...props }, ref) => {
|
|
622
|
+
const collapsible = useContext(CollapsibleContext);
|
|
623
|
+
return useRender({
|
|
624
|
+
defaultTagName: 'button',
|
|
625
|
+
props: {
|
|
626
|
+
'aria-controls': collapsible?.controls,
|
|
627
|
+
'aria-expanded': collapsible?.isOpen ?? false,
|
|
628
|
+
'data-disabled': collapsible?.disabled ? '' : undefined,
|
|
629
|
+
// (No part of its own: it's what it renders, e.g. a row's title, an
|
|
630
|
+
// accessory, keeping their styles.)
|
|
631
|
+
'data-panel-open': collapsible?.isOpen ? '' : undefined,
|
|
632
|
+
disabled: collapsible?.disabled,
|
|
633
|
+
type: 'button',
|
|
634
|
+
...props,
|
|
635
|
+
onClick: (event) => {
|
|
636
|
+
onClick?.(event);
|
|
637
|
+
if (event.defaultPrevented || !collapsible || collapsible.disabled) {
|
|
638
|
+
return;
|
|
639
|
+
}
|
|
640
|
+
collapsible.setOpen(!collapsible.isOpen, {
|
|
641
|
+
event: event,
|
|
642
|
+
reason: 'trigger-press',
|
|
643
|
+
});
|
|
644
|
+
},
|
|
645
|
+
},
|
|
646
|
+
ref,
|
|
647
|
+
render,
|
|
648
|
+
});
|
|
649
|
+
});
|
|
650
|
+
// The rows of a `CollapsiblePanel` (see `Item`): shown or not.
|
|
651
|
+
const PanelContext = createContext(undefined);
|
|
652
|
+
/**
|
|
653
|
+
* Its collapsible's rows (Base UI `Collapsible.Panel`, `Accordion.Panel`),
|
|
654
|
+
* shown or not, opening and closing in place, together (each its height),
|
|
655
|
+
* e.g. an inline `Calendar` or `TimeRoll` below a row with a `DatePicker`
|
|
656
|
+
* (see `DatePicker.Expandable`, as a calendar app's). Placed among a group's
|
|
657
|
+
* rows (no element of its own: the group's rows stay its children), or
|
|
658
|
+
* among another's (closed with it). Closed, they're inert.
|
|
659
|
+
*/
|
|
660
|
+
const CollapsiblePanel = ({ children, }) => {
|
|
661
|
+
const collapsible = useContext(CollapsibleContext);
|
|
662
|
+
// In another's rows: closed with it.
|
|
663
|
+
const outer = useContext(PanelContext);
|
|
664
|
+
const isOpen = (collapsible?.isOpen ?? false) && (outer?.isOpen ?? true);
|
|
665
|
+
const register = collapsible?.register;
|
|
666
|
+
const context = useMemo(() => ({ isOpen, register }), [isOpen, register]);
|
|
667
|
+
// Its rows aren't its collapsible's triggers (nor a picker's, see
|
|
668
|
+
// `useCollapsible`): theirs are their own collapsibles'.
|
|
669
|
+
return (_jsx(CollapsibleContext.Provider, { value: undefined, children: _jsx(PanelContext.Provider, { value: context, children: children }) }));
|
|
670
|
+
};
|
|
671
|
+
const AccordionContext = createContext(undefined);
|
|
672
|
+
/**
|
|
673
|
+
* Collapsibles, one open at a time (unless `multiple`), as Base UI
|
|
674
|
+
* `Accordion.Root`: its `AccordionItem`s, by their `value`; no element of
|
|
675
|
+
* its own.
|
|
676
|
+
*/
|
|
677
|
+
const AccordionRoot = ({ children, defaultValue = [], disabled = false, multiple = false, onValueChange, value: valueProp, }) => {
|
|
678
|
+
const [uncontrolled, setUncontrolled] = useState(defaultValue);
|
|
679
|
+
const value = valueProp ?? uncontrolled;
|
|
680
|
+
const context = useMemo(() => ({
|
|
681
|
+
disabled,
|
|
682
|
+
isOpen: (item) => value.includes(item),
|
|
683
|
+
setOpen: (item, isOpen, eventDetails) => {
|
|
684
|
+
const others = value.filter((open) => open !== item);
|
|
685
|
+
const next = isOpen
|
|
686
|
+
? [...(multiple ? others : []), item]
|
|
687
|
+
: others;
|
|
688
|
+
onValueChange?.(next, eventDetails);
|
|
689
|
+
if (valueProp === undefined)
|
|
690
|
+
setUncontrolled(next);
|
|
691
|
+
},
|
|
692
|
+
}), [disabled, multiple, onValueChange, value, valueProp]);
|
|
693
|
+
return (_jsx(AccordionContext.Provider, { value: context, children: children }));
|
|
694
|
+
};
|
|
695
|
+
/**
|
|
696
|
+
* A collapsible of its `AccordionRoot` (Base UI `Accordion.Item`), open as
|
|
697
|
+
* its root holds (by its `value`): its trigger and panel as a
|
|
698
|
+
* `CollapsibleRoot`'s; no element of its own.
|
|
699
|
+
*/
|
|
700
|
+
const AccordionItem = ({ children, disabled: disabledProp, onOpenChange, value: valueProp, }) => {
|
|
701
|
+
const accordion = useContext(AccordionContext);
|
|
702
|
+
const ownValue = useId();
|
|
703
|
+
const value = valueProp ?? ownValue;
|
|
704
|
+
const isOpen = accordion?.isOpen(value) ?? false;
|
|
705
|
+
const disabled = disabledProp ?? accordion?.disabled ?? false;
|
|
706
|
+
const [controls, register] = useControls();
|
|
707
|
+
const context = useMemo(() => ({
|
|
708
|
+
controls,
|
|
709
|
+
disabled,
|
|
710
|
+
isOpen,
|
|
711
|
+
register,
|
|
712
|
+
setOpen: (isNextOpen, eventDetails) => {
|
|
713
|
+
onOpenChange?.(isNextOpen, eventDetails);
|
|
714
|
+
accordion?.setOpen(value, isNextOpen, eventDetails);
|
|
715
|
+
},
|
|
716
|
+
}), [accordion, controls, disabled, isOpen, onOpenChange, register, value]);
|
|
717
|
+
return (_jsx(CollapsibleContext.Provider, { value: context, children: children }));
|
|
718
|
+
};
|
|
719
|
+
/**
|
|
720
|
+
* The collapsible around (a `CollapsibleRoot`, an `AccordionItem`; not in
|
|
721
|
+
* its panel): whether it's open, and opening or closing it (e.g. for a
|
|
722
|
+
* control opening rows of its own, see `DatePicker` `handle`).
|
|
723
|
+
*/
|
|
724
|
+
export const useCollapsible = () => useContext(CollapsibleContext);
|
|
725
|
+
/**
|
|
726
|
+
* Whether the collapsible rows around (see `CollapsiblePanel`) are open;
|
|
727
|
+
* `undefined` outside any (e.g. for a control closing its popups with
|
|
728
|
+
* them, see `DatePicker`).
|
|
729
|
+
*/
|
|
730
|
+
export const useExpandedOpen = () => useContext(PanelContext)?.isOpen;
|
|
731
|
+
/**
|
|
732
|
+
* A row of a `CollapsiblePanel`: shown or not (`isOpen`, unset outside
|
|
733
|
+
* one), its height and padding transitioning; its id (given, or its own)
|
|
734
|
+
* one its `CollapsibleTrigger` controls.
|
|
735
|
+
*/
|
|
736
|
+
const useExpandedRow = (itemRef, idProp) => {
|
|
737
|
+
const expanded = useContext(PanelContext);
|
|
738
|
+
const isOpen = expanded?.isOpen;
|
|
739
|
+
const ownId = useId();
|
|
740
|
+
const id = expanded && (idProp === undefined || typeof idProp === 'string')
|
|
741
|
+
? (idProp ?? ownId)
|
|
742
|
+
: undefined;
|
|
743
|
+
const register = expanded?.register;
|
|
744
|
+
const shown = useRef(undefined);
|
|
745
|
+
useLayoutEffect(() => (!register || id === undefined ? undefined : register(id)), [id, register]);
|
|
746
|
+
useLayoutEffect(() => {
|
|
747
|
+
const { current: item } = itemRef;
|
|
748
|
+
if (!item || isOpen === undefined)
|
|
749
|
+
return undefined;
|
|
750
|
+
const wasShown = shown.current;
|
|
751
|
+
shown.current = isOpen;
|
|
752
|
+
const settle = () => {
|
|
753
|
+
item.toggleAttribute('data-closed', !isOpen);
|
|
754
|
+
item.inert = !isOpen;
|
|
755
|
+
};
|
|
756
|
+
if (wasShown === undefined || wasShown === isOpen) {
|
|
757
|
+
settle();
|
|
758
|
+
return undefined;
|
|
759
|
+
}
|
|
760
|
+
// From its height as it is, to the other state's. Opening, it's
|
|
761
|
+
// measured open; closing, it closes once the animation finishes (its
|
|
762
|
+
// content shrinking at once, a scroll container could scroll back).
|
|
763
|
+
// eslint-disable-next-line unicorn/no-unnecessary-parameters
|
|
764
|
+
const box = (element) => {
|
|
765
|
+
const style = getComputedStyle(element);
|
|
766
|
+
return {
|
|
767
|
+
height: `${String(element.offsetHeight)}px`,
|
|
768
|
+
paddingBottom: style.paddingBottom,
|
|
769
|
+
paddingTop: style.paddingTop,
|
|
770
|
+
};
|
|
771
|
+
};
|
|
772
|
+
const closed = { height: '0px', paddingBottom: '0px', paddingTop: '0px' };
|
|
773
|
+
const from = isOpen ? closed : box(item);
|
|
774
|
+
if (isOpen)
|
|
775
|
+
settle();
|
|
776
|
+
const to = isOpen ? box(item) : closed;
|
|
777
|
+
item.inert = !isOpen;
|
|
778
|
+
item.style.overflow = 'clip';
|
|
779
|
+
const animation = item.animate([
|
|
780
|
+
{
|
|
781
|
+
...from,
|
|
782
|
+
minHeight: '0px',
|
|
783
|
+
opacity: isOpen ? 0 : 1,
|
|
784
|
+
visibility: 'visible',
|
|
785
|
+
},
|
|
786
|
+
{
|
|
787
|
+
...to,
|
|
788
|
+
minHeight: '0px',
|
|
789
|
+
opacity: isOpen ? 1 : 0,
|
|
790
|
+
visibility: 'visible',
|
|
791
|
+
},
|
|
792
|
+
], { duration: expandDuration, easing: 'ease' });
|
|
793
|
+
const done = () => {
|
|
794
|
+
item.style.removeProperty('overflow');
|
|
795
|
+
if (!isOpen)
|
|
796
|
+
settle();
|
|
797
|
+
};
|
|
798
|
+
animation.finished.then(done).catch(() => undefined);
|
|
799
|
+
return () => {
|
|
800
|
+
animation.cancel();
|
|
801
|
+
item.style.removeProperty('overflow');
|
|
802
|
+
settle();
|
|
803
|
+
};
|
|
804
|
+
}, [itemRef, isOpen]);
|
|
805
|
+
return id ?? idProp;
|
|
806
|
+
};
|
|
807
|
+
/**
|
|
808
|
+
* A row in reordering (see `reorder.ts`): its name, its handles; in a
|
|
809
|
+
* range, one of its rows.
|
|
810
|
+
*/
|
|
811
|
+
const useReorderItem = (itemRef, reorderHandle, dropName) => {
|
|
812
|
+
const range = useContext(RangeContext);
|
|
813
|
+
useLayoutEffect(() => {
|
|
814
|
+
if (!range)
|
|
815
|
+
return undefined;
|
|
816
|
+
range.add(itemRef);
|
|
817
|
+
return () => {
|
|
818
|
+
range.delete(itemRef);
|
|
819
|
+
};
|
|
820
|
+
}, [itemRef, range]);
|
|
821
|
+
const latest = useRef({ dropName, reorderHandle });
|
|
822
|
+
useLayoutEffect(() => {
|
|
823
|
+
latest.current = { dropName, reorderHandle };
|
|
824
|
+
});
|
|
825
|
+
const [entry] = useState(() => ({
|
|
826
|
+
handles: () => handlesOf(latest.current.reorderHandle),
|
|
827
|
+
name: () => latest.current.dropName,
|
|
828
|
+
ref: itemRef,
|
|
829
|
+
}));
|
|
830
|
+
useHandleEntry(entry, handlesOf(reorderHandle), itemsOf);
|
|
831
|
+
useLayoutEffect(() => {
|
|
832
|
+
const { current: element } = itemRef;
|
|
833
|
+
if (!element)
|
|
834
|
+
return undefined;
|
|
835
|
+
setItemEntry(element, entry);
|
|
836
|
+
return () => setItemEntry(element, undefined);
|
|
837
|
+
}, [entry, itemRef]);
|
|
838
|
+
};
|
|
839
|
+
/**
|
|
840
|
+
* A row, with optional swipe actions. With a click
|
|
571
841
|
* handler, it's pressable itself (e.g. passing the click on to a control in
|
|
572
842
|
* it), but where its own controls are pressed.
|
|
573
843
|
*
|
|
@@ -578,10 +848,20 @@ const scrollEnds = typeof window !== 'undefined' && 'onscrollend' in window;
|
|
|
578
848
|
* once the scroll comes to rest there, so scrolling back disarms it.
|
|
579
849
|
*/
|
|
580
850
|
const Item = forwardRef((itemProps, ref) => {
|
|
581
|
-
const { children, onBlurCapture, onClickCapture, onLostPointerCapture, onPointerCancel, onPointerDown, onPointerMove, onPointerUp, level, selected, style, ...props } = useSecondaryClick(itemProps);
|
|
851
|
+
const { children, onBlurCapture, onClickCapture, onLostPointerCapture, onPointerCancel, onPointerDown, onPointerMove, onPointerUp, dropName, editing: itemEditing, id: idProp, level, reorderHandle, selected, style, ...props } = useSecondaryClick(itemProps);
|
|
852
|
+
const inheritedEditing = useContext(EditingContext);
|
|
853
|
+
const editing = itemEditing ?? inheritedEditing;
|
|
582
854
|
const itemRef = useForwardedRef(ref);
|
|
855
|
+
useReorderItem(itemRef, reorderHandle, dropName);
|
|
856
|
+
const id = useExpandedRow(itemRef, idProp);
|
|
857
|
+
useEditingSizes(itemRef, editing !== 'ignore');
|
|
858
|
+
useStrictSlots(itemRef);
|
|
583
859
|
const actionsRef = useRef({});
|
|
584
860
|
const overswipeRef = useRef({});
|
|
861
|
+
// What swiping does to each side's actions (see `ListAllowSwipe`).
|
|
862
|
+
const allowRef = useRef({});
|
|
863
|
+
const canReveal = (side) => ['all', 'reveal'].includes(allowRef.current[side] ?? 'all');
|
|
864
|
+
const canConceal = (side) => ['all', 'conceal'].includes(allowRef.current[side] ?? 'all');
|
|
585
865
|
const snapsRef = useRef({});
|
|
586
866
|
const swipeRef = useRef({ arms: {}, extents: {}, widths: {} });
|
|
587
867
|
const placesRef = useRef({});
|
|
@@ -593,17 +873,22 @@ const Item = forwardRef((itemProps, ref) => {
|
|
|
593
873
|
const swipingRef = useRef(false);
|
|
594
874
|
// Open, at rest there (see `overswipable`).
|
|
595
875
|
const restingOpenRef = useRef(false);
|
|
876
|
+
// The last wheel event's time (scrolled: at rest once the wheel is quiet).
|
|
877
|
+
const wheelRef = useRef(0);
|
|
596
878
|
const dragRef = useRef(null);
|
|
597
879
|
const pressRef = useRef(null);
|
|
598
880
|
const openSideRef = useRef(undefined);
|
|
599
881
|
const suppressClickRef = useRef(false);
|
|
600
882
|
const settleRef = useRef(undefined);
|
|
601
883
|
const outsideRef = useRef(undefined);
|
|
602
|
-
const [
|
|
884
|
+
const [isSwipeable, setIsSwipeable] = useState(false);
|
|
603
885
|
const [pin, setPin] = useState(null);
|
|
604
886
|
const overswipes = (side) => Boolean(overswipeRef.current[side]);
|
|
605
|
-
// The track's room before the row (the leading side's
|
|
606
|
-
|
|
887
|
+
// The track's room before the row (the leading side's, see `layOut`),
|
|
888
|
+
// and after it.
|
|
889
|
+
const leadRef = useRef(0);
|
|
890
|
+
const trailRef = useRef(0);
|
|
891
|
+
const lead = () => leadRef.current;
|
|
607
892
|
// The row's offset (towards its inline end), from the scroll position.
|
|
608
893
|
const offsetOf = (item) => isRtl(item) ? item.scrollLeft + lead() : lead() - item.scrollLeft;
|
|
609
894
|
// Overswiping a side: swiped (touch, a mouse drag) in one go; scrolled
|
|
@@ -612,31 +897,101 @@ const Item = forwardRef((itemProps, ref) => {
|
|
|
612
897
|
const overswipable = (side) => swipingRef.current ||
|
|
613
898
|
(openSideRef.current === side && restingOpenRef.current);
|
|
614
899
|
const overswipesNow = (side) => overswipes(side) && overswipable(side);
|
|
900
|
+
const scrollTo = (offset, isSmooth) => {
|
|
901
|
+
const { current: item } = itemRef;
|
|
902
|
+
if (!item)
|
|
903
|
+
return;
|
|
904
|
+
const isRightToLeft = isRtl(item);
|
|
905
|
+
const left = isRightToLeft ? offset - lead() : lead() - offset;
|
|
906
|
+
item.scrollTo({ behavior: isSmooth ? 'smooth' : 'instant', left });
|
|
907
|
+
};
|
|
908
|
+
// The track's room on a side: the actions' width; across the whole row
|
|
909
|
+
// only while overswiping it is possible (see `overswipable`), so a scroll
|
|
910
|
+
// opening the actions stops at them, not past them (snapping back).
|
|
911
|
+
const roomOf = (side) => {
|
|
912
|
+
// Not swiped open (see `allowSwipe`): no room, unless open.
|
|
913
|
+
if (openSideRef.current !== side && !canReveal(side))
|
|
914
|
+
return 0;
|
|
915
|
+
const { [side]: width = 0 } = swipeRef.current.widths;
|
|
916
|
+
return overswipesNow(side)
|
|
917
|
+
? (swipeRef.current.extents[side] ?? width)
|
|
918
|
+
: width;
|
|
919
|
+
};
|
|
920
|
+
// Lays the track out for each side's room: its size, the snap points'
|
|
921
|
+
// places, the actions' reveal; the row kept where it is (the room before
|
|
922
|
+
// it moving the scroll position). The room grows at once, but narrows at
|
|
923
|
+
// rest only (`isAtRest`): narrowed, the track re-snaps at once (e.g.
|
|
924
|
+
// released from a drag, before snapping smoothly), and never less than
|
|
925
|
+
// where the row is.
|
|
926
|
+
const layOut = (isAtRest) => {
|
|
927
|
+
const { current: item } = itemRef;
|
|
928
|
+
if (!item)
|
|
929
|
+
return;
|
|
930
|
+
const offset = offsetOf(item);
|
|
931
|
+
const fit = (room, current, reach) => Math.max(isAtRest ? room : Math.max(room, current), reach);
|
|
932
|
+
const { current: wasLead } = leadRef;
|
|
933
|
+
const { current: wasTrail } = trailRef;
|
|
934
|
+
leadRef.current = fit(roomOf('leading'), leadRef.current, offset);
|
|
935
|
+
trailRef.current = fit(roomOf('trailing'), trailRef.current, -offset);
|
|
936
|
+
const isResized = leadRef.current !== wasLead || trailRef.current !== wasTrail;
|
|
937
|
+
item.style.setProperty('--uikit-list-swipe-lead', `${String(lead())}px`);
|
|
938
|
+
item.style.setProperty('--uikit-list-swipe-trail', `${String(trailRef.current)}px`);
|
|
939
|
+
const places = snapPlaces(swipeRef.current, lead(), overswipes);
|
|
940
|
+
placesRef.current = places;
|
|
941
|
+
for (const side of sides) {
|
|
942
|
+
const { [side]: container } = actionsRef.current;
|
|
943
|
+
if (!container)
|
|
944
|
+
continue;
|
|
945
|
+
revealRanges(container, side, lead());
|
|
946
|
+
// Safari keeps running its reveal (on the compositor) for the scroll
|
|
947
|
+
// range it started in, so scaling in out of order and flickering once
|
|
948
|
+
// the room changed (e.g. as a swipe starts, overswiping): restarted.
|
|
949
|
+
if (!isResized)
|
|
950
|
+
continue;
|
|
951
|
+
for (const animation of container.getAnimations({ subtree: true })) {
|
|
952
|
+
// (Not the stretched action's transitions.)
|
|
953
|
+
if (!(animation instanceof CSSAnimation))
|
|
954
|
+
continue;
|
|
955
|
+
animation.cancel();
|
|
956
|
+
animation.play();
|
|
957
|
+
}
|
|
958
|
+
}
|
|
959
|
+
for (const point of snapPoints) {
|
|
960
|
+
const snap = snapsRef.current[point];
|
|
961
|
+
if (snap)
|
|
962
|
+
snap.style.insetInlineStart = `${String(places[point] ?? 0)}px`;
|
|
963
|
+
}
|
|
964
|
+
// (Only if it moved: a scroll on its way, e.g. closing, goes on.)
|
|
965
|
+
if (offsetOf(item) !== offset)
|
|
966
|
+
scrollTo(offset, false);
|
|
967
|
+
};
|
|
615
968
|
// The snap points (see `snapPlaces`). Open, the other side's actions
|
|
616
969
|
// don't open (scrolled past closed, the row snaps back closed): only from
|
|
617
970
|
// closed; overswiped, only as above. (They change at rest, or as a touch
|
|
618
|
-
// starts, only: changed while scrolling, browsers snap at once.)
|
|
619
|
-
|
|
971
|
+
// starts, only: changed while scrolling, browsers snap at once.) Safari
|
|
972
|
+
// snaps to the point at the same place in their order once they change
|
|
973
|
+
// (e.g. armed, shown before closed as a touch starts), so the row is put
|
|
974
|
+
// back where it was.
|
|
975
|
+
const showSnaps = (isAtRest = false) => {
|
|
976
|
+
const { current: item } = itemRef;
|
|
977
|
+
const offset = item ? offsetOf(item) : undefined;
|
|
978
|
+
// (The room changing with them, see `layOut`.)
|
|
979
|
+
layOut(isAtRest);
|
|
620
980
|
const { current: openSide } = openSideRef;
|
|
621
981
|
for (const point of snapPoints) {
|
|
622
982
|
const snap = snapsRef.current[point];
|
|
623
983
|
if (!snap)
|
|
624
984
|
continue;
|
|
625
985
|
const side = point.startsWith('leading') ? 'leading' : 'trailing';
|
|
626
|
-
const
|
|
986
|
+
const isOverswiping = point.endsWith('Armed') || point.endsWith('Overswipe');
|
|
627
987
|
snap.hidden =
|
|
628
988
|
placesRef.current[point] === undefined ||
|
|
629
989
|
(openSide !== undefined && point !== 'closed' && side !== openSide) ||
|
|
630
|
-
(
|
|
990
|
+
(isOverswiping && !overswipable(side));
|
|
991
|
+
}
|
|
992
|
+
if (item && offset !== undefined && offsetOf(item) !== offset) {
|
|
993
|
+
scrollTo(offset, false);
|
|
631
994
|
}
|
|
632
|
-
};
|
|
633
|
-
const scrollTo = (offset, smooth) => {
|
|
634
|
-
const { current: item } = itemRef;
|
|
635
|
-
if (!item)
|
|
636
|
-
return;
|
|
637
|
-
const rtl = isRtl(item);
|
|
638
|
-
const left = rtl ? offset - lead() : lead() - offset;
|
|
639
|
-
item.scrollTo({ behavior: smooth ? 'smooth' : 'instant', left });
|
|
640
995
|
};
|
|
641
996
|
// Measures the actions (and the row) for the track's room and snap
|
|
642
997
|
// points, keeping the row where it is (closed, or open).
|
|
@@ -657,23 +1012,7 @@ const Item = forwardRef((itemProps, ref) => {
|
|
|
657
1012
|
swipe.extents[side] = overswipes(side) ? item.clientWidth : width;
|
|
658
1013
|
}
|
|
659
1014
|
swipeRef.current = swipe;
|
|
660
|
-
|
|
661
|
-
item.style.setProperty('--uikit-list-swipe-trail', `${String(swipe.extents.trailing ?? 0)}px`);
|
|
662
|
-
const places = snapPlaces(swipe, lead(), overswipes);
|
|
663
|
-
placesRef.current = places;
|
|
664
|
-
for (const side of sides) {
|
|
665
|
-
const { [side]: container } = actionsRef.current;
|
|
666
|
-
if (container)
|
|
667
|
-
revealRanges(container, side, lead());
|
|
668
|
-
}
|
|
669
|
-
for (const point of snapPoints) {
|
|
670
|
-
const snap = snapsRef.current[point];
|
|
671
|
-
if (!snap)
|
|
672
|
-
continue;
|
|
673
|
-
const place = places[point];
|
|
674
|
-
snap.hidden = place === undefined;
|
|
675
|
-
snap.style.insetInlineStart = `${String(place ?? 0)}px`;
|
|
676
|
-
}
|
|
1015
|
+
showSnaps(true);
|
|
677
1016
|
const { current: side } = openSideRef;
|
|
678
1017
|
const offset = side
|
|
679
1018
|
? (side === 'leading' ? 1 : -1) * (swipe.widths[side] ?? 0)
|
|
@@ -695,6 +1034,18 @@ const Item = forwardRef((itemProps, ref) => {
|
|
|
695
1034
|
}
|
|
696
1035
|
item.style.removeProperty('clip-path');
|
|
697
1036
|
};
|
|
1037
|
+
// As allowed (see `allowSwipe`), keyboards too: open, not swiped closed,
|
|
1038
|
+
// no scrolling (closed by scrolling it programmatically only); closed,
|
|
1039
|
+
// not swiped open, its actions inert (not revealed by focusing them).
|
|
1040
|
+
const lock = () => {
|
|
1041
|
+
const { current: openSide } = openSideRef;
|
|
1042
|
+
itemRef.current?.toggleAttribute('data-swipe-locked', openSide !== undefined && !canConceal(openSide));
|
|
1043
|
+
for (const side of sides) {
|
|
1044
|
+
const { [side]: container } = actionsRef.current;
|
|
1045
|
+
if (container)
|
|
1046
|
+
container.inert = openSide !== side && !canReveal(side);
|
|
1047
|
+
}
|
|
1048
|
+
};
|
|
698
1049
|
const context = useMemo(() => {
|
|
699
1050
|
const value = {
|
|
700
1051
|
close: () => {
|
|
@@ -709,9 +1060,19 @@ const Item = forwardRef((itemProps, ref) => {
|
|
|
709
1060
|
openSideRef.current = undefined;
|
|
710
1061
|
restingOpenRef.current = false;
|
|
711
1062
|
closingRef.current = true;
|
|
1063
|
+
lock();
|
|
712
1064
|
// (Its snap points change once closed, see `settle`.)
|
|
713
1065
|
scrollTo(0, true);
|
|
714
1066
|
},
|
|
1067
|
+
focus: (side) => {
|
|
1068
|
+
if (openSideRef.current !== side)
|
|
1069
|
+
return;
|
|
1070
|
+
// (The row scrolling to show them on its own.)
|
|
1071
|
+
actionsRef.current[side]
|
|
1072
|
+
?.querySelector('button:not(:disabled)')
|
|
1073
|
+
?.focus({ preventScroll: true });
|
|
1074
|
+
},
|
|
1075
|
+
isOpen: (side) => openSideRef.current === side,
|
|
715
1076
|
open: (side) => {
|
|
716
1077
|
const { current: item } = itemRef;
|
|
717
1078
|
const width = swipeRef.current.widths[side];
|
|
@@ -723,12 +1084,15 @@ const Item = forwardRef((itemProps, ref) => {
|
|
|
723
1084
|
if (openSideRef.current !== side)
|
|
724
1085
|
restingOpenRef.current = false;
|
|
725
1086
|
openSideRef.current = side;
|
|
1087
|
+
lock();
|
|
726
1088
|
showSnaps();
|
|
727
1089
|
scrollTo((side === 'leading' ? 1 : -1) * width, true);
|
|
728
1090
|
if (outsideRef.current)
|
|
729
1091
|
return;
|
|
730
1092
|
outsideRef.current = (event) => {
|
|
731
|
-
|
|
1093
|
+
// Not swiped closed (see `allowSwipe`): nor by a press outside.
|
|
1094
|
+
if ((event.target instanceof Node && item.contains(event.target)) ||
|
|
1095
|
+
(openSideRef.current && !canConceal(openSideRef.current))) {
|
|
732
1096
|
return;
|
|
733
1097
|
}
|
|
734
1098
|
value.close();
|
|
@@ -737,15 +1101,17 @@ const Item = forwardRef((itemProps, ref) => {
|
|
|
737
1101
|
capture: true,
|
|
738
1102
|
});
|
|
739
1103
|
},
|
|
740
|
-
setActions: (side, element, overswipe = false) => {
|
|
1104
|
+
setActions: (side, element, overswipe = false, allowSwipe = 'all') => {
|
|
741
1105
|
overswipeRef.current[side] = overswipe;
|
|
1106
|
+
allowRef.current[side] = allowSwipe;
|
|
742
1107
|
if (element) {
|
|
743
1108
|
actionsRef.current[side] = element;
|
|
744
1109
|
}
|
|
745
1110
|
else {
|
|
746
1111
|
delete actionsRef.current[side];
|
|
747
1112
|
}
|
|
748
|
-
|
|
1113
|
+
lock();
|
|
1114
|
+
setIsSwipeable(Boolean(actionsRef.current.leading ?? actionsRef.current.trailing));
|
|
749
1115
|
measureRef.current();
|
|
750
1116
|
},
|
|
751
1117
|
};
|
|
@@ -781,11 +1147,32 @@ const Item = forwardRef((itemProps, ref) => {
|
|
|
781
1147
|
if (container)
|
|
782
1148
|
outermostAction(container, side)?.click();
|
|
783
1149
|
};
|
|
1150
|
+
// Not swiped closed (see `allowSwipe`): nor scrolled closed otherwise
|
|
1151
|
+
// (e.g. by the browser, focusing the row's content), open again.
|
|
1152
|
+
const reopen = () => {
|
|
1153
|
+
const { current: openSide } = openSideRef;
|
|
1154
|
+
if (!openSide || canConceal(openSide))
|
|
1155
|
+
return false;
|
|
1156
|
+
const { [openSide]: width = 0 } = swipeRef.current.widths;
|
|
1157
|
+
scrollTo((openSide === 'leading' ? 1 : -1) * width, true);
|
|
1158
|
+
return true;
|
|
1159
|
+
};
|
|
1160
|
+
// Closed, at rest.
|
|
1161
|
+
const restClosed = (item) => {
|
|
1162
|
+
swipingRef.current = false;
|
|
1163
|
+
restingOpenRef.current = false;
|
|
1164
|
+
openSideRef.current = undefined;
|
|
1165
|
+
lock();
|
|
1166
|
+
showSnaps(true);
|
|
1167
|
+
if (closeOpenItem === context.close)
|
|
1168
|
+
closeOpenItem = undefined;
|
|
1169
|
+
resetRow(item);
|
|
1170
|
+
};
|
|
784
1171
|
// The scroll at rest (not touched): overswiped (armed, or across the
|
|
785
1172
|
// whole row: triggering there), open or closed.
|
|
786
1173
|
const settle = () => {
|
|
787
1174
|
const { current: item } = itemRef;
|
|
788
|
-
if (!item || dragRef.current?.
|
|
1175
|
+
if (!item || dragRef.current?.isMoved || touchingRef.current)
|
|
789
1176
|
return;
|
|
790
1177
|
item.style.removeProperty('scroll-snap-type');
|
|
791
1178
|
const offset = offsetOf(item);
|
|
@@ -794,15 +1181,11 @@ const Item = forwardRef((itemProps, ref) => {
|
|
|
794
1181
|
const { [side]: width = 0 } = swipeRef.current.widths;
|
|
795
1182
|
const { [side]: extent = 0 } = swipeRef.current.extents;
|
|
796
1183
|
const { [side]: arm = Infinity } = swipeRef.current.arms;
|
|
1184
|
+
const { current: isClosing } = closingRef;
|
|
797
1185
|
closingRef.current = false;
|
|
798
1186
|
if (distance < 1) {
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
openSideRef.current = undefined;
|
|
802
|
-
showSnaps();
|
|
803
|
-
if (closeOpenItem === context.close)
|
|
804
|
-
closeOpenItem = undefined;
|
|
805
|
-
resetRow(item);
|
|
1187
|
+
if (isClosing || !reopen())
|
|
1188
|
+
restClosed(item);
|
|
806
1189
|
return;
|
|
807
1190
|
}
|
|
808
1191
|
if (overswipesNow(side) && distance > arm) {
|
|
@@ -821,9 +1204,18 @@ const Item = forwardRef((itemProps, ref) => {
|
|
|
821
1204
|
if (Math.abs(distance - width) < 1) {
|
|
822
1205
|
if (openSideRef.current !== side)
|
|
823
1206
|
context.open(side);
|
|
1207
|
+
// Scrolled open (stopped at the actions, see `roomOf`): at rest only
|
|
1208
|
+
// once the wheel (a trackpad's momentum too) is quiet, so the same
|
|
1209
|
+
// scroll doesn't overswipe.
|
|
1210
|
+
const quiet = performance.now() - wheelRef.current;
|
|
1211
|
+
if (quiet < wheelQuiet) {
|
|
1212
|
+
clearTimeout(settleRef.current);
|
|
1213
|
+
settleRef.current = setTimeout(settle, wheelQuiet - quiet);
|
|
1214
|
+
return;
|
|
1215
|
+
}
|
|
824
1216
|
restingOpenRef.current = true;
|
|
825
1217
|
}
|
|
826
|
-
showSnaps();
|
|
1218
|
+
showSnaps(true);
|
|
827
1219
|
};
|
|
828
1220
|
// Scrolled (by any means): the row's actions follow, overswiping arms
|
|
829
1221
|
// past its distance.
|
|
@@ -835,18 +1227,23 @@ const Item = forwardRef((itemProps, ref) => {
|
|
|
835
1227
|
const side = offset > 0 ? 'leading' : 'trailing';
|
|
836
1228
|
if (Math.abs(offset) >= 1) {
|
|
837
1229
|
item.dataset.swipe = side;
|
|
838
|
-
|
|
1230
|
+
// (Swiped, it closes another row's; closing, not: e.g. as another
|
|
1231
|
+
// opens by a trigger, which its scroll would close again.)
|
|
1232
|
+
if (!closingRef.current &&
|
|
1233
|
+
closeOpenItem &&
|
|
1234
|
+
closeOpenItem !== context.close) {
|
|
839
1235
|
closeOpenItem();
|
|
1236
|
+
}
|
|
840
1237
|
}
|
|
841
1238
|
placeRow(item, actionsRef.current, offset, false, overswipesNow);
|
|
842
1239
|
const { [side]: arm = Infinity } = swipeRef.current.arms;
|
|
843
|
-
const
|
|
1240
|
+
const isArmed = !closingRef.current && overswipesNow(side) && Math.abs(offset) > arm;
|
|
844
1241
|
for (const key of sides) {
|
|
845
1242
|
const { [key]: actions } = actionsRef.current;
|
|
846
1243
|
const action = actions && outermostAction(actions, key);
|
|
847
|
-
action?.toggleAttribute('data-armed',
|
|
1244
|
+
action?.toggleAttribute('data-armed', isArmed && key === side);
|
|
848
1245
|
}
|
|
849
|
-
if (
|
|
1246
|
+
if (hasScrollEnd)
|
|
850
1247
|
return;
|
|
851
1248
|
clearTimeout(settleRef.current);
|
|
852
1249
|
settleRef.current = setTimeout(settle, scrollEndDelay);
|
|
@@ -860,9 +1257,12 @@ const Item = forwardRef((itemProps, ref) => {
|
|
|
860
1257
|
});
|
|
861
1258
|
useEffect(() => {
|
|
862
1259
|
const { current: item } = itemRef;
|
|
863
|
-
if (!item || !
|
|
1260
|
+
if (!item || !isSwipeable)
|
|
864
1261
|
return undefined;
|
|
865
1262
|
const onScrollEnd = () => settleNowRef.current();
|
|
1263
|
+
const onWheel = () => {
|
|
1264
|
+
wheelRef.current = performance.now();
|
|
1265
|
+
};
|
|
866
1266
|
const onTouchStart = () => {
|
|
867
1267
|
touchingRef.current = true;
|
|
868
1268
|
// Swiped: overswiping in one go (see `overswipable`).
|
|
@@ -877,19 +1277,21 @@ const Item = forwardRef((itemProps, ref) => {
|
|
|
877
1277
|
settleRef.current = setTimeout(onScrollEnd, scrollEndDelay);
|
|
878
1278
|
};
|
|
879
1279
|
item.addEventListener('scrollend', onScrollEnd);
|
|
1280
|
+
item.addEventListener('wheel', onWheel, { passive: true });
|
|
880
1281
|
item.addEventListener('touchstart', onTouchStart, { passive: true });
|
|
881
1282
|
item.addEventListener('touchend', onTouchEnd);
|
|
882
1283
|
item.addEventListener('touchcancel', onTouchEnd);
|
|
883
1284
|
return () => {
|
|
884
1285
|
item.removeEventListener('scrollend', onScrollEnd);
|
|
1286
|
+
item.removeEventListener('wheel', onWheel);
|
|
885
1287
|
item.removeEventListener('touchstart', onTouchStart);
|
|
886
1288
|
item.removeEventListener('touchend', onTouchEnd);
|
|
887
1289
|
item.removeEventListener('touchcancel', onTouchEnd);
|
|
888
1290
|
};
|
|
889
|
-
}, [itemRef,
|
|
1291
|
+
}, [itemRef, isSwipeable]);
|
|
890
1292
|
useLayoutEffect(() => {
|
|
891
1293
|
const { current: item } = itemRef;
|
|
892
|
-
if (!item || !
|
|
1294
|
+
if (!item || !isSwipeable)
|
|
893
1295
|
return undefined;
|
|
894
1296
|
measureRef.current();
|
|
895
1297
|
const observer = new ResizeObserver(() => measureRef.current());
|
|
@@ -900,7 +1302,7 @@ const Item = forwardRef((itemProps, ref) => {
|
|
|
900
1302
|
observer.observe(container);
|
|
901
1303
|
}
|
|
902
1304
|
return () => observer.disconnect();
|
|
903
|
-
}, [itemRef,
|
|
1305
|
+
}, [itemRef, isSwipeable]);
|
|
904
1306
|
const release = () => {
|
|
905
1307
|
if (itemRef.current)
|
|
906
1308
|
delete itemRef.current.dataset.pressed;
|
|
@@ -916,7 +1318,7 @@ const Item = forwardRef((itemProps, ref) => {
|
|
|
916
1318
|
if (props.onClick && !(control && item.contains(control))) {
|
|
917
1319
|
item.dataset.pressed = '';
|
|
918
1320
|
}
|
|
919
|
-
if (!
|
|
1321
|
+
if (!isSwipeable ||
|
|
920
1322
|
sides.some((side) => actions[side]?.contains(event.target))) {
|
|
921
1323
|
return;
|
|
922
1324
|
}
|
|
@@ -925,14 +1327,18 @@ const Item = forwardRef((itemProps, ref) => {
|
|
|
925
1327
|
x: event.clientX,
|
|
926
1328
|
y: event.clientY,
|
|
927
1329
|
};
|
|
928
|
-
// Touch scrolls natively; a mouse drags the scroll position
|
|
1330
|
+
// Touch scrolls natively; a mouse drags the scroll position, as allowed
|
|
1331
|
+
// (see `allowSwipe`; touch: by the room, and the lock, see style.css).
|
|
929
1332
|
if (event.pointerType !== 'mouse' || isOwnGesture(item, event))
|
|
930
1333
|
return;
|
|
1334
|
+
const { current: openSide } = openSideRef;
|
|
1335
|
+
if (openSide ? !canConceal(openSide) : sides.every((side) => !canReveal(side))) {
|
|
1336
|
+
return;
|
|
1337
|
+
}
|
|
931
1338
|
dragRef.current = {
|
|
932
1339
|
base: offsetOf(item),
|
|
933
|
-
|
|
1340
|
+
isMoved: false,
|
|
934
1341
|
pointerId: event.pointerId,
|
|
935
|
-
scroll: item.scrollLeft,
|
|
936
1342
|
time: performance.now(),
|
|
937
1343
|
x: event.clientX,
|
|
938
1344
|
y: event.clientY,
|
|
@@ -945,7 +1351,7 @@ const Item = forwardRef((itemProps, ref) => {
|
|
|
945
1351
|
if (!item || drag?.pointerId !== event.pointerId)
|
|
946
1352
|
return;
|
|
947
1353
|
const dx = event.clientX - drag.x;
|
|
948
|
-
if (!drag.
|
|
1354
|
+
if (!drag.isMoved) {
|
|
949
1355
|
const vertical = Math.abs(event.clientY - drag.y);
|
|
950
1356
|
if (vertical > swipeThreshold && vertical > Math.abs(dx)) {
|
|
951
1357
|
dragRef.current = null;
|
|
@@ -953,7 +1359,7 @@ const Item = forwardRef((itemProps, ref) => {
|
|
|
953
1359
|
}
|
|
954
1360
|
if (Math.abs(dx) < swipeThreshold)
|
|
955
1361
|
return;
|
|
956
|
-
drag.
|
|
1362
|
+
drag.isMoved = true;
|
|
957
1363
|
// Swiped: overswiping in one go (see `overswipable`).
|
|
958
1364
|
swipingRef.current = true;
|
|
959
1365
|
release();
|
|
@@ -961,12 +1367,13 @@ const Item = forwardRef((itemProps, ref) => {
|
|
|
961
1367
|
item.style.scrollSnapType = 'none';
|
|
962
1368
|
showSnaps();
|
|
963
1369
|
}
|
|
964
|
-
// The content follows the pointer
|
|
965
|
-
|
|
1370
|
+
// The content follows the pointer (by its offset: the room before it
|
|
1371
|
+
// grows as the swipe starts, see `showSnaps`).
|
|
1372
|
+
scrollTo(drag.base + (isRtl(item) ? -dx : dx), false);
|
|
966
1373
|
};
|
|
967
1374
|
// A mouse drag released: overswiped (armed), opened (past half its
|
|
968
1375
|
// actions, or quickly towards them) or closed, scrolling there.
|
|
969
|
-
const endDrag = (drag,
|
|
1376
|
+
const endDrag = (drag, isCancelled) => {
|
|
970
1377
|
const { current: item } = itemRef;
|
|
971
1378
|
if (!item)
|
|
972
1379
|
return;
|
|
@@ -977,10 +1384,10 @@ const Item = forwardRef((itemProps, ref) => {
|
|
|
977
1384
|
const { [side]: arm = Infinity } = swipeRef.current.arms;
|
|
978
1385
|
suppressClick();
|
|
979
1386
|
// Open, the other side doesn't (see `showSnaps`).
|
|
980
|
-
const
|
|
1387
|
+
const isLocked = openSideRef.current !== undefined && openSideRef.current !== side;
|
|
981
1388
|
// Across the whole row, triggering there (see `settle`): not snapping
|
|
982
1389
|
// until then (which would start where it is).
|
|
983
|
-
if (!
|
|
1390
|
+
if (!isLocked && !isCancelled && overswipesNow(side) && distance > arm) {
|
|
984
1391
|
const { [side]: extent = 0 } = swipeRef.current.extents;
|
|
985
1392
|
scrollTo((side === 'leading' ? 1 : -1) * extent, true);
|
|
986
1393
|
return;
|
|
@@ -989,30 +1396,28 @@ const Item = forwardRef((itemProps, ref) => {
|
|
|
989
1396
|
// where it's dragged, as far as overswiped).
|
|
990
1397
|
swipingRef.current = false;
|
|
991
1398
|
showSnaps();
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
1399
|
+
const isOpening = !isLocked && !isCancelled && opensOnRelease(drag, offset, side, width);
|
|
1400
|
+
// Snapping again once at rest there (see `settle`): snapping now, the
|
|
1401
|
+
// browser would snap at once, not smoothly. (Already there: now.)
|
|
1402
|
+
if (Math.abs(distance - (isOpening ? (width ?? 0) : 0)) < 1) {
|
|
1403
|
+
item.style.removeProperty('scroll-snap-type');
|
|
996
1404
|
}
|
|
997
|
-
|
|
998
|
-
const quick = performance.now() - drag.time < 300;
|
|
999
|
-
const towards = side === 'leading' ? moved > 10 : moved < -10;
|
|
1000
|
-
if (quick ? towards : distance > width / 2) {
|
|
1405
|
+
if (isOpening) {
|
|
1001
1406
|
context.open(side);
|
|
1002
1407
|
}
|
|
1003
1408
|
else {
|
|
1004
1409
|
context.close();
|
|
1005
1410
|
}
|
|
1006
1411
|
};
|
|
1007
|
-
const finish = (event,
|
|
1412
|
+
const finish = (event, isCancelled) => {
|
|
1008
1413
|
const { current: press } = pressRef;
|
|
1009
1414
|
const { current: drag } = dragRef;
|
|
1010
1415
|
if (press?.pointerId === event.pointerId)
|
|
1011
1416
|
pressRef.current = null;
|
|
1012
1417
|
if (drag?.pointerId === event.pointerId) {
|
|
1013
1418
|
dragRef.current = null;
|
|
1014
|
-
if (drag.
|
|
1015
|
-
endDrag(drag,
|
|
1419
|
+
if (drag.isMoved) {
|
|
1420
|
+
endDrag(drag, isCancelled);
|
|
1016
1421
|
return;
|
|
1017
1422
|
}
|
|
1018
1423
|
}
|
|
@@ -1020,7 +1425,7 @@ const Item = forwardRef((itemProps, ref) => {
|
|
|
1020
1425
|
return;
|
|
1021
1426
|
// A tap on an open row closes it.
|
|
1022
1427
|
const moved = Math.hypot(event.clientX - press.x, event.clientY - press.y);
|
|
1023
|
-
if (!
|
|
1428
|
+
if (!isCancelled && moved < swipeThreshold && openSideRef.current) {
|
|
1024
1429
|
context.close();
|
|
1025
1430
|
suppressClick();
|
|
1026
1431
|
}
|
|
@@ -1028,10 +1433,15 @@ const Item = forwardRef((itemProps, ref) => {
|
|
|
1028
1433
|
const handleBlurCapture = (event) => {
|
|
1029
1434
|
onBlurCapture?.(event);
|
|
1030
1435
|
const { current: item } = itemRef;
|
|
1031
|
-
|
|
1436
|
+
const { current: openSide } = openSideRef;
|
|
1437
|
+
// Not swiped closed (see `allowSwipe`): nor by focus leaving it.
|
|
1438
|
+
if (!openSide || !item || !canConceal(openSide))
|
|
1032
1439
|
return;
|
|
1440
|
+
// Focus moving elsewhere only (e.g. tabbing on): not to nothing, as
|
|
1441
|
+
// WebKit's, pressing a button (its actions' too) not focusing it (a
|
|
1442
|
+
// press outside closes it, see `open`).
|
|
1033
1443
|
const { relatedTarget } = event;
|
|
1034
|
-
if (relatedTarget instanceof Node
|
|
1444
|
+
if (!(relatedTarget instanceof Node) || item.contains(relatedTarget)) {
|
|
1035
1445
|
return;
|
|
1036
1446
|
}
|
|
1037
1447
|
context.close();
|
|
@@ -1044,9 +1454,9 @@ const Item = forwardRef((itemProps, ref) => {
|
|
|
1044
1454
|
event.preventDefault();
|
|
1045
1455
|
event.stopPropagation();
|
|
1046
1456
|
};
|
|
1047
|
-
return (_jsx(ItemContext.Provider, { value: context, children: _jsx(StyledItem, { ref: itemRef, "aria-current": selected ? 'true' : undefined, "data-clickable": props.onClick ? '' : undefined, "data-selected": selected ? '' : undefined, "data-swipeable":
|
|
1457
|
+
return (_jsx(ItemContext.Provider, { value: context, children: _jsx(StyledItem, { ref: itemRef, "aria-current": selected ? 'true' : undefined, "data-clickable": props.onClick ? '' : undefined, "data-edit-leading": editSide(editing, 'leading'), "data-edit-trailing": editSide(editing, 'trailing'), "data-selected": selected ? '' : undefined, "data-swipeable": isSwipeable ? '' : undefined, id: id, style: withStyle({
|
|
1048
1458
|
'--uikit-list-level': level === undefined ? undefined : String(level),
|
|
1049
|
-
}, style), ...props, onBlurCapture: handleBlurCapture, onClickCapture: handleClickCapture, onPointerDown: handlePointerDown, onPointerMove: handlePointerMove, onScroll:
|
|
1459
|
+
}, style), ...props, onBlurCapture: handleBlurCapture, onClickCapture: handleClickCapture, onPointerDown: handlePointerDown, onPointerMove: handlePointerMove, onScroll: isSwipeable ? onScroll : undefined, onLostPointerCapture: (event) => {
|
|
1050
1460
|
onLostPointerCapture?.(event);
|
|
1051
1461
|
// Only the row's own capture: taking it over from the touched
|
|
1052
1462
|
// element (implicitly captured) makes that lose its capture.
|
|
@@ -1061,84 +1471,124 @@ const Item = forwardRef((itemProps, ref) => {
|
|
|
1061
1471
|
onPointerUp?.(event);
|
|
1062
1472
|
release();
|
|
1063
1473
|
finish(event, false);
|
|
1064
|
-
}, children: _jsxs("div", { className: "uikit-list-track", "data-list-part": "track", children: [_jsx(Pin, { ref: setPin }),
|
|
1474
|
+
}, children: _jsxs("div", { className: "uikit-list-track", "data-list-part": "track", children: [_jsx(Pin, { ref: setPin }), isSwipeable
|
|
1065
1475
|
? snapPoints.map((point) => (_jsx("span", { ref: (element) => {
|
|
1066
1476
|
snapsRef.current[point] = element;
|
|
1067
1477
|
}, hidden: true, "aria-hidden": "true", className: "uikit-list-snap", "data-closed": point === 'closed' ? '' : undefined, "data-list-part": "snap" }, point)))
|
|
1068
1478
|
: null, _jsx(PinContext.Provider, { value: pin, children: _jsx("div", { className: "uikit-list-row", "data-list-part": "row", children: children }) })] }) }) }));
|
|
1069
1479
|
});
|
|
1070
|
-
|
|
1071
|
-
|
|
1480
|
+
// Row slots (see style.css): a row's parts in a line, in their order;
|
|
1481
|
+
// elements of other components only in these.
|
|
1072
1482
|
/**
|
|
1073
|
-
*
|
|
1074
|
-
*
|
|
1075
|
-
* `DatePicker` (without popovers, as iOS's Calendar). Closed, it's inert.
|
|
1483
|
+
* Any elements before a row's content (e.g. a spinner, an avatar), in a
|
|
1484
|
+
* line; several per row; sliding in or out in edit mode (`whileEditing`).
|
|
1076
1485
|
*/
|
|
1077
|
-
const
|
|
1078
|
-
|
|
1079
|
-
|
|
1486
|
+
const Leading = forwardRef(({ className, render, whileEditing, ...props }, ref) => useRender({
|
|
1487
|
+
defaultTagName: 'span',
|
|
1488
|
+
props: {
|
|
1489
|
+
'data-list-part': 'leading',
|
|
1490
|
+
...whileEditingOf(whileEditing),
|
|
1491
|
+
className: cn('uikit-list-leading', className),
|
|
1492
|
+
...props,
|
|
1493
|
+
},
|
|
1494
|
+
ref,
|
|
1495
|
+
render,
|
|
1496
|
+
}));
|
|
1497
|
+
/**
|
|
1498
|
+
* Any elements after a row's content (e.g. a `Switch`, a `Stepper`), in a
|
|
1499
|
+
* line; several per row; sliding in or out in edit mode (`whileEditing`).
|
|
1500
|
+
*/
|
|
1501
|
+
const Trailing = forwardRef(({ className, render, whileEditing, ...props }, ref) => useRender({
|
|
1502
|
+
defaultTagName: 'span',
|
|
1503
|
+
props: {
|
|
1504
|
+
'data-list-part': 'trailing',
|
|
1505
|
+
...whileEditingOf(whileEditing),
|
|
1506
|
+
className: cn('uikit-list-trailing', className),
|
|
1507
|
+
...props,
|
|
1508
|
+
},
|
|
1509
|
+
ref,
|
|
1510
|
+
render,
|
|
1511
|
+
}));
|
|
1512
|
+
/**
|
|
1513
|
+
* A row's text (its `Title`, `Subtitle`, `Text`; or a field's label),
|
|
1514
|
+
* taking the rest of its line; every row has one (or a `Span`).
|
|
1515
|
+
*/
|
|
1516
|
+
const Content = forwardRef(({ className, render, ...props }, ref) => useRender({
|
|
1517
|
+
defaultTagName: 'span',
|
|
1518
|
+
props: {
|
|
1519
|
+
'data-list-part': 'content',
|
|
1520
|
+
className: cn('uikit-list-content', className),
|
|
1521
|
+
...props,
|
|
1522
|
+
},
|
|
1523
|
+
ref,
|
|
1524
|
+
render,
|
|
1525
|
+
}));
|
|
1526
|
+
/**
|
|
1527
|
+
* Content across a row's whole line (e.g. a `Slider` between its symbols,
|
|
1528
|
+
* a `Segmented` control, an inline calendar).
|
|
1529
|
+
*/
|
|
1530
|
+
const Span = forwardRef(({ className, render, ...props }, ref) => useRender({
|
|
1531
|
+
defaultTagName: 'span',
|
|
1532
|
+
props: {
|
|
1533
|
+
'data-list-part': 'span',
|
|
1534
|
+
className: cn('uikit-list-span', className),
|
|
1535
|
+
...props,
|
|
1536
|
+
},
|
|
1537
|
+
ref,
|
|
1538
|
+
render,
|
|
1539
|
+
}));
|
|
1540
|
+
/**
|
|
1541
|
+
* A `Below`'s start: its row's content's (after the leading parts, e.g. an
|
|
1542
|
+
* image, edit controls), as `--uikit-list-below-start`; measured, again as
|
|
1543
|
+
* the row's parts resize (e.g. entering edit mode).
|
|
1544
|
+
*/
|
|
1545
|
+
const useBelowStart = (below) => {
|
|
1080
1546
|
useLayoutEffect(() => {
|
|
1081
|
-
const { current:
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
shown.current = open;
|
|
1086
|
-
const settle = () => {
|
|
1087
|
-
item.toggleAttribute('data-closed', !open);
|
|
1088
|
-
item.inert = !open;
|
|
1089
|
-
};
|
|
1090
|
-
if (was === undefined || was === open) {
|
|
1091
|
-
settle();
|
|
1547
|
+
const { current: element } = below;
|
|
1548
|
+
const row = element?.parentElement;
|
|
1549
|
+
const content = row?.querySelector(':scope > :is([data-list-part="content"], [data-list-part="span"])');
|
|
1550
|
+
if (!element || !row || !content)
|
|
1092
1551
|
return undefined;
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
paddingBottom: style.paddingBottom,
|
|
1103
|
-
paddingTop: style.paddingTop,
|
|
1104
|
-
};
|
|
1552
|
+
const measure = () => {
|
|
1553
|
+
const style = getComputedStyle(row);
|
|
1554
|
+
const rowRect = row.getBoundingClientRect();
|
|
1555
|
+
const contentRect = content.getBoundingClientRect();
|
|
1556
|
+
const offset = style.direction === 'rtl'
|
|
1557
|
+
? rowRect.right - contentRect.right
|
|
1558
|
+
: contentRect.left - rowRect.left;
|
|
1559
|
+
const start = Math.max(offset - Number.parseFloat(style.paddingInlineStart), 0);
|
|
1560
|
+
element.style.setProperty('--uikit-list-below-start', `${String(start)}px`);
|
|
1105
1561
|
};
|
|
1106
|
-
|
|
1107
|
-
const
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
const to = open ? box(item) : closed;
|
|
1111
|
-
item.inert = !open;
|
|
1112
|
-
item.style.overflow = 'clip';
|
|
1113
|
-
const animation = item.animate([
|
|
1114
|
-
{
|
|
1115
|
-
...from,
|
|
1116
|
-
minHeight: '0px',
|
|
1117
|
-
opacity: open ? 0 : 1,
|
|
1118
|
-
visibility: 'visible',
|
|
1119
|
-
},
|
|
1120
|
-
{
|
|
1121
|
-
...to,
|
|
1122
|
-
minHeight: '0px',
|
|
1123
|
-
opacity: open ? 1 : 0,
|
|
1124
|
-
visibility: 'visible',
|
|
1125
|
-
},
|
|
1126
|
-
], { duration: expandDuration, easing: 'ease' });
|
|
1127
|
-
const done = () => {
|
|
1128
|
-
item.style.removeProperty('overflow');
|
|
1129
|
-
if (!open)
|
|
1130
|
-
settle();
|
|
1131
|
-
};
|
|
1132
|
-
animation.finished.then(done).catch(() => undefined);
|
|
1562
|
+
measure();
|
|
1563
|
+
const observer = new ResizeObserver(measure);
|
|
1564
|
+
observer.observe(row);
|
|
1565
|
+
observer.observe(content);
|
|
1133
1566
|
return () => {
|
|
1134
|
-
|
|
1135
|
-
item.style.removeProperty('overflow');
|
|
1136
|
-
settle();
|
|
1567
|
+
observer.disconnect();
|
|
1137
1568
|
};
|
|
1138
|
-
}, [
|
|
1139
|
-
|
|
1569
|
+
}, [below]);
|
|
1570
|
+
};
|
|
1571
|
+
/**
|
|
1572
|
+
* A line under a row's line, across it from where its content starts (e.g.
|
|
1573
|
+
* a field's description and error, a status, a message's preview); last in
|
|
1574
|
+
* its row. Hidden (`hidden`), it collapses: growing and shrinking as it's
|
|
1575
|
+
* shown and hidden (kept rendered).
|
|
1576
|
+
*/
|
|
1577
|
+
const Below = forwardRef(({ className, render, ...props }, forwardedRef) => {
|
|
1578
|
+
const ref = useForwardedRef(forwardedRef);
|
|
1579
|
+
useBelowStart(ref);
|
|
1580
|
+
return useRender({
|
|
1581
|
+
defaultTagName: 'div',
|
|
1582
|
+
props: {
|
|
1583
|
+
'data-list-part': 'below',
|
|
1584
|
+
className: cn('uikit-list-below', className),
|
|
1585
|
+
...props,
|
|
1586
|
+
},
|
|
1587
|
+
ref,
|
|
1588
|
+
render,
|
|
1589
|
+
});
|
|
1140
1590
|
});
|
|
1141
|
-
//
|
|
1591
|
+
// A row's title; as a link or button (`render`), it makes the row pressable.
|
|
1142
1592
|
const Title = forwardRef(({ className, render, ...props }, ref) => useRender({
|
|
1143
1593
|
defaultTagName: 'span',
|
|
1144
1594
|
props: {
|
|
@@ -1150,7 +1600,7 @@ const Title = forwardRef(({ className, render, ...props }, ref) => useRender({
|
|
|
1150
1600
|
ref,
|
|
1151
1601
|
render,
|
|
1152
1602
|
}));
|
|
1153
|
-
//
|
|
1603
|
+
// A subtitle (rows), or a supertitle or subtitle (headers).
|
|
1154
1604
|
const Subtitle = forwardRef(({ className, render, ...props }, ref) => useRender({
|
|
1155
1605
|
defaultTagName: 'span',
|
|
1156
1606
|
props: {
|
|
@@ -1185,7 +1635,7 @@ const Supertitle = forwardRef(({ className, render, ...props }, ref) => useRende
|
|
|
1185
1635
|
ref,
|
|
1186
1636
|
render,
|
|
1187
1637
|
}));
|
|
1188
|
-
//
|
|
1638
|
+
// A detail (trailing text).
|
|
1189
1639
|
const Detail = forwardRef(({ className, render, ...props }, ref) => useRender({
|
|
1190
1640
|
defaultTagName: 'span',
|
|
1191
1641
|
props: {
|
|
@@ -1196,7 +1646,7 @@ const Detail = forwardRef(({ className, render, ...props }, ref) => useRender({
|
|
|
1196
1646
|
ref,
|
|
1197
1647
|
render,
|
|
1198
1648
|
}));
|
|
1199
|
-
//
|
|
1649
|
+
// A symbol, or an image (`img`, `video`, `canvas` filling
|
|
1200
1650
|
// it, or a symbol) in a rounded, circular or square frame.
|
|
1201
1651
|
const Image = forwardRef(({ className, render, variant = 'symbol', ...props }, ref) => useRender({
|
|
1202
1652
|
defaultTagName: 'span',
|
|
@@ -1209,7 +1659,7 @@ const Image = forwardRef(({ className, render, variant = 'symbol', ...props }, r
|
|
|
1209
1659
|
ref,
|
|
1210
1660
|
render,
|
|
1211
1661
|
}));
|
|
1212
|
-
//
|
|
1662
|
+
// A symbol (e.g. info) in the tint color, pressable as a
|
|
1213
1663
|
// link or button (`render`).
|
|
1214
1664
|
const Accessory = forwardRef(({ className, render, ...props }, ref) => useRender({
|
|
1215
1665
|
defaultTagName: 'span',
|
|
@@ -1221,7 +1671,7 @@ const Accessory = forwardRef(({ className, render, ...props }, ref) => useRender
|
|
|
1221
1671
|
ref,
|
|
1222
1672
|
render,
|
|
1223
1673
|
}));
|
|
1224
|
-
//
|
|
1674
|
+
// A checkmark (17px, 590).
|
|
1225
1675
|
const Checkmark = forwardRef(({ children, className, render, ...props }, ref) => useRender({
|
|
1226
1676
|
defaultTagName: 'span',
|
|
1227
1677
|
props: {
|
|
@@ -1233,7 +1683,7 @@ const Checkmark = forwardRef(({ children, className, render, ...props }, ref) =>
|
|
|
1233
1683
|
ref,
|
|
1234
1684
|
render,
|
|
1235
1685
|
}));
|
|
1236
|
-
//
|
|
1686
|
+
// A drill-in chevron (17px, 590).
|
|
1237
1687
|
const DrillIn = forwardRef(({ children, className, render, ...props }, ref) => useRender({
|
|
1238
1688
|
defaultTagName: 'span',
|
|
1239
1689
|
props: {
|
|
@@ -1246,26 +1696,33 @@ const DrillIn = forwardRef(({ children, className, render, ...props }, ref) => u
|
|
|
1246
1696
|
ref,
|
|
1247
1697
|
render,
|
|
1248
1698
|
}));
|
|
1249
|
-
//
|
|
1699
|
+
// A disclosure chevron (rows: 17px, headers: 19px, 590, in the tint color),
|
|
1250
1700
|
// turned down while open (e.g. in a Base UI `Collapsible.Trigger`).
|
|
1251
|
-
const Disclosure = forwardRef(({ children, className, render, ...props }, ref) =>
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
})
|
|
1263
|
-
|
|
1701
|
+
const Disclosure = forwardRef(({ children, className, render, ...props }, ref) => {
|
|
1702
|
+
// Turned down while its row's collapsible is open (see
|
|
1703
|
+
// `CollapsibleRoot`, `AccordionItem`).
|
|
1704
|
+
const collapsible = useContext(CollapsibleContext);
|
|
1705
|
+
return useRender({
|
|
1706
|
+
defaultTagName: 'span',
|
|
1707
|
+
props: {
|
|
1708
|
+
'data-list-part': 'disclosure',
|
|
1709
|
+
'data-panel-open': collapsible?.isOpen ? '' : undefined,
|
|
1710
|
+
className: cn('uikit-list-disclosure', className),
|
|
1711
|
+
'aria-hidden': 'true',
|
|
1712
|
+
children: children ?? _jsx(Chevron, {}),
|
|
1713
|
+
...props,
|
|
1714
|
+
},
|
|
1715
|
+
ref,
|
|
1716
|
+
render,
|
|
1717
|
+
});
|
|
1718
|
+
});
|
|
1719
|
+
// Three lines (17px, 400).
|
|
1264
1720
|
/**
|
|
1265
|
-
*
|
|
1266
|
-
* `
|
|
1721
|
+
* A grabber: drags its row to reorder it (see `Item`
|
|
1722
|
+
* `reorderHandle`); focused, arrow keys move the row (grabbed by the app:
|
|
1723
|
+
* from target to target, Enter or Space dropping it).
|
|
1267
1724
|
*/
|
|
1268
|
-
const Grabber = forwardRef(({ children, className, render, ...props }, ref) => useRender({
|
|
1725
|
+
const Grabber = forwardRef(({ children, className, onClick, onKeyDown, onPointerDown, render, ...props }, ref) => useRender({
|
|
1269
1726
|
defaultTagName: 'span',
|
|
1270
1727
|
props: {
|
|
1271
1728
|
'data-list-part': 'grabber',
|
|
@@ -1273,11 +1730,30 @@ const Grabber = forwardRef(({ children, className, render, ...props }, ref) => u
|
|
|
1273
1730
|
tabIndex: 0,
|
|
1274
1731
|
children: children ?? _jsx(Lines, {}),
|
|
1275
1732
|
...props,
|
|
1733
|
+
onKeyDown: (event) => {
|
|
1734
|
+
onKeyDown?.(event);
|
|
1735
|
+
if (event.defaultPrevented)
|
|
1736
|
+
return;
|
|
1737
|
+
reorderByKey(event, event.currentTarget);
|
|
1738
|
+
},
|
|
1739
|
+
onPointerDown: (event) => {
|
|
1740
|
+
onPointerDown?.(event);
|
|
1741
|
+
if (event.defaultPrevented)
|
|
1742
|
+
return;
|
|
1743
|
+
startReorderDrag(event, event.currentTarget);
|
|
1744
|
+
},
|
|
1745
|
+
// The click ending a drag (captured by the grabber, see `reorder.ts`)
|
|
1746
|
+
// stays with it: its row doesn't act on it (e.g. pass it on to its
|
|
1747
|
+
// checkbox, see `forwardClick`).
|
|
1748
|
+
onClick: (event) => {
|
|
1749
|
+
onClick?.(event);
|
|
1750
|
+
event.stopPropagation();
|
|
1751
|
+
},
|
|
1276
1752
|
},
|
|
1277
1753
|
ref,
|
|
1278
1754
|
render,
|
|
1279
1755
|
}));
|
|
1280
|
-
//
|
|
1756
|
+
// A button (rows) or an action (headers): text in the tint
|
|
1281
1757
|
// color.
|
|
1282
1758
|
const Action = forwardRef(({ className, render, ...props }, ref) => useRender({
|
|
1283
1759
|
defaultTagName: 'button',
|
|
@@ -1290,7 +1766,7 @@ const Action = forwardRef(({ className, render, ...props }, ref) => useRender({
|
|
|
1290
1766
|
ref,
|
|
1291
1767
|
render,
|
|
1292
1768
|
}));
|
|
1293
|
-
//
|
|
1769
|
+
// A button row: a pressable row's title in the tint color.
|
|
1294
1770
|
const Button = forwardRef(({ className, destructive, render, ...props }, ref) => useRender({
|
|
1295
1771
|
defaultTagName: 'button',
|
|
1296
1772
|
props: {
|
|
@@ -1303,18 +1779,38 @@ const Button = forwardRef(({ className, destructive, render, ...props }, ref) =>
|
|
|
1303
1779
|
ref,
|
|
1304
1780
|
render,
|
|
1305
1781
|
}));
|
|
1306
|
-
/**
|
|
1307
|
-
|
|
1782
|
+
/**
|
|
1783
|
+
* A checkbox (selecting rows); pressed and dragged along the rows,
|
|
1784
|
+
* selecting them (see `select.ts`, `Root`'s `dragToSelect`): neither
|
|
1785
|
+
* scrolling nor swiping a sheet away then.
|
|
1786
|
+
*/
|
|
1787
|
+
const Checkbox = forwardRef(({ onPointerDown, onTouchMove, whileEditing, ...props }, ref) => {
|
|
1788
|
+
const isDragToSelect = useContext(DragToSelectContext);
|
|
1789
|
+
return (_jsx(CheckboxBase.Root, { ref: ref, "data-base-ui-swipe-ignore": isDragToSelect ? '' : undefined, "data-drag-to-select": isDragToSelect ? '' : undefined, "data-list-part": "edit", onPointerDown: (event) => {
|
|
1790
|
+
onPointerDown?.(event);
|
|
1791
|
+
const { button, currentTarget, isPrimary } = event;
|
|
1792
|
+
const root = currentTarget.closest('[data-list-part=root]');
|
|
1793
|
+
if (!isDragToSelect || !isPrimary || button !== 0 || !root)
|
|
1794
|
+
return;
|
|
1795
|
+
dragToSelect(currentTarget, root, event);
|
|
1796
|
+
},
|
|
1797
|
+
// Not scrolling where `touch-action` isn't kept (seen on iOS): on
|
|
1798
|
+
// the element itself, cancelable.
|
|
1799
|
+
onTouchMove: (event) => {
|
|
1800
|
+
onTouchMove?.(event);
|
|
1801
|
+
if (isDragToSelect && event.cancelable)
|
|
1802
|
+
event.preventDefault();
|
|
1803
|
+
}, ...whileEditingOf(whileEditing), ...props }));
|
|
1804
|
+
});
|
|
1308
1805
|
/**
|
|
1309
1806
|
* A radio (selecting one row), as `Checkbox`; its group is a `RadioGroup`
|
|
1310
1807
|
* (e.g. rendering a `Group`).
|
|
1311
1808
|
*/
|
|
1312
1809
|
const Radio = forwardRef((props, ref) => (_jsx(RadioBase.Root, { ref: ref, "data-list-part": "edit", ...props })));
|
|
1313
|
-
const StyledEditButton = forwardRef(({ className,
|
|
1810
|
+
const StyledEditButton = forwardRef(({ className, render, ...props }, ref) => useRender({
|
|
1314
1811
|
defaultTagName: 'button',
|
|
1315
1812
|
props: {
|
|
1316
1813
|
'data-list-part': 'edit',
|
|
1317
|
-
'data-editing-style': editingStyle,
|
|
1318
1814
|
className: cn('uikit-list-edit-button uikit-checkbox-edit-circle', className),
|
|
1319
1815
|
type: 'button',
|
|
1320
1816
|
...useSecondaryClick(props),
|
|
@@ -1323,19 +1819,15 @@ const StyledEditButton = forwardRef(({ className, editingStyle, render, ...props
|
|
|
1323
1819
|
render,
|
|
1324
1820
|
}));
|
|
1325
1821
|
/**
|
|
1326
|
-
*
|
|
1327
|
-
* (
|
|
1822
|
+
* A remove or add button: a symbol (its child) in a circle of its `tint`,
|
|
1823
|
+
* doing what the app gives it (e.g. deleting the row; or, rendered by a
|
|
1824
|
+
* `SwipeActionsTrigger`, opening its trailing actions).
|
|
1328
1825
|
*/
|
|
1329
|
-
const EditButton = forwardRef(({
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
return;
|
|
1335
|
-
item?.open('trailing');
|
|
1336
|
-
}, children: children ?? _jsx(Sign, { plus: editingStyle === 'insert' }) }));
|
|
1337
|
-
});
|
|
1338
|
-
// Swipe actions (Figma “Row with Swipe Actions”, “_Swipe Actions”): shapes
|
|
1826
|
+
const EditButton = forwardRef(({ style, textColor, tint, ...props }, ref) => (_jsx(StyledEditButton, { ref: ref, style: withStyle({
|
|
1827
|
+
'--uikit-list-edit-text-color': textColor,
|
|
1828
|
+
'--uikit-list-edit-tint': tint,
|
|
1829
|
+
}, style), ...props })));
|
|
1830
|
+
// Swipe actions: shapes
|
|
1339
1831
|
// 10px apart, 10px from the row and 16px from the edge.
|
|
1340
1832
|
// Circles centered in the row, rounded rectangles 4px from its edges.
|
|
1341
1833
|
const StyledSwipeActions = forwardRef(({ className, overswipe, render, side, ...props }, ref) => useRender({
|
|
@@ -1350,7 +1842,7 @@ const StyledSwipeActions = forwardRef(({ className, overswipe, render, side, ...
|
|
|
1350
1842
|
ref,
|
|
1351
1843
|
render,
|
|
1352
1844
|
}));
|
|
1353
|
-
const SwipeActions = forwardRef(({ onFocusCapture, onOverswipe, overswipe = false, side: sideProp = 'inline-end', ...props }, ref) => {
|
|
1845
|
+
const SwipeActions = forwardRef(({ allowSwipe = 'all', handle, onFocusCapture, onOverswipe, overswipe = false, side: sideProp = 'inline-end', ...props }, ref) => {
|
|
1354
1846
|
// (Internally: leading, trailing.)
|
|
1355
1847
|
const side = sideProp === 'inline-start' ? 'leading' : 'trailing';
|
|
1356
1848
|
const item = useContext(ItemContext);
|
|
@@ -1362,13 +1854,24 @@ const SwipeActions = forwardRef(({ onFocusCapture, onOverswipe, overswipe = fals
|
|
|
1362
1854
|
onOverswipeRef.current = onOverswipe;
|
|
1363
1855
|
});
|
|
1364
1856
|
const hasHandler = onOverswipe !== undefined;
|
|
1857
|
+
// Opened and closed by their handle, while mounted.
|
|
1858
|
+
useLayoutEffect(() => {
|
|
1859
|
+
if (!handle || !item)
|
|
1860
|
+
return undefined;
|
|
1861
|
+
return handle.attach({
|
|
1862
|
+
close: () => item.close(),
|
|
1863
|
+
focus: () => item.focus(side),
|
|
1864
|
+
isOpen: () => item.isOpen(side),
|
|
1865
|
+
open: () => item.open(side),
|
|
1866
|
+
});
|
|
1867
|
+
}, [handle, item, side]);
|
|
1365
1868
|
useLayoutEffect(() => {
|
|
1366
1869
|
const { current: element } = elementRef;
|
|
1367
1870
|
if (!item || !element)
|
|
1368
1871
|
return undefined;
|
|
1369
|
-
item.setActions(side, element, hasHandler ? () => onOverswipeRef.current?.() : overswipe);
|
|
1872
|
+
item.setActions(side, element, hasHandler ? () => onOverswipeRef.current?.() : overswipe, allowSwipe);
|
|
1370
1873
|
return () => item.setActions(side, undefined);
|
|
1371
|
-
}, [elementRef, hasHandler, item, overswipe, pin, side]);
|
|
1874
|
+
}, [allowSwipe, elementRef, hasHandler, item, overswipe, pin, side]);
|
|
1372
1875
|
// In the row's pin layer, staying in place as it scrolls (see `Pin`).
|
|
1373
1876
|
if (!pin)
|
|
1374
1877
|
return null;
|
|
@@ -1377,6 +1880,40 @@ const SwipeActions = forwardRef(({ onFocusCapture, onOverswipe, overswipe = fals
|
|
|
1377
1880
|
item?.open(side);
|
|
1378
1881
|
} }), pin);
|
|
1379
1882
|
});
|
|
1883
|
+
/**
|
|
1884
|
+
* Opens a row's swipe actions when clicked (Base UI's triggers' shape):
|
|
1885
|
+
* those of its `handle`, from anywhere, or, in the row, its own on its
|
|
1886
|
+
* `side`; focusing the first of them. Renders a button, or what it's given
|
|
1887
|
+
* (e.g. the delete `EditButton`).
|
|
1888
|
+
*/
|
|
1889
|
+
const SwipeActionsTrigger = forwardRef(({ className, handle, onClick, render, side = 'inline-end', ...props }, ref) => {
|
|
1890
|
+
const item = useContext(ItemContext);
|
|
1891
|
+
return useRender({
|
|
1892
|
+
defaultTagName: 'button',
|
|
1893
|
+
props: {
|
|
1894
|
+
className: cn('uikit-list-swipe-actions-trigger', className),
|
|
1895
|
+
type: 'button',
|
|
1896
|
+
...props,
|
|
1897
|
+
onClick: (event) => {
|
|
1898
|
+
onClick?.(event);
|
|
1899
|
+
if (event.defaultPrevented)
|
|
1900
|
+
return;
|
|
1901
|
+
// Moving focus to the actions it opened (as Base UI's triggers
|
|
1902
|
+
// to their popups).
|
|
1903
|
+
if (handle) {
|
|
1904
|
+
handle.open();
|
|
1905
|
+
handle.focus();
|
|
1906
|
+
return;
|
|
1907
|
+
}
|
|
1908
|
+
const itemSide = side === 'inline-start' ? 'leading' : 'trailing';
|
|
1909
|
+
item?.open(itemSide);
|
|
1910
|
+
item?.focus(itemSide);
|
|
1911
|
+
},
|
|
1912
|
+
},
|
|
1913
|
+
ref,
|
|
1914
|
+
render,
|
|
1915
|
+
});
|
|
1916
|
+
});
|
|
1380
1917
|
const StyledSwipeAction = forwardRef(({ className, render, shape, showLabel, ...props }, ref) => useRender({
|
|
1381
1918
|
defaultTagName: 'button',
|
|
1382
1919
|
props: {
|
|
@@ -1404,8 +1941,7 @@ const SwipeAction = forwardRef(({ children, label, onClick, style, textColor, ti
|
|
|
1404
1941
|
item?.close();
|
|
1405
1942
|
}, children: [_jsx("span", { "data-list-part": "swipe-action-shape", children: _jsx("span", { "data-list-part": "swipe-action-symbol", children: children }) }), _jsx("span", { "aria-hidden": "true", "data-list-part": "swipe-action-label", children: label })] }));
|
|
1406
1943
|
});
|
|
1407
|
-
// Headers (
|
|
1408
|
-
// “Grouped Table Footer”).
|
|
1944
|
+
// Headers (and section titles) and footers.
|
|
1409
1945
|
const Header = forwardRef(({ className, prominence, render, ...props }, ref) => useRender({
|
|
1410
1946
|
defaultTagName: 'div',
|
|
1411
1947
|
props: {
|
|
@@ -1439,7 +1975,7 @@ const Block = forwardRef(({ className, render, strong, ...props }, ref) => useRe
|
|
|
1439
1975
|
ref,
|
|
1440
1976
|
render,
|
|
1441
1977
|
}));
|
|
1442
|
-
// Index (
|
|
1978
|
+
// Index (Framework7 “List Index”): letters in the tint
|
|
1443
1979
|
// color, selected by pressing or scrubbing over them (clicking each item).
|
|
1444
1980
|
// Placing it is up to the page (Framework7: at the page's edge), above the
|
|
1445
1981
|
// sticky headers of plain lists (z-index 2).
|
|
@@ -1475,11 +2011,13 @@ const scrub = (index, state, y) => {
|
|
|
1475
2011
|
state.item = item;
|
|
1476
2012
|
item.click();
|
|
1477
2013
|
};
|
|
1478
|
-
const Index = forwardRef(({ onLostPointerCapture, onPointerCancel, onPointerDown, onPointerMove, onPointerUp, ...props }, ref) => {
|
|
2014
|
+
const Index = forwardRef(({ onLostPointerCapture, onPointerCancel, onPointerDown, onPointerMove, onPointerUp, onTouchMove, ...props }, ref) => {
|
|
1479
2015
|
const handlers = usePointerDrag({
|
|
1480
2016
|
end: () => undefined,
|
|
1481
2017
|
move: (index, state, event) => scrub(index, state, event.clientY),
|
|
1482
2018
|
start: (index, event) => {
|
|
2019
|
+
// No text selection while scrubbing (from the mouse's default).
|
|
2020
|
+
event.preventDefault();
|
|
1483
2021
|
const state = {};
|
|
1484
2022
|
scrub(index, state, event.clientY);
|
|
1485
2023
|
return state;
|
|
@@ -1490,6 +2028,7 @@ const Index = forwardRef(({ onLostPointerCapture, onPointerCancel, onPointerDown
|
|
|
1490
2028
|
onPointerDown,
|
|
1491
2029
|
onPointerMove,
|
|
1492
2030
|
onPointerUp,
|
|
2031
|
+
onTouchMove,
|
|
1493
2032
|
});
|
|
1494
2033
|
return (_jsx(StyledIndex, { ref: ref, ...props, ...handlers }));
|
|
1495
2034
|
});
|
|
@@ -1506,7 +2045,7 @@ const IndexItem = forwardRef(({ className, render, ...props }, ref) => useRender
|
|
|
1506
2045
|
}));
|
|
1507
2046
|
/**
|
|
1508
2047
|
* A row's click handler passing the click on to the control in it
|
|
1509
|
-
* (`selector`, e.g. `[role=switch]`), as
|
|
2048
|
+
* (`selector`, e.g. `[role=switch]`), as native rows do, unless it was the
|
|
1510
2049
|
* control's own: `<List.Item onClick={forwardClick('[role=switch]')}>`. As
|
|
1511
2050
|
* the click it is: a pointer's (`detail` > 0) or a keyboard's (a control's
|
|
1512
2051
|
* `click()` would be a keyboard's, so menus would open with their first
|
|
@@ -1525,8 +2064,22 @@ export const List = {
|
|
|
1525
2064
|
Section,
|
|
1526
2065
|
Header,
|
|
1527
2066
|
Group,
|
|
2067
|
+
DropGroup,
|
|
2068
|
+
DropTarget,
|
|
1528
2069
|
Item,
|
|
1529
|
-
|
|
2070
|
+
Leading,
|
|
2071
|
+
Content,
|
|
2072
|
+
Trailing,
|
|
2073
|
+
Span,
|
|
2074
|
+
Below,
|
|
2075
|
+
CollapsibleRoot,
|
|
2076
|
+
CollapsibleTrigger,
|
|
2077
|
+
CollapsiblePanel,
|
|
2078
|
+
AccordionRoot,
|
|
2079
|
+
AccordionItem,
|
|
2080
|
+
// (Base UI's names in an accordion: the same parts.)
|
|
2081
|
+
AccordionTrigger: CollapsibleTrigger,
|
|
2082
|
+
AccordionPanel: CollapsiblePanel,
|
|
1530
2083
|
Footer,
|
|
1531
2084
|
Block,
|
|
1532
2085
|
Title,
|
|
@@ -1546,8 +2099,12 @@ export const List = {
|
|
|
1546
2099
|
Radio,
|
|
1547
2100
|
EditButton,
|
|
1548
2101
|
SwipeActions,
|
|
2102
|
+
SwipeActionsTrigger,
|
|
1549
2103
|
SwipeAction,
|
|
1550
2104
|
Index,
|
|
1551
2105
|
IndexItem,
|
|
2106
|
+
createSwipeActionsHandle,
|
|
2107
|
+
createReorderHandle,
|
|
2108
|
+
reorder,
|
|
1552
2109
|
};
|
|
1553
2110
|
//# sourceMappingURL=main.js.map
|