@zyncat/ui 0.8.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/LICENSE +21 -0
- package/README.md +133 -0
- package/dist/alert.css +132 -0
- package/dist/alert.d.ts +46 -0
- package/dist/alert.js +80 -0
- package/dist/alert.js.map +1 -0
- package/dist/avatar-group.d.ts +24 -0
- package/dist/avatar-group.js +23 -0
- package/dist/avatar-group.js.map +1 -0
- package/dist/avatar.css +200 -0
- package/dist/avatar.d.ts +35 -0
- package/dist/avatar.js +67 -0
- package/dist/avatar.js.map +1 -0
- package/dist/badge.css +182 -0
- package/dist/badge.d.ts +34 -0
- package/dist/badge.js +4 -0
- package/dist/badge.js.map +1 -0
- package/dist/button.css +269 -0
- package/dist/button.d.ts +44 -0
- package/dist/button.js +4 -0
- package/dist/button.js.map +1 -0
- package/dist/checkbox.css +177 -0
- package/dist/checkbox.d.ts +35 -0
- package/dist/checkbox.js +5 -0
- package/dist/checkbox.js.map +1 -0
- package/dist/chunk-2ERBBFZS.js +12 -0
- package/dist/chunk-2ERBBFZS.js.map +1 -0
- package/dist/chunk-2HORSLXJ.js +191 -0
- package/dist/chunk-2HORSLXJ.js.map +1 -0
- package/dist/chunk-36WVAQKL.js +40 -0
- package/dist/chunk-36WVAQKL.js.map +1 -0
- package/dist/chunk-3SBCBYB7.js +575 -0
- package/dist/chunk-3SBCBYB7.js.map +1 -0
- package/dist/chunk-4R2GQO43.js +125 -0
- package/dist/chunk-4R2GQO43.js.map +1 -0
- package/dist/chunk-64UU4LGU.js +258 -0
- package/dist/chunk-64UU4LGU.js.map +1 -0
- package/dist/chunk-7SZCJ7WI.js +35 -0
- package/dist/chunk-7SZCJ7WI.js.map +1 -0
- package/dist/chunk-BIDVNLJO.js +38 -0
- package/dist/chunk-BIDVNLJO.js.map +1 -0
- package/dist/chunk-CONSWNIV.js +17 -0
- package/dist/chunk-CONSWNIV.js.map +1 -0
- package/dist/chunk-EQ32F2QJ.js +75 -0
- package/dist/chunk-EQ32F2QJ.js.map +1 -0
- package/dist/chunk-GY7JOPUQ.js +111 -0
- package/dist/chunk-GY7JOPUQ.js.map +1 -0
- package/dist/chunk-I4XQ4PV2.js +30 -0
- package/dist/chunk-I4XQ4PV2.js.map +1 -0
- package/dist/chunk-JSKXZMLH.js +67 -0
- package/dist/chunk-JSKXZMLH.js.map +1 -0
- package/dist/chunk-L3Q3VDIW.js +295 -0
- package/dist/chunk-L3Q3VDIW.js.map +1 -0
- package/dist/chunk-LDC3RIYA.js +62 -0
- package/dist/chunk-LDC3RIYA.js.map +1 -0
- package/dist/chunk-MKIQFK7S.js +43 -0
- package/dist/chunk-MKIQFK7S.js.map +1 -0
- package/dist/chunk-MMRIQNEN.js +20 -0
- package/dist/chunk-MMRIQNEN.js.map +1 -0
- package/dist/chunk-MXOPCFWR.js +59 -0
- package/dist/chunk-MXOPCFWR.js.map +1 -0
- package/dist/chunk-NEF5XAHG.js +17 -0
- package/dist/chunk-NEF5XAHG.js.map +1 -0
- package/dist/chunk-NNXJCLTV.js +22 -0
- package/dist/chunk-NNXJCLTV.js.map +1 -0
- package/dist/chunk-O4N2OBTR.js +94 -0
- package/dist/chunk-O4N2OBTR.js.map +1 -0
- package/dist/chunk-PMECHR3A.js +38 -0
- package/dist/chunk-PMECHR3A.js.map +1 -0
- package/dist/chunk-QDK66S4G.js +44 -0
- package/dist/chunk-QDK66S4G.js.map +1 -0
- package/dist/chunk-QGNC7LH5.js +8 -0
- package/dist/chunk-QGNC7LH5.js.map +1 -0
- package/dist/chunk-QMSJZCK3.js +398 -0
- package/dist/chunk-QMSJZCK3.js.map +1 -0
- package/dist/chunk-S5ZTZANS.js +57 -0
- package/dist/chunk-S5ZTZANS.js.map +1 -0
- package/dist/chunk-S7B34VGN.js +14 -0
- package/dist/chunk-S7B34VGN.js.map +1 -0
- package/dist/chunk-TCUCYFT7.js +25 -0
- package/dist/chunk-TCUCYFT7.js.map +1 -0
- package/dist/chunk-TYHR4VNM.js +193 -0
- package/dist/chunk-TYHR4VNM.js.map +1 -0
- package/dist/chunk-U5QQZC3U.js +56 -0
- package/dist/chunk-U5QQZC3U.js.map +1 -0
- package/dist/chunk-UE63OOVG.js +13 -0
- package/dist/chunk-UE63OOVG.js.map +1 -0
- package/dist/chunk-VTJTGVZZ.js +22 -0
- package/dist/chunk-VTJTGVZZ.js.map +1 -0
- package/dist/chunk-W3SHPKSB.js +49 -0
- package/dist/chunk-W3SHPKSB.js.map +1 -0
- package/dist/chunk-XZAEIQDR.js +188 -0
- package/dist/chunk-XZAEIQDR.js.map +1 -0
- package/dist/chunk-YGGCQNNU.js +92 -0
- package/dist/chunk-YGGCQNNU.js.map +1 -0
- package/dist/collapse.css +88 -0
- package/dist/collapse.d.ts +46 -0
- package/dist/collapse.js +5 -0
- package/dist/collapse.js.map +1 -0
- package/dist/count-badge.d.ts +13 -0
- package/dist/count-badge.js +13 -0
- package/dist/count-badge.js.map +1 -0
- package/dist/date-field.d.ts +25 -0
- package/dist/date-field.js +87 -0
- package/dist/date-field.js.map +1 -0
- package/dist/date-picker.css +595 -0
- package/dist/date-range-field.d.ts +33 -0
- package/dist/date-range-field.js +404 -0
- package/dist/date-range-field.js.map +1 -0
- package/dist/datetime-field.d.ts +29 -0
- package/dist/datetime-field.js +155 -0
- package/dist/datetime-field.js.map +1 -0
- package/dist/dialog.css +180 -0
- package/dist/dialog.d.ts +42 -0
- package/dist/dialog.js +128 -0
- package/dist/dialog.js.map +1 -0
- package/dist/dom-props-C0jrllBw.d.ts +5 -0
- package/dist/field-chrome-CMPOQSLs.d.ts +28 -0
- package/dist/field-shell-Cuda-feL.d.ts +24 -0
- package/dist/glide.d.ts +15 -0
- package/dist/glide.js +5 -0
- package/dist/glide.js.map +1 -0
- package/dist/icon.css +33 -0
- package/dist/input.css +333 -0
- package/dist/mcp.js +359 -0
- package/dist/motion-devtools.css +265 -0
- package/dist/motion-devtools.d.ts +51 -0
- package/dist/motion-devtools.js +354 -0
- package/dist/motion-devtools.js.map +1 -0
- package/dist/motion-scale-Canq4stZ.d.ts +18 -0
- package/dist/motion-tokens.d.ts +28 -0
- package/dist/motion-tokens.js +3 -0
- package/dist/motion-tokens.js.map +1 -0
- package/dist/multi-select.d.ts +44 -0
- package/dist/multi-select.js +109 -0
- package/dist/multi-select.js.map +1 -0
- package/dist/number-field.d.ts +36 -0
- package/dist/number-field.js +112 -0
- package/dist/number-field.js.map +1 -0
- package/dist/odometer.css +62 -0
- package/dist/otp-field.d.ts +31 -0
- package/dist/otp-field.js +98 -0
- package/dist/otp-field.js.map +1 -0
- package/dist/overlay.css +23 -0
- package/dist/pagination.css +43 -0
- package/dist/pagination.d.ts +29 -0
- package/dist/pagination.js +107 -0
- package/dist/pagination.js.map +1 -0
- package/dist/popover.css +69 -0
- package/dist/popover.d.ts +35 -0
- package/dist/popover.js +15 -0
- package/dist/popover.js.map +1 -0
- package/dist/radio-group.css +300 -0
- package/dist/radio-group.d.ts +52 -0
- package/dist/radio-group.js +115 -0
- package/dist/radio-group.js.map +1 -0
- package/dist/select.css +416 -0
- package/dist/select.d.ts +49 -0
- package/dist/select.js +99 -0
- package/dist/select.js.map +1 -0
- package/dist/sheet.css +26 -0
- package/dist/sheet.d.ts +31 -0
- package/dist/sheet.js +14 -0
- package/dist/sheet.js.map +1 -0
- package/dist/status-badge.d.ts +19 -0
- package/dist/status-badge.js +72 -0
- package/dist/status-badge.js.map +1 -0
- package/dist/table.css +348 -0
- package/dist/table.d.ts +75 -0
- package/dist/table.js +262 -0
- package/dist/table.js.map +1 -0
- package/dist/tabs.css +208 -0
- package/dist/tabs.d.ts +71 -0
- package/dist/tabs.js +181 -0
- package/dist/tabs.js.map +1 -0
- package/dist/tag.css +248 -0
- package/dist/tag.d.ts +52 -0
- package/dist/tag.js +72 -0
- package/dist/tag.js.map +1 -0
- package/dist/text-field.d.ts +28 -0
- package/dist/text-field.js +69 -0
- package/dist/text-field.js.map +1 -0
- package/dist/textarea.css +219 -0
- package/dist/textarea.d.ts +38 -0
- package/dist/textarea.js +144 -0
- package/dist/textarea.js.map +1 -0
- package/dist/time-field.d.ts +28 -0
- package/dist/time-field.js +66 -0
- package/dist/time-field.js.map +1 -0
- package/dist/timing-7JA_zQHP.d.ts +27 -0
- package/dist/toast-store.d.ts +86 -0
- package/dist/toast-store.js +3 -0
- package/dist/toast-store.js.map +1 -0
- package/dist/toast.css +257 -0
- package/dist/toast.d.ts +12 -0
- package/dist/toast.js +310 -0
- package/dist/toast.js.map +1 -0
- package/dist/toggle-tag.d.ts +34 -0
- package/dist/toggle-tag.js +57 -0
- package/dist/toggle-tag.js.map +1 -0
- package/dist/toggle.css +152 -0
- package/dist/toggle.d.ts +31 -0
- package/dist/toggle.js +75 -0
- package/dist/toggle.js.map +1 -0
- package/dist/tooltip.css +86 -0
- package/dist/tooltip.d.ts +30 -0
- package/dist/tooltip.js +268 -0
- package/dist/tooltip.js.map +1 -0
- package/dist/types-SGMShK7R.d.ts +22 -0
- package/llms.txt +196 -0
- package/next.d.mts +7 -0
- package/next.mjs +59 -0
- package/package.json +257 -0
- package/src/components/composites/alert/Alert.tsx +141 -0
- package/src/components/composites/alert/alert.css +132 -0
- package/src/components/composites/date-picker/DateField.tsx +80 -0
- package/src/components/composites/date-picker/DateRangeField.tsx +110 -0
- package/src/components/composites/date-picker/DateTimeField.tsx +162 -0
- package/src/components/composites/date-picker/TimeField.tsx +78 -0
- package/src/components/composites/date-picker/calendar-panel.tsx +216 -0
- package/src/components/composites/date-picker/date-picker.css +595 -0
- package/src/components/composites/date-picker/date-utils.ts +56 -0
- package/src/components/composites/date-picker/field-shell.tsx +85 -0
- package/src/components/composites/date-picker/range-panel.tsx +363 -0
- package/src/components/composites/date-picker/time-core.tsx +290 -0
- package/src/components/composites/date-picker/use-day-focus.ts +35 -0
- package/src/components/composites/dialog/Dialog.tsx +198 -0
- package/src/components/composites/dialog/dialog.css +180 -0
- package/src/components/composites/pagination/Pagination.tsx +131 -0
- package/src/components/composites/pagination/pagination.css +43 -0
- package/src/components/composites/popover/Popover.tsx +141 -0
- package/src/components/composites/popover/popover.css +69 -0
- package/src/components/composites/select/MultiSelect.tsx +133 -0
- package/src/components/composites/select/Select.tsx +122 -0
- package/src/components/composites/select/core/index.ts +4 -0
- package/src/components/composites/select/core/menu.tsx +100 -0
- package/src/components/composites/select/core/panel.tsx +154 -0
- package/src/components/composites/select/core/trigger.tsx +74 -0
- package/src/components/composites/select/core/types.ts +39 -0
- package/src/components/composites/select/core/use-listbox.ts +182 -0
- package/src/components/composites/select/select.css +416 -0
- package/src/components/composites/sheet/Sheet.tsx +135 -0
- package/src/components/composites/sheet/sheet.css +26 -0
- package/src/components/composites/sheet/use-sheet-drag.ts +126 -0
- package/src/components/composites/table/Table.tsx +377 -0
- package/src/components/composites/table/table.css +348 -0
- package/src/components/composites/tabs/Tabs.tsx +278 -0
- package/src/components/composites/tabs/tabs.css +208 -0
- package/src/components/composites/toast/Toast.tsx +380 -0
- package/src/components/composites/toast/toast-store.ts +295 -0
- package/src/components/composites/toast/toast.css +257 -0
- package/src/components/composites/tooltip/Tooltip.tsx +110 -0
- package/src/components/composites/tooltip/tooltip-host.tsx +184 -0
- package/src/components/composites/tooltip/tooltip-store.ts +81 -0
- package/src/components/composites/tooltip/tooltip.css +86 -0
- package/src/components/dev/MotionDevtools.tsx +200 -0
- package/src/components/dev/motion-devtools.css +265 -0
- package/src/components/dev/slowmo-engine.ts +230 -0
- package/src/components/internal/glass/glass.css +100 -0
- package/src/components/internal/glass/glint.ts +9 -0
- package/src/components/internal/hooks/use-controllable.ts +21 -0
- package/src/components/internal/hooks/use-scroll-edges.ts +46 -0
- package/src/components/internal/icon/Icon.tsx +66 -0
- package/src/components/internal/icon/IconSlot.tsx +10 -0
- package/src/components/internal/icon/icon.css +33 -0
- package/src/components/internal/overlay/focus.ts +68 -0
- package/src/components/internal/overlay/layer.tsx +149 -0
- package/src/components/internal/overlay/modal.tsx +141 -0
- package/src/components/internal/overlay/overlay.css +23 -0
- package/src/components/internal/overlay/position.ts +103 -0
- package/src/components/internal/utils/cx.ts +3 -0
- package/src/components/internal/utils/token-px.ts +8 -0
- package/src/components/primitives/avatar/Avatar.tsx +120 -0
- package/src/components/primitives/avatar/AvatarGroup.tsx +56 -0
- package/src/components/primitives/avatar/avatar.css +200 -0
- package/src/components/primitives/badge/Badge.tsx +75 -0
- package/src/components/primitives/badge/CountBadge.tsx +20 -0
- package/src/components/primitives/badge/StatusBadge.tsx +111 -0
- package/src/components/primitives/badge/badge.css +182 -0
- package/src/components/primitives/badge/odometer.css +62 -0
- package/src/components/primitives/badge/odometer.tsx +36 -0
- package/src/components/primitives/button/Button.tsx +102 -0
- package/src/components/primitives/button/button.css +269 -0
- package/src/components/primitives/checkbox/Checkbox.tsx +76 -0
- package/src/components/primitives/checkbox/check-glyph.tsx +28 -0
- package/src/components/primitives/checkbox/checkbox.css +177 -0
- package/src/components/primitives/collapse/Collapse.tsx +86 -0
- package/src/components/primitives/collapse/collapse.css +88 -0
- package/src/components/primitives/collapse/collapse.typecheck.tsx +29 -0
- package/src/components/primitives/input/NumberField.tsx +139 -0
- package/src/components/primitives/input/OtpField.tsx +134 -0
- package/src/components/primitives/input/TextField.tsx +110 -0
- package/src/components/primitives/input/field-chrome.tsx +83 -0
- package/src/components/primitives/input/input.css +333 -0
- package/src/components/primitives/radio-group/RadioGroup.tsx +183 -0
- package/src/components/primitives/radio-group/radio-group.css +300 -0
- package/src/components/primitives/tag/Tag.tsx +143 -0
- package/src/components/primitives/tag/ToggleTag.tsx +97 -0
- package/src/components/primitives/tag/tag.css +248 -0
- package/src/components/primitives/textarea/Textarea.tsx +190 -0
- package/src/components/primitives/textarea/textarea.css +219 -0
- package/src/components/primitives/toggle/Toggle.tsx +105 -0
- package/src/components/primitives/toggle/toggle.css +152 -0
- package/src/css.d.ts +1 -0
- package/src/dom-props.ts +1 -0
- package/src/engine/animate.ts +141 -0
- package/src/engine/drag.ts +53 -0
- package/src/engine/ease.ts +155 -0
- package/src/engine/flip.ts +59 -0
- package/src/engine/index.ts +13 -0
- package/src/mcp/server.ts +420 -0
- package/src/motion/element.tsx +53 -0
- package/src/motion/flip.tsx +87 -0
- package/src/motion/glide.tsx +47 -0
- package/src/motion/motion-timing.ts +33 -0
- package/src/motion/presence-context.ts +18 -0
- package/src/motion/presence.tsx +91 -0
- package/src/motion/timing.ts +49 -0
- package/src/motion/use-motion.ts +64 -0
- package/src/styles.css +26 -0
- package/src/tokens/avatar.css +20 -0
- package/src/tokens/color.css +58 -0
- package/src/tokens/elevation.css +22 -0
- package/src/tokens/fonts.css +3 -0
- package/src/tokens/glass.css +20 -0
- package/src/tokens/icons.css +7 -0
- package/src/tokens/layers.css +6 -0
- package/src/tokens/motion-scale.ts +17 -0
- package/src/tokens/motion-tokens.ts +92 -0
- package/src/tokens/motion.css +49 -0
- package/src/tokens/radius.css +11 -0
- package/src/tokens/semantic.css +65 -0
- package/src/tokens/spacing.css +26 -0
- package/src/tokens/typography.css +52 -0
|
@@ -0,0 +1,416 @@
|
|
|
1
|
+
/* Select family - <Select> (single) + <MultiSelect>, one .select__* vocabulary (no native <select>). */
|
|
2
|
+
|
|
3
|
+
.select {
|
|
4
|
+
position: relative;
|
|
5
|
+
display: inline-block;
|
|
6
|
+
width: 100%;
|
|
7
|
+
font-family: var(--font-sans);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
.select__trigger {
|
|
11
|
+
appearance: none;
|
|
12
|
+
margin: 0;
|
|
13
|
+
font-family: inherit;
|
|
14
|
+
cursor: pointer;
|
|
15
|
+
text-align: left;
|
|
16
|
+
display: flex;
|
|
17
|
+
align-items: center;
|
|
18
|
+
gap: var(--space-2);
|
|
19
|
+
width: 100%;
|
|
20
|
+
height: var(--control-height);
|
|
21
|
+
padding: 0 var(--space-3);
|
|
22
|
+
background: var(--bg-inset);
|
|
23
|
+
border: var(--border-hairline) solid var(--border-default);
|
|
24
|
+
border-radius: var(--radius-md);
|
|
25
|
+
color: var(--text-body);
|
|
26
|
+
font-size: var(--size-body);
|
|
27
|
+
line-height: var(--leading-body);
|
|
28
|
+
font-weight: var(--weight-regular);
|
|
29
|
+
transition:
|
|
30
|
+
color var(--duration-base) var(--ease-standard),
|
|
31
|
+
background-color var(--duration-base) var(--ease-standard),
|
|
32
|
+
border-color var(--duration-base) var(--ease-standard),
|
|
33
|
+
box-shadow var(--duration-base) var(--ease-standard);
|
|
34
|
+
}
|
|
35
|
+
.select__trigger:hover {
|
|
36
|
+
border-color: var(--border-strong);
|
|
37
|
+
background-color: var(--gray-wash-strong);
|
|
38
|
+
}
|
|
39
|
+
.select__trigger:focus-visible {
|
|
40
|
+
outline: none;
|
|
41
|
+
border-color: var(--accent);
|
|
42
|
+
background: var(--bg-surface);
|
|
43
|
+
box-shadow: var(--ring-accent);
|
|
44
|
+
}
|
|
45
|
+
.select[data-open='true'] .select__trigger {
|
|
46
|
+
border-color: var(--accent);
|
|
47
|
+
background: var(--bg-surface);
|
|
48
|
+
box-shadow: var(--ring-accent);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
.select[data-size='sm'] .select__trigger {
|
|
52
|
+
height: var(--control-height-sm);
|
|
53
|
+
padding: 0 var(--space-2);
|
|
54
|
+
font-size: var(--size-caption);
|
|
55
|
+
line-height: var(--leading-caption);
|
|
56
|
+
gap: var(--space-1);
|
|
57
|
+
}
|
|
58
|
+
.select[data-size='lg'] .select__trigger {
|
|
59
|
+
height: var(--control-height-lg);
|
|
60
|
+
padding: 0 var(--space-4);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
.select[data-invalid='true'] .select__trigger {
|
|
64
|
+
border-color: var(--danger);
|
|
65
|
+
}
|
|
66
|
+
.select[data-invalid='true'] .select__trigger:focus-visible,
|
|
67
|
+
.select[data-invalid='true'][data-open='true'] .select__trigger {
|
|
68
|
+
border-color: var(--danger);
|
|
69
|
+
box-shadow: var(--ring-danger);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
.select[data-disabled='true'] .select__trigger {
|
|
73
|
+
cursor: not-allowed;
|
|
74
|
+
background: var(--bg-muted);
|
|
75
|
+
border-color: var(--border-subtle);
|
|
76
|
+
color: var(--text-disabled);
|
|
77
|
+
box-shadow: none;
|
|
78
|
+
}
|
|
79
|
+
.select[data-disabled='true'] .select__value,
|
|
80
|
+
.select[data-disabled='true'] .select__leading,
|
|
81
|
+
.select[data-disabled='true'] .select__caret {
|
|
82
|
+
color: var(--text-disabled);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
.select[data-loading='true'] .select__value {
|
|
86
|
+
color: var(--text-muted);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
.select__leading {
|
|
90
|
+
display: inline-flex;
|
|
91
|
+
flex: 0 0 auto;
|
|
92
|
+
font-size: var(--icon-sm);
|
|
93
|
+
color: var(--text-muted);
|
|
94
|
+
}
|
|
95
|
+
.select__value {
|
|
96
|
+
flex: 1 1 auto;
|
|
97
|
+
min-width: 0;
|
|
98
|
+
color: var(--text-body);
|
|
99
|
+
}
|
|
100
|
+
.select__value[data-placeholder='true'] {
|
|
101
|
+
color: var(--text-disabled);
|
|
102
|
+
}
|
|
103
|
+
.select__caret {
|
|
104
|
+
display: inline-flex;
|
|
105
|
+
flex: 0 0 auto;
|
|
106
|
+
font-size: var(--icon-sm);
|
|
107
|
+
color: var(--text-subtle);
|
|
108
|
+
transition:
|
|
109
|
+
transform var(--duration-base) var(--ease-entrance),
|
|
110
|
+
color var(--duration-fast) var(--ease-standard);
|
|
111
|
+
}
|
|
112
|
+
.select[data-open='true'] .select__caret {
|
|
113
|
+
transform: rotate(180deg);
|
|
114
|
+
color: var(--text-muted);
|
|
115
|
+
}
|
|
116
|
+
.select__count {
|
|
117
|
+
flex: 0 0 auto;
|
|
118
|
+
font-family: var(--font-mono);
|
|
119
|
+
font-size: var(--size-micro);
|
|
120
|
+
line-height: 1;
|
|
121
|
+
font-variant-numeric: tabular-nums;
|
|
122
|
+
color: var(--text-accent);
|
|
123
|
+
background: var(--accent-wash);
|
|
124
|
+
padding: var(--space-px) var(--space-1);
|
|
125
|
+
border-radius: var(--radius-sm);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
.select__value,
|
|
129
|
+
.select__option-label,
|
|
130
|
+
.select__option-desc {
|
|
131
|
+
overflow: hidden;
|
|
132
|
+
text-overflow: ellipsis;
|
|
133
|
+
white-space: nowrap;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/* Menu enter/exit are Motion-owned inline styles (selectMenuVariants); this sheet only sets the look + transform-origin. */
|
|
137
|
+
.select__menu {
|
|
138
|
+
position: fixed;
|
|
139
|
+
margin: 0;
|
|
140
|
+
inset: auto; /* JS sets top/left/min-width - anchor() needs the top layer, which we don't use */
|
|
141
|
+
z-index: var(
|
|
142
|
+
--layer-overlay
|
|
143
|
+
); /* base of the overlay band (tokens/layers.css) - plain React-owned node, not the top layer */
|
|
144
|
+
width: max-content;
|
|
145
|
+
max-width: min(22rem, 92vw);
|
|
146
|
+
background: var(--bg-surface-raised);
|
|
147
|
+
border: var(--border-hairline) solid var(--border-default);
|
|
148
|
+
border-radius: var(--radius-lg);
|
|
149
|
+
box-shadow: var(--shadow-lg);
|
|
150
|
+
padding: var(--space-1);
|
|
151
|
+
transform-origin: top left;
|
|
152
|
+
}
|
|
153
|
+
/* flipped above the trigger (data-side from useAnchorPosition) - scale from the anchored edge */
|
|
154
|
+
.select__menu[data-side='top'] {
|
|
155
|
+
transform-origin: bottom left;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
.select__search {
|
|
159
|
+
display: flex;
|
|
160
|
+
align-items: center;
|
|
161
|
+
gap: var(--space-2);
|
|
162
|
+
padding: var(--space-2);
|
|
163
|
+
margin: 0 0 var(--space-1);
|
|
164
|
+
border-bottom: var(--border-hairline) solid var(--border-subtle);
|
|
165
|
+
font-size: var(--icon-sm);
|
|
166
|
+
color: var(--text-subtle);
|
|
167
|
+
}
|
|
168
|
+
.select__search-input {
|
|
169
|
+
appearance: none;
|
|
170
|
+
border: none;
|
|
171
|
+
outline: none;
|
|
172
|
+
background: transparent;
|
|
173
|
+
width: 100%;
|
|
174
|
+
padding: 0;
|
|
175
|
+
font-family: var(--font-sans);
|
|
176
|
+
font-size: var(--size-body);
|
|
177
|
+
line-height: var(--leading-body);
|
|
178
|
+
color: var(--text-body);
|
|
179
|
+
}
|
|
180
|
+
.select__search-input::placeholder {
|
|
181
|
+
color: var(--text-disabled);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/* Row-height motion is the Collapse primitive, not this scroll container.
|
|
185
|
+
position: relative anchors the glide pill (a single absolute child) to the scrolled content. */
|
|
186
|
+
.select__list {
|
|
187
|
+
position: relative;
|
|
188
|
+
max-height: 16.5rem;
|
|
189
|
+
overflow-y: auto;
|
|
190
|
+
overscroll-behavior: contain;
|
|
191
|
+
scroll-behavior: smooth;
|
|
192
|
+
scrollbar-width: none;
|
|
193
|
+
}
|
|
194
|
+
.select__list::-webkit-scrollbar {
|
|
195
|
+
width: 0;
|
|
196
|
+
height: 0;
|
|
197
|
+
display: none;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
.select__group-label {
|
|
201
|
+
position: sticky;
|
|
202
|
+
top: 0;
|
|
203
|
+
z-index: 1;
|
|
204
|
+
background: var(--bg-surface-raised);
|
|
205
|
+
padding: var(--space-2) var(--space-2) var(--space-1);
|
|
206
|
+
font: var(--type-micro);
|
|
207
|
+
text-transform: uppercase;
|
|
208
|
+
letter-spacing: var(--tracking-caps);
|
|
209
|
+
color: var(--text-subtle);
|
|
210
|
+
}
|
|
211
|
+
.select__group + .select__group .select__group-label {
|
|
212
|
+
border-top: var(--border-hairline) solid var(--border-subtle);
|
|
213
|
+
margin-top: var(--space-1);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
.select__option {
|
|
217
|
+
padding: var(--option-padding);
|
|
218
|
+
position: relative;
|
|
219
|
+
display: flex;
|
|
220
|
+
align-items: center;
|
|
221
|
+
gap: var(--space-2);
|
|
222
|
+
border-radius: var(--radius-md);
|
|
223
|
+
cursor: pointer;
|
|
224
|
+
color: var(--text-body);
|
|
225
|
+
user-select: none;
|
|
226
|
+
transition:
|
|
227
|
+
background-color var(--duration-base) var(--ease-standard),
|
|
228
|
+
color var(--duration-base) var(--ease-standard);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
.select__option[data-size='sm'] {
|
|
232
|
+
--option-padding: var(--space-1);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
.select__option[data-size='md'] {
|
|
236
|
+
--option-padding: var(--space-2);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
.select__option[data-size='lg'] {
|
|
240
|
+
--option-padding: var(--space-4);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
.select__option-icon {
|
|
244
|
+
display: inline-flex;
|
|
245
|
+
flex: 0 0 auto;
|
|
246
|
+
font-size: var(--icon-sm);
|
|
247
|
+
color: var(--text-muted);
|
|
248
|
+
}
|
|
249
|
+
.select__option-text {
|
|
250
|
+
display: flex;
|
|
251
|
+
flex-direction: column;
|
|
252
|
+
gap: var(--space-px);
|
|
253
|
+
min-width: 0;
|
|
254
|
+
flex: 1 1 auto;
|
|
255
|
+
}
|
|
256
|
+
.select__option-label {
|
|
257
|
+
font-size: var(--size-body);
|
|
258
|
+
line-height: var(--leading-body);
|
|
259
|
+
}
|
|
260
|
+
.select__option-desc {
|
|
261
|
+
font: var(--type-caption);
|
|
262
|
+
color: var(--text-subtle);
|
|
263
|
+
}
|
|
264
|
+
.select__option-check {
|
|
265
|
+
display: inline-flex;
|
|
266
|
+
align-items: center;
|
|
267
|
+
justify-content: center;
|
|
268
|
+
flex: 0 0 auto;
|
|
269
|
+
min-width: var(--icon-sm);
|
|
270
|
+
font-size: var(--icon-sm);
|
|
271
|
+
color: var(--accent);
|
|
272
|
+
opacity: 0;
|
|
273
|
+
transition: var(--transition-opacity);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/* Hover pill - one persistent fill in the list (../motion/glide) that travels to the active row and
|
|
277
|
+
animates its real size, so it's never clipped by the searchable rows' collapse and never scales.
|
|
278
|
+
GlidePill sets x/y/width/height inline; the option (position: relative) paints above it. */
|
|
279
|
+
.select__glide {
|
|
280
|
+
position: absolute;
|
|
281
|
+
top: 0;
|
|
282
|
+
left: 0;
|
|
283
|
+
z-index: 0;
|
|
284
|
+
border-radius: var(--radius-md);
|
|
285
|
+
background: var(--neutral-wash);
|
|
286
|
+
pointer-events: none;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/* Active row: the pill carries the fill; here we only lift the text. Selected rules follow, so source order wins. */
|
|
290
|
+
.select__option[data-active='true'] {
|
|
291
|
+
color: var(--text-strong);
|
|
292
|
+
}
|
|
293
|
+
.select__option[data-active='true'] .select__option-icon {
|
|
294
|
+
color: var(--text-body);
|
|
295
|
+
}
|
|
296
|
+
.select__option[data-selected='true'] {
|
|
297
|
+
background-color: var(--accent-wash);
|
|
298
|
+
}
|
|
299
|
+
.select__option[data-selected='true'] .select__option-label {
|
|
300
|
+
color: var(--text-accent);
|
|
301
|
+
font-weight: var(--weight-medium);
|
|
302
|
+
}
|
|
303
|
+
.select__option[data-selected='true'] .select__option-icon {
|
|
304
|
+
color: var(--text-accent);
|
|
305
|
+
}
|
|
306
|
+
.select__option[data-selected='true'] .select__option-check {
|
|
307
|
+
opacity: 1;
|
|
308
|
+
}
|
|
309
|
+
.select__option[data-disabled='true'] {
|
|
310
|
+
cursor: not-allowed;
|
|
311
|
+
color: var(--text-disabled);
|
|
312
|
+
}
|
|
313
|
+
.select__option[data-disabled='true'] .select__option-icon {
|
|
314
|
+
color: var(--text-disabled);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/* check lands with a spring when a row becomes selected (remounts via React key) */
|
|
318
|
+
.select__option[data-selected='true'] .select__option-check :is(i, svg) {
|
|
319
|
+
animation: select-check-in var(--duration-base) var(--ease-spring);
|
|
320
|
+
}
|
|
321
|
+
@keyframes select-check-in {
|
|
322
|
+
from {
|
|
323
|
+
opacity: 0;
|
|
324
|
+
transform: scale(0.5);
|
|
325
|
+
}
|
|
326
|
+
to {
|
|
327
|
+
opacity: 1;
|
|
328
|
+
transform: scale(1);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
/* Multi-select: the reused Checkbox box IS the indicator - no row fill (avoid double-encoding); strip the .cbx standalone chrome. */
|
|
333
|
+
.select__menu[data-multiple='true'] .select__option-check {
|
|
334
|
+
opacity: 1;
|
|
335
|
+
}
|
|
336
|
+
.select__menu[data-multiple='true'] .select__option .cbx {
|
|
337
|
+
padding: 0;
|
|
338
|
+
gap: 0;
|
|
339
|
+
pointer-events: none;
|
|
340
|
+
}
|
|
341
|
+
.select__menu[data-multiple='true'] .select__option .cbx__box {
|
|
342
|
+
margin-top: 0;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/* Row owns the press (.cbx is pointer-events:none): dip the box on press - explicit transform,
|
|
346
|
+
so a checked box (whose resting scale would otherwise dilute --press) still scales from center. */
|
|
347
|
+
.select__menu[data-multiple='true'] .select__option:active:not([data-disabled='true']) .cbx__box {
|
|
348
|
+
transform: scale(0.86);
|
|
349
|
+
}
|
|
350
|
+
.select__menu[data-multiple='true'] .select__option[data-selected='true'] {
|
|
351
|
+
background-color: transparent;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
.select__empty {
|
|
355
|
+
padding: var(--space-4) var(--space-3);
|
|
356
|
+
text-align: center;
|
|
357
|
+
font: var(--type-caption);
|
|
358
|
+
color: var(--text-subtle);
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
.select__loading {
|
|
362
|
+
display: flex;
|
|
363
|
+
flex-direction: column;
|
|
364
|
+
gap: var(--space-1);
|
|
365
|
+
padding: var(--space-1);
|
|
366
|
+
}
|
|
367
|
+
.select__skeleton {
|
|
368
|
+
display: flex;
|
|
369
|
+
align-items: center;
|
|
370
|
+
gap: var(--space-2);
|
|
371
|
+
padding: var(--space-2);
|
|
372
|
+
}
|
|
373
|
+
.select__skeleton-dot {
|
|
374
|
+
width: var(--icon-sm);
|
|
375
|
+
height: var(--icon-sm);
|
|
376
|
+
border-radius: var(--radius-full);
|
|
377
|
+
background: var(--bg-muted);
|
|
378
|
+
flex: 0 0 auto;
|
|
379
|
+
}
|
|
380
|
+
.select__skeleton-bar {
|
|
381
|
+
height: 0.5rem;
|
|
382
|
+
border-radius: var(--radius-full);
|
|
383
|
+
background: var(--bg-muted);
|
|
384
|
+
flex: 1 1 auto;
|
|
385
|
+
max-width: 11rem;
|
|
386
|
+
}
|
|
387
|
+
.select__skeleton:nth-child(2) .select__skeleton-bar {
|
|
388
|
+
max-width: 7rem;
|
|
389
|
+
}
|
|
390
|
+
.select__skeleton:nth-child(3) .select__skeleton-bar {
|
|
391
|
+
max-width: 9rem;
|
|
392
|
+
}
|
|
393
|
+
.select__loading [data-pulse] {
|
|
394
|
+
animation: select-pulse var(--duration-spin) var(--ease-standard) infinite alternate;
|
|
395
|
+
}
|
|
396
|
+
@keyframes select-pulse {
|
|
397
|
+
from {
|
|
398
|
+
opacity: 0.55;
|
|
399
|
+
}
|
|
400
|
+
to {
|
|
401
|
+
opacity: 1;
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
@media (prefers-reduced-motion: reduce) {
|
|
406
|
+
.select__list {
|
|
407
|
+
scroll-behavior: auto;
|
|
408
|
+
}
|
|
409
|
+
.select__option-check :is(i, svg),
|
|
410
|
+
.select__loading [data-pulse] {
|
|
411
|
+
animation: none;
|
|
412
|
+
}
|
|
413
|
+
.select__loading [data-pulse] {
|
|
414
|
+
opacity: 0.7;
|
|
415
|
+
}
|
|
416
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import './sheet.css';
|
|
4
|
+
import { Fragment, useId, useRef, type HTMLAttributes, type ReactElement, type ReactNode } from 'react';
|
|
5
|
+
import { animate, type Layer } from '../../../engine';
|
|
6
|
+
import { Presence } from '../../../motion/presence';
|
|
7
|
+
import type { MotionSpecs } from '../../../motion/use-motion';
|
|
8
|
+
import { resolveMotionTiming } from '../../../motion/motion-timing';
|
|
9
|
+
import type { DisableableAnimation } from '../../../motion/timing';
|
|
10
|
+
import { useControllable } from '../../internal/hooks/use-controllable';
|
|
11
|
+
import { ovCloneTrigger, OverlayPortal } from '../../internal/overlay/layer';
|
|
12
|
+
import { ModalShell } from '../../internal/overlay/modal';
|
|
13
|
+
import { useSheetDrag, sheetSpan } from './use-sheet-drag';
|
|
14
|
+
import type { DataAttributes } from '../../../dom-props';
|
|
15
|
+
|
|
16
|
+
const SHEET_TIMING = {
|
|
17
|
+
open: { duration: 'slow', ease: 'entrance' },
|
|
18
|
+
close: { duration: 'base', ease: 'exit' },
|
|
19
|
+
} as const;
|
|
20
|
+
|
|
21
|
+
export interface SheetProps {
|
|
22
|
+
/** Controlled open state. Omit to stay uncontrolled. */
|
|
23
|
+
open?: boolean;
|
|
24
|
+
/** Initial state when uncontrolled. Default false. */
|
|
25
|
+
defaultOpen?: boolean;
|
|
26
|
+
/** Fires whenever the open state changes. Pair with `open` for controlled use. */
|
|
27
|
+
onOpenChange?: (open: boolean) => void;
|
|
28
|
+
|
|
29
|
+
/** Cloned to open the sheet on click. */
|
|
30
|
+
trigger?: ReactElement | null;
|
|
31
|
+
|
|
32
|
+
/** Edge the sheet slides in from. Default 'right'. */
|
|
33
|
+
side?: 'right' | 'bottom';
|
|
34
|
+
|
|
35
|
+
/** Scrim/Esc dismissal + drag-to-edge. Default true. */
|
|
36
|
+
dismissible?: boolean;
|
|
37
|
+
|
|
38
|
+
/** Base id for the panel; drives the trigger's `aria-controls`. Auto-generated when omitted. */
|
|
39
|
+
id?: string;
|
|
40
|
+
/** Standard attributes (className, style, data-*, ...) forwarded to the sheet panel. */
|
|
41
|
+
htmlProps?: HTMLAttributes<HTMLDivElement> & DataAttributes;
|
|
42
|
+
/** Open/close timing - motion tokens only, or `null` to disable. @default open 'slow'/'entrance', close 'base'/'exit' */
|
|
43
|
+
animation?: DisableableAnimation;
|
|
44
|
+
/** The ENTIRE surface - paint AND semantics. Drive dismissal with `open`/`onOpenChange`. */
|
|
45
|
+
children: ReactNode;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function sheetSlide(slot: HTMLElement, side: 'right' | 'bottom', at: number[]): Layer {
|
|
49
|
+
const frames = at.map((ratio) => ratio * sheetSpan(slot, side));
|
|
50
|
+
return side === 'bottom' ? { y: frames } : { x: frames };
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function SheetShell({
|
|
54
|
+
side,
|
|
55
|
+
panelId,
|
|
56
|
+
dismissible,
|
|
57
|
+
requestClose,
|
|
58
|
+
htmlProps,
|
|
59
|
+
animate,
|
|
60
|
+
exit,
|
|
61
|
+
children,
|
|
62
|
+
}: {
|
|
63
|
+
side: 'right' | 'bottom';
|
|
64
|
+
panelId: string;
|
|
65
|
+
dismissible: boolean;
|
|
66
|
+
requestClose: () => void;
|
|
67
|
+
htmlProps?: HTMLAttributes<HTMLDivElement> & DataAttributes;
|
|
68
|
+
children: ReactNode;
|
|
69
|
+
} & MotionSpecs) {
|
|
70
|
+
const panelRef = useRef<HTMLElement>(null);
|
|
71
|
+
const dragProps = useSheetDrag({ side, panelRef, enabled: dismissible, requestClose });
|
|
72
|
+
return (
|
|
73
|
+
<ModalShell
|
|
74
|
+
animate={animate}
|
|
75
|
+
exit={exit}
|
|
76
|
+
layerClass={'overlay-layer--sheet-' + side}
|
|
77
|
+
panelClass={'overlay-panel--sheet-' + side}
|
|
78
|
+
panelId={panelId}
|
|
79
|
+
dismissible={dismissible}
|
|
80
|
+
requestClose={requestClose}
|
|
81
|
+
panelRef={panelRef}
|
|
82
|
+
panelProps={{ ...htmlProps, ...dragProps }}
|
|
83
|
+
>
|
|
84
|
+
{children}
|
|
85
|
+
</ModalShell>
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export function Sheet({
|
|
90
|
+
open: controlledOpen,
|
|
91
|
+
defaultOpen = false,
|
|
92
|
+
onOpenChange,
|
|
93
|
+
trigger = null,
|
|
94
|
+
side = 'right',
|
|
95
|
+
dismissible = true,
|
|
96
|
+
id,
|
|
97
|
+
htmlProps,
|
|
98
|
+
animation,
|
|
99
|
+
children,
|
|
100
|
+
}: SheetProps) {
|
|
101
|
+
const [open, setOpen] = useControllable(controlledOpen, defaultOpen, onOpenChange);
|
|
102
|
+
const triggerRef = useRef<HTMLElement>(null);
|
|
103
|
+
const autoId = useId();
|
|
104
|
+
const panelId = id || 'sheet-' + autoId;
|
|
105
|
+
const close = () => setOpen(false);
|
|
106
|
+
const timings = resolveMotionTiming(animation, SHEET_TIMING);
|
|
107
|
+
|
|
108
|
+
return (
|
|
109
|
+
<Fragment>
|
|
110
|
+
{ovCloneTrigger(trigger, { open, onPress: () => setOpen(true), panelId, haspopup: 'dialog', triggerRef })}
|
|
111
|
+
<OverlayPortal>
|
|
112
|
+
<Presence>
|
|
113
|
+
{open && (
|
|
114
|
+
<SheetShell
|
|
115
|
+
key="sheet"
|
|
116
|
+
animate={(slot) => {
|
|
117
|
+
const play = animate(slot, { ...sheetSlide(slot, side, [1, 0]), timing: timings.open });
|
|
118
|
+
play.finished.then(() => play.stop());
|
|
119
|
+
return play;
|
|
120
|
+
}}
|
|
121
|
+
exit={(slot) => animate(slot, { ...sheetSlide(slot, side, [1]), timing: timings.close })}
|
|
122
|
+
side={side}
|
|
123
|
+
panelId={panelId}
|
|
124
|
+
dismissible={dismissible}
|
|
125
|
+
requestClose={close}
|
|
126
|
+
htmlProps={htmlProps}
|
|
127
|
+
>
|
|
128
|
+
{children}
|
|
129
|
+
</SheetShell>
|
|
130
|
+
)}
|
|
131
|
+
</Presence>
|
|
132
|
+
</OverlayPortal>
|
|
133
|
+
</Fragment>
|
|
134
|
+
);
|
|
135
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/* sheet.css - edge-docked placement on the modal shell: sheets dock flush (no layer padding); the panel spans the docked edge. */
|
|
2
|
+
.overlay-layer--sheet-right {
|
|
3
|
+
align-items: stretch;
|
|
4
|
+
justify-items: end;
|
|
5
|
+
}
|
|
6
|
+
.overlay-panel--sheet-right {
|
|
7
|
+
height: 100%;
|
|
8
|
+
max-width: 100%;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.overlay-layer--sheet-bottom {
|
|
12
|
+
align-items: end;
|
|
13
|
+
justify-items: stretch;
|
|
14
|
+
}
|
|
15
|
+
.overlay-panel--sheet-bottom {
|
|
16
|
+
width: 100%;
|
|
17
|
+
max-height: 100%;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/* Drag stretch scales the panel away from the edge it is docked to. */
|
|
21
|
+
.overlay-panel--sheet-right {
|
|
22
|
+
transform-origin: 100% 50%;
|
|
23
|
+
}
|
|
24
|
+
.overlay-panel--sheet-bottom {
|
|
25
|
+
transform-origin: 50% 100%;
|
|
26
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useEffect, useRef, type PointerEvent as ReactPointerEvent, type RefObject } from 'react';
|
|
4
|
+
import { animate, startDrag, type PanInfo } from '../../../engine';
|
|
5
|
+
import { UIMotion } from '../../../tokens/motion-tokens';
|
|
6
|
+
|
|
7
|
+
const SM = UIMotion;
|
|
8
|
+
|
|
9
|
+
const DISMISS_RATIO = 0.4;
|
|
10
|
+
const DISMISS_VELOCITY = 500;
|
|
11
|
+
const INTENT_PX = 4;
|
|
12
|
+
const STRETCH_MAX = 0.06;
|
|
13
|
+
|
|
14
|
+
function findScrollable(node: EventTarget | null, stop: HTMLElement | null): HTMLElement | null {
|
|
15
|
+
let el = node instanceof Element ? node : null;
|
|
16
|
+
while (el && el !== stop) {
|
|
17
|
+
const s = getComputedStyle(el);
|
|
18
|
+
if (
|
|
19
|
+
/(auto|scroll)/.test(s.overflowY + s.overflowX) &&
|
|
20
|
+
(el.scrollHeight > el.clientHeight || el.scrollWidth > el.clientWidth)
|
|
21
|
+
)
|
|
22
|
+
return el as HTMLElement;
|
|
23
|
+
el = el.parentElement;
|
|
24
|
+
}
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function sheetScrim(panel: HTMLElement | null): HTMLElement | null {
|
|
29
|
+
return panel?.parentElement?.querySelector<HTMLElement>('.overlay-scrim') ?? null;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function sheetSpan(panel: HTMLElement, side: 'right' | 'bottom'): number {
|
|
33
|
+
return side === 'bottom' ? panel.offsetHeight : panel.offsetWidth;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function useSheetDrag({
|
|
37
|
+
side,
|
|
38
|
+
panelRef,
|
|
39
|
+
enabled,
|
|
40
|
+
requestClose,
|
|
41
|
+
}: {
|
|
42
|
+
side: 'right' | 'bottom';
|
|
43
|
+
panelRef: RefObject<HTMLElement>;
|
|
44
|
+
enabled: boolean;
|
|
45
|
+
requestClose: () => void;
|
|
46
|
+
}) {
|
|
47
|
+
const axis = side === 'bottom' ? 'y' : 'x';
|
|
48
|
+
const savedUserSelect = useRef<string | null>(null);
|
|
49
|
+
|
|
50
|
+
function suspendSelection() {
|
|
51
|
+
const sel = window.getSelection();
|
|
52
|
+
if (sel) sel.removeAllRanges();
|
|
53
|
+
savedUserSelect.current = document.body.style.userSelect;
|
|
54
|
+
document.body.style.userSelect = 'none';
|
|
55
|
+
}
|
|
56
|
+
function restoreSelection() {
|
|
57
|
+
if (savedUserSelect.current === null) return;
|
|
58
|
+
document.body.style.userSelect = savedUserSelect.current;
|
|
59
|
+
savedUserSelect.current = null;
|
|
60
|
+
}
|
|
61
|
+
useEffect(() => restoreSelection, []); // eslint-disable-line react-hooks/exhaustive-deps
|
|
62
|
+
|
|
63
|
+
function paint(el: HTMLElement, travel: number, stretch: number) {
|
|
64
|
+
const span = sheetSpan(el, side);
|
|
65
|
+
el.style.translate = axis === 'y' ? `0px ${travel}px` : `${travel}px 0px`;
|
|
66
|
+
el.style.scale = axis === 'y' ? `1 ${stretch}` : `${stretch} 1`;
|
|
67
|
+
const scrim = sheetScrim(el);
|
|
68
|
+
if (scrim) scrim.style.opacity = String(1 - Math.min(Math.max(travel / span, 0), 1));
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function onPointerDown(e: ReactPointerEvent) {
|
|
72
|
+
if (e.button !== 0) return;
|
|
73
|
+
const startX = e.clientX,
|
|
74
|
+
startY = e.clientY;
|
|
75
|
+
const scrollable = findScrollable(e.target, panelRef.current);
|
|
76
|
+
|
|
77
|
+
const onMove = (ev: PointerEvent) => {
|
|
78
|
+
const dx = ev.clientX - startX,
|
|
79
|
+
dy = ev.clientY - startY;
|
|
80
|
+
if (Math.max(Math.abs(dx), Math.abs(dy)) < INTENT_PX) return;
|
|
81
|
+
cleanup();
|
|
82
|
+
const along = axis === 'y' ? dy : dx;
|
|
83
|
+
const cross = axis === 'y' ? dx : dy;
|
|
84
|
+
if (Math.abs(along) <= Math.abs(cross)) return;
|
|
85
|
+
if (scrollable) {
|
|
86
|
+
if (along < 0) return;
|
|
87
|
+
if (axis === 'y' ? scrollable.scrollTop > 0 : scrollable.scrollLeft > 0) return;
|
|
88
|
+
}
|
|
89
|
+
suspendSelection();
|
|
90
|
+
startDrag(ev, { onMove: onDrag, onEnd: onDragEnd });
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const cleanup = () => {
|
|
94
|
+
window.removeEventListener('pointermove', onMove);
|
|
95
|
+
window.removeEventListener('pointerup', cleanup);
|
|
96
|
+
window.removeEventListener('pointercancel', cleanup);
|
|
97
|
+
};
|
|
98
|
+
window.addEventListener('pointermove', onMove);
|
|
99
|
+
window.addEventListener('pointerup', cleanup);
|
|
100
|
+
window.addEventListener('pointercancel', cleanup);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function onDrag(info: PanInfo) {
|
|
104
|
+
const el = panelRef.current;
|
|
105
|
+
if (!el) return;
|
|
106
|
+
const o = info.offset[axis];
|
|
107
|
+
const span = sheetSpan(el, side);
|
|
108
|
+
paint(el, Math.max(o, 0), o < 0 ? 1 + Math.min(-o / span, 1) * STRETCH_MAX : 1);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function onDragEnd(info: PanInfo) {
|
|
112
|
+
restoreSelection();
|
|
113
|
+
const el = panelRef.current;
|
|
114
|
+
if (!el) return;
|
|
115
|
+
const span = sheetSpan(el, side);
|
|
116
|
+
if (info.offset[axis] > span * DISMISS_RATIO || info.velocity[axis] > DISMISS_VELOCITY) {
|
|
117
|
+
requestClose();
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
animate(el, { x: [0], y: [0], scale: [[1, 1]], timing: SM.t.settle });
|
|
121
|
+
const scrim = sheetScrim(el);
|
|
122
|
+
if (scrim) animate(scrim, { opacity: [1], timing: SM.t.settle });
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return enabled ? { onPointerDown } : {};
|
|
126
|
+
}
|