@jcsoftdev/ui 0.5.0 → 0.7.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/CHANGELOG.md +361 -0
- package/README.md +31 -5
- package/bin/ui-theme.mjs +40 -6
- package/dist/ai/code-block/code-block.js +1 -1
- package/dist/atoms/avatar/avatar.d.ts +6 -1
- package/dist/atoms/avatar/avatar.js +3 -2
- package/dist/atoms/big-date/big-date.js +2 -2
- package/dist/atoms/button/button.d.ts +6 -1
- package/dist/atoms/button/button.js +2 -2
- package/dist/atoms/chip/chip.d.ts +5 -0
- package/dist/atoms/chip/chip.js +3 -3
- package/dist/atoms/icon-button/icon-button.js +1 -1
- package/dist/atoms/internal/hit-area.d.ts +5 -4
- package/dist/atoms/internal/hit-area.js +1 -1
- package/dist/atoms/progress/index.d.ts +1 -1
- package/dist/atoms/progress/index.js +4 -1
- package/dist/atoms/progress/progress.d.ts +6 -1
- package/dist/atoms/progress/progress.js +19 -1
- package/dist/atoms/radio-group/radio-group.js +1 -1
- package/dist/atoms/status-pill/status-pill.d.ts +16 -5
- package/dist/atoms/status-pill/status-pill.js +43 -18
- package/dist/brand/logo-forge.js +1 -1
- package/dist/charts/candlestick-chart/candlestick-chart.js +2 -2
- package/dist/charts/chart-grid/chart-grid.js +2 -2
- package/dist/charts/chord-chart/chord-chart.js +1 -1
- package/dist/charts/core/axes.js +2 -2
- package/dist/charts/core/cartesian/annotations.js +2 -2
- package/dist/charts/core/cartesian/marks.js +1 -1
- package/dist/charts/core/distribution/marks.js +1 -1
- package/dist/charts/core/distribution/xy-points.js +1 -1
- package/dist/charts/core/export-menu.js +1 -1
- package/dist/charts/funnel-chart/funnel-chart.js +1 -1
- package/dist/charts/gantt-chart/gantt-chart.js +4 -4
- package/dist/charts/gantt-chart/gantt-marks.js +3 -3
- package/dist/charts/index.d.ts +2 -0
- package/dist/charts/index.js +2 -0
- package/dist/charts/maps/geo/map-data-table.js +1 -1
- package/dist/charts/polar-area-chart/polar-area-chart.js +1 -1
- package/dist/charts/radar-chart/radar-chart.js +1 -1
- package/dist/charts/stock-chart/stock-chart.js +1 -1
- package/dist/charts/stock-chart/stock-drawing-layer.js +3 -3
- package/dist/charts/stock-chart/stock-plot.js +2 -2
- package/dist/containers/chat-thread/chat-thread.d.ts +98 -0
- package/dist/containers/chat-thread/chat-thread.js +219 -0
- package/dist/containers/chat-thread/format.d.ts +20 -0
- package/dist/containers/chat-thread/format.js +50 -0
- package/dist/containers/chat-thread/index.d.ts +1 -0
- package/dist/containers/chat-thread/index.js +8 -0
- package/dist/containers/cols/cols.d.ts +1 -1
- package/dist/containers/cols/cols.js +7 -0
- package/dist/containers/comment/comment.js +1 -1
- package/dist/containers/context-rail/context-rail.d.ts +62 -0
- package/dist/containers/context-rail/context-rail.js +175 -0
- package/dist/containers/context-rail/index.d.ts +1 -0
- package/dist/containers/context-rail/index.js +6 -0
- package/dist/containers/dashboard/dashboard.d.ts +40 -0
- package/dist/containers/dashboard/dashboard.js +84 -0
- package/dist/containers/dashboard/index.d.ts +1 -0
- package/dist/containers/dashboard/index.js +14 -0
- package/dist/containers/data-grid/data-grid.demos.js +4 -4
- package/dist/containers/data-grid/data-grid.js +6 -6
- package/dist/containers/data-grid/filter-builder-editor.js +2 -2
- package/dist/containers/data-grid/grid-toolbar.js +1 -1
- package/dist/containers/data-grid/spreadsheet.demos.d.ts +1 -1
- package/dist/containers/data-grid/spreadsheet.demos.js +1 -1
- package/dist/containers/detail-header/detail-header.d.ts +24 -0
- package/dist/containers/detail-header/detail-header.js +32 -0
- package/dist/containers/detail-header/index.d.ts +1 -0
- package/dist/containers/detail-header/index.js +6 -0
- package/dist/containers/facts/facts.js +1 -1
- package/dist/containers/filter-bar/filter-bar.d.ts +58 -0
- package/dist/containers/filter-bar/filter-bar.js +123 -0
- package/dist/containers/filter-bar/index.d.ts +1 -0
- package/dist/containers/filter-bar/index.js +6 -0
- package/dist/containers/hbars/hbars.js +2 -2
- package/dist/containers/index.d.ts +9 -0
- package/dist/containers/index.js +9 -0
- package/dist/containers/kanban/kanban.d.ts +23 -2
- package/dist/containers/kanban/kanban.js +103 -21
- package/dist/containers/kanban/model.d.ts +12 -0
- package/dist/containers/kanban/model.js +8 -0
- package/dist/containers/kpi/kpi.js +1 -1
- package/dist/containers/kpi-group/kpi-group.d.ts +6 -1
- package/dist/containers/kpi-group/kpi-group.js +6 -2
- package/dist/containers/list-detail/index.d.ts +1 -1
- package/dist/containers/list-detail/index.js +4 -0
- package/dist/containers/list-detail/list-detail.d.ts +51 -3
- package/dist/containers/list-detail/list-detail.js +111 -15
- package/dist/containers/page/page.d.ts +17 -4
- package/dist/containers/page/page.js +33 -4
- package/dist/containers/page-header/back.d.ts +10 -0
- package/dist/containers/page-header/back.js +28 -0
- package/dist/containers/page-header/index.d.ts +1 -0
- package/dist/containers/page-header/index.js +1 -0
- package/dist/containers/page-header/page-header.d.ts +19 -2
- package/dist/containers/page-header/page-header.js +26 -2
- package/dist/containers/pagination/cursor-pagination.d.ts +28 -0
- package/dist/containers/pagination/cursor-pagination.js +48 -0
- package/dist/containers/pagination/index.d.ts +3 -0
- package/dist/containers/pagination/index.js +10 -0
- package/dist/containers/pagination/pagination.d.ts +52 -0
- package/dist/containers/pagination/pagination.js +216 -0
- package/dist/containers/pagination/range.d.ts +29 -0
- package/dist/containers/pagination/range.js +42 -0
- package/dist/containers/pagination/use-pagination.d.ts +18 -0
- package/dist/containers/pagination/use-pagination.js +22 -0
- package/dist/containers/responsive-list/responsive-list.d.ts +29 -3
- package/dist/containers/responsive-list/responsive-list.js +202 -82
- package/dist/containers/row-actions/index.d.ts +1 -0
- package/dist/containers/row-actions/index.js +4 -0
- package/dist/containers/row-actions/row-actions.d.ts +26 -0
- package/dist/containers/row-actions/row-actions.js +78 -0
- package/dist/containers/selectable-card/index.d.ts +1 -0
- package/dist/containers/selectable-card/index.js +6 -0
- package/dist/containers/selectable-card/selectable-card.d.ts +26 -0
- package/dist/containers/selectable-card/selectable-card.js +57 -0
- package/dist/containers/settings-layout/settings-layout.d.ts +24 -7
- package/dist/containers/settings-layout/settings-layout.js +63 -8
- package/dist/containers/shortcuts/shortcuts.js +1 -1
- package/dist/containers/table/cell-padding.d.ts +2 -0
- package/dist/containers/table/cell-padding.js +4 -0
- package/dist/containers/table/index.d.ts +1 -0
- package/dist/containers/table/index.js +8 -0
- package/dist/containers/table/sort.d.ts +14 -0
- package/dist/containers/table/sort.js +11 -0
- package/dist/containers/table/table-parts.d.ts +24 -0
- package/dist/containers/table/table-parts.js +52 -0
- package/dist/containers/table/table.d.ts +37 -3
- package/dist/containers/table/table.js +120 -19
- package/dist/containers/table-columns-menu/index.d.ts +1 -0
- package/dist/containers/table-columns-menu/index.js +6 -0
- package/dist/containers/table-columns-menu/table-columns-menu.d.ts +14 -0
- package/dist/containers/table-columns-menu/table-columns-menu.js +46 -0
- package/dist/dashboards/layout.d.ts +1 -27
- package/dist/dashboards/layout.js +8 -40
- package/dist/forms/chip-group/chip-group.d.ts +5 -0
- package/dist/forms/chip-group/chip-group.js +3 -1
- package/dist/forms/combobox/combobox.js +1 -1
- package/dist/forms/copy-field/copy-field.js +1 -1
- package/dist/forms/date-picker/date-picker.d.ts +3 -1
- package/dist/forms/date-picker/date-picker.js +4 -2
- package/dist/forms/date-picker/date-time-picker.d.ts +8 -2
- package/dist/forms/date-picker/date-time-picker.js +13 -2
- package/dist/forms/field/field.d.ts +9 -2
- package/dist/forms/field/field.js +18 -4
- package/dist/forms/fieldset/fieldset.d.ts +11 -0
- package/dist/forms/fieldset/fieldset.js +12 -0
- package/dist/forms/fieldset/index.d.ts +1 -0
- package/dist/forms/fieldset/index.js +4 -0
- package/dist/forms/form-footer/form-footer.d.ts +26 -0
- package/dist/forms/form-footer/form-footer.js +44 -0
- package/dist/forms/form-footer/index.d.ts +1 -0
- package/dist/forms/form-footer/index.js +4 -0
- package/dist/forms/form-grid/form-grid.d.ts +21 -4
- package/dist/forms/form-grid/form-grid.js +20 -3
- package/dist/forms/form-grid/index.d.ts +1 -1
- package/dist/forms/form-grid/index.js +6 -2
- package/dist/forms/form-section/form-section.d.ts +12 -0
- package/dist/forms/form-section/form-section.js +30 -0
- package/dist/forms/form-section/index.d.ts +1 -0
- package/dist/forms/form-section/index.js +4 -0
- package/dist/forms/index.d.ts +3 -0
- package/dist/forms/index.js +3 -0
- package/dist/forms/input/input.d.ts +6 -2
- package/dist/forms/input/input.js +4 -1
- package/dist/forms/internal/listbox-items.d.ts +1 -1
- package/dist/forms/internal/listbox-items.js +3 -2
- package/dist/forms/native-select/native-select.js +1 -1
- package/dist/forms/number-stepper/index.d.ts +1 -1
- package/dist/forms/number-stepper/number-stepper.d.ts +7 -0
- package/dist/forms/number-stepper/number-stepper.js +37 -6
- package/dist/forms/select/index.d.ts +1 -1
- package/dist/forms/select/select.d.ts +5 -2
- package/dist/forms/select/select.js +7 -2
- package/dist/forms/select-menu/select-menu.js +1 -1
- package/dist/forms/time-input/time-input.d.ts +4 -2
- package/dist/forms/time-input/time-input.js +3 -1
- package/dist/i18n/strings.d.ts +94 -0
- package/dist/i18n/strings.js +50 -0
- package/dist/motion/count-up.d.ts +20 -0
- package/dist/motion/count-up.js +59 -0
- package/dist/motion/cross-fade.d.ts +21 -0
- package/dist/motion/cross-fade.js +86 -0
- package/dist/motion/index.d.ts +5 -0
- package/dist/motion/index.js +14 -0
- package/dist/motion/model.d.ts +15 -0
- package/dist/motion/model.js +68 -0
- package/dist/motion/motion-styles.d.ts +1 -0
- package/dist/motion/motion-styles.js +35 -0
- package/dist/motion/reveal.d.ts +37 -0
- package/dist/motion/reveal.js +69 -0
- package/dist/motion/use-enter-phase.d.ts +11 -0
- package/dist/motion/use-enter-phase.js +40 -0
- package/dist/motion/use-highlight-row.d.ts +22 -0
- package/dist/motion/use-highlight-row.js +38 -0
- package/dist/navigation/tabs/tabs.js +1 -1
- package/dist/navigation/wizard/wizard.d.ts +4 -1
- package/dist/navigation/wizard/wizard.js +3 -0
- package/dist/overlays/alert-dialog/alert-dialog.js +8 -1
- package/dist/overlays/context-menu/context-menu.js +3 -1
- package/dist/overlays/dialog/dialog.d.ts +1 -0
- package/dist/overlays/dialog/dialog.js +11 -3
- package/dist/overlays/drawer/drawer.d.ts +18 -4
- package/dist/overlays/drawer/drawer.js +53 -4
- package/dist/overlays/drawer/index.d.ts +1 -1
- package/dist/overlays/dropdown-menu/dropdown-menu.d.ts +1 -1
- package/dist/overlays/dropdown-menu/dropdown-menu.js +5 -4
- package/dist/overlays/hover-card/hover-card.js +2 -0
- package/dist/overlays/popover/popover.js +2 -0
- package/dist/overlays/toaster/index.d.ts +1 -1
- package/dist/overlays/toaster/toast-store.d.ts +2 -0
- package/dist/overlays/toaster/toast-store.js +6 -1
- package/dist/overlays/toaster/toaster.d.ts +28 -2
- package/dist/overlays/toaster/toaster.js +86 -29
- package/dist/overlays/tooltip/tooltip.js +2 -0
- package/dist/primitives/use-presence.js +9 -0
- package/dist/shell/app-shell/app-shell.d.ts +8 -1
- package/dist/shell/app-shell/app-shell.js +50 -3
- package/dist/shell/index.d.ts +1 -0
- package/dist/shell/index.js +1 -0
- package/dist/shell/sidebar/sidebar.d.ts +17 -1
- package/dist/shell/sidebar/sidebar.js +126 -76
- package/dist/shell/topbar/topbar.d.ts +4 -2
- package/dist/shell/topbar/topbar.js +2 -0
- package/dist/showcase/operations-bento.js +2 -2
- package/dist/states/empty-state/empty-state.d.ts +10 -3
- package/dist/states/empty-state/empty-state.js +46 -5
- package/dist/states/error-state/error-state.js +1 -1
- package/dist/states/skeleton/skeleton.d.ts +16 -1
- package/dist/states/skeleton/skeleton.js +13 -5
- package/dist/utils/class-tokens.generated.js +4 -6
- package/dist/utils/focus-chain.d.ts +11 -0
- package/dist/utils/focus-chain.js +39 -0
- package/dist/utils/focus-rescue.d.ts +13 -0
- package/dist/utils/focus-rescue.js +48 -0
- package/dist/utils/list-navigation.d.ts +14 -0
- package/dist/utils/list-navigation.js +44 -0
- package/dist/utils/overlay-motion.d.ts +12 -0
- package/dist/utils/overlay-motion.js +14 -0
- package/dist/utils/use-container-width.d.ts +6 -0
- package/dist/utils/use-container-width.js +19 -0
- package/package.json +2 -2
- package/scripts/build-theme.mjs +46 -5
- package/src/ai/code-block/code-block.tsx +1 -1
- package/src/atoms/avatar/avatar.tsx +8 -2
- package/src/atoms/big-date/big-date.tsx +2 -2
- package/src/atoms/button/button.tsx +8 -3
- package/src/atoms/chip/chip.tsx +8 -3
- package/src/atoms/icon-button/icon-button.tsx +1 -1
- package/src/atoms/internal/hit-area.ts +5 -4
- package/src/atoms/progress/index.ts +8 -1
- package/src/atoms/progress/progress.tsx +30 -1
- package/src/atoms/radio-group/radio-group.tsx +1 -1
- package/src/atoms/status-pill/status-pill.tsx +59 -18
- package/src/brand/logo-forge.tsx +1 -1
- package/src/charts/candlestick-chart/candlestick-chart.tsx +2 -2
- package/src/charts/chart-grid/chart-grid.tsx +2 -2
- package/src/charts/chord-chart/chord-chart.tsx +1 -1
- package/src/charts/core/axes.tsx +2 -2
- package/src/charts/core/cartesian/annotations.tsx +2 -2
- package/src/charts/core/cartesian/marks.tsx +1 -1
- package/src/charts/core/distribution/marks.tsx +1 -1
- package/src/charts/core/distribution/xy-points.tsx +1 -1
- package/src/charts/core/export-menu.tsx +1 -1
- package/src/charts/funnel-chart/funnel-chart.tsx +1 -1
- package/src/charts/gantt-chart/gantt-chart.tsx +4 -4
- package/src/charts/gantt-chart/gantt-marks.tsx +3 -3
- package/src/charts/index.ts +2 -0
- package/src/charts/maps/geo/map-data-table.tsx +1 -1
- package/src/charts/polar-area-chart/polar-area-chart.tsx +1 -1
- package/src/charts/radar-chart/radar-chart.tsx +1 -1
- package/src/charts/stock-chart/stock-chart.tsx +1 -1
- package/src/charts/stock-chart/stock-drawing-layer.tsx +3 -3
- package/src/charts/stock-chart/stock-plot.tsx +2 -2
- package/src/containers/chat-thread/chat-thread.tsx +331 -0
- package/src/containers/chat-thread/format.ts +67 -0
- package/src/containers/chat-thread/index.ts +12 -0
- package/src/containers/cols/cols.tsx +13 -1
- package/src/containers/comment/comment.tsx +1 -1
- package/src/containers/context-rail/context-rail.tsx +229 -0
- package/src/containers/context-rail/index.ts +7 -0
- package/src/containers/dashboard/dashboard.tsx +142 -0
- package/src/containers/dashboard/index.ts +12 -0
- package/src/containers/data-grid/data-grid.demos.tsx +4 -4
- package/src/containers/data-grid/data-grid.tsx +6 -6
- package/src/containers/data-grid/filter-builder-editor.tsx +2 -2
- package/src/containers/data-grid/grid-toolbar.tsx +1 -1
- package/src/containers/data-grid/spreadsheet.demos.tsx +1 -1
- package/src/containers/detail-header/detail-header.tsx +64 -0
- package/src/containers/detail-header/index.ts +5 -0
- package/src/containers/facts/facts.tsx +1 -1
- package/src/containers/filter-bar/filter-bar.tsx +201 -0
- package/src/containers/filter-bar/index.ts +7 -0
- package/src/containers/hbars/hbars.tsx +2 -2
- package/src/containers/index.ts +9 -0
- package/src/containers/kanban/kanban.tsx +148 -39
- package/src/containers/kanban/model.ts +20 -0
- package/src/containers/kpi/kpi.tsx +1 -1
- package/src/containers/kpi-group/kpi-group.tsx +17 -2
- package/src/containers/list-detail/index.ts +5 -0
- package/src/containers/list-detail/list-detail.tsx +159 -9
- package/src/containers/page/page.tsx +61 -7
- package/src/containers/page-header/back.tsx +42 -0
- package/src/containers/page-header/index.ts +1 -0
- package/src/containers/page-header/page-header.tsx +49 -3
- package/src/containers/pagination/cursor-pagination.tsx +79 -0
- package/src/containers/pagination/index.ts +7 -0
- package/src/containers/pagination/pagination.tsx +266 -0
- package/src/containers/pagination/range.ts +68 -0
- package/src/containers/pagination/use-pagination.ts +44 -0
- package/src/containers/responsive-list/responsive-list.tsx +190 -47
- package/src/containers/row-actions/index.ts +1 -0
- package/src/containers/row-actions/row-actions.tsx +114 -0
- package/src/containers/selectable-card/index.ts +5 -0
- package/src/containers/selectable-card/selectable-card.tsx +84 -0
- package/src/containers/settings-layout/settings-layout.tsx +104 -13
- package/src/containers/shortcuts/shortcuts.tsx +1 -1
- package/src/containers/table/cell-padding.ts +2 -0
- package/src/containers/table/index.ts +6 -0
- package/src/containers/table/sort.ts +23 -0
- package/src/containers/table/table-parts.tsx +81 -0
- package/src/containers/table/table.tsx +212 -45
- package/src/containers/table-columns-menu/index.ts +5 -0
- package/src/containers/table-columns-menu/table-columns-menu.tsx +68 -0
- package/src/dashboards/layout.tsx +8 -75
- package/src/forms/chip-group/chip-group.tsx +8 -1
- package/src/forms/combobox/combobox.tsx +1 -1
- package/src/forms/copy-field/copy-field.tsx +1 -1
- package/src/forms/date-picker/date-picker.tsx +7 -2
- package/src/forms/date-picker/date-time-picker.tsx +28 -2
- package/src/forms/field/field.tsx +30 -3
- package/src/forms/fieldset/fieldset.tsx +22 -0
- package/src/forms/fieldset/index.ts +1 -0
- package/src/forms/form-footer/form-footer.tsx +74 -0
- package/src/forms/form-footer/index.ts +1 -0
- package/src/forms/form-grid/form-grid.tsx +42 -5
- package/src/forms/form-grid/index.ts +8 -1
- package/src/forms/form-section/form-section.tsx +41 -0
- package/src/forms/form-section/index.ts +1 -0
- package/src/forms/index.ts +3 -0
- package/src/forms/input/input.tsx +10 -3
- package/src/forms/internal/listbox-items.tsx +3 -4
- package/src/forms/native-select/native-select.tsx +1 -1
- package/src/forms/number-stepper/index.ts +1 -0
- package/src/forms/number-stepper/number-stepper.tsx +51 -6
- package/src/forms/select/index.ts +1 -1
- package/src/forms/select/select.tsx +14 -3
- package/src/forms/select-menu/select-menu.tsx +1 -1
- package/src/forms/time-input/time-input.tsx +6 -2
- package/src/i18n/strings.ts +94 -0
- package/src/motion/count-up.tsx +83 -0
- package/src/motion/cross-fade.tsx +139 -0
- package/src/motion/index.ts +5 -0
- package/src/motion/model.ts +86 -0
- package/src/motion/motion-styles.tsx +47 -0
- package/src/motion/reveal.tsx +115 -0
- package/src/motion/use-enter-phase.ts +50 -0
- package/src/motion/use-highlight-row.ts +63 -0
- package/src/navigation/tabs/tabs.tsx +1 -1
- package/src/navigation/wizard/wizard.tsx +6 -1
- package/src/overlays/alert-dialog/alert-dialog.tsx +5 -1
- package/src/overlays/context-menu/context-menu.tsx +3 -2
- package/src/overlays/dialog/dialog.tsx +9 -3
- package/src/overlays/drawer/drawer.tsx +68 -6
- package/src/overlays/drawer/index.ts +1 -0
- package/src/overlays/dropdown-menu/dropdown-menu.tsx +5 -4
- package/src/overlays/hover-card/hover-card.tsx +2 -0
- package/src/overlays/popover/popover.tsx +2 -0
- package/src/overlays/toaster/index.ts +2 -0
- package/src/overlays/toaster/toast-store.ts +8 -0
- package/src/overlays/toaster/toaster.tsx +127 -17
- package/src/overlays/tooltip/tooltip.tsx +2 -0
- package/src/primitives/use-presence.ts +13 -0
- package/src/shell/app-shell/app-shell.tsx +54 -2
- package/src/shell/index.ts +1 -0
- package/src/shell/sidebar/sidebar.tsx +154 -75
- package/src/shell/topbar/topbar.tsx +8 -0
- package/src/showcase/operations-bento.tsx +2 -2
- package/src/states/empty-state/empty-state.tsx +52 -9
- package/src/states/error-state/error-state.tsx +1 -1
- package/src/states/skeleton/skeleton.tsx +33 -5
- package/src/utils/class-tokens.generated.ts +4 -6
- package/src/utils/focus-chain.ts +53 -0
- package/src/utils/focus-rescue.ts +68 -0
- package/src/utils/list-navigation.ts +63 -0
- package/src/utils/overlay-motion.ts +33 -0
- package/src/utils/use-container-width.ts +24 -0
- package/styles/Theme.kt +15 -18
- package/styles/tailwind.css +29 -28
- package/styles/theme.css +29 -28
- package/styles/tokens.css +46 -0
- package/tokens/default.json +51 -29
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ReactNode } from "react";
|
|
2
|
+
import { focusChain } from "../../utils/focus-chain.js";
|
|
2
3
|
|
|
3
4
|
/** `error` is the danger toast (kept under its original name); `info` and `warning` are neutral-status additions. */
|
|
4
5
|
export type ToastTone = "default" | "success" | "error" | "info" | "warning";
|
|
@@ -26,6 +27,8 @@ export interface ToastRecord extends Omit<ToastOptions, "id"> {
|
|
|
26
27
|
state: "open" | "closed";
|
|
27
28
|
/** Bumped on every update so timers restart. */
|
|
28
29
|
revision: number;
|
|
30
|
+
/** Where focus was, nearest first, when the toast was published; focus returns there once the toast leaves. */
|
|
31
|
+
origin: readonly HTMLElement[];
|
|
29
32
|
}
|
|
30
33
|
|
|
31
34
|
const EMPTY: readonly ToastRecord[] = [];
|
|
@@ -53,6 +56,10 @@ export function getServerSnapshot(): readonly ToastRecord[] {
|
|
|
53
56
|
return EMPTY;
|
|
54
57
|
}
|
|
55
58
|
|
|
59
|
+
function currentFocusChain(): readonly HTMLElement[] {
|
|
60
|
+
return typeof document === "undefined" ? [] : focusChain(document.activeElement);
|
|
61
|
+
}
|
|
62
|
+
|
|
56
63
|
/** Adds a toast, or updates and reopens the one sharing `options.id`. Returns its id. */
|
|
57
64
|
export function publish(
|
|
58
65
|
message: ReactNode,
|
|
@@ -68,6 +75,7 @@ export function publish(
|
|
|
68
75
|
tone,
|
|
69
76
|
state: "open",
|
|
70
77
|
revision: (existing?.revision ?? 0) + 1,
|
|
78
|
+
origin: existing?.origin ?? currentFocusChain(),
|
|
71
79
|
};
|
|
72
80
|
commit(existing ? toasts.map((t) => (t.id === id ? record : t)) : [...toasts, record]);
|
|
73
81
|
return id;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
|
+
type CSSProperties,
|
|
4
5
|
type KeyboardEvent,
|
|
5
6
|
type PointerEvent,
|
|
6
7
|
useEffect,
|
|
8
|
+
useLayoutEffect,
|
|
7
9
|
useRef,
|
|
8
10
|
useState,
|
|
9
11
|
useSyncExternalStore,
|
|
@@ -13,6 +15,7 @@ import { useUiStrings } from "../../i18n/ui-strings-provider.js";
|
|
|
13
15
|
import { Portal } from "../../primitives/portal.js";
|
|
14
16
|
import type { ClassNames } from "../../utils/class-names.js";
|
|
15
17
|
import { cn } from "../../utils/cn.js";
|
|
18
|
+
import { restoreFocusFromChain } from "../../utils/focus-chain.js";
|
|
16
19
|
import { usePrefersReducedMotion } from "../../utils/reduced-motion.js";
|
|
17
20
|
import {
|
|
18
21
|
dismiss,
|
|
@@ -36,12 +39,28 @@ export type ToasterPosition =
|
|
|
36
39
|
| "bottom-center"
|
|
37
40
|
| "bottom-right";
|
|
38
41
|
|
|
42
|
+
/**
|
|
43
|
+
* One position, or one per viewport width: `base` always applies, `sm` from 640 px and `lg` from
|
|
44
|
+
* 1024 px of viewport width (a toast is anchored to the viewport, so these are media queries).
|
|
45
|
+
*/
|
|
46
|
+
export type ToasterResponsivePosition =
|
|
47
|
+
| ToasterPosition
|
|
48
|
+
| { base: ToasterPosition; sm?: ToasterPosition; lg?: ToasterPosition };
|
|
49
|
+
|
|
50
|
+
/** Distance from the viewport edges: a number is px, a string is any CSS length (`calc(env(safe-area-inset-bottom) + 4rem)`). */
|
|
51
|
+
export type ToasterOffset = number | string | { x?: number | string; y?: number | string };
|
|
52
|
+
|
|
39
53
|
export type ToasterPart = "root" | "list" | "toast" | "title" | "description" | "action";
|
|
40
54
|
|
|
41
55
|
export interface ToasterProps {
|
|
42
56
|
/** Per-part classes merged with `cn`; consumer classes win. `className` still targets the root and is merged last. */
|
|
43
57
|
classNames?: ClassNames<ToasterPart>;
|
|
44
|
-
position?:
|
|
58
|
+
position?: ToasterResponsivePosition;
|
|
59
|
+
/**
|
|
60
|
+
* Distance from the edges the region is anchored to. Defaults to 1rem on both axes; `y` is
|
|
61
|
+
* measured from the top or the bottom edge, whichever the position uses.
|
|
62
|
+
*/
|
|
63
|
+
offset?: ToasterOffset;
|
|
45
64
|
/** Default auto dismiss delay in ms; `Infinity` disables it. */
|
|
46
65
|
duration?: number;
|
|
47
66
|
/** Toasts shown at once; older ones wait until a newer one leaves. */
|
|
@@ -94,14 +113,97 @@ const EXIT_MS = 200;
|
|
|
94
113
|
const SWIPE_THRESHOLD = 60;
|
|
95
114
|
|
|
96
115
|
const POSITION: Record<ToasterPosition, string> = {
|
|
97
|
-
"top-left":
|
|
98
|
-
|
|
99
|
-
"top-
|
|
100
|
-
|
|
101
|
-
"
|
|
102
|
-
|
|
116
|
+
"top-left":
|
|
117
|
+
"top-[var(--toast-y,1rem)] bottom-auto left-[var(--toast-x,1rem)] right-auto translate-x-0 items-start",
|
|
118
|
+
"top-center":
|
|
119
|
+
"top-[var(--toast-y,1rem)] bottom-auto left-1/2 right-auto -translate-x-1/2 items-center",
|
|
120
|
+
"top-right":
|
|
121
|
+
"top-[var(--toast-y,1rem)] bottom-auto right-[var(--toast-x,1rem)] left-auto translate-x-0 items-end",
|
|
122
|
+
"bottom-left":
|
|
123
|
+
"bottom-[var(--toast-y,calc(var(--app-bottom-bar,0px)_+_1rem))] top-auto left-[var(--toast-x,1rem)] right-auto translate-x-0 items-start",
|
|
124
|
+
"bottom-center":
|
|
125
|
+
"bottom-[var(--toast-y,calc(var(--app-bottom-bar,0px)_+_1rem))] top-auto left-1/2 right-auto -translate-x-1/2 items-center",
|
|
126
|
+
"bottom-right":
|
|
127
|
+
"bottom-[var(--toast-y,calc(var(--app-bottom-bar,0px)_+_1rem))] top-auto right-[var(--toast-x,1rem)] left-auto translate-x-0 items-end",
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
const POSITION_SM: Record<ToasterPosition, string> = {
|
|
131
|
+
"top-left":
|
|
132
|
+
"min-[640px]:top-[var(--toast-y,1rem)] min-[640px]:bottom-auto min-[640px]:left-[var(--toast-x,1rem)] min-[640px]:right-auto min-[640px]:translate-x-0 min-[640px]:items-start",
|
|
133
|
+
"top-center":
|
|
134
|
+
"min-[640px]:top-[var(--toast-y,1rem)] min-[640px]:bottom-auto min-[640px]:left-1/2 min-[640px]:right-auto min-[640px]:-translate-x-1/2 min-[640px]:items-center",
|
|
135
|
+
"top-right":
|
|
136
|
+
"min-[640px]:top-[var(--toast-y,1rem)] min-[640px]:bottom-auto min-[640px]:right-[var(--toast-x,1rem)] min-[640px]:left-auto min-[640px]:translate-x-0 min-[640px]:items-end",
|
|
137
|
+
"bottom-left":
|
|
138
|
+
"min-[640px]:bottom-[var(--toast-y,calc(var(--app-bottom-bar,0px)_+_1rem))] min-[640px]:top-auto min-[640px]:left-[var(--toast-x,1rem)] min-[640px]:right-auto min-[640px]:translate-x-0 min-[640px]:items-start",
|
|
139
|
+
"bottom-center":
|
|
140
|
+
"min-[640px]:bottom-[var(--toast-y,calc(var(--app-bottom-bar,0px)_+_1rem))] min-[640px]:top-auto min-[640px]:left-1/2 min-[640px]:right-auto min-[640px]:-translate-x-1/2 min-[640px]:items-center",
|
|
141
|
+
"bottom-right":
|
|
142
|
+
"min-[640px]:bottom-[var(--toast-y,calc(var(--app-bottom-bar,0px)_+_1rem))] min-[640px]:top-auto min-[640px]:right-[var(--toast-x,1rem)] min-[640px]:left-auto min-[640px]:translate-x-0 min-[640px]:items-end",
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
const POSITION_LG: Record<ToasterPosition, string> = {
|
|
146
|
+
"top-left":
|
|
147
|
+
"min-[1024px]:top-[var(--toast-y,1rem)] min-[1024px]:bottom-auto min-[1024px]:left-[var(--toast-x,1rem)] min-[1024px]:right-auto min-[1024px]:translate-x-0 min-[1024px]:items-start",
|
|
148
|
+
"top-center":
|
|
149
|
+
"min-[1024px]:top-[var(--toast-y,1rem)] min-[1024px]:bottom-auto min-[1024px]:left-1/2 min-[1024px]:right-auto min-[1024px]:-translate-x-1/2 min-[1024px]:items-center",
|
|
150
|
+
"top-right":
|
|
151
|
+
"min-[1024px]:top-[var(--toast-y,1rem)] min-[1024px]:bottom-auto min-[1024px]:right-[var(--toast-x,1rem)] min-[1024px]:left-auto min-[1024px]:translate-x-0 min-[1024px]:items-end",
|
|
152
|
+
"bottom-left":
|
|
153
|
+
"min-[1024px]:bottom-[var(--toast-y,calc(var(--app-bottom-bar,0px)_+_1rem))] min-[1024px]:top-auto min-[1024px]:left-[var(--toast-x,1rem)] min-[1024px]:right-auto min-[1024px]:translate-x-0 min-[1024px]:items-start",
|
|
154
|
+
"bottom-center":
|
|
155
|
+
"min-[1024px]:bottom-[var(--toast-y,calc(var(--app-bottom-bar,0px)_+_1rem))] min-[1024px]:top-auto min-[1024px]:left-1/2 min-[1024px]:right-auto min-[1024px]:-translate-x-1/2 min-[1024px]:items-center",
|
|
156
|
+
"bottom-right":
|
|
157
|
+
"min-[1024px]:bottom-[var(--toast-y,calc(var(--app-bottom-bar,0px)_+_1rem))] min-[1024px]:top-auto min-[1024px]:right-[var(--toast-x,1rem)] min-[1024px]:left-auto min-[1024px]:translate-x-0 min-[1024px]:items-end",
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
const LIST_ORDER: Record<ToasterVertical, string> = {
|
|
161
|
+
top: "flex-col-reverse",
|
|
162
|
+
bottom: "flex-col",
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
const LIST_ORDER_SM: Record<ToasterVertical, string> = {
|
|
166
|
+
top: "min-[640px]:flex-col-reverse",
|
|
167
|
+
bottom: "min-[640px]:flex-col",
|
|
103
168
|
};
|
|
104
169
|
|
|
170
|
+
const LIST_ORDER_LG: Record<ToasterVertical, string> = {
|
|
171
|
+
top: "min-[1024px]:flex-col-reverse",
|
|
172
|
+
bottom: "min-[1024px]:flex-col",
|
|
173
|
+
};
|
|
174
|
+
type ToasterVertical = "top" | "bottom";
|
|
175
|
+
|
|
176
|
+
const verticalOf = (position: ToasterPosition): ToasterVertical =>
|
|
177
|
+
position.startsWith("top") ? "top" : "bottom";
|
|
178
|
+
|
|
179
|
+
function sideValue(value: number | string | undefined): string | undefined {
|
|
180
|
+
return typeof value === "number" ? `${value}px` : value;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/** Region classes, list direction and offset variables for a position and an offset. */
|
|
184
|
+
export function toasterPlacement(
|
|
185
|
+
position: ToasterResponsivePosition,
|
|
186
|
+
offset?: ToasterOffset,
|
|
187
|
+
): { region: string; list: string; style: CSSProperties } {
|
|
188
|
+
const base = typeof position === "string" ? position : position.base;
|
|
189
|
+
const sm = typeof position === "string" ? undefined : position.sm;
|
|
190
|
+
const lg = typeof position === "string" ? undefined : position.lg;
|
|
191
|
+
const x = sideValue(typeof offset === "object" ? offset.x : offset);
|
|
192
|
+
const y = sideValue(typeof offset === "object" ? offset.y : offset);
|
|
193
|
+
return {
|
|
194
|
+
region: cn(POSITION[base], sm && POSITION_SM[sm], lg && POSITION_LG[lg]),
|
|
195
|
+
list: cn(
|
|
196
|
+
LIST_ORDER[verticalOf(base)],
|
|
197
|
+
sm && LIST_ORDER_SM[verticalOf(sm)],
|
|
198
|
+
lg && LIST_ORDER_LG[verticalOf(lg)],
|
|
199
|
+
),
|
|
200
|
+
style: {
|
|
201
|
+
...(x !== undefined ? { "--toast-x": x } : {}),
|
|
202
|
+
...(y !== undefined ? { "--toast-y": y } : {}),
|
|
203
|
+
} as CSSProperties,
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
|
|
105
207
|
function documentDir(): "ltr" | "rtl" | undefined {
|
|
106
208
|
if (typeof document === "undefined") return undefined;
|
|
107
209
|
const value = document.documentElement.getAttribute("dir");
|
|
@@ -154,11 +256,22 @@ function ToastItem({ record, duration, reducedMotion, classNames }: ToastItemPro
|
|
|
154
256
|
const [entered, setEntered] = useState(false);
|
|
155
257
|
const [dragX, setDragX] = useState(0);
|
|
156
258
|
const drag = useRef<{ x: number; pointerId: number } | null>(null);
|
|
259
|
+
const rootRef = useRef<HTMLDivElement>(null);
|
|
157
260
|
const hidden = useDocumentHidden();
|
|
158
261
|
const effectiveDuration = record.duration ?? duration;
|
|
159
262
|
|
|
160
263
|
useDismissTimer(record, effectiveDuration, hovered || focused || hidden);
|
|
161
264
|
|
|
265
|
+
const originRef = useRef(record.origin);
|
|
266
|
+
originRef.current = record.origin;
|
|
267
|
+
useLayoutEffect(
|
|
268
|
+
() => () => {
|
|
269
|
+
const current = document.activeElement;
|
|
270
|
+
if (current && rootRef.current?.contains(current)) restoreFocusFromChain(originRef.current);
|
|
271
|
+
},
|
|
272
|
+
[],
|
|
273
|
+
);
|
|
274
|
+
|
|
162
275
|
useEffect(() => {
|
|
163
276
|
const frame = requestAnimationFrame(() => setEntered(true));
|
|
164
277
|
return () => cancelAnimationFrame(frame);
|
|
@@ -205,6 +318,7 @@ function ToastItem({ record, duration, reducedMotion, classNames }: ToastItemPro
|
|
|
205
318
|
return (
|
|
206
319
|
// biome-ignore lint/a11y/noStaticElementInteractions: role is status/alert; handlers only pause the timer, swipe and Escape.
|
|
207
320
|
<div
|
|
321
|
+
ref={rootRef}
|
|
208
322
|
role={isError ? "alert" : "status"}
|
|
209
323
|
aria-live={isError ? "assertive" : "polite"}
|
|
210
324
|
aria-atomic="true"
|
|
@@ -252,7 +366,7 @@ function ToastItem({ record, duration, reducedMotion, classNames }: ToastItemPro
|
|
|
252
366
|
<button
|
|
253
367
|
type="button"
|
|
254
368
|
className={cn(
|
|
255
|
-
"h-8 shrink-0 rounded-button px-3 font-bold focus-ring",
|
|
369
|
+
"h-8 shrink-0 rounded-button px-3 font-bold focus-visible:focus-ring",
|
|
256
370
|
toneActionClasses[tone],
|
|
257
371
|
classNames?.action,
|
|
258
372
|
)}
|
|
@@ -274,6 +388,7 @@ function ToastItem({ record, duration, reducedMotion, classNames }: ToastItemPro
|
|
|
274
388
|
*/
|
|
275
389
|
export function Toaster({
|
|
276
390
|
position = "bottom-center",
|
|
391
|
+
offset,
|
|
277
392
|
duration = 6000,
|
|
278
393
|
visibleToasts = 2,
|
|
279
394
|
className,
|
|
@@ -287,7 +402,7 @@ export function Toaster({
|
|
|
287
402
|
const records = useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
|
|
288
403
|
const regionRef = useRef<HTMLElement>(null);
|
|
289
404
|
const shown = selectVisible(records, visibleToasts);
|
|
290
|
-
const
|
|
405
|
+
const placement = toasterPlacement(position, offset);
|
|
291
406
|
|
|
292
407
|
useEffect(() => {
|
|
293
408
|
const onKey = (event: globalThis.KeyboardEvent) => {
|
|
@@ -306,20 +421,15 @@ export function Toaster({
|
|
|
306
421
|
data-ui-layer-branch=""
|
|
307
422
|
aria-label={label ?? strings.notifications}
|
|
308
423
|
tabIndex={-1}
|
|
424
|
+
style={placement.style}
|
|
309
425
|
className={cn(
|
|
310
426
|
"pointer-events-none fixed z-[1000] flex outline-none",
|
|
311
|
-
|
|
427
|
+
placement.region,
|
|
312
428
|
classNames?.root,
|
|
313
429
|
className,
|
|
314
430
|
)}
|
|
315
431
|
>
|
|
316
|
-
<div
|
|
317
|
-
className={cn(
|
|
318
|
-
"m-0 flex list-none gap-2 p-0",
|
|
319
|
-
fromTop ? "flex-col-reverse" : "flex-col",
|
|
320
|
-
classNames?.list,
|
|
321
|
-
)}
|
|
322
|
-
>
|
|
432
|
+
<div className={cn("m-0 flex list-none gap-2 p-0", placement.list, classNames?.list)}>
|
|
323
433
|
{shown.map((record) => (
|
|
324
434
|
<ToastItem
|
|
325
435
|
key={record.id}
|
|
@@ -16,6 +16,7 @@ import type { Align, Side } from "../../primitives/popper/geometry.js";
|
|
|
16
16
|
import type { ClassNames } from "../../utils/class-names.js";
|
|
17
17
|
import { cn } from "../../utils/cn.js";
|
|
18
18
|
import { type Material, materialClass } from "../../utils/material.js";
|
|
19
|
+
import { POPPER_MOTION } from "../../utils/overlay-motion.js";
|
|
19
20
|
import { Slot } from "../../utils/slot.js";
|
|
20
21
|
import { useControllableState } from "../../utils/use-controllable-state.js";
|
|
21
22
|
import { opensOnFocus, opensOnHover } from "./model.js";
|
|
@@ -152,6 +153,7 @@ export function Tooltip({
|
|
|
152
153
|
onMouseLeave={() => schedule(false, closeDelay)}
|
|
153
154
|
className={cn(
|
|
154
155
|
"z-85 flex w-max max-w-[min(16rem,var(--ui-popper-available-width))] items-center gap-2 rounded-popover surface-overlay px-2.5 py-1.5 text-meta text-ink shadow-overlay",
|
|
156
|
+
POPPER_MOTION,
|
|
155
157
|
materialClass(material, "surface-solid"),
|
|
156
158
|
classNames?.content,
|
|
157
159
|
className,
|
|
@@ -66,6 +66,16 @@ export function exitDuration(node: Element): number {
|
|
|
66
66
|
return Math.max(animated, transitioned);
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
+
/** Whether an exit-relevant animation or transition on the node itself is still running. */
|
|
70
|
+
function stillRunning(node: Element): boolean {
|
|
71
|
+
if (typeof node.getAnimations !== "function") return false;
|
|
72
|
+
return node.getAnimations().some((animation) => {
|
|
73
|
+
if (animation.playState !== "running") return false;
|
|
74
|
+
const property = (animation as Animation & { transitionProperty?: string }).transitionProperty;
|
|
75
|
+
return property === undefined || EXIT_PROPERTIES.has(property);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
69
79
|
function prefersReducedMotion(): boolean {
|
|
70
80
|
return typeof window.matchMedia === "function"
|
|
71
81
|
? window.matchMedia("(prefers-reduced-motion: reduce)").matches
|
|
@@ -95,6 +105,9 @@ export function usePresence(present: boolean, ref: RefObject<HTMLElement | null>
|
|
|
95
105
|
if (event.target !== node) return;
|
|
96
106
|
const property = (event as TransitionEvent).propertyName;
|
|
97
107
|
if (event.type === "transitionend" && !EXIT_PROPERTIES.has(property)) return;
|
|
108
|
+
// A built-in exit transition and a consumer's own (longer) exit animation can run together:
|
|
109
|
+
// wait for the last one, not the first to end.
|
|
110
|
+
if (stillRunning(node)) return;
|
|
98
111
|
finish();
|
|
99
112
|
};
|
|
100
113
|
node.addEventListener("animationend", onEnd);
|
|
@@ -105,6 +105,23 @@ export function useAppShell(): AppShellState | null {
|
|
|
105
105
|
|
|
106
106
|
export interface AppShellProps extends ComponentPropsWithRef<"div"> {
|
|
107
107
|
children: ReactNode;
|
|
108
|
+
/**
|
|
109
|
+
* Phone navigation, usually a `BottomNav`. Rendered after the children and fixed to the bottom
|
|
110
|
+
* edge; while the shell is compact it reserves the bar's height and safe-area inset at the
|
|
111
|
+
* bottom and publishes it as the `--app-bottom-bar` CSS variable (on the shell and on the
|
|
112
|
+
* document root), so sticky bars and the `Toaster` stay above it.
|
|
113
|
+
*/
|
|
114
|
+
bottomBar?: ReactNode;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const BOTTOM_BAR_HEIGHT = "calc(3.5rem + env(safe-area-inset-bottom))";
|
|
118
|
+
|
|
119
|
+
/** Publishes `--app-bottom-bar` on the shell and the document root while the shell is compact. */
|
|
120
|
+
function reserveBottomBar(element: HTMLElement, compact: boolean) {
|
|
121
|
+
for (const target of [element, document.documentElement]) {
|
|
122
|
+
if (compact) target.style.setProperty("--app-bottom-bar", BOTTOM_BAR_HEIGHT);
|
|
123
|
+
else target.style.removeProperty("--app-bottom-bar");
|
|
124
|
+
}
|
|
108
125
|
}
|
|
109
126
|
|
|
110
127
|
/**
|
|
@@ -117,17 +134,52 @@ export interface AppShellProps extends ComponentPropsWithRef<"div"> {
|
|
|
117
134
|
* the measure arrives, so nothing above a still-dehydrated Suspense boundary re-renders during
|
|
118
135
|
* hydration (a provider value that changed there made Next.js client-render those boundaries).
|
|
119
136
|
*/
|
|
120
|
-
export function AppShell({
|
|
137
|
+
export function AppShell({
|
|
138
|
+
children,
|
|
139
|
+
bottomBar,
|
|
140
|
+
className,
|
|
141
|
+
ref: forwardedRef,
|
|
142
|
+
...props
|
|
143
|
+
}: AppShellProps) {
|
|
121
144
|
const ref = useRef<HTMLDivElement>(null);
|
|
122
145
|
const [store] = useState(createAppShellStore);
|
|
123
146
|
const composedRef = useComposedRefs(ref, forwardedRef);
|
|
147
|
+
const hasBottomBar = bottomBar != null && bottomBar !== false;
|
|
124
148
|
|
|
125
149
|
useEffect(() => (ref.current ? store.observe(ref.current) : undefined), [store]);
|
|
126
150
|
|
|
151
|
+
useEffect(() => {
|
|
152
|
+
const element = ref.current;
|
|
153
|
+
if (!hasBottomBar || !element) return;
|
|
154
|
+
const sync = () => reserveBottomBar(element, store.getSnapshot());
|
|
155
|
+
sync();
|
|
156
|
+
const unsubscribe = store.subscribe(sync);
|
|
157
|
+
return () => {
|
|
158
|
+
unsubscribe();
|
|
159
|
+
reserveBottomBar(element, false);
|
|
160
|
+
};
|
|
161
|
+
}, [store, hasBottomBar]);
|
|
162
|
+
|
|
127
163
|
return (
|
|
128
164
|
<AppShellContext.Provider value={store}>
|
|
129
|
-
<div
|
|
165
|
+
<div
|
|
166
|
+
ref={composedRef}
|
|
167
|
+
{...props}
|
|
168
|
+
className={cn(
|
|
169
|
+
"@container/app flex min-w-0",
|
|
170
|
+
hasBottomBar && "pb-(--app-bottom-bar,0px)",
|
|
171
|
+
className,
|
|
172
|
+
)}
|
|
173
|
+
>
|
|
130
174
|
{children}
|
|
175
|
+
{hasBottomBar ? (
|
|
176
|
+
<div
|
|
177
|
+
data-app-bottom-bar=""
|
|
178
|
+
className="fixed inset-x-0 bottom-0 z-40 @min-[900px]/app:hidden"
|
|
179
|
+
>
|
|
180
|
+
{bottomBar}
|
|
181
|
+
</div>
|
|
182
|
+
) : null}
|
|
131
183
|
</div>
|
|
132
184
|
</AppShellContext.Provider>
|
|
133
185
|
);
|
package/src/shell/index.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import { type CSSProperties, type ReactNode, useEffect, useRef } from "react";
|
|
3
|
+
import { type CSSProperties, type ReactNode, useEffect, useId, useRef } from "react";
|
|
4
|
+
import { ChevronDown } from "../../icons/index.js";
|
|
4
5
|
import type { ClassNames } from "../../utils/class-names.js";
|
|
5
6
|
import { cn } from "../../utils/cn.js";
|
|
6
7
|
import { type Material, materialClass } from "../../utils/material.js";
|
|
8
|
+
import { useControllableState } from "../../utils/use-controllable-state.js";
|
|
7
9
|
import { useAppShell, useCompactContainer } from "../app-shell/app-shell.js";
|
|
8
10
|
|
|
9
11
|
export interface SidebarLinkProps {
|
|
@@ -35,12 +37,28 @@ export interface SidebarGroup {
|
|
|
35
37
|
id: string;
|
|
36
38
|
label: string;
|
|
37
39
|
items: SidebarItem[];
|
|
40
|
+
/**
|
|
41
|
+
* Turns the group label into a button that shows or hides the items (`aria-expanded`). Ignored
|
|
42
|
+
* in rail mode, where every item stays visible.
|
|
43
|
+
*/
|
|
44
|
+
collapsible?: boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Starts collapsed when `collapsible`. A group that contains the active item starts open
|
|
47
|
+
* regardless, and an uncontrolled group opens when one of its items becomes active later, so
|
|
48
|
+
* the current page is never hidden.
|
|
49
|
+
*/
|
|
50
|
+
defaultCollapsed?: boolean;
|
|
51
|
+
/** Controlled collapsed state of a `collapsible` group. */
|
|
52
|
+
collapsed?: boolean;
|
|
53
|
+
onCollapsedChange?: (collapsed: boolean) => void;
|
|
38
54
|
}
|
|
39
55
|
|
|
40
56
|
export type SidebarPart =
|
|
41
57
|
| "root"
|
|
42
58
|
| "group"
|
|
43
59
|
| "groupLabel"
|
|
60
|
+
| "groupToggle"
|
|
61
|
+
| "groupItems"
|
|
44
62
|
| "item"
|
|
45
63
|
| "link"
|
|
46
64
|
| "label"
|
|
@@ -81,6 +99,135 @@ const defaultRenderLink: SidebarRenderLink = ({ children, ...props }) => (
|
|
|
81
99
|
<a {...props}>{children}</a>
|
|
82
100
|
);
|
|
83
101
|
|
|
102
|
+
interface SidebarGroupSectionProps {
|
|
103
|
+
group: SidebarGroup;
|
|
104
|
+
rail: boolean;
|
|
105
|
+
renderLink: SidebarRenderLink;
|
|
106
|
+
classNames: ClassNames<SidebarPart> | undefined;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** Whether an uncontrolled group must open: one of its items just became the active page. */
|
|
110
|
+
export function opensOnActivation(
|
|
111
|
+
wasActive: boolean,
|
|
112
|
+
isActive: boolean,
|
|
113
|
+
controlled: boolean,
|
|
114
|
+
): boolean {
|
|
115
|
+
return isActive && !wasActive && !controlled;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function SidebarGroupSection({ group, rail, renderLink, classNames }: SidebarGroupSectionProps) {
|
|
119
|
+
const itemsId = useId();
|
|
120
|
+
const collapsible = group.collapsible === true && !rail;
|
|
121
|
+
const holdsActive = group.items.some((item) => item.active);
|
|
122
|
+
const [collapsedState, setCollapsed] = useControllableState<boolean>({
|
|
123
|
+
prop: group.collapsed,
|
|
124
|
+
defaultProp: (group.defaultCollapsed ?? false) && !holdsActive,
|
|
125
|
+
onChange: group.onCollapsedChange,
|
|
126
|
+
});
|
|
127
|
+
const collapsed = collapsible && collapsedState;
|
|
128
|
+
const wasActive = useRef(holdsActive);
|
|
129
|
+
const uncontrolled = group.collapsed === undefined;
|
|
130
|
+
useEffect(() => {
|
|
131
|
+
if (opensOnActivation(wasActive.current, holdsActive, !uncontrolled)) setCollapsed(false);
|
|
132
|
+
wasActive.current = holdsActive;
|
|
133
|
+
}, [holdsActive, uncontrolled, setCollapsed]);
|
|
134
|
+
return (
|
|
135
|
+
<nav aria-label={group.label} className={cn("flex flex-col gap-px", classNames?.group)}>
|
|
136
|
+
{collapsible ? (
|
|
137
|
+
<button
|
|
138
|
+
type="button"
|
|
139
|
+
aria-expanded={!collapsed}
|
|
140
|
+
aria-controls={itemsId}
|
|
141
|
+
onClick={() => setCollapsed(!collapsed)}
|
|
142
|
+
className={cn(
|
|
143
|
+
"flex w-full items-center gap-1 rounded-control px-2.5 pb-1.5 text-left text-overline text-ink-3 hover:text-ink focus-visible:focus-ring",
|
|
144
|
+
classNames?.groupLabel,
|
|
145
|
+
classNames?.groupToggle,
|
|
146
|
+
)}
|
|
147
|
+
>
|
|
148
|
+
<span className="min-w-0 flex-1 truncate">{group.label}</span>
|
|
149
|
+
<ChevronDown
|
|
150
|
+
aria-hidden="true"
|
|
151
|
+
className={cn("size-3.5 shrink-0 transition-transform", collapsed && "-rotate-90")}
|
|
152
|
+
/>
|
|
153
|
+
</button>
|
|
154
|
+
) : (
|
|
155
|
+
<div
|
|
156
|
+
className={cn(
|
|
157
|
+
"px-2.5 pb-1.5 text-overline text-ink-3",
|
|
158
|
+
rail && "sr-only",
|
|
159
|
+
classNames?.groupLabel,
|
|
160
|
+
)}
|
|
161
|
+
>
|
|
162
|
+
{group.label}
|
|
163
|
+
</div>
|
|
164
|
+
)}
|
|
165
|
+
<div
|
|
166
|
+
id={itemsId}
|
|
167
|
+
hidden={collapsed}
|
|
168
|
+
className={cn("flex flex-col gap-px", classNames?.groupItems)}
|
|
169
|
+
>
|
|
170
|
+
{group.items.map((item) => {
|
|
171
|
+
const badgeTone =
|
|
172
|
+
item.badgeTone === "danger" ? "bg-danger-soft text-danger" : "bg-surface-2 text-ink-2";
|
|
173
|
+
return (
|
|
174
|
+
<div key={item.id} className={classNames?.item}>
|
|
175
|
+
{renderLink({
|
|
176
|
+
href: item.href,
|
|
177
|
+
"aria-current": item.active ? "page" : undefined,
|
|
178
|
+
title: rail ? item.label : undefined,
|
|
179
|
+
className: cn(
|
|
180
|
+
"flex min-h-(--touch-target) items-center gap-2.5 rounded-control px-2.5 py-2 text-control text-ink-2 hover:bg-surface-2 hover:text-ink [&_svg]:size-4.25 [&_svg]:shrink-0",
|
|
181
|
+
rail && "relative justify-center",
|
|
182
|
+
item.active && "bg-accent-soft font-bold text-accent-ink",
|
|
183
|
+
classNames?.link,
|
|
184
|
+
),
|
|
185
|
+
children: (
|
|
186
|
+
<>
|
|
187
|
+
{item.icon}
|
|
188
|
+
<span className={cn("min-w-0 truncate", rail && "sr-only", classNames?.label)}>
|
|
189
|
+
{item.label}
|
|
190
|
+
</span>
|
|
191
|
+
{item.badge !== undefined && rail ? (
|
|
192
|
+
<>
|
|
193
|
+
<span
|
|
194
|
+
aria-hidden="true"
|
|
195
|
+
className={cn(
|
|
196
|
+
"absolute top-1 right-1 size-2 rounded-full ring-2 ring-surface",
|
|
197
|
+
item.badgeTone === "danger" ? "bg-danger" : "bg-accent",
|
|
198
|
+
classNames?.badge,
|
|
199
|
+
)}
|
|
200
|
+
/>
|
|
201
|
+
<span className="sr-only">
|
|
202
|
+
{item.badge}
|
|
203
|
+
{item.badgeLabel ? ` ${item.badgeLabel}` : null}
|
|
204
|
+
</span>
|
|
205
|
+
</>
|
|
206
|
+
) : item.badge !== undefined ? (
|
|
207
|
+
<span
|
|
208
|
+
className={cn(
|
|
209
|
+
"ml-auto shrink-0 rounded-chip px-1.5 py-0.75 text-count",
|
|
210
|
+
badgeTone,
|
|
211
|
+
classNames?.badge,
|
|
212
|
+
)}
|
|
213
|
+
>
|
|
214
|
+
{item.badge}
|
|
215
|
+
{item.badgeLabel ? (
|
|
216
|
+
<span className="sr-only"> {item.badgeLabel}</span>
|
|
217
|
+
) : null}
|
|
218
|
+
</span>
|
|
219
|
+
) : null}
|
|
220
|
+
</>
|
|
221
|
+
),
|
|
222
|
+
})}
|
|
223
|
+
</div>
|
|
224
|
+
);
|
|
225
|
+
})}
|
|
226
|
+
</div>
|
|
227
|
+
</nav>
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
|
|
84
231
|
/**
|
|
85
232
|
* Main navigation. Always visible when its app container is wide; an off-canvas drawer under
|
|
86
233
|
* 900 px of container width, `inert` while closed so it is not reachable by keyboard.
|
|
@@ -153,81 +300,13 @@ export function Sidebar({
|
|
|
153
300
|
>
|
|
154
301
|
{header}
|
|
155
302
|
{groups.map((group) => (
|
|
156
|
-
<
|
|
303
|
+
<SidebarGroupSection
|
|
157
304
|
key={group.id}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
"px-2.5 pb-1.5 text-overline text-ink-3",
|
|
164
|
-
rail && "sr-only",
|
|
165
|
-
classNames?.groupLabel,
|
|
166
|
-
)}
|
|
167
|
-
>
|
|
168
|
-
{group.label}
|
|
169
|
-
</div>
|
|
170
|
-
{group.items.map((item) => {
|
|
171
|
-
const badgeTone =
|
|
172
|
-
item.badgeTone === "danger"
|
|
173
|
-
? "bg-danger-soft text-danger"
|
|
174
|
-
: "bg-surface-2 text-ink-2";
|
|
175
|
-
return (
|
|
176
|
-
<div key={item.id} className={classNames?.item}>
|
|
177
|
-
{renderLink({
|
|
178
|
-
href: item.href,
|
|
179
|
-
"aria-current": item.active ? "page" : undefined,
|
|
180
|
-
title: rail ? item.label : undefined,
|
|
181
|
-
className: cn(
|
|
182
|
-
"flex items-center gap-2.5 rounded-control px-2.5 py-2 text-control text-ink-2 hover:bg-surface-2 hover:text-ink [&_svg]:size-4.25 [&_svg]:shrink-0",
|
|
183
|
-
rail && "relative justify-center in-data-[density=touch]:min-h-11",
|
|
184
|
-
item.active && "bg-accent-soft font-bold text-accent-ink",
|
|
185
|
-
classNames?.link,
|
|
186
|
-
),
|
|
187
|
-
children: (
|
|
188
|
-
<>
|
|
189
|
-
{item.icon}
|
|
190
|
-
<span
|
|
191
|
-
className={cn("min-w-0 truncate", rail && "sr-only", classNames?.label)}
|
|
192
|
-
>
|
|
193
|
-
{item.label}
|
|
194
|
-
</span>
|
|
195
|
-
{item.badge !== undefined && rail ? (
|
|
196
|
-
<>
|
|
197
|
-
<span
|
|
198
|
-
aria-hidden="true"
|
|
199
|
-
className={cn(
|
|
200
|
-
"absolute top-1 right-1 size-2 rounded-full ring-2 ring-surface",
|
|
201
|
-
item.badgeTone === "danger" ? "bg-danger" : "bg-accent",
|
|
202
|
-
classNames?.badge,
|
|
203
|
-
)}
|
|
204
|
-
/>
|
|
205
|
-
<span className="sr-only">
|
|
206
|
-
{item.badge}
|
|
207
|
-
{item.badgeLabel ? ` ${item.badgeLabel}` : null}
|
|
208
|
-
</span>
|
|
209
|
-
</>
|
|
210
|
-
) : item.badge !== undefined ? (
|
|
211
|
-
<span
|
|
212
|
-
className={cn(
|
|
213
|
-
"ml-auto shrink-0 rounded-chip px-1.5 py-0.75 text-count",
|
|
214
|
-
badgeTone,
|
|
215
|
-
classNames?.badge,
|
|
216
|
-
)}
|
|
217
|
-
>
|
|
218
|
-
{item.badge}
|
|
219
|
-
{item.badgeLabel ? (
|
|
220
|
-
<span className="sr-only"> {item.badgeLabel}</span>
|
|
221
|
-
) : null}
|
|
222
|
-
</span>
|
|
223
|
-
) : null}
|
|
224
|
-
</>
|
|
225
|
-
),
|
|
226
|
-
})}
|
|
227
|
-
</div>
|
|
228
|
-
);
|
|
229
|
-
})}
|
|
230
|
-
</nav>
|
|
305
|
+
group={group}
|
|
306
|
+
rail={rail}
|
|
307
|
+
renderLink={renderLink}
|
|
308
|
+
classNames={classNames}
|
|
309
|
+
/>
|
|
231
310
|
))}
|
|
232
311
|
{footer ? <div className={cn("mt-auto", classNames?.footer)}>{footer}</div> : null}
|
|
233
312
|
</aside>
|