@justanarthur/modo-ui 1.0.0 → 2.0.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/README.md +59 -20
- package/blocks/desktop-shell/examples.mdx +153 -0
- package/blocks/desktop-shell/index.tsx +352 -0
- package/blocks/shell-card/examples.mdx +72 -0
- package/blocks/shell-card/index.tsx +127 -0
- package/blocks/sidebar-app/index.tsx +3 -2
- package/blocks/sidebar-app/thread-page.tsx +2 -2
- package/components/{button → actions/button}/index.tsx +14 -22
- package/components/actions/button/variants.ts +138 -0
- package/components/{copy → actions/copy}/examples.mdx +40 -2
- package/components/{copy → actions/copy}/index.tsx +206 -36
- package/components/{accordion → containers/accordion}/accordion-content.tsx +14 -11
- package/components/{accordion → containers/accordion}/accordion-context.tsx +21 -12
- package/components/{accordion → containers/accordion}/accordion-group.tsx +11 -11
- package/components/{accordion → containers/accordion}/index.tsx +95 -47
- package/components/{card → containers/card}/card-group.tsx +7 -7
- package/components/{card → containers/card}/card-media.tsx +5 -5
- package/components/{card → containers/card}/card-parts.tsx +27 -17
- package/components/{card → containers/card}/examples.mdx +3 -2
- package/components/{card → containers/card}/index.tsx +12 -11
- package/components/{avatar → data-display/avatar}/examples.mdx +1 -1
- package/components/{avatar → data-display/avatar}/index.tsx +5 -5
- package/components/{badge → data-display/badge}/change-demo.tsx +1 -1
- package/components/{badge → data-display/badge}/index.tsx +8 -10
- package/components/{badge → data-display/badge}/variants.ts +7 -0
- package/components/data-display/diff/examples.mdx +72 -0
- package/components/data-display/diff/index.tsx +147 -0
- package/components/data-display/kbd/examples.mdx +55 -0
- package/components/data-display/kbd/index.tsx +65 -0
- package/components/data-display/list/examples.mdx +157 -0
- package/components/data-display/list/index.tsx +130 -0
- package/components/data-display/log-view/examples.mdx +69 -0
- package/components/data-display/log-view/index.tsx +290 -0
- package/components/data-display/log-view/stream-demo.tsx +46 -0
- package/components/data-display/markdown/examples.mdx +92 -0
- package/components/data-display/markdown/index.tsx +291 -0
- package/components/{table → data-display/table}/context.ts +12 -2
- package/components/{table → data-display/table}/head.tsx +5 -5
- package/components/{table → data-display/table}/index.tsx +40 -14
- package/components/{table → data-display/table}/parts.tsx +66 -52
- package/components/feedback/empty-state/examples.mdx +38 -0
- package/components/feedback/empty-state/index.tsx +96 -0
- package/components/feedback/meter/examples.mdx +61 -0
- package/components/feedback/meter/index.tsx +182 -0
- package/components/{progress → feedback/progress}/examples.mdx +2 -2
- package/components/{progress → feedback/progress}/index.tsx +5 -5
- package/components/{progress → feedback/progress}/step-demo.tsx +1 -1
- package/components/feedback/status-dot/examples.mdx +75 -0
- package/components/feedback/status-dot/index.tsx +105 -0
- package/components/inputs/checkbox/index.tsx +15 -9
- package/components/inputs/choice-list/examples.mdx +101 -0
- package/components/inputs/choice-list/index.tsx +186 -0
- package/components/inputs/color-picker/examples.mdx +10 -0
- package/components/inputs/color-picker/format-menu.tsx +1 -1
- package/components/inputs/color-picker/index.tsx +26 -10
- package/components/inputs/color-picker/inputs-row.tsx +1 -1
- package/components/inputs/color-picker/popover.tsx +40 -8
- package/components/inputs/color-picker/saturation-square.tsx +1 -1
- package/components/inputs/color-picker/swatches.tsx +1 -1
- package/components/inputs/combobox/context.ts +25 -1
- package/components/inputs/combobox/examples.mdx +1 -1
- package/components/inputs/combobox/fields.tsx +100 -51
- package/components/inputs/combobox/index.tsx +218 -200
- package/components/inputs/combobox/list.tsx +1 -1
- package/components/inputs/combobox/remote-demo.tsx +1 -1
- package/components/inputs/date-time/calendar/index.tsx +6 -3
- package/components/inputs/date-time/date-picker/examples.mdx +36 -0
- package/components/inputs/date-time/date-picker/index.tsx +106 -20
- package/components/inputs/date-time/date-range-picker/examples.mdx +36 -0
- package/components/inputs/date-time/date-range-picker/index.tsx +331 -54
- package/components/inputs/date-time/day-rules.ts +6 -3
- package/components/inputs/date-time/duration-picker/examples.mdx +16 -0
- package/components/inputs/date-time/duration-picker/index.tsx +74 -22
- package/components/inputs/date-time/month-picker/examples.mdx +12 -0
- package/components/inputs/date-time/month-picker/index.tsx +76 -21
- package/components/inputs/date-time/picker-shell.tsx +142 -11
- package/components/inputs/date-time/time-columns.tsx +5 -2
- package/components/inputs/date-time/time-picker/examples.mdx +13 -0
- package/components/inputs/date-time/time-picker/index.tsx +63 -12
- package/components/inputs/editable-text/examples.mdx +33 -0
- package/components/inputs/editable-text/index.tsx +175 -0
- package/components/inputs/field/index.tsx +1 -1
- package/components/inputs/file-dropzone/file-row.tsx +2 -2
- package/components/inputs/file-dropzone/index.tsx +5 -0
- package/components/inputs/input/index.tsx +1 -1
- package/components/inputs/key-value/examples.mdx +58 -0
- package/components/inputs/key-value/index.tsx +232 -0
- package/components/inputs/label/examples.mdx +1 -1
- package/components/inputs/number-input/index.tsx +4 -4
- package/components/inputs/radio/examples.mdx +10 -0
- package/components/inputs/radio/index.tsx +15 -6
- package/components/inputs/search/examples.mdx +1 -1
- package/components/inputs/search/index.tsx +1 -1
- package/components/inputs/select/examples.mdx +28 -1
- package/components/inputs/select/index.tsx +248 -167
- package/components/inputs/switch/index.tsx +1 -1
- package/components/navigation/breadcrumb/examples.mdx +45 -0
- package/components/navigation/breadcrumb/index.tsx +284 -0
- package/components/navigation/navigation-menu/context.ts +5 -1
- package/components/navigation/navigation-menu/examples.mdx +23 -0
- package/components/navigation/navigation-menu/index.tsx +8 -1
- package/components/navigation/navigation-menu/indicator.tsx +38 -0
- package/components/navigation/navigation-menu/list.tsx +33 -22
- package/components/navigation/pagination/index.tsx +2 -2
- package/components/navigation/sidebar/index.tsx +1 -1
- package/components/navigation/sidebar/sidebar-menu-item.tsx +1 -1
- package/components/navigation/sidebar/sidebar-rail.tsx +1 -1
- package/components/navigation/tabs/examples.mdx +11 -0
- package/components/navigation/tabs/index.tsx +1 -1
- package/components/navigation/tabs/item.tsx +3 -3
- package/components/navigation/tree/examples.mdx +76 -0
- package/components/navigation/tree/index.tsx +431 -0
- package/components/overlays/alert-dialog/examples.mdx +1 -1
- package/components/overlays/alert-dialog/index.tsx +37 -26
- package/components/overlays/alert-dialog/pending-demo.tsx +1 -1
- package/components/overlays/command/examples.mdx +2 -2
- package/components/overlays/command/index.tsx +20 -17
- package/components/overlays/context-menu/index.tsx +38 -29
- package/components/overlays/dialog/examples.mdx +22 -2
- package/components/overlays/dialog/index.tsx +87 -32
- package/components/overlays/dropdown/examples.mdx +86 -2
- package/components/overlays/dropdown/index.tsx +136 -48
- package/components/overlays/dropdown/menu-item.tsx +165 -65
- package/components/overlays/dropdown/menu-parts.tsx +153 -0
- package/components/overlays/dropdown/menu-popup.tsx +52 -10
- package/components/overlays/dropdown/panel-state.ts +49 -16
- package/components/overlays/dropdown/submenu.tsx +26 -27
- package/components/overlays/lightbox/examples.mdx +29 -0
- package/components/overlays/lightbox/index.tsx +395 -0
- package/components/overlays/popover/anchored-demo.tsx +1 -1
- package/components/overlays/popover/examples.mdx +1 -1
- package/components/overlays/popover/index.tsx +27 -24
- package/components/overlays/preview-card/index.tsx +16 -13
- package/components/overlays/sheet/examples.mdx +14 -1
- package/components/overlays/sheet/index.tsx +122 -54
- package/components/overlays/toast/examples.mdx +17 -1
- package/components/overlays/toast/index.tsx +117 -45
- package/components/overlays/toast/manager.ts +45 -12
- package/components/overlays/tooltip/examples.mdx +7 -7
- package/components/overlays/tooltip/index.tsx +59 -50
- package/dist/base.css +62 -82
- package/dist/blocks/desktop-shell/index.d.ts +84 -0
- package/dist/blocks/desktop-shell/index.js +45 -0
- package/dist/blocks/shell-card/index.d.ts +57 -0
- package/dist/blocks/shell-card/index.js +13 -0
- package/dist/blocks/sidebar-app/index.d.ts +24 -4
- package/dist/blocks/sidebar-app/index.js +43 -37
- package/dist/components/{button → actions/button}/index.d.ts +28 -12
- package/dist/components/actions/button/index.js +22 -0
- package/dist/components/actions/button/variants.d.ts +29 -0
- package/dist/components/{button → actions/button}/variants.js +1 -1
- package/dist/components/actions/copy/index.d.ts +79 -0
- package/dist/components/actions/copy/index.js +26 -0
- package/dist/components/{accordion → containers/accordion}/index.d.ts +51 -19
- package/dist/components/containers/accordion/index.js +40 -0
- package/dist/components/{card → containers/card}/index.d.ts +27 -23
- package/dist/components/containers/card/index.js +58 -0
- package/dist/components/data-display/avatar/index.js +20 -0
- package/dist/components/{badge → data-display/badge}/index.d.ts +6 -3
- package/dist/components/data-display/badge/index.js +21 -0
- package/dist/components/{badge → data-display/badge}/variants.d.ts +6 -1
- package/dist/components/{badge → data-display/badge}/variants.js +1 -1
- package/dist/components/data-display/diff/index.d.ts +42 -0
- package/dist/components/data-display/diff/index.js +17 -0
- package/dist/components/data-display/kbd/index.d.ts +28 -0
- package/dist/components/data-display/kbd/index.js +11 -0
- package/dist/components/data-display/list/index.d.ts +60 -0
- package/dist/components/data-display/list/index.js +21 -0
- package/dist/components/data-display/log-view/index.d.ts +47 -0
- package/dist/components/data-display/log-view/index.js +26 -0
- package/dist/components/data-display/markdown/index.d.ts +43 -0
- package/dist/components/data-display/markdown/index.js +34 -0
- package/dist/components/{table → data-display/table}/index.d.ts +24 -7
- package/dist/components/data-display/table/index.js +40 -0
- package/dist/components/feedback/empty-state/index.d.ts +38 -0
- package/dist/components/feedback/empty-state/index.js +15 -0
- package/dist/components/feedback/meter/index.d.ts +48 -0
- package/dist/components/feedback/meter/index.js +13 -0
- package/dist/components/feedback/progress/index.js +16 -0
- package/dist/components/feedback/status-dot/index.d.ts +37 -0
- package/dist/components/feedback/status-dot/index.js +15 -0
- package/dist/components/inputs/checkbox/index.d.ts +8 -5
- package/dist/components/inputs/checkbox/index.js +13 -13
- package/dist/components/inputs/choice-list/index.d.ts +52 -0
- package/dist/components/inputs/choice-list/index.js +25 -0
- package/dist/components/inputs/color-picker/index.d.ts +39 -23
- package/dist/components/inputs/color-picker/index.js +27 -25
- 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 +40 -9
- package/dist/components/inputs/combobox/index.js +21 -21
- package/dist/components/inputs/date-time/calendar/index.d.ts +6 -1
- package/dist/components/inputs/date-time/calendar/index.js +10 -10
- package/dist/components/inputs/date-time/date-picker/index.d.ts +48 -8
- package/dist/components/inputs/date-time/date-picker/index.js +31 -31
- package/dist/components/inputs/date-time/date-range-picker/index.d.ts +99 -18
- package/dist/components/inputs/date-time/date-range-picker/index.js +32 -30
- package/dist/components/inputs/date-time/duration-picker/index.d.ts +52 -9
- package/dist/components/inputs/date-time/duration-picker/index.js +29 -29
- package/dist/components/inputs/date-time/month-picker/index.d.ts +49 -8
- package/dist/components/inputs/date-time/month-picker/index.js +28 -28
- package/dist/components/inputs/date-time/time-picker/index.d.ts +47 -8
- package/dist/components/inputs/date-time/time-picker/index.js +29 -29
- package/dist/components/inputs/editable-text/index.d.ts +38 -0
- package/dist/components/inputs/editable-text/index.js +17 -0
- package/dist/components/inputs/field/index.js +8 -8
- package/dist/components/inputs/file-dropzone/index.d.ts +3 -1
- package/dist/components/inputs/file-dropzone/index.js +10 -10
- package/dist/components/inputs/input/index.js +9 -9
- package/dist/components/inputs/key-value/index.d.ts +57 -0
- package/dist/components/inputs/key-value/index.js +29 -0
- package/dist/components/inputs/label/index.js +2 -2
- package/dist/components/inputs/number-input/index.d.ts +3 -2
- package/dist/components/inputs/number-input/index.js +11 -11
- package/dist/components/inputs/radio/index.d.ts +2 -2
- package/dist/components/inputs/radio/index.js +11 -11
- package/dist/components/inputs/search/index.js +23 -23
- package/dist/components/inputs/select/index.d.ts +71 -47
- package/dist/components/inputs/select/index.js +23 -22
- package/dist/components/inputs/slider/index.js +4 -4
- package/dist/components/inputs/switch/index.js +9 -9
- package/dist/components/inputs/textarea/index.js +5 -5
- package/dist/components/navigation/breadcrumb/index.d.ts +44 -0
- package/dist/components/navigation/breadcrumb/index.js +45 -0
- package/dist/components/navigation/navigation-menu/index.d.ts +13 -2
- package/dist/components/navigation/navigation-menu/index.js +20 -18
- package/dist/components/navigation/pagination/index.js +19 -19
- package/dist/components/navigation/sidebar/index.d.ts +1 -9
- package/dist/components/navigation/sidebar/index.js +26 -26
- package/dist/components/navigation/tabs/index.d.ts +5 -5
- package/dist/components/navigation/tabs/index.js +12 -12
- package/dist/components/navigation/tree/index.d.ts +65 -0
- package/dist/components/navigation/tree/index.js +25 -0
- package/dist/components/overlays/alert-dialog/index.d.ts +35 -15
- package/dist/components/overlays/alert-dialog/index.js +15 -15
- package/dist/components/overlays/command/index.d.ts +6 -1
- package/dist/components/overlays/command/index.js +21 -21
- package/dist/components/overlays/context-menu/index.d.ts +138 -14
- package/dist/components/overlays/context-menu/index.js +29 -26
- package/dist/components/overlays/dialog/index.d.ts +43 -15
- package/dist/components/overlays/dialog/index.js +14 -14
- package/dist/components/overlays/dropdown/index.d.ts +163 -59
- package/dist/components/overlays/dropdown/index.js +37 -26
- package/dist/components/overlays/lightbox/index.d.ts +59 -0
- package/dist/components/overlays/lightbox/index.js +30 -0
- package/dist/components/overlays/popover/index.d.ts +7 -1
- package/dist/components/overlays/popover/index.js +11 -11
- package/dist/components/overlays/preview-card/index.d.ts +4 -1
- package/dist/components/overlays/preview-card/index.js +10 -10
- package/dist/components/overlays/sheet/index.d.ts +49 -8
- package/dist/components/overlays/sheet/index.js +15 -15
- package/dist/components/overlays/toast/index.d.ts +92 -39
- package/dist/components/overlays/toast/index.js +13 -11
- package/dist/components/overlays/tooltip/index.d.ts +16 -6
- package/dist/components/overlays/tooltip/index.js +8 -8
- package/dist/docs/index.d.ts +54 -0
- package/dist/docs/index.js +327 -0
- package/dist/docs/vite.d.ts +50 -0
- package/dist/docs/vite.js +63 -0
- package/dist/index.d.ts +3722 -2274
- package/dist/index.js +240 -115
- package/dist/lib/date-locale.d.ts +13 -1
- package/dist/lib/date-locale.js +11 -3
- package/dist/lib/field-box.js +3 -3
- package/dist/lib/fluid-hover-highlight.js +4 -4
- package/dist/lib/focus-ring.js +3 -3
- package/dist/lib/goo-indicator.js +3 -3
- package/dist/lib/icon-context.d.ts +7 -2
- package/dist/lib/icon-context.js +4 -2
- package/dist/lib/morph-layers.js +3 -3
- package/dist/lib/overlay.js +3 -3
- package/dist/lib/popup-rows.js +2 -2
- package/dist/lib/popup-surface.js +7 -7
- package/dist/lib/row-index.d.ts +6 -9
- package/dist/lib/row-index.js +1 -1
- package/dist/lib/row-order.d.ts +28 -0
- package/dist/lib/row-order.js +11 -0
- package/dist/lib/scroll-column.js +6 -6
- package/dist/lib/shape-context.d.ts +8 -1
- package/dist/lib/shape-context.js +4 -2
- package/dist/lib/slot.d.ts +9 -2
- package/dist/lib/slot.js +5 -3
- package/dist/lib/use-merge-split.js +4 -4
- package/dist/lib/use-morph.js +1 -1
- package/dist/lib/utils.js +1 -1
- package/dist/lib/weight-label.js +2 -2
- package/dist/preset.d.ts +9 -0
- package/dist/preset.js +11 -2
- package/dist/primitives/content/code/index.js +14 -0
- package/dist/primitives/content/skeleton/index.js +14 -0
- package/dist/primitives/layout/resizable/index.d.ts +67 -0
- package/dist/primitives/layout/resizable/index.js +16 -0
- package/dist/primitives/layout/scroll-area/index.js +14 -0
- package/dist/primitives/{separator → layout/separator}/index.js +2 -2
- package/dist/primitives/layout/sortable/index.d.ts +79 -0
- package/dist/primitives/layout/sortable/index.js +23 -0
- package/dist/primitives/layout/virtual-list/index.d.ts +50 -0
- package/dist/primitives/layout/virtual-list/index.js +9 -0
- package/dist/primitives/systems/craft/index.js +16 -0
- package/dist/primitives/systems/fluid-hover/index.js +30 -0
- package/dist/primitives/{morph → systems/morph}/index.d.ts +3 -1
- package/dist/primitives/systems/morph/index.js +30 -0
- package/dist/primitives/systems/motion/index.js +25 -0
- package/dist/primitives/{sizes → systems/sizes}/index.d.ts +2 -2
- package/dist/primitives/{sizes → systems/sizes}/index.js +4 -4
- package/dist/primitives/{surface → systems/surface}/index.js +6 -6
- package/dist/shared/{components-7t3pz7v7.js → components-0cpte6s1.js} +76 -40
- package/dist/shared/{components-gc5zky2w.js → components-0h2mng6m.js} +7 -7
- package/dist/shared/{components-62mg6pab.js → components-14wzcym0.js} +16 -16
- package/dist/shared/components-1asw2ph0.js +237 -0
- package/dist/shared/{components-p0z99d5b.js → components-1bnf96sr.js} +17 -15
- package/dist/shared/components-1f3a7gmg.js +168 -0
- package/dist/shared/components-1hb27y2e.js +77 -0
- package/dist/shared/{components-1axxc3tk.js → components-1hga6pkn.js} +8 -8
- package/dist/shared/{components-wyfmhtw9.js → components-1ztgy933.js} +2 -2
- package/dist/shared/{components-0h3f5jae.js → components-22h8dvt1.js} +19 -16
- package/dist/shared/{components-07g2gbjy.js → components-280grw6q.js} +19 -12
- package/dist/shared/components-29ebea21.js +129 -0
- package/dist/shared/{components-zbzx62pg.js → components-2m2hg11x.js} +93 -378
- package/dist/shared/components-3rvrdsa9.js +208 -0
- package/dist/shared/components-464zs8v6.js +152 -0
- package/dist/shared/components-4t2cjav8.js +73 -0
- package/dist/shared/{components-9ybenn5v.js → components-5xs8pkkj.js} +5 -5
- package/dist/shared/{components-gbsdhmrv.js → components-62510420.js} +62 -27
- package/dist/shared/components-6h5qg9rs.js +188 -0
- package/dist/shared/{components-7fsy0jxg.js → components-6rtawx8y.js} +108 -75
- package/dist/shared/{components-n7e31ct4.js → components-77gxngmc.js} +8 -8
- package/dist/shared/components-7mj5wsv3.js +200 -0
- package/dist/shared/{components-amsc86fb.js → components-7xc2dne4.js} +68 -37
- package/dist/shared/{components-pedbt2dc.js → components-8pnvkrbw.js} +1 -1
- package/dist/shared/{components-be3wggg1.js → components-91mmbrw3.js} +5 -5
- package/dist/shared/components-92mvpt9h.js +243 -0
- package/dist/shared/{components-jtfptckj.js → components-9ca0c92a.js} +6 -6
- package/dist/shared/{components-ejn6tvbw.js → components-9h3g4mnq.js} +1 -1
- package/dist/shared/components-9rebr89j.js +249 -0
- package/dist/shared/{components-re8p99fj.js → components-9z7bq8gn.js} +147 -21
- package/dist/shared/{components-3js2vgds.js → components-a1ms36qq.js} +3 -3
- package/dist/shared/{components-q4wyd06h.js → components-a1mwqxsv.js} +88 -22
- package/dist/shared/{components-cy5z8zxy.js → components-azrjnfxn.js} +2 -2
- package/dist/shared/{components-85epgxwf.js → components-b2kjsn1s.js} +60 -37
- package/dist/shared/{components-vgzerqt0.js → components-b7p1pjcm.js} +8 -7
- package/dist/shared/{components-j4z3rtw2.js → components-b9bj65j3.js} +46 -21
- package/dist/shared/{components-0mrhj88d.js → components-c515d6xr.js} +2 -2
- package/dist/shared/{components-5f3tq4qb.js → components-chda6b23.js} +2 -2
- package/dist/shared/{components-az04rmng.js → components-cp5ym3g2.js} +2 -2
- package/dist/shared/components-czvraaw9.js +135 -0
- package/dist/shared/{components-kn5c7652.js → components-e7zxwja1.js} +7 -6
- package/dist/shared/components-ee09xmkh.js +359 -0
- package/dist/shared/{components-3m4rqrqm.js → components-esy5nsvc.js} +3 -3
- package/dist/shared/{components-34brwmgp.js → components-ev0ytbqb.js} +12 -10
- package/dist/shared/{components-zpatc9x3.js → components-fmyvz4r2.js} +9 -8
- package/dist/shared/{components-f9adtfq8.js → components-fpsfr52a.js} +1 -1
- package/dist/shared/{components-zf0nnvvg.js → components-fqsgd07c.js} +68 -24
- package/dist/shared/{components-5vyaexsj.js → components-g35n8tzm.js} +2 -2
- package/dist/shared/components-g8qgr7p8.js +28 -0
- package/dist/shared/{components-88r046aa.js → components-gd8gmr6w.js} +4 -4
- package/dist/shared/{components-f75y4gn8.js → components-gsstwhtv.js} +6 -6
- package/dist/shared/{components-1hc3xv0y.js → components-h0x2pj2y.js} +170 -118
- package/dist/shared/components-h8v9nh5r.js +142 -0
- package/dist/shared/{components-6xfhc5qm.js → components-hcftn5r8.js} +14 -12
- package/dist/shared/components-hh1g7r3t.js +57 -0
- package/dist/shared/{components-jm91mjm1.js → components-hz6armxa.js} +13 -9
- package/dist/shared/{components-k81x1aea.js → components-j3q9kaps.js} +2 -2
- package/dist/shared/{components-88ktjdg0.js → components-j79a6jqa.js} +13 -12
- package/dist/shared/{components-k785rge6.js → components-jeecysvd.js} +24 -168
- package/dist/shared/{components-1nv9q3s8.js → components-jnhpgpfk.js} +29 -2
- package/dist/shared/{components-wgd1nebp.js → components-jw45ck66.js} +4 -4
- package/dist/shared/{components-7fqnqbh0.js → components-kwxye0an.js} +10 -4
- package/dist/shared/{components-qrpdtvxa.js → components-kxpcj2ry.js} +7 -1
- package/dist/shared/components-m3vxpz2z.js +123 -0
- package/dist/shared/{components-86vvx0c8.js → components-me742146.js} +9 -9
- package/dist/shared/{components-jx9qb4z8.js → components-n0gbyp5a.js} +18 -16
- package/dist/shared/{components-8hfrd2fk.js → components-nhmgr5xc.js} +14 -14
- package/dist/shared/{components-nv5m3gcv.js → components-nxqrw789.js} +2 -2
- package/dist/shared/{components-1a7cr7vh.js → components-nz14rwtd.js} +1 -1
- package/dist/shared/{components-j8tcbm8y.js → components-p32aqk3q.js} +2 -2
- package/dist/shared/components-pa2t12j2.js +327 -0
- package/dist/shared/{components-r33dxr5j.js → components-q0hs5rqn.js} +1 -1
- package/dist/shared/{components-xzcgr3gy.js → components-q7zk70tx.js} +6 -6
- package/dist/shared/{components-8sazy704.js → components-r5q9gdh4.js} +13 -12
- package/dist/shared/{components-tjxy84s9.js → components-rgng034x.js} +1 -1
- package/dist/shared/{components-skn189mp.js → components-rzy6h7s4.js} +5 -5
- package/dist/shared/{components-wrbw67f6.js → components-s4x951hj.js} +3 -3
- package/dist/shared/{components-gw0wd7gd.js → components-s90v3jpr.js} +371 -187
- package/dist/shared/components-t0c1rw40.js +75 -0
- package/dist/shared/components-t84071ay.js +76 -0
- package/dist/shared/{components-0p2na0cp.js → components-ta4e10mx.js} +3 -3
- package/dist/shared/components-twyj2y8c.js +336 -0
- package/dist/shared/components-vfreweq3.js +210 -0
- package/dist/shared/{components-2xmke84n.js → components-w1ysefg1.js} +2 -2
- package/dist/shared/{components-5atrr490.js → components-w2at9ntm.js} +27 -13
- package/dist/shared/{components-346ged8v.js → components-wq9hrera.js} +2 -2
- package/dist/shared/{components-tnj6mkhg.js → components-wx1dcp2n.js} +17 -10
- package/dist/shared/components-xa9fvd5b.js +302 -0
- package/dist/shared/{components-1jxw899c.js → components-xnkc892z.js} +8 -6
- package/dist/shared/{components-ycx2kxeq.js → components-xnp09586.js} +1 -1
- package/dist/shared/{components-vp6vzsee.js → components-y09nr7fe.js} +1 -1
- package/dist/shared/{components-sesrjvcc.js → components-y4gsk1jt.js} +3 -3
- package/dist/shared/{components-099sdasz.js → components-y8m64zdw.js} +31 -22
- package/dist/shared/components-yf2gtq68.js +302 -0
- package/dist/shared/{components-xpw8dzb0.js → components-ymq8tbq9.js} +2 -2
- package/dist/shared/components-ywgqahmg.js +80 -0
- package/dist/shared/{components-5ynncdpn.js → components-z0kz9rxj.js} +2 -2
- package/dist/styles.css +212 -137
- package/dist/tailwind.css +14 -0
- package/dist/tokens.css +37 -4
- package/docs/chrome.css +175 -0
- package/docs/chrome.tsx +314 -0
- package/docs/index.ts +8 -0
- package/docs/vite.ts +123 -0
- package/index.ts +40 -21
- package/lib/date-locale.ts +152 -6
- package/lib/icon-context.tsx +45 -1
- package/lib/row-index.tsx +6 -16
- package/lib/row-order.tsx +111 -0
- package/lib/shape-context.tsx +9 -1
- package/lib/slot.tsx +17 -4
- package/lib/use-autosize-textarea.ts +1 -1
- package/lib/use-morph.ts +1 -1
- package/lib/utils.ts +1 -1
- package/package.json +200 -38
- package/primitives/{code → content/code}/index.tsx +4 -4
- package/primitives/{skeleton → content/skeleton}/examples.mdx +1 -1
- package/primitives/{skeleton → content/skeleton}/index.tsx +4 -4
- package/primitives/layout/resizable/examples.mdx +93 -0
- package/primitives/layout/resizable/index.tsx +332 -0
- package/primitives/{scroll-area → layout/scroll-area}/index.tsx +3 -3
- package/primitives/{separator → layout/separator}/examples.mdx +1 -1
- package/primitives/{separator → layout/separator}/index.tsx +1 -1
- package/primitives/layout/sortable/examples.mdx +53 -0
- package/primitives/layout/sortable/index.tsx +351 -0
- package/primitives/layout/virtual-list/examples.mdx +45 -0
- package/primitives/layout/virtual-list/index.tsx +269 -0
- package/primitives/layout/virtual-list/jump-demo.tsx +53 -0
- package/primitives/{craft → systems/craft}/demos.tsx +8 -8
- package/primitives/{craft → systems/craft}/examples.mdx +5 -5
- package/primitives/{craft → systems/craft}/index.tsx +3 -3
- package/primitives/{fluid-hover → systems/fluid-hover}/examples.mdx +1 -1
- package/primitives/{fluid-hover → systems/fluid-hover}/index.tsx +10 -10
- package/primitives/{morph → systems/morph}/examples.mdx +4 -4
- package/primitives/{morph → systems/morph}/index.tsx +71 -66
- package/primitives/{motion → systems/motion}/index.tsx +5 -5
- package/primitives/{sizes → systems/sizes}/examples.mdx +4 -4
- package/primitives/{sizes → systems/sizes}/index.tsx +8 -8
- package/primitives/{surface → systems/surface}/examples.mdx +2 -2
- package/primitives/{surface → systems/surface}/index.tsx +3 -3
- package/tokens/colors.css +234 -0
- package/tokens/motion.css +40 -0
- package/tokens/radius.css +24 -0
- package/tokens/spacing.css +9 -0
- package/tokens/typography.css +119 -0
- package/components/AI/input-message/examples.mdx +0 -134
- package/components/AI/input-message/file-preview-tile.tsx +0 -59
- package/components/AI/input-message/file-thumbnail.tsx +0 -146
- package/components/AI/input-message/index.tsx +0 -625
- package/components/AI/input-message/input-message.css +0 -25
- package/components/AI/input-message/queued-row.tsx +0 -102
- package/components/AI/input-message/shared.ts +0 -38
- package/components/AI/input-message/suggestion-row.tsx +0 -64
- package/components/AI/input-message/use-composer-files.ts +0 -142
- package/components/AI/input-message/use-history-nav.ts +0 -60
- package/components/AI/input-message/use-message-queue.ts +0 -108
- package/components/AI/input-message/use-region-height.ts +0 -34
- package/components/AI/thinking-indicator/examples.mdx +0 -27
- package/components/AI/thinking-indicator/index.tsx +0 -188
- package/components/button/variants.ts +0 -63
- package/dist/components/AI/input-message/index.d.ts +0 -128
- package/dist/components/AI/input-message/index.js +0 -39
- package/dist/components/AI/thinking-indicator/index.d.ts +0 -34
- package/dist/components/AI/thinking-indicator/index.js +0 -17
- package/dist/components/accordion/index.js +0 -39
- package/dist/components/avatar/index.js +0 -20
- package/dist/components/badge/index.js +0 -21
- package/dist/components/button/index.js +0 -22
- package/dist/components/button/variants.d.ts +0 -8
- package/dist/components/card/index.js +0 -57
- package/dist/components/copy/index.d.ts +0 -46
- package/dist/components/copy/index.js +0 -25
- package/dist/components/progress/index.js +0 -16
- package/dist/components/table/index.js +0 -39
- package/dist/primitives/code/index.js +0 -14
- package/dist/primitives/craft/index.js +0 -16
- package/dist/primitives/fluid-hover/index.js +0 -30
- package/dist/primitives/morph/index.js +0 -29
- package/dist/primitives/motion/index.js +0 -25
- package/dist/primitives/scroll-area/index.js +0 -14
- package/dist/primitives/skeleton/index.js +0 -14
- package/dist/shared/components-1p3k62x2.js +0 -137
- package/dist/shared/components-38wa9nx5.js +0 -19
- package/dist/shared/components-50rh4ggz.js +0 -54
- package/dist/shared/components-bdkm2jzy.js +0 -34
- package/dist/shared/components-gkdx1787.js +0 -159
- package/dist/shared/components-nskr4hwg.js +0 -1008
- /package/components/{button → actions/button}/examples.mdx +0 -0
- /package/components/{button → actions/button}/loading-demo.tsx +0 -0
- /package/components/{accordion → containers/accordion}/examples.mdx +0 -0
- /package/components/{badge → data-display/badge}/examples.mdx +0 -0
- /package/components/{table → data-display/table}/examples.mdx +0 -0
- /package/components/{table → data-display/table}/sort-demo.tsx +0 -0
- /package/components/{progress → feedback/progress}/progress.css +0 -0
- /package/components/inputs/color-picker/{color-math.ts → variants.ts} +0 -0
- /package/dist/components/{avatar → data-display/avatar}/index.d.ts +0 -0
- /package/dist/components/{progress → feedback/progress}/index.d.ts +0 -0
- /package/dist/primitives/{code → content/code}/index.d.ts +0 -0
- /package/dist/primitives/{skeleton → content/skeleton}/index.d.ts +0 -0
- /package/dist/primitives/{scroll-area → layout/scroll-area}/index.d.ts +0 -0
- /package/dist/primitives/{separator → layout/separator}/index.d.ts +0 -0
- /package/dist/primitives/{craft → systems/craft}/index.d.ts +0 -0
- /package/dist/primitives/{fluid-hover → systems/fluid-hover}/index.d.ts +0 -0
- /package/dist/primitives/{motion → systems/motion}/index.d.ts +0 -0
- /package/dist/primitives/{surface → systems/surface}/index.d.ts +0 -0
- /package/primitives/{code → content/code}/examples.mdx +0 -0
- /package/primitives/{skeleton → content/skeleton}/skeleton.css +0 -0
- /package/primitives/{scroll-area → layout/scroll-area}/examples.mdx +0 -0
- /package/primitives/{motion → systems/motion}/examples.mdx +0 -0
- /package/primitives/{surface → systems/surface}/surface.css +0 -0
|
@@ -9,7 +9,6 @@
|
|
|
9
9
|
import {
|
|
10
10
|
Children,
|
|
11
11
|
cloneElement,
|
|
12
|
-
createElement,
|
|
13
12
|
isValidElement,
|
|
14
13
|
type ReactElement,
|
|
15
14
|
type ReactNode,
|
|
@@ -17,10 +16,10 @@ import {
|
|
|
17
16
|
useMemo,
|
|
18
17
|
useState,
|
|
19
18
|
} from 'react'
|
|
20
|
-
import {
|
|
21
|
-
import { IndexedRows } from '../../../lib/row-index'
|
|
19
|
+
import { PopupSeparator } from '../../../lib/popup-rows'
|
|
22
20
|
import { useControllableState } from '../../../lib/use-controllable-state'
|
|
23
21
|
import { DropdownEmpty, type DropdownFilterContextValue, DropdownSearch } from './dropdown-search'
|
|
22
|
+
import { DropdownGroup, DropdownLabel, DropdownRadioGroup } from './menu-parts'
|
|
24
23
|
|
|
25
24
|
// `useControllableState` reads `undefined` as uncontrolled, so "nothing checked" needs a value of its own.
|
|
26
25
|
const NONE = -1
|
|
@@ -98,9 +97,37 @@ export function usePanelSelection(
|
|
|
98
97
|
return { checkedIndex: renderedIndex, checkedIndices: renderedIndices, multiple, selfManaged, toggleIndex }
|
|
99
98
|
}
|
|
100
99
|
|
|
101
|
-
|
|
100
|
+
/** The rows a `Dropdown.CheckboxItem` / `Dropdown.RadioItem` reports checked, for the merged selection background. */
|
|
101
|
+
export function useValueChecked() {
|
|
102
|
+
const [valueChecked, setValueChecked] = useState(NO_INDICES)
|
|
103
|
+
const reportChecked = useCallback(
|
|
104
|
+
(index: number, on: boolean) =>
|
|
105
|
+
setValueChecked(prev =>
|
|
106
|
+
on === prev.includes(index) ? prev : on ? [...prev, index] : prev.filter(i => i !== index),
|
|
107
|
+
),
|
|
108
|
+
[],
|
|
109
|
+
)
|
|
110
|
+
return { valueChecked, reportChecked }
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** The rows checked by index and by value: what the merged selection backgrounds cover. */
|
|
114
|
+
export function useCheckedRows(checkedIndices: number[] | undefined, valueChecked: number[]) {
|
|
115
|
+
return useMemo(
|
|
116
|
+
() => (valueChecked.length === 0 ? (checkedIndices ?? NO_INDICES) : [...(checkedIndices ?? []), ...valueChecked]),
|
|
117
|
+
[checkedIndices, valueChecked],
|
|
118
|
+
)
|
|
119
|
+
}
|
|
102
120
|
|
|
103
|
-
|
|
121
|
+
const NOT_ROWS = new Set<unknown>([
|
|
122
|
+
DropdownLabel,
|
|
123
|
+
PopupSeparator,
|
|
124
|
+
DropdownSearch,
|
|
125
|
+
DropdownEmpty,
|
|
126
|
+
DropdownGroup,
|
|
127
|
+
DropdownRadioGroup,
|
|
128
|
+
])
|
|
129
|
+
|
|
130
|
+
/** Every element child but the panel's captions, rules, groups, search and empty state takes a row index. */
|
|
104
131
|
const isPanelRow = (child: ReactElement) => !NOT_ROWS.has(child.type)
|
|
105
132
|
|
|
106
133
|
interface PanelRows {
|
|
@@ -114,13 +141,14 @@ interface PanelRows {
|
|
|
114
141
|
}
|
|
115
142
|
|
|
116
143
|
/**
|
|
117
|
-
*
|
|
144
|
+
* Rows that bring no `index` number themselves in document order
|
|
145
|
+
* (`lib/row-order.tsx`, provided by the panel).
|
|
118
146
|
*
|
|
119
147
|
* Uncontrolled search: a `Dropdown.Search filter` among the panel's direct
|
|
120
|
-
* children hands it the query. The panel keeps the rows
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
* `sourceIndex`.
|
|
148
|
+
* children hands it the query. The panel keeps the direct rows with a text
|
|
149
|
+
* (`textValue`, else `label`, else string `children`) that contains it,
|
|
150
|
+
* re-indexes them from 0 for the fluid hover and stamps each with its
|
|
151
|
+
* authored index (its `index`, else its position) as `sourceIndex`.
|
|
124
152
|
*/
|
|
125
153
|
export function usePanelRows(children: ReactNode): PanelRows {
|
|
126
154
|
const [query, setQuery] = useState('')
|
|
@@ -136,8 +164,7 @@ export function usePanelRows(children: ReactNode): PanelRows {
|
|
|
136
164
|
const filterCtx = useMemo(() => ({ query, setQuery }), [query])
|
|
137
165
|
|
|
138
166
|
const { content, sourceOf } = useMemo(() => {
|
|
139
|
-
if (!filtering)
|
|
140
|
-
return { content: createElement(IndexedRows, { isRow: isPanelRow, children }), sourceOf: NO_INDICES }
|
|
167
|
+
if (!filtering) return { content: children, sourceOf: NO_INDICES }
|
|
141
168
|
const needle = query.trim().toLowerCase()
|
|
142
169
|
const rendered: ReactNode[] = []
|
|
143
170
|
const empties: ReactNode[] = []
|
|
@@ -154,15 +181,21 @@ export function usePanelRows(children: ReactNode): PanelRows {
|
|
|
154
181
|
continue
|
|
155
182
|
}
|
|
156
183
|
|
|
157
|
-
const row = child.props as { label?: unknown; index?: unknown }
|
|
184
|
+
const row = child.props as { textValue?: unknown; label?: unknown; children?: unknown; index?: unknown }
|
|
158
185
|
const authored = typeof row.index === 'number' ? row.index : position
|
|
159
|
-
if (isPanelRow(child))
|
|
160
|
-
|
|
186
|
+
if (!isPanelRow(child)) {
|
|
187
|
+
rendered.push(child)
|
|
188
|
+
continue
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
position++
|
|
192
|
+
const text = [row.textValue, row.label, row.children].find(t => typeof t === 'string') as string | undefined
|
|
193
|
+
if (text === undefined) {
|
|
161
194
|
rendered.push(child)
|
|
162
195
|
continue
|
|
163
196
|
}
|
|
164
197
|
|
|
165
|
-
if (needle && !
|
|
198
|
+
if (needle && !text.toLowerCase().includes(needle)) continue
|
|
166
199
|
rendered.push(
|
|
167
200
|
cloneElement(child as ReactElement<Record<string, unknown>>, { index: sources.length, sourceIndex: authored }),
|
|
168
201
|
)
|
|
@@ -7,16 +7,15 @@
|
|
|
7
7
|
|
|
8
8
|
'use client'
|
|
9
9
|
|
|
10
|
-
import { Menu } from '@base-ui/react/menu'
|
|
11
|
-
import { forwardRef, type HTMLAttributes, type ReactNode,
|
|
12
|
-
import {
|
|
10
|
+
import { Menu, type MenuRootChangeEventDetails } from '@base-ui/react/menu'
|
|
11
|
+
import { forwardRef, type HTMLAttributes, type ReactNode, useMemo } from 'react'
|
|
12
|
+
import { useIcon } from '../../../lib/icon-context'
|
|
13
13
|
import { type AnchorProps, OverlayContext, positionerProps, useOverlay, useOverlayRoot } from '../../../lib/overlay'
|
|
14
|
-
import { useRowIndex } from '../../../lib/row-index'
|
|
15
14
|
import { useSize } from '../../../lib/size-context'
|
|
16
15
|
import type { MorphProps } from '../../../lib/use-morph'
|
|
17
16
|
import { cn } from '../../../lib/utils'
|
|
18
|
-
import { DropdownContext, type DropdownContextValue,
|
|
19
|
-
import { MenuPopup } from './menu-popup'
|
|
17
|
+
import { DropdownContext, type DropdownContextValue, type MenuItemProps, MenuRow, useDropdown } from './menu-item'
|
|
18
|
+
import { type MenuFocusProps, MenuPopup } from './menu-popup'
|
|
20
19
|
import type { PanelSelectionProps } from './panel-state'
|
|
21
20
|
|
|
22
21
|
interface DropdownSubProps {
|
|
@@ -26,19 +25,28 @@ interface DropdownSubProps {
|
|
|
26
25
|
open?: boolean
|
|
27
26
|
/** Initial open state, uncontrolled. Defaults to `false`. */
|
|
28
27
|
defaultOpen?: boolean
|
|
29
|
-
/** Called when the submenu opens or closes. */
|
|
30
|
-
onOpenChange?: (open: boolean) => void
|
|
28
|
+
/** Called when the submenu opens or closes, with Base UI's change details: `reason`, the `event`, and `cancel()` to keep it as it is. */
|
|
29
|
+
onOpenChange?: (open: boolean, details: MenuRootChangeEventDetails) => void
|
|
31
30
|
/** Disables the submenu: its trigger row dims and never opens it. Defaults to `false`. */
|
|
32
31
|
disabled?: boolean
|
|
33
32
|
}
|
|
34
33
|
|
|
35
34
|
/** A submenu: its trigger row and its panel, inside `Dropdown.Content` or another submenu. */
|
|
36
35
|
function DropdownSub({ children, open, defaultOpen, onOpenChange, disabled = false }: DropdownSubProps) {
|
|
37
|
-
const root = useOverlayRoot({ open, defaultOpen
|
|
36
|
+
const root = useOverlayRoot({ open, defaultOpen })
|
|
38
37
|
|
|
39
38
|
return (
|
|
40
39
|
<OverlayContext.Provider value={root.state}>
|
|
41
|
-
<Menu.SubmenuRoot
|
|
40
|
+
<Menu.SubmenuRoot
|
|
41
|
+
open={root.open}
|
|
42
|
+
onOpenChange={(next, details) => {
|
|
43
|
+
// Base UI re-reports a closed submenu as closed once per sibling that opens: the handler hears changes only.
|
|
44
|
+
if (next === root.open) return
|
|
45
|
+
onOpenChange?.(next, details)
|
|
46
|
+
if (!details.isCanceled) root.onOpenChange(next, details)
|
|
47
|
+
}}
|
|
48
|
+
disabled={disabled}
|
|
49
|
+
>
|
|
42
50
|
{children}
|
|
43
51
|
</Menu.SubmenuRoot>
|
|
44
52
|
</OverlayContext.Provider>
|
|
@@ -47,13 +55,8 @@ function DropdownSub({ children, open, defaultOpen, onOpenChange, disabled = fal
|
|
|
47
55
|
|
|
48
56
|
DropdownSub.displayName = 'DropdownSub'
|
|
49
57
|
|
|
50
|
-
interface DropdownSubTriggerProps
|
|
51
|
-
|
|
52
|
-
icon?: IconComponent
|
|
53
|
-
/** The row's label; also its typeahead text. */
|
|
54
|
-
label: string
|
|
55
|
-
/** Position among the parent panel's rows. Omitted, the row takes its place in order. */
|
|
56
|
-
index?: number
|
|
58
|
+
interface DropdownSubTriggerProps
|
|
59
|
+
extends Omit<MenuItemProps, 'checked' | 'onSelect' | 'closeOnClick' | 'render' | 'asChild' | 'sourceIndex'> {
|
|
57
60
|
/** Dims the row; the pointer and the keyboard skip it. Defaults to `false`. */
|
|
58
61
|
disabled?: boolean
|
|
59
62
|
/** Open the submenu when the pointer rests on the row. Defaults to `true`. */
|
|
@@ -70,19 +73,12 @@ interface DropdownSubTriggerProps extends Omit<HTMLAttributes<HTMLDivElement>, '
|
|
|
70
73
|
* stays lit while its submenu is open.
|
|
71
74
|
*/
|
|
72
75
|
const DropdownSubTrigger = forwardRef<HTMLDivElement, DropdownSubTriggerProps>(
|
|
73
|
-
({
|
|
76
|
+
({ openOnHover = true, delay, closeDelay, ...props }, ref) => {
|
|
74
77
|
const { open } = useOverlay('Dropdown.SubTrigger')
|
|
75
|
-
const index = useRowIndex(indexProp)
|
|
76
78
|
const parent = useDropdown()
|
|
77
|
-
const { pin } = parent
|
|
78
79
|
const Chevron = useIcon('chevron-right')
|
|
79
80
|
const size = useSize()
|
|
80
81
|
|
|
81
|
-
useEffect(() => {
|
|
82
|
-
pin?.(index, open)
|
|
83
|
-
return () => pin?.(index, false)
|
|
84
|
-
}, [pin, index, open])
|
|
85
|
-
|
|
86
82
|
const ctx = useMemo<DropdownContextValue>(
|
|
87
83
|
() => ({
|
|
88
84
|
...parent,
|
|
@@ -104,7 +100,7 @@ const DropdownSubTrigger = forwardRef<HTMLDivElement, DropdownSubTriggerProps>(
|
|
|
104
100
|
size={size.icon}
|
|
105
101
|
strokeWidth={open ? 2 : 1.5}
|
|
106
102
|
className={cn(
|
|
107
|
-
'shrink-0 transition-[color,stroke-width] duration-fast',
|
|
103
|
+
'ml-auto shrink-0 transition-[color,stroke-width] duration-fast',
|
|
108
104
|
open ? 'text-foreground' : 'text-muted-foreground',
|
|
109
105
|
)}
|
|
110
106
|
/>
|
|
@@ -116,7 +112,7 @@ const DropdownSubTrigger = forwardRef<HTMLDivElement, DropdownSubTriggerProps>(
|
|
|
116
112
|
|
|
117
113
|
return (
|
|
118
114
|
<DropdownContext.Provider value={ctx}>
|
|
119
|
-
<
|
|
115
|
+
<MenuRow ref={ref} pinned={open} {...props} />
|
|
120
116
|
</DropdownContext.Provider>
|
|
121
117
|
)
|
|
122
118
|
},
|
|
@@ -126,6 +122,7 @@ DropdownSubTrigger.displayName = 'DropdownSubTrigger'
|
|
|
126
122
|
|
|
127
123
|
interface DropdownSubContentProps
|
|
128
124
|
extends PanelSelectionProps,
|
|
125
|
+
MenuFocusProps,
|
|
129
126
|
AnchorProps,
|
|
130
127
|
MorphProps,
|
|
131
128
|
Omit<HTMLAttributes<HTMLDivElement>, 'children'> {
|
|
@@ -139,6 +136,8 @@ interface DropdownSubContentProps
|
|
|
139
136
|
sideOffset?: number
|
|
140
137
|
/** Extra classes for the submenu surface: it is 14rem wide by default. */
|
|
141
138
|
className?: string
|
|
139
|
+
/** Keep the submenu mounted (hidden) while closed, so its rows keep their own state across opens. A kept parent keeps it too. Defaults to `false`. */
|
|
140
|
+
keepMounted?: boolean
|
|
142
141
|
}
|
|
143
142
|
|
|
144
143
|
/** The submenu's panel, lifted above the menu it came from and grown out of its trigger row. */
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import Lightbox from './index'
|
|
2
|
+
|
|
3
|
+
# Attachment strip
|
|
4
|
+
|
|
5
|
+
Press a thumbnail: its image grows out of it. Step with the arrow keys, the side buttons or a swipe; Escape shrinks it back into the thumbnail of the image showing. Click the image to zoom.
|
|
6
|
+
|
|
7
|
+
<Lightbox
|
|
8
|
+
items={[
|
|
9
|
+
{ src: "data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' width='1600' height='1000' viewBox='0 0 1600 1000'><radialGradient id='a' cx='.2' cy='.15' r='1'><stop stop-color='%236B97FF'/><stop offset='1' stop-color='%231E2A4A'/></radialGradient><rect width='1600' height='1000' fill='url(%23a)'/></svg>", alt: 'Dashboard screenshot', caption: 'The new dashboard' },
|
|
10
|
+
{ src: "data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' width='1000' height='1400' viewBox='0 0 1000 1400'><radialGradient id='a' cx='.7' cy='.2' r='1'><stop stop-color='%23FFB36B'/><stop offset='1' stop-color='%234A2A1E'/></radialGradient><rect width='1000' height='1400' fill='url(%23a)'/></svg>", alt: 'Mobile settings screen', caption: 'Settings on a phone' },
|
|
11
|
+
{ src: "data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' width='1400' height='1400' viewBox='0 0 1400 1400'><radialGradient id='a' cx='.5' cy='.5' r='1'><stop stop-color='%237BE0A8'/><stop offset='1' stop-color='%231E4A35'/></radialGradient><rect width='1400' height='1400' fill='url(%23a)'/></svg>", alt: 'App icon draft', caption: 'Icon, third draft' },
|
|
12
|
+
{ src: "data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' width='1800' height='900' viewBox='0 0 1800 900'><radialGradient id='a' cx='.8' cy='.8' r='1'><stop stop-color='%23D18BFF'/><stop offset='1' stop-color='%232E1E4A'/></radialGradient><rect width='1800' height='900' fill='url(%23a)'/></svg>", alt: 'Onboarding banner', caption: 'Onboarding banner' },
|
|
13
|
+
]}
|
|
14
|
+
>
|
|
15
|
+
<div className="flex gap-2">
|
|
16
|
+
<Lightbox.Trigger index={0} />
|
|
17
|
+
<Lightbox.Trigger index={1} />
|
|
18
|
+
<Lightbox.Trigger index={2} />
|
|
19
|
+
<Lightbox.Trigger index={3} />
|
|
20
|
+
</div>
|
|
21
|
+
</Lightbox>
|
|
22
|
+
|
|
23
|
+
# One image, no zoom
|
|
24
|
+
|
|
25
|
+
A single image has no stepping; `zoom={false}` keeps clicks on the image inert.
|
|
26
|
+
|
|
27
|
+
<Lightbox zoom={false} items={[{ src: "data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' width='1600' height='1000' viewBox='0 0 1600 1000'><radialGradient id='a' cx='.2' cy='.15' r='1'><stop stop-color='%236B97FF'/><stop offset='1' stop-color='%231E2A4A'/></radialGradient><rect width='1600' height='1000' fill='url(%23a)'/></svg>", alt: 'Dashboard screenshot' }]}>
|
|
28
|
+
<Lightbox.Trigger index={0} className="h-24 w-40" />
|
|
29
|
+
</Lightbox>
|
|
@@ -0,0 +1,395 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Local addition (not part of Fluid Functionalism): a full-window image
|
|
3
|
+
* viewer over the scrim. The image grows out of the thumbnail that opened it
|
|
4
|
+
* through the shared morph (`lib/use-morph.ts` + `MorphSurface`, a plain
|
|
5
|
+
* morph from the trigger) and, scaled to cover the growing shape, closes back
|
|
6
|
+
* into whichever thumbnail is current. Base UI's Dialog keeps focus, Escape
|
|
7
|
+
* and scroll lock.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
'use client'
|
|
11
|
+
|
|
12
|
+
import { Dialog as DialogPrimitive } from '@base-ui/react/dialog'
|
|
13
|
+
import { motion, useMotionValueEvent } from 'motion/react'
|
|
14
|
+
import {
|
|
15
|
+
createContext,
|
|
16
|
+
type KeyboardEvent,
|
|
17
|
+
type MouseEvent,
|
|
18
|
+
type PointerEvent,
|
|
19
|
+
type ReactNode,
|
|
20
|
+
useContext,
|
|
21
|
+
useLayoutEffect,
|
|
22
|
+
useMemo,
|
|
23
|
+
useRef,
|
|
24
|
+
useState,
|
|
25
|
+
} from 'react'
|
|
26
|
+
import { useIcon } from '../../../lib/icon-context'
|
|
27
|
+
import { MorphSurface } from '../../../lib/morph-layers'
|
|
28
|
+
import { useReduceMotion } from '../../../lib/reduced-motion'
|
|
29
|
+
import { useShape } from '../../../lib/shape-context'
|
|
30
|
+
import { spring, springEnter } from '../../../lib/springs'
|
|
31
|
+
import { SURFACE_BG, SURFACE_SHADOW } from '../../../lib/surface-classes'
|
|
32
|
+
import { SurfaceProvider, useLift } from '../../../lib/surface-context'
|
|
33
|
+
import { useControllableState } from '../../../lib/use-controllable-state'
|
|
34
|
+
import { holdExit, type MorphOrigin, useMorph, useMorphOrigin } from '../../../lib/use-morph'
|
|
35
|
+
import { cn } from '../../../lib/utils'
|
|
36
|
+
import Button from '../../actions/button'
|
|
37
|
+
|
|
38
|
+
/** One image: its source, its description, and optionally a smaller thumbnail and a caption. */
|
|
39
|
+
interface LightboxImage {
|
|
40
|
+
src: string
|
|
41
|
+
alt: string
|
|
42
|
+
thumbnail?: string
|
|
43
|
+
caption?: string
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
interface LightboxState {
|
|
47
|
+
items: LightboxImage[]
|
|
48
|
+
current: number | null
|
|
49
|
+
open: (index: number, trigger: HTMLElement, event: Event) => void
|
|
50
|
+
register: (index: number, el: HTMLElement | null) => void
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const LightboxContext = createContext<LightboxState | null>(null)
|
|
54
|
+
|
|
55
|
+
const SWIPE = 48
|
|
56
|
+
const ZOOM = 2
|
|
57
|
+
const MOVE = springEnter(spring.moderate)
|
|
58
|
+
const STILL = { duration: 0 }
|
|
59
|
+
|
|
60
|
+
interface LightboxTriggerProps {
|
|
61
|
+
/** Which item it opens, counted from 0. */
|
|
62
|
+
index: number
|
|
63
|
+
/** What the thumbnail shows. Defaults to the item's `thumbnail` (or `src`), cropped to fill. */
|
|
64
|
+
children?: ReactNode
|
|
65
|
+
/** Accessible name. Defaults to "View" followed by the item's `alt`. */
|
|
66
|
+
label?: string
|
|
67
|
+
/** Classes for the button: its size, and its radius, which the opening image starts from. */
|
|
68
|
+
className?: string
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** A thumbnail that opens the lightbox at its item. */
|
|
72
|
+
function LightboxTrigger({ index, children, label, className }: LightboxTriggerProps) {
|
|
73
|
+
const lightbox = useContext(LightboxContext)
|
|
74
|
+
const shape = useShape()
|
|
75
|
+
if (!lightbox) throw new Error('Lightbox.Trigger must sit inside a Lightbox.')
|
|
76
|
+
const item = lightbox.items[index]
|
|
77
|
+
|
|
78
|
+
return (
|
|
79
|
+
<button
|
|
80
|
+
ref={el => lightbox.register(index, el)}
|
|
81
|
+
type="button"
|
|
82
|
+
aria-label={label ?? `View ${item?.alt ?? `image ${index + 1}`}`}
|
|
83
|
+
aria-haspopup="dialog"
|
|
84
|
+
onClick={e => lightbox.open(index, e.currentTarget, e.nativeEvent)}
|
|
85
|
+
className={cn(
|
|
86
|
+
'relative block size-16 shrink-0 cursor-zoom-in overflow-hidden bg-muted outline-none focus-visible:ring-1 focus-visible:ring-focus-ring',
|
|
87
|
+
shape.item,
|
|
88
|
+
className,
|
|
89
|
+
)}
|
|
90
|
+
>
|
|
91
|
+
{children ??
|
|
92
|
+
(item && <img src={item.thumbnail ?? item.src} alt="" draggable={false} className="size-full object-cover" />)}
|
|
93
|
+
</button>
|
|
94
|
+
)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
interface ViewerProps {
|
|
98
|
+
items: LightboxImage[]
|
|
99
|
+
current: number | null
|
|
100
|
+
origin: { current: MorphOrigin }
|
|
101
|
+
zoom: boolean
|
|
102
|
+
onValueChange: (index: number | null) => void
|
|
103
|
+
onExited: () => void
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function Viewer({ items, current, origin, zoom, onValueChange, onExited }: ViewerProps) {
|
|
107
|
+
const open = current !== null
|
|
108
|
+
const outer = useRef<HTMLDivElement>(null)
|
|
109
|
+
const frame = useRef<HTMLDivElement>(null)
|
|
110
|
+
const hold = useRef<Animation | null>(null)
|
|
111
|
+
const swipe = useRef<{ x: number; moved: boolean } | null>(null)
|
|
112
|
+
const [shown, setShown] = useState(current ?? 0)
|
|
113
|
+
const [zoomed, setZoomed] = useState<{ x: number; y: number } | null>(null)
|
|
114
|
+
const [stepped, setStepped] = useState(false)
|
|
115
|
+
const reduced = useReduceMotion()
|
|
116
|
+
const shape = useShape()
|
|
117
|
+
const level = useLift(4)
|
|
118
|
+
const X = useIcon('x')
|
|
119
|
+
const ArrowLeft = useIcon('arrow-left')
|
|
120
|
+
const ArrowRight = useIcon('arrow-right')
|
|
121
|
+
|
|
122
|
+
const morph = useMorph(open, origin, { effect: 'morph', hideSource: true }, () => {
|
|
123
|
+
hold.current?.finish()
|
|
124
|
+
onExited()
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
// The image fades in only when stepping, not when it grows out of its thumbnail.
|
|
128
|
+
const [seen, setSeen] = useState(current)
|
|
129
|
+
if (current !== seen) {
|
|
130
|
+
setSeen(current)
|
|
131
|
+
setZoomed(null)
|
|
132
|
+
if (current !== null) {
|
|
133
|
+
setShown(current)
|
|
134
|
+
setStepped(seen !== null)
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
const item = items[shown]
|
|
138
|
+
|
|
139
|
+
// Base UI waits on the popup's own animations; the morph runs on the image box inside it.
|
|
140
|
+
useLayoutEffect(() => {
|
|
141
|
+
if (open || !outer.current) return
|
|
142
|
+
hold.current = holdExit(outer.current, 'slow')
|
|
143
|
+
return () => hold.current?.cancel()
|
|
144
|
+
}, [open])
|
|
145
|
+
|
|
146
|
+
// The image covers the growing shape, scaled from the thumbnail rather than revealed by the clip alone.
|
|
147
|
+
useMotionValueEvent(morph.progress, 'change', p => {
|
|
148
|
+
const el = frame.current
|
|
149
|
+
const box = morph.popup?.getBoundingClientRect()
|
|
150
|
+
const thumb = origin.current.trigger?.getBoundingClientRect()
|
|
151
|
+
if (!el) return
|
|
152
|
+
if (p >= 1 || morph.effect === 'fade' || !box || !thumb?.width) {
|
|
153
|
+
el.style.transform = ''
|
|
154
|
+
return
|
|
155
|
+
}
|
|
156
|
+
const w = thumb.width + (box.width - thumb.width) * p
|
|
157
|
+
const h = thumb.height + (box.height - thumb.height) * p
|
|
158
|
+
const x = (thumb.left - box.left) * (1 - p) + w / 2 - box.width / 2
|
|
159
|
+
const y = (thumb.top - box.top) * (1 - p) + h / 2 - box.height / 2
|
|
160
|
+
el.style.transform = `translate(${x}px, ${y}px) scale(${Math.max(w / box.width, h / box.height)})`
|
|
161
|
+
})
|
|
162
|
+
|
|
163
|
+
const step = (by: number) => {
|
|
164
|
+
if (current === null || items.length < 2) return
|
|
165
|
+
onValueChange((current + by + items.length) % items.length)
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const onKeyDown = (e: KeyboardEvent) => {
|
|
169
|
+
if (e.key === 'ArrowLeft') step(-1)
|
|
170
|
+
else if (e.key === 'ArrowRight') step(1)
|
|
171
|
+
else return
|
|
172
|
+
e.preventDefault()
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const onPointerDown = (e: PointerEvent) => {
|
|
176
|
+
if (zoomed || e.button !== 0) return
|
|
177
|
+
swipe.current = { x: e.clientX, moved: false }
|
|
178
|
+
}
|
|
179
|
+
const onPointerUp = (e: PointerEvent) => {
|
|
180
|
+
const start = swipe.current
|
|
181
|
+
if (!start) return
|
|
182
|
+
const dx = e.clientX - start.x
|
|
183
|
+
start.moved = Math.abs(dx) > 6
|
|
184
|
+
if (Math.abs(dx) > SWIPE) step(dx < 0 ? 1 : -1)
|
|
185
|
+
}
|
|
186
|
+
const onImageClick = (e: MouseEvent<HTMLImageElement>) => {
|
|
187
|
+
if (!zoom || swipe.current?.moved) return
|
|
188
|
+
const rect = e.currentTarget.getBoundingClientRect()
|
|
189
|
+
setZoomed(
|
|
190
|
+
zoomed
|
|
191
|
+
? null
|
|
192
|
+
: { x: ((e.clientX - rect.left) / rect.width) * 100, y: ((e.clientY - rect.top) / rect.height) * 100 },
|
|
193
|
+
)
|
|
194
|
+
}
|
|
195
|
+
const onImageMove = (e: MouseEvent<HTMLImageElement>) => {
|
|
196
|
+
if (!zoomed) return
|
|
197
|
+
const rect = e.currentTarget.getBoundingClientRect()
|
|
198
|
+
setZoomed({ x: ((e.clientX - rect.left) / rect.width) * 100, y: ((e.clientY - rect.top) / rect.height) * 100 })
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
const chrome = { style: { opacity: morph.progress } }
|
|
202
|
+
const many = items.length > 1
|
|
203
|
+
|
|
204
|
+
return (
|
|
205
|
+
<DialogPrimitive.Portal>
|
|
206
|
+
<DialogPrimitive.Backdrop
|
|
207
|
+
render={<motion.div style={{ opacity: morph.progress }} />}
|
|
208
|
+
className="fixed inset-0 z-50 bg-scrim"
|
|
209
|
+
/>
|
|
210
|
+
<DialogPrimitive.Popup
|
|
211
|
+
ref={outer}
|
|
212
|
+
aria-label={item?.alt}
|
|
213
|
+
finalFocus={() => origin.current.trigger ?? true}
|
|
214
|
+
onKeyDown={onKeyDown}
|
|
215
|
+
onClick={e => e.target === e.currentTarget && onValueChange(null)}
|
|
216
|
+
className="fixed inset-0 z-50 flex items-center justify-center p-[var(--space-6)] outline-none"
|
|
217
|
+
>
|
|
218
|
+
<SurfaceProvider value={level}>
|
|
219
|
+
<div ref={morph.popupRef} className="relative">
|
|
220
|
+
<MorphSurface
|
|
221
|
+
morph={morph}
|
|
222
|
+
bg={SURFACE_BG[level]}
|
|
223
|
+
shadow={SURFACE_SHADOW[level]}
|
|
224
|
+
radius={shape.container}
|
|
225
|
+
className={cn('overflow-hidden', shape.container)}
|
|
226
|
+
>
|
|
227
|
+
<div ref={frame} className="origin-center">
|
|
228
|
+
{item && (
|
|
229
|
+
<motion.img
|
|
230
|
+
key={shown}
|
|
231
|
+
src={item.src}
|
|
232
|
+
alt={item.alt}
|
|
233
|
+
draggable={false}
|
|
234
|
+
initial={stepped ? { opacity: 0 } : false}
|
|
235
|
+
animate={{ opacity: 1, scale: zoomed ? ZOOM : 1 }}
|
|
236
|
+
transition={reduced ? STILL : MOVE}
|
|
237
|
+
style={{ transformOrigin: zoomed ? `${zoomed.x}% ${zoomed.y}%` : undefined }}
|
|
238
|
+
onPointerDown={onPointerDown}
|
|
239
|
+
onPointerUp={onPointerUp}
|
|
240
|
+
onClick={onImageClick}
|
|
241
|
+
onMouseMove={onImageMove}
|
|
242
|
+
className={cn(
|
|
243
|
+
'block max-h-[calc(100dvh-10rem)] max-w-[calc(100vw-10rem)] touch-pan-y select-none object-contain',
|
|
244
|
+
zoom && (zoomed ? 'cursor-zoom-out' : 'cursor-zoom-in'),
|
|
245
|
+
)}
|
|
246
|
+
/>
|
|
247
|
+
)}
|
|
248
|
+
</div>
|
|
249
|
+
</MorphSurface>
|
|
250
|
+
</div>
|
|
251
|
+
|
|
252
|
+
<motion.div {...chrome} className="absolute top-[var(--space-4)] right-[var(--space-4)]">
|
|
253
|
+
<DialogPrimitive.Close
|
|
254
|
+
render={
|
|
255
|
+
<Button variant="secondary" size="icon" aria-label="Close">
|
|
256
|
+
<X />
|
|
257
|
+
</Button>
|
|
258
|
+
}
|
|
259
|
+
/>
|
|
260
|
+
</motion.div>
|
|
261
|
+
|
|
262
|
+
{many && (
|
|
263
|
+
<>
|
|
264
|
+
<motion.div {...chrome} className="absolute top-1/2 left-[var(--space-4)] -translate-y-1/2">
|
|
265
|
+
<Button variant="secondary" size="icon" aria-label="Previous image" onClick={() => step(-1)}>
|
|
266
|
+
<ArrowLeft />
|
|
267
|
+
</Button>
|
|
268
|
+
</motion.div>
|
|
269
|
+
<motion.div {...chrome} className="absolute top-1/2 right-[var(--space-4)] -translate-y-1/2">
|
|
270
|
+
<Button variant="secondary" size="icon" aria-label="Next image" onClick={() => step(1)}>
|
|
271
|
+
<ArrowRight />
|
|
272
|
+
</Button>
|
|
273
|
+
</motion.div>
|
|
274
|
+
</>
|
|
275
|
+
)}
|
|
276
|
+
|
|
277
|
+
{(many || item?.caption) && (
|
|
278
|
+
<motion.div
|
|
279
|
+
{...chrome}
|
|
280
|
+
aria-live="polite"
|
|
281
|
+
className={cn(
|
|
282
|
+
'absolute bottom-[var(--space-4)] left-1/2 flex max-w-[calc(100vw-2rem)] -translate-x-1/2 items-center gap-2 px-3 py-1.5 text-caption',
|
|
283
|
+
SURFACE_BG[level],
|
|
284
|
+
SURFACE_SHADOW[3],
|
|
285
|
+
shape.button,
|
|
286
|
+
)}
|
|
287
|
+
>
|
|
288
|
+
{many && (
|
|
289
|
+
<span className="shrink-0 tabular-nums text-muted-foreground">{`${shown + 1} / ${items.length}`}</span>
|
|
290
|
+
)}
|
|
291
|
+
{item?.caption && <span className="truncate text-foreground">{item.caption}</span>}
|
|
292
|
+
</motion.div>
|
|
293
|
+
)}
|
|
294
|
+
</SurfaceProvider>
|
|
295
|
+
</DialogPrimitive.Popup>
|
|
296
|
+
</DialogPrimitive.Portal>
|
|
297
|
+
)
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
interface LightboxProps {
|
|
301
|
+
/** The images, in viewing order: `{ src, alt, thumbnail?, caption? }`. */
|
|
302
|
+
items: LightboxImage[]
|
|
303
|
+
/** Controlled open item, counted from 0, or `null` while closed. Pair with `onValueChange`. */
|
|
304
|
+
value?: number | null
|
|
305
|
+
/** Item open at first, for an uncontrolled lightbox. Defaults to `null`. */
|
|
306
|
+
defaultValue?: number | null
|
|
307
|
+
/** Called with the item shown, or `null` when the lightbox closes. */
|
|
308
|
+
onValueChange?: (value: number | null) => void
|
|
309
|
+
/** Click the image to zoom in at that point, move to pan, click again to zoom out. Defaults to `true`. */
|
|
310
|
+
zoom?: boolean
|
|
311
|
+
/** The thumbnails (`Lightbox.Trigger`) and whatever lays them out. */
|
|
312
|
+
children?: ReactNode
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* Images viewed full-window, grown out of the thumbnail you pressed.
|
|
317
|
+
*
|
|
318
|
+
* Press a thumbnail and its image grows out of it over the scrim, scaled from
|
|
319
|
+
* the thumbnail's box to the window's, while the thumbnail steps aside (see
|
|
320
|
+
* Morph). The arrow keys, the side buttons or a swipe step through the items;
|
|
321
|
+
* Escape, the close button or a click on the scrim closes it, and the image
|
|
322
|
+
* shrinks back into the thumbnail of whichever item is showing. A click on
|
|
323
|
+
* the image zooms in at that point and follows the pointer; another zooms
|
|
324
|
+
* out. Built on Base UI's Dialog, so focus stays inside and returns to the
|
|
325
|
+
* thumbnail. Works controlled (`value` + `onValueChange`: the item's index, `null`
|
|
326
|
+
* closed) or uncontrolled (`defaultValue`).
|
|
327
|
+
*
|
|
328
|
+
* Statics:
|
|
329
|
+
* - `Lightbox.Trigger` — one thumbnail: `index`, `children` to draw your
|
|
330
|
+
* own, `label`, `className` (its size and radius).
|
|
331
|
+
*
|
|
332
|
+
* @example {@include ./examples.mdx}
|
|
333
|
+
*/
|
|
334
|
+
const Lightbox = Object.assign(
|
|
335
|
+
function Lightbox({ items, value, defaultValue = null, onValueChange, zoom = true, children }: LightboxProps) {
|
|
336
|
+
const [current, setCurrent] = useControllableState<number | null>(value, defaultValue, onValueChange)
|
|
337
|
+
const { origin, capture } = useMorphOrigin()
|
|
338
|
+
const triggers = useRef(new Map<number, HTMLElement>())
|
|
339
|
+
// A thumbnail this hid when stepping to its item, shown again once the close lands.
|
|
340
|
+
const swapped = useRef<HTMLElement | null>(null)
|
|
341
|
+
|
|
342
|
+
// Stepping to another item makes its thumbnail the one to close into.
|
|
343
|
+
useLayoutEffect(() => {
|
|
344
|
+
if (current === null) return
|
|
345
|
+
const el = triggers.current.get(current)
|
|
346
|
+
const previous = origin.current.trigger
|
|
347
|
+
if (!el || el === previous) return
|
|
348
|
+
if (previous) previous.style.opacity = ''
|
|
349
|
+
el.style.opacity = '0'
|
|
350
|
+
swapped.current = el
|
|
351
|
+
origin.current.trigger = el
|
|
352
|
+
}, [current, origin])
|
|
353
|
+
|
|
354
|
+
const ctx = useMemo<LightboxState>(
|
|
355
|
+
() => ({
|
|
356
|
+
items,
|
|
357
|
+
current,
|
|
358
|
+
open: (at, trigger, event) => {
|
|
359
|
+
capture({ trigger, event })
|
|
360
|
+
setCurrent(at)
|
|
361
|
+
},
|
|
362
|
+
register: (at, el) => {
|
|
363
|
+
if (el) triggers.current.set(at, el)
|
|
364
|
+
else triggers.current.delete(at)
|
|
365
|
+
},
|
|
366
|
+
}),
|
|
367
|
+
[items, current, capture, setCurrent],
|
|
368
|
+
)
|
|
369
|
+
|
|
370
|
+
return (
|
|
371
|
+
<LightboxContext.Provider value={ctx}>
|
|
372
|
+
<DialogPrimitive.Root open={current !== null} onOpenChange={next => next || setCurrent(null)}>
|
|
373
|
+
{children}
|
|
374
|
+
<Viewer
|
|
375
|
+
items={items}
|
|
376
|
+
current={current}
|
|
377
|
+
origin={origin}
|
|
378
|
+
zoom={zoom}
|
|
379
|
+
onValueChange={setCurrent}
|
|
380
|
+
onExited={() => {
|
|
381
|
+
if (swapped.current) swapped.current.style.opacity = ''
|
|
382
|
+
swapped.current = null
|
|
383
|
+
}}
|
|
384
|
+
/>
|
|
385
|
+
</DialogPrimitive.Root>
|
|
386
|
+
</LightboxContext.Provider>
|
|
387
|
+
)
|
|
388
|
+
},
|
|
389
|
+
{ Trigger: LightboxTrigger },
|
|
390
|
+
)
|
|
391
|
+
|
|
392
|
+
export type { LightboxImage, LightboxProps, LightboxTriggerProps }
|
|
393
|
+
export { Lightbox, LightboxTrigger }
|
|
394
|
+
|
|
395
|
+
export default Lightbox
|