@mrpelz/uikit-ish 7.8.0 → 7.9.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 -15
- package/dist/components/action-sheet/main.d.ts.map +1 -1
- package/dist/components/action-sheet/main.js +86 -16
- 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 +15 -0
- package/dist/components/activity-view/main.d.ts +14 -3
- package/dist/components/activity-view/main.d.ts.map +1 -1
- package/dist/components/activity-view/main.js +19 -4
- 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 +8 -46
- package/dist/components/alert/main.d.ts +6 -4
- package/dist/components/alert/main.d.ts.map +1 -1
- package/dist/components/alert/main.js +20 -4
- package/dist/components/alert/main.js.map +1 -1
- package/dist/components/alert/props.d.ts +12 -1
- package/dist/components/alert/props.d.ts.map +1 -1
- package/dist/components/alert/style.css +13 -27
- 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 +3 -0
- 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 +0 -6
- package/dist/components/badge/main.d.ts +2 -2
- package/dist/components/badge/main.d.ts.map +1 -1
- package/dist/components/badge/main.js +5 -5
- 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 +3 -2
- package/dist/components/button/main.d.ts.map +1 -1
- package/dist/components/button/main.js +6 -6
- package/dist/components/button/main.js.map +1 -1
- package/dist/components/button/style.css +11 -27
- package/dist/components/checkbox/style.css +2 -5
- 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 +1 -1
- package/dist/components/color-picker/main.d.ts.map +1 -1
- package/dist/components/color-picker/main.js +40 -33
- package/dist/components/color-picker/main.js.map +1 -1
- package/dist/components/color-picker/props.d.ts +21 -7
- package/dist/components/color-picker/props.d.ts.map +1 -1
- package/dist/components/color-picker/style.css +9 -27
- 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 +99 -47
- package/dist/components/contextual-menu/main.js.map +1 -1
- package/dist/components/contextual-menu/props.d.ts +17 -7
- package/dist/components/contextual-menu/props.d.ts.map +1 -1
- package/dist/components/contextual-menu/style.css +11 -8
- 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 +300 -139
- 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 +93 -22
- package/dist/components/date-picker/props.d.ts.map +1 -1
- package/dist/components/date-picker/style.css +59 -71
- 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 +74 -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 +31 -23
- package/dist/components/edit-menu/main.js.map +1 -1
- package/dist/components/edit-menu/props.d.ts +13 -0
- package/dist/components/edit-menu/props.d.ts.map +1 -1
- package/dist/components/edit-menu/style.css +5 -7
- 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 +15 -2
- 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/style.css +19 -4
- 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 +56 -27
- 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 +62 -42
- package/dist/components/index.d.ts +26 -22
- 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 +59 -163
- 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 +18 -89
- package/dist/components/list/main.d.ts +49 -9
- package/dist/components/list/main.d.ts.map +1 -1
- package/dist/components/list/main.js +769 -208
- package/dist/components/list/main.js.map +1 -1
- package/dist/components/list/props.d.ts +165 -8
- package/dist/components/list/props.d.ts.map +1 -1
- package/dist/components/list/style.css +308 -371
- 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 +31 -8
- package/dist/components/menu/main.d.ts.map +1 -1
- package/dist/components/menu/main.js +175 -39
- package/dist/components/menu/main.js.map +1 -1
- package/dist/components/menu/props.d.ts +2 -1
- package/dist/components/menu/props.d.ts.map +1 -1
- package/dist/components/menu/style.css +10 -32
- package/dist/components/navigation/main.d.ts +11 -2
- package/dist/components/navigation/main.d.ts.map +1 -1
- package/dist/components/navigation/main.js +186 -98
- package/dist/components/navigation/main.js.map +1 -1
- package/dist/components/navigation/props.d.ts +20 -3
- package/dist/components/navigation/props.d.ts.map +1 -1
- package/dist/components/navigation/style.css +24 -7
- package/dist/components/page/main.d.ts.map +1 -1
- package/dist/components/page/main.js +2 -2
- 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 -1
- package/dist/components/page-control/main.d.ts +1 -1
- package/dist/components/page-control/main.d.ts.map +1 -1
- package/dist/components/page-control/main.js +59 -25
- 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 +5 -0
- 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 +53 -31
- 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 +45 -4
- package/dist/components/progress/main.d.ts +1 -1
- package/dist/components/progress/main.d.ts.map +1 -1
- package/dist/components/progress/main.js +108 -15
- package/dist/components/progress/main.js.map +1 -1
- package/dist/components/progress/props.d.ts +25 -5
- package/dist/components/progress/props.d.ts.map +1 -1
- package/dist/components/progress/style.css +67 -35
- 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 +81 -25
- package/dist/components/roll/main.js.map +1 -1
- package/dist/components/roll/props.d.ts +24 -7
- package/dist/components/roll/props.d.ts.map +1 -1
- package/dist/components/roll/style.css +1 -13
- package/dist/components/segmented/main.js +3 -3
- package/dist/components/segmented/main.js.map +1 -1
- package/dist/components/segmented/style.css +2 -14
- 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 +57 -73
- package/dist/components/sheet/main.js.map +1 -1
- package/dist/components/sheet/props.d.ts +36 -2
- package/dist/components/sheet/props.d.ts.map +1 -1
- package/dist/components/sheet/style.css +176 -44
- package/dist/components/sidebar/style.css +13 -7
- package/dist/components/slider/main.d.ts.map +1 -1
- package/dist/components/slider/main.js +6 -5
- package/dist/components/slider/main.js.map +1 -1
- package/dist/components/slider/style.css +2 -28
- 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 +17 -11
- package/dist/components/stepper/main.js.map +1 -1
- package/dist/components/stepper/style.css +4 -8
- package/dist/components/switch/main.d.ts.map +1 -1
- package/dist/components/switch/main.js +16 -11
- package/dist/components/switch/main.js.map +1 -1
- package/dist/components/switch/props.d.ts +2 -2
- package/dist/components/switch/props.d.ts.map +1 -1
- package/dist/components/switch/style.css +28 -1
- 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 +34 -27
- 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 +25 -4
- package/dist/components/tab-bar/main.d.ts.map +1 -1
- package/dist/components/tab-bar/main.js +59 -46
- package/dist/components/tab-bar/main.js.map +1 -1
- package/dist/components/tab-bar/props.d.ts +3 -3
- package/dist/components/tab-bar/props.d.ts.map +1 -1
- package/dist/components/tab-bar/style.css +24 -46
- package/dist/components/text-field/main.d.ts.map +1 -1
- package/dist/components/text-field/main.js +9 -8
- package/dist/components/text-field/main.js.map +1 -1
- package/dist/components/text-field/props.d.ts +8 -1
- package/dist/components/text-field/props.d.ts.map +1 -1
- package/dist/components/text-field/style.css +21 -55
- package/dist/components/toolbar/main.d.ts.map +1 -1
- package/dist/components/toolbar/main.js +11 -9
- package/dist/components/toolbar/main.js.map +1 -1
- package/dist/components/toolbar/style.css +28 -22
- 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 +35 -6
- 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 +11 -11
- package/dist/components/typography/main.d.ts.map +1 -1
- package/dist/components/typography/main.js +16 -6
- package/dist/components/typography/main.js.map +1 -1
- package/dist/components/typography/props.d.ts +2 -9
- package/dist/components/typography/props.d.ts.map +1 -1
- package/dist/components/typography/style.css +0 -120
- package/dist/components/utils/main.d.ts +34 -5
- package/dist/components/utils/main.d.ts.map +1 -1
- package/dist/components/utils/main.js +81 -12
- package/dist/components/utils/main.js.map +1 -1
- package/dist/components/utils/props.d.ts +4 -2
- package/dist/components/utils/props.d.ts.map +1 -1
- package/dist/components/utils/style.css +29 -16
- package/dist/components/viewport/input.d.ts +23 -0
- package/dist/components/viewport/input.d.ts.map +1 -0
- package/dist/components/viewport/input.js +95 -0
- package/dist/components/viewport/input.js.map +1 -0
- package/dist/components/viewport/main.d.ts +42 -9
- package/dist/components/viewport/main.d.ts.map +1 -1
- package/dist/components/viewport/main.js +488 -66
- package/dist/components/viewport/main.js.map +1 -1
- package/dist/components/viewport/padding.d.ts +50 -0
- package/dist/components/viewport/padding.d.ts.map +1 -0
- package/dist/components/viewport/padding.js +226 -0
- package/dist/components/viewport/padding.js.map +1 -0
- package/dist/components/viewport/props.d.ts +155 -7
- package/dist/components/viewport/props.d.ts.map +1 -1
- package/dist/components/viewport/style.css +172 -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 +35 -2
- 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 +6 -13
|
@@ -3,10 +3,12 @@ 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
9
|
import { cn, edgeScrollDelta, frameElapsed, useForwardedRef, usePointerDrag, useSecondaryClick, withStyle, } from '../utils/main.js';
|
|
10
|
+
import { createSwipeActionsHandle } from './swipe-actions-handle.js';
|
|
11
|
+
export { ListSwipeActionsHandle, useCreateSwipeActionsHandle, } from './swipe-actions-handle.js';
|
|
10
12
|
// Source: Apple iOS 26 Figma (“Lists and tables”: “Row” Height=Regular/Tall,
|
|
11
13
|
// “_Images”, “_Trailing”, “_Edit Buttons”, “_Grabber”, “_Separator”, “Row -
|
|
12
14
|
// Button”, “Row with Swipe Actions”, “_Swipe Actions”, “Header”, “_Header
|
|
@@ -18,7 +20,8 @@ import { cn, edgeScrollDelta, frameElapsed, useForwardedRef, usePointerDrag, use
|
|
|
18
20
|
// `swipeout.js`, `list-index.less`, `block.less`):
|
|
19
21
|
// - list styles (UIKit `UITableView.Style`): `insetGrouped` (the default: 16px
|
|
20
22
|
// inset, 24px corners), `grouped`, `plain` (Framework7 `.list`,
|
|
21
|
-
// `.list.inset`); 35px between sections
|
|
23
|
+
// `.list.inset`); 35px between sections (none at the list's ends: its
|
|
24
|
+
// neighbors' and container's spacing); optionally outlined
|
|
22
25
|
// (`.list-outline`)
|
|
23
26
|
// - pressed rows (UIKit's cell selection, `systemGray4`), hiding the separators
|
|
24
27
|
// around pressed and swiped rows
|
|
@@ -32,7 +35,9 @@ import { cn, edgeScrollDelta, frameElapsed, useForwardedRef, usePointerDrag, use
|
|
|
32
35
|
// its symbol moves to the row's end, its label hides (150ms)
|
|
33
36
|
// - reordering rows by their grabbers (`sortable.js`, see `useReorder`),
|
|
34
37
|
// independent of the leading edit controls (`Checkbox`, `Radio`,
|
|
35
|
-
// `EditButton`)
|
|
38
|
+
// `EditButton`); entering and leaving edit mode (`Root` `editing`; UIKit
|
|
39
|
+
// `setEditing(_:animated:)`), they slide in and out from the rows' edges
|
|
40
|
+
// (300ms), the rows' content making room
|
|
36
41
|
// - media rows, as in Mail (`.media-list`: a `Text` part)
|
|
37
42
|
// - the Content Block (`Block`)
|
|
38
43
|
//
|
|
@@ -53,8 +58,9 @@ import { cn, edgeScrollDelta, frameElapsed, useForwardedRef, usePointerDrag, use
|
|
|
53
58
|
// trailing controls.
|
|
54
59
|
//
|
|
55
60
|
// Deviations:
|
|
56
|
-
// - Focusing a swipe action opens the actions
|
|
57
|
-
// the
|
|
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.
|
|
58
64
|
// - Header and footer text is aligned with the rows' text (Figma: headers are
|
|
59
65
|
// laid out for the full width, footers for the rows').
|
|
60
66
|
// - Sticky section titles (plain lists) are opaque (Framework7 contacts list;
|
|
@@ -82,11 +88,18 @@ import { cn, edgeScrollDelta, frameElapsed, useForwardedRef, usePointerDrag, use
|
|
|
82
88
|
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
89
|
// Figma PNG: 15.2 × 14.5px of ink at 17px (590).
|
|
84
90
|
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
91
|
// Root: the list's style, as custom properties for its parts (their
|
|
87
92
|
// fallbacks are `insetGrouped`'s, for parts outside of a root).
|
|
88
|
-
|
|
89
|
-
|
|
93
|
+
// Edit modes: the root's, its sections' (unless their own), their groups'
|
|
94
|
+
// (unless their own), their rows' (unless their own); each row marks its
|
|
95
|
+
// sides (see `Item`), its parts
|
|
96
|
+
// reacting by their `whileEditing` (see style.css).
|
|
97
|
+
const EditingContext = createContext('ignore');
|
|
98
|
+
/** A part's `whileEditing`, as its attribute (see style.css). */
|
|
99
|
+
const whileEditingOf = (whileEditing) => ({
|
|
100
|
+
'data-while-editing': whileEditing,
|
|
101
|
+
});
|
|
102
|
+
const StyledRoot = forwardRef(({ className, listStyle, outline, render, ...props }, ref) => useRender({
|
|
90
103
|
defaultTagName: 'div',
|
|
91
104
|
props: {
|
|
92
105
|
'data-list-part': 'root',
|
|
@@ -98,8 +111,9 @@ const Root = forwardRef(({ className, listStyle, outline, render, ...props }, re
|
|
|
98
111
|
ref,
|
|
99
112
|
render,
|
|
100
113
|
}));
|
|
101
|
-
/** A
|
|
102
|
-
const
|
|
114
|
+
/** A list (UIKit `UITableView`): sections of rows, headers and footers. */
|
|
115
|
+
const Root = forwardRef(({ editing = 'ignore', ...props }, ref) => (_jsx(EditingContext.Provider, { value: editing, children: _jsx(StyledRoot, { ref: ref, ...props }) })));
|
|
116
|
+
const StyledSection = forwardRef(({ className, render, ...props }, ref) => useRender({
|
|
103
117
|
defaultTagName: 'section',
|
|
104
118
|
props: {
|
|
105
119
|
'data-list-part': 'section',
|
|
@@ -109,6 +123,11 @@ const Section = forwardRef(({ className, render, ...props }, ref) => useRender({
|
|
|
109
123
|
ref,
|
|
110
124
|
render,
|
|
111
125
|
}));
|
|
126
|
+
/** A section: an optional `Header`, a `Group` or `Block`, a `Footer`. */
|
|
127
|
+
const Section = forwardRef(({ editing, ...props }, ref) => {
|
|
128
|
+
const inherited = useContext(EditingContext);
|
|
129
|
+
return (_jsx(EditingContext.Provider, { value: editing ?? inherited, children: _jsx(StyledSection, { ref: ref, ...props }) }));
|
|
130
|
+
});
|
|
112
131
|
// Reordering (Framework7 `sortable.js`, `sortable.less`): dragging a row's
|
|
113
132
|
// grabber lifts the row, which follows the pointer within its group, the
|
|
114
133
|
// other rows making room (300ms); near an end of the scroll container, it
|
|
@@ -129,8 +148,10 @@ const scrollContainerOf = (element) => {
|
|
|
129
148
|
}
|
|
130
149
|
return element.ownerDocument.scrollingElement ?? element.ownerDocument.body;
|
|
131
150
|
};
|
|
132
|
-
const setOffset = (item, offset,
|
|
133
|
-
item.style.transition =
|
|
151
|
+
const setOffset = (item, offset, isAnimated) => {
|
|
152
|
+
item.style.transition = isAnimated
|
|
153
|
+
? `transform ${reorderDuration}ms`
|
|
154
|
+
: 'none';
|
|
134
155
|
item.style.transform = offset === 0 ? '' : `translateY(${offset}px)`;
|
|
135
156
|
};
|
|
136
157
|
/** Reorders a group's rows by their grabbers (see above). */
|
|
@@ -157,11 +178,11 @@ const useReorder = (groupRef, onReorder) => {
|
|
|
157
178
|
const commit = (items, from, to) => {
|
|
158
179
|
const settle = { observer: undefined };
|
|
159
180
|
let timeout;
|
|
160
|
-
const clearOffsets = (
|
|
181
|
+
const clearOffsets = (isAnimated) => {
|
|
161
182
|
settle.observer?.disconnect();
|
|
162
183
|
clearTimeout(timeout);
|
|
163
184
|
for (const element of items) {
|
|
164
|
-
setOffset(element, 0,
|
|
185
|
+
setOffset(element, 0, isAnimated);
|
|
165
186
|
delete element.dataset.reordering;
|
|
166
187
|
delete element.dataset.reorderEdge;
|
|
167
188
|
}
|
|
@@ -231,9 +252,9 @@ const useReorder = (groupRef, onReorder) => {
|
|
|
231
252
|
for (const [index, element] of items.entries()) {
|
|
232
253
|
if (index === from)
|
|
233
254
|
continue;
|
|
234
|
-
const
|
|
235
|
-
const
|
|
236
|
-
setOffset(element, (
|
|
255
|
+
const isBelow = index > from && index <= to;
|
|
256
|
+
const isAbove = index < from && index >= to;
|
|
257
|
+
setOffset(element, (isAbove ? height : 0) - (isBelow ? height : 0), true);
|
|
237
258
|
}
|
|
238
259
|
markEdges(to);
|
|
239
260
|
};
|
|
@@ -318,10 +339,11 @@ const StyledGroup = forwardRef(({ className, render, ...props }, ref) => useRend
|
|
|
318
339
|
ref,
|
|
319
340
|
render,
|
|
320
341
|
}));
|
|
321
|
-
const Group = forwardRef(({ onReorder, ...props }, ref) => {
|
|
342
|
+
const Group = forwardRef(({ editing, onReorder, ...props }, ref) => {
|
|
322
343
|
const groupRef = useForwardedRef(ref);
|
|
344
|
+
const inherited = useContext(EditingContext);
|
|
323
345
|
useReorder(groupRef, onReorder);
|
|
324
|
-
return (_jsx(StyledGroup, { ref: groupRef, ...props }));
|
|
346
|
+
return (_jsx(EditingContext.Provider, { value: editing ?? inherited, children: _jsx(StyledGroup, { ref: groupRef, ...props }) }));
|
|
325
347
|
});
|
|
326
348
|
// Rows.
|
|
327
349
|
/**
|
|
@@ -346,12 +368,89 @@ const StyledItem = forwardRef(({ className, render, ...props }, ref) => useRende
|
|
|
346
368
|
render,
|
|
347
369
|
}));
|
|
348
370
|
const ItemContext = createContext(undefined);
|
|
371
|
+
/** A row's side in an edit mode: editing, not, or not managed. */
|
|
372
|
+
const editSide = (editing, side) => {
|
|
373
|
+
if (editing === 'ignore')
|
|
374
|
+
return undefined;
|
|
375
|
+
return editing === side || editing === 'both' ? 'on' : 'off';
|
|
376
|
+
};
|
|
377
|
+
// The slots sliding in or out by their width (see style.css).
|
|
378
|
+
const sizedParts = ':scope > [data-list-part="row"] > :is([data-list-part="leading"], [data-list-part="trailing"])';
|
|
379
|
+
// A row's slots: its only children (see style.css).
|
|
380
|
+
const slots = new Set(['below', 'content', 'leading', 'span', 'trailing']);
|
|
381
|
+
// Rows already told about their foreign elements (see `useStrictSlots`).
|
|
382
|
+
const toldRows = new WeakSet();
|
|
383
|
+
/**
|
|
384
|
+
* Warns (once per row) about elements of other components placed in a row
|
|
385
|
+
* directly, not in one of its slots (`Leading`, `Content`, `Trailing`,
|
|
386
|
+
* `Span`, `Below`): the row places only its own parts.
|
|
387
|
+
*/
|
|
388
|
+
const useStrictSlots = (itemRef) => {
|
|
389
|
+
useLayoutEffect(() => {
|
|
390
|
+
const row = itemRef.current?.querySelector(':scope > [data-list-part="track"] > [data-list-part="row"]');
|
|
391
|
+
if (!row || toldRows.has(row))
|
|
392
|
+
return;
|
|
393
|
+
const foreign = [...row.children].filter((child) => !(child instanceof HTMLElement &&
|
|
394
|
+
slots.has(child.dataset.listPart ?? '')));
|
|
395
|
+
if (foreign.length === 0)
|
|
396
|
+
return;
|
|
397
|
+
toldRows.add(row);
|
|
398
|
+
// eslint-disable-next-line no-console -- a misuse, told to the developer
|
|
399
|
+
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);
|
|
400
|
+
});
|
|
401
|
+
};
|
|
402
|
+
/**
|
|
403
|
+
* A managed row's slots sliding in or out in edit mode, their widths as
|
|
404
|
+
* `--uikit-list-slot-size` (taking no room while out, see style.css):
|
|
405
|
+
* measured before it's first shown, sliding only after (`data-sized` on
|
|
406
|
+
* its track; not sliding out from where they'd be unmeasured).
|
|
407
|
+
*/
|
|
408
|
+
const useEditingSizes = (itemRef, isManaged) => {
|
|
409
|
+
useLayoutEffect(() => {
|
|
410
|
+
const track = itemRef.current?.querySelector(':scope > [data-list-part="track"]');
|
|
411
|
+
if (!isManaged || !(track instanceof HTMLElement))
|
|
412
|
+
return undefined;
|
|
413
|
+
const size = (target) => {
|
|
414
|
+
if (!(target instanceof HTMLElement))
|
|
415
|
+
return;
|
|
416
|
+
target.style.setProperty('--uikit-list-slot-size', `${String(target.offsetWidth)}px`);
|
|
417
|
+
};
|
|
418
|
+
const resizeObserver = new ResizeObserver((entries) => {
|
|
419
|
+
for (const { target } of entries)
|
|
420
|
+
size(target);
|
|
421
|
+
});
|
|
422
|
+
const observe = () => {
|
|
423
|
+
resizeObserver.disconnect();
|
|
424
|
+
for (const part of track.querySelectorAll(sizedParts)) {
|
|
425
|
+
size(part);
|
|
426
|
+
resizeObserver.observe(part);
|
|
427
|
+
}
|
|
428
|
+
};
|
|
429
|
+
observe();
|
|
430
|
+
const row = track.querySelector('[data-list-part="row"]');
|
|
431
|
+
const mutationObserver = new MutationObserver(observe);
|
|
432
|
+
if (row)
|
|
433
|
+
mutationObserver.observe(row, { childList: true });
|
|
434
|
+
// (Sliding from the next frame on: the first shown as measured.)
|
|
435
|
+
const frame = requestAnimationFrame(() => {
|
|
436
|
+
track.dataset.sized = '';
|
|
437
|
+
});
|
|
438
|
+
return () => {
|
|
439
|
+
cancelAnimationFrame(frame);
|
|
440
|
+
resizeObserver.disconnect();
|
|
441
|
+
mutationObserver.disconnect();
|
|
442
|
+
};
|
|
443
|
+
}, [itemRef, isManaged]);
|
|
444
|
+
};
|
|
349
445
|
/** Closes the item whose swipe actions are open (one at a time). */
|
|
350
446
|
let closeOpenItem;
|
|
351
447
|
const swipeDuration = 300;
|
|
352
448
|
const swipeThreshold = 8;
|
|
353
449
|
/** A sideways scroll swiping a row ends after this long without scrolling. */
|
|
354
450
|
const scrollEndDelay = 150;
|
|
451
|
+
// How long a wheel (or a trackpad's momentum) is quiet before a row it
|
|
452
|
+
// scrolled open is at rest there (see `settle`).
|
|
453
|
+
const wheelQuiet = 300;
|
|
355
454
|
/**
|
|
356
455
|
* How far a row arms overswiping, with any actions (also fewer, or
|
|
357
456
|
* labelled ones): past 5 circles (5 × (44 + 10) + 16 + 10 + 8px;
|
|
@@ -428,12 +527,12 @@ const rowPath = (width, height, offset) => {
|
|
|
428
527
|
const revealRanges = (container, side, lead) => {
|
|
429
528
|
const width = container.offsetWidth;
|
|
430
529
|
// Whether the row is on the container's left (the edge on its right).
|
|
431
|
-
const
|
|
530
|
+
const isRowOnLeft = (side === 'trailing') === !isRtl(container);
|
|
432
531
|
for (const button of container.children) {
|
|
433
532
|
if (!(button instanceof HTMLElement))
|
|
434
533
|
continue;
|
|
435
534
|
// From the edge, uncovered from `start` to `start` + its width.
|
|
436
|
-
const start =
|
|
535
|
+
const start = isRowOnLeft
|
|
437
536
|
? width - button.offsetLeft - button.offsetWidth
|
|
438
537
|
: button.offsetLeft;
|
|
439
538
|
const end = start + button.offsetWidth;
|
|
@@ -455,15 +554,21 @@ const revealRanges = (container, side, lead) => {
|
|
|
455
554
|
* actions stay in place by themselves (see `Pin`) and scale in with the
|
|
456
555
|
* scroll (see `StyledSwipeAction`).
|
|
457
556
|
*/
|
|
458
|
-
const placeRow = (item, actions, offset,
|
|
557
|
+
const placeRow = (item, actions, offset, isAnimated, overswipes) => {
|
|
459
558
|
const direction = isRtl(item) ? -1 : 1;
|
|
460
559
|
const transition = (...properties) => properties
|
|
461
|
-
.map((property) => `${property} ${
|
|
560
|
+
.map((property) => `${property} ${isAnimated ? swipeDuration : 0}ms`)
|
|
462
561
|
.join(', ');
|
|
463
|
-
// Rounded at the side the content leaves (changing with the side only)
|
|
464
|
-
|
|
465
|
-
if (
|
|
466
|
-
item.style.
|
|
562
|
+
// Rounded at the side the content leaves (changing with the side only); at
|
|
563
|
+
// rest, none (the row's own corners, e.g. pressed, see `resetRow`).
|
|
564
|
+
if (offset === 0) {
|
|
565
|
+
item.style.removeProperty('clip-path');
|
|
566
|
+
}
|
|
567
|
+
else {
|
|
568
|
+
const clipPath = rowPath(item.offsetWidth, item.offsetHeight, offset * direction);
|
|
569
|
+
if (item.style.clipPath !== clipPath)
|
|
570
|
+
item.style.clipPath = clipPath;
|
|
571
|
+
}
|
|
467
572
|
for (const side of sides) {
|
|
468
573
|
const container = actions[side];
|
|
469
574
|
if (!container)
|
|
@@ -472,8 +577,8 @@ const placeRow = (item, actions, offset, animate, overswipes) => {
|
|
|
472
577
|
const revealed = Math.max(0, side === 'leading' ? offset : -offset);
|
|
473
578
|
const extra = overswipes(side) ? Math.max(0, revealed - width) : 0;
|
|
474
579
|
const outermost = outermostAction(container, side);
|
|
475
|
-
const
|
|
476
|
-
const towardsRow =
|
|
580
|
+
const isRowOnLeft = (side === 'trailing') === (direction === 1);
|
|
581
|
+
const towardsRow = isRowOnLeft ? -1 : 1;
|
|
477
582
|
const arm = armDistance(item, container, side, width);
|
|
478
583
|
const arming = Math.min(extra / (arm - width), 1);
|
|
479
584
|
// Past the armed place, on across the whole row (see `snapPlaces`): the
|
|
@@ -565,7 +670,251 @@ const snapPlaces = (swipe, lead, overswipes) => {
|
|
|
565
670
|
return places;
|
|
566
671
|
};
|
|
567
672
|
/** Whether the browser fires `scrollend` (else: a pause in scrolling). */
|
|
568
|
-
const
|
|
673
|
+
const hasScrollEnd = typeof window !== 'undefined' && 'onscrollend' in window;
|
|
674
|
+
/**
|
|
675
|
+
* Whether a row dragged to `offset` (towards `side`) opens its actions
|
|
676
|
+
* there when released: flicked towards them, or past half their `width`.
|
|
677
|
+
*/
|
|
678
|
+
const opensOnRelease = (drag, offset, side, width) => {
|
|
679
|
+
const distance = Math.abs(offset);
|
|
680
|
+
if (width === undefined || distance < 1)
|
|
681
|
+
return false;
|
|
682
|
+
const moved = offset - drag.base;
|
|
683
|
+
const isQuick = performance.now() - drag.time < 300;
|
|
684
|
+
const isMovedTowards = side === 'leading' ? moved > 10 : moved < -10;
|
|
685
|
+
return isQuick ? isMovedTowards : distance > width / 2;
|
|
686
|
+
};
|
|
687
|
+
/** How long a collapsible row opens or closes (as swiping). */
|
|
688
|
+
const expandDuration = 300;
|
|
689
|
+
// Rows opening and closing in place, as Base UI's Collapsible and Accordion
|
|
690
|
+
// (without elements of their own: a group's rows stay its children, a list
|
|
691
|
+
// having no other elements among them). A `CollapsibleRoot` (or an
|
|
692
|
+
// `AccordionItem`, its `AccordionRoot` holding which are open) holds the
|
|
693
|
+
// state, its `CollapsibleTrigger` (e.g. a row's title, `render`) toggles
|
|
694
|
+
// it, its `CollapsiblePanel` shows its rows.
|
|
695
|
+
const CollapsibleContext = createContext(undefined);
|
|
696
|
+
// A collapsible's rows' ids (see `useExpandedRow`), in mounting order: its
|
|
697
|
+
// trigger's `aria-controls`.
|
|
698
|
+
const useControls = () => {
|
|
699
|
+
const [ids, setIds] = useState([]);
|
|
700
|
+
const register = useCallback((id) => {
|
|
701
|
+
setIds((current) => [...current, id]);
|
|
702
|
+
return () => setIds((current) => current.filter((other) => other !== id));
|
|
703
|
+
}, []);
|
|
704
|
+
return [ids.join(' ') || undefined, register];
|
|
705
|
+
};
|
|
706
|
+
/**
|
|
707
|
+
* Rows' state (Base UI `Collapsible.Root`), for their trigger and them; no
|
|
708
|
+
* element of its own.
|
|
709
|
+
*/
|
|
710
|
+
const CollapsibleRoot = ({ children, defaultOpen = false, disabled = false, onOpenChange, open: openProp, }) => {
|
|
711
|
+
const [isUncontrolled, setIsUncontrolled] = useState(defaultOpen);
|
|
712
|
+
const isOpen = openProp ?? isUncontrolled;
|
|
713
|
+
const [controls, register] = useControls();
|
|
714
|
+
const context = useMemo(() => ({
|
|
715
|
+
controls,
|
|
716
|
+
disabled,
|
|
717
|
+
isOpen,
|
|
718
|
+
register,
|
|
719
|
+
setOpen: (isNextOpen, eventDetails) => {
|
|
720
|
+
onOpenChange?.(isNextOpen, eventDetails);
|
|
721
|
+
if (openProp === undefined)
|
|
722
|
+
setIsUncontrolled(isNextOpen);
|
|
723
|
+
},
|
|
724
|
+
}), [controls, disabled, isOpen, onOpenChange, openProp, register]);
|
|
725
|
+
return (_jsx(CollapsibleContext.Provider, { value: context, children: children }));
|
|
726
|
+
};
|
|
727
|
+
/**
|
|
728
|
+
* Toggles its collapsible's rows (Base UI `Collapsible.Trigger`,
|
|
729
|
+
* `Accordion.Trigger`): a button (e.g. rendered by a row's `Title`, making
|
|
730
|
+
* the row pressable), with `aria-expanded` and `aria-controls`.
|
|
731
|
+
*/
|
|
732
|
+
const CollapsibleTrigger = forwardRef(({ onClick, render, ...props }, ref) => {
|
|
733
|
+
const collapsible = useContext(CollapsibleContext);
|
|
734
|
+
return useRender({
|
|
735
|
+
defaultTagName: 'button',
|
|
736
|
+
props: {
|
|
737
|
+
'aria-controls': collapsible?.controls,
|
|
738
|
+
'aria-expanded': collapsible?.isOpen ?? false,
|
|
739
|
+
'data-disabled': collapsible?.disabled ? '' : undefined,
|
|
740
|
+
// (No part of its own: it's what it renders, e.g. a row's title, an
|
|
741
|
+
// accessory, keeping their styles.)
|
|
742
|
+
'data-panel-open': collapsible?.isOpen ? '' : undefined,
|
|
743
|
+
disabled: collapsible?.disabled,
|
|
744
|
+
type: 'button',
|
|
745
|
+
...props,
|
|
746
|
+
onClick: (event) => {
|
|
747
|
+
onClick?.(event);
|
|
748
|
+
if (event.defaultPrevented || !collapsible || collapsible.disabled) {
|
|
749
|
+
return;
|
|
750
|
+
}
|
|
751
|
+
collapsible.setOpen(!collapsible.isOpen, {
|
|
752
|
+
event: event,
|
|
753
|
+
reason: 'trigger-press',
|
|
754
|
+
});
|
|
755
|
+
},
|
|
756
|
+
},
|
|
757
|
+
ref,
|
|
758
|
+
render,
|
|
759
|
+
});
|
|
760
|
+
});
|
|
761
|
+
// The rows of a `CollapsiblePanel` (see `Item`): shown or not.
|
|
762
|
+
const PanelContext = createContext(undefined);
|
|
763
|
+
/**
|
|
764
|
+
* Its collapsible's rows (Base UI `Collapsible.Panel`, `Accordion.Panel`),
|
|
765
|
+
* shown or not, opening and closing in place, together (each its height),
|
|
766
|
+
* e.g. an inline `Calendar` or `TimeRoll` below a row with a `DatePicker`
|
|
767
|
+
* (see `DatePicker.Expandable`, as iOS's Calendar). Placed among a group's
|
|
768
|
+
* rows (no element of its own: the group's rows stay its children), or
|
|
769
|
+
* among another's (closed with it). Closed, they're inert.
|
|
770
|
+
*/
|
|
771
|
+
const CollapsiblePanel = ({ children, }) => {
|
|
772
|
+
const collapsible = useContext(CollapsibleContext);
|
|
773
|
+
// In another's rows: closed with it.
|
|
774
|
+
const outer = useContext(PanelContext);
|
|
775
|
+
const isOpen = (collapsible?.isOpen ?? false) && (outer?.isOpen ?? true);
|
|
776
|
+
const register = collapsible?.register;
|
|
777
|
+
const context = useMemo(() => ({ isOpen, register }), [isOpen, register]);
|
|
778
|
+
// Its rows aren't its collapsible's triggers (nor a picker's, see
|
|
779
|
+
// `useCollapsible`): theirs are their own collapsibles'.
|
|
780
|
+
return (_jsx(CollapsibleContext.Provider, { value: undefined, children: _jsx(PanelContext.Provider, { value: context, children: children }) }));
|
|
781
|
+
};
|
|
782
|
+
const AccordionContext = createContext(undefined);
|
|
783
|
+
/**
|
|
784
|
+
* Collapsibles, one open at a time (unless `multiple`), as Base UI
|
|
785
|
+
* `Accordion.Root`: its `AccordionItem`s, by their `value`; no element of
|
|
786
|
+
* its own.
|
|
787
|
+
*/
|
|
788
|
+
const AccordionRoot = ({ children, defaultValue = [], disabled = false, multiple = false, onValueChange, value: valueProp, }) => {
|
|
789
|
+
const [uncontrolled, setUncontrolled] = useState(defaultValue);
|
|
790
|
+
const value = valueProp ?? uncontrolled;
|
|
791
|
+
const context = useMemo(() => ({
|
|
792
|
+
disabled,
|
|
793
|
+
isOpen: (item) => value.includes(item),
|
|
794
|
+
setOpen: (item, isOpen, eventDetails) => {
|
|
795
|
+
const others = value.filter((open) => open !== item);
|
|
796
|
+
const next = isOpen
|
|
797
|
+
? [...(multiple ? others : []), item]
|
|
798
|
+
: others;
|
|
799
|
+
onValueChange?.(next, eventDetails);
|
|
800
|
+
if (valueProp === undefined)
|
|
801
|
+
setUncontrolled(next);
|
|
802
|
+
},
|
|
803
|
+
}), [disabled, multiple, onValueChange, value, valueProp]);
|
|
804
|
+
return (_jsx(AccordionContext.Provider, { value: context, children: children }));
|
|
805
|
+
};
|
|
806
|
+
/**
|
|
807
|
+
* A collapsible of its `AccordionRoot` (Base UI `Accordion.Item`), open as
|
|
808
|
+
* its root holds (by its `value`): its trigger and panel as a
|
|
809
|
+
* `CollapsibleRoot`'s; no element of its own.
|
|
810
|
+
*/
|
|
811
|
+
const AccordionItem = ({ children, disabled: disabledProp, onOpenChange, value: valueProp, }) => {
|
|
812
|
+
const accordion = useContext(AccordionContext);
|
|
813
|
+
const ownValue = useId();
|
|
814
|
+
const value = valueProp ?? ownValue;
|
|
815
|
+
const isOpen = accordion?.isOpen(value) ?? false;
|
|
816
|
+
const disabled = disabledProp ?? accordion?.disabled ?? false;
|
|
817
|
+
const [controls, register] = useControls();
|
|
818
|
+
const context = useMemo(() => ({
|
|
819
|
+
controls,
|
|
820
|
+
disabled,
|
|
821
|
+
isOpen,
|
|
822
|
+
register,
|
|
823
|
+
setOpen: (isNextOpen, eventDetails) => {
|
|
824
|
+
onOpenChange?.(isNextOpen, eventDetails);
|
|
825
|
+
accordion?.setOpen(value, isNextOpen, eventDetails);
|
|
826
|
+
},
|
|
827
|
+
}), [accordion, controls, disabled, isOpen, onOpenChange, register, value]);
|
|
828
|
+
return (_jsx(CollapsibleContext.Provider, { value: context, children: children }));
|
|
829
|
+
};
|
|
830
|
+
/**
|
|
831
|
+
* The collapsible around (a `CollapsibleRoot`, an `AccordionItem`; not in
|
|
832
|
+
* its panel): whether it's open, and opening or closing it (e.g. for a
|
|
833
|
+
* control opening rows of its own, see `DatePicker` `handle`).
|
|
834
|
+
*/
|
|
835
|
+
export const useCollapsible = () => useContext(CollapsibleContext);
|
|
836
|
+
/**
|
|
837
|
+
* Whether the collapsible rows around (see `CollapsiblePanel`) are open;
|
|
838
|
+
* `undefined` outside any (e.g. for a control closing its popups with
|
|
839
|
+
* them, see `DatePicker`).
|
|
840
|
+
*/
|
|
841
|
+
export const useExpandedOpen = () => useContext(PanelContext)?.isOpen;
|
|
842
|
+
/**
|
|
843
|
+
* A row of a `CollapsiblePanel`: shown or not (`isOpen`, unset outside
|
|
844
|
+
* one), its height and padding transitioning; its id (given, or its own)
|
|
845
|
+
* one its `CollapsibleTrigger` controls.
|
|
846
|
+
*/
|
|
847
|
+
const useExpandedRow = (itemRef, idProp) => {
|
|
848
|
+
const expanded = useContext(PanelContext);
|
|
849
|
+
const isOpen = expanded?.isOpen;
|
|
850
|
+
const ownId = useId();
|
|
851
|
+
const id = expanded && (idProp === undefined || typeof idProp === 'string')
|
|
852
|
+
? (idProp ?? ownId)
|
|
853
|
+
: undefined;
|
|
854
|
+
const register = expanded?.register;
|
|
855
|
+
const shown = useRef(undefined);
|
|
856
|
+
useLayoutEffect(() => (!register || id === undefined ? undefined : register(id)), [id, register]);
|
|
857
|
+
useLayoutEffect(() => {
|
|
858
|
+
const { current: item } = itemRef;
|
|
859
|
+
if (!item || isOpen === undefined)
|
|
860
|
+
return undefined;
|
|
861
|
+
const wasShown = shown.current;
|
|
862
|
+
shown.current = isOpen;
|
|
863
|
+
const settle = () => {
|
|
864
|
+
item.toggleAttribute('data-closed', !isOpen);
|
|
865
|
+
item.inert = !isOpen;
|
|
866
|
+
};
|
|
867
|
+
if (wasShown === undefined || wasShown === isOpen) {
|
|
868
|
+
settle();
|
|
869
|
+
return undefined;
|
|
870
|
+
}
|
|
871
|
+
// From its height as it is, to the other state's. Opening, it's
|
|
872
|
+
// measured open; closing, it closes once the animation finishes (its
|
|
873
|
+
// content shrinking at once, a scroll container could scroll back).
|
|
874
|
+
// eslint-disable-next-line unicorn/no-unnecessary-parameters
|
|
875
|
+
const box = (element) => {
|
|
876
|
+
const style = getComputedStyle(element);
|
|
877
|
+
return {
|
|
878
|
+
height: `${String(element.offsetHeight)}px`,
|
|
879
|
+
paddingBottom: style.paddingBottom,
|
|
880
|
+
paddingTop: style.paddingTop,
|
|
881
|
+
};
|
|
882
|
+
};
|
|
883
|
+
const closed = { height: '0px', paddingBottom: '0px', paddingTop: '0px' };
|
|
884
|
+
const from = isOpen ? closed : box(item);
|
|
885
|
+
if (isOpen)
|
|
886
|
+
settle();
|
|
887
|
+
const to = isOpen ? box(item) : closed;
|
|
888
|
+
item.inert = !isOpen;
|
|
889
|
+
item.style.overflow = 'clip';
|
|
890
|
+
const animation = item.animate([
|
|
891
|
+
{
|
|
892
|
+
...from,
|
|
893
|
+
minHeight: '0px',
|
|
894
|
+
opacity: isOpen ? 0 : 1,
|
|
895
|
+
visibility: 'visible',
|
|
896
|
+
},
|
|
897
|
+
{
|
|
898
|
+
...to,
|
|
899
|
+
minHeight: '0px',
|
|
900
|
+
opacity: isOpen ? 1 : 0,
|
|
901
|
+
visibility: 'visible',
|
|
902
|
+
},
|
|
903
|
+
], { duration: expandDuration, easing: 'ease' });
|
|
904
|
+
const done = () => {
|
|
905
|
+
item.style.removeProperty('overflow');
|
|
906
|
+
if (!isOpen)
|
|
907
|
+
settle();
|
|
908
|
+
};
|
|
909
|
+
animation.finished.then(done).catch(() => undefined);
|
|
910
|
+
return () => {
|
|
911
|
+
animation.cancel();
|
|
912
|
+
item.style.removeProperty('overflow');
|
|
913
|
+
settle();
|
|
914
|
+
};
|
|
915
|
+
}, [itemRef, isOpen]);
|
|
916
|
+
return id ?? idProp;
|
|
917
|
+
};
|
|
569
918
|
/**
|
|
570
919
|
* A row (UIKit `UITableViewCell`), with optional swipe actions. With a click
|
|
571
920
|
* handler, it's pressable itself (e.g. passing the click on to a control in
|
|
@@ -578,10 +927,19 @@ const scrollEnds = typeof window !== 'undefined' && 'onscrollend' in window;
|
|
|
578
927
|
* once the scroll comes to rest there, so scrolling back disarms it.
|
|
579
928
|
*/
|
|
580
929
|
const Item = forwardRef((itemProps, ref) => {
|
|
581
|
-
const { children, onBlurCapture, onClickCapture, onLostPointerCapture, onPointerCancel, onPointerDown, onPointerMove, onPointerUp, level, selected, style, ...props } = useSecondaryClick(itemProps);
|
|
930
|
+
const { children, onBlurCapture, onClickCapture, onLostPointerCapture, onPointerCancel, onPointerDown, onPointerMove, onPointerUp, editing: itemEditing, id: idProp, level, selected, style, ...props } = useSecondaryClick(itemProps);
|
|
931
|
+
const inheritedEditing = useContext(EditingContext);
|
|
932
|
+
const editing = itemEditing ?? inheritedEditing;
|
|
582
933
|
const itemRef = useForwardedRef(ref);
|
|
934
|
+
const id = useExpandedRow(itemRef, idProp);
|
|
935
|
+
useEditingSizes(itemRef, editing !== 'ignore');
|
|
936
|
+
useStrictSlots(itemRef);
|
|
583
937
|
const actionsRef = useRef({});
|
|
584
938
|
const overswipeRef = useRef({});
|
|
939
|
+
// What swiping does to each side's actions (see `ListAllowSwipe`).
|
|
940
|
+
const allowRef = useRef({});
|
|
941
|
+
const canReveal = (side) => ['all', 'reveal'].includes(allowRef.current[side] ?? 'all');
|
|
942
|
+
const canConceal = (side) => ['all', 'conceal'].includes(allowRef.current[side] ?? 'all');
|
|
585
943
|
const snapsRef = useRef({});
|
|
586
944
|
const swipeRef = useRef({ arms: {}, extents: {}, widths: {} });
|
|
587
945
|
const placesRef = useRef({});
|
|
@@ -593,17 +951,22 @@ const Item = forwardRef((itemProps, ref) => {
|
|
|
593
951
|
const swipingRef = useRef(false);
|
|
594
952
|
// Open, at rest there (see `overswipable`).
|
|
595
953
|
const restingOpenRef = useRef(false);
|
|
954
|
+
// The last wheel event's time (scrolled: at rest once the wheel is quiet).
|
|
955
|
+
const wheelRef = useRef(0);
|
|
596
956
|
const dragRef = useRef(null);
|
|
597
957
|
const pressRef = useRef(null);
|
|
598
958
|
const openSideRef = useRef(undefined);
|
|
599
959
|
const suppressClickRef = useRef(false);
|
|
600
960
|
const settleRef = useRef(undefined);
|
|
601
961
|
const outsideRef = useRef(undefined);
|
|
602
|
-
const [
|
|
962
|
+
const [isSwipeable, setIsSwipeable] = useState(false);
|
|
603
963
|
const [pin, setPin] = useState(null);
|
|
604
964
|
const overswipes = (side) => Boolean(overswipeRef.current[side]);
|
|
605
|
-
// The track's room before the row (the leading side's
|
|
606
|
-
|
|
965
|
+
// The track's room before the row (the leading side's, see `layOut`),
|
|
966
|
+
// and after it.
|
|
967
|
+
const leadRef = useRef(0);
|
|
968
|
+
const trailRef = useRef(0);
|
|
969
|
+
const lead = () => leadRef.current;
|
|
607
970
|
// The row's offset (towards its inline end), from the scroll position.
|
|
608
971
|
const offsetOf = (item) => isRtl(item) ? item.scrollLeft + lead() : lead() - item.scrollLeft;
|
|
609
972
|
// Overswiping a side: swiped (touch, a mouse drag) in one go; scrolled
|
|
@@ -612,31 +975,101 @@ const Item = forwardRef((itemProps, ref) => {
|
|
|
612
975
|
const overswipable = (side) => swipingRef.current ||
|
|
613
976
|
(openSideRef.current === side && restingOpenRef.current);
|
|
614
977
|
const overswipesNow = (side) => overswipes(side) && overswipable(side);
|
|
978
|
+
const scrollTo = (offset, isSmooth) => {
|
|
979
|
+
const { current: item } = itemRef;
|
|
980
|
+
if (!item)
|
|
981
|
+
return;
|
|
982
|
+
const isRightToLeft = isRtl(item);
|
|
983
|
+
const left = isRightToLeft ? offset - lead() : lead() - offset;
|
|
984
|
+
item.scrollTo({ behavior: isSmooth ? 'smooth' : 'instant', left });
|
|
985
|
+
};
|
|
986
|
+
// The track's room on a side: the actions' width; across the whole row
|
|
987
|
+
// only while overswiping it is possible (see `overswipable`), so a scroll
|
|
988
|
+
// opening the actions stops at them, not past them (snapping back).
|
|
989
|
+
const roomOf = (side) => {
|
|
990
|
+
// Not swiped open (see `allowSwipe`): no room, unless open.
|
|
991
|
+
if (openSideRef.current !== side && !canReveal(side))
|
|
992
|
+
return 0;
|
|
993
|
+
const { [side]: width = 0 } = swipeRef.current.widths;
|
|
994
|
+
return overswipesNow(side)
|
|
995
|
+
? (swipeRef.current.extents[side] ?? width)
|
|
996
|
+
: width;
|
|
997
|
+
};
|
|
998
|
+
// Lays the track out for each side's room: its size, the snap points'
|
|
999
|
+
// places, the actions' reveal; the row kept where it is (the room before
|
|
1000
|
+
// it moving the scroll position). The room grows at once, but narrows at
|
|
1001
|
+
// rest only (`isAtRest`): narrowed, the track re-snaps at once (e.g.
|
|
1002
|
+
// released from a drag, before snapping smoothly), and never less than
|
|
1003
|
+
// where the row is.
|
|
1004
|
+
const layOut = (isAtRest) => {
|
|
1005
|
+
const { current: item } = itemRef;
|
|
1006
|
+
if (!item)
|
|
1007
|
+
return;
|
|
1008
|
+
const offset = offsetOf(item);
|
|
1009
|
+
const fit = (room, current, reach) => Math.max(isAtRest ? room : Math.max(room, current), reach);
|
|
1010
|
+
const { current: wasLead } = leadRef;
|
|
1011
|
+
const { current: wasTrail } = trailRef;
|
|
1012
|
+
leadRef.current = fit(roomOf('leading'), leadRef.current, offset);
|
|
1013
|
+
trailRef.current = fit(roomOf('trailing'), trailRef.current, -offset);
|
|
1014
|
+
const isResized = leadRef.current !== wasLead || trailRef.current !== wasTrail;
|
|
1015
|
+
item.style.setProperty('--uikit-list-swipe-lead', `${String(lead())}px`);
|
|
1016
|
+
item.style.setProperty('--uikit-list-swipe-trail', `${String(trailRef.current)}px`);
|
|
1017
|
+
const places = snapPlaces(swipeRef.current, lead(), overswipes);
|
|
1018
|
+
placesRef.current = places;
|
|
1019
|
+
for (const side of sides) {
|
|
1020
|
+
const { [side]: container } = actionsRef.current;
|
|
1021
|
+
if (!container)
|
|
1022
|
+
continue;
|
|
1023
|
+
revealRanges(container, side, lead());
|
|
1024
|
+
// Safari keeps running its reveal (on the compositor) for the scroll
|
|
1025
|
+
// range it started in, so scaling in out of order and flickering once
|
|
1026
|
+
// the room changed (e.g. as a swipe starts, overswiping): restarted.
|
|
1027
|
+
if (!isResized)
|
|
1028
|
+
continue;
|
|
1029
|
+
for (const animation of container.getAnimations({ subtree: true })) {
|
|
1030
|
+
// (Not the stretched action's transitions.)
|
|
1031
|
+
if (!(animation instanceof CSSAnimation))
|
|
1032
|
+
continue;
|
|
1033
|
+
animation.cancel();
|
|
1034
|
+
animation.play();
|
|
1035
|
+
}
|
|
1036
|
+
}
|
|
1037
|
+
for (const point of snapPoints) {
|
|
1038
|
+
const snap = snapsRef.current[point];
|
|
1039
|
+
if (snap)
|
|
1040
|
+
snap.style.insetInlineStart = `${String(places[point] ?? 0)}px`;
|
|
1041
|
+
}
|
|
1042
|
+
// (Only if it moved: a scroll on its way, e.g. closing, goes on.)
|
|
1043
|
+
if (offsetOf(item) !== offset)
|
|
1044
|
+
scrollTo(offset, false);
|
|
1045
|
+
};
|
|
615
1046
|
// The snap points (see `snapPlaces`). Open, the other side's actions
|
|
616
1047
|
// don't open (scrolled past closed, the row snaps back closed): only from
|
|
617
1048
|
// closed; overswiped, only as above. (They change at rest, or as a touch
|
|
618
|
-
// starts, only: changed while scrolling, browsers snap at once.)
|
|
619
|
-
|
|
1049
|
+
// starts, only: changed while scrolling, browsers snap at once.) Safari
|
|
1050
|
+
// snaps to the point at the same place in their order once they change
|
|
1051
|
+
// (e.g. armed, shown before closed as a touch starts), so the row is put
|
|
1052
|
+
// back where it was.
|
|
1053
|
+
const showSnaps = (isAtRest = false) => {
|
|
1054
|
+
const { current: item } = itemRef;
|
|
1055
|
+
const offset = item ? offsetOf(item) : undefined;
|
|
1056
|
+
// (The room changing with them, see `layOut`.)
|
|
1057
|
+
layOut(isAtRest);
|
|
620
1058
|
const { current: openSide } = openSideRef;
|
|
621
1059
|
for (const point of snapPoints) {
|
|
622
1060
|
const snap = snapsRef.current[point];
|
|
623
1061
|
if (!snap)
|
|
624
1062
|
continue;
|
|
625
1063
|
const side = point.startsWith('leading') ? 'leading' : 'trailing';
|
|
626
|
-
const
|
|
1064
|
+
const isOverswiping = point.endsWith('Armed') || point.endsWith('Overswipe');
|
|
627
1065
|
snap.hidden =
|
|
628
1066
|
placesRef.current[point] === undefined ||
|
|
629
1067
|
(openSide !== undefined && point !== 'closed' && side !== openSide) ||
|
|
630
|
-
(
|
|
1068
|
+
(isOverswiping && !overswipable(side));
|
|
1069
|
+
}
|
|
1070
|
+
if (item && offset !== undefined && offsetOf(item) !== offset) {
|
|
1071
|
+
scrollTo(offset, false);
|
|
631
1072
|
}
|
|
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
1073
|
};
|
|
641
1074
|
// Measures the actions (and the row) for the track's room and snap
|
|
642
1075
|
// points, keeping the row where it is (closed, or open).
|
|
@@ -657,23 +1090,7 @@ const Item = forwardRef((itemProps, ref) => {
|
|
|
657
1090
|
swipe.extents[side] = overswipes(side) ? item.clientWidth : width;
|
|
658
1091
|
}
|
|
659
1092
|
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
|
-
}
|
|
1093
|
+
showSnaps(true);
|
|
677
1094
|
const { current: side } = openSideRef;
|
|
678
1095
|
const offset = side
|
|
679
1096
|
? (side === 'leading' ? 1 : -1) * (swipe.widths[side] ?? 0)
|
|
@@ -695,6 +1112,18 @@ const Item = forwardRef((itemProps, ref) => {
|
|
|
695
1112
|
}
|
|
696
1113
|
item.style.removeProperty('clip-path');
|
|
697
1114
|
};
|
|
1115
|
+
// As allowed (see `allowSwipe`), keyboards too: open, not swiped closed,
|
|
1116
|
+
// no scrolling (closed by scrolling it programmatically only); closed,
|
|
1117
|
+
// not swiped open, its actions inert (not revealed by focusing them).
|
|
1118
|
+
const lock = () => {
|
|
1119
|
+
const { current: openSide } = openSideRef;
|
|
1120
|
+
itemRef.current?.toggleAttribute('data-swipe-locked', openSide !== undefined && !canConceal(openSide));
|
|
1121
|
+
for (const side of sides) {
|
|
1122
|
+
const { [side]: container } = actionsRef.current;
|
|
1123
|
+
if (container)
|
|
1124
|
+
container.inert = openSide !== side && !canReveal(side);
|
|
1125
|
+
}
|
|
1126
|
+
};
|
|
698
1127
|
const context = useMemo(() => {
|
|
699
1128
|
const value = {
|
|
700
1129
|
close: () => {
|
|
@@ -709,9 +1138,19 @@ const Item = forwardRef((itemProps, ref) => {
|
|
|
709
1138
|
openSideRef.current = undefined;
|
|
710
1139
|
restingOpenRef.current = false;
|
|
711
1140
|
closingRef.current = true;
|
|
1141
|
+
lock();
|
|
712
1142
|
// (Its snap points change once closed, see `settle`.)
|
|
713
1143
|
scrollTo(0, true);
|
|
714
1144
|
},
|
|
1145
|
+
focus: (side) => {
|
|
1146
|
+
if (openSideRef.current !== side)
|
|
1147
|
+
return;
|
|
1148
|
+
// (The row scrolling to show them on its own.)
|
|
1149
|
+
actionsRef.current[side]
|
|
1150
|
+
?.querySelector('button:not(:disabled)')
|
|
1151
|
+
?.focus({ preventScroll: true });
|
|
1152
|
+
},
|
|
1153
|
+
isOpen: (side) => openSideRef.current === side,
|
|
715
1154
|
open: (side) => {
|
|
716
1155
|
const { current: item } = itemRef;
|
|
717
1156
|
const width = swipeRef.current.widths[side];
|
|
@@ -723,12 +1162,15 @@ const Item = forwardRef((itemProps, ref) => {
|
|
|
723
1162
|
if (openSideRef.current !== side)
|
|
724
1163
|
restingOpenRef.current = false;
|
|
725
1164
|
openSideRef.current = side;
|
|
1165
|
+
lock();
|
|
726
1166
|
showSnaps();
|
|
727
1167
|
scrollTo((side === 'leading' ? 1 : -1) * width, true);
|
|
728
1168
|
if (outsideRef.current)
|
|
729
1169
|
return;
|
|
730
1170
|
outsideRef.current = (event) => {
|
|
731
|
-
|
|
1171
|
+
// Not swiped closed (see `allowSwipe`): nor by a press outside.
|
|
1172
|
+
if ((event.target instanceof Node && item.contains(event.target)) ||
|
|
1173
|
+
(openSideRef.current && !canConceal(openSideRef.current))) {
|
|
732
1174
|
return;
|
|
733
1175
|
}
|
|
734
1176
|
value.close();
|
|
@@ -737,15 +1179,17 @@ const Item = forwardRef((itemProps, ref) => {
|
|
|
737
1179
|
capture: true,
|
|
738
1180
|
});
|
|
739
1181
|
},
|
|
740
|
-
setActions: (side, element, overswipe = false) => {
|
|
1182
|
+
setActions: (side, element, overswipe = false, allowSwipe = 'all') => {
|
|
741
1183
|
overswipeRef.current[side] = overswipe;
|
|
1184
|
+
allowRef.current[side] = allowSwipe;
|
|
742
1185
|
if (element) {
|
|
743
1186
|
actionsRef.current[side] = element;
|
|
744
1187
|
}
|
|
745
1188
|
else {
|
|
746
1189
|
delete actionsRef.current[side];
|
|
747
1190
|
}
|
|
748
|
-
|
|
1191
|
+
lock();
|
|
1192
|
+
setIsSwipeable(Boolean(actionsRef.current.leading ?? actionsRef.current.trailing));
|
|
749
1193
|
measureRef.current();
|
|
750
1194
|
},
|
|
751
1195
|
};
|
|
@@ -781,11 +1225,32 @@ const Item = forwardRef((itemProps, ref) => {
|
|
|
781
1225
|
if (container)
|
|
782
1226
|
outermostAction(container, side)?.click();
|
|
783
1227
|
};
|
|
1228
|
+
// Not swiped closed (see `allowSwipe`): nor scrolled closed otherwise
|
|
1229
|
+
// (e.g. by the browser, focusing the row's content), open again.
|
|
1230
|
+
const reopen = () => {
|
|
1231
|
+
const { current: openSide } = openSideRef;
|
|
1232
|
+
if (!openSide || canConceal(openSide))
|
|
1233
|
+
return false;
|
|
1234
|
+
const { [openSide]: width = 0 } = swipeRef.current.widths;
|
|
1235
|
+
scrollTo((openSide === 'leading' ? 1 : -1) * width, true);
|
|
1236
|
+
return true;
|
|
1237
|
+
};
|
|
1238
|
+
// Closed, at rest.
|
|
1239
|
+
const restClosed = (item) => {
|
|
1240
|
+
swipingRef.current = false;
|
|
1241
|
+
restingOpenRef.current = false;
|
|
1242
|
+
openSideRef.current = undefined;
|
|
1243
|
+
lock();
|
|
1244
|
+
showSnaps(true);
|
|
1245
|
+
if (closeOpenItem === context.close)
|
|
1246
|
+
closeOpenItem = undefined;
|
|
1247
|
+
resetRow(item);
|
|
1248
|
+
};
|
|
784
1249
|
// The scroll at rest (not touched): overswiped (armed, or across the
|
|
785
1250
|
// whole row: triggering there), open or closed.
|
|
786
1251
|
const settle = () => {
|
|
787
1252
|
const { current: item } = itemRef;
|
|
788
|
-
if (!item || dragRef.current?.
|
|
1253
|
+
if (!item || dragRef.current?.isMoved || touchingRef.current)
|
|
789
1254
|
return;
|
|
790
1255
|
item.style.removeProperty('scroll-snap-type');
|
|
791
1256
|
const offset = offsetOf(item);
|
|
@@ -794,15 +1259,11 @@ const Item = forwardRef((itemProps, ref) => {
|
|
|
794
1259
|
const { [side]: width = 0 } = swipeRef.current.widths;
|
|
795
1260
|
const { [side]: extent = 0 } = swipeRef.current.extents;
|
|
796
1261
|
const { [side]: arm = Infinity } = swipeRef.current.arms;
|
|
1262
|
+
const { current: isClosing } = closingRef;
|
|
797
1263
|
closingRef.current = false;
|
|
798
1264
|
if (distance < 1) {
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
openSideRef.current = undefined;
|
|
802
|
-
showSnaps();
|
|
803
|
-
if (closeOpenItem === context.close)
|
|
804
|
-
closeOpenItem = undefined;
|
|
805
|
-
resetRow(item);
|
|
1265
|
+
if (isClosing || !reopen())
|
|
1266
|
+
restClosed(item);
|
|
806
1267
|
return;
|
|
807
1268
|
}
|
|
808
1269
|
if (overswipesNow(side) && distance > arm) {
|
|
@@ -821,9 +1282,18 @@ const Item = forwardRef((itemProps, ref) => {
|
|
|
821
1282
|
if (Math.abs(distance - width) < 1) {
|
|
822
1283
|
if (openSideRef.current !== side)
|
|
823
1284
|
context.open(side);
|
|
1285
|
+
// Scrolled open (stopped at the actions, see `roomOf`): at rest only
|
|
1286
|
+
// once the wheel (a trackpad's momentum too) is quiet, so the same
|
|
1287
|
+
// scroll doesn't overswipe.
|
|
1288
|
+
const quiet = performance.now() - wheelRef.current;
|
|
1289
|
+
if (quiet < wheelQuiet) {
|
|
1290
|
+
clearTimeout(settleRef.current);
|
|
1291
|
+
settleRef.current = setTimeout(settle, wheelQuiet - quiet);
|
|
1292
|
+
return;
|
|
1293
|
+
}
|
|
824
1294
|
restingOpenRef.current = true;
|
|
825
1295
|
}
|
|
826
|
-
showSnaps();
|
|
1296
|
+
showSnaps(true);
|
|
827
1297
|
};
|
|
828
1298
|
// Scrolled (by any means): the row's actions follow, overswiping arms
|
|
829
1299
|
// past its distance.
|
|
@@ -835,18 +1305,23 @@ const Item = forwardRef((itemProps, ref) => {
|
|
|
835
1305
|
const side = offset > 0 ? 'leading' : 'trailing';
|
|
836
1306
|
if (Math.abs(offset) >= 1) {
|
|
837
1307
|
item.dataset.swipe = side;
|
|
838
|
-
|
|
1308
|
+
// (Swiped, it closes another row's; closing, not: e.g. as another
|
|
1309
|
+
// opens by a trigger, which its scroll would close again.)
|
|
1310
|
+
if (!closingRef.current &&
|
|
1311
|
+
closeOpenItem &&
|
|
1312
|
+
closeOpenItem !== context.close) {
|
|
839
1313
|
closeOpenItem();
|
|
1314
|
+
}
|
|
840
1315
|
}
|
|
841
1316
|
placeRow(item, actionsRef.current, offset, false, overswipesNow);
|
|
842
1317
|
const { [side]: arm = Infinity } = swipeRef.current.arms;
|
|
843
|
-
const
|
|
1318
|
+
const isArmed = !closingRef.current && overswipesNow(side) && Math.abs(offset) > arm;
|
|
844
1319
|
for (const key of sides) {
|
|
845
1320
|
const { [key]: actions } = actionsRef.current;
|
|
846
1321
|
const action = actions && outermostAction(actions, key);
|
|
847
|
-
action?.toggleAttribute('data-armed',
|
|
1322
|
+
action?.toggleAttribute('data-armed', isArmed && key === side);
|
|
848
1323
|
}
|
|
849
|
-
if (
|
|
1324
|
+
if (hasScrollEnd)
|
|
850
1325
|
return;
|
|
851
1326
|
clearTimeout(settleRef.current);
|
|
852
1327
|
settleRef.current = setTimeout(settle, scrollEndDelay);
|
|
@@ -860,9 +1335,12 @@ const Item = forwardRef((itemProps, ref) => {
|
|
|
860
1335
|
});
|
|
861
1336
|
useEffect(() => {
|
|
862
1337
|
const { current: item } = itemRef;
|
|
863
|
-
if (!item || !
|
|
1338
|
+
if (!item || !isSwipeable)
|
|
864
1339
|
return undefined;
|
|
865
1340
|
const onScrollEnd = () => settleNowRef.current();
|
|
1341
|
+
const onWheel = () => {
|
|
1342
|
+
wheelRef.current = performance.now();
|
|
1343
|
+
};
|
|
866
1344
|
const onTouchStart = () => {
|
|
867
1345
|
touchingRef.current = true;
|
|
868
1346
|
// Swiped: overswiping in one go (see `overswipable`).
|
|
@@ -877,19 +1355,21 @@ const Item = forwardRef((itemProps, ref) => {
|
|
|
877
1355
|
settleRef.current = setTimeout(onScrollEnd, scrollEndDelay);
|
|
878
1356
|
};
|
|
879
1357
|
item.addEventListener('scrollend', onScrollEnd);
|
|
1358
|
+
item.addEventListener('wheel', onWheel, { passive: true });
|
|
880
1359
|
item.addEventListener('touchstart', onTouchStart, { passive: true });
|
|
881
1360
|
item.addEventListener('touchend', onTouchEnd);
|
|
882
1361
|
item.addEventListener('touchcancel', onTouchEnd);
|
|
883
1362
|
return () => {
|
|
884
1363
|
item.removeEventListener('scrollend', onScrollEnd);
|
|
1364
|
+
item.removeEventListener('wheel', onWheel);
|
|
885
1365
|
item.removeEventListener('touchstart', onTouchStart);
|
|
886
1366
|
item.removeEventListener('touchend', onTouchEnd);
|
|
887
1367
|
item.removeEventListener('touchcancel', onTouchEnd);
|
|
888
1368
|
};
|
|
889
|
-
}, [itemRef,
|
|
1369
|
+
}, [itemRef, isSwipeable]);
|
|
890
1370
|
useLayoutEffect(() => {
|
|
891
1371
|
const { current: item } = itemRef;
|
|
892
|
-
if (!item || !
|
|
1372
|
+
if (!item || !isSwipeable)
|
|
893
1373
|
return undefined;
|
|
894
1374
|
measureRef.current();
|
|
895
1375
|
const observer = new ResizeObserver(() => measureRef.current());
|
|
@@ -900,7 +1380,7 @@ const Item = forwardRef((itemProps, ref) => {
|
|
|
900
1380
|
observer.observe(container);
|
|
901
1381
|
}
|
|
902
1382
|
return () => observer.disconnect();
|
|
903
|
-
}, [itemRef,
|
|
1383
|
+
}, [itemRef, isSwipeable]);
|
|
904
1384
|
const release = () => {
|
|
905
1385
|
if (itemRef.current)
|
|
906
1386
|
delete itemRef.current.dataset.pressed;
|
|
@@ -916,7 +1396,7 @@ const Item = forwardRef((itemProps, ref) => {
|
|
|
916
1396
|
if (props.onClick && !(control && item.contains(control))) {
|
|
917
1397
|
item.dataset.pressed = '';
|
|
918
1398
|
}
|
|
919
|
-
if (!
|
|
1399
|
+
if (!isSwipeable ||
|
|
920
1400
|
sides.some((side) => actions[side]?.contains(event.target))) {
|
|
921
1401
|
return;
|
|
922
1402
|
}
|
|
@@ -925,12 +1405,17 @@ const Item = forwardRef((itemProps, ref) => {
|
|
|
925
1405
|
x: event.clientX,
|
|
926
1406
|
y: event.clientY,
|
|
927
1407
|
};
|
|
928
|
-
// Touch scrolls natively; a mouse drags the scroll position
|
|
1408
|
+
// Touch scrolls natively; a mouse drags the scroll position, as allowed
|
|
1409
|
+
// (see `allowSwipe`; touch: by the room, and the lock, see style.css).
|
|
929
1410
|
if (event.pointerType !== 'mouse' || isOwnGesture(item, event))
|
|
930
1411
|
return;
|
|
1412
|
+
const { current: openSide } = openSideRef;
|
|
1413
|
+
if (openSide ? !canConceal(openSide) : sides.every((side) => !canReveal(side))) {
|
|
1414
|
+
return;
|
|
1415
|
+
}
|
|
931
1416
|
dragRef.current = {
|
|
932
1417
|
base: offsetOf(item),
|
|
933
|
-
|
|
1418
|
+
isMoved: false,
|
|
934
1419
|
pointerId: event.pointerId,
|
|
935
1420
|
scroll: item.scrollLeft,
|
|
936
1421
|
time: performance.now(),
|
|
@@ -945,7 +1430,7 @@ const Item = forwardRef((itemProps, ref) => {
|
|
|
945
1430
|
if (!item || drag?.pointerId !== event.pointerId)
|
|
946
1431
|
return;
|
|
947
1432
|
const dx = event.clientX - drag.x;
|
|
948
|
-
if (!drag.
|
|
1433
|
+
if (!drag.isMoved) {
|
|
949
1434
|
const vertical = Math.abs(event.clientY - drag.y);
|
|
950
1435
|
if (vertical > swipeThreshold && vertical > Math.abs(dx)) {
|
|
951
1436
|
dragRef.current = null;
|
|
@@ -953,7 +1438,7 @@ const Item = forwardRef((itemProps, ref) => {
|
|
|
953
1438
|
}
|
|
954
1439
|
if (Math.abs(dx) < swipeThreshold)
|
|
955
1440
|
return;
|
|
956
|
-
drag.
|
|
1441
|
+
drag.isMoved = true;
|
|
957
1442
|
// Swiped: overswiping in one go (see `overswipable`).
|
|
958
1443
|
swipingRef.current = true;
|
|
959
1444
|
release();
|
|
@@ -966,7 +1451,7 @@ const Item = forwardRef((itemProps, ref) => {
|
|
|
966
1451
|
};
|
|
967
1452
|
// A mouse drag released: overswiped (armed), opened (past half its
|
|
968
1453
|
// actions, or quickly towards them) or closed, scrolling there.
|
|
969
|
-
const endDrag = (drag,
|
|
1454
|
+
const endDrag = (drag, isCancelled) => {
|
|
970
1455
|
const { current: item } = itemRef;
|
|
971
1456
|
if (!item)
|
|
972
1457
|
return;
|
|
@@ -977,10 +1462,10 @@ const Item = forwardRef((itemProps, ref) => {
|
|
|
977
1462
|
const { [side]: arm = Infinity } = swipeRef.current.arms;
|
|
978
1463
|
suppressClick();
|
|
979
1464
|
// Open, the other side doesn't (see `showSnaps`).
|
|
980
|
-
const
|
|
1465
|
+
const isLocked = openSideRef.current !== undefined && openSideRef.current !== side;
|
|
981
1466
|
// Across the whole row, triggering there (see `settle`): not snapping
|
|
982
1467
|
// until then (which would start where it is).
|
|
983
|
-
if (!
|
|
1468
|
+
if (!isLocked && !isCancelled && overswipesNow(side) && distance > arm) {
|
|
984
1469
|
const { [side]: extent = 0 } = swipeRef.current.extents;
|
|
985
1470
|
scrollTo((side === 'leading' ? 1 : -1) * extent, true);
|
|
986
1471
|
return;
|
|
@@ -989,30 +1474,28 @@ const Item = forwardRef((itemProps, ref) => {
|
|
|
989
1474
|
// where it's dragged, as far as overswiped).
|
|
990
1475
|
swipingRef.current = false;
|
|
991
1476
|
showSnaps();
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
1477
|
+
const isOpening = !isLocked && !isCancelled && opensOnRelease(drag, offset, side, width);
|
|
1478
|
+
// Snapping again once at rest there (see `settle`): snapping now, the
|
|
1479
|
+
// browser would snap at once, not smoothly. (Already there: now.)
|
|
1480
|
+
if (Math.abs(distance - (isOpening ? (width ?? 0) : 0)) < 1) {
|
|
1481
|
+
item.style.removeProperty('scroll-snap-type');
|
|
996
1482
|
}
|
|
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) {
|
|
1483
|
+
if (isOpening) {
|
|
1001
1484
|
context.open(side);
|
|
1002
1485
|
}
|
|
1003
1486
|
else {
|
|
1004
1487
|
context.close();
|
|
1005
1488
|
}
|
|
1006
1489
|
};
|
|
1007
|
-
const finish = (event,
|
|
1490
|
+
const finish = (event, isCancelled) => {
|
|
1008
1491
|
const { current: press } = pressRef;
|
|
1009
1492
|
const { current: drag } = dragRef;
|
|
1010
1493
|
if (press?.pointerId === event.pointerId)
|
|
1011
1494
|
pressRef.current = null;
|
|
1012
1495
|
if (drag?.pointerId === event.pointerId) {
|
|
1013
1496
|
dragRef.current = null;
|
|
1014
|
-
if (drag.
|
|
1015
|
-
endDrag(drag,
|
|
1497
|
+
if (drag.isMoved) {
|
|
1498
|
+
endDrag(drag, isCancelled);
|
|
1016
1499
|
return;
|
|
1017
1500
|
}
|
|
1018
1501
|
}
|
|
@@ -1020,7 +1503,7 @@ const Item = forwardRef((itemProps, ref) => {
|
|
|
1020
1503
|
return;
|
|
1021
1504
|
// A tap on an open row closes it.
|
|
1022
1505
|
const moved = Math.hypot(event.clientX - press.x, event.clientY - press.y);
|
|
1023
|
-
if (!
|
|
1506
|
+
if (!isCancelled && moved < swipeThreshold && openSideRef.current) {
|
|
1024
1507
|
context.close();
|
|
1025
1508
|
suppressClick();
|
|
1026
1509
|
}
|
|
@@ -1028,10 +1511,15 @@ const Item = forwardRef((itemProps, ref) => {
|
|
|
1028
1511
|
const handleBlurCapture = (event) => {
|
|
1029
1512
|
onBlurCapture?.(event);
|
|
1030
1513
|
const { current: item } = itemRef;
|
|
1031
|
-
|
|
1514
|
+
const { current: openSide } = openSideRef;
|
|
1515
|
+
// Not swiped closed (see `allowSwipe`): nor by focus leaving it.
|
|
1516
|
+
if (!openSide || !item || !canConceal(openSide))
|
|
1032
1517
|
return;
|
|
1518
|
+
// Focus moving elsewhere only (e.g. tabbing on): not to nothing, as
|
|
1519
|
+
// WebKit's, pressing a button (its actions' too) not focusing it (a
|
|
1520
|
+
// press outside closes it, see `open`).
|
|
1033
1521
|
const { relatedTarget } = event;
|
|
1034
|
-
if (relatedTarget instanceof Node
|
|
1522
|
+
if (!(relatedTarget instanceof Node) || item.contains(relatedTarget)) {
|
|
1035
1523
|
return;
|
|
1036
1524
|
}
|
|
1037
1525
|
context.close();
|
|
@@ -1044,9 +1532,9 @@ const Item = forwardRef((itemProps, ref) => {
|
|
|
1044
1532
|
event.preventDefault();
|
|
1045
1533
|
event.stopPropagation();
|
|
1046
1534
|
};
|
|
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":
|
|
1535
|
+
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
1536
|
'--uikit-list-level': level === undefined ? undefined : String(level),
|
|
1049
|
-
}, style), ...props, onBlurCapture: handleBlurCapture, onClickCapture: handleClickCapture, onPointerDown: handlePointerDown, onPointerMove: handlePointerMove, onScroll:
|
|
1537
|
+
}, style), ...props, onBlurCapture: handleBlurCapture, onClickCapture: handleClickCapture, onPointerDown: handlePointerDown, onPointerMove: handlePointerMove, onScroll: isSwipeable ? onScroll : undefined, onLostPointerCapture: (event) => {
|
|
1050
1538
|
onLostPointerCapture?.(event);
|
|
1051
1539
|
// Only the row's own capture: taking it over from the touched
|
|
1052
1540
|
// element (implicitly captured) makes that lose its capture.
|
|
@@ -1061,83 +1549,87 @@ const Item = forwardRef((itemProps, ref) => {
|
|
|
1061
1549
|
onPointerUp?.(event);
|
|
1062
1550
|
release();
|
|
1063
1551
|
finish(event, false);
|
|
1064
|
-
}, children: _jsxs("div", { className: "uikit-list-track", "data-list-part": "track", children: [_jsx(Pin, { ref: setPin }),
|
|
1552
|
+
}, children: _jsxs("div", { className: "uikit-list-track", "data-list-part": "track", children: [_jsx(Pin, { ref: setPin }), isSwipeable
|
|
1065
1553
|
? snapPoints.map((point) => (_jsx("span", { ref: (element) => {
|
|
1066
1554
|
snapsRef.current[point] = element;
|
|
1067
1555
|
}, hidden: true, "aria-hidden": "true", className: "uikit-list-snap", "data-closed": point === 'closed' ? '' : undefined, "data-list-part": "snap" }, point)))
|
|
1068
1556
|
: null, _jsx(PinContext.Provider, { value: pin, children: _jsx("div", { className: "uikit-list-row", "data-list-part": "row", children: children }) })] }) }) }));
|
|
1069
1557
|
});
|
|
1070
|
-
|
|
1071
|
-
|
|
1558
|
+
// Row slots (see style.css): a row's parts in a line, in their order;
|
|
1559
|
+
// elements of other components only in these.
|
|
1072
1560
|
/**
|
|
1073
|
-
*
|
|
1074
|
-
*
|
|
1075
|
-
* `DatePicker` (without popovers, as iOS's Calendar). Closed, it's inert.
|
|
1561
|
+
* Any elements before a row's content (e.g. a spinner, an avatar), in a
|
|
1562
|
+
* line; several per row; sliding in or out in edit mode (`whileEditing`).
|
|
1076
1563
|
*/
|
|
1077
|
-
const
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1564
|
+
const Leading = forwardRef(({ className, render, whileEditing, ...props }, ref) => useRender({
|
|
1565
|
+
defaultTagName: 'span',
|
|
1566
|
+
props: {
|
|
1567
|
+
'data-list-part': 'leading',
|
|
1568
|
+
...whileEditingOf(whileEditing),
|
|
1569
|
+
className: cn('uikit-list-leading', className),
|
|
1570
|
+
...props,
|
|
1571
|
+
},
|
|
1572
|
+
ref,
|
|
1573
|
+
render,
|
|
1574
|
+
}));
|
|
1575
|
+
/**
|
|
1576
|
+
* Any elements after a row's content (e.g. a `Switch`, a `Stepper`), in a
|
|
1577
|
+
* line; several per row; sliding in or out in edit mode (`whileEditing`).
|
|
1578
|
+
*/
|
|
1579
|
+
const Trailing = forwardRef(({ className, render, whileEditing, ...props }, ref) => useRender({
|
|
1580
|
+
defaultTagName: 'span',
|
|
1581
|
+
props: {
|
|
1582
|
+
'data-list-part': 'trailing',
|
|
1583
|
+
...whileEditingOf(whileEditing),
|
|
1584
|
+
className: cn('uikit-list-trailing', className),
|
|
1585
|
+
...props,
|
|
1586
|
+
},
|
|
1587
|
+
ref,
|
|
1588
|
+
render,
|
|
1589
|
+
}));
|
|
1590
|
+
/**
|
|
1591
|
+
* A row's text (its `Title`, `Subtitle`, `Text`; or a field's label),
|
|
1592
|
+
* taking the rest of its line; every row has one (or a `Span`).
|
|
1593
|
+
*/
|
|
1594
|
+
const Content = forwardRef(({ className, render, ...props }, ref) => useRender({
|
|
1595
|
+
defaultTagName: 'span',
|
|
1596
|
+
props: {
|
|
1597
|
+
'data-list-part': 'content',
|
|
1598
|
+
className: cn('uikit-list-content', className),
|
|
1599
|
+
...props,
|
|
1600
|
+
},
|
|
1601
|
+
ref,
|
|
1602
|
+
render,
|
|
1603
|
+
}));
|
|
1604
|
+
/**
|
|
1605
|
+
* Content across a row's whole line (e.g. a `Slider` between its symbols,
|
|
1606
|
+
* a `Segmented` control, an inline calendar).
|
|
1607
|
+
*/
|
|
1608
|
+
const Span = forwardRef(({ className, render, ...props }, ref) => useRender({
|
|
1609
|
+
defaultTagName: 'span',
|
|
1610
|
+
props: {
|
|
1611
|
+
'data-list-part': 'span',
|
|
1612
|
+
className: cn('uikit-list-span', className),
|
|
1613
|
+
...props,
|
|
1614
|
+
},
|
|
1615
|
+
ref,
|
|
1616
|
+
render,
|
|
1617
|
+
}));
|
|
1618
|
+
/**
|
|
1619
|
+
* A line under a row's line, across it (e.g. a field's description and
|
|
1620
|
+
* error, a status); last in its row. Hidden (`hidden`), it collapses:
|
|
1621
|
+
* growing and shrinking as it's shown and hidden (kept rendered).
|
|
1622
|
+
*/
|
|
1623
|
+
const Below = forwardRef(({ className, render, ...props }, ref) => useRender({
|
|
1624
|
+
defaultTagName: 'div',
|
|
1625
|
+
props: {
|
|
1626
|
+
'data-list-part': 'below',
|
|
1627
|
+
className: cn('uikit-list-below', className),
|
|
1628
|
+
...props,
|
|
1629
|
+
},
|
|
1630
|
+
ref,
|
|
1631
|
+
render,
|
|
1632
|
+
}));
|
|
1141
1633
|
// Figma “Title”; as a link or button (`render`), it makes the row pressable.
|
|
1142
1634
|
const Title = forwardRef(({ className, render, ...props }, ref) => useRender({
|
|
1143
1635
|
defaultTagName: 'span',
|
|
@@ -1248,24 +1740,30 @@ const DrillIn = forwardRef(({ children, className, render, ...props }, ref) => u
|
|
|
1248
1740
|
}));
|
|
1249
1741
|
// Figma “Disclosure” (rows: 17px, headers: 19px, 590, in the tint color),
|
|
1250
1742
|
// 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
|
-
})
|
|
1743
|
+
const Disclosure = forwardRef(({ children, className, render, ...props }, ref) => {
|
|
1744
|
+
// Turned down while its row's collapsible is open (see
|
|
1745
|
+
// `CollapsibleRoot`, `AccordionItem`).
|
|
1746
|
+
const collapsible = useContext(CollapsibleContext);
|
|
1747
|
+
return useRender({
|
|
1748
|
+
defaultTagName: 'span',
|
|
1749
|
+
props: {
|
|
1750
|
+
'data-list-part': 'disclosure',
|
|
1751
|
+
'data-panel-open': collapsible?.isOpen ? '' : undefined,
|
|
1752
|
+
className: cn('uikit-list-disclosure', className),
|
|
1753
|
+
'aria-hidden': 'true',
|
|
1754
|
+
children: children ?? _jsx(Chevron, {}),
|
|
1755
|
+
...props,
|
|
1756
|
+
},
|
|
1757
|
+
ref,
|
|
1758
|
+
render,
|
|
1759
|
+
});
|
|
1760
|
+
});
|
|
1263
1761
|
// Figma “_Grabber” (, 17px, 400).
|
|
1264
1762
|
/**
|
|
1265
1763
|
* Figma “_Grabber”: drags its row to reorder its group (see `Group`
|
|
1266
1764
|
* `onReorder`); focused, arrow keys move the row.
|
|
1267
1765
|
*/
|
|
1268
|
-
const Grabber = forwardRef(({ children, className, render, ...props }, ref) => useRender({
|
|
1766
|
+
const Grabber = forwardRef(({ children, className, onClick, render, ...props }, ref) => useRender({
|
|
1269
1767
|
defaultTagName: 'span',
|
|
1270
1768
|
props: {
|
|
1271
1769
|
'data-list-part': 'grabber',
|
|
@@ -1273,6 +1771,13 @@ const Grabber = forwardRef(({ children, className, render, ...props }, ref) => u
|
|
|
1273
1771
|
tabIndex: 0,
|
|
1274
1772
|
children: children ?? _jsx(Lines, {}),
|
|
1275
1773
|
...props,
|
|
1774
|
+
// The click ending a drag (captured by the grabber, see `useReorder`)
|
|
1775
|
+
// stays with it: its row doesn't act on it (e.g. pass it on to its
|
|
1776
|
+
// checkbox, see `forwardClick`).
|
|
1777
|
+
onClick: (event) => {
|
|
1778
|
+
onClick?.(event);
|
|
1779
|
+
event.stopPropagation();
|
|
1780
|
+
},
|
|
1276
1781
|
},
|
|
1277
1782
|
ref,
|
|
1278
1783
|
render,
|
|
@@ -1304,17 +1809,16 @@ const Button = forwardRef(({ className, destructive, render, ...props }, ref) =>
|
|
|
1304
1809
|
render,
|
|
1305
1810
|
}));
|
|
1306
1811
|
/** Figma State=Selected/Unselected: a checkbox (selecting rows). */
|
|
1307
|
-
const Checkbox = forwardRef((props, ref) => (_jsx(CheckboxBase.Root, { ref: ref, "data-list-part": "edit", ...props })));
|
|
1812
|
+
const Checkbox = forwardRef(({ whileEditing, ...props }, ref) => (_jsx(CheckboxBase.Root, { ref: ref, "data-list-part": "edit", ...whileEditingOf(whileEditing), ...props })));
|
|
1308
1813
|
/**
|
|
1309
1814
|
* A radio (selecting one row), as `Checkbox`; its group is a `RadioGroup`
|
|
1310
1815
|
* (e.g. rendering a `Group`).
|
|
1311
1816
|
*/
|
|
1312
1817
|
const Radio = forwardRef((props, ref) => (_jsx(RadioBase.Root, { ref: ref, "data-list-part": "edit", ...props })));
|
|
1313
|
-
const StyledEditButton = forwardRef(({ className,
|
|
1818
|
+
const StyledEditButton = forwardRef(({ className, render, ...props }, ref) => useRender({
|
|
1314
1819
|
defaultTagName: 'button',
|
|
1315
1820
|
props: {
|
|
1316
1821
|
'data-list-part': 'edit',
|
|
1317
|
-
'data-editing-style': editingStyle,
|
|
1318
1822
|
className: cn('uikit-list-edit-button uikit-checkbox-edit-circle', className),
|
|
1319
1823
|
type: 'button',
|
|
1320
1824
|
...useSecondaryClick(props),
|
|
@@ -1323,18 +1827,14 @@ const StyledEditButton = forwardRef(({ className, editingStyle, render, ...props
|
|
|
1323
1827
|
render,
|
|
1324
1828
|
}));
|
|
1325
1829
|
/**
|
|
1326
|
-
* Figma State=Remove/Add
|
|
1327
|
-
* (
|
|
1830
|
+
* Figma State=Remove/Add: a symbol (its child) in a circle of its `tint`,
|
|
1831
|
+
* doing what the app gives it (e.g. deleting the row; or, rendered by a
|
|
1832
|
+
* `SwipeActionsTrigger`, opening its trailing actions).
|
|
1328
1833
|
*/
|
|
1329
|
-
const EditButton = forwardRef(({
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
if (event.defaultPrevented || editingStyle !== 'delete')
|
|
1334
|
-
return;
|
|
1335
|
-
item?.open('trailing');
|
|
1336
|
-
}, children: children ?? _jsx(Sign, { plus: editingStyle === 'insert' }) }));
|
|
1337
|
-
});
|
|
1834
|
+
const EditButton = forwardRef(({ style, textColor, tint, ...props }, ref) => (_jsx(StyledEditButton, { ref: ref, style: withStyle({
|
|
1835
|
+
'--uikit-list-edit-text-color': textColor,
|
|
1836
|
+
'--uikit-list-edit-tint': tint,
|
|
1837
|
+
}, style), ...props })));
|
|
1338
1838
|
// Swipe actions (Figma “Row with Swipe Actions”, “_Swipe Actions”): shapes
|
|
1339
1839
|
// 10px apart, 10px from the row and 16px from the edge.
|
|
1340
1840
|
// Circles centered in the row, rounded rectangles 4px from its edges.
|
|
@@ -1350,7 +1850,7 @@ const StyledSwipeActions = forwardRef(({ className, overswipe, render, side, ...
|
|
|
1350
1850
|
ref,
|
|
1351
1851
|
render,
|
|
1352
1852
|
}));
|
|
1353
|
-
const SwipeActions = forwardRef(({ onFocusCapture, onOverswipe, overswipe = false, side: sideProp = 'inline-end', ...props }, ref) => {
|
|
1853
|
+
const SwipeActions = forwardRef(({ allowSwipe = 'all', handle, onFocusCapture, onOverswipe, overswipe = false, side: sideProp = 'inline-end', ...props }, ref) => {
|
|
1354
1854
|
// (Internally: leading, trailing.)
|
|
1355
1855
|
const side = sideProp === 'inline-start' ? 'leading' : 'trailing';
|
|
1356
1856
|
const item = useContext(ItemContext);
|
|
@@ -1362,13 +1862,24 @@ const SwipeActions = forwardRef(({ onFocusCapture, onOverswipe, overswipe = fals
|
|
|
1362
1862
|
onOverswipeRef.current = onOverswipe;
|
|
1363
1863
|
});
|
|
1364
1864
|
const hasHandler = onOverswipe !== undefined;
|
|
1865
|
+
// Opened and closed by their handle, while mounted.
|
|
1866
|
+
useLayoutEffect(() => {
|
|
1867
|
+
if (!handle || !item)
|
|
1868
|
+
return undefined;
|
|
1869
|
+
return handle.attach({
|
|
1870
|
+
close: () => item.close(),
|
|
1871
|
+
focus: () => item.focus(side),
|
|
1872
|
+
isOpen: () => item.isOpen(side),
|
|
1873
|
+
open: () => item.open(side),
|
|
1874
|
+
});
|
|
1875
|
+
}, [handle, item, side]);
|
|
1365
1876
|
useLayoutEffect(() => {
|
|
1366
1877
|
const { current: element } = elementRef;
|
|
1367
1878
|
if (!item || !element)
|
|
1368
1879
|
return undefined;
|
|
1369
|
-
item.setActions(side, element, hasHandler ? () => onOverswipeRef.current?.() : overswipe);
|
|
1880
|
+
item.setActions(side, element, hasHandler ? () => onOverswipeRef.current?.() : overswipe, allowSwipe);
|
|
1370
1881
|
return () => item.setActions(side, undefined);
|
|
1371
|
-
}, [elementRef, hasHandler, item, overswipe, pin, side]);
|
|
1882
|
+
}, [allowSwipe, elementRef, hasHandler, item, overswipe, pin, side]);
|
|
1372
1883
|
// In the row's pin layer, staying in place as it scrolls (see `Pin`).
|
|
1373
1884
|
if (!pin)
|
|
1374
1885
|
return null;
|
|
@@ -1377,6 +1888,40 @@ const SwipeActions = forwardRef(({ onFocusCapture, onOverswipe, overswipe = fals
|
|
|
1377
1888
|
item?.open(side);
|
|
1378
1889
|
} }), pin);
|
|
1379
1890
|
});
|
|
1891
|
+
/**
|
|
1892
|
+
* Opens a row's swipe actions when clicked (Base UI's triggers' shape):
|
|
1893
|
+
* those of its `handle`, from anywhere, or, in the row, its own on its
|
|
1894
|
+
* `side`; focusing the first of them. Renders a button, or what it's given
|
|
1895
|
+
* (e.g. the delete `EditButton`).
|
|
1896
|
+
*/
|
|
1897
|
+
const SwipeActionsTrigger = forwardRef(({ className, handle, onClick, render, side = 'inline-end', ...props }, ref) => {
|
|
1898
|
+
const item = useContext(ItemContext);
|
|
1899
|
+
return useRender({
|
|
1900
|
+
defaultTagName: 'button',
|
|
1901
|
+
props: {
|
|
1902
|
+
className: cn('uikit-list-swipe-actions-trigger', className),
|
|
1903
|
+
type: 'button',
|
|
1904
|
+
...props,
|
|
1905
|
+
onClick: (event) => {
|
|
1906
|
+
onClick?.(event);
|
|
1907
|
+
if (event.defaultPrevented)
|
|
1908
|
+
return;
|
|
1909
|
+
// Moving focus to the actions it opened (as Base UI's triggers
|
|
1910
|
+
// to their popups).
|
|
1911
|
+
if (handle) {
|
|
1912
|
+
handle.open();
|
|
1913
|
+
handle.focus();
|
|
1914
|
+
return;
|
|
1915
|
+
}
|
|
1916
|
+
const itemSide = side === 'inline-start' ? 'leading' : 'trailing';
|
|
1917
|
+
item?.open(itemSide);
|
|
1918
|
+
item?.focus(itemSide);
|
|
1919
|
+
},
|
|
1920
|
+
},
|
|
1921
|
+
ref,
|
|
1922
|
+
render,
|
|
1923
|
+
});
|
|
1924
|
+
});
|
|
1380
1925
|
const StyledSwipeAction = forwardRef(({ className, render, shape, showLabel, ...props }, ref) => useRender({
|
|
1381
1926
|
defaultTagName: 'button',
|
|
1382
1927
|
props: {
|
|
@@ -1480,6 +2025,8 @@ const Index = forwardRef(({ onLostPointerCapture, onPointerCancel, onPointerDown
|
|
|
1480
2025
|
end: () => undefined,
|
|
1481
2026
|
move: (index, state, event) => scrub(index, state, event.clientY),
|
|
1482
2027
|
start: (index, event) => {
|
|
2028
|
+
// No text selection while scrubbing (from the mouse's default).
|
|
2029
|
+
event.preventDefault();
|
|
1483
2030
|
const state = {};
|
|
1484
2031
|
scrub(index, state, event.clientY);
|
|
1485
2032
|
return state;
|
|
@@ -1526,7 +2073,19 @@ export const List = {
|
|
|
1526
2073
|
Header,
|
|
1527
2074
|
Group,
|
|
1528
2075
|
Item,
|
|
1529
|
-
|
|
2076
|
+
Leading,
|
|
2077
|
+
Content,
|
|
2078
|
+
Trailing,
|
|
2079
|
+
Span,
|
|
2080
|
+
Below,
|
|
2081
|
+
CollapsibleRoot,
|
|
2082
|
+
CollapsibleTrigger,
|
|
2083
|
+
CollapsiblePanel,
|
|
2084
|
+
AccordionRoot,
|
|
2085
|
+
AccordionItem,
|
|
2086
|
+
// (Base UI's names in an accordion: the same parts.)
|
|
2087
|
+
AccordionTrigger: CollapsibleTrigger,
|
|
2088
|
+
AccordionPanel: CollapsiblePanel,
|
|
1530
2089
|
Footer,
|
|
1531
2090
|
Block,
|
|
1532
2091
|
Title,
|
|
@@ -1546,8 +2105,10 @@ export const List = {
|
|
|
1546
2105
|
Radio,
|
|
1547
2106
|
EditButton,
|
|
1548
2107
|
SwipeActions,
|
|
2108
|
+
SwipeActionsTrigger,
|
|
1549
2109
|
SwipeAction,
|
|
1550
2110
|
Index,
|
|
1551
2111
|
IndexItem,
|
|
2112
|
+
createSwipeActionsHandle,
|
|
1552
2113
|
};
|
|
1553
2114
|
//# sourceMappingURL=main.js.map
|