@justanarthur/modo-ui 0.5.0 → 0.6.0-canary.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/DESIGN.md +608 -0
- package/README.md +61 -39
- package/blocks/sidebar-app/examples.mdx +33 -0
- package/blocks/sidebar-app/index.tsx +218 -0
- package/blocks/sidebar-app/inset-topbar.tsx +25 -0
- package/blocks/sidebar-app/menu-grid.ts +26 -0
- package/blocks/sidebar-app/nav-data.ts +36 -0
- package/blocks/sidebar-app/search-field.tsx +48 -0
- package/blocks/sidebar-app/user-footer.tsx +67 -0
- package/blocks/sidebar-app/workspace-header.tsx +129 -0
- package/components/AI/input-message/examples.mdx +124 -0
- package/components/AI/input-message/file-thumbnail.tsx +173 -0
- package/components/AI/input-message/index.tsx +1383 -0
- package/components/AI/thinking-indicator/examples.mdx +27 -0
- package/components/AI/thinking-indicator/index.tsx +210 -0
- package/components/accordion/examples.mdx +148 -0
- package/components/accordion/index.tsx +1034 -0
- package/components/avatar/examples.mdx +95 -0
- package/components/avatar/index.tsx +129 -0
- package/components/badge/change-demo.tsx +29 -0
- package/components/badge/examples.mdx +120 -0
- package/components/badge/index.tsx +225 -0
- package/components/badge/variants.ts +73 -0
- package/components/button/examples.mdx +164 -0
- package/components/button/index.tsx +416 -0
- package/components/button/loading-demo.tsx +25 -0
- package/components/button/variants.ts +166 -0
- package/components/card/examples.mdx +212 -0
- package/components/card/index.tsx +1037 -0
- package/components/copy/examples.mdx +87 -0
- package/components/copy/index.tsx +482 -0
- package/components/inputs/checkbox/examples.mdx +83 -0
- package/components/inputs/checkbox/index.tsx +611 -0
- package/components/inputs/checkbox/select-all-demo.tsx +48 -0
- package/components/inputs/color-picker/examples.mdx +72 -0
- package/components/inputs/color-picker/index.tsx +1955 -0
- package/components/inputs/color-picker/variants.ts +401 -0
- package/components/inputs/combobox/examples.mdx +273 -0
- package/components/inputs/combobox/index.tsx +1436 -0
- package/components/inputs/combobox/remote-demo.tsx +101 -0
- package/components/inputs/date-time/calendar/examples.mdx +34 -0
- package/components/inputs/date-time/calendar/index.tsx +351 -0
- package/components/inputs/date-time/calendar/use-month-window.ts +163 -0
- package/components/inputs/date-time/date-picker/examples.mdx +166 -0
- package/components/inputs/date-time/date-picker/index.tsx +385 -0
- package/components/inputs/date-time/date-picker/masked-date-input.tsx +336 -0
- package/components/inputs/date-time/date-range-picker/examples.mdx +29 -0
- package/components/inputs/date-time/date-range-picker/index.tsx +217 -0
- package/components/inputs/date-time/duration-picker/examples.mdx +16 -0
- package/components/inputs/date-time/duration-picker/index.tsx +189 -0
- package/components/inputs/date-time/month-picker/examples.mdx +16 -0
- package/components/inputs/date-time/month-picker/index.tsx +190 -0
- package/components/inputs/date-time/picker-shell.tsx +395 -0
- package/components/inputs/date-time/time-columns.tsx +91 -0
- package/components/inputs/date-time/time-picker/examples.mdx +26 -0
- package/components/inputs/date-time/time-picker/index.tsx +166 -0
- package/components/inputs/field/examples.mdx +113 -0
- package/components/inputs/field/index.tsx +267 -0
- package/components/inputs/file-dropzone/examples.mdx +73 -0
- package/components/inputs/file-dropzone/file-row.tsx +201 -0
- package/components/inputs/file-dropzone/index.tsx +296 -0
- package/components/inputs/file-dropzone/upload-demo.tsx +67 -0
- package/components/inputs/file-dropzone/variants.ts +94 -0
- package/components/inputs/input/examples.mdx +135 -0
- package/components/inputs/input/index.tsx +494 -0
- package/components/inputs/input/password-demo.tsx +30 -0
- package/components/inputs/label/examples.mdx +67 -0
- package/components/inputs/label/index.tsx +85 -0
- package/components/inputs/number-input/examples.mdx +56 -0
- package/components/inputs/number-input/index.tsx +214 -0
- package/components/inputs/radio/examples.mdx +77 -0
- package/components/inputs/radio/index.tsx +636 -0
- package/components/inputs/search/examples.mdx +74 -0
- package/components/inputs/search/index.tsx +333 -0
- package/components/inputs/select/examples.mdx +218 -0
- package/components/inputs/select/index.tsx +862 -0
- package/components/inputs/select/variants.ts +32 -0
- package/components/inputs/slider/examples.mdx +127 -0
- package/components/inputs/slider/index.tsx +1725 -0
- package/components/inputs/switch/examples.mdx +94 -0
- package/components/inputs/switch/index.tsx +504 -0
- package/components/inputs/textarea/examples.mdx +88 -0
- package/components/inputs/textarea/index.tsx +161 -0
- package/components/navigation/navigation-menu/examples.mdx +109 -0
- package/components/navigation/navigation-menu/index.tsx +613 -0
- package/components/navigation/pagination/examples.mdx +64 -0
- package/components/navigation/pagination/index.tsx +395 -0
- package/components/navigation/sidebar/examples.mdx +319 -0
- package/components/navigation/sidebar/index.tsx +453 -0
- package/components/navigation/sidebar/sidebar-core.tsx +1408 -0
- package/components/navigation/sidebar/sidebar-menu.tsx +1495 -0
- package/components/navigation/sidebar/sidebar.css +74 -0
- package/components/navigation/sidebar/variants.ts +55 -0
- package/components/navigation/tabs/examples.mdx +89 -0
- package/components/navigation/tabs/index.tsx +494 -0
- package/components/navigation/tabs-subtle/examples.mdx +49 -0
- package/components/navigation/tabs-subtle/index.tsx +512 -0
- package/components/overlays/alert-dialog/examples.mdx +123 -0
- package/components/overlays/alert-dialog/index.tsx +258 -0
- package/components/overlays/alert-dialog/pending-demo.tsx +36 -0
- package/components/overlays/command/examples.mdx +113 -0
- package/components/overlays/command/index.tsx +416 -0
- package/components/overlays/context-menu/examples.mdx +56 -0
- package/components/overlays/context-menu/index.tsx +279 -0
- package/components/overlays/dialog/examples.mdx +144 -0
- package/components/overlays/dialog/index.tsx +366 -0
- package/components/overlays/dropdown/dropdown-search.tsx +395 -0
- package/components/overlays/dropdown/examples.mdx +294 -0
- package/components/overlays/dropdown/index.tsx +1168 -0
- package/components/overlays/dropdown/menu-item.tsx +464 -0
- package/components/overlays/dropdown/menu-parts.tsx +660 -0
- package/components/overlays/popover/anchored-demo.tsx +59 -0
- package/components/overlays/popover/examples.mdx +180 -0
- package/components/overlays/popover/index.tsx +315 -0
- package/components/overlays/preview-card/examples.mdx +61 -0
- package/components/overlays/preview-card/index.tsx +204 -0
- package/components/overlays/sheet/examples.mdx +89 -0
- package/components/overlays/sheet/index.tsx +247 -0
- package/components/overlays/toast/examples.mdx +68 -0
- package/components/overlays/toast/global-demo.tsx +72 -0
- package/components/overlays/toast/index.tsx +474 -0
- package/components/overlays/toast/manager.ts +193 -0
- package/components/overlays/tooltip/examples.mdx +106 -0
- package/components/overlays/tooltip/index.tsx +519 -0
- package/components/progress/examples.mdx +59 -0
- package/components/progress/index.tsx +174 -0
- package/components/progress/progress.css +49 -0
- package/components/progress/step-demo.tsx +27 -0
- package/components/table/examples.mdx +184 -0
- package/components/table/index.tsx +510 -0
- package/components/table/sort-demo.tsx +61 -0
- package/dist/base.css +100 -0
- package/dist/blocks/sidebar-app/index.js +39 -26
- package/dist/components/AI/input-message/index.js +22 -16
- package/dist/components/AI/thinking-indicator/index.js +9 -6
- package/dist/components/accordion/index.js +16 -13
- package/dist/components/avatar/index.d.ts +46 -0
- package/dist/components/avatar/index.js +18 -0
- package/dist/components/badge/index.d.ts +18 -11
- package/dist/components/badge/index.js +11 -7
- package/dist/components/badge/variants.d.ts +33 -0
- package/dist/components/badge/variants.js +10 -0
- package/dist/components/button/index.d.ts +53 -17
- package/dist/components/button/index.js +10 -6
- package/dist/components/button/variants.d.ts +39 -0
- package/dist/components/button/variants.js +8 -0
- package/dist/components/card/index.d.ts +16 -3
- package/dist/components/card/index.js +16 -11
- package/dist/components/copy/index.js +13 -9
- package/dist/components/inputs/checkbox/index.d.ts +28 -9
- package/dist/components/inputs/checkbox/index.js +17 -13
- package/dist/components/inputs/color-picker/index.d.ts +13 -13
- package/dist/components/inputs/color-picker/index.js +25 -18
- package/dist/components/inputs/color-picker/variants.d.ts +61 -0
- package/dist/components/inputs/color-picker/variants.js +28 -0
- package/dist/components/inputs/combobox/index.d.ts +60 -17
- package/dist/components/inputs/combobox/index.js +26 -18
- package/dist/components/inputs/date-time/calendar/index.js +14 -11
- package/dist/components/inputs/date-time/date-picker/index.d.ts +53 -11
- package/dist/components/inputs/date-time/date-picker/index.js +33 -25
- package/dist/components/inputs/date-time/date-range-picker/index.d.ts +3 -3
- package/dist/components/inputs/date-time/date-range-picker/index.js +32 -24
- package/dist/components/inputs/date-time/duration-picker/index.d.ts +3 -3
- package/dist/components/inputs/date-time/duration-picker/index.js +32 -24
- package/dist/components/inputs/date-time/month-picker/index.d.ts +3 -3
- package/dist/components/inputs/date-time/month-picker/index.js +31 -23
- package/dist/components/inputs/date-time/time-picker/index.d.ts +3 -3
- package/dist/components/inputs/date-time/time-picker/index.js +32 -24
- package/dist/components/inputs/field/index.d.ts +116 -0
- package/dist/components/inputs/field/index.js +28 -0
- package/dist/components/inputs/file-dropzone/index.d.ts +165 -0
- package/dist/components/inputs/file-dropzone/index.js +32 -0
- package/dist/components/inputs/file-dropzone/variants.d.ts +35 -0
- package/dist/components/inputs/file-dropzone/variants.js +12 -0
- package/dist/components/inputs/input/index.d.ts +95 -13
- package/dist/components/inputs/input/index.js +17 -9
- package/dist/components/inputs/label/index.d.ts +32 -0
- package/dist/components/inputs/label/index.js +11 -0
- package/dist/components/inputs/number-input/index.d.ts +84 -0
- package/dist/components/inputs/number-input/index.js +20 -0
- package/dist/components/inputs/radio/index.d.ts +20 -5
- package/dist/components/inputs/radio/index.js +15 -12
- package/dist/components/inputs/search/index.js +25 -18
- package/dist/components/inputs/select/index.d.ts +41 -11
- package/dist/components/inputs/select/index.js +27 -14
- package/dist/components/inputs/select/variants.d.ts +5 -0
- package/dist/components/inputs/select/variants.js +6 -0
- package/dist/components/inputs/slider/index.js +7 -5
- package/dist/components/inputs/switch/index.d.ts +8 -2
- package/dist/components/inputs/switch/index.js +14 -12
- package/dist/components/inputs/textarea/index.d.ts +4 -0
- package/dist/components/inputs/textarea/index.js +8 -6
- package/dist/components/navigation/navigation-menu/index.d.ts +114 -0
- package/dist/components/navigation/navigation-menu/index.js +40 -0
- package/dist/components/navigation/pagination/index.d.ts +73 -0
- package/dist/components/navigation/pagination/index.js +39 -0
- package/dist/components/navigation/sidebar/index.d.ts +44 -21
- package/dist/components/navigation/sidebar/index.js +41 -31
- package/dist/components/navigation/sidebar/variants.d.ts +25 -0
- package/dist/components/navigation/sidebar/variants.js +28 -0
- package/dist/components/navigation/tabs/index.d.ts +8 -2
- package/dist/components/navigation/tabs/index.js +14 -10
- package/dist/components/navigation/tabs-subtle/index.js +12 -10
- package/dist/components/overlays/alert-dialog/index.d.ts +121 -15
- package/dist/components/overlays/alert-dialog/index.js +22 -13
- package/dist/components/overlays/command/index.js +24 -17
- package/dist/components/overlays/context-menu/index.d.ts +33 -17
- package/dist/components/overlays/context-menu/index.js +27 -18
- package/dist/components/overlays/dialog/index.js +17 -12
- package/dist/components/overlays/dropdown/index.d.ts +257 -31
- package/dist/components/overlays/dropdown/index.js +42 -17
- package/dist/components/overlays/popover/index.d.ts +31 -9
- package/dist/components/overlays/popover/index.js +12 -9
- package/dist/components/overlays/preview-card/index.js +11 -8
- package/dist/components/overlays/sheet/index.js +18 -13
- package/dist/components/overlays/toast/index.d.ts +123 -47
- package/dist/components/overlays/toast/index.js +18 -10
- package/dist/components/overlays/tooltip/index.d.ts +113 -21
- package/dist/components/overlays/tooltip/index.js +15 -6
- package/dist/components/progress/index.d.ts +56 -0
- package/dist/components/progress/index.js +15 -0
- package/dist/components/table/index.d.ts +63 -8
- package/dist/components/table/index.js +19 -9
- package/dist/index.d.ts +2201 -736
- package/dist/index.js +223 -82
- package/dist/lib/date-locale.d.ts +14 -0
- package/dist/lib/date-locale.js +16 -0
- package/dist/lib/field-classes.d.ts +144 -0
- package/dist/lib/field-classes.js +40 -0
- package/dist/lib/field-variants.d.ts +47 -0
- package/dist/lib/field-variants.js +26 -0
- package/dist/lib/fluid-hover-highlight.d.ts +112 -0
- package/dist/lib/fluid-hover-highlight.js +17 -0
- package/dist/lib/focus-ring.d.ts +18 -0
- package/dist/lib/focus-ring.js +10 -0
- package/dist/lib/goo-indicator.d.ts +46 -0
- package/dist/lib/goo-indicator.js +14 -0
- package/dist/lib/icon-context.d.ts +30 -0
- package/dist/lib/icon-context.js +12 -0
- package/dist/lib/inert.d.ts +9 -0
- package/dist/lib/inert.js +8 -0
- package/dist/lib/morph-layers.d.ts +93 -0
- package/dist/lib/morph-layers.js +13 -0
- package/dist/lib/morph-part.d.ts +21 -0
- package/dist/lib/morph-part.js +12 -0
- package/dist/lib/popup.d.ts +20 -0
- package/dist/lib/popup.js +12 -0
- package/dist/lib/reduced-motion.d.ts +9 -0
- package/dist/lib/reduced-motion.js +6 -0
- package/dist/lib/row-index.d.ts +10 -0
- package/dist/lib/row-index.js +8 -0
- package/dist/lib/row-order.d.ts +28 -0
- package/dist/lib/row-order.js +10 -0
- package/dist/lib/scroll-column.d.ts +27 -0
- package/dist/lib/scroll-column.js +18 -0
- package/dist/lib/shape-context.d.ts +30 -0
- package/dist/lib/shape-context.js +12 -0
- package/dist/lib/size-context.d.ts +94 -0
- package/dist/lib/size-context.js +20 -0
- package/dist/lib/size-scale.d.ts +79 -0
- package/dist/lib/size-scale.js +8 -0
- package/dist/lib/slot.d.ts +12 -0
- package/dist/lib/slot.js +6 -0
- package/dist/lib/springs.d.ts +44 -0
- package/dist/lib/springs.js +8 -0
- package/dist/lib/surface-classes.d.ts +19 -0
- package/dist/lib/surface-classes.js +10 -0
- package/dist/lib/surface-context.d.ts +9 -0
- package/dist/lib/surface-context.js +8 -0
- package/dist/lib/use-controllable-state.d.ts +2 -0
- package/dist/lib/use-controllable-state.js +6 -0
- package/dist/lib/use-fluid-hover.d.ts +138 -0
- package/dist/lib/use-fluid-hover.js +14 -0
- package/dist/lib/use-is-mobile.d.ts +2 -0
- package/dist/lib/use-is-mobile.js +6 -0
- package/dist/lib/use-keyboard-nav-gate.d.ts +20 -0
- package/dist/lib/use-keyboard-nav-gate.js +7 -0
- package/dist/lib/use-merge-split.d.ts +47 -0
- package/dist/lib/use-merge-split.js +15 -0
- package/dist/lib/use-morph.d.ts +101 -0
- package/dist/lib/use-morph.js +20 -0
- package/dist/lib/use-touch-primary.d.ts +2 -0
- package/dist/lib/use-touch-primary.js +6 -0
- package/dist/lib/utils.d.ts +3 -0
- package/dist/lib/utils.js +6 -0
- package/dist/preset.d.ts +17 -0
- package/dist/preset.js +22 -2
- package/dist/primitives/code/index.js +7 -5
- package/dist/primitives/craft/index.js +9 -6
- package/dist/primitives/fluid-hover/index.js +9 -8
- package/dist/primitives/morph/index.js +15 -10
- package/dist/primitives/motion/index.js +10 -8
- package/dist/primitives/scroll-area/index.js +4 -3
- package/dist/primitives/separator/index.d.ts +25 -0
- package/dist/primitives/separator/index.js +9 -0
- package/dist/primitives/sizes/index.js +6 -4
- package/dist/primitives/skeleton/index.d.ts +35 -0
- package/dist/primitives/skeleton/index.js +12 -0
- package/dist/primitives/surface/index.js +6 -4
- package/dist/shared/{components-3mkepka5.js → components-0jmqhx2k.js} +28 -25
- package/dist/shared/components-124epb7f.js +53 -0
- package/dist/shared/{components-gz8zf3ec.js → components-1k0wv53d.js} +15 -43
- package/dist/shared/components-26snnbs9.js +322 -0
- package/dist/shared/{components-2dxkv6zm.js → components-2c0qcfx4.js} +8 -7
- package/dist/shared/{components-473g814w.js → components-2mt9te6d.js} +243 -137
- package/dist/shared/{components-hawvy2qz.js → components-2z48g4fp.js} +9 -30
- package/dist/shared/components-34txk9rj.js +35 -0
- package/dist/shared/components-3h92d94m.js +23 -0
- package/dist/shared/{components-zfnmn5d4.js → components-3sp623ae.js} +36 -31
- package/dist/shared/{components-jwst3vtj.js → components-3wxkjgqn.js} +186 -76
- package/dist/shared/{components-s2bz1xpk.js → components-49bsynbw.js} +8 -5
- package/dist/shared/components-4bwsd46w.js +71 -0
- package/dist/shared/components-4n4f5m3e.js +297 -0
- package/dist/shared/{components-0q0sqfh4.js → components-4y816hwp.js} +27 -49
- package/dist/shared/components-52ngsgca.js +399 -0
- package/dist/shared/{components-y9y0g8er.js → components-52r5763g.js} +22 -19
- package/dist/shared/components-559tf7yb.js +28 -0
- package/dist/shared/components-5mkga9hj.js +440 -0
- package/dist/shared/{components-kwa6mrf9.js → components-5s0nfqvw.js} +14 -9
- package/dist/shared/{components-dk0gjr5a.js → components-60atskhp.js} +19 -18
- package/dist/shared/{components-rr7a6ja9.js → components-658b26nb.js} +21 -18
- package/dist/shared/{components-xxvdw7k1.js → components-65vwfjs6.js} +37 -34
- package/dist/shared/{components-frw34b65.js → components-6j2fh74k.js} +114 -123
- package/dist/shared/components-6zg1yft7.js +167 -0
- package/dist/shared/components-6zng858q.js +53 -0
- package/dist/shared/components-72w4ge68.js +64 -0
- package/dist/shared/{components-cv16mryv.js → components-78x40gee.js} +13 -7
- package/dist/shared/{components-b2wyq2cq.js → components-7d4r7hh1.js} +39 -57
- package/dist/shared/components-7ntvvegr.js +316 -0
- package/dist/shared/components-8nwsqjn8.js +34 -0
- package/dist/shared/{components-5xc2j8jz.js → components-8tt3xbb5.js} +19 -18
- package/dist/shared/{components-vc7vq5nz.js → components-9as3rf68.js} +6 -3
- package/dist/shared/components-9mys9jna.js +255 -0
- package/dist/shared/components-adkarj8n.js +35 -0
- package/dist/shared/{components-b3c5et5b.js → components-ae9fncz4.js} +32 -31
- package/dist/shared/{components-hqeq3w9q.js → components-awra5sff.js} +24 -16
- package/dist/shared/components-b1e239g3.js +28 -0
- package/dist/shared/{components-q5xj5c16.js → components-b1f2bjf1.js} +9 -8
- package/dist/shared/{components-qmmjx1qw.js → components-bn42vq6d.js} +71 -72
- package/dist/shared/components-c96g82th.js +1444 -0
- package/dist/shared/components-c9yr4ed1.js +44 -0
- package/dist/shared/components-d3shbwqq.js +95 -0
- package/dist/shared/{components-jjw69c4c.js → components-dcc02hs2.js} +7 -4
- package/dist/shared/{components-men63rwj.js → components-de99ykt7.js} +3 -2
- package/dist/shared/components-dhgk6mbt.js +16 -0
- package/dist/shared/components-drxrtnp2.js +25 -0
- package/dist/shared/{components-6p8tfcd6.js → components-ds9fqat9.js} +21 -18
- package/dist/shared/{components-mjthm1kf.js → components-egy4tyjt.js} +11 -8
- package/dist/shared/components-f0xfpkhh.js +82 -0
- package/dist/shared/components-f7h57m6t.js +59 -0
- package/dist/shared/{components-d6xtjht3.js → components-fjkpbg6n.js} +33 -30
- package/dist/shared/{components-gc5vtq2f.js → components-gh0qeey3.js} +63 -29
- package/dist/shared/{components-39jq9va1.js → components-gvbapfen.js} +29 -24
- package/dist/shared/{components-5vgpnxgy.js → components-gzesg7hy.js} +19 -16
- package/dist/shared/components-h6p86be3.js +19 -0
- package/dist/shared/components-h83az0bz.js +33 -0
- package/dist/shared/components-jjrj6ymn.js +104 -0
- package/dist/shared/{components-wvp1m52g.js → components-jp5v0m0f.js} +15 -14
- package/dist/shared/{components-zrkzcayz.js → components-jqpefjsn.js} +54 -6
- package/dist/shared/{components-1z6tdadk.js → components-k74j4hwh.js} +20 -17
- package/dist/shared/components-kswxnm3h.js +24 -0
- package/dist/shared/{components-jbbmdr74.js → components-mkkbbgb7.js} +36 -17
- package/dist/shared/{components-pbmqctfa.js → components-mpw667rb.js} +169 -65
- package/dist/shared/{components-s5ngg32c.js → components-paa08427.js} +121 -47
- package/dist/shared/{components-vfbhxf5r.js → components-pd42emw3.js} +6 -5
- package/dist/shared/{components-hw9yk32z.js → components-pmfszv7a.js} +35 -23
- package/dist/shared/{components-chacnk61.js → components-pw06rbxq.js} +19 -19
- package/dist/shared/components-q03cktx8.js +246 -0
- package/dist/shared/{components-kvr7f9hy.js → components-qdm3yh26.js} +19 -10
- package/dist/shared/{components-27nnvrwe.js → components-qs4rkqsj.js} +15 -14
- package/dist/shared/{components-s083f38z.js → components-r6gbmkew.js} +22 -21
- package/dist/shared/{components-ta7shw28.js → components-r8eqs7gz.js} +4 -4
- package/dist/shared/{components-sn1rxx1d.js → components-rm02h9nt.js} +12 -11
- package/dist/shared/{components-c6s6b43g.js → components-rrbpmfx4.js} +3 -2
- package/dist/shared/{components-n7mjr357.js → components-tz1fv35x.js} +3 -2
- package/dist/shared/components-tz4gaf1v.js +23 -0
- package/dist/shared/{components-zx6b6yby.js → components-vf45j12c.js} +4 -18
- package/dist/shared/{components-3ky44908.js → components-vfjc9jzz.js} +2 -3
- package/dist/shared/{components-39vmfq9s.js → components-vsa625vk.js} +21 -20
- package/dist/shared/components-wawnmkph.js +500 -0
- package/dist/shared/components-wktrrb4m.js +38 -0
- package/dist/shared/{components-8snj490h.js → components-wwd363me.js} +78 -32
- package/dist/shared/{components-5pnw8183.js → components-xcwvgcrd.js} +23 -22
- package/dist/shared/components-xdqmt6ed.js +20 -0
- package/dist/shared/{components-h2ajmhwn.js → components-y1w3a6wx.js} +107 -35
- package/dist/shared/{components-ar66gnt0.js → components-y6578b8h.js} +37 -34
- package/dist/shared/{components-59efxjd9.js → components-yhgq0qxx.js} +13 -12
- package/dist/shared/{components-jthe1pwb.js → components-yz84gpkq.js} +101 -404
- package/dist/shared/components-z3v0n0de.js +11 -0
- package/dist/shared/{components-7r3etddy.js → components-z9n19fyk.js} +19 -54
- package/dist/shared/components-zbvjzh1p.js +141 -0
- package/dist/styles.css +241 -16
- package/dist/tailwind.css +13 -0
- package/dist/tokens.css +34 -0
- package/index.ts +60 -0
- package/lib/date-locale.ts +50 -0
- package/lib/field-classes.ts +115 -0
- package/lib/field-variants.ts +117 -0
- package/lib/fluid-hover-highlight.tsx +139 -0
- package/lib/focus-ring.tsx +46 -0
- package/lib/goo-indicator.tsx +261 -0
- package/lib/icon-context.tsx +310 -0
- package/lib/inert.ts +22 -0
- package/lib/morph-layers.tsx +102 -0
- package/lib/morph-part.tsx +49 -0
- package/lib/popup.ts +52 -0
- package/lib/reduced-motion.ts +19 -0
- package/lib/row-index.tsx +29 -0
- package/lib/row-order.tsx +115 -0
- package/lib/scroll-column.tsx +244 -0
- package/lib/shape-context.tsx +124 -0
- package/lib/size-context.tsx +66 -0
- package/lib/size-scale.ts +115 -0
- package/lib/slot.ts +25 -0
- package/lib/springs.ts +62 -0
- package/lib/surface-classes.ts +58 -0
- package/lib/surface-context.tsx +21 -0
- package/lib/use-controllable-state.ts +44 -0
- package/lib/use-fluid-hover.ts +541 -0
- package/lib/use-is-mobile.ts +25 -0
- package/lib/use-keyboard-nav-gate.ts +45 -0
- package/lib/use-merge-split.tsx +209 -0
- package/lib/use-morph.ts +557 -0
- package/lib/use-touch-primary.tsx +43 -0
- package/lib/utils.ts +37 -0
- package/package.json +177 -4
- package/preset.ts +196 -0
- package/primitives/code/examples.mdx +27 -0
- package/primitives/code/index.tsx +80 -0
- package/primitives/craft/demos.tsx +173 -0
- package/primitives/craft/examples.mdx +138 -0
- package/primitives/craft/index.tsx +76 -0
- package/primitives/fluid-hover/examples.mdx +84 -0
- package/primitives/fluid-hover/index.tsx +316 -0
- package/primitives/morph/examples.mdx +135 -0
- package/primitives/morph/index.tsx +192 -0
- package/primitives/motion/examples.mdx +100 -0
- package/primitives/motion/index.tsx +160 -0
- package/primitives/scroll-area/examples.mdx +58 -0
- package/primitives/scroll-area/index.tsx +200 -0
- package/primitives/separator/examples.mdx +30 -0
- package/primitives/separator/index.tsx +53 -0
- package/primitives/sizes/examples.mdx +167 -0
- package/primitives/sizes/index.tsx +89 -0
- package/primitives/skeleton/examples.mdx +51 -0
- package/primitives/skeleton/index.tsx +72 -0
- package/primitives/skeleton/skeleton.css +15 -0
- package/primitives/surface/examples.mdx +173 -0
- package/primitives/surface/index.tsx +109 -0
- package/primitives/surface/surface.css +176 -0
- package/dist/shared/components-0sn7ypjw.js +0 -61
- package/dist/shared/components-1434p1mh.js +0 -123
- package/dist/shared/components-a86dytt0.js +0 -986
- package/dist/shared/components-gf5s6ap9.js +0 -42
- package/dist/shared/components-hyq23phv.js +0 -310
- package/dist/shared/components-ng72k97e.js +0 -128
- package/dist/shared/components-raknhppb.js +0 -64
- package/dist/shared/components-vynjtrk6.js +0 -19
- package/dist/shared/components-wy9jpqny.js +0 -146
- /package/dist/shared/{components-1v7rxytx.js → components-3ey0hzpb.js} +0 -0
- /package/dist/shared/{components-ezxhrmer.js → components-jcnjay5g.js} +0 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Local addition (not part of Fluid Functionalism): the docs stage of the
|
|
3
|
+
* Combobox page's remote example. A fake server answers each query after a
|
|
4
|
+
* beat, a page at a time, so the example stays hook-free.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { useEffect, useState } from 'react'
|
|
8
|
+
import Button from '../../button'
|
|
9
|
+
import Combobox from './index'
|
|
10
|
+
|
|
11
|
+
const CITIES = [
|
|
12
|
+
'Amsterdam',
|
|
13
|
+
'Athens',
|
|
14
|
+
'Barcelona',
|
|
15
|
+
'Berlin',
|
|
16
|
+
'Bratislava',
|
|
17
|
+
'Brussels',
|
|
18
|
+
'Bucharest',
|
|
19
|
+
'Budapest',
|
|
20
|
+
'Copenhagen',
|
|
21
|
+
'Dublin',
|
|
22
|
+
'Helsinki',
|
|
23
|
+
'Kyiv',
|
|
24
|
+
'Lisbon',
|
|
25
|
+
'Ljubljana',
|
|
26
|
+
'London',
|
|
27
|
+
'Madrid',
|
|
28
|
+
'Oslo',
|
|
29
|
+
'Paris',
|
|
30
|
+
'Prague',
|
|
31
|
+
'Riga',
|
|
32
|
+
'Rome',
|
|
33
|
+
'Sofia',
|
|
34
|
+
'Stockholm',
|
|
35
|
+
'Tallinn',
|
|
36
|
+
'Vienna',
|
|
37
|
+
'Vilnius',
|
|
38
|
+
'Warsaw',
|
|
39
|
+
'Zagreb',
|
|
40
|
+
]
|
|
41
|
+
|
|
42
|
+
const PAGE = 6
|
|
43
|
+
|
|
44
|
+
interface RemoteDemoProps {
|
|
45
|
+
/** How long the fake server takes, in ms. Defaults to `600`. */
|
|
46
|
+
latency?: number
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export default function RemoteDemo({ latency = 600 }: RemoteDemoProps) {
|
|
50
|
+
const [query, setQuery] = useState('')
|
|
51
|
+
const [limit, setLimit] = useState(PAGE)
|
|
52
|
+
const [items, setItems] = useState<string[]>([])
|
|
53
|
+
const [total, setTotal] = useState(0)
|
|
54
|
+
const [loading, setLoading] = useState(true)
|
|
55
|
+
|
|
56
|
+
useEffect(() => {
|
|
57
|
+
setLoading(true)
|
|
58
|
+
const timer = setTimeout(() => {
|
|
59
|
+
const matches = CITIES.filter(city => city.toLowerCase().includes(query.trim().toLowerCase()))
|
|
60
|
+
setItems(matches.slice(0, limit))
|
|
61
|
+
setTotal(matches.length)
|
|
62
|
+
setLoading(false)
|
|
63
|
+
}, latency)
|
|
64
|
+
return () => clearTimeout(timer)
|
|
65
|
+
}, [query, limit, latency])
|
|
66
|
+
|
|
67
|
+
return (
|
|
68
|
+
<div className="w-72 max-w-full">
|
|
69
|
+
<Combobox
|
|
70
|
+
items={items}
|
|
71
|
+
filter={null}
|
|
72
|
+
loading={loading}
|
|
73
|
+
inputValue={query}
|
|
74
|
+
onInputValueChange={next => {
|
|
75
|
+
setQuery(next)
|
|
76
|
+
setLimit(PAGE)
|
|
77
|
+
}}
|
|
78
|
+
>
|
|
79
|
+
<Combobox.Input placeholder="Search a city…" />
|
|
80
|
+
<Combobox.Content
|
|
81
|
+
footer={
|
|
82
|
+
items.length < total ? (
|
|
83
|
+
<Button variant="ghost" size="compact" className="w-full" onClick={() => setLimit(limit + PAGE)}>
|
|
84
|
+
Load more ({total - items.length})
|
|
85
|
+
</Button>
|
|
86
|
+
) : undefined
|
|
87
|
+
}
|
|
88
|
+
>
|
|
89
|
+
<Combobox.Empty>No city matches.</Combobox.Empty>
|
|
90
|
+
<Combobox.List>
|
|
91
|
+
{item => (
|
|
92
|
+
<Combobox.Item key={String(item)} value={String(item)}>
|
|
93
|
+
{String(item)}
|
|
94
|
+
</Combobox.Item>
|
|
95
|
+
)}
|
|
96
|
+
</Combobox.List>
|
|
97
|
+
</Combobox.Content>
|
|
98
|
+
</Combobox>
|
|
99
|
+
</div>
|
|
100
|
+
)
|
|
101
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import Calendar from './index'
|
|
2
|
+
import { de } from 'react-day-picker/locale'
|
|
3
|
+
|
|
4
|
+
# Single day
|
|
5
|
+
|
|
6
|
+
Scroll through the months, or jump with the month and year columns.
|
|
7
|
+
|
|
8
|
+
<Calendar mode="single" selected={new Date(2026, 9, 9)} />
|
|
9
|
+
|
|
10
|
+
# Range
|
|
11
|
+
|
|
12
|
+
`mode="range"` picks a span of days.
|
|
13
|
+
|
|
14
|
+
<Calendar mode="range" selected={{ from: new Date(2026, 9, 9), to: new Date(2026, 9, 15) }} />
|
|
15
|
+
|
|
16
|
+
# German
|
|
17
|
+
|
|
18
|
+
A react-day-picker locale names the months and weekdays and starts the week on its first day.
|
|
19
|
+
|
|
20
|
+
<Calendar mode="single" locale={de} selected={new Date(2026, 9, 9)} />
|
|
21
|
+
|
|
22
|
+
# Columns first
|
|
23
|
+
|
|
24
|
+
`columnsSide="start"` stands the year and month columns before the days.
|
|
25
|
+
|
|
26
|
+
<Calendar mode="single" columnsSide="start" selected={new Date(2026, 9, 9)} />
|
|
27
|
+
|
|
28
|
+
# Narrow
|
|
29
|
+
|
|
30
|
+
Without room for the columns, they turn into strips above the days.
|
|
31
|
+
|
|
32
|
+
<div className="w-72 max-w-full">
|
|
33
|
+
<Calendar mode="single" selected={new Date(2026, 9, 9)} />
|
|
34
|
+
</div>
|
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Local addition (not part of Fluid Functionalism): a scrolling calendar on
|
|
3
|
+
* react-day-picker (daypicker.dev), styled through its `classNames` and
|
|
4
|
+
* custom components with DS utilities (its stylesheet isn't loaded). Props
|
|
5
|
+
* pass through to DayPicker, the way shadcn's Calendar does.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
addDays,
|
|
10
|
+
addYears,
|
|
11
|
+
endOfYear,
|
|
12
|
+
format,
|
|
13
|
+
isSameYear,
|
|
14
|
+
type Locale,
|
|
15
|
+
startOfMonth,
|
|
16
|
+
startOfWeek,
|
|
17
|
+
startOfYear,
|
|
18
|
+
} from 'date-fns'
|
|
19
|
+
import { type ReactNode, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react'
|
|
20
|
+
import { type DayButtonProps, DayPicker, type DayPickerProps, type DayProps, type MonthProps } from 'react-day-picker'
|
|
21
|
+
import { defaultLocale, fieldLabel } from '../../../../lib/date-locale'
|
|
22
|
+
import { dividedColumns, ScrollColumn } from '../../../../lib/scroll-column'
|
|
23
|
+
import { useShape } from '../../../../lib/shape-context'
|
|
24
|
+
import { type SizeVariant, useSize } from '../../../../lib/size-context'
|
|
25
|
+
import { cn } from '../../../../lib/utils'
|
|
26
|
+
import { SizeProvider } from '../../../../primitives/sizes'
|
|
27
|
+
import { monthKey, useMonthWindow } from './use-month-window'
|
|
28
|
+
|
|
29
|
+
const WEEKEND = { dayOfWeek: [0, 6] }
|
|
30
|
+
|
|
31
|
+
/** The day picked for the columns' dot and the first scroll: a single date, or a range's start. */
|
|
32
|
+
function pickedDate(props: DayPickerProps): Date | undefined {
|
|
33
|
+
if (props.mode === 'single') return props.selected
|
|
34
|
+
if (props.mode === 'range') return props.selected?.from
|
|
35
|
+
return undefined
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Stamps each month with its key, so the window can find and measure it. */
|
|
39
|
+
function Month({ calendarMonth, displayIndex: _, ...props }: MonthProps) {
|
|
40
|
+
return <div {...props} data-calendar-month={monthKey(calendarMonth.date)} />
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** The day's cell: draws a range's band behind the pills. */
|
|
44
|
+
function Day({ day: _, modifiers, className, ...props }: DayProps) {
|
|
45
|
+
const start = modifiers.range_start && !modifiers.range_end
|
|
46
|
+
const end = modifiers.range_end && !modifiers.range_start
|
|
47
|
+
return (
|
|
48
|
+
<td
|
|
49
|
+
{...props}
|
|
50
|
+
className={cn(
|
|
51
|
+
'relative p-0',
|
|
52
|
+
// FF's fills: a committed span is `bg-active` (Checkbox's merged
|
|
53
|
+
// rows), the preview one step lighter at `bg-hover`.
|
|
54
|
+
!modifiers.hidden && modifiers.range_middle && 'bg-active',
|
|
55
|
+
!modifiers.hidden && modifiers.preview && !modifiers.selected && 'bg-hover',
|
|
56
|
+
(start || end) && 'before:absolute before:inset-y-0 before:bg-active',
|
|
57
|
+
start && 'before:start-1/2 before:end-0',
|
|
58
|
+
end && 'before:start-0 before:end-1/2',
|
|
59
|
+
className,
|
|
60
|
+
)}
|
|
61
|
+
/>
|
|
62
|
+
)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function DayButton({ day: _, modifiers, className, ...props }: DayButtonProps) {
|
|
66
|
+
const ref = useRef<HTMLButtonElement>(null)
|
|
67
|
+
// DayPicker's own DayButton does this: keyboard focus follows `focused`.
|
|
68
|
+
useEffect(() => {
|
|
69
|
+
if (modifiers.focused) ref.current?.focus()
|
|
70
|
+
}, [modifiers.focused])
|
|
71
|
+
const shape = useShape()
|
|
72
|
+
const sizeClasses = useSize()
|
|
73
|
+
const pill = modifiers.selected && !modifiers.range_middle
|
|
74
|
+
|
|
75
|
+
return (
|
|
76
|
+
<button
|
|
77
|
+
ref={ref}
|
|
78
|
+
{...props}
|
|
79
|
+
className={cn(
|
|
80
|
+
'relative flex items-center justify-center tabular-nums outline-none cursor-pointer',
|
|
81
|
+
'transition-[color,background-color] duration-fast focus-visible:ring-1 focus-visible:ring-focus-ring',
|
|
82
|
+
'disabled:opacity-50 disabled:cursor-default',
|
|
83
|
+
sizeClasses.variant === 'compact' ? 'size-7' : 'size-9',
|
|
84
|
+
sizeClasses.text,
|
|
85
|
+
shape.item,
|
|
86
|
+
// FF keeps red for errors: weekends step back to the muted text.
|
|
87
|
+
modifiers.weekend && 'text-muted-foreground',
|
|
88
|
+
modifiers.today &&
|
|
89
|
+
'after:absolute after:bottom-1 after:left-1/2 after:size-1 after:-translate-x-1/2 after:rounded-full after:bg-current',
|
|
90
|
+
// Foreground is FF's primary (its primary button's fill), text-background on it.
|
|
91
|
+
pill ? 'bg-foreground text-background weight-semibold hover:bg-foreground/90' : 'enabled:hover:bg-hover',
|
|
92
|
+
className,
|
|
93
|
+
)}
|
|
94
|
+
/>
|
|
95
|
+
)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* A calendar that scrolls through the months instead of paging, with month
|
|
100
|
+
* and year columns to jump by.
|
|
101
|
+
*
|
|
102
|
+
* Months run on in one list, each under its name, with the weekday row pinned
|
|
103
|
+
* above them; weekends step back to the muted text and today carries a dot. The month column
|
|
104
|
+
* marks the month being read and the year column its year, so either works
|
|
105
|
+
* as a scrollbar you can click: a month or a year scrolls the calendar there.
|
|
106
|
+
* The picked day, month and year show a filled pill or a dot. The columns
|
|
107
|
+
* stand after the days by default; `columnsSide="start"` puts them before
|
|
108
|
+
* (and `extraColumnsSide` places any extra ones). When the calendar is too
|
|
109
|
+
* narrow for them, they turn into strips above it. The list renders a window of months and moves it as you scroll, so the
|
|
110
|
+
* range is as long as `startMonth` / `endMonth` allow (100 years back and 50
|
|
111
|
+
* ahead by default).
|
|
112
|
+
*
|
|
113
|
+
* It is react-day-picker's DayPicker underneath: `mode` (`'single'`,
|
|
114
|
+
* `'range'`), `selected` / `onSelect`, `disabled` and `hidden` matchers,
|
|
115
|
+
* `modifiers`, `weekStartsOn`, `dir` and the other DayPicker props pass
|
|
116
|
+
* through. Its navigation props don't apply: the calendar scrolls.
|
|
117
|
+
* DatePicker and DateRangePicker put it in a field.
|
|
118
|
+
*
|
|
119
|
+
* @example {@include ./examples.mdx}
|
|
120
|
+
*/
|
|
121
|
+
function Calendar({
|
|
122
|
+
locale = defaultLocale,
|
|
123
|
+
size,
|
|
124
|
+
columnsSide = 'end',
|
|
125
|
+
extraColumns,
|
|
126
|
+
extraColumnsSide = 'end',
|
|
127
|
+
className,
|
|
128
|
+
...props
|
|
129
|
+
}: DayPickerProps & {
|
|
130
|
+
/** The locale: a react-day-picker / date-fns locale (`import { de } from 'react-day-picker/locale'`). Names months and weekdays, picks the first day of the week. Defaults to `enUS`. */
|
|
131
|
+
locale?: Locale
|
|
132
|
+
/** Pins the calendar to one step of the size ladder (36px days, compact 28px). Defaults to the surrounding SizeProvider. */
|
|
133
|
+
size?: SizeVariant
|
|
134
|
+
/** Which side of the days the month and year columns stand on; the month column keeps next to the days. Defaults to `'end'`. */
|
|
135
|
+
columnsSide?: 'start' | 'end'
|
|
136
|
+
/** More columns, given the layout's orientation — the date picker's hours and minutes. */
|
|
137
|
+
extraColumns?: (orientation: 'vertical' | 'horizontal') => ReactNode
|
|
138
|
+
/** Which side of the days the extra columns stand on, outside the month and year columns when they share it. Defaults to `'end'`. */
|
|
139
|
+
extraColumnsSide?: 'start' | 'end'
|
|
140
|
+
/** Classes for the calendar's box. */
|
|
141
|
+
className?: string
|
|
142
|
+
}) {
|
|
143
|
+
const sizeClasses = useSize(size)
|
|
144
|
+
const picked = pickedDate(props)
|
|
145
|
+
const today = useMemo(() => new Date(), [])
|
|
146
|
+
const start = startOfMonth(props.startMonth ?? startOfYear(addYears(today, -100)))
|
|
147
|
+
const end = startOfMonth(props.endMonth ?? endOfYear(addYears(today, 50)))
|
|
148
|
+
const anchor = picked ?? props.month ?? props.defaultMonth ?? today
|
|
149
|
+
const scroll = useMonthWindow(start, end, anchor)
|
|
150
|
+
const { jumpTo, visible } = scroll
|
|
151
|
+
|
|
152
|
+
// Before the first measure, the month the list opens on.
|
|
153
|
+
const currentKey = scroll.current ?? monthKey(anchor)
|
|
154
|
+
const yearInView = Number(currentKey.slice(0, 4))
|
|
155
|
+
const monthInView = Number(currentKey.slice(5, 7)) - 1
|
|
156
|
+
|
|
157
|
+
// A pick from outside the calendar (typed into a picker's field) scrolls to it.
|
|
158
|
+
const pickedTime = picked?.getTime()
|
|
159
|
+
const pickedRef = useRef(pickedTime)
|
|
160
|
+
useEffect(() => {
|
|
161
|
+
if (pickedTime === pickedRef.current) return
|
|
162
|
+
pickedRef.current = pickedTime
|
|
163
|
+
if (pickedTime !== undefined && !visible.includes(monthKey(new Date(pickedTime)))) jumpTo(new Date(pickedTime))
|
|
164
|
+
}, [pickedTime, jumpTo, visible])
|
|
165
|
+
|
|
166
|
+
// The columns stand beside the grid while they fit, and turn into strips
|
|
167
|
+
// above it when they don't. The width they need is remembered, so the
|
|
168
|
+
// strips only turn back once there is room again.
|
|
169
|
+
const rootRef = useRef<HTMLDivElement>(null)
|
|
170
|
+
const [wide, setWide] = useState(true)
|
|
171
|
+
const needed = useRef(0)
|
|
172
|
+
useLayoutEffect(() => {
|
|
173
|
+
const root = rootRef.current
|
|
174
|
+
if (!root) return
|
|
175
|
+
const check = () => {
|
|
176
|
+
if (wide && root.scrollWidth > root.clientWidth + 1) {
|
|
177
|
+
needed.current = root.scrollWidth
|
|
178
|
+
setWide(false)
|
|
179
|
+
} else if (!wide && root.clientWidth >= needed.current) setWide(true)
|
|
180
|
+
}
|
|
181
|
+
check()
|
|
182
|
+
const observer = new ResizeObserver(check)
|
|
183
|
+
observer.observe(root)
|
|
184
|
+
return () => observer.disconnect()
|
|
185
|
+
}, [wide])
|
|
186
|
+
|
|
187
|
+
// Turning changes the grid's height: put the picked day (or today) back in the middle.
|
|
188
|
+
const turned = useRef(wide)
|
|
189
|
+
useLayoutEffect(() => {
|
|
190
|
+
if (turned.current === wide) return
|
|
191
|
+
turned.current = wide
|
|
192
|
+
scroll.centreDay(picked ?? today)
|
|
193
|
+
})
|
|
194
|
+
|
|
195
|
+
// Range picking previews the span under the pointer before the second click.
|
|
196
|
+
const [hovered, setHovered] = useState<Date>()
|
|
197
|
+
const from = props.mode === 'range' ? props.selected?.from : undefined
|
|
198
|
+
const previewing = from && props.mode === 'range' && !props.selected?.to && hovered
|
|
199
|
+
const preview = previewing ? (hovered < from ? { from: hovered, to: from } : { from, to: hovered }) : false
|
|
200
|
+
|
|
201
|
+
const weekStartsOn = props.weekStartsOn ?? locale.options?.weekStartsOn ?? 0
|
|
202
|
+
const weekdays = useMemo(() => {
|
|
203
|
+
const first = startOfWeek(today, { weekStartsOn })
|
|
204
|
+
return Array.from({ length: 7 }, (_, i) => addDays(first, i))
|
|
205
|
+
}, [today, weekStartsOn])
|
|
206
|
+
|
|
207
|
+
const months = useMemo(
|
|
208
|
+
() =>
|
|
209
|
+
Array.from({ length: 12 }, (_, m) => ({
|
|
210
|
+
value: m,
|
|
211
|
+
label: format(new Date(2000, m, 1), 'LLL', { locale }),
|
|
212
|
+
disabled: new Date(yearInView, m, 1) < start || new Date(yearInView, m, 1) > end,
|
|
213
|
+
})),
|
|
214
|
+
[locale, yearInView, start.getTime(), end.getTime()],
|
|
215
|
+
)
|
|
216
|
+
const years = useMemo(
|
|
217
|
+
() =>
|
|
218
|
+
Array.from({ length: end.getFullYear() - start.getFullYear() + 1 }, (_, i) => {
|
|
219
|
+
const year = start.getFullYear() + i
|
|
220
|
+
return { value: year, label: String(year) }
|
|
221
|
+
}),
|
|
222
|
+
[start.getFullYear(), end.getFullYear()],
|
|
223
|
+
)
|
|
224
|
+
|
|
225
|
+
const jumpToYear = useCallback((year: number) => jumpTo(new Date(year, monthInView, 1)), [jumpTo, monthInView])
|
|
226
|
+
const orientation = wide ? 'vertical' : 'horizontal'
|
|
227
|
+
const column = wide ? 'w-16 shrink-0' : 'w-full'
|
|
228
|
+
|
|
229
|
+
const monthColumn = (
|
|
230
|
+
<ScrollColumn
|
|
231
|
+
key="month"
|
|
232
|
+
label={fieldLabel(locale, 'month')}
|
|
233
|
+
options={months}
|
|
234
|
+
value={picked && isSameYear(picked, new Date(yearInView, 0, 1)) ? picked.getMonth() : null}
|
|
235
|
+
follow={monthInView}
|
|
236
|
+
inView={m => m === monthInView}
|
|
237
|
+
onValueChange={m => jumpTo(new Date(yearInView, m, 1))}
|
|
238
|
+
orientation={orientation}
|
|
239
|
+
className={column}
|
|
240
|
+
/>
|
|
241
|
+
)
|
|
242
|
+
const yearColumn = (
|
|
243
|
+
<ScrollColumn
|
|
244
|
+
key="year"
|
|
245
|
+
label={fieldLabel(locale, 'year')}
|
|
246
|
+
options={years}
|
|
247
|
+
value={picked?.getFullYear() ?? null}
|
|
248
|
+
follow={yearInView}
|
|
249
|
+
inView={y => y === yearInView}
|
|
250
|
+
onValueChange={jumpToYear}
|
|
251
|
+
orientation={orientation}
|
|
252
|
+
className={column}
|
|
253
|
+
/>
|
|
254
|
+
)
|
|
255
|
+
const extras = extraColumns?.(orientation)
|
|
256
|
+
// Outward from the days: the month column, the year column, then the extras.
|
|
257
|
+
const before = [extraColumnsSide === 'start' && extras, columnsSide === 'start' && [yearColumn, monthColumn]]
|
|
258
|
+
const after = [columnsSide === 'end' && [monthColumn, yearColumn], extraColumnsSide === 'end' && extras]
|
|
259
|
+
const side = (place: 'start' | 'end') =>
|
|
260
|
+
wide
|
|
261
|
+
? cn(dividedColumns, 'h-full shrink-0 border-border', place === 'start' ? 'border-e' : 'border-s')
|
|
262
|
+
: 'order-first flex w-full flex-col [&>*]:border-b [&>*]:border-border'
|
|
263
|
+
|
|
264
|
+
const grid = (
|
|
265
|
+
<div className={cn('flex min-h-0 shrink-0 flex-col', wide ? 'h-full' : 'flex-1 self-center')}>
|
|
266
|
+
<div aria-hidden className="flex border-b border-border px-1 pb-1">
|
|
267
|
+
{weekdays.map(day => (
|
|
268
|
+
<span
|
|
269
|
+
key={day.getDay()}
|
|
270
|
+
className={cn(
|
|
271
|
+
'flex items-center justify-center text-caption',
|
|
272
|
+
sizeClasses.variant === 'compact' ? 'w-7' : 'w-9',
|
|
273
|
+
'text-muted-foreground',
|
|
274
|
+
)}
|
|
275
|
+
>
|
|
276
|
+
{format(day, 'EEEEEE', { locale })}
|
|
277
|
+
</span>
|
|
278
|
+
))}
|
|
279
|
+
</div>
|
|
280
|
+
<div
|
|
281
|
+
ref={scroll.scrollerRef}
|
|
282
|
+
onScroll={scroll.measure}
|
|
283
|
+
className="relative min-h-0 flex-1 overflow-y-auto overflow-x-hidden px-1 scrollbar-hide scroll-fade [--scroll-fade-size:16px] [overflow-anchor:none]"
|
|
284
|
+
>
|
|
285
|
+
<DayPicker
|
|
286
|
+
{...props}
|
|
287
|
+
locale={locale}
|
|
288
|
+
month={scroll.first}
|
|
289
|
+
numberOfMonths={scroll.count}
|
|
290
|
+
startMonth={start}
|
|
291
|
+
endMonth={end}
|
|
292
|
+
onMonthChange={scroll.recentre}
|
|
293
|
+
hideNavigation
|
|
294
|
+
hideWeekdays
|
|
295
|
+
showOutsideDays={false}
|
|
296
|
+
modifiers={{ weekend: WEEKEND, preview, ...props.modifiers }}
|
|
297
|
+
onDayMouseEnter={(date, modifiers, e) => {
|
|
298
|
+
setHovered(date)
|
|
299
|
+
props.onDayMouseEnter?.(date, modifiers, e)
|
|
300
|
+
}}
|
|
301
|
+
onDayMouseLeave={(date, modifiers, e) => {
|
|
302
|
+
setHovered(undefined)
|
|
303
|
+
props.onDayMouseLeave?.(date, modifiers, e)
|
|
304
|
+
}}
|
|
305
|
+
formatters={{
|
|
306
|
+
// The current year's months go by name alone, the rest with their year.
|
|
307
|
+
formatCaption: month => format(month, isSameYear(month, today) ? 'LLLL' : 'LLLL y', { locale }),
|
|
308
|
+
...props.formatters,
|
|
309
|
+
}}
|
|
310
|
+
components={{ Month, Day, DayButton, ...props.components }}
|
|
311
|
+
classNames={{
|
|
312
|
+
months: 'flex flex-col',
|
|
313
|
+
month: 'pb-2',
|
|
314
|
+
month_caption: cn(
|
|
315
|
+
'px-2 pt-2 pb-1 text-subtitle weight-semibold',
|
|
316
|
+
sizeClasses.variant === 'compact' && 'text-subtitle-compact',
|
|
317
|
+
),
|
|
318
|
+
month_grid: 'border-collapse',
|
|
319
|
+
...props.classNames,
|
|
320
|
+
}}
|
|
321
|
+
/>
|
|
322
|
+
</div>
|
|
323
|
+
</div>
|
|
324
|
+
)
|
|
325
|
+
|
|
326
|
+
const content = (
|
|
327
|
+
<div
|
|
328
|
+
ref={rootRef}
|
|
329
|
+
dir={props.dir}
|
|
330
|
+
className={cn(
|
|
331
|
+
'flex w-max max-w-full overflow-hidden',
|
|
332
|
+
wide ? 'h-80 flex-row' : 'h-[min(30rem,65dvh)] flex-col',
|
|
333
|
+
className,
|
|
334
|
+
)}
|
|
335
|
+
>
|
|
336
|
+
{/* Strips are reordered by CSS, not in the tree, so turning doesn't remount the grid. */}
|
|
337
|
+
{before.some(Boolean) ? <div className={side('start')}>{before}</div> : null}
|
|
338
|
+
{grid}
|
|
339
|
+
{after.some(Boolean) ? <div className={side('end')}>{after}</div> : null}
|
|
340
|
+
</div>
|
|
341
|
+
)
|
|
342
|
+
|
|
343
|
+
return size ? <SizeProvider size={size}>{content}</SizeProvider> : content
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
type CalendarProps = Parameters<typeof Calendar>[0]
|
|
347
|
+
|
|
348
|
+
export type { CalendarProps }
|
|
349
|
+
export { Calendar }
|
|
350
|
+
|
|
351
|
+
export default Calendar
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { addMonths, differenceInCalendarMonths, format, startOfMonth } from 'date-fns'
|
|
2
|
+
import { useCallback, useLayoutEffect, useRef, useState } from 'react'
|
|
3
|
+
|
|
4
|
+
/** Months rendered at once, and how far the window moves when the reader nears its edge. */
|
|
5
|
+
const WINDOW = 25
|
|
6
|
+
const SHIFT = 12
|
|
7
|
+
|
|
8
|
+
const monthKey = (date: Date) => format(date, 'yyyy-MM')
|
|
9
|
+
|
|
10
|
+
/** A rendered month's element in the scroller (the Calendar's `Month` stamps the key). */
|
|
11
|
+
const findMonth = (scroller: HTMLElement, key: string) =>
|
|
12
|
+
scroller.querySelector<HTMLElement>(`[data-calendar-month="${key}"]`)
|
|
13
|
+
|
|
14
|
+
/** What the next layout pass scrolls to: back to where the reader was, a month's top, or a day in the middle. */
|
|
15
|
+
interface Pending {
|
|
16
|
+
keep?: { key: string; delta: number }
|
|
17
|
+
month?: string
|
|
18
|
+
day?: Date
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The calendar's scroll: an endless-feeling list of months between `start` and
|
|
23
|
+
* `end` that renders only `WINDOW` of them. Nearing either rendered edge moves
|
|
24
|
+
* the window by `SHIFT` months and puts the reader back on the month they were
|
|
25
|
+
* reading. Also reports the months in view, for the month and year columns.
|
|
26
|
+
*/
|
|
27
|
+
function useMonthWindow(start: Date, end: Date, anchor: Date) {
|
|
28
|
+
const total = differenceInCalendarMonths(end, start) + 1
|
|
29
|
+
const count = Math.min(WINDOW, total)
|
|
30
|
+
const startTime = start.getTime()
|
|
31
|
+
|
|
32
|
+
const clamp = useCallback(
|
|
33
|
+
(first: Date) => {
|
|
34
|
+
const from = new Date(startTime)
|
|
35
|
+
const last = addMonths(from, total - count)
|
|
36
|
+
return first < from ? from : first > last ? last : startOfMonth(first)
|
|
37
|
+
},
|
|
38
|
+
[startTime, total, count],
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
const [first, setFirst] = useState(() => clamp(addMonths(startOfMonth(anchor), -Math.floor(WINDOW / 2))))
|
|
42
|
+
const [visible, setVisible] = useState<string[]>([])
|
|
43
|
+
// The month taking up most of the view: the one the columns mark.
|
|
44
|
+
const [current, setCurrent] = useState<string>()
|
|
45
|
+
const scrollerRef = useRef<HTMLDivElement>(null)
|
|
46
|
+
const firstRef = useRef(first)
|
|
47
|
+
firstRef.current = first
|
|
48
|
+
const pending = useRef<Pending | null>({ day: anchor })
|
|
49
|
+
// Set while a smooth jump runs: moving the window under it would cut it short.
|
|
50
|
+
const settling = useRef(false)
|
|
51
|
+
|
|
52
|
+
const topMonth = useCallback(() => {
|
|
53
|
+
const scroller = scrollerRef.current
|
|
54
|
+
if (!scroller) return undefined
|
|
55
|
+
const top = scroller.scrollTop
|
|
56
|
+
return [...scroller.querySelectorAll<HTMLElement>('[data-calendar-month]')].find(
|
|
57
|
+
el => el.offsetTop + el.offsetHeight > top,
|
|
58
|
+
)
|
|
59
|
+
}, [])
|
|
60
|
+
|
|
61
|
+
const moveWindow = useCallback(
|
|
62
|
+
(nextFirst: Date, target?: string) => {
|
|
63
|
+
const next = clamp(nextFirst)
|
|
64
|
+
if (next.getTime() === firstRef.current.getTime()) return
|
|
65
|
+
const scroller = scrollerRef.current
|
|
66
|
+
const top = topMonth()
|
|
67
|
+
pending.current = {
|
|
68
|
+
month: target,
|
|
69
|
+
keep:
|
|
70
|
+
scroller && top
|
|
71
|
+
? { key: top.dataset.calendarMonth ?? '', delta: top.offsetTop - scroller.scrollTop }
|
|
72
|
+
: undefined,
|
|
73
|
+
}
|
|
74
|
+
setFirst(next)
|
|
75
|
+
},
|
|
76
|
+
[clamp, topMonth],
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
/** Scrolls a rendered day into the middle of the list, at once. */
|
|
80
|
+
const centreDay = useCallback((date: Date) => {
|
|
81
|
+
const scroller = scrollerRef.current
|
|
82
|
+
const day = scroller?.querySelector<HTMLElement>(`[data-day="${format(date, 'yyyy-MM-dd')}"]`)
|
|
83
|
+
if (!scroller || !day) return
|
|
84
|
+
const s = scroller.getBoundingClientRect()
|
|
85
|
+
const d = day.getBoundingClientRect()
|
|
86
|
+
// In layout pixels: the panel may still be scaled by its opening morph.
|
|
87
|
+
const scale = s.height / scroller.offsetHeight || 1
|
|
88
|
+
scroller.scrollTop += (d.top - s.top) / scale - (scroller.clientHeight - day.offsetHeight) / 2
|
|
89
|
+
}, [])
|
|
90
|
+
|
|
91
|
+
const measure = useCallback(() => {
|
|
92
|
+
const scroller = scrollerRef.current
|
|
93
|
+
if (!scroller) return
|
|
94
|
+
const top = scroller.scrollTop
|
|
95
|
+
const bottom = top + scroller.clientHeight
|
|
96
|
+
const shown = [...scroller.querySelectorAll<HTMLElement>('[data-calendar-month]')]
|
|
97
|
+
.map(el => ({
|
|
98
|
+
key: el.dataset.calendarMonth ?? '',
|
|
99
|
+
height: Math.min(bottom, el.offsetTop + el.offsetHeight) - Math.max(top, el.offsetTop),
|
|
100
|
+
}))
|
|
101
|
+
.filter(m => m.height > 0)
|
|
102
|
+
const inView = shown.map(m => m.key)
|
|
103
|
+
setVisible(prev => (prev.join() === inView.join() ? prev : inView))
|
|
104
|
+
setCurrent(
|
|
105
|
+
shown.reduce<(typeof shown)[number] | undefined>((a, m) => (a && a.height >= m.height ? a : m), undefined)?.key,
|
|
106
|
+
)
|
|
107
|
+
if (settling.current) return
|
|
108
|
+
|
|
109
|
+
const margin = scroller.clientHeight
|
|
110
|
+
if (top < margin) moveWindow(addMonths(firstRef.current, -SHIFT))
|
|
111
|
+
else if (scroller.scrollHeight - bottom < margin) moveWindow(addMonths(firstRef.current, SHIFT))
|
|
112
|
+
}, [moveWindow])
|
|
113
|
+
|
|
114
|
+
// Runs after the window moves (and on mount) to restore the reader's place.
|
|
115
|
+
useLayoutEffect(() => {
|
|
116
|
+
const scroller = scrollerRef.current
|
|
117
|
+
const p = pending.current
|
|
118
|
+
pending.current = null
|
|
119
|
+
if (!scroller || !p) return
|
|
120
|
+
const target = p.month && findMonth(scroller, p.month)
|
|
121
|
+
const kept = p.keep && findMonth(scroller, p.keep.key)
|
|
122
|
+
if (target) scroller.scrollTop = target.offsetTop
|
|
123
|
+
else if (kept && p.keep) scroller.scrollTop = kept.offsetTop - p.keep.delta
|
|
124
|
+
else if (p.day) centreDay(p.day)
|
|
125
|
+
measure()
|
|
126
|
+
}, [first])
|
|
127
|
+
|
|
128
|
+
/** Scrolls a month to the top: smoothly when it is rendered, else by moving the window to it. */
|
|
129
|
+
const jumpTo = useCallback(
|
|
130
|
+
(month: Date, behavior: ScrollBehavior = 'smooth') => {
|
|
131
|
+
const scroller = scrollerRef.current
|
|
132
|
+
const key = monthKey(month)
|
|
133
|
+
const el = scroller && findMonth(scroller, key)
|
|
134
|
+
if (!scroller || !el) {
|
|
135
|
+
moveWindow(addMonths(startOfMonth(month), -Math.floor(WINDOW / 2)), key)
|
|
136
|
+
return
|
|
137
|
+
}
|
|
138
|
+
if (behavior === 'smooth') {
|
|
139
|
+
settling.current = true
|
|
140
|
+
const done = () => {
|
|
141
|
+
settling.current = false
|
|
142
|
+
scroller.removeEventListener('scrollend', done)
|
|
143
|
+
measure()
|
|
144
|
+
}
|
|
145
|
+
scroller.addEventListener('scrollend', done)
|
|
146
|
+
// Browsers without `scrollend` (and a jump that doesn't move) still settle.
|
|
147
|
+
setTimeout(done, 600)
|
|
148
|
+
}
|
|
149
|
+
scroller.scrollTo({ top: el.offsetTop, behavior })
|
|
150
|
+
},
|
|
151
|
+
[measure, moveWindow],
|
|
152
|
+
)
|
|
153
|
+
|
|
154
|
+
/** Keyboard focus left the window: recentre it on that month and keep the reader's place. */
|
|
155
|
+
const recentre = useCallback(
|
|
156
|
+
(month: Date) => moveWindow(addMonths(startOfMonth(month), -Math.floor(WINDOW / 2))),
|
|
157
|
+
[moveWindow],
|
|
158
|
+
)
|
|
159
|
+
|
|
160
|
+
return { first, count, visible, current, scrollerRef, measure, jumpTo, recentre, centreDay }
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export { monthKey, useMonthWindow }
|