@zyncat/ui 0.21.0 → 0.22.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/alert.js +10 -9
- package/dist/alert.js.map +1 -1
- package/dist/avatar.css +1 -1
- package/dist/badge.css +1 -1
- package/dist/badge.js +5 -100
- package/dist/badge.js.map +1 -1
- package/dist/button.css +24 -27
- package/dist/button.js +3 -3
- package/dist/checkbox.css +0 -1
- package/dist/chunk-2EPNCOLN.js +177 -0
- package/dist/chunk-2EPNCOLN.js.map +1 -0
- package/dist/{chunk-3HE7N3UK.js → chunk-2GYZ3HP3.js} +3 -3
- package/dist/chunk-2GYZ3HP3.js.map +1 -0
- package/dist/{chunk-ODRO3KS6.js → chunk-7GTACTZD.js} +8 -6
- package/dist/chunk-7GTACTZD.js.map +1 -0
- package/dist/{chunk-BWGK3OD6.js → chunk-AK2AXGEC.js} +33 -6
- package/dist/chunk-AK2AXGEC.js.map +1 -0
- package/dist/{chunk-5VC3TUZ2.js → chunk-BA4ALXQW.js} +2 -2
- package/dist/{chunk-5VC3TUZ2.js.map → chunk-BA4ALXQW.js.map} +1 -1
- package/dist/{chunk-AXZBD7LY.js → chunk-CF6ZFXRV.js} +16 -11
- package/dist/chunk-CF6ZFXRV.js.map +1 -0
- package/dist/{chunk-AQMR7ZYO.js → chunk-DOAR4PJ3.js} +4 -4
- package/dist/{chunk-AQMR7ZYO.js.map → chunk-DOAR4PJ3.js.map} +1 -1
- package/dist/chunk-EUAXI6OF.js +16 -0
- package/dist/chunk-EUAXI6OF.js.map +1 -0
- package/dist/{chunk-AOEO2LCZ.js → chunk-G2TOUG2A.js} +6 -5
- package/dist/chunk-G2TOUG2A.js.map +1 -0
- package/dist/{chunk-CYZKPUCG.js → chunk-HRP4UFWN.js} +3 -3
- package/dist/chunk-HRP4UFWN.js.map +1 -0
- package/dist/chunk-INK2GJTA.js +102 -0
- package/dist/chunk-INK2GJTA.js.map +1 -0
- package/dist/{chunk-GM7IPTTT.js → chunk-JJHEVW4M.js} +5 -5
- package/dist/{chunk-GM7IPTTT.js.map → chunk-JJHEVW4M.js.map} +1 -1
- package/dist/{chunk-7NHY2CRA.js → chunk-JUC35N3C.js} +2 -2
- package/dist/chunk-JUC35N3C.js.map +1 -0
- package/dist/{chunk-LC6NQQER.js → chunk-LFJ4C7ZP.js} +7 -7
- package/dist/chunk-LFJ4C7ZP.js.map +1 -0
- package/dist/{chunk-JQZ3FTHP.js → chunk-MCOIR3CK.js} +3 -3
- package/dist/{chunk-JQZ3FTHP.js.map → chunk-MCOIR3CK.js.map} +1 -1
- package/dist/{chunk-TXJQUN7C.js → chunk-NATK4DDW.js} +15 -15
- package/dist/{chunk-TXJQUN7C.js.map → chunk-NATK4DDW.js.map} +1 -1
- package/dist/{chunk-BIDVNLJO.js → chunk-O3RMSMBP.js} +8 -3
- package/dist/{chunk-BIDVNLJO.js.map → chunk-O3RMSMBP.js.map} +1 -1
- package/dist/{chunk-47OMFFIB.js → chunk-ODO2TCTS.js} +27 -13
- package/dist/chunk-ODO2TCTS.js.map +1 -0
- package/dist/{chunk-LV442ZOR.js → chunk-P3QSWNED.js} +11 -11
- package/dist/{chunk-LV442ZOR.js.map → chunk-P3QSWNED.js.map} +1 -1
- package/dist/{chunk-QDAN43B6.js → chunk-Q4K337QY.js} +6 -6
- package/dist/chunk-Q4K337QY.js.map +1 -0
- package/dist/{chunk-ZSP4ZTII.js → chunk-RLRZJAF7.js} +20 -8
- package/dist/chunk-RLRZJAF7.js.map +1 -0
- package/dist/{chunk-V4ZN5RD4.js → chunk-SY5UA6WS.js} +29 -9
- package/dist/chunk-SY5UA6WS.js.map +1 -0
- package/dist/{chunk-SPFHWHJ6.js → chunk-TFC5SCAB.js} +32 -13
- package/dist/chunk-TFC5SCAB.js.map +1 -0
- package/dist/{chunk-HBWRKEW4.js → chunk-VBALIMST.js} +3 -3
- package/dist/{chunk-HBWRKEW4.js.map → chunk-VBALIMST.js.map} +1 -1
- package/dist/{chunk-2W7FOMWE.js → chunk-VXQ7A6ZI.js} +8 -8
- package/dist/{chunk-2W7FOMWE.js.map → chunk-VXQ7A6ZI.js.map} +1 -1
- package/dist/{chunk-TBLPZQSI.js → chunk-W7CHDHRV.js} +114 -42
- package/dist/chunk-W7CHDHRV.js.map +1 -0
- package/dist/{chunk-DEZIQTBW.js → chunk-WBWVOOKM.js} +58 -53
- package/dist/chunk-WBWVOOKM.js.map +1 -0
- package/dist/{chunk-6H3IJ752.js → chunk-WJEZWKEY.js} +20 -10
- package/dist/chunk-WJEZWKEY.js.map +1 -0
- package/dist/{chunk-TBIY5YR5.js → chunk-WMTOAYGP.js} +9 -9
- package/dist/{chunk-TBIY5YR5.js.map → chunk-WMTOAYGP.js.map} +1 -1
- package/dist/{chunk-C3D32LE3.js → chunk-WTHIUPVJ.js} +3 -3
- package/dist/{chunk-C3D32LE3.js.map → chunk-WTHIUPVJ.js.map} +1 -1
- package/dist/{chunk-PNFFK5HY.js → chunk-XCTMTOGT.js} +5 -5
- package/dist/{chunk-PNFFK5HY.js.map → chunk-XCTMTOGT.js.map} +1 -1
- package/dist/chunk-XMJ343KF.js +18 -0
- package/dist/chunk-XMJ343KF.js.map +1 -0
- package/dist/collapse.js +1 -1
- package/dist/combobox.css +7 -0
- package/dist/combobox.js +183 -0
- package/dist/combobox.js.map +1 -0
- package/dist/confetti.js +2 -2
- package/dist/{crossfade-XFZLFLT7.js → crossfade-UHUQBUVG.js} +53 -11
- package/dist/crossfade-UHUQBUVG.js.map +1 -0
- package/dist/date-field.js +23 -20
- package/dist/date-field.js.map +1 -1
- package/dist/date-picker.css +25 -40
- package/dist/date-range-field.js +458 -276
- package/dist/date-range-field.js.map +1 -1
- package/dist/datetime-field.js +24 -21
- package/dist/datetime-field.js.map +1 -1
- package/dist/dialog-sheet.css +31 -0
- package/dist/dialog.css +3 -0
- package/dist/dialog.js +42 -40
- package/dist/dialog.js.map +1 -1
- package/dist/dropdown.css +2 -2
- package/dist/dropdown.js +56 -31
- package/dist/dropdown.js.map +1 -1
- package/dist/emoji-picker.js +20 -19
- package/dist/emoji-picker.js.map +1 -1
- package/dist/flow-field.js +2 -2
- package/dist/glide.js +3 -3
- package/dist/input.css +54 -34
- package/dist/instagram-feed.js +3 -3
- package/dist/lens.js +184 -160
- package/dist/lens.js.map +1 -1
- package/dist/mcp.js +29 -22
- package/dist/modal.js +10 -9
- package/dist/modal.js.map +1 -1
- package/dist/morphing-text.js +2 -2
- package/dist/motion-devtools.css +6 -5
- package/dist/motion-devtools.js +6 -6
- package/dist/motion-tokens.js +1 -1
- package/dist/motion.js +6 -5
- package/dist/multi-select.js +41 -20
- package/dist/multi-select.js.map +1 -1
- package/dist/number-field.js +121 -74
- package/dist/number-field.js.map +1 -1
- package/dist/odometer.css +12 -7
- package/dist/odometer.js +158 -39
- package/dist/odometer.js.map +1 -1
- package/dist/otp-field.js +32 -3
- package/dist/otp-field.js.map +1 -1
- package/dist/overlay.css +1 -0
- package/dist/pagination.css +1 -1
- package/dist/pagination.js +6 -6
- package/dist/popover.js +11 -10
- package/dist/radio-group.css +1 -2
- package/dist/radio-group.js +9 -8
- package/dist/radio-group.js.map +1 -1
- package/dist/range-sheet-days.css +35 -0
- package/dist/range-sheet.css +80 -0
- package/dist/range-summary.css +67 -0
- package/dist/scroll-area.css +150 -0
- package/dist/scroll-area.js +85 -0
- package/dist/scroll-area.js.map +1 -0
- package/dist/select.css +22 -1
- package/dist/select.js +15 -14
- package/dist/select.js.map +1 -1
- package/dist/sheet.js +11 -10
- package/dist/support-rail.css +2 -2
- package/dist/support-rail.js +15 -13
- package/dist/support-rail.js.map +1 -1
- package/dist/table-detail.css +27 -0
- package/dist/table.css +35 -13
- package/dist/table.js +341 -172
- package/dist/table.js.map +1 -1
- package/dist/tabs.css +16 -11
- package/dist/tabs.js +68 -56
- package/dist/tabs.js.map +1 -1
- package/dist/tag.css +2 -4
- package/dist/tag.js +8 -7
- package/dist/tag.js.map +1 -1
- package/dist/text-field.js +4 -4
- package/dist/textarea.css +15 -42
- package/dist/textarea.js +24 -26
- package/dist/textarea.js.map +1 -1
- package/dist/theme-grid.js +8 -7
- package/dist/theme-switcher.js +17 -16
- package/dist/theme-switcher.js.map +1 -1
- package/dist/{theme-transition-FDF2REFD.js → theme-transition-F3CBENM5.js} +5 -5
- package/dist/{theme-transition-FDF2REFD.js.map → theme-transition-F3CBENM5.js.map} +1 -1
- package/dist/theme.js +5 -4
- package/dist/theme.js.map +1 -1
- package/dist/tiktok.js +3 -3
- package/dist/time-field.js +13 -8
- package/dist/time-field.js.map +1 -1
- package/dist/toast.css +1 -1
- package/dist/toast.js +11 -10
- package/dist/toast.js.map +1 -1
- package/dist/toggle-tag.js.map +1 -1
- package/dist/toggle.css +0 -1
- package/dist/tooltip.css +1 -1
- package/dist/tooltip.js +21 -15
- package/dist/tooltip.js.map +1 -1
- package/dist/types/components/composites/combobox/Combobox.d.ts +51 -0
- package/dist/types/components/composites/combobox/caret.d.ts +8 -0
- package/dist/types/components/composites/combobox/use-combobox.d.ts +52 -0
- package/dist/types/components/composites/date-picker/DateField.d.ts +1 -1
- package/dist/types/components/composites/date-picker/DateRangeField.d.ts +6 -3
- package/dist/types/components/composites/date-picker/DateTimeField.d.ts +1 -1
- package/dist/types/components/composites/date-picker/TimeField.d.ts +1 -1
- package/dist/types/components/composites/date-picker/date-utils.d.ts +2 -0
- package/dist/types/components/composites/date-picker/field-shell.d.ts +4 -1
- package/dist/types/components/composites/date-picker/month-swipe.d.ts +3 -0
- package/dist/types/components/composites/date-picker/range-day.d.ts +11 -0
- package/dist/types/components/composites/date-picker/range-month.d.ts +14 -0
- package/dist/types/components/composites/date-picker/range-panel.d.ts +4 -18
- package/dist/types/components/composites/date-picker/range-presets.d.ts +24 -0
- package/dist/types/components/composites/date-picker/range-sheet.d.ts +12 -0
- package/dist/types/components/composites/date-picker/range-summary.d.ts +9 -0
- package/dist/types/components/composites/date-picker/typed-key.d.ts +3 -0
- package/dist/types/components/composites/date-picker/use-month-view.d.ts +14 -0
- package/dist/types/components/composites/date-picker/use-range-panel.d.ts +44 -0
- package/dist/types/components/composites/dialog/Dialog.d.ts +3 -2
- package/dist/types/components/composites/dialog/surface.d.ts +17 -0
- package/dist/types/components/composites/dropdown/Dropdown.d.ts +9 -3
- package/dist/types/components/composites/dropdown/types.d.ts +4 -1
- package/dist/types/components/composites/scroll-area/ScrollArea.d.ts +29 -0
- package/dist/types/components/composites/select/MultiSelect.d.ts +9 -3
- package/dist/types/components/composites/select/core/menu.d.ts +3 -1
- package/dist/types/components/composites/select/core/panel.d.ts +4 -3
- package/dist/types/components/composites/select/core/use-listbox.d.ts +5 -5
- package/dist/types/components/composites/select/presets.d.ts +17 -0
- package/dist/types/components/composites/table/Table.d.ts +3 -74
- package/dist/types/components/composites/table/body.d.ts +15 -0
- package/dist/types/components/composites/table/detail.d.ts +24 -0
- package/dist/types/components/composites/table/head.d.ts +16 -0
- package/dist/types/components/composites/table/types.d.ts +86 -0
- package/dist/types/components/composites/table/use-scroller.d.ts +12 -0
- package/dist/types/components/composites/table/use-table-state.d.ts +16 -0
- package/dist/types/components/composites/tabs/Tabs.d.ts +3 -71
- package/dist/types/components/composites/tabs/tab-panel.d.ts +26 -0
- package/dist/types/components/composites/tabs/types.d.ts +48 -0
- package/dist/types/components/composites/tabs/use-ink.d.ts +5 -0
- package/dist/types/components/composites/tooltip/Tooltip.d.ts +1 -1
- package/dist/types/components/compound/support-rail/SupportRail.d.ts +1 -1
- package/dist/types/components/expressive/lens/Lens.d.ts +1 -1
- package/dist/types/components/expressive/lens/input.d.ts +2 -0
- package/dist/types/components/expressive/lens/optics.d.ts +37 -0
- package/dist/types/components/expressive/lens/paint.d.ts +2 -0
- package/dist/types/components/expressive/lens/use-lens.d.ts +10 -0
- package/dist/types/components/expressive/odometer/roll.d.ts +9 -11
- package/dist/types/components/expressive/odometer/spring.d.ts +11 -0
- package/dist/types/components/internal/hooks/use-hold-repeat.d.ts +8 -0
- package/dist/types/components/internal/icon/Icon.d.ts +2 -0
- package/dist/types/components/internal/support/types.d.ts +1 -1
- package/dist/types/components/primitives/button/Button.d.ts +4 -8
- package/dist/types/components/primitives/button/button-style.d.ts +8 -4
- package/dist/types/components/primitives/collapse/Collapse.d.ts +3 -2
- package/dist/types/components/primitives/input/NumberField.d.ts +1 -1
- package/dist/types/components/primitives/input/OtpField.d.ts +5 -1
- package/dist/types/components/primitives/input/TextField.d.ts +1 -1
- package/dist/types/components/primitives/input/field-chrome.d.ts +2 -1
- package/dist/types/components/primitives/input/use-number-value.d.ts +16 -0
- package/dist/types/components/primitives/tag/Tag.d.ts +1 -1
- package/dist/types/components/primitives/tag/ToggleTag.d.ts +2 -2
- package/dist/types/components/primitives/textarea/Textarea.d.ts +3 -1
- package/dist/types/engine/flip.d.ts +3 -1
- package/dist/types/engine/index.d.ts +2 -2
- package/dist/types/engine/loop.d.ts +5 -2
- package/dist/types/motion/before-paint.d.ts +4 -0
- package/dist/types/motion/crossfade.d.ts +2 -1
- package/dist/types/motion/element.d.ts +14 -5
- package/dist/types/motion/flip.d.ts +6 -3
- package/dist/types/motion/holders.d.ts +4 -0
- package/dist/types/motion/use-motion.d.ts +3 -1
- package/dist/types/tokens/motion-defaults.generated.d.ts +2 -0
- package/dist/types/tokens/motion-scale.d.ts +18 -15
- package/dist/types/tokens/motion-tokens.d.ts +1 -1
- package/dist/types/tokens/theme-store.d.ts +4 -4
- package/dist/types/tokens/theme-tokens.generated.d.ts +43 -31
- package/dist/types/tokens/theme.d.ts +1 -1
- package/dist/typing-lines.js +2 -2
- package/dist/youtube.js +3 -3
- package/package.json +11 -1
- package/skills/zyncat-ui/SKILL.md +6 -6
- package/skills/zyncat-ui/references/components.md +4 -2
- package/skills/zyncat-ui/references/recipes.md +1 -1
- package/src/components/composites/combobox/Combobox.tsx +100 -0
- package/src/components/composites/combobox/Combobox.usage.md +32 -0
- package/src/components/composites/combobox/caret.ts +41 -0
- package/src/components/composites/combobox/combobox.css +7 -0
- package/src/components/composites/combobox/use-combobox.ts +112 -0
- package/src/components/composites/date-picker/DateField.tsx +2 -0
- package/src/components/composites/date-picker/DateRangeField.tsx +13 -18
- package/src/components/composites/date-picker/DateTimeField.tsx +2 -0
- package/src/components/composites/date-picker/TimeField.tsx +10 -4
- package/src/components/composites/date-picker/date-picker.css +25 -40
- package/src/components/composites/date-picker/date-utils.ts +4 -0
- package/src/components/composites/date-picker/field-shell.tsx +31 -7
- package/src/components/composites/date-picker/month-swipe.ts +41 -0
- package/src/components/composites/date-picker/range-day.tsx +112 -0
- package/src/components/composites/date-picker/range-month.tsx +79 -0
- package/src/components/composites/date-picker/range-panel.tsx +30 -356
- package/src/components/composites/date-picker/range-presets.tsx +104 -0
- package/src/components/composites/date-picker/range-sheet-days.css +35 -0
- package/src/components/composites/date-picker/range-sheet.css +80 -0
- package/src/components/composites/date-picker/range-sheet.tsx +72 -0
- package/src/components/composites/date-picker/range-summary.css +67 -0
- package/src/components/composites/date-picker/range-summary.tsx +69 -0
- package/src/components/composites/date-picker/time-core.tsx +23 -17
- package/src/components/composites/date-picker/typed-key.ts +9 -0
- package/src/components/composites/date-picker/use-month-view.ts +32 -0
- package/src/components/composites/date-picker/use-range-panel.ts +145 -0
- package/src/components/composites/dialog/Dialog.tsx +28 -110
- package/src/components/composites/dialog/dialog-sheet.css +31 -0
- package/src/components/composites/dialog/dialog.css +3 -0
- package/src/components/composites/dialog/surface.tsx +93 -0
- package/src/components/composites/dropdown/Dropdown.tsx +31 -6
- package/src/components/composites/dropdown/dropdown.css +2 -2
- package/src/components/composites/dropdown/menu-panel.tsx +22 -14
- package/src/components/composites/dropdown/types.ts +4 -1
- package/src/components/composites/pagination/pagination.css +1 -1
- package/src/components/composites/scroll-area/ScrollArea.tsx +114 -0
- package/src/components/composites/scroll-area/ScrollArea.usage.md +28 -0
- package/src/components/composites/scroll-area/scroll-area.css +150 -0
- package/src/components/composites/select/MultiSelect.tsx +15 -7
- package/src/components/composites/select/core/menu.tsx +6 -2
- package/src/components/composites/select/core/panel.tsx +9 -7
- package/src/components/composites/select/core/trigger.tsx +1 -3
- package/src/components/composites/select/core/use-listbox.ts +35 -28
- package/src/components/composites/select/presets.tsx +47 -0
- package/src/components/composites/select/select.css +22 -1
- package/src/components/composites/sheet/use-sheet-drag.ts +13 -0
- package/src/components/composites/table/Table.tsx +65 -305
- package/src/components/composites/table/Table.usage.md +19 -2
- package/src/components/composites/table/body.tsx +147 -0
- package/src/components/composites/table/detail.tsx +76 -0
- package/src/components/composites/table/head.tsx +90 -0
- package/src/components/composites/table/table-detail.css +27 -0
- package/src/components/composites/table/table.css +35 -13
- package/src/components/composites/table/types.ts +97 -0
- package/src/components/composites/table/use-scroller.ts +53 -0
- package/src/components/composites/table/use-table-state.ts +98 -0
- package/src/components/composites/tabs/Tabs.tsx +21 -191
- package/src/components/composites/tabs/tab-panel.tsx +63 -0
- package/src/components/composites/tabs/tabs.css +16 -11
- package/src/components/composites/tabs/types.ts +51 -0
- package/src/components/composites/tabs/use-ink.ts +87 -0
- package/src/components/composites/toast/toast.css +1 -1
- package/src/components/composites/tooltip/Tooltip.tsx +6 -5
- package/src/components/composites/tooltip/tooltip-host.tsx +9 -5
- package/src/components/composites/tooltip/tooltip.css +1 -1
- package/src/components/compound/support-rail/SupportRail.tsx +3 -2
- package/src/components/compound/support-rail/support-rail.css +2 -2
- package/src/components/dev/motion-devtools.css +6 -5
- package/src/components/expressive/lens/Lens.tsx +11 -368
- package/src/components/expressive/lens/input.ts +91 -0
- package/src/components/expressive/lens/optics.ts +119 -0
- package/src/components/expressive/lens/paint.ts +60 -0
- package/src/components/expressive/lens/use-lens.ts +121 -0
- package/src/components/expressive/odometer/Odometer.tsx +38 -12
- package/src/components/expressive/odometer/odometer.css +12 -7
- package/src/components/expressive/odometer/roll.ts +85 -40
- package/src/components/expressive/odometer/spring.ts +86 -0
- package/src/components/internal/hooks/use-hold-repeat.ts +43 -0
- package/src/components/internal/hooks/use-scroll-edges.ts +6 -1
- package/src/components/internal/icon/Icon.tsx +4 -0
- package/src/components/internal/overlay/overlay.css +1 -0
- package/src/components/internal/overlay/track-anchor.ts +1 -1
- package/src/components/internal/support/types.ts +1 -1
- package/src/components/internal/utils/activation.ts +2 -2
- package/src/components/primitives/avatar/avatar.css +1 -1
- package/src/components/primitives/badge/badge.css +1 -1
- package/src/components/primitives/button/Button.tsx +5 -8
- package/src/components/primitives/button/Button.usage.md +5 -4
- package/src/components/primitives/button/button-style.ts +11 -5
- package/src/components/primitives/button/button.css +24 -27
- package/src/components/primitives/checkbox/checkbox.css +0 -1
- package/src/components/primitives/collapse/Collapse.tsx +3 -2
- package/src/components/primitives/input/NumberField.tsx +38 -46
- package/src/components/primitives/input/OtpField.tsx +35 -2
- package/src/components/primitives/input/OtpField.usage.md +2 -1
- package/src/components/primitives/input/TextField.tsx +5 -3
- package/src/components/primitives/input/field-chrome.tsx +3 -2
- package/src/components/primitives/input/input.css +54 -34
- package/src/components/primitives/input/use-number-value.ts +38 -0
- package/src/components/primitives/radio-group/radio-group.css +1 -2
- package/src/components/primitives/tag/Tag.tsx +1 -1
- package/src/components/primitives/tag/ToggleTag.tsx +2 -2
- package/src/components/primitives/tag/tag.css +2 -4
- package/src/components/primitives/textarea/Textarea.tsx +24 -6
- package/src/components/primitives/textarea/char-meter.tsx +1 -16
- package/src/components/primitives/textarea/textarea.css +15 -42
- package/src/components/primitives/toggle/toggle.css +0 -1
- package/src/engine/animate.ts +5 -3
- package/src/engine/flip.ts +23 -3
- package/src/engine/index.ts +2 -2
- package/src/engine/loop.ts +17 -6
- package/src/mcp/server.ts +30 -20
- package/src/motion/before-paint.ts +15 -0
- package/src/motion/crossfade.ts +54 -8
- package/src/motion/element.tsx +22 -4
- package/src/motion/flip.ts +69 -37
- package/src/motion/holders.ts +10 -0
- package/src/motion/presence.tsx +18 -9
- package/src/motion/use-motion.ts +38 -4
- package/src/tokens/base.css +0 -5
- package/src/tokens/dark.css +5 -5
- package/src/tokens/motion-defaults.generated.ts +15 -8
- package/src/tokens/motion-scale.ts +18 -15
- package/src/tokens/motion-tokens.ts +4 -4
- package/src/tokens/motion.css +19 -11
- package/src/tokens/reset.css +1 -0
- package/src/tokens/semantic.css +8 -8
- package/src/tokens/spacing.css +5 -3
- package/src/tokens/theme-store.ts +4 -4
- package/src/tokens/theme-sync.tsx +4 -2
- package/src/tokens/theme-tokens.generated.ts +44 -31
- package/src/tokens/theme.tsx +1 -1
- package/tailwind.css +4 -0
- package/dist/chunk-3HE7N3UK.js.map +0 -1
- package/dist/chunk-47OMFFIB.js.map +0 -1
- package/dist/chunk-6BY5G7BI.js +0 -122
- package/dist/chunk-6BY5G7BI.js.map +0 -1
- package/dist/chunk-6H3IJ752.js.map +0 -1
- package/dist/chunk-7NHY2CRA.js.map +0 -1
- package/dist/chunk-AOEO2LCZ.js.map +0 -1
- package/dist/chunk-AXZBD7LY.js.map +0 -1
- package/dist/chunk-BWGK3OD6.js.map +0 -1
- package/dist/chunk-CYZKPUCG.js.map +0 -1
- package/dist/chunk-DEZIQTBW.js.map +0 -1
- package/dist/chunk-KSAJ6DED.js +0 -16
- package/dist/chunk-KSAJ6DED.js.map +0 -1
- package/dist/chunk-LC6NQQER.js.map +0 -1
- package/dist/chunk-ODRO3KS6.js.map +0 -1
- package/dist/chunk-QDAN43B6.js.map +0 -1
- package/dist/chunk-SPFHWHJ6.js.map +0 -1
- package/dist/chunk-TBLPZQSI.js.map +0 -1
- package/dist/chunk-V4ZN5RD4.js.map +0 -1
- package/dist/chunk-ZSP4ZTII.js.map +0 -1
- package/dist/crossfade-XFZLFLT7.js.map +0 -1
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import type { ReactNode } from 'react';
|
|
4
|
+
|
|
5
|
+
import { Icon } from '../../internal/icon/Icon';
|
|
6
|
+
import { activationProps, type ActivateOn } from '../../internal/utils/activation';
|
|
7
|
+
import type { TableColumn, TableSort } from './types';
|
|
8
|
+
|
|
9
|
+
export function cellMods(col: TableColumn, i: number, pinFirst: boolean, selectable: boolean) {
|
|
10
|
+
const a: string[] = [];
|
|
11
|
+
if (col.align === 'end') a.push('zc-tbl__cell--end');
|
|
12
|
+
if (col.align === 'center') a.push('zc-tbl__cell--center');
|
|
13
|
+
if (col.grow) a.push('zc-tbl__cell--grow');
|
|
14
|
+
if (col.hideBelow) a.push('zc-tbl__cell--hide-' + col.hideBelow);
|
|
15
|
+
if (pinFirst && i === 0) {
|
|
16
|
+
a.push('zc-tbl__cell--pin', 'zc-tbl__cell--pinEdge');
|
|
17
|
+
if (selectable) a.push('zc-tbl__cell--pinOff');
|
|
18
|
+
}
|
|
19
|
+
return a;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
interface TableHeadProps<Row> {
|
|
23
|
+
columns: TableColumn<Row>[];
|
|
24
|
+
sort: TableSort | null;
|
|
25
|
+
onSort: (col: TableColumn<Row>) => void;
|
|
26
|
+
activateOn: ActivateOn;
|
|
27
|
+
mods: (col: TableColumn<Row>, i: number) => string[];
|
|
28
|
+
selectAll: ReactNode;
|
|
29
|
+
checkCellCls: string;
|
|
30
|
+
toggleColumn: boolean;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function TableHead<Row>({
|
|
34
|
+
columns,
|
|
35
|
+
sort,
|
|
36
|
+
onSort,
|
|
37
|
+
activateOn,
|
|
38
|
+
mods,
|
|
39
|
+
selectAll,
|
|
40
|
+
checkCellCls,
|
|
41
|
+
toggleColumn,
|
|
42
|
+
}: TableHeadProps<Row>) {
|
|
43
|
+
return (
|
|
44
|
+
<thead>
|
|
45
|
+
<tr>
|
|
46
|
+
{selectAll ? (
|
|
47
|
+
<th scope="col" className={checkCellCls}>
|
|
48
|
+
{selectAll}
|
|
49
|
+
</th>
|
|
50
|
+
) : null}
|
|
51
|
+
{columns.map((c, i) => {
|
|
52
|
+
const active = sort && sort.key === c.key;
|
|
53
|
+
const cls = (c.sortable ? ['zc-tbl__cell--sortable'] : []).concat(mods(c, i));
|
|
54
|
+
return (
|
|
55
|
+
<th
|
|
56
|
+
key={c.key}
|
|
57
|
+
scope="col"
|
|
58
|
+
className={cls.join(' ')}
|
|
59
|
+
style={c.width ? { width: c.width } : undefined}
|
|
60
|
+
aria-sort={active ? (sort.dir === 'asc' ? 'ascending' : 'descending') : undefined}
|
|
61
|
+
>
|
|
62
|
+
{c.sortable ? (
|
|
63
|
+
<button
|
|
64
|
+
type="button"
|
|
65
|
+
className="zc-tbl__sort"
|
|
66
|
+
{...activationProps<HTMLButtonElement>(() => onSort(c), { on: activateOn })}
|
|
67
|
+
>
|
|
68
|
+
<span className="zc-tbl__sortLbl">{c.label}</span>
|
|
69
|
+
<span
|
|
70
|
+
className={
|
|
71
|
+
'zc-tbl__sortIcon' +
|
|
72
|
+
(active ? ' zc-is-on' : '') +
|
|
73
|
+
(active && sort.dir === 'desc' ? ' zc-is-desc' : '')
|
|
74
|
+
}
|
|
75
|
+
aria-hidden="true"
|
|
76
|
+
>
|
|
77
|
+
<Icon name="arrow-up" size="sm" />
|
|
78
|
+
</span>
|
|
79
|
+
</button>
|
|
80
|
+
) : c.label != null ? (
|
|
81
|
+
<span className="zc-tbl__hLbl">{c.label}</span>
|
|
82
|
+
) : null}
|
|
83
|
+
</th>
|
|
84
|
+
);
|
|
85
|
+
})}
|
|
86
|
+
{toggleColumn ? <th scope="col" className="zc-tbl__cell--toggle" /> : null}
|
|
87
|
+
</tr>
|
|
88
|
+
</thead>
|
|
89
|
+
);
|
|
90
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
@layer zyncat.reset, zyncat.tokens, zyncat.base, zyncat.components;
|
|
2
|
+
|
|
3
|
+
@layer zyncat.components {
|
|
4
|
+
.zc-tbl__row[data-expandable] > td {
|
|
5
|
+
border-bottom-width: 0;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
.zc-tbl__table .zc-tbl__detail > td {
|
|
9
|
+
padding-block: 0;
|
|
10
|
+
white-space: normal;
|
|
11
|
+
}
|
|
12
|
+
.zc-tbl__detailBody {
|
|
13
|
+
padding: var(--ring-gutter) 0 var(--tbl-pad-y);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.zc-tbl__table .zc-tbl__cell--toggle {
|
|
17
|
+
width: 0;
|
|
18
|
+
padding: 0 var(--space-2);
|
|
19
|
+
text-align: right;
|
|
20
|
+
}
|
|
21
|
+
.zc-tbl__toggle .zc-icon {
|
|
22
|
+
transition: transform var(--duration-slow) var(--ease-standard);
|
|
23
|
+
}
|
|
24
|
+
.zc-tbl__toggle[aria-expanded='true'] .zc-icon {
|
|
25
|
+
transform: rotate(180deg);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -38,6 +38,7 @@
|
|
|
38
38
|
min-height: 0;
|
|
39
39
|
}
|
|
40
40
|
.zc-tbl__scroll {
|
|
41
|
+
position: relative;
|
|
41
42
|
flex: 1 1 auto;
|
|
42
43
|
min-height: 0;
|
|
43
44
|
overflow: auto;
|
|
@@ -49,6 +50,8 @@
|
|
|
49
50
|
}
|
|
50
51
|
|
|
51
52
|
.zc-tbl__table {
|
|
53
|
+
position: relative;
|
|
54
|
+
z-index: 1;
|
|
52
55
|
width: 100%;
|
|
53
56
|
border-collapse: separate; /* collapse breaks sticky borders */
|
|
54
57
|
border-spacing: 0;
|
|
@@ -77,7 +80,7 @@
|
|
|
77
80
|
.zc-tbl__table td {
|
|
78
81
|
padding: var(--tbl-pad-y) var(--space-3);
|
|
79
82
|
border-bottom: var(--border-hairline) solid var(--border-subtle);
|
|
80
|
-
background: var(--row-bg,
|
|
83
|
+
background: var(--row-bg, transparent);
|
|
81
84
|
font: var(--type-body);
|
|
82
85
|
color: var(--text-body);
|
|
83
86
|
vertical-align: middle;
|
|
@@ -93,7 +96,7 @@
|
|
|
93
96
|
padding-inline-start: var(--space-4);
|
|
94
97
|
}
|
|
95
98
|
.zc-tbl__table th:last-child:not(.zc-tbl__cell--sortable),
|
|
96
|
-
.zc-tbl__table td:last-child {
|
|
99
|
+
.zc-tbl__table td:last-child:not(.zc-tbl__cell--toggle) {
|
|
97
100
|
padding-inline-end: var(--space-4);
|
|
98
101
|
}
|
|
99
102
|
|
|
@@ -101,20 +104,30 @@
|
|
|
101
104
|
--_tbl-row-hover: var(--bg-subtle);
|
|
102
105
|
}
|
|
103
106
|
|
|
104
|
-
.zc-tbl__row {
|
|
105
|
-
--row-bg: var(--
|
|
107
|
+
.zc-tbl__row[data-selected] {
|
|
108
|
+
--row-bg: color-mix(in oklab, var(--accent) 5%, transparent);
|
|
106
109
|
}
|
|
107
|
-
.zc-tbl__row
|
|
108
|
-
|
|
110
|
+
.zc-tbl--clickable tbody .zc-tbl__row,
|
|
111
|
+
.zc-tbl__row[data-expandable] {
|
|
112
|
+
cursor: pointer;
|
|
109
113
|
}
|
|
110
|
-
|
|
111
|
-
|
|
114
|
+
|
|
115
|
+
.zc-tbl__glide {
|
|
116
|
+
position: absolute;
|
|
117
|
+
top: 0;
|
|
118
|
+
left: 0;
|
|
119
|
+
opacity: 0;
|
|
120
|
+
pointer-events: none;
|
|
112
121
|
}
|
|
113
|
-
.zc-
|
|
114
|
-
|
|
122
|
+
.zc-tbl__glide::before {
|
|
123
|
+
content: '';
|
|
124
|
+
position: absolute;
|
|
125
|
+
inset: var(--space-1) var(--space-2);
|
|
126
|
+
border-radius: var(--radius-md);
|
|
127
|
+
background: var(--_tbl-row-hover);
|
|
115
128
|
}
|
|
116
|
-
.zc-tbl--
|
|
117
|
-
|
|
129
|
+
.zc-tbl--loading .zc-tbl__glide {
|
|
130
|
+
visibility: hidden;
|
|
118
131
|
}
|
|
119
132
|
|
|
120
133
|
.zc-tbl__table td.zc-tbl__cell--mono {
|
|
@@ -134,6 +147,12 @@
|
|
|
134
147
|
.zc-tbl__cell--grow {
|
|
135
148
|
width: 100%;
|
|
136
149
|
}
|
|
150
|
+
.zc-tbl--shares .zc-tbl__table .zc-tbl__cell--grow {
|
|
151
|
+
width: auto;
|
|
152
|
+
}
|
|
153
|
+
.zc-tbl--shares .zc-tbl__table th:not(.zc-tbl__cell--grow, .zc-tbl__cell--check) {
|
|
154
|
+
width: 0;
|
|
155
|
+
}
|
|
137
156
|
|
|
138
157
|
.zc-tbl__table th.zc-tbl__cell--sortable {
|
|
139
158
|
padding: 0;
|
|
@@ -248,7 +267,7 @@
|
|
|
248
267
|
.zc-tbl__bulkCount {
|
|
249
268
|
display: inline-flex;
|
|
250
269
|
align-items: baseline;
|
|
251
|
-
font-family: var(--font-
|
|
270
|
+
font-family: var(--font-body);
|
|
252
271
|
font-size: var(--size-caption);
|
|
253
272
|
line-height: var(--leading-caption);
|
|
254
273
|
font-weight: var(--weight-medium);
|
|
@@ -268,6 +287,9 @@
|
|
|
268
287
|
.zc-tbl--pin thead .zc-tbl__cell--pin {
|
|
269
288
|
z-index: 3;
|
|
270
289
|
}
|
|
290
|
+
.zc-tbl[data-x-back] td.zc-tbl__cell--pin {
|
|
291
|
+
background: linear-gradient(var(--row-bg, transparent) 0 0), linear-gradient(var(--bg-surface) 0 0);
|
|
292
|
+
}
|
|
271
293
|
.zc-tbl--pin .zc-tbl__cell--pinOff {
|
|
272
294
|
left: var(--tbl-check-w);
|
|
273
295
|
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import type { HTMLAttributes, ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
import type { DataAttributes } from '../../../dom-props';
|
|
4
|
+
import type { ActivateOn } from '../../internal/utils/activation';
|
|
5
|
+
|
|
6
|
+
export type TableAlign = 'start' | 'end' | 'center';
|
|
7
|
+
export type TableHideBelow = 'sm' | 'md';
|
|
8
|
+
|
|
9
|
+
export interface TableColumn<Row = any> {
|
|
10
|
+
/** Unique column id; also the default data accessor (row[key]). */
|
|
11
|
+
key: string;
|
|
12
|
+
/** Header cell content; omit for a header-less column (e.g. an actions column). */
|
|
13
|
+
label?: ReactNode;
|
|
14
|
+
/** Cell + header alignment. Default 'start'. */
|
|
15
|
+
align?: TableAlign;
|
|
16
|
+
/** Mono + tabular numerals (timestamps, counts, IDs - section E). */
|
|
17
|
+
mono?: boolean;
|
|
18
|
+
/** Identity emphasis: strong text, medium weight. */
|
|
19
|
+
strong?: boolean;
|
|
20
|
+
/** The one greedy column - absorbs slack width. Others size to content. */
|
|
21
|
+
grow?: boolean;
|
|
22
|
+
/** Share of the table's width this column takes, e.g. '30%'. A grow column takes what the shares leave;
|
|
23
|
+
* when the table is too narrow, the cells' content widths win. */
|
|
24
|
+
width?: `${number}%`;
|
|
25
|
+
/** Header becomes a sort control. Sort is local; asc - desc, no third state. */
|
|
26
|
+
sortable?: boolean;
|
|
27
|
+
/** Sort accessor: a row property name, or a function. Defaults to row[key]. */
|
|
28
|
+
sortBy?: string | ((row: Row) => unknown);
|
|
29
|
+
/** Collapse this column below a container breakpoint (30rem / 42rem). */
|
|
30
|
+
hideBelow?: TableHideBelow;
|
|
31
|
+
/** Custom cell renderer. Defaults to row[key]. */
|
|
32
|
+
render?: (row: Row) => ReactNode;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface TableSort {
|
|
36
|
+
/** `key` of the column being sorted by. */
|
|
37
|
+
key: string;
|
|
38
|
+
/** Sort direction - `asc` or `desc`. */
|
|
39
|
+
dir: 'asc' | 'desc';
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface TableProps<Row = any> {
|
|
43
|
+
/** Column defs, rendered left to right. */
|
|
44
|
+
columns: TableColumn<Row>[];
|
|
45
|
+
/** The row data; sorted locally per the active sort before render. */
|
|
46
|
+
rows: Row[];
|
|
47
|
+
/** Row identity property. Default 'id'. Must be unique and stable. */
|
|
48
|
+
rowKey?: string;
|
|
49
|
+
/** Accessible name for the <table>. */
|
|
50
|
+
ariaLabel?: string;
|
|
51
|
+
|
|
52
|
+
/** Checkbox column + bulk bar. Selection is a Set of row keys, owned here. */
|
|
53
|
+
selectable?: boolean;
|
|
54
|
+
/** Fires with the selected row keys after every selection change. */
|
|
55
|
+
onSelectionChange?: (keys: Array<string | number>) => void;
|
|
56
|
+
/** Rendered in the bulk bar between the count and the built-in Clear. */
|
|
57
|
+
bulkActions?: (keys: Array<string | number>, clear: () => void) => ReactNode;
|
|
58
|
+
/** Per-row checkbox aria-label. Default 'Select row'. */
|
|
59
|
+
selectionLabel?: (row: Row) => string;
|
|
60
|
+
|
|
61
|
+
/** Initial sort; sorting stays local and uncontrolled after that. */
|
|
62
|
+
defaultSort?: TableSort | null;
|
|
63
|
+
/** Notification only - fires after the local sort updates. */
|
|
64
|
+
onSortChange?: (sort: TableSort) => void;
|
|
65
|
+
|
|
66
|
+
/** A row's details, unfolding full width under it from its disclosure button or a click on the
|
|
67
|
+
* row. A falsy return leaves that row without details. */
|
|
68
|
+
renderDetail?: (row: Row) => ReactNode;
|
|
69
|
+
/** Keys of the rows whose details are open. Omit to let the table own it. */
|
|
70
|
+
expanded?: Array<string | number>;
|
|
71
|
+
/** Fires with the open row keys after every toggle. */
|
|
72
|
+
onExpandedChange?: (keys: Array<string | number>) => void;
|
|
73
|
+
/** `single` closes the open row as another opens. Default 'multiple'. */
|
|
74
|
+
expandMode?: 'single' | 'multiple';
|
|
75
|
+
|
|
76
|
+
/** Row rhythm. Default 'cozy' (46px rows); 'compact' is 38px. */
|
|
77
|
+
density?: 'cozy' | 'compact';
|
|
78
|
+
/** Pin checkbox + first column under horizontal overflow. Default true. */
|
|
79
|
+
pinFirst?: boolean;
|
|
80
|
+
|
|
81
|
+
/** Rows recede and go inert (list-fetch convention). */
|
|
82
|
+
loading?: boolean;
|
|
83
|
+
/** Shown when rows is empty and not loading. Default 'Nothing to show'. */
|
|
84
|
+
empty?: ReactNode;
|
|
85
|
+
/** Footer strip - pagination, summaries. */
|
|
86
|
+
footer?: ReactNode;
|
|
87
|
+
|
|
88
|
+
/** Makes rows clickable. A click on the checkbox cell, or on a link, button, field or label in a
|
|
89
|
+
* cell, stays with it. */
|
|
90
|
+
onRowClick?: (row: Row) => void;
|
|
91
|
+
/** Whether a sortable header fires on `pointerdown` (snappier) or waits for `click`. @default 'pointerdown' */
|
|
92
|
+
activateOn?: ActivateOn;
|
|
93
|
+
/** Size the table here - the internal scroller absorbs the constraint. */
|
|
94
|
+
className?: string;
|
|
95
|
+
/** Standard <div> attributes (style, data-*, aria-*, ...) forwarded to the table wrapper. */
|
|
96
|
+
htmlProps?: Omit<HTMLAttributes<HTMLDivElement>, 'className'> & DataAttributes;
|
|
97
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useEffect, useRef, type RefObject } from 'react';
|
|
4
|
+
|
|
5
|
+
import { useGlide } from '../../../motion/glide';
|
|
6
|
+
import { useScrollEdges } from '../../internal/hooks/use-scroll-edges';
|
|
7
|
+
|
|
8
|
+
export function useRowGlide(scrollRef: RefObject<HTMLDivElement | null>) {
|
|
9
|
+
const tableRef = useRef<HTMLTableElement>(null);
|
|
10
|
+
const hoveredRef = useRef<HTMLElement | null>(null);
|
|
11
|
+
const glide = useGlide(scrollRef);
|
|
12
|
+
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
const table = tableRef.current;
|
|
15
|
+
if (!table) return undefined;
|
|
16
|
+
const follow = new ResizeObserver(() => glide.enter(hoveredRef.current));
|
|
17
|
+
follow.observe(table);
|
|
18
|
+
return () => follow.disconnect();
|
|
19
|
+
}, [glide]);
|
|
20
|
+
|
|
21
|
+
function hoverRow(row: Element | null) {
|
|
22
|
+
hoveredRef.current = row instanceof HTMLElement ? row : null;
|
|
23
|
+
glide.enter(hoveredRef.current);
|
|
24
|
+
}
|
|
25
|
+
function leaveRows() {
|
|
26
|
+
hoveredRef.current = null;
|
|
27
|
+
glide.leave();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return { tableRef, glide, hoverRow, leaveRows };
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function useEdgeAttributes(
|
|
34
|
+
scrollRef: RefObject<HTMLDivElement | null>,
|
|
35
|
+
wrapRef: RefObject<HTMLDivElement | null>,
|
|
36
|
+
) {
|
|
37
|
+
useScrollEdges(
|
|
38
|
+
scrollRef,
|
|
39
|
+
(edges, el) => {
|
|
40
|
+
const w = wrapRef.current;
|
|
41
|
+
if (!w) return;
|
|
42
|
+
const set = (attr: string, on: boolean) => {
|
|
43
|
+
if (on) w.setAttribute(attr, '');
|
|
44
|
+
else w.removeAttribute(attr);
|
|
45
|
+
};
|
|
46
|
+
set('data-scrolled', el.scrollTop > 0);
|
|
47
|
+
set('data-y-scroll', el.scrollHeight > el.clientHeight);
|
|
48
|
+
set('data-x-back', edges.left);
|
|
49
|
+
set('data-x-more', edges.right);
|
|
50
|
+
},
|
|
51
|
+
{ content: true },
|
|
52
|
+
);
|
|
53
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useMemo, useRef, useState } from 'react';
|
|
4
|
+
|
|
5
|
+
import type { TableColumn, TableSort } from './types';
|
|
6
|
+
|
|
7
|
+
function tblCompare(a: unknown, b: unknown) {
|
|
8
|
+
if (a == null && b == null) return 0;
|
|
9
|
+
if (a == null) return 1;
|
|
10
|
+
if (b == null) return -1;
|
|
11
|
+
if (typeof a === 'number' && typeof b === 'number') return a - b;
|
|
12
|
+
return String(a).localeCompare(String(b), undefined, { numeric: true, sensitivity: 'base' });
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function useSort<Row>(
|
|
16
|
+
rows: Row[],
|
|
17
|
+
columns: TableColumn<Row>[],
|
|
18
|
+
defaultSort: TableSort | null,
|
|
19
|
+
onSortChange?: (sort: TableSort) => void,
|
|
20
|
+
) {
|
|
21
|
+
const [sort, setSort] = useState<TableSort | null>(defaultSort);
|
|
22
|
+
|
|
23
|
+
const sortedRows = useMemo(() => {
|
|
24
|
+
if (!sort) return rows;
|
|
25
|
+
const col = columns.find((c) => c.key === sort.key);
|
|
26
|
+
if (!col) return rows;
|
|
27
|
+
const get =
|
|
28
|
+
typeof col.sortBy === 'function'
|
|
29
|
+
? col.sortBy
|
|
30
|
+
: col.sortBy
|
|
31
|
+
? (r: Row) => (r as Record<string, unknown>)[col.sortBy as string]
|
|
32
|
+
: (r: Row) => (r as Record<string, unknown>)[col.key];
|
|
33
|
+
const dir = sort.dir === 'desc' ? -1 : 1;
|
|
34
|
+
return rows.slice().sort((a, b) => dir * tblCompare(get(a), get(b)));
|
|
35
|
+
}, [rows, columns, sort]);
|
|
36
|
+
|
|
37
|
+
function cycleSort(col: TableColumn<Row>) {
|
|
38
|
+
const next: TableSort =
|
|
39
|
+
sort && sort.key === col.key
|
|
40
|
+
? { key: col.key, dir: sort.dir === 'asc' ? 'desc' : 'asc' }
|
|
41
|
+
: { key: col.key, dir: 'asc' };
|
|
42
|
+
setSort(next);
|
|
43
|
+
if (onSortChange) onSortChange(next);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return { sort, sortedRows, cycleSort };
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function useSelection<Row>(
|
|
50
|
+
rows: Row[],
|
|
51
|
+
keyOf: (row: Row) => string | number,
|
|
52
|
+
onSelectionChange?: (keys: Array<string | number>) => void,
|
|
53
|
+
) {
|
|
54
|
+
const [selected, setSelected] = useState<Set<string | number>>(() => new Set());
|
|
55
|
+
const lastIdxRef = useRef(-1);
|
|
56
|
+
const shiftRef = useRef(false);
|
|
57
|
+
|
|
58
|
+
const allSelected = rows.length > 0 && rows.every((r) => selected.has(keyOf(r)));
|
|
59
|
+
const someSelected = selected.size > 0 && !allSelected;
|
|
60
|
+
|
|
61
|
+
function commitSelection(next: Set<string | number>) {
|
|
62
|
+
setSelected(next);
|
|
63
|
+
if (onSelectionChange) onSelectionChange(Array.from(next));
|
|
64
|
+
}
|
|
65
|
+
function clearSelection() {
|
|
66
|
+
lastIdxRef.current = -1;
|
|
67
|
+
commitSelection(new Set());
|
|
68
|
+
}
|
|
69
|
+
function toggleAll() {
|
|
70
|
+
const next = new Set<string | number>();
|
|
71
|
+
if (!allSelected) rows.forEach((r) => next.add(keyOf(r)));
|
|
72
|
+
commitSelection(next);
|
|
73
|
+
}
|
|
74
|
+
function toggleRow(idx: number) {
|
|
75
|
+
const next = new Set(selected);
|
|
76
|
+
const on = !next.has(keyOf(rows[idx]));
|
|
77
|
+
if (shiftRef.current && lastIdxRef.current >= 0 && lastIdxRef.current !== idx) {
|
|
78
|
+
const lo = Math.min(lastIdxRef.current, idx);
|
|
79
|
+
const hi = Math.max(lastIdxRef.current, idx);
|
|
80
|
+
for (let i = lo; i <= hi; i++) {
|
|
81
|
+
const k = keyOf(rows[i]);
|
|
82
|
+
if (on) next.add(k);
|
|
83
|
+
else next.delete(k);
|
|
84
|
+
}
|
|
85
|
+
} else if (on) {
|
|
86
|
+
next.add(keyOf(rows[idx]));
|
|
87
|
+
} else {
|
|
88
|
+
next.delete(keyOf(rows[idx]));
|
|
89
|
+
}
|
|
90
|
+
lastIdxRef.current = idx;
|
|
91
|
+
shiftRef.current = false;
|
|
92
|
+
commitSelection(next);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return { selected, allSelected, someSelected, shiftRef, clearSelection, toggleAll, toggleRow };
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export type Selection = ReturnType<typeof useSelection>;
|