@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
|
@@ -2,107 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
import './table.css';
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { useRef } from 'react';
|
|
6
6
|
|
|
7
|
-
import
|
|
8
|
-
import { Motion } from '../../../motion/element';
|
|
9
|
-
import { UIMotion } from '../../../tokens/motion-tokens';
|
|
10
|
-
import { useScrollEdges } from '../../internal/hooks/use-scroll-edges';
|
|
11
|
-
import { Icon } from '../../internal/icon/Icon';
|
|
12
|
-
import { activationProps, type ActivateOn } from '../../internal/utils/activation';
|
|
7
|
+
import { GlidePill } from '../../../motion/glide';
|
|
13
8
|
import { cx } from '../../internal/utils/cx';
|
|
14
9
|
import { DigitStrip } from '../../primitives/badge/digit-strip';
|
|
15
10
|
import { Button } from '../../primitives/button/Button';
|
|
16
11
|
import { Checkbox } from '../../primitives/checkbox/Checkbox';
|
|
12
|
+
import { TableBody } from './body';
|
|
13
|
+
import { cellMods, TableHead } from './head';
|
|
14
|
+
import type { TableColumn, TableProps } from './types';
|
|
15
|
+
import { useEdgeAttributes, useRowGlide } from './use-scroller';
|
|
16
|
+
import { useSelection, useSort } from './use-table-state';
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
export type TableAlign = 'start' | 'end' | 'center';
|
|
21
|
-
export type TableHideBelow = 'sm' | 'md';
|
|
22
|
-
|
|
23
|
-
export interface TableColumn<Row = any> {
|
|
24
|
-
/** Unique column id; also the default data accessor (row[key]). */
|
|
25
|
-
key: string;
|
|
26
|
-
/** Header cell content; omit for a header-less column (e.g. an actions column). */
|
|
27
|
-
label?: ReactNode;
|
|
28
|
-
/** Cell + header alignment. Default 'start'. */
|
|
29
|
-
align?: TableAlign;
|
|
30
|
-
/** Mono + tabular numerals (timestamps, counts, IDs - section E). */
|
|
31
|
-
mono?: boolean;
|
|
32
|
-
/** Identity emphasis: strong text, medium weight. */
|
|
33
|
-
strong?: boolean;
|
|
34
|
-
/** The one greedy column - absorbs slack width. Others size to content. */
|
|
35
|
-
grow?: boolean;
|
|
36
|
-
/** Header becomes a sort control. Sort is local; asc - desc, no third state. */
|
|
37
|
-
sortable?: boolean;
|
|
38
|
-
/** Sort accessor: a row property name, or a function. Defaults to row[key]. */
|
|
39
|
-
sortBy?: string | ((row: Row) => unknown);
|
|
40
|
-
/** Collapse this column below a container breakpoint (30rem / 42rem). */
|
|
41
|
-
hideBelow?: TableHideBelow;
|
|
42
|
-
/** Custom cell renderer. Defaults to row[key]. */
|
|
43
|
-
render?: (row: Row) => ReactNode;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export interface TableSort {
|
|
47
|
-
/** `key` of the column being sorted by. */
|
|
48
|
-
key: string;
|
|
49
|
-
/** Sort direction - `asc` or `desc`. */
|
|
50
|
-
dir: 'asc' | 'desc';
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export interface TableProps<Row = any> {
|
|
54
|
-
/** Column defs, rendered left to right. */
|
|
55
|
-
columns: TableColumn<Row>[];
|
|
56
|
-
/** The row data; sorted locally per the active sort before render. */
|
|
57
|
-
rows: Row[];
|
|
58
|
-
/** Row identity property. Default 'id'. Must be unique and stable. */
|
|
59
|
-
rowKey?: string;
|
|
60
|
-
/** Accessible name for the <table>. */
|
|
61
|
-
ariaLabel?: string;
|
|
62
|
-
|
|
63
|
-
/** Checkbox column + bulk bar. Selection is a Set of row keys, owned here. */
|
|
64
|
-
selectable?: boolean;
|
|
65
|
-
/** Fires with the selected row keys after every selection change. */
|
|
66
|
-
onSelectionChange?: (keys: Array<string | number>) => void;
|
|
67
|
-
/** Rendered in the bulk bar between the count and the built-in Clear. */
|
|
68
|
-
bulkActions?: (keys: Array<string | number>, clear: () => void) => ReactNode;
|
|
69
|
-
/** Per-row checkbox aria-label. Default 'Select row'. */
|
|
70
|
-
selectionLabel?: (row: Row) => string;
|
|
71
|
-
|
|
72
|
-
/** Initial sort; sorting stays local and uncontrolled after that. */
|
|
73
|
-
defaultSort?: TableSort | null;
|
|
74
|
-
/** Notification only - fires after the local sort updates. */
|
|
75
|
-
onSortChange?: (sort: TableSort) => void;
|
|
76
|
-
|
|
77
|
-
/** Row rhythm. Default 'cozy' (46px rows); 'compact' is 38px. */
|
|
78
|
-
density?: 'cozy' | 'compact';
|
|
79
|
-
/** Pin checkbox + first column under horizontal overflow. Default true. */
|
|
80
|
-
pinFirst?: boolean;
|
|
81
|
-
|
|
82
|
-
/** Rows recede and go inert (list-fetch convention). */
|
|
83
|
-
loading?: boolean;
|
|
84
|
-
/** Shown when rows is empty and not loading. Default 'Nothing to show'. */
|
|
85
|
-
empty?: ReactNode;
|
|
86
|
-
/** Footer strip - pagination, summaries. */
|
|
87
|
-
footer?: ReactNode;
|
|
88
|
-
|
|
89
|
-
/** Makes rows clickable (checkbox cell excluded). */
|
|
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
|
-
}
|
|
98
|
-
|
|
99
|
-
function tblCompare(a: unknown, b: unknown) {
|
|
100
|
-
if (a == null && b == null) return 0;
|
|
101
|
-
if (a == null) return 1;
|
|
102
|
-
if (b == null) return -1;
|
|
103
|
-
if (typeof a === 'number' && typeof b === 'number') return a - b;
|
|
104
|
-
return String(a).localeCompare(String(b), undefined, { numeric: true, sensitivity: 'base' });
|
|
105
|
-
}
|
|
18
|
+
export type { TableAlign, TableColumn, TableHideBelow, TableProps, TableSort } from './types';
|
|
106
19
|
|
|
107
20
|
export function Table<Row = any>({
|
|
108
21
|
columns = [],
|
|
@@ -115,6 +28,10 @@ export function Table<Row = any>({
|
|
|
115
28
|
selectionLabel,
|
|
116
29
|
defaultSort = null,
|
|
117
30
|
onSortChange,
|
|
31
|
+
renderDetail,
|
|
32
|
+
expanded,
|
|
33
|
+
onExpandedChange,
|
|
34
|
+
expandMode = 'multiple',
|
|
118
35
|
density = 'cozy',
|
|
119
36
|
pinFirst = true,
|
|
120
37
|
loading = false,
|
|
@@ -125,111 +42,21 @@ export function Table<Row = any>({
|
|
|
125
42
|
className = '',
|
|
126
43
|
htmlProps,
|
|
127
44
|
}: TableProps<Row>) {
|
|
128
|
-
const
|
|
129
|
-
const
|
|
45
|
+
const { sort, sortedRows, cycleSort } = useSort(rows, columns, defaultSort, onSortChange);
|
|
46
|
+
const keyOf = (row: Row): string | number => (row as Record<string, string | number>)[rowKey];
|
|
47
|
+
const selection = useSelection(sortedRows, keyOf, onSelectionChange);
|
|
48
|
+
const { selected, allSelected, someSelected, toggleAll, clearSelection } = selection;
|
|
130
49
|
const wrapRef = useRef<HTMLDivElement>(null);
|
|
131
50
|
const scrollRef = useRef<HTMLDivElement>(null);
|
|
132
|
-
const lastIdxRef = useRef(-1);
|
|
133
|
-
const shiftRef = useRef(false);
|
|
134
51
|
const lastCountRef = useRef(0);
|
|
52
|
+
const { tableRef, glide, hoverRow, leaveRows } = useRowGlide(scrollRef);
|
|
53
|
+
useEdgeAttributes(scrollRef, wrapRef);
|
|
135
54
|
|
|
136
|
-
const
|
|
137
|
-
|
|
138
|
-
const sortedRows = useMemo(() => {
|
|
139
|
-
if (!sort) return rows;
|
|
140
|
-
const col = columns.find((c) => c.key === sort.key);
|
|
141
|
-
if (!col) return rows;
|
|
142
|
-
const get =
|
|
143
|
-
typeof col.sortBy === 'function'
|
|
144
|
-
? col.sortBy
|
|
145
|
-
: col.sortBy
|
|
146
|
-
? (r: Row) => (r as Record<string, unknown>)[col.sortBy as string]
|
|
147
|
-
: (r: Row) => (r as Record<string, unknown>)[col.key];
|
|
148
|
-
const dir = sort.dir === 'desc' ? -1 : 1;
|
|
149
|
-
return rows.slice().sort((a, b) => dir * tblCompare(get(a), get(b)));
|
|
150
|
-
}, [rows, columns, sort]);
|
|
151
|
-
|
|
152
|
-
function cycleSort(col: TableColumn<Row>) {
|
|
153
|
-
const next: TableSort =
|
|
154
|
-
sort && sort.key === col.key
|
|
155
|
-
? { key: col.key, dir: sort.dir === 'asc' ? 'desc' : 'asc' }
|
|
156
|
-
: { key: col.key, dir: 'asc' };
|
|
157
|
-
setSort(next);
|
|
158
|
-
if (onSortChange) onSortChange(next);
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
const allSelected = sortedRows.length > 0 && sortedRows.every((r) => selected.has(keyOf(r)));
|
|
162
|
-
const someSelected = selected.size > 0 && !allSelected;
|
|
163
|
-
|
|
164
|
-
function commitSelection(next: Set<string | number>) {
|
|
165
|
-
setSelected(next);
|
|
166
|
-
if (onSelectionChange) onSelectionChange(Array.from(next));
|
|
167
|
-
}
|
|
168
|
-
function clearSelection() {
|
|
169
|
-
lastIdxRef.current = -1;
|
|
170
|
-
commitSelection(new Set());
|
|
171
|
-
}
|
|
172
|
-
function toggleAll() {
|
|
173
|
-
const next = new Set<string | number>();
|
|
174
|
-
if (!allSelected) sortedRows.forEach((r) => next.add(keyOf(r)));
|
|
175
|
-
commitSelection(next);
|
|
176
|
-
}
|
|
177
|
-
function toggleRow(idx: number) {
|
|
178
|
-
const next = new Set(selected);
|
|
179
|
-
const on = !next.has(keyOf(sortedRows[idx]));
|
|
180
|
-
if (shiftRef.current && lastIdxRef.current >= 0 && lastIdxRef.current !== idx) {
|
|
181
|
-
const lo = Math.min(lastIdxRef.current, idx);
|
|
182
|
-
const hi = Math.max(lastIdxRef.current, idx);
|
|
183
|
-
for (let i = lo; i <= hi; i++) {
|
|
184
|
-
const k = keyOf(sortedRows[i]);
|
|
185
|
-
if (on) next.add(k);
|
|
186
|
-
else next.delete(k);
|
|
187
|
-
}
|
|
188
|
-
} else if (on) {
|
|
189
|
-
next.add(keyOf(sortedRows[idx]));
|
|
190
|
-
} else {
|
|
191
|
-
next.delete(keyOf(sortedRows[idx]));
|
|
192
|
-
}
|
|
193
|
-
lastIdxRef.current = idx;
|
|
194
|
-
shiftRef.current = false;
|
|
195
|
-
commitSelection(next);
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
useScrollEdges(
|
|
199
|
-
scrollRef,
|
|
200
|
-
(edges, el) => {
|
|
201
|
-
const w = wrapRef.current;
|
|
202
|
-
if (!w) return;
|
|
203
|
-
const set = (attr: string, on: boolean) => {
|
|
204
|
-
if (on) w.setAttribute(attr, '');
|
|
205
|
-
else w.removeAttribute(attr);
|
|
206
|
-
};
|
|
207
|
-
set('data-scrolled', el.scrollTop > 0);
|
|
208
|
-
set('data-y-scroll', el.scrollHeight > el.clientHeight);
|
|
209
|
-
set('data-x-back', edges.left);
|
|
210
|
-
set('data-x-more', edges.right);
|
|
211
|
-
},
|
|
212
|
-
{ content: true },
|
|
213
|
-
);
|
|
214
|
-
|
|
215
|
-
function cellMods(col: TableColumn<Row>, i: number) {
|
|
216
|
-
const a: string[] = [];
|
|
217
|
-
if (col.align === 'end') a.push('zc-tbl__cell--end');
|
|
218
|
-
if (col.align === 'center') a.push('zc-tbl__cell--center');
|
|
219
|
-
if (col.grow) a.push('zc-tbl__cell--grow');
|
|
220
|
-
if (col.hideBelow) a.push('zc-tbl__cell--hide-' + col.hideBelow);
|
|
221
|
-
if (pinFirst && i === 0) {
|
|
222
|
-
a.push('zc-tbl__cell--pin', 'zc-tbl__cell--pinEdge');
|
|
223
|
-
if (selectable) a.push('zc-tbl__cell--pinOff');
|
|
224
|
-
}
|
|
225
|
-
return a;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
const colCount = columns.length + (selectable ? 1 : 0);
|
|
229
|
-
const showEmpty = !loading && sortedRows.length === 0;
|
|
55
|
+
const mods = (c: TableColumn<Row>, i: number) => cellMods(c, i, pinFirst, selectable);
|
|
230
56
|
const checkCellCls = 'zc-tbl__cell--check' + (pinFirst ? ' zc-tbl__cell--pin' : '');
|
|
231
57
|
|
|
232
58
|
const checkSize = density === 'compact' ? 'sm' : 'md';
|
|
59
|
+
const toggleSize = density === 'compact' ? 'xs' : 'sm';
|
|
233
60
|
const bulkOpen = selectable && selected.size > 0;
|
|
234
61
|
if (selected.size > 0) lastCountRef.current = selected.size;
|
|
235
62
|
|
|
@@ -239,8 +66,19 @@ export function Table<Row = any>({
|
|
|
239
66
|
pinFirst && 'zc-tbl--pin',
|
|
240
67
|
loading && 'zc-tbl--loading',
|
|
241
68
|
onRowClick && 'zc-tbl--clickable',
|
|
69
|
+
columns.some((c) => c.width) && columns.some((c) => c.grow) && 'zc-tbl--shares',
|
|
242
70
|
className,
|
|
243
71
|
);
|
|
72
|
+
const selectAll = selectable ? (
|
|
73
|
+
<Checkbox
|
|
74
|
+
className="zc-tbl__cbx"
|
|
75
|
+
size={checkSize}
|
|
76
|
+
checked={allSelected}
|
|
77
|
+
indeterminate={someSelected}
|
|
78
|
+
htmlProps={{ 'aria-label': 'Select all rows' }}
|
|
79
|
+
onChange={toggleAll}
|
|
80
|
+
/>
|
|
81
|
+
) : null;
|
|
244
82
|
|
|
245
83
|
return (
|
|
246
84
|
<div ref={wrapRef} className={rootCls} {...htmlProps}>
|
|
@@ -252,14 +90,7 @@ export function Table<Row = any>({
|
|
|
252
90
|
role="toolbar"
|
|
253
91
|
aria-label="Selection actions"
|
|
254
92
|
>
|
|
255
|
-
|
|
256
|
-
className="zc-tbl__cbx"
|
|
257
|
-
size={checkSize}
|
|
258
|
-
checked={allSelected}
|
|
259
|
-
indeterminate={someSelected}
|
|
260
|
-
htmlProps={{ 'aria-label': 'Select all rows' }}
|
|
261
|
-
onChange={toggleAll}
|
|
262
|
-
/>
|
|
93
|
+
{selectAll}
|
|
263
94
|
<span className="zc-tbl__bulkCount" aria-live="polite" aria-atomic="true">
|
|
264
95
|
<DigitStrip value={bulkOpen ? selected.size : lastCountRef.current} />
|
|
265
96
|
<span> selected</span>
|
|
@@ -274,111 +105,40 @@ export function Table<Row = any>({
|
|
|
274
105
|
|
|
275
106
|
<div className="zc-tbl__viewport">
|
|
276
107
|
<div className="zc-tbl__scroll" ref={scrollRef}>
|
|
277
|
-
<table className="zc-tbl__table" aria-label={ariaLabel} aria-busy={loading || undefined}>
|
|
278
|
-
<
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
<span
|
|
310
|
-
className={
|
|
311
|
-
'zc-tbl__sortIcon' +
|
|
312
|
-
(active ? ' zc-is-on' : '') +
|
|
313
|
-
(active && sort.dir === 'desc' ? ' zc-is-desc' : '')
|
|
314
|
-
}
|
|
315
|
-
aria-hidden="true"
|
|
316
|
-
>
|
|
317
|
-
<Icon name="arrow-up" size="sm" />
|
|
318
|
-
</span>
|
|
319
|
-
</button>
|
|
320
|
-
) : c.label != null ? (
|
|
321
|
-
<span className="zc-tbl__hLbl">{c.label}</span>
|
|
322
|
-
) : null}
|
|
323
|
-
</th>
|
|
324
|
-
);
|
|
325
|
-
})}
|
|
326
|
-
</tr>
|
|
327
|
-
</thead>
|
|
328
|
-
<tbody>
|
|
329
|
-
{showEmpty ? (
|
|
330
|
-
<tr>
|
|
331
|
-
<td colSpan={colCount} className="zc-tbl__emptyCell">
|
|
332
|
-
{empty != null ? empty : 'Nothing to show'}
|
|
333
|
-
</td>
|
|
334
|
-
</tr>
|
|
335
|
-
) : (
|
|
336
|
-
sortedRows.map((row, idx) => {
|
|
337
|
-
const k = keyOf(row);
|
|
338
|
-
const isSel = selected.has(k);
|
|
339
|
-
return (
|
|
340
|
-
<Motion
|
|
341
|
-
as="tr"
|
|
342
|
-
key={k}
|
|
343
|
-
layout
|
|
344
|
-
layoutTransition={ROW_FLIP}
|
|
345
|
-
className="zc-tbl__row"
|
|
346
|
-
data-selected={isSel ? '' : undefined}
|
|
347
|
-
onClick={onRowClick ? () => onRowClick(row) : undefined}
|
|
348
|
-
>
|
|
349
|
-
{selectable ? (
|
|
350
|
-
<td className={checkCellCls} onClick={(e) => e.stopPropagation()}>
|
|
351
|
-
<Checkbox
|
|
352
|
-
className="zc-tbl__cbx"
|
|
353
|
-
size={checkSize}
|
|
354
|
-
checked={isSel}
|
|
355
|
-
htmlProps={{
|
|
356
|
-
'aria-label': selectionLabel ? selectionLabel(row) : 'Select row',
|
|
357
|
-
onClick: (e) => {
|
|
358
|
-
shiftRef.current = e.shiftKey;
|
|
359
|
-
},
|
|
360
|
-
}}
|
|
361
|
-
onChange={() => toggleRow(idx)}
|
|
362
|
-
/>
|
|
363
|
-
</td>
|
|
364
|
-
) : null}
|
|
365
|
-
{columns.map((c, i) => (
|
|
366
|
-
<td
|
|
367
|
-
key={c.key}
|
|
368
|
-
className={cellMods(c, i)
|
|
369
|
-
.concat(c.mono ? ['zc-tbl__cell--mono'] : [])
|
|
370
|
-
.concat(c.strong ? ['zc-tbl__cell--strong'] : [])
|
|
371
|
-
.join(' ')}
|
|
372
|
-
>
|
|
373
|
-
{c.render ? c.render(row) : (row as Record<string, ReactNode>)[c.key]}
|
|
374
|
-
</td>
|
|
375
|
-
))}
|
|
376
|
-
</Motion>
|
|
377
|
-
);
|
|
378
|
-
})
|
|
379
|
-
)}
|
|
380
|
-
</tbody>
|
|
108
|
+
<table ref={tableRef} className="zc-tbl__table" aria-label={ariaLabel} aria-busy={loading || undefined}>
|
|
109
|
+
<TableHead
|
|
110
|
+
columns={columns}
|
|
111
|
+
sort={sort}
|
|
112
|
+
onSort={cycleSort}
|
|
113
|
+
activateOn={activateOn}
|
|
114
|
+
mods={mods}
|
|
115
|
+
selectAll={selectAll}
|
|
116
|
+
checkCellCls={checkCellCls}
|
|
117
|
+
toggleColumn={!!renderDetail}
|
|
118
|
+
/>
|
|
119
|
+
<TableBody
|
|
120
|
+
rows={sortedRows}
|
|
121
|
+
keyOf={keyOf}
|
|
122
|
+
columns={columns}
|
|
123
|
+
mods={mods}
|
|
124
|
+
selectable={selectable}
|
|
125
|
+
selection={selection}
|
|
126
|
+
selectionLabel={selectionLabel}
|
|
127
|
+
checkCellCls={checkCellCls}
|
|
128
|
+
checkSize={checkSize}
|
|
129
|
+
toggleSize={toggleSize}
|
|
130
|
+
renderDetail={renderDetail}
|
|
131
|
+
expanded={expanded}
|
|
132
|
+
onExpandedChange={onExpandedChange}
|
|
133
|
+
expandMode={expandMode}
|
|
134
|
+
loading={loading}
|
|
135
|
+
empty={empty}
|
|
136
|
+
onRowClick={onRowClick}
|
|
137
|
+
hoverRow={hoverRow}
|
|
138
|
+
leaveRows={leaveRows}
|
|
139
|
+
/>
|
|
381
140
|
</table>
|
|
141
|
+
<GlidePill className="zc-tbl__glide" glide={glide} />
|
|
382
142
|
</div>
|
|
383
143
|
<div className="zc-tbl__edge zc-tbl__edge--l" aria-hidden="true"></div>
|
|
384
144
|
<div className="zc-tbl__edge zc-tbl__edge--r" aria-hidden="true"></div>
|
|
@@ -5,8 +5,15 @@ Docs: https://ui.zyncat.app/table
|
|
|
5
5
|
|
|
6
6
|
Declare columns + rows; owns sort, selection, stickiness, overflow.
|
|
7
7
|
|
|
8
|
-
columns: TableColumn<T>[] ({ key, label, render?, sortable?, sortBy?, align?, mono?, strong?, grow
|
|
9
|
-
}); selectable, defaultSort, footer.
|
|
8
|
+
columns: TableColumn<T>[] ({ key, label, render?, sortable?, sortBy?, align?, mono?, strong?, grow?,
|
|
9
|
+
width? }); selectable, defaultSort, footer. width: '30%' gives a column that share of the table, and a
|
|
10
|
+
grow column takes what the shares leave.
|
|
11
|
+
|
|
12
|
+
renderDetail(row) unfolds a full-width row under its row, from a trailing caret or a click on the
|
|
13
|
+
row; a null return leaves that row without one. expanded + onExpandedChange control which rows are
|
|
14
|
+
open, and expandMode="single" keeps one open at a time. A click on a link, button, field or label in
|
|
15
|
+
a cell stays with it, never toggling the row or firing onRowClick. Hover is one pill gliding
|
|
16
|
+
between rows.
|
|
10
17
|
|
|
11
18
|
```tsx
|
|
12
19
|
<Table<Invoice>
|
|
@@ -17,3 +24,13 @@ columns: TableColumn<T>[] ({ key, label, render?, sortable?, sortBy?, align?, mo
|
|
|
17
24
|
defaultSort={{ key: 'amount', dir: 'desc' }}
|
|
18
25
|
/>
|
|
19
26
|
```
|
|
27
|
+
|
|
28
|
+
```tsx
|
|
29
|
+
<Table<Member>
|
|
30
|
+
ariaLabel="Team"
|
|
31
|
+
columns={COLUMNS}
|
|
32
|
+
rows={members}
|
|
33
|
+
expandMode="single"
|
|
34
|
+
renderDetail={(member) => (canManage ? <MemberAccess {...member} /> : null)}
|
|
35
|
+
/>
|
|
36
|
+
```
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { Fragment, useId, type MouseEvent, type PointerEventHandler, type ReactNode } from 'react';
|
|
4
|
+
|
|
5
|
+
import { Motion } from '../../../motion/element';
|
|
6
|
+
import { Presence } from '../../../motion/presence';
|
|
7
|
+
import { UIMotion } from '../../../tokens/motion-tokens';
|
|
8
|
+
import { Checkbox } from '../../primitives/checkbox/Checkbox';
|
|
9
|
+
import { DetailRow, DetailToggle, rowNameId, useExpanded } from './detail';
|
|
10
|
+
import type { TableColumn, TableProps } from './types';
|
|
11
|
+
import type { Selection } from './use-table-state';
|
|
12
|
+
|
|
13
|
+
const ROW_MOTION = {
|
|
14
|
+
layout: true,
|
|
15
|
+
layoutTransition: { timing: UIMotion.t.layout },
|
|
16
|
+
animate: { opacity: [0, 1], y: [UIMotion.dist.sm, 0], timing: UIMotion.t.enter },
|
|
17
|
+
exit: { opacity: [0], y: [UIMotion.dist.sm], timing: UIMotion.t.exit },
|
|
18
|
+
};
|
|
19
|
+
const PRESS_OWNERS = 'a, button, input, select, textarea, label, tr';
|
|
20
|
+
|
|
21
|
+
type TableBodyProps<Row> = Pick<
|
|
22
|
+
TableProps<Row>,
|
|
23
|
+
'columns' | 'selectionLabel' | 'renderDetail' | 'expanded' | 'onExpandedChange' | 'empty' | 'onRowClick'
|
|
24
|
+
> &
|
|
25
|
+
Required<Pick<TableProps<Row>, 'selectable' | 'expandMode' | 'loading'>> & {
|
|
26
|
+
rows: Row[];
|
|
27
|
+
keyOf: (row: Row) => string | number;
|
|
28
|
+
mods: (col: TableColumn<Row>, i: number) => string[];
|
|
29
|
+
selection: Selection;
|
|
30
|
+
checkCellCls: string;
|
|
31
|
+
checkSize: 'sm' | 'md';
|
|
32
|
+
toggleSize: 'xs' | 'sm';
|
|
33
|
+
hoverRow: (row: Element | null) => void;
|
|
34
|
+
leaveRows: () => void;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export function TableBody<Row>({
|
|
38
|
+
rows,
|
|
39
|
+
keyOf,
|
|
40
|
+
columns,
|
|
41
|
+
mods,
|
|
42
|
+
selectable,
|
|
43
|
+
selection,
|
|
44
|
+
selectionLabel,
|
|
45
|
+
checkCellCls,
|
|
46
|
+
checkSize,
|
|
47
|
+
toggleSize,
|
|
48
|
+
renderDetail,
|
|
49
|
+
expanded,
|
|
50
|
+
onExpandedChange,
|
|
51
|
+
expandMode,
|
|
52
|
+
loading,
|
|
53
|
+
empty,
|
|
54
|
+
onRowClick,
|
|
55
|
+
hoverRow,
|
|
56
|
+
leaveRows,
|
|
57
|
+
}: TableBodyProps<Row>) {
|
|
58
|
+
const uid = useId();
|
|
59
|
+
const [openKeys, toggleDetail] = useExpanded(expanded, onExpandedChange, expandMode);
|
|
60
|
+
const colCount = columns.length + (selectable ? 1 : 0) + (renderDetail ? 1 : 0);
|
|
61
|
+
const showEmpty = !loading && rows.length === 0;
|
|
62
|
+
const enterRow: PointerEventHandler<HTMLElement> = (e) => hoverRow(e.currentTarget);
|
|
63
|
+
const enterDetail: PointerEventHandler<HTMLElement> = (e) => hoverRow(e.currentTarget.previousElementSibling);
|
|
64
|
+
|
|
65
|
+
function pressRow(e: MouseEvent<HTMLElement>, row: Row, detailKey: string | number | null) {
|
|
66
|
+
if (!(e.target instanceof Element) || e.target.closest(PRESS_OWNERS) !== e.currentTarget) return;
|
|
67
|
+
if (detailKey != null) toggleDetail(detailKey);
|
|
68
|
+
if (onRowClick) onRowClick(row);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return (
|
|
72
|
+
<tbody onPointerLeave={leaveRows}>
|
|
73
|
+
<Presence initial={false} mode={showEmpty ? 'wait' : 'sync'}>
|
|
74
|
+
{showEmpty && (
|
|
75
|
+
<Motion as="tr" key="empty" {...ROW_MOTION}>
|
|
76
|
+
<td colSpan={colCount} className="zc-tbl__emptyCell">
|
|
77
|
+
{empty != null ? empty : 'Nothing to show'}
|
|
78
|
+
</td>
|
|
79
|
+
</Motion>
|
|
80
|
+
)}
|
|
81
|
+
{rows.map((row, idx) => {
|
|
82
|
+
const k = keyOf(row);
|
|
83
|
+
const isSel = selection.selected.has(k);
|
|
84
|
+
const detail = renderDetail ? renderDetail(row) : null;
|
|
85
|
+
const open = openKeys.includes(k);
|
|
86
|
+
const id = `${uid}${idx}`;
|
|
87
|
+
return (
|
|
88
|
+
<Fragment key={k}>
|
|
89
|
+
<Motion
|
|
90
|
+
as="tr"
|
|
91
|
+
{...ROW_MOTION}
|
|
92
|
+
className="zc-tbl__row"
|
|
93
|
+
data-selected={isSel ? '' : undefined}
|
|
94
|
+
data-expandable={detail ? '' : undefined}
|
|
95
|
+
onClick={
|
|
96
|
+
onRowClick || detail ? (e: MouseEvent<HTMLElement>) => pressRow(e, row, detail ? k : null) : undefined
|
|
97
|
+
}
|
|
98
|
+
onPointerEnter={enterRow}
|
|
99
|
+
>
|
|
100
|
+
{selectable ? (
|
|
101
|
+
<td className={checkCellCls} onClick={(e) => e.stopPropagation()}>
|
|
102
|
+
<Checkbox
|
|
103
|
+
className="zc-tbl__cbx"
|
|
104
|
+
size={checkSize}
|
|
105
|
+
checked={isSel}
|
|
106
|
+
htmlProps={{
|
|
107
|
+
'aria-label': selectionLabel ? selectionLabel(row) : 'Select row',
|
|
108
|
+
onClick: (e) => {
|
|
109
|
+
selection.shiftRef.current = e.shiftKey;
|
|
110
|
+
},
|
|
111
|
+
}}
|
|
112
|
+
onChange={() => selection.toggleRow(idx)}
|
|
113
|
+
/>
|
|
114
|
+
</td>
|
|
115
|
+
) : null}
|
|
116
|
+
{columns.map((c, i) => (
|
|
117
|
+
<td
|
|
118
|
+
key={c.key}
|
|
119
|
+
id={detail && i === 0 ? rowNameId(id) : undefined}
|
|
120
|
+
className={mods(c, i)
|
|
121
|
+
.concat(c.mono ? ['zc-tbl__cell--mono'] : [])
|
|
122
|
+
.concat(c.strong ? ['zc-tbl__cell--strong'] : [])
|
|
123
|
+
.join(' ')}
|
|
124
|
+
>
|
|
125
|
+
{c.render ? c.render(row) : (row as Record<string, ReactNode>)[c.key]}
|
|
126
|
+
</td>
|
|
127
|
+
))}
|
|
128
|
+
{renderDetail ? (
|
|
129
|
+
<td className="zc-tbl__cell--toggle">
|
|
130
|
+
{detail ? (
|
|
131
|
+
<DetailToggle id={id} open={open} size={toggleSize} onToggle={() => toggleDetail(k)} />
|
|
132
|
+
) : null}
|
|
133
|
+
</td>
|
|
134
|
+
) : null}
|
|
135
|
+
</Motion>
|
|
136
|
+
{detail ? (
|
|
137
|
+
<DetailRow id={id} open={open} span={colCount} motion={ROW_MOTION} onPointerEnter={enterDetail}>
|
|
138
|
+
{detail}
|
|
139
|
+
</DetailRow>
|
|
140
|
+
) : null}
|
|
141
|
+
</Fragment>
|
|
142
|
+
);
|
|
143
|
+
})}
|
|
144
|
+
</Presence>
|
|
145
|
+
</tbody>
|
|
146
|
+
);
|
|
147
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import './table-detail.css';
|
|
4
|
+
|
|
5
|
+
import type { PointerEventHandler, ReactNode } from 'react';
|
|
6
|
+
|
|
7
|
+
import { Motion, type MotionProps } from '../../../motion/element';
|
|
8
|
+
import { useControllable } from '../../internal/hooks/use-controllable';
|
|
9
|
+
import { Icon } from '../../internal/icon/Icon';
|
|
10
|
+
import { Button, type ButtonSize } from '../../primitives/button/Button';
|
|
11
|
+
import { Collapse, type CollapseAnimation } from '../../primitives/collapse/Collapse';
|
|
12
|
+
|
|
13
|
+
type RowKey = string | number;
|
|
14
|
+
|
|
15
|
+
const NONE_OPEN: RowKey[] = [];
|
|
16
|
+
const DETAIL_MOTION: CollapseAnimation = { duration: { close: 'base' }, ease: { close: 'exit' } };
|
|
17
|
+
|
|
18
|
+
export const rowNameId = (id: string) => `${id}-n`;
|
|
19
|
+
|
|
20
|
+
export function useExpanded(
|
|
21
|
+
value: RowKey[] | undefined,
|
|
22
|
+
onChange: ((keys: RowKey[]) => void) | undefined,
|
|
23
|
+
mode: 'single' | 'multiple',
|
|
24
|
+
) {
|
|
25
|
+
const [open, setOpen] = useControllable(value, NONE_OPEN, onChange);
|
|
26
|
+
const toggle = (key: RowKey) =>
|
|
27
|
+
setOpen(open.includes(key) ? open.filter((k) => k !== key) : mode === 'single' ? [key] : [...open, key]);
|
|
28
|
+
return [open, toggle] as const;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
interface DetailToggleProps {
|
|
32
|
+
id: string;
|
|
33
|
+
open: boolean;
|
|
34
|
+
size: ButtonSize;
|
|
35
|
+
onToggle: () => void;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function DetailToggle({ id, open, size, onToggle }: DetailToggleProps) {
|
|
39
|
+
return (
|
|
40
|
+
<Button
|
|
41
|
+
variant="ghost"
|
|
42
|
+
size={size}
|
|
43
|
+
iconOnly
|
|
44
|
+
className="zc-tbl__toggle"
|
|
45
|
+
id={`${id}-t`}
|
|
46
|
+
aria-label="Details"
|
|
47
|
+
aria-labelledby={`${id}-t ${rowNameId(id)}`}
|
|
48
|
+
aria-expanded={open}
|
|
49
|
+
aria-controls={`${id}-d`}
|
|
50
|
+
onClick={onToggle}
|
|
51
|
+
>
|
|
52
|
+
<Icon name="caret-down" />
|
|
53
|
+
</Button>
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
interface DetailRowProps {
|
|
58
|
+
id: string;
|
|
59
|
+
open: boolean;
|
|
60
|
+
span: number;
|
|
61
|
+
motion: Pick<MotionProps, 'layout' | 'layoutTransition' | 'animate' | 'exit'>;
|
|
62
|
+
onPointerEnter: PointerEventHandler<HTMLElement>;
|
|
63
|
+
children: ReactNode;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function DetailRow({ id, open, span, motion, onPointerEnter, children }: DetailRowProps) {
|
|
67
|
+
return (
|
|
68
|
+
<Motion as="tr" {...motion} className="zc-tbl__detail" onPointerEnter={onPointerEnter}>
|
|
69
|
+
<td colSpan={span}>
|
|
70
|
+
<Collapse open={open} animation={DETAIL_MOTION} htmlProps={{ id: `${id}-d` }}>
|
|
71
|
+
<div className="zc-tbl__detailBody">{children}</div>
|
|
72
|
+
</Collapse>
|
|
73
|
+
</td>
|
|
74
|
+
</Motion>
|
|
75
|
+
);
|
|
76
|
+
}
|