@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,1495 @@
|
|
|
1
|
+
// biome-ignore-all lint: vendored upstream code keeps its own patterns (see the header)
|
|
2
|
+
/*
|
|
3
|
+
* Ported from Fluid Functionalism — github.com/mickadesign/fluid-functionalism
|
|
4
|
+
* `registry/default/sidebar-menu.tsx` @ b3587bdbd83fc66c2a6aae3817ffb856cb09260b
|
|
5
|
+
* MIT License © 2026 Micka Touillaud — fluidfunctionalism.com (notice: LICENSE.fluid-functionalism)
|
|
6
|
+
* Local modifications:
|
|
7
|
+
* - `"use client"` dropped; `framer-motion` → `motion/react`; `@/lib/*` and
|
|
8
|
+
* `@/hooks/*` imports rewritten to `../../../lib/*`, `SizeProvider` from
|
|
9
|
+
* `../../../primitives/sizes`, `@/components/ui/sidebar-core` → `./sidebar-core`.
|
|
10
|
+
* - Styling reads DS tokens (AGENTS.md styling): inline
|
|
11
|
+
* `fontVariationSettings` → `weight-*`; the `sm` rows' `text-[12px]` →
|
|
12
|
+
* `text-body-compact`, the badge's `text-[10px]` / `text-[11px]` →
|
|
13
|
+
* `text-micro-compact` / `text-micro`; the hex focus-ring fallback →
|
|
14
|
+
* `border-focus-ring`; `duration-80` → `duration-fast`.
|
|
15
|
+
* - The active row backgrounds are `GooIndicator`s (`lib/goo-indicator.tsx`):
|
|
16
|
+
* a new selection melts across from the old one instead of sliding as a
|
|
17
|
+
* box; the hover background already melts (`lib/fluid-hover-highlight.tsx`).
|
|
18
|
+
* - Uncontrolled selection: a button with a `value` is the active row when it
|
|
19
|
+
* matches the selection a surrounding `Sidebar` holds (`SidebarSelection`),
|
|
20
|
+
* and pressing it selects it; `status="active"` then keeps only its dot.
|
|
21
|
+
* - Collapsible rows: `SidebarMenuItem collapsible` holds its sub-menu's open
|
|
22
|
+
* state (`open` / `defaultOpen` / `onOpenChange`), so its button toggles it
|
|
23
|
+
* (`aria-expanded`) and draws the docs' trailing chevron, and a
|
|
24
|
+
* `SidebarMenuSub` without `open` follows it. FF's docs held that state in
|
|
25
|
+
* the page.
|
|
26
|
+
* - Refs written by hand are typed `MutableRefObject` (React 18).
|
|
27
|
+
* - A folded `SidebarMenuSub` is `inert` (through `inertProps` from `lib/inert.ts`, right on React 18
|
|
28
|
+
* and 19): an active sub-row inside it stayed a
|
|
29
|
+
* tab stop while `aria-hidden` and clipped away.
|
|
30
|
+
* - `sidebarMenuButtonVariants` lives in `./variants.ts` (no JSX, hooks or
|
|
31
|
+
* contexts), so server code can call it; re-exported here unchanged.
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
import type { VariantProps } from 'class-variance-authority'
|
|
35
|
+
import { AnimatePresence, motion } from 'motion/react'
|
|
36
|
+
import {
|
|
37
|
+
type AnchorHTMLAttributes,
|
|
38
|
+
type ButtonHTMLAttributes,
|
|
39
|
+
Children,
|
|
40
|
+
type CSSProperties,
|
|
41
|
+
createContext,
|
|
42
|
+
forwardRef,
|
|
43
|
+
type HTMLAttributes,
|
|
44
|
+
type LiHTMLAttributes,
|
|
45
|
+
type MouseEvent,
|
|
46
|
+
type MutableRefObject,
|
|
47
|
+
type ReactElement,
|
|
48
|
+
type ReactNode,
|
|
49
|
+
type Ref,
|
|
50
|
+
type RefObject,
|
|
51
|
+
useCallback,
|
|
52
|
+
useContext,
|
|
53
|
+
useEffect,
|
|
54
|
+
useId,
|
|
55
|
+
useLayoutEffect,
|
|
56
|
+
useMemo,
|
|
57
|
+
useRef,
|
|
58
|
+
useState,
|
|
59
|
+
} from 'react'
|
|
60
|
+
import { FluidHoverHighlight } from '../../../lib/fluid-hover-highlight'
|
|
61
|
+
import { GooIndicator } from '../../../lib/goo-indicator'
|
|
62
|
+
import { type IconComponent, useIcon } from '../../../lib/icon-context'
|
|
63
|
+
import { inertProps } from '../../../lib/inert'
|
|
64
|
+
import { useShape } from '../../../lib/shape-context'
|
|
65
|
+
import { type SizeVariant, useSize } from '../../../lib/size-context'
|
|
66
|
+
import { spring } from '../../../lib/springs'
|
|
67
|
+
import { useControllableState } from '../../../lib/use-controllable-state'
|
|
68
|
+
import { type ItemRect, useFluidHover } from '../../../lib/use-fluid-hover'
|
|
69
|
+
import { cn } from '../../../lib/utils'
|
|
70
|
+
import { SizeProvider } from '../../../primitives/sizes'
|
|
71
|
+
import { resolveSlotTemplate, slotElement } from './sidebar-core'
|
|
72
|
+
import { sidebarMenuButtonVariants } from './variants'
|
|
73
|
+
|
|
74
|
+
export { sidebarMenuButtonVariants }
|
|
75
|
+
|
|
76
|
+
// SSR-safe layout effect (client components still server-render in Next).
|
|
77
|
+
const useIsoLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect
|
|
78
|
+
|
|
79
|
+
// ─── Menu scope ──────────────────────────────────────────────────────────────
|
|
80
|
+
//
|
|
81
|
+
// One scope per SidebarMenu tree: a single fluid-hover system plus the
|
|
82
|
+
// traveling overlays — hover background, active background(s), focus ring —
|
|
83
|
+
// that glide between every visible row, sub-menu rows included, so the hover
|
|
84
|
+
// moves from a parent into its children as one continuous piece. Sub rows
|
|
85
|
+
// live inside positioned ancestors, so their rects are accumulated into the
|
|
86
|
+
// menu's own coordinate space by the fluid hover hook. The active background
|
|
87
|
+
// stays one per level (the root rows, and each sub-menu) so a current section
|
|
88
|
+
// and the current page inside it can both be lit, exactly as before.
|
|
89
|
+
|
|
90
|
+
interface MenuScopeValue {
|
|
91
|
+
registerRow: (el: HTMLElement) => () => void
|
|
92
|
+
setRowButton: (row: HTMLElement, button: HTMLElement | null) => void
|
|
93
|
+
setRowActive: (row: HTMLElement, active: boolean) => void
|
|
94
|
+
hoveredRowEl: HTMLElement | null
|
|
95
|
+
/** Every visible active row, in DOM order — a parent section marker and
|
|
96
|
+
* the current row inside its sub-tree can be active at once. */
|
|
97
|
+
activeRows: HTMLElement[]
|
|
98
|
+
firstRowEl: HTMLElement | null
|
|
99
|
+
hasActive: boolean
|
|
100
|
+
/** A sub-menu toggled: rows changed visibility in place, so hover targets
|
|
101
|
+
* and the visible active set must be recomputed. */
|
|
102
|
+
refreshVisibility: () => void
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const MenuScopeContext = createContext<MenuScopeValue | null>(null)
|
|
106
|
+
|
|
107
|
+
/** The selection a `Sidebar` holds for buttons that carry a `value`. */
|
|
108
|
+
interface SidebarSelectionValue {
|
|
109
|
+
value: string | undefined
|
|
110
|
+
select: (value: string) => void
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const SidebarSelection = createContext<SidebarSelectionValue | null>(null)
|
|
114
|
+
|
|
115
|
+
interface MenuItemContextValue {
|
|
116
|
+
rowRef: MutableRefObject<HTMLLIElement | null>
|
|
117
|
+
/** Ref callback for the row's <li> — also replays the row's active flag
|
|
118
|
+
* to the scope, covering the windows where the ref is detached. */
|
|
119
|
+
attachRow: (node: HTMLLIElement | null) => void
|
|
120
|
+
isHovered: boolean
|
|
121
|
+
isActiveRow: boolean
|
|
122
|
+
/** True inside SidebarMenuSubItem — actions center on the shorter row. */
|
|
123
|
+
isSubRow: boolean
|
|
124
|
+
setActive: (active: boolean) => void
|
|
125
|
+
setButtonEl: (el: HTMLElement | null) => void
|
|
126
|
+
/** Trailing controls on this row, registered by the action / badge parts.
|
|
127
|
+
* The button turns them into an exact padding-right reservation. */
|
|
128
|
+
actionCount: number
|
|
129
|
+
actionsShowOnHover: boolean
|
|
130
|
+
hasBadge: boolean
|
|
131
|
+
setActions: (count: number, showOnHover: boolean) => void
|
|
132
|
+
setHasBadge: (hasBadge: boolean) => void
|
|
133
|
+
/** A collapsible row's sub-menu state; `undefined` for a plain row. */
|
|
134
|
+
subOpen: boolean | undefined
|
|
135
|
+
toggleSub: () => void
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const MenuItemContext = createContext<MenuItemContextValue | null>(null)
|
|
139
|
+
|
|
140
|
+
/** True while rendering inside a SidebarMenuActions cluster, where each
|
|
141
|
+
* action flows in the wrapper's row instead of positioning itself. */
|
|
142
|
+
const MenuActionsClusterContext = createContext(false)
|
|
143
|
+
|
|
144
|
+
/** True while the element sits inside a collapsed sub-tree — clipped away,
|
|
145
|
+
* so it must be invisible to hover, highlights, and keyboard order. Rows
|
|
146
|
+
* stay registered either way: unregistering on every toggle would churn the
|
|
147
|
+
* fluid hover measurements and blink the overlays. */
|
|
148
|
+
function rowHidden(el: HTMLElement) {
|
|
149
|
+
return el.closest('[data-sidebar="menu-sub"][data-state="closed"]') !== null
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** True for a disabled row: it stays in the list (and in the layout) but is
|
|
153
|
+
* never lit, never takes a routed click, and is skipped by the keyboard.
|
|
154
|
+
* The hook registers the row's button (falling back to the row itself), so
|
|
155
|
+
* check the element first, then a button directly inside it. A sub-row's
|
|
156
|
+
* anchor carries aria-disabled instead of `disabled`. */
|
|
157
|
+
const DISABLED_CONTROL = ':disabled, [aria-disabled="true"]'
|
|
158
|
+
function rowDisabled(el: HTMLElement) {
|
|
159
|
+
return (
|
|
160
|
+
el.matches(DISABLED_CONTROL) ||
|
|
161
|
+
el.querySelector(
|
|
162
|
+
`:scope > [data-sidebar="menu-button"]:is(${DISABLED_CONTROL}), :scope > [data-sidebar="menu-sub-button"]:is(${DISABLED_CONTROL})`,
|
|
163
|
+
) !== null
|
|
164
|
+
)
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/** Hidden or disabled: what hover, highlights, and the keyboard skip. */
|
|
168
|
+
function rowSkipped(el: HTMLElement) {
|
|
169
|
+
return rowHidden(el) || rowDisabled(el)
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** Stable keys for the per-level active overlays: one id per sub-menu <ul>
|
|
173
|
+
* (or the menu root), so the active background glides when the active row
|
|
174
|
+
* moves within its level instead of remounting. */
|
|
175
|
+
let overlayGroupSeq = 0
|
|
176
|
+
const overlayGroupIds = new WeakMap<Element, number>()
|
|
177
|
+
function overlayGroupId(el: Element) {
|
|
178
|
+
let id = overlayGroupIds.get(el)
|
|
179
|
+
if (id === undefined) {
|
|
180
|
+
id = ++overlayGroupSeq
|
|
181
|
+
overlayGroupIds.set(el, id)
|
|
182
|
+
}
|
|
183
|
+
return id
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function byDomOrder(a: HTMLElement, b: HTMLElement) {
|
|
187
|
+
return a.compareDocumentPosition(b) & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function sameElements(a: HTMLElement[], b: HTMLElement[]) {
|
|
191
|
+
return a.length === b.length && a.every((el, i) => el === b[i])
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
interface MenuScope {
|
|
195
|
+
value: MenuScopeValue
|
|
196
|
+
containerProps: {
|
|
197
|
+
onMouseEnter: () => void
|
|
198
|
+
onMouseMove: (e: React.MouseEvent) => void
|
|
199
|
+
onMouseLeave: () => void
|
|
200
|
+
/** A click between rows lands on the highlighted row's button. */
|
|
201
|
+
onClick: (e: React.MouseEvent) => void
|
|
202
|
+
onFocus: (e: React.FocusEvent) => void
|
|
203
|
+
onBlur: (e: React.FocusEvent) => void
|
|
204
|
+
onPointerDown: () => void
|
|
205
|
+
onKeyDown?: (e: React.KeyboardEvent) => void
|
|
206
|
+
}
|
|
207
|
+
overlays: ReactNode
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
interface MenuScopeOptions {
|
|
211
|
+
/** Draw the traveling keyboard focus ring. Off, keyboard focus moves the
|
|
212
|
+
* hover background only — for menus whose rows are the whole surface,
|
|
213
|
+
* like a settings dialog's section list. @default true */
|
|
214
|
+
focusRing?: boolean
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
function useMenuScope(
|
|
218
|
+
containerRef: RefObject<HTMLElement | null>,
|
|
219
|
+
{ focusRing = true }: MenuScopeOptions = {},
|
|
220
|
+
): MenuScope {
|
|
221
|
+
const { activeIndex, setActiveIndex, itemRects, isMeasured, sessionRef, handlers, registerItem } = useFluidHover(
|
|
222
|
+
containerRef,
|
|
223
|
+
{ isItemDisabled: rowSkipped },
|
|
224
|
+
)
|
|
225
|
+
|
|
226
|
+
const rowsRef = useRef<Set<HTMLElement>>(new Set())
|
|
227
|
+
const rowButtonsRef = useRef<Map<HTMLElement, HTMLElement>>(new Map())
|
|
228
|
+
const activeMapRef = useRef<Map<HTMLElement, boolean>>(new Map())
|
|
229
|
+
const [orderedRows, setOrderedRows] = useState<HTMLElement[]>([])
|
|
230
|
+
const orderedRowsRef = useRef(orderedRows)
|
|
231
|
+
orderedRowsRef.current = orderedRows
|
|
232
|
+
const registeredCountRef = useRef(0)
|
|
233
|
+
const [activeRows, setActiveRows] = useState<HTMLElement[]>([])
|
|
234
|
+
const [focusedRowEl, setFocusedRowEl] = useState<HTMLElement | null>(null)
|
|
235
|
+
|
|
236
|
+
const recomputeActive = useCallback(() => {
|
|
237
|
+
const next = orderedRowsRef.current.filter(el => activeMapRef.current.get(el) && !rowSkipped(el))
|
|
238
|
+
setActiveRows(prev => (sameElements(prev, next) ? prev : next))
|
|
239
|
+
}, [])
|
|
240
|
+
|
|
241
|
+
const rowButton = useCallback(
|
|
242
|
+
(row: HTMLElement) =>
|
|
243
|
+
rowButtonsRef.current.get(row) ??
|
|
244
|
+
row.querySelector<HTMLElement>(
|
|
245
|
+
':scope > [data-sidebar="menu-button"], :scope > [data-sidebar="menu-sub-button"]',
|
|
246
|
+
),
|
|
247
|
+
[],
|
|
248
|
+
)
|
|
249
|
+
|
|
250
|
+
// Rows register by element; indexes are derived from DOM order so consumers
|
|
251
|
+
// never pass an index prop and conditional rows just work. The fluid hover
|
|
252
|
+
// system measures the row's BUTTON, not the <li>: a row hosting an expanded
|
|
253
|
+
// sub-tree is a tall <li>, and hit-testing against that whole box would hand
|
|
254
|
+
// the sub-tree's gaps and gutter to the parent — the button strip is the
|
|
255
|
+
// only part that is really "the row".
|
|
256
|
+
const syncRows = useCallback(() => {
|
|
257
|
+
const sorted = [...rowsRef.current].sort(byDomOrder)
|
|
258
|
+
// The ref updates synchronously (not just at the next render): callers in
|
|
259
|
+
// the same commit — a row registering, its button turning active — must
|
|
260
|
+
// see the row set they just changed, or the first recompute of a mount
|
|
261
|
+
// filters every row out against the previous render's empty list.
|
|
262
|
+
orderedRowsRef.current = sorted
|
|
263
|
+
setOrderedRows(prev => (sameElements(prev, sorted) ? prev : sorted))
|
|
264
|
+
sorted.forEach((el, i) => registerItem(i, rowButton(el) ?? el))
|
|
265
|
+
for (let i = sorted.length; i < registeredCountRef.current; i++) {
|
|
266
|
+
registerItem(i, null)
|
|
267
|
+
}
|
|
268
|
+
registeredCountRef.current = sorted.length
|
|
269
|
+
recomputeActive()
|
|
270
|
+
}, [registerItem, recomputeActive, rowButton])
|
|
271
|
+
|
|
272
|
+
const registerRow = useCallback(
|
|
273
|
+
(el: HTMLElement) => {
|
|
274
|
+
rowsRef.current.add(el)
|
|
275
|
+
syncRows()
|
|
276
|
+
return () => {
|
|
277
|
+
rowsRef.current.delete(el)
|
|
278
|
+
rowButtonsRef.current.delete(el)
|
|
279
|
+
activeMapRef.current.delete(el)
|
|
280
|
+
syncRows()
|
|
281
|
+
}
|
|
282
|
+
},
|
|
283
|
+
[syncRows],
|
|
284
|
+
)
|
|
285
|
+
|
|
286
|
+
const setRowButton = useCallback(
|
|
287
|
+
(row: HTMLElement, button: HTMLElement | null) => {
|
|
288
|
+
if (button) rowButtonsRef.current.set(row, button)
|
|
289
|
+
else rowButtonsRef.current.delete(row)
|
|
290
|
+
// The button is the row's measured element, so a button arriving after
|
|
291
|
+
// its row registered must re-sync what the fluid hover system observes.
|
|
292
|
+
syncRows()
|
|
293
|
+
},
|
|
294
|
+
[syncRows],
|
|
295
|
+
)
|
|
296
|
+
|
|
297
|
+
const setRowActive = useCallback(
|
|
298
|
+
(row: HTMLElement, active: boolean) => {
|
|
299
|
+
activeMapRef.current.set(row, active)
|
|
300
|
+
recomputeActive()
|
|
301
|
+
},
|
|
302
|
+
[recomputeActive],
|
|
303
|
+
)
|
|
304
|
+
|
|
305
|
+
const refreshVisibility = useCallback(() => {
|
|
306
|
+
recomputeActive()
|
|
307
|
+
// A hover riding a row that just collapsed away has nothing under it.
|
|
308
|
+
setActiveIndex(prev => {
|
|
309
|
+
const row = prev !== null ? orderedRowsRef.current[prev] : undefined
|
|
310
|
+
return row && rowSkipped(row) ? null : prev
|
|
311
|
+
})
|
|
312
|
+
}, [recomputeActive, setActiveIndex])
|
|
313
|
+
|
|
314
|
+
// A row's rect spans the whole <li> — which grows when it hosts an expanded
|
|
315
|
+
// sub-menu — so overlay heights are clamped to the row's button box. The
|
|
316
|
+
// 48px fallback (the tallest row, size="lg") guarantees the highlight can
|
|
317
|
+
// never cover an expanded sub-tree even if the button lookup misses.
|
|
318
|
+
const overlayRect = useCallback(
|
|
319
|
+
(row: HTMLElement | null): ItemRect | null => {
|
|
320
|
+
if (!row) return null
|
|
321
|
+
const idx = orderedRowsRef.current.indexOf(row)
|
|
322
|
+
const rect = idx === -1 ? null : itemRects[idx]
|
|
323
|
+
if (!rect) return null
|
|
324
|
+
const height = Math.min(rect.height, rowButton(row)?.offsetHeight ?? 48)
|
|
325
|
+
return { ...rect, height }
|
|
326
|
+
},
|
|
327
|
+
[itemRects, rowButton],
|
|
328
|
+
)
|
|
329
|
+
|
|
330
|
+
// While a popup anchored in the sidebar is open (a row action's or the
|
|
331
|
+
// header/footer rows' dropdown), hover tracking freezes across every menu
|
|
332
|
+
// scope — otherwise a non-modal popup lets rows underneath keep
|
|
333
|
+
// highlighting. Popup triggers are detected by the primitives' open
|
|
334
|
+
// attributes (Radix data-state, Base UI data-popup-open); collapsible rows
|
|
335
|
+
// only set aria-expanded, so they never match.
|
|
336
|
+
const popupOpen = useCallback(() => {
|
|
337
|
+
const container = containerRef.current
|
|
338
|
+
if (!container) return false
|
|
339
|
+
const root = container.closest('[data-slot="sidebar-wrapper"]') ?? container
|
|
340
|
+
return !!root.querySelector(
|
|
341
|
+
'[data-sidebar="menu-button"][data-state="open"], [data-sidebar="menu-button"][data-popup-open], [data-sidebar="menu-action"][data-state="open"], [data-sidebar="menu-action"][data-popup-open]',
|
|
342
|
+
)
|
|
343
|
+
}, [containerRef])
|
|
344
|
+
|
|
345
|
+
const onMouseMove = useCallback(
|
|
346
|
+
(e: React.MouseEvent) => {
|
|
347
|
+
if (popupOpen()) return
|
|
348
|
+
handlers.onMouseMove(e)
|
|
349
|
+
},
|
|
350
|
+
[popupOpen, handlers],
|
|
351
|
+
)
|
|
352
|
+
|
|
353
|
+
const onFocus = useCallback(
|
|
354
|
+
(e: React.FocusEvent) => {
|
|
355
|
+
const target = e.target as HTMLElement
|
|
356
|
+
// Only the row's main button drives the traveling highlight and ring —
|
|
357
|
+
// actions keep their own static focus rings.
|
|
358
|
+
if (!target.closest('[data-sidebar="menu-button"],[data-sidebar="menu-sub-button"]')) return
|
|
359
|
+
const row = target.closest('[data-sidebar="menu-item"],[data-sidebar="menu-sub-item"]') as HTMLElement | null
|
|
360
|
+
if (!row) return
|
|
361
|
+
const idx = orderedRowsRef.current.indexOf(row)
|
|
362
|
+
if (idx === -1) return
|
|
363
|
+
setActiveIndex(idx)
|
|
364
|
+
setFocusedRowEl(target.matches(':focus-visible') ? row : null)
|
|
365
|
+
},
|
|
366
|
+
[setActiveIndex],
|
|
367
|
+
)
|
|
368
|
+
|
|
369
|
+
const onPointerDown = useCallback(() => {
|
|
370
|
+
setFocusedRowEl(null)
|
|
371
|
+
}, [])
|
|
372
|
+
|
|
373
|
+
const onBlur = useCallback(
|
|
374
|
+
(e: React.FocusEvent) => {
|
|
375
|
+
if (containerRef.current?.contains(e.relatedTarget as Node)) return
|
|
376
|
+
setFocusedRowEl(null)
|
|
377
|
+
setActiveIndex(null)
|
|
378
|
+
},
|
|
379
|
+
[containerRef, setActiveIndex],
|
|
380
|
+
)
|
|
381
|
+
|
|
382
|
+
// Arrow/Home/End over every button in DOM order, sub rows included — only
|
|
383
|
+
// the root scope binds it so nested scopes don't double-handle.
|
|
384
|
+
const onKeyDown = useCallback(
|
|
385
|
+
(e: React.KeyboardEvent) => {
|
|
386
|
+
if (!['ArrowDown', 'ArrowUp', 'ArrowRight', 'ArrowLeft', 'Home', 'End'].includes(e.key)) return
|
|
387
|
+
const container = containerRef.current
|
|
388
|
+
if (!container) return
|
|
389
|
+
const items = Array.from(
|
|
390
|
+
container.querySelectorAll<HTMLElement>('[data-sidebar="menu-button"], [data-sidebar="menu-sub-button"]'),
|
|
391
|
+
).filter(el => !el.closest('[data-sidebar="menu-sub"][data-state="closed"]'))
|
|
392
|
+
const currentIdx = items.indexOf(e.target as HTMLElement)
|
|
393
|
+
if (currentIdx === -1) return
|
|
394
|
+
e.preventDefault()
|
|
395
|
+
// Keep handled arrows from also reaching window-level listeners (the
|
|
396
|
+
// docs site's ←/→ page navigation) — same rule as AskUserQuestions.
|
|
397
|
+
e.stopPropagation()
|
|
398
|
+
if (e.key === 'Home') items[0]?.focus()
|
|
399
|
+
else if (e.key === 'End') items[items.length - 1]?.focus()
|
|
400
|
+
else {
|
|
401
|
+
const next = ['ArrowDown', 'ArrowRight'].includes(e.key)
|
|
402
|
+
? (currentIdx + 1) % items.length
|
|
403
|
+
: (currentIdx - 1 + items.length) % items.length
|
|
404
|
+
items[next]?.focus()
|
|
405
|
+
}
|
|
406
|
+
},
|
|
407
|
+
[containerRef],
|
|
408
|
+
)
|
|
409
|
+
|
|
410
|
+
const hoveredRowEl = activeIndex !== null ? (orderedRows[activeIndex] ?? null) : null
|
|
411
|
+
|
|
412
|
+
const value = useMemo<MenuScopeValue>(
|
|
413
|
+
() => ({
|
|
414
|
+
registerRow,
|
|
415
|
+
setRowButton,
|
|
416
|
+
setRowActive,
|
|
417
|
+
hoveredRowEl,
|
|
418
|
+
activeRows,
|
|
419
|
+
firstRowEl: orderedRows[0] ?? null,
|
|
420
|
+
hasActive: activeRows.length > 0,
|
|
421
|
+
refreshVisibility,
|
|
422
|
+
}),
|
|
423
|
+
[registerRow, setRowButton, setRowActive, hoveredRowEl, activeRows, orderedRows, refreshVisibility],
|
|
424
|
+
)
|
|
425
|
+
|
|
426
|
+
const shape = useShape()
|
|
427
|
+
// Every active row gets its own background — the buttons' own text styling
|
|
428
|
+
// already lights each active row, so the overlays must match. Keys are the
|
|
429
|
+
// row's level (root, or its sub-menu) plus its occurrence within that
|
|
430
|
+
// level: the usual case — one active per level, e.g. a current section
|
|
431
|
+
// marker plus the current page inside its sub-tree — keeps a stable key,
|
|
432
|
+
// so the background GLIDES when the selection moves instead of remounting.
|
|
433
|
+
const rowLevel = useCallback(
|
|
434
|
+
(row: HTMLElement) => row.closest('[data-sidebar="menu-sub"]') ?? containerRef.current,
|
|
435
|
+
[containerRef],
|
|
436
|
+
)
|
|
437
|
+
// A rect change has two causes with two right answers. The highlight moving
|
|
438
|
+
// to a DIFFERENT row springs — that's the glide. The same row itself moving
|
|
439
|
+
// — a sibling sub-tree collapsing above reflows every row below on every
|
|
440
|
+
// frame of its own spring — must snap, or the overlay chases the row it is
|
|
441
|
+
// sitting on with a trailing second spring. Targets are compared against
|
|
442
|
+
// the previous COMMIT (the effect below), not the previous render, so
|
|
443
|
+
// strict mode's double render can't eat a genuine row change.
|
|
444
|
+
const prevTargetsRef = useRef<{
|
|
445
|
+
hover: HTMLElement | null
|
|
446
|
+
focus: HTMLElement | null
|
|
447
|
+
actives: Map<string, HTMLElement>
|
|
448
|
+
}>({ hover: null, focus: null, actives: new Map() })
|
|
449
|
+
|
|
450
|
+
const levelOccurrence = new Map<number, number>()
|
|
451
|
+
const levelFirstActive = new Map<number, HTMLElement>()
|
|
452
|
+
const activeRects: {
|
|
453
|
+
key: string
|
|
454
|
+
rect: ItemRect
|
|
455
|
+
row: HTMLElement
|
|
456
|
+
rowChanged: boolean
|
|
457
|
+
}[] = []
|
|
458
|
+
for (const row of activeRows) {
|
|
459
|
+
const level = rowLevel(row)
|
|
460
|
+
if (!level) continue
|
|
461
|
+
const levelId = overlayGroupId(level)
|
|
462
|
+
const occurrence = levelOccurrence.get(levelId) ?? 0
|
|
463
|
+
levelOccurrence.set(levelId, occurrence + 1)
|
|
464
|
+
if (!levelFirstActive.has(levelId)) levelFirstActive.set(levelId, row)
|
|
465
|
+
const rect = overlayRect(row)
|
|
466
|
+
if (rect)
|
|
467
|
+
activeRects.push({
|
|
468
|
+
key: `${levelId}:${occurrence}`,
|
|
469
|
+
rect,
|
|
470
|
+
row,
|
|
471
|
+
rowChanged: prevTargetsRef.current.actives.get(`${levelId}:${occurrence}`) !== row,
|
|
472
|
+
})
|
|
473
|
+
}
|
|
474
|
+
const hoverRect = overlayRect(hoveredRowEl)
|
|
475
|
+
const focusRect = focusRing ? overlayRect(focusedRowEl) : null
|
|
476
|
+
const hoverRowChanged = prevTargetsRef.current.hover !== hoveredRowEl
|
|
477
|
+
const focusRowChanged = prevTargetsRef.current.focus !== focusedRowEl
|
|
478
|
+
|
|
479
|
+
useIsoLayoutEffect(() => {
|
|
480
|
+
prevTargetsRef.current = {
|
|
481
|
+
hover: hoveredRowEl,
|
|
482
|
+
focus: focusedRowEl,
|
|
483
|
+
actives: new Map(activeRects.map(({ key, row }) => [key, row])),
|
|
484
|
+
}
|
|
485
|
+
})
|
|
486
|
+
// The hover background fades in anchored on the active row of the hovered
|
|
487
|
+
// row's own level (falling back to any active), so entering the menu reads
|
|
488
|
+
// as the highlight detaching from where the selection lives.
|
|
489
|
+
const hoveredLevel = hoveredRowEl ? rowLevel(hoveredRowEl) : null
|
|
490
|
+
const hoverAnchorRow =
|
|
491
|
+
(hoveredLevel ? levelFirstActive.get(overlayGroupId(hoveredLevel)) : undefined) ??
|
|
492
|
+
levelFirstActive.values().next().value
|
|
493
|
+
const hoverAnchorRect = hoverAnchorRow ? overlayRect(hoverAnchorRow) : null
|
|
494
|
+
|
|
495
|
+
const overlays = isMeasured ? (
|
|
496
|
+
<>
|
|
497
|
+
{/* Active row backgrounds — one per active row (see activeRects above) */}
|
|
498
|
+
<AnimatePresence>
|
|
499
|
+
{activeRects.map(({ key, rect, rowChanged }) => (
|
|
500
|
+
<motion.div
|
|
501
|
+
key={key}
|
|
502
|
+
className="pointer-events-none absolute top-0 left-0"
|
|
503
|
+
initial={false}
|
|
504
|
+
animate={{ opacity: 1 }}
|
|
505
|
+
exit={{ opacity: 0, transition: spring.moderate.exit }}
|
|
506
|
+
>
|
|
507
|
+
<GooIndicator
|
|
508
|
+
rect={rect}
|
|
509
|
+
className={cn('bg-active', shape.bg)}
|
|
510
|
+
transition={rowChanged ? spring.moderate : false}
|
|
511
|
+
/>
|
|
512
|
+
</motion.div>
|
|
513
|
+
))}
|
|
514
|
+
</AnimatePresence>
|
|
515
|
+
|
|
516
|
+
{/* Hover background. Fades in from the level's active row; snaps (no
|
|
517
|
+
travel) when only a reflow moved the rows underneath. */}
|
|
518
|
+
<FluidHoverHighlight
|
|
519
|
+
rect={hoverRect}
|
|
520
|
+
session={sessionRef.current}
|
|
521
|
+
from={hoverAnchorRect}
|
|
522
|
+
className={shape.bg}
|
|
523
|
+
transition={hoverRowChanged ? undefined : false}
|
|
524
|
+
/>
|
|
525
|
+
|
|
526
|
+
{/* Focus ring */}
|
|
527
|
+
<AnimatePresence>
|
|
528
|
+
{focusRect && (
|
|
529
|
+
<motion.div
|
|
530
|
+
className={`absolute ${shape.focusRing} pointer-events-none z-20 border border-focus-ring`}
|
|
531
|
+
initial={false}
|
|
532
|
+
animate={{
|
|
533
|
+
left: focusRect.left - 2,
|
|
534
|
+
top: focusRect.top - 2,
|
|
535
|
+
width: focusRect.width + 4,
|
|
536
|
+
height: focusRect.height + 4,
|
|
537
|
+
}}
|
|
538
|
+
exit={{ opacity: 0, transition: spring.fast.exit }}
|
|
539
|
+
transition={focusRowChanged ? { ...spring.fast, opacity: { duration: 0.08 } } : { duration: 0 }}
|
|
540
|
+
/>
|
|
541
|
+
)}
|
|
542
|
+
</AnimatePresence>
|
|
543
|
+
</>
|
|
544
|
+
) : null
|
|
545
|
+
|
|
546
|
+
return {
|
|
547
|
+
value,
|
|
548
|
+
containerProps: {
|
|
549
|
+
onMouseEnter: handlers.onMouseEnter,
|
|
550
|
+
onMouseMove,
|
|
551
|
+
onMouseLeave: handlers.onMouseLeave,
|
|
552
|
+
onClick: handlers.onClick,
|
|
553
|
+
onFocus,
|
|
554
|
+
onBlur,
|
|
555
|
+
// Pointer interaction switches modality back to pointer. Clicking the
|
|
556
|
+
// already-focused row never re-fires focus, so without this the
|
|
557
|
+
// keyboard ring would stick until focus left the menu.
|
|
558
|
+
onPointerDown,
|
|
559
|
+
onKeyDown,
|
|
560
|
+
},
|
|
561
|
+
overlays,
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
// ─── SidebarMenu ─────────────────────────────────────────────────────────────
|
|
566
|
+
|
|
567
|
+
export interface SidebarMenuProps extends HTMLAttributes<HTMLUListElement> {
|
|
568
|
+
/** Pins the menu's rows to one step of the size ladder. Omitted, they
|
|
569
|
+
* follow the surrounding SizeProvider. */
|
|
570
|
+
size?: SizeVariant
|
|
571
|
+
/** Draw the traveling keyboard focus ring. Off, keyboard focus moves the
|
|
572
|
+
* hover background only. @default true */
|
|
573
|
+
focusRing?: boolean
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
const SidebarMenu = forwardRef<HTMLUListElement, SidebarMenuProps>(
|
|
577
|
+
({ className, size, focusRing, children, ...props }, ref) => {
|
|
578
|
+
const containerRef = useRef<HTMLUListElement | null>(null)
|
|
579
|
+
const { value, containerProps, overlays } = useMenuScope(containerRef, { focusRing })
|
|
580
|
+
|
|
581
|
+
const content = (
|
|
582
|
+
<MenuScopeContext.Provider value={value}>
|
|
583
|
+
<ul
|
|
584
|
+
ref={node => {
|
|
585
|
+
containerRef.current = node
|
|
586
|
+
if (typeof ref === 'function') ref(node)
|
|
587
|
+
else if (ref) (ref as React.MutableRefObject<HTMLUListElement | null>).current = node
|
|
588
|
+
}}
|
|
589
|
+
data-sidebar="menu"
|
|
590
|
+
className={cn('relative flex w-full min-w-0 flex-col select-none', className)}
|
|
591
|
+
{...containerProps}
|
|
592
|
+
{...props}
|
|
593
|
+
>
|
|
594
|
+
{overlays}
|
|
595
|
+
{children}
|
|
596
|
+
</ul>
|
|
597
|
+
</MenuScopeContext.Provider>
|
|
598
|
+
)
|
|
599
|
+
|
|
600
|
+
return size ? <SizeProvider size={size}>{content}</SizeProvider> : content
|
|
601
|
+
},
|
|
602
|
+
)
|
|
603
|
+
SidebarMenu.displayName = 'SidebarMenu'
|
|
604
|
+
|
|
605
|
+
// ─── SidebarMenuItem / SidebarMenuSubItem ────────────────────────────────────
|
|
606
|
+
|
|
607
|
+
export interface SidebarMenuItemProps extends LiHTMLAttributes<HTMLLIElement> {
|
|
608
|
+
/** The row folds a `SidebarMenuSub` under it: its button toggles the sub-menu and shows a chevron. */
|
|
609
|
+
collapsible?: boolean
|
|
610
|
+
/** Controlled open state of a collapsible row's sub-menu. */
|
|
611
|
+
open?: boolean
|
|
612
|
+
/** Initial open state of a collapsible row's sub-menu. */
|
|
613
|
+
defaultOpen?: boolean
|
|
614
|
+
/** Called when a collapsible row opens or closes. */
|
|
615
|
+
onOpenChange?: (open: boolean) => void
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
function useMenuRow(
|
|
619
|
+
rowRef: MutableRefObject<HTMLLIElement | null>,
|
|
620
|
+
isSubRow = false,
|
|
621
|
+
sub?: Pick<SidebarMenuItemProps, 'collapsible' | 'open' | 'defaultOpen' | 'onOpenChange'>,
|
|
622
|
+
) {
|
|
623
|
+
const scope = useContext(MenuScopeContext)
|
|
624
|
+
const registerRow = scope?.registerRow
|
|
625
|
+
const setRowButton = scope?.setRowButton
|
|
626
|
+
const setRowActive = scope?.setRowActive
|
|
627
|
+
|
|
628
|
+
// The button's setActive effect can fire while this row's <li> ref is
|
|
629
|
+
// detached: a child's layout effects run before its parent's ref attaches
|
|
630
|
+
// — at mount, and on EVERY re-render whose inline ref identity changes
|
|
631
|
+
// (React detaches the old callback, nulling the ref, before the layout
|
|
632
|
+
// phase). The flag holds the truth through that window, and attachRow
|
|
633
|
+
// re-syncs the scope whenever the <li> lands.
|
|
634
|
+
const activeFlagRef = useRef(false)
|
|
635
|
+
|
|
636
|
+
useIsoLayoutEffect(() => {
|
|
637
|
+
const el = rowRef.current
|
|
638
|
+
if (!el || !registerRow) return
|
|
639
|
+
return registerRow(el)
|
|
640
|
+
}, [registerRow, rowRef])
|
|
641
|
+
|
|
642
|
+
/** The <li>'s ref callback: tracks the element and replays the active flag
|
|
643
|
+
* the scope may have missed while the ref was detached. */
|
|
644
|
+
const attachRow = useCallback(
|
|
645
|
+
(node: HTMLLIElement | null) => {
|
|
646
|
+
rowRef.current = node
|
|
647
|
+
if (node && setRowActive) setRowActive(node, activeFlagRef.current)
|
|
648
|
+
},
|
|
649
|
+
[setRowActive, rowRef],
|
|
650
|
+
)
|
|
651
|
+
|
|
652
|
+
const setActive = useCallback(
|
|
653
|
+
(active: boolean) => {
|
|
654
|
+
activeFlagRef.current = active
|
|
655
|
+
if (rowRef.current && setRowActive) setRowActive(rowRef.current, active)
|
|
656
|
+
},
|
|
657
|
+
[setRowActive, rowRef],
|
|
658
|
+
)
|
|
659
|
+
|
|
660
|
+
const setButtonEl = useCallback(
|
|
661
|
+
(el: HTMLElement | null) => {
|
|
662
|
+
if (rowRef.current && setRowButton) setRowButton(rowRef.current, el)
|
|
663
|
+
},
|
|
664
|
+
[setRowButton, rowRef],
|
|
665
|
+
)
|
|
666
|
+
|
|
667
|
+
const isHovered = rowRef.current !== null && scope?.hoveredRowEl === rowRef.current
|
|
668
|
+
const isActiveRow = rowRef.current !== null && (scope?.activeRows.includes(rowRef.current) ?? false)
|
|
669
|
+
|
|
670
|
+
const [trailing, setTrailing] = useState({
|
|
671
|
+
actionCount: 0,
|
|
672
|
+
actionsShowOnHover: false,
|
|
673
|
+
hasBadge: false,
|
|
674
|
+
})
|
|
675
|
+
const setActions = useCallback(
|
|
676
|
+
(count: number, showOnHover: boolean) =>
|
|
677
|
+
setTrailing(prev =>
|
|
678
|
+
prev.actionCount === count && prev.actionsShowOnHover === showOnHover
|
|
679
|
+
? prev
|
|
680
|
+
: { ...prev, actionCount: count, actionsShowOnHover: showOnHover },
|
|
681
|
+
),
|
|
682
|
+
[],
|
|
683
|
+
)
|
|
684
|
+
const setHasBadge = useCallback(
|
|
685
|
+
(hasBadge: boolean) => setTrailing(prev => (prev.hasBadge === hasBadge ? prev : { ...prev, hasBadge })),
|
|
686
|
+
[],
|
|
687
|
+
)
|
|
688
|
+
|
|
689
|
+
const [open, setOpen] = useControllableState(sub?.open, sub?.defaultOpen ?? false, sub?.onOpenChange)
|
|
690
|
+
const subOpen = sub?.collapsible ? open : undefined
|
|
691
|
+
const toggleSub = useCallback(() => setOpen(prev => !prev), [setOpen])
|
|
692
|
+
|
|
693
|
+
return useMemo(
|
|
694
|
+
() => ({
|
|
695
|
+
rowRef,
|
|
696
|
+
attachRow,
|
|
697
|
+
isHovered,
|
|
698
|
+
isActiveRow,
|
|
699
|
+
isSubRow,
|
|
700
|
+
setActive,
|
|
701
|
+
setButtonEl,
|
|
702
|
+
...trailing,
|
|
703
|
+
setActions,
|
|
704
|
+
setHasBadge,
|
|
705
|
+
subOpen,
|
|
706
|
+
toggleSub,
|
|
707
|
+
}),
|
|
708
|
+
[
|
|
709
|
+
rowRef,
|
|
710
|
+
attachRow,
|
|
711
|
+
isHovered,
|
|
712
|
+
isActiveRow,
|
|
713
|
+
isSubRow,
|
|
714
|
+
setActive,
|
|
715
|
+
setButtonEl,
|
|
716
|
+
trailing,
|
|
717
|
+
setActions,
|
|
718
|
+
setHasBadge,
|
|
719
|
+
subOpen,
|
|
720
|
+
toggleSub,
|
|
721
|
+
],
|
|
722
|
+
)
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
// ─── Trailing-gutter math ────────────────────────────────────────────────────
|
|
726
|
+
//
|
|
727
|
+
// The label reserves exactly the trailing run it has to clear, plus one gap
|
|
728
|
+
// — the same rule the section header's label follows, so a row's chevron and
|
|
729
|
+
// a section header's chevron each sit one 4px gap from their action run.
|
|
730
|
+
// A run is: the badge's 24px slot (rightmost when present), the action
|
|
731
|
+
// cluster (24px apiece, 4px between), and a gap where both appear.
|
|
732
|
+
const ROW_BASE_PAD = 8
|
|
733
|
+
const ROW_SLOT = 24
|
|
734
|
+
const ROW_GAP = 4
|
|
735
|
+
/** Where the run's rightmost element sits, measured from the row's right
|
|
736
|
+
* edge: a badge at right-2, an action cluster at right-1.5 (its wider box
|
|
737
|
+
* puts both on the same centre line). */
|
|
738
|
+
const ROW_BADGE_INSET = 8
|
|
739
|
+
const ROW_ACTION_INSET = 6
|
|
740
|
+
|
|
741
|
+
function rowGutter(actionCount: number, hasBadge: boolean) {
|
|
742
|
+
if (!actionCount && !hasBadge) return ROW_BASE_PAD
|
|
743
|
+
const actionsWidth = actionCount ? actionCount * ROW_SLOT + (actionCount - 1) * ROW_GAP : 0
|
|
744
|
+
const runWidth = (hasBadge ? ROW_SLOT : 0) + actionsWidth + (hasBadge && actionCount ? ROW_GAP : 0)
|
|
745
|
+
const inset = hasBadge ? ROW_BADGE_INSET : ROW_ACTION_INSET
|
|
746
|
+
return inset + runWidth + ROW_GAP
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
const SidebarMenuItem = forwardRef<HTMLLIElement, SidebarMenuItemProps>(
|
|
750
|
+
({ collapsible, open, defaultOpen, onOpenChange, className, children, ...props }, ref) => {
|
|
751
|
+
const rowRef = useRef<HTMLLIElement | null>(null)
|
|
752
|
+
const item = useMenuRow(rowRef, false, { collapsible, open, defaultOpen, onOpenChange })
|
|
753
|
+
const { attachRow } = item
|
|
754
|
+
// Stable ref callback: an inline one is detached and re-attached around
|
|
755
|
+
// every re-render, and child layout effects fire inside that null window.
|
|
756
|
+
const refCb = useCallback(
|
|
757
|
+
(node: HTMLLIElement | null) => {
|
|
758
|
+
attachRow(node)
|
|
759
|
+
if (typeof ref === 'function') ref(node)
|
|
760
|
+
else if (ref) (ref as React.MutableRefObject<HTMLLIElement | null>).current = node
|
|
761
|
+
},
|
|
762
|
+
[attachRow, ref],
|
|
763
|
+
)
|
|
764
|
+
return (
|
|
765
|
+
<MenuItemContext.Provider value={item}>
|
|
766
|
+
<li ref={refCb} data-sidebar="menu-item" className={cn('group/menu-item relative', className)} {...props}>
|
|
767
|
+
{children}
|
|
768
|
+
</li>
|
|
769
|
+
</MenuItemContext.Provider>
|
|
770
|
+
)
|
|
771
|
+
},
|
|
772
|
+
)
|
|
773
|
+
SidebarMenuItem.displayName = 'SidebarMenuItem'
|
|
774
|
+
|
|
775
|
+
export type SidebarMenuSubItemProps = LiHTMLAttributes<HTMLLIElement>
|
|
776
|
+
|
|
777
|
+
const SidebarMenuSubItem = forwardRef<HTMLLIElement, SidebarMenuSubItemProps>(
|
|
778
|
+
({ className, children, ...props }, ref) => {
|
|
779
|
+
const rowRef = useRef<HTMLLIElement | null>(null)
|
|
780
|
+
const item = useMenuRow(rowRef, true)
|
|
781
|
+
const { attachRow } = item
|
|
782
|
+
// Stable ref callback — same reason as SidebarMenuItem's.
|
|
783
|
+
const refCb = useCallback(
|
|
784
|
+
(node: HTMLLIElement | null) => {
|
|
785
|
+
attachRow(node)
|
|
786
|
+
if (typeof ref === 'function') ref(node)
|
|
787
|
+
else if (ref) (ref as React.MutableRefObject<HTMLLIElement | null>).current = node
|
|
788
|
+
},
|
|
789
|
+
[attachRow, ref],
|
|
790
|
+
)
|
|
791
|
+
return (
|
|
792
|
+
<MenuItemContext.Provider value={item}>
|
|
793
|
+
<li
|
|
794
|
+
ref={refCb}
|
|
795
|
+
data-sidebar="menu-sub-item"
|
|
796
|
+
className={cn('group/menu-sub-item relative', className)}
|
|
797
|
+
{...props}
|
|
798
|
+
>
|
|
799
|
+
{children}
|
|
800
|
+
</li>
|
|
801
|
+
</MenuItemContext.Provider>
|
|
802
|
+
)
|
|
803
|
+
},
|
|
804
|
+
)
|
|
805
|
+
SidebarMenuSubItem.displayName = 'SidebarMenuSubItem'
|
|
806
|
+
|
|
807
|
+
// ─── Row label (ghost-span weight animation) ─────────────────────────────────
|
|
808
|
+
|
|
809
|
+
/** Splits leading string children out as the label so it can get the
|
|
810
|
+
* ghost-span weight treatment; remaining element children (dots, trailing
|
|
811
|
+
* icons) render as flex siblings after it — outside the text-box-trimmed
|
|
812
|
+
* span, which would clip an inline SVG, and where `ml-auto` can push a
|
|
813
|
+
* trailing control to the row's end. */
|
|
814
|
+
function MenuRowLabel({
|
|
815
|
+
content,
|
|
816
|
+
lit,
|
|
817
|
+
emphasized,
|
|
818
|
+
textClass,
|
|
819
|
+
}: {
|
|
820
|
+
content: ReactNode
|
|
821
|
+
lit: boolean
|
|
822
|
+
emphasized: boolean
|
|
823
|
+
textClass: string
|
|
824
|
+
}) {
|
|
825
|
+
const nodes = Children.toArray(content)
|
|
826
|
+
const textParts: string[] = []
|
|
827
|
+
let i = 0
|
|
828
|
+
while (i < nodes.length && (typeof nodes[i] === 'string' || typeof nodes[i] === 'number')) {
|
|
829
|
+
textParts.push(String(nodes[i]))
|
|
830
|
+
i++
|
|
831
|
+
}
|
|
832
|
+
const label = textParts.join('')
|
|
833
|
+
const rest = nodes.slice(i)
|
|
834
|
+
|
|
835
|
+
if (!label) {
|
|
836
|
+
return (
|
|
837
|
+
<span
|
|
838
|
+
className={cn(
|
|
839
|
+
'flex min-w-0 flex-1 items-center gap-2 transition-colors duration-fast',
|
|
840
|
+
lit ? 'text-foreground' : 'text-muted-foreground',
|
|
841
|
+
textClass,
|
|
842
|
+
)}
|
|
843
|
+
>
|
|
844
|
+
{content}
|
|
845
|
+
</span>
|
|
846
|
+
)
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
return (
|
|
850
|
+
<>
|
|
851
|
+
<span className={cn('inline-grid min-w-0 text-left', textClass)}>
|
|
852
|
+
{/* Ghost: reserves width at the heaviest weight, hidden from AT.
|
|
853
|
+
Both cells truncate so a long label clips with an ellipsis
|
|
854
|
+
instead of wrapping the row. The trim box spans cap height to
|
|
855
|
+
baseline, so the overflow clip would shave ascenders and
|
|
856
|
+
descenders — symmetric padding extends the clip box past both
|
|
857
|
+
and the negative margins cancel it out of the row's height. */}
|
|
858
|
+
<span
|
|
859
|
+
className="col-start-1 row-start-1 invisible truncate pt-[0.25em] -mt-[0.25em] pb-[0.25em] -mb-[0.25em] weight-semibold [text-box:trim-both_cap_alphabetic]"
|
|
860
|
+
aria-hidden="true"
|
|
861
|
+
>
|
|
862
|
+
{label}
|
|
863
|
+
</span>
|
|
864
|
+
{/* Visible: animates between weights in the same cell */}
|
|
865
|
+
<span
|
|
866
|
+
className={cn(
|
|
867
|
+
'col-start-1 row-start-1 truncate pt-[0.25em] -mt-[0.25em] pb-[0.25em] -mb-[0.25em] transition-[color,font-variation-settings] duration-fast [text-box:trim-both_cap_alphabetic]',
|
|
868
|
+
lit ? 'text-foreground' : 'text-muted-foreground',
|
|
869
|
+
emphasized ? 'weight-semibold' : 'weight-normal',
|
|
870
|
+
)}
|
|
871
|
+
>
|
|
872
|
+
{label}
|
|
873
|
+
</span>
|
|
874
|
+
</span>
|
|
875
|
+
{rest}
|
|
876
|
+
</>
|
|
877
|
+
)
|
|
878
|
+
}
|
|
879
|
+
|
|
880
|
+
// ─── SidebarMenuButton ───────────────────────────────────────────────────────
|
|
881
|
+
|
|
882
|
+
export interface SidebarMenuButtonProps
|
|
883
|
+
extends ButtonHTMLAttributes<HTMLButtonElement>,
|
|
884
|
+
VariantProps<typeof sidebarMenuButtonVariants> {
|
|
885
|
+
isActive?: boolean
|
|
886
|
+
size?: 'default' | 'sm' | 'lg'
|
|
887
|
+
icon?: IconComponent
|
|
888
|
+
/** Semantic thread state for status-dot navigation. Drives the dot
|
|
889
|
+
* visuals (`active`/`unread` → filled, `idle` → ring), stamps
|
|
890
|
+
* `data-status` on the button, appends visually-hidden "unread" text for
|
|
891
|
+
* screen readers, and `"active"` implies `isActive`. */
|
|
892
|
+
status?: 'active' | 'unread' | 'idle'
|
|
893
|
+
/** Visual-only dot in the icon column — the escape hatch when the
|
|
894
|
+
* semantic `status` vocabulary doesn't fit. Overrides the dot derived
|
|
895
|
+
* from `status`. Ignored when `icon` is set. */
|
|
896
|
+
dot?: 'filled' | 'ring'
|
|
897
|
+
/** Selection key: the row is active while the surrounding `Sidebar`'s
|
|
898
|
+
* `value` matches it, and pressing it selects it. With a `value`,
|
|
899
|
+
* `status="active"` no longer implies the active row. */
|
|
900
|
+
value?: string
|
|
901
|
+
render?: ReactElement
|
|
902
|
+
asChild?: boolean
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
const SidebarMenuButton = forwardRef<HTMLButtonElement, SidebarMenuButtonProps>(
|
|
906
|
+
(
|
|
907
|
+
{
|
|
908
|
+
isActive = false,
|
|
909
|
+
size = 'default',
|
|
910
|
+
variant,
|
|
911
|
+
icon: Icon,
|
|
912
|
+
status,
|
|
913
|
+
dot,
|
|
914
|
+
value,
|
|
915
|
+
render,
|
|
916
|
+
asChild,
|
|
917
|
+
className,
|
|
918
|
+
style,
|
|
919
|
+
onClick,
|
|
920
|
+
children,
|
|
921
|
+
...props
|
|
922
|
+
},
|
|
923
|
+
ref,
|
|
924
|
+
) => {
|
|
925
|
+
const scope = useContext(MenuScopeContext)
|
|
926
|
+
const item = useContext(MenuItemContext)
|
|
927
|
+
const selection = useContext(SidebarSelection)
|
|
928
|
+
const shape = useShape()
|
|
929
|
+
const sizeClasses = useSize()
|
|
930
|
+
const buttonRef = useRef<HTMLElement | null>(null)
|
|
931
|
+
const ChevronRightIcon = useIcon('chevron-right')
|
|
932
|
+
const subOpen = item?.subOpen
|
|
933
|
+
const collapsible = subOpen !== undefined
|
|
934
|
+
|
|
935
|
+
// status="active" implies the row-active treatment, unless a `value`
|
|
936
|
+
// hands the choice to the sidebar's selection; an explicit dot overrides
|
|
937
|
+
// the status-derived one.
|
|
938
|
+
const effectiveActive = isActive || (value === undefined ? status === 'active' : selection?.value === value)
|
|
939
|
+
|
|
940
|
+
const setActive = item?.setActive
|
|
941
|
+
useIsoLayoutEffect(() => {
|
|
942
|
+
setActive?.(effectiveActive)
|
|
943
|
+
return () => setActive?.(false)
|
|
944
|
+
}, [effectiveActive, setActive])
|
|
945
|
+
|
|
946
|
+
const setButtonEl = item?.setButtonEl
|
|
947
|
+
useIsoLayoutEffect(() => {
|
|
948
|
+
setButtonEl?.(buttonRef.current)
|
|
949
|
+
return () => setButtonEl?.(null)
|
|
950
|
+
}, [setButtonEl])
|
|
951
|
+
const resolvedDot = dot ?? (status ? (status === 'idle' ? 'ring' : 'filled') : undefined)
|
|
952
|
+
const lit = effectiveActive || (item?.isHovered ?? false)
|
|
953
|
+
const heightClass =
|
|
954
|
+
size === 'sm' ? 'h-7' : size === 'lg' ? 'h-12' : sizeClasses.variant === 'compact' ? 'h-7' : 'h-8'
|
|
955
|
+
const textClass = size === 'sm' ? 'text-body-compact' : sizeClasses.text
|
|
956
|
+
|
|
957
|
+
// Roving tabindex: the active rows' buttons are the menu's tab stops; with
|
|
958
|
+
// no active row, the menu's first row keeps it keyboard-reachable.
|
|
959
|
+
const row = item?.rowRef.current ?? null
|
|
960
|
+
const tabIdx = effectiveActive ? 0 : scope?.hasActive ? -1 : row !== null && row === scope?.firstRowEl ? 0 : -1
|
|
961
|
+
|
|
962
|
+
// Exact trailing reservation: at rest, hover-revealed actions claim no
|
|
963
|
+
// width (the label owns the row); once revealed the row widens to
|
|
964
|
+
// --row-gutter-hover.
|
|
965
|
+
const gutterHover = rowGutter(item?.actionCount ?? 0, item?.hasBadge ?? false)
|
|
966
|
+
const gutterRest = item?.actionsShowOnHover ? rowGutter(0, item?.hasBadge ?? false) : gutterHover
|
|
967
|
+
const gutterVars = {
|
|
968
|
+
'--row-gutter': `${gutterRest}px`,
|
|
969
|
+
'--row-gutter-hover': `${gutterHover}px`,
|
|
970
|
+
} as CSSProperties
|
|
971
|
+
|
|
972
|
+
const { template, content } = resolveSlotTemplate(render, asChild, children)
|
|
973
|
+
|
|
974
|
+
const inner = (
|
|
975
|
+
<>
|
|
976
|
+
{Icon && (
|
|
977
|
+
<Icon
|
|
978
|
+
size={sizeClasses.icon}
|
|
979
|
+
strokeWidth={lit ? 2 : 1.5}
|
|
980
|
+
className={cn(
|
|
981
|
+
'shrink-0 transition-[color,stroke-width] duration-fast',
|
|
982
|
+
lit ? 'text-foreground' : 'text-muted-foreground',
|
|
983
|
+
)}
|
|
984
|
+
/>
|
|
985
|
+
)}
|
|
986
|
+
{!Icon && resolvedDot && (
|
|
987
|
+
<span
|
|
988
|
+
className="flex shrink-0 items-center justify-center"
|
|
989
|
+
style={{ width: sizeClasses.icon, height: sizeClasses.icon }}
|
|
990
|
+
>
|
|
991
|
+
<span
|
|
992
|
+
className={cn(
|
|
993
|
+
'size-2 rounded-full transition-colors duration-fast',
|
|
994
|
+
resolvedDot === 'filled'
|
|
995
|
+
? lit
|
|
996
|
+
? 'bg-foreground/60'
|
|
997
|
+
: 'bg-muted-foreground/50'
|
|
998
|
+
: lit
|
|
999
|
+
? 'border border-foreground/60'
|
|
1000
|
+
: 'border border-muted-foreground/50',
|
|
1001
|
+
)}
|
|
1002
|
+
/>
|
|
1003
|
+
</span>
|
|
1004
|
+
)}
|
|
1005
|
+
<MenuRowLabel content={content} lit={lit} emphasized={effectiveActive} textClass={textClass} />
|
|
1006
|
+
{status === 'unread' && <span className="sr-only">, unread</span>}
|
|
1007
|
+
{/* At rest the chevron shows only on a closed row, so an open tree isn't a column of arrows. */}
|
|
1008
|
+
{collapsible && (
|
|
1009
|
+
<span className="ml-auto -mr-0.5 flex size-6 shrink-0 items-center justify-center">
|
|
1010
|
+
<motion.span className="inline-flex" animate={{ rotate: subOpen ? 90 : 0 }} transition={spring.fast}>
|
|
1011
|
+
<ChevronRightIcon
|
|
1012
|
+
size={sizeClasses.icon}
|
|
1013
|
+
strokeWidth={1.5}
|
|
1014
|
+
className={cn(
|
|
1015
|
+
'text-muted-foreground transition-opacity duration-fast',
|
|
1016
|
+
subOpen
|
|
1017
|
+
? 'opacity-0 group-hover/parent-row:opacity-100 group-focus-within/parent-row:opacity-100'
|
|
1018
|
+
: 'opacity-100',
|
|
1019
|
+
)}
|
|
1020
|
+
/>
|
|
1021
|
+
</motion.span>
|
|
1022
|
+
</span>
|
|
1023
|
+
)}
|
|
1024
|
+
</>
|
|
1025
|
+
)
|
|
1026
|
+
|
|
1027
|
+
return slotElement(
|
|
1028
|
+
template,
|
|
1029
|
+
'button',
|
|
1030
|
+
{
|
|
1031
|
+
ref: (node: HTMLElement | null) => {
|
|
1032
|
+
buttonRef.current = node
|
|
1033
|
+
if (typeof ref === 'function') ref(node as HTMLButtonElement | null)
|
|
1034
|
+
else if (ref) (ref as React.MutableRefObject<HTMLElement | null>).current = node
|
|
1035
|
+
},
|
|
1036
|
+
type: template ? undefined : 'button',
|
|
1037
|
+
'data-sidebar': 'menu-button',
|
|
1038
|
+
'data-size': size,
|
|
1039
|
+
'data-active': effectiveActive ? 'true' : undefined,
|
|
1040
|
+
'data-status': status,
|
|
1041
|
+
'aria-current': effectiveActive ? 'page' : undefined,
|
|
1042
|
+
'aria-expanded': subOpen,
|
|
1043
|
+
tabIndex: tabIdx,
|
|
1044
|
+
className: cn(
|
|
1045
|
+
sidebarMenuButtonVariants({ variant }),
|
|
1046
|
+
heightClass,
|
|
1047
|
+
shape.item,
|
|
1048
|
+
collapsible && 'group/parent-row',
|
|
1049
|
+
className,
|
|
1050
|
+
),
|
|
1051
|
+
onClick: (event: MouseEvent<HTMLButtonElement>) => {
|
|
1052
|
+
onClick?.(event)
|
|
1053
|
+
if (collapsible) item?.toggleSub()
|
|
1054
|
+
else if (value !== undefined) selection?.select(value)
|
|
1055
|
+
},
|
|
1056
|
+
...props,
|
|
1057
|
+
// The chevron takes the trailing slot, so a collapsible row keeps the
|
|
1058
|
+
// widened gutter at rest.
|
|
1059
|
+
style: {
|
|
1060
|
+
...gutterVars,
|
|
1061
|
+
...(collapsible ? ({ '--row-gutter': 'var(--row-gutter-hover)' } as CSSProperties) : {}),
|
|
1062
|
+
...style,
|
|
1063
|
+
},
|
|
1064
|
+
},
|
|
1065
|
+
inner,
|
|
1066
|
+
)
|
|
1067
|
+
},
|
|
1068
|
+
)
|
|
1069
|
+
SidebarMenuButton.displayName = 'SidebarMenuButton'
|
|
1070
|
+
|
|
1071
|
+
// ─── SidebarMenuAction ───────────────────────────────────────────────────────
|
|
1072
|
+
|
|
1073
|
+
export interface SidebarMenuActionProps extends ButtonHTMLAttributes<HTMLButtonElement> {
|
|
1074
|
+
showOnHover?: boolean
|
|
1075
|
+
render?: ReactElement
|
|
1076
|
+
asChild?: boolean
|
|
1077
|
+
}
|
|
1078
|
+
|
|
1079
|
+
const SidebarMenuAction = forwardRef<HTMLButtonElement, SidebarMenuActionProps>(
|
|
1080
|
+
({ className, showOnHover = false, render, asChild, children, onClick, ...props }, ref) => {
|
|
1081
|
+
const shape = useShape()
|
|
1082
|
+
const sizeClasses = useSize()
|
|
1083
|
+
const item = useContext(MenuItemContext)
|
|
1084
|
+
const inCluster = useContext(MenuActionsClusterContext)
|
|
1085
|
+
const { template, content } = resolveSlotTemplate(render, asChild, children)
|
|
1086
|
+
|
|
1087
|
+
// A lone action registers its own slot; inside a cluster the wrapper
|
|
1088
|
+
// registers the whole count and each action flows in its row.
|
|
1089
|
+
const setActions = item?.setActions
|
|
1090
|
+
useIsoLayoutEffect(() => {
|
|
1091
|
+
if (inCluster || !setActions) return
|
|
1092
|
+
setActions(1, showOnHover)
|
|
1093
|
+
return () => setActions(0, false)
|
|
1094
|
+
}, [inCluster, setActions, showOnHover])
|
|
1095
|
+
return slotElement(
|
|
1096
|
+
template,
|
|
1097
|
+
'button',
|
|
1098
|
+
{
|
|
1099
|
+
ref: ref as Ref<HTMLElement>,
|
|
1100
|
+
type: template ? undefined : 'button',
|
|
1101
|
+
'data-sidebar': 'menu-action',
|
|
1102
|
+
'data-show-on-hover': showOnHover ? '' : undefined,
|
|
1103
|
+
className: cn(
|
|
1104
|
+
// right-1.5 centers the 24px hit-box on the same axis as the badge
|
|
1105
|
+
// (right-2 + min-w-5): both land 18px from the row's right edge.
|
|
1106
|
+
// With a badge on the same row the badge keeps that rightmost spot
|
|
1107
|
+
// and the action slides left of it. Inside a cluster the wrapper
|
|
1108
|
+
// owns the positioning and actions simply flow.
|
|
1109
|
+
inCluster
|
|
1110
|
+
? 'relative flex size-6 shrink-0 items-center justify-center text-muted-foreground outline-none'
|
|
1111
|
+
: 'absolute right-1.5 z-10 flex size-6 items-center justify-center text-muted-foreground outline-none',
|
|
1112
|
+
!inCluster &&
|
|
1113
|
+
(item?.isSubRow
|
|
1114
|
+
? 'group-has-[>[data-sidebar=menu-badge]]/menu-sub-item:right-8.5'
|
|
1115
|
+
: 'group-has-[>[data-sidebar=menu-badge]]/menu-item:right-8.5'),
|
|
1116
|
+
!inCluster && (item?.isSubRow || sizeClasses.variant === 'compact' ? 'top-0.5' : 'top-1'),
|
|
1117
|
+
'hover:bg-hover hover:text-foreground transition-[color,background-color,opacity] duration-fast',
|
|
1118
|
+
'focus-visible:ring-1 focus-visible:ring-focus-ring',
|
|
1119
|
+
// One icon size across the sidebar: row actions match the leading
|
|
1120
|
+
// icons and the section header's actions, all on the size ladder.
|
|
1121
|
+
// Normalize bare icons to the site's 1.5 stroke (library defaults
|
|
1122
|
+
// vary), thickening to 2 on hover — Button's icon-only treatment.
|
|
1123
|
+
'[&_svg]:size-[var(--icon-size)] [&_svg]:shrink-0 [&_svg]:stroke-[1.5] [&_svg]:transition-[stroke-width] [&_svg]:duration-fast hover:[&_svg]:stroke-[2]',
|
|
1124
|
+
shape.item,
|
|
1125
|
+
// Reveal on the OWN row only. A sub action must not use the
|
|
1126
|
+
// menu-item group — its nearest one is the parent li, which would
|
|
1127
|
+
// light every sibling sub action on any hover inside the sub-tree.
|
|
1128
|
+
!inCluster &&
|
|
1129
|
+
showOnHover &&
|
|
1130
|
+
(item?.isSubRow
|
|
1131
|
+
? 'opacity-0 group-hover/menu-sub-item:opacity-100 group-focus-within/menu-sub-item:opacity-100 data-[state=open]:opacity-100 aria-expanded:opacity-100'
|
|
1132
|
+
: // Tracks the row's own button (its peer), not the <li> — a row
|
|
1133
|
+
// that hosts a sub-menu wraps its children too, and hovering a
|
|
1134
|
+
// child should not light the parent's action.
|
|
1135
|
+
'opacity-0 peer-hover/menu-button:opacity-100 peer-focus-visible/menu-button:opacity-100 hover:opacity-100 focus-visible:opacity-100 data-[state=open]:opacity-100 aria-expanded:opacity-100'),
|
|
1136
|
+
className,
|
|
1137
|
+
),
|
|
1138
|
+
onClick: (event: React.MouseEvent<HTMLButtonElement>) => {
|
|
1139
|
+
// The action often sits on a row composed via `render` — keep its
|
|
1140
|
+
// click from also triggering the row.
|
|
1141
|
+
event.stopPropagation()
|
|
1142
|
+
onClick?.(event)
|
|
1143
|
+
},
|
|
1144
|
+
...props,
|
|
1145
|
+
style: { ...({ '--icon-size': `${sizeClasses.icon}px` } as CSSProperties), ...(props.style ?? {}) },
|
|
1146
|
+
},
|
|
1147
|
+
content,
|
|
1148
|
+
)
|
|
1149
|
+
},
|
|
1150
|
+
)
|
|
1151
|
+
SidebarMenuAction.displayName = 'SidebarMenuAction'
|
|
1152
|
+
|
|
1153
|
+
// ─── SidebarMenuActions ──────────────────────────────────────────────────────
|
|
1154
|
+
|
|
1155
|
+
export interface SidebarMenuActionsProps extends HTMLAttributes<HTMLDivElement> {
|
|
1156
|
+
/** Hide the cluster until the row is hovered or focused. */
|
|
1157
|
+
showOnHover?: boolean
|
|
1158
|
+
}
|
|
1159
|
+
|
|
1160
|
+
/** Row-level cluster for more than one SidebarMenuAction. It owns the
|
|
1161
|
+
* positioning and publishes the whole count to the row, so the button
|
|
1162
|
+
* reserves the exact gutter the cluster occupies. */
|
|
1163
|
+
const SidebarMenuActions = forwardRef<HTMLDivElement, SidebarMenuActionsProps>(
|
|
1164
|
+
({ className, showOnHover = false, children, ...props }, ref) => {
|
|
1165
|
+
const item = useContext(MenuItemContext)
|
|
1166
|
+
const sizeClasses = useSize()
|
|
1167
|
+
const count = Children.count(children)
|
|
1168
|
+
|
|
1169
|
+
const setActions = item?.setActions
|
|
1170
|
+
useIsoLayoutEffect(() => {
|
|
1171
|
+
setActions?.(count, showOnHover)
|
|
1172
|
+
return () => setActions?.(0, false)
|
|
1173
|
+
}, [setActions, count, showOnHover])
|
|
1174
|
+
|
|
1175
|
+
return (
|
|
1176
|
+
<div
|
|
1177
|
+
ref={ref}
|
|
1178
|
+
data-sidebar="menu-actions"
|
|
1179
|
+
className={cn(
|
|
1180
|
+
'absolute right-1.5 z-10 flex items-center gap-1',
|
|
1181
|
+
// The badge keeps the rightmost slot; the cluster sits left of it.
|
|
1182
|
+
item?.isSubRow
|
|
1183
|
+
? 'group-has-[>[data-sidebar=menu-badge]]/menu-sub-item:right-8.5'
|
|
1184
|
+
: 'group-has-[>[data-sidebar=menu-badge]]/menu-item:right-8.5',
|
|
1185
|
+
item?.isSubRow || sizeClasses.variant === 'compact' ? 'top-0.5' : 'top-1',
|
|
1186
|
+
showOnHover &&
|
|
1187
|
+
(item?.isSubRow
|
|
1188
|
+
? 'opacity-0 transition-opacity duration-fast group-hover/menu-sub-item:opacity-100 group-focus-within/menu-sub-item:opacity-100 has-[[data-state=open]]:opacity-100 has-[[data-popup-open]]:opacity-100'
|
|
1189
|
+
: // Peer-scoped for the same reason as a lone action: the row's
|
|
1190
|
+
// <li> also wraps its sub-menu.
|
|
1191
|
+
'opacity-0 transition-opacity duration-fast peer-hover/menu-button:opacity-100 peer-focus-visible/menu-button:opacity-100 hover:opacity-100 focus-within:opacity-100 has-[[data-state=open]]:opacity-100 has-[[data-popup-open]]:opacity-100'),
|
|
1192
|
+
className,
|
|
1193
|
+
)}
|
|
1194
|
+
{...props}
|
|
1195
|
+
>
|
|
1196
|
+
<MenuActionsClusterContext.Provider value={true}>{children}</MenuActionsClusterContext.Provider>
|
|
1197
|
+
</div>
|
|
1198
|
+
)
|
|
1199
|
+
},
|
|
1200
|
+
)
|
|
1201
|
+
SidebarMenuActions.displayName = 'SidebarMenuActions'
|
|
1202
|
+
|
|
1203
|
+
// ─── SidebarMenuBadge ────────────────────────────────────────────────────────
|
|
1204
|
+
|
|
1205
|
+
export type SidebarMenuBadgeProps = HTMLAttributes<HTMLDivElement>
|
|
1206
|
+
|
|
1207
|
+
const SidebarMenuBadge = forwardRef<HTMLDivElement, SidebarMenuBadgeProps>(({ className, ...props }, ref) => {
|
|
1208
|
+
const item = useContext(MenuItemContext)
|
|
1209
|
+
const sizeClasses = useSize()
|
|
1210
|
+
const lit = item?.isActiveRow ?? false
|
|
1211
|
+
|
|
1212
|
+
const setHasBadge = item?.setHasBadge
|
|
1213
|
+
useIsoLayoutEffect(() => {
|
|
1214
|
+
setHasBadge?.(true)
|
|
1215
|
+
return () => setHasBadge?.(false)
|
|
1216
|
+
}, [setHasBadge])
|
|
1217
|
+
return (
|
|
1218
|
+
<div
|
|
1219
|
+
ref={ref}
|
|
1220
|
+
data-sidebar="menu-badge"
|
|
1221
|
+
className={cn(
|
|
1222
|
+
'pointer-events-none absolute right-2 z-10 flex h-5 min-w-5 items-center justify-center px-1 tabular-nums',
|
|
1223
|
+
sizeClasses.variant === 'compact' ? 'top-1 text-micro-compact' : 'top-1.5 text-micro',
|
|
1224
|
+
'transition-[color,font-variation-settings] duration-fast',
|
|
1225
|
+
lit ? 'text-foreground weight-semibold' : 'text-muted-foreground weight-normal',
|
|
1226
|
+
className,
|
|
1227
|
+
)}
|
|
1228
|
+
{...props}
|
|
1229
|
+
/>
|
|
1230
|
+
)
|
|
1231
|
+
})
|
|
1232
|
+
SidebarMenuBadge.displayName = 'SidebarMenuBadge'
|
|
1233
|
+
|
|
1234
|
+
// ─── SidebarMenuSkeleton ─────────────────────────────────────────────────────
|
|
1235
|
+
|
|
1236
|
+
export interface SidebarMenuSkeletonProps extends HTMLAttributes<HTMLDivElement> {
|
|
1237
|
+
showIcon?: boolean
|
|
1238
|
+
}
|
|
1239
|
+
|
|
1240
|
+
// Deterministic width cycle (not Math.random) so server and client render the
|
|
1241
|
+
// same markup — a random width per render is a hydration mismatch.
|
|
1242
|
+
const SKELETON_WIDTHS = ['62%', '74%', '55%', '82%', '68%']
|
|
1243
|
+
|
|
1244
|
+
const SidebarMenuSkeleton = forwardRef<HTMLDivElement, SidebarMenuSkeletonProps>(
|
|
1245
|
+
({ className, showIcon = false, ...props }, ref) => {
|
|
1246
|
+
const sizeClasses = useSize()
|
|
1247
|
+
const id = useId()
|
|
1248
|
+
let sum = 0
|
|
1249
|
+
for (let i = 0; i < id.length; i++) sum += id.charCodeAt(i)
|
|
1250
|
+
const width = SKELETON_WIDTHS[sum % SKELETON_WIDTHS.length]
|
|
1251
|
+
return (
|
|
1252
|
+
<div
|
|
1253
|
+
ref={ref}
|
|
1254
|
+
data-sidebar="menu-skeleton"
|
|
1255
|
+
className={cn('flex items-center gap-2 px-2', sizeClasses.variant === 'compact' ? 'h-7' : 'h-8', className)}
|
|
1256
|
+
{...props}
|
|
1257
|
+
>
|
|
1258
|
+
{showIcon && (
|
|
1259
|
+
<div data-sidebar="menu-skeleton-icon" className="size-4 shrink-0 animate-pulse rounded-md bg-hover" />
|
|
1260
|
+
)}
|
|
1261
|
+
<div
|
|
1262
|
+
data-sidebar="menu-skeleton-text"
|
|
1263
|
+
className="h-4 flex-1 animate-pulse rounded-md bg-hover"
|
|
1264
|
+
style={{ maxWidth: width }}
|
|
1265
|
+
/>
|
|
1266
|
+
</div>
|
|
1267
|
+
)
|
|
1268
|
+
},
|
|
1269
|
+
)
|
|
1270
|
+
SidebarMenuSkeleton.displayName = 'SidebarMenuSkeleton'
|
|
1271
|
+
|
|
1272
|
+
// ─── SidebarMenuSub ──────────────────────────────────────────────────────────
|
|
1273
|
+
|
|
1274
|
+
export interface SidebarMenuSubProps extends HTMLAttributes<HTMLUListElement> {
|
|
1275
|
+
/** Built-in measured-height collapse. Omitted, the sub-menu follows its
|
|
1276
|
+
* `collapsible` row's state, or stays visible without one. */
|
|
1277
|
+
open?: boolean
|
|
1278
|
+
}
|
|
1279
|
+
|
|
1280
|
+
const SidebarMenuSub = forwardRef<HTMLUListElement, SidebarMenuSubProps>(
|
|
1281
|
+
({ className, open: openProp, children, ...props }, ref) => {
|
|
1282
|
+
const containerRef = useRef<HTMLUListElement | null>(null)
|
|
1283
|
+
const row = useContext(MenuItemContext)
|
|
1284
|
+
const open = openProp ?? row?.subOpen ?? true
|
|
1285
|
+
// The sub-menu is NOT its own highlight scope: its rows register with the
|
|
1286
|
+
// surrounding SidebarMenu, so one hover background glides from a parent
|
|
1287
|
+
// row into its children. Toggling flips the rows' visibility in place
|
|
1288
|
+
// (they stay registered), so the scope re-reads what is visible.
|
|
1289
|
+
const scope = useContext(MenuScopeContext)
|
|
1290
|
+
const refreshVisibility = scope?.refreshVisibility
|
|
1291
|
+
useIsoLayoutEffect(() => {
|
|
1292
|
+
refreshVisibility?.()
|
|
1293
|
+
}, [open, refreshVisibility])
|
|
1294
|
+
|
|
1295
|
+
// Measured-height collapse: animate between 0 and the content's real
|
|
1296
|
+
// offsetHeight — never to "auto", which framer measures wrong under a
|
|
1297
|
+
// scaled ancestor.
|
|
1298
|
+
const [contentHeight, setContentHeight] = useState<number | null>(null)
|
|
1299
|
+
useIsoLayoutEffect(() => {
|
|
1300
|
+
const el = containerRef.current
|
|
1301
|
+
if (!el || typeof ResizeObserver === 'undefined') return
|
|
1302
|
+
const measure = () => setContentHeight(el.offsetHeight)
|
|
1303
|
+
measure()
|
|
1304
|
+
const ro = new ResizeObserver(measure)
|
|
1305
|
+
ro.observe(el)
|
|
1306
|
+
return () => ro.disconnect()
|
|
1307
|
+
}, [])
|
|
1308
|
+
const measured = contentHeight !== null
|
|
1309
|
+
|
|
1310
|
+
// Same rule as SidebarGroup: spring only when this sub-tree itself
|
|
1311
|
+
// toggles. A height change coming from a nested sub collapsing inside it
|
|
1312
|
+
// snaps, so the wrapper tracks its content instead of chasing it with a
|
|
1313
|
+
// second spring and moving everything below late.
|
|
1314
|
+
const prevOpenRef = useRef(open)
|
|
1315
|
+
const togglingRef = useRef(false)
|
|
1316
|
+
if (prevOpenRef.current !== open) {
|
|
1317
|
+
prevOpenRef.current = open
|
|
1318
|
+
togglingRef.current = true
|
|
1319
|
+
}
|
|
1320
|
+
|
|
1321
|
+
return (
|
|
1322
|
+
<motion.div
|
|
1323
|
+
data-slot="sidebar-menu-sub-wrapper"
|
|
1324
|
+
// `animate` stays defined from the first render — framer ignores an
|
|
1325
|
+
// animate prop that appears later in the element's life. Until the
|
|
1326
|
+
// content is measured, a closed sub collapses via the h-0 class and
|
|
1327
|
+
// an open one keeps its natural height.
|
|
1328
|
+
className={cn('overflow-hidden', !measured && !open && 'h-0')}
|
|
1329
|
+
initial={false}
|
|
1330
|
+
animate={measured ? { height: open ? contentHeight : 0, opacity: open ? 1 : 0 } : { opacity: open ? 1 : 0 }}
|
|
1331
|
+
// Do NOT simplify this to `open ? spring.moderate : …` — see the
|
|
1332
|
+
// togglingRef note above. Springing on a re-measure stacks a second
|
|
1333
|
+
// spring on a nested sub's own collapse.
|
|
1334
|
+
transition={togglingRef.current ? (open ? spring.moderate : spring.moderate.exit) : { duration: 0 }}
|
|
1335
|
+
onAnimationComplete={() => {
|
|
1336
|
+
togglingRef.current = false
|
|
1337
|
+
}}
|
|
1338
|
+
>
|
|
1339
|
+
<ul
|
|
1340
|
+
ref={node => {
|
|
1341
|
+
containerRef.current = node
|
|
1342
|
+
if (typeof ref === 'function') ref(node)
|
|
1343
|
+
else if (ref) (ref as React.MutableRefObject<HTMLUListElement | null>).current = node
|
|
1344
|
+
}}
|
|
1345
|
+
data-sidebar="menu-sub"
|
|
1346
|
+
data-state={open ? 'open' : 'closed'}
|
|
1347
|
+
aria-hidden={open ? undefined : true}
|
|
1348
|
+
{...inertProps(!open)}
|
|
1349
|
+
className={cn(
|
|
1350
|
+
// ml-[15px] (a margin, not a translate, so the rows' measured
|
|
1351
|
+
// rects include it) + 1px border + pl-2 lands the sub-row label
|
|
1352
|
+
// (+ the row's own pl-2 = 32px) exactly on the parent label's x
|
|
1353
|
+
// (px-2 + 16px icon + gap-2 = 32px).
|
|
1354
|
+
'relative ml-[15px] flex min-w-0 flex-col border-l border-border pl-2 select-none',
|
|
1355
|
+
className,
|
|
1356
|
+
)}
|
|
1357
|
+
{...props}
|
|
1358
|
+
>
|
|
1359
|
+
{children}
|
|
1360
|
+
</ul>
|
|
1361
|
+
</motion.div>
|
|
1362
|
+
)
|
|
1363
|
+
},
|
|
1364
|
+
)
|
|
1365
|
+
SidebarMenuSub.displayName = 'SidebarMenuSub'
|
|
1366
|
+
|
|
1367
|
+
// ─── SidebarMenuSubButton ────────────────────────────────────────────────────
|
|
1368
|
+
|
|
1369
|
+
export interface SidebarMenuSubButtonProps extends AnchorHTMLAttributes<HTMLAnchorElement> {
|
|
1370
|
+
isActive?: boolean
|
|
1371
|
+
size?: 'sm' | 'md'
|
|
1372
|
+
icon?: IconComponent
|
|
1373
|
+
/** Selection key, as on `SidebarMenuButton`. Without an `href` the row renders a button. */
|
|
1374
|
+
value?: string
|
|
1375
|
+
render?: ReactElement
|
|
1376
|
+
asChild?: boolean
|
|
1377
|
+
}
|
|
1378
|
+
|
|
1379
|
+
const SidebarMenuSubButton = forwardRef<HTMLAnchorElement, SidebarMenuSubButtonProps>(
|
|
1380
|
+
(
|
|
1381
|
+
{
|
|
1382
|
+
isActive: isActiveProp = false,
|
|
1383
|
+
size = 'md',
|
|
1384
|
+
icon: Icon,
|
|
1385
|
+
value,
|
|
1386
|
+
render,
|
|
1387
|
+
asChild,
|
|
1388
|
+
className,
|
|
1389
|
+
onClick,
|
|
1390
|
+
children,
|
|
1391
|
+
...props
|
|
1392
|
+
},
|
|
1393
|
+
ref,
|
|
1394
|
+
) => {
|
|
1395
|
+
const item = useContext(MenuItemContext)
|
|
1396
|
+
const selection = useContext(SidebarSelection)
|
|
1397
|
+
const isActive = isActiveProp || (value !== undefined && selection?.value === value)
|
|
1398
|
+
const shape = useShape()
|
|
1399
|
+
const sizeClasses = useSize()
|
|
1400
|
+
const buttonRef = useRef<HTMLElement | null>(null)
|
|
1401
|
+
|
|
1402
|
+
const setActive = item?.setActive
|
|
1403
|
+
useIsoLayoutEffect(() => {
|
|
1404
|
+
setActive?.(isActive)
|
|
1405
|
+
return () => setActive?.(false)
|
|
1406
|
+
}, [isActive, setActive])
|
|
1407
|
+
|
|
1408
|
+
const setButtonEl = item?.setButtonEl
|
|
1409
|
+
useIsoLayoutEffect(() => {
|
|
1410
|
+
setButtonEl?.(buttonRef.current)
|
|
1411
|
+
return () => setButtonEl?.(null)
|
|
1412
|
+
}, [setButtonEl])
|
|
1413
|
+
|
|
1414
|
+
const lit = isActive || (item?.isHovered ?? false)
|
|
1415
|
+
const tabIdx = isActive ? 0 : -1
|
|
1416
|
+
|
|
1417
|
+
const gutterHover = rowGutter(item?.actionCount ?? 0, item?.hasBadge ?? false)
|
|
1418
|
+
const gutterRest = item?.actionsShowOnHover ? rowGutter(0, item?.hasBadge ?? false) : gutterHover
|
|
1419
|
+
const gutterVars = {
|
|
1420
|
+
'--row-gutter': `${gutterRest}px`,
|
|
1421
|
+
'--row-gutter-hover': `${gutterHover}px`,
|
|
1422
|
+
} as CSSProperties
|
|
1423
|
+
|
|
1424
|
+
const { template, content } = resolveSlotTemplate(render, asChild, children)
|
|
1425
|
+
|
|
1426
|
+
const asButton = !template && value !== undefined && props.href === undefined
|
|
1427
|
+
|
|
1428
|
+
return slotElement(
|
|
1429
|
+
template,
|
|
1430
|
+
asButton ? 'button' : 'a',
|
|
1431
|
+
{
|
|
1432
|
+
type: asButton ? 'button' : undefined,
|
|
1433
|
+
ref: (node: HTMLElement | null) => {
|
|
1434
|
+
buttonRef.current = node
|
|
1435
|
+
if (typeof ref === 'function') ref(node as HTMLAnchorElement | null)
|
|
1436
|
+
else if (ref) (ref as React.MutableRefObject<HTMLElement | null>).current = node
|
|
1437
|
+
},
|
|
1438
|
+
'data-sidebar': 'menu-sub-button',
|
|
1439
|
+
'data-size': size,
|
|
1440
|
+
'data-active': isActive ? 'true' : undefined,
|
|
1441
|
+
'aria-current': isActive ? 'page' : undefined,
|
|
1442
|
+
tabIndex: tabIdx,
|
|
1443
|
+
className: cn(
|
|
1444
|
+
'relative z-10 flex w-full cursor-pointer select-none items-center gap-2 pl-2 text-left outline-none',
|
|
1445
|
+
'transition-[padding] duration-fast pr-[var(--row-gutter)] group-hover/menu-sub-item:pr-[var(--row-gutter-hover)] group-focus-within/menu-sub-item:pr-[var(--row-gutter-hover)] group-has-[[data-sidebar=menu-action]:is([data-state=open],[data-popup-open],[aria-expanded=true])]/menu-sub-item:pr-[var(--row-gutter-hover)]',
|
|
1446
|
+
size === 'sm' ? 'h-6' : sizeClasses.variant === 'compact' ? 'h-6' : 'h-7',
|
|
1447
|
+
shape.item,
|
|
1448
|
+
className,
|
|
1449
|
+
),
|
|
1450
|
+
onClick: (event: MouseEvent<HTMLAnchorElement>) => {
|
|
1451
|
+
onClick?.(event)
|
|
1452
|
+
if (value !== undefined) selection?.select(value)
|
|
1453
|
+
},
|
|
1454
|
+
...props,
|
|
1455
|
+
style: { ...gutterVars, ...(props.style ?? {}) },
|
|
1456
|
+
},
|
|
1457
|
+
<>
|
|
1458
|
+
{Icon && (
|
|
1459
|
+
<Icon
|
|
1460
|
+
size={sizeClasses.icon}
|
|
1461
|
+
strokeWidth={lit ? 2 : 1.5}
|
|
1462
|
+
className={cn(
|
|
1463
|
+
'shrink-0 transition-[color,stroke-width] duration-fast',
|
|
1464
|
+
lit ? 'text-foreground' : 'text-muted-foreground',
|
|
1465
|
+
)}
|
|
1466
|
+
/>
|
|
1467
|
+
)}
|
|
1468
|
+
{/* Sub-rows keep the parent rows' type size — only the row height
|
|
1469
|
+
steps down. */}
|
|
1470
|
+
<MenuRowLabel
|
|
1471
|
+
content={content}
|
|
1472
|
+
lit={lit}
|
|
1473
|
+
emphasized={isActive}
|
|
1474
|
+
textClass={size === 'sm' ? 'text-body-compact' : sizeClasses.text}
|
|
1475
|
+
/>
|
|
1476
|
+
</>,
|
|
1477
|
+
)
|
|
1478
|
+
},
|
|
1479
|
+
)
|
|
1480
|
+
SidebarMenuSubButton.displayName = 'SidebarMenuSubButton'
|
|
1481
|
+
|
|
1482
|
+
export type { SidebarSelectionValue }
|
|
1483
|
+
export {
|
|
1484
|
+
SidebarMenu,
|
|
1485
|
+
SidebarMenuAction,
|
|
1486
|
+
SidebarMenuActions,
|
|
1487
|
+
SidebarMenuBadge,
|
|
1488
|
+
SidebarMenuButton,
|
|
1489
|
+
SidebarMenuItem,
|
|
1490
|
+
SidebarMenuSkeleton,
|
|
1491
|
+
SidebarMenuSub,
|
|
1492
|
+
SidebarMenuSubButton,
|
|
1493
|
+
SidebarMenuSubItem,
|
|
1494
|
+
SidebarSelection,
|
|
1495
|
+
}
|