@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
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import type { ClassNames } from "../../utils/class-names.js";
|
|
3
|
+
import { type ChatTimestamp } from "./format.js";
|
|
4
|
+
export type ChatAuthorKind = "customer" | "bot" | "staff";
|
|
5
|
+
export type ChatDeliveryStatus = "sending" | "sent" | "delivered" | "read" | "failed";
|
|
6
|
+
export interface ChatThreadMessage {
|
|
7
|
+
id: string;
|
|
8
|
+
kind?: "message";
|
|
9
|
+
/** Who wrote it: the customer (incoming), the bot or a staff member (outgoing). */
|
|
10
|
+
author: ChatAuthorKind;
|
|
11
|
+
/** Name shown above the bubble. Defaults to the localized author kind. */
|
|
12
|
+
name?: string;
|
|
13
|
+
at: ChatTimestamp;
|
|
14
|
+
content: ReactNode;
|
|
15
|
+
/** Delivery state, shown under outgoing messages only. Omit it to show none. */
|
|
16
|
+
status?: ChatDeliveryStatus;
|
|
17
|
+
}
|
|
18
|
+
/** A line in the middle of the thread that is not a message, e.g. "The customer asked for a person". */
|
|
19
|
+
export interface ChatThreadNote {
|
|
20
|
+
id: string;
|
|
21
|
+
kind: "note";
|
|
22
|
+
at: ChatTimestamp;
|
|
23
|
+
content: ReactNode;
|
|
24
|
+
}
|
|
25
|
+
export type ChatThreadItem = ChatThreadMessage | ChatThreadNote;
|
|
26
|
+
export interface ChatThreadLabels {
|
|
27
|
+
conversation: string;
|
|
28
|
+
today: string;
|
|
29
|
+
yesterday: string;
|
|
30
|
+
customer: string;
|
|
31
|
+
bot: string;
|
|
32
|
+
staff: string;
|
|
33
|
+
sending: string;
|
|
34
|
+
sent: string;
|
|
35
|
+
delivered: string;
|
|
36
|
+
read: string;
|
|
37
|
+
notSent: string;
|
|
38
|
+
}
|
|
39
|
+
/** Ready-made labels; the thread defaults to `en`. Pass `chatThreadLabels.es` for Spanish. */
|
|
40
|
+
export declare const chatThreadLabels: {
|
|
41
|
+
readonly en: {
|
|
42
|
+
readonly conversation: "Conversation";
|
|
43
|
+
readonly today: "Today";
|
|
44
|
+
readonly yesterday: "Yesterday";
|
|
45
|
+
readonly customer: "Customer";
|
|
46
|
+
readonly bot: "Bot";
|
|
47
|
+
readonly staff: "Staff";
|
|
48
|
+
readonly sending: "Sending";
|
|
49
|
+
readonly sent: "Sent";
|
|
50
|
+
readonly delivered: "Delivered";
|
|
51
|
+
readonly read: "Read";
|
|
52
|
+
readonly notSent: "Not sent";
|
|
53
|
+
};
|
|
54
|
+
readonly es: {
|
|
55
|
+
readonly conversation: "Conversación";
|
|
56
|
+
readonly today: "Hoy";
|
|
57
|
+
readonly yesterday: "Ayer";
|
|
58
|
+
readonly customer: "Cliente";
|
|
59
|
+
readonly bot: "Bot";
|
|
60
|
+
readonly staff: "Equipo";
|
|
61
|
+
readonly sending: "Enviando";
|
|
62
|
+
readonly sent: "Enviado";
|
|
63
|
+
readonly delivered: "Entregado";
|
|
64
|
+
readonly read: "Leído";
|
|
65
|
+
readonly notSent: "No se envió";
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
export type ChatThreadPart = "root" | "log" | "day" | "message" | "bubble" | "author" | "meta" | "note" | "composer";
|
|
69
|
+
export interface ChatThreadProps {
|
|
70
|
+
items: readonly ChatThreadItem[];
|
|
71
|
+
/** Slot under the thread, usually a `Textarea` or `PromptInput` with a send button. */
|
|
72
|
+
composer?: ReactNode;
|
|
73
|
+
/** Texts of the thread (name, day labels, authors, delivery states). English by default; see `chatThreadLabels`. */
|
|
74
|
+
labels?: Partial<ChatThreadLabels>;
|
|
75
|
+
/** Accessible name of the thread. Defaults to `labels.conversation`. */
|
|
76
|
+
label?: string;
|
|
77
|
+
/** Called by the retry button of a `failed` message. Without it the button is not shown. */
|
|
78
|
+
onRetry?: (id: string) => void;
|
|
79
|
+
/** Shown instead of the log while there are no items. */
|
|
80
|
+
empty?: ReactNode;
|
|
81
|
+
/** `Intl` locale for times and day labels. */
|
|
82
|
+
locale?: string;
|
|
83
|
+
/** Time zone for times and day breaks; the local one when omitted. */
|
|
84
|
+
timeZone?: string;
|
|
85
|
+
/** The instant "Today" refers to. Pass a fixed value for stable output. Defaults to the current time. */
|
|
86
|
+
now?: ChatTimestamp;
|
|
87
|
+
className?: string;
|
|
88
|
+
/** Per-part classes merged with `cn`; consumer classes win. `className` still targets the root and is merged last. */
|
|
89
|
+
classNames?: ClassNames<ChatThreadPart>;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Business conversation between a customer, a bot and staff: incoming messages on the start side,
|
|
93
|
+
* outgoing ones (bot, staff) on the end side with distinct tones, day separators, optional delivery
|
|
94
|
+
* status, system notes and a composer slot. It is a live `log` that stays at the bottom while new
|
|
95
|
+
* items arrive and you are already there. Colors come from the kit tokens in both schemes. The
|
|
96
|
+
* `ai/` chat parts model user and assistant only; this one models the three authors of a shop chat.
|
|
97
|
+
*/
|
|
98
|
+
export declare function ChatThread({ items, composer, labels: labelsProp, label, onRetry, empty, locale, timeZone, now, className, classNames, }: ChatThreadProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect, useLayoutEffect, useRef } from "react";
|
|
4
|
+
import { Button } from "../../atoms/button/button.js";
|
|
5
|
+
import { useUiStrings } from "../../i18n/index.js";
|
|
6
|
+
import { Check, CheckCheck } from "../../icons/index.js";
|
|
7
|
+
import { cn } from "../../utils/cn.js";
|
|
8
|
+
import { dayKey, formatDay, formatTime, withDayBreaks } from "./format.js";
|
|
9
|
+
const chatThreadLabels = {
|
|
10
|
+
en: {
|
|
11
|
+
conversation: "Conversation",
|
|
12
|
+
today: "Today",
|
|
13
|
+
yesterday: "Yesterday",
|
|
14
|
+
customer: "Customer",
|
|
15
|
+
bot: "Bot",
|
|
16
|
+
staff: "Staff",
|
|
17
|
+
sending: "Sending",
|
|
18
|
+
sent: "Sent",
|
|
19
|
+
delivered: "Delivered",
|
|
20
|
+
read: "Read",
|
|
21
|
+
notSent: "Not sent"
|
|
22
|
+
},
|
|
23
|
+
es: {
|
|
24
|
+
conversation: "Conversaci\xF3n",
|
|
25
|
+
today: "Hoy",
|
|
26
|
+
yesterday: "Ayer",
|
|
27
|
+
customer: "Cliente",
|
|
28
|
+
bot: "Bot",
|
|
29
|
+
staff: "Equipo",
|
|
30
|
+
sending: "Enviando",
|
|
31
|
+
sent: "Enviado",
|
|
32
|
+
delivered: "Entregado",
|
|
33
|
+
read: "Le\xEDdo",
|
|
34
|
+
notSent: "No se envi\xF3"
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
const useIsomorphicLayoutEffect = typeof window === "undefined" ? useEffect : useLayoutEffect;
|
|
38
|
+
const bubbleTone = {
|
|
39
|
+
customer: "bg-surface-2 text-ink",
|
|
40
|
+
bot: "border border-accent-line bg-accent-soft text-accent-ink",
|
|
41
|
+
staff: "bg-accent text-on-accent"
|
|
42
|
+
};
|
|
43
|
+
function Status({ status, labels }) {
|
|
44
|
+
const label = {
|
|
45
|
+
sending: labels.sending,
|
|
46
|
+
sent: labels.sent,
|
|
47
|
+
delivered: labels.delivered,
|
|
48
|
+
read: labels.read,
|
|
49
|
+
failed: labels.notSent
|
|
50
|
+
}[status];
|
|
51
|
+
return /* @__PURE__ */ jsxs(
|
|
52
|
+
"span",
|
|
53
|
+
{
|
|
54
|
+
"data-status": status,
|
|
55
|
+
className: cn(
|
|
56
|
+
"inline-flex items-center gap-1",
|
|
57
|
+
status === "read" && "text-accent-ink",
|
|
58
|
+
status === "failed" && "text-danger"
|
|
59
|
+
),
|
|
60
|
+
children: [
|
|
61
|
+
status === "sent" ? /* @__PURE__ */ jsx(Check, { "aria-hidden": "true", className: "size-3" }) : null,
|
|
62
|
+
status === "delivered" || status === "read" ? /* @__PURE__ */ jsx(CheckCheck, { "aria-hidden": "true", className: "size-3" }) : null,
|
|
63
|
+
label
|
|
64
|
+
]
|
|
65
|
+
}
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
function ChatThread({
|
|
69
|
+
items,
|
|
70
|
+
composer,
|
|
71
|
+
labels: labelsProp,
|
|
72
|
+
label,
|
|
73
|
+
onRetry,
|
|
74
|
+
empty,
|
|
75
|
+
locale,
|
|
76
|
+
timeZone,
|
|
77
|
+
now,
|
|
78
|
+
className,
|
|
79
|
+
classNames
|
|
80
|
+
}) {
|
|
81
|
+
const labels = { ...chatThreadLabels.en, ...labelsProp };
|
|
82
|
+
const logRef = useRef(null);
|
|
83
|
+
const stickToEnd = useRef(true);
|
|
84
|
+
const reference = now ?? /* @__PURE__ */ new Date();
|
|
85
|
+
const format = { locale, timeZone };
|
|
86
|
+
const authorName = { customer: labels.customer, bot: labels.bot, staff: labels.staff };
|
|
87
|
+
useIsomorphicLayoutEffect(() => {
|
|
88
|
+
const log = logRef.current;
|
|
89
|
+
if (log && stickToEnd.current) log.scrollTop = log.scrollHeight;
|
|
90
|
+
});
|
|
91
|
+
return /* @__PURE__ */ jsxs(
|
|
92
|
+
"section",
|
|
93
|
+
{
|
|
94
|
+
"aria-label": label ?? labels.conversation,
|
|
95
|
+
className: cn("flex min-h-0 min-w-0 flex-col", classNames?.root, className),
|
|
96
|
+
children: [
|
|
97
|
+
items.length === 0 && empty != null ? /* @__PURE__ */ jsx("div", { className: "flex flex-1 items-center justify-center p-card", children: empty }) : /* @__PURE__ */ jsx(
|
|
98
|
+
"div",
|
|
99
|
+
{
|
|
100
|
+
ref: logRef,
|
|
101
|
+
role: "log",
|
|
102
|
+
"aria-live": "polite",
|
|
103
|
+
"aria-relevant": "additions",
|
|
104
|
+
tabIndex: 0,
|
|
105
|
+
onScroll: (event) => {
|
|
106
|
+
const log = event.currentTarget;
|
|
107
|
+
stickToEnd.current = log.scrollHeight - log.scrollTop - log.clientHeight < 80;
|
|
108
|
+
},
|
|
109
|
+
className: cn(
|
|
110
|
+
"min-h-0 flex-1 overflow-y-auto overscroll-contain p-density focus-visible:focus-ring",
|
|
111
|
+
classNames?.log
|
|
112
|
+
),
|
|
113
|
+
children: /* @__PURE__ */ jsx("ol", { className: "m-0 flex list-none flex-col gap-2 p-0", children: withDayBreaks(items, timeZone).map(({ item, dayStart }) => /* @__PURE__ */ jsx(
|
|
114
|
+
ChatThreadRow,
|
|
115
|
+
{
|
|
116
|
+
item,
|
|
117
|
+
dayLabel: dayStart ? formatDay(
|
|
118
|
+
item.at,
|
|
119
|
+
reference,
|
|
120
|
+
{ today: labels.today, yesterday: labels.yesterday },
|
|
121
|
+
format
|
|
122
|
+
) : void 0,
|
|
123
|
+
dayValue: dayStart ? dayKey(item.at, timeZone) : void 0,
|
|
124
|
+
time: formatTime(item.at, format),
|
|
125
|
+
authorName,
|
|
126
|
+
labels,
|
|
127
|
+
onRetry,
|
|
128
|
+
classNames
|
|
129
|
+
},
|
|
130
|
+
item.id
|
|
131
|
+
)) })
|
|
132
|
+
}
|
|
133
|
+
),
|
|
134
|
+
composer != null ? /* @__PURE__ */ jsx(
|
|
135
|
+
"div",
|
|
136
|
+
{
|
|
137
|
+
className: cn("shrink-0 border-t-divider p-density", classNames?.composer),
|
|
138
|
+
"data-slot": "composer",
|
|
139
|
+
children: composer
|
|
140
|
+
}
|
|
141
|
+
) : null
|
|
142
|
+
]
|
|
143
|
+
}
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
function ChatThreadRow({
|
|
147
|
+
item,
|
|
148
|
+
dayLabel,
|
|
149
|
+
dayValue,
|
|
150
|
+
time,
|
|
151
|
+
authorName,
|
|
152
|
+
labels,
|
|
153
|
+
onRetry,
|
|
154
|
+
classNames
|
|
155
|
+
}) {
|
|
156
|
+
const strings = useUiStrings();
|
|
157
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
158
|
+
dayLabel ? /* @__PURE__ */ jsx("li", { className: cn("flex justify-center py-1", classNames?.day), "data-slot": "day", children: /* @__PURE__ */ jsx(
|
|
159
|
+
"time",
|
|
160
|
+
{
|
|
161
|
+
dateTime: dayValue,
|
|
162
|
+
className: "rounded-badge bg-sunken px-2.5 py-0.5 text-ink-2 text-meta",
|
|
163
|
+
children: dayLabel
|
|
164
|
+
}
|
|
165
|
+
) }) : null,
|
|
166
|
+
item.kind === "note" ? /* @__PURE__ */ jsx("li", { className: "flex justify-center", "data-kind": "note", children: /* @__PURE__ */ jsx(
|
|
167
|
+
"p",
|
|
168
|
+
{
|
|
169
|
+
className: cn(
|
|
170
|
+
"m-0 max-w-[85%] rounded-badge bg-sunken px-3 py-1 text-center text-ink-2 text-meta",
|
|
171
|
+
classNames?.note
|
|
172
|
+
),
|
|
173
|
+
children: item.content
|
|
174
|
+
}
|
|
175
|
+
) }) : /* @__PURE__ */ jsx(
|
|
176
|
+
"li",
|
|
177
|
+
{
|
|
178
|
+
"data-author": item.author,
|
|
179
|
+
className: cn(
|
|
180
|
+
"flex",
|
|
181
|
+
item.author === "customer" ? "justify-start" : "justify-end",
|
|
182
|
+
classNames?.message
|
|
183
|
+
),
|
|
184
|
+
children: /* @__PURE__ */ jsxs(
|
|
185
|
+
"div",
|
|
186
|
+
{
|
|
187
|
+
className: cn(
|
|
188
|
+
"flex min-w-0 max-w-[min(34rem,85%)] flex-col gap-0.5",
|
|
189
|
+
item.author === "customer" ? "items-start" : "items-end"
|
|
190
|
+
),
|
|
191
|
+
children: [
|
|
192
|
+
/* @__PURE__ */ jsx("span", { className: cn("text-ink-3 text-meta", classNames?.author), children: item.name ?? authorName[item.author] }),
|
|
193
|
+
/* @__PURE__ */ jsx(
|
|
194
|
+
"div",
|
|
195
|
+
{
|
|
196
|
+
className: cn(
|
|
197
|
+
"min-w-0 whitespace-pre-wrap rounded-card px-3 py-2 text-body [overflow-wrap:anywhere]",
|
|
198
|
+
bubbleTone[item.author],
|
|
199
|
+
classNames?.bubble
|
|
200
|
+
),
|
|
201
|
+
children: item.content
|
|
202
|
+
}
|
|
203
|
+
),
|
|
204
|
+
/* @__PURE__ */ jsxs("div", { className: cn("flex items-center gap-2 text-ink-3 text-meta", classNames?.meta), children: [
|
|
205
|
+
/* @__PURE__ */ jsx("time", { dateTime: new Date(item.at).toISOString(), children: time }),
|
|
206
|
+
item.author !== "customer" && item.status ? /* @__PURE__ */ jsx(Status, { status: item.status, labels }) : null,
|
|
207
|
+
item.status === "failed" && onRetry ? /* @__PURE__ */ jsx(Button, { variant: "ghost", size: "sm", onClick: () => onRetry(item.id), children: strings.retry }) : null
|
|
208
|
+
] })
|
|
209
|
+
]
|
|
210
|
+
}
|
|
211
|
+
)
|
|
212
|
+
}
|
|
213
|
+
)
|
|
214
|
+
] });
|
|
215
|
+
}
|
|
216
|
+
export {
|
|
217
|
+
ChatThread,
|
|
218
|
+
chatThreadLabels
|
|
219
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export type ChatTimestamp = Date | string | number;
|
|
2
|
+
export interface ChatThreadFormat {
|
|
3
|
+
locale?: string | undefined;
|
|
4
|
+
timeZone?: string | undefined;
|
|
5
|
+
}
|
|
6
|
+
/** `YYYY-MM-DD` of the instant in `timeZone` (the local zone when omitted). */
|
|
7
|
+
export declare function dayKey(at: ChatTimestamp, timeZone?: string): string;
|
|
8
|
+
export declare function formatTime(at: ChatTimestamp, { locale, timeZone }?: ChatThreadFormat): string;
|
|
9
|
+
/** "Today" and "Yesterday" relative to `now`, otherwise a long date (with the year when it differs). */
|
|
10
|
+
export declare function formatDay(at: ChatTimestamp, now: ChatTimestamp, labels: {
|
|
11
|
+
today: string;
|
|
12
|
+
yesterday: string;
|
|
13
|
+
}, { locale, timeZone }?: ChatThreadFormat): string;
|
|
14
|
+
/** Items in order, each flagged with whether a new day starts at it. */
|
|
15
|
+
export declare function withDayBreaks<T extends {
|
|
16
|
+
at: ChatTimestamp;
|
|
17
|
+
}>(items: readonly T[], timeZone?: string): Array<{
|
|
18
|
+
item: T;
|
|
19
|
+
dayStart: boolean;
|
|
20
|
+
}>;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
const toDate = (at) => at instanceof Date ? at : new Date(at);
|
|
2
|
+
function dayKey(at, timeZone) {
|
|
3
|
+
return new Intl.DateTimeFormat("en-CA", {
|
|
4
|
+
timeZone,
|
|
5
|
+
year: "numeric",
|
|
6
|
+
month: "2-digit",
|
|
7
|
+
day: "2-digit"
|
|
8
|
+
}).format(toDate(at));
|
|
9
|
+
}
|
|
10
|
+
function shiftDay(key, days) {
|
|
11
|
+
const [year = 0, month = 1, day = 1] = key.split("-").map(Number);
|
|
12
|
+
const shifted = new Date(Date.UTC(year, month - 1, day + days));
|
|
13
|
+
return shifted.toISOString().slice(0, 10);
|
|
14
|
+
}
|
|
15
|
+
function formatTime(at, { locale, timeZone } = {}) {
|
|
16
|
+
return new Intl.DateTimeFormat(locale, {
|
|
17
|
+
timeZone,
|
|
18
|
+
hour: "2-digit",
|
|
19
|
+
minute: "2-digit"
|
|
20
|
+
}).format(toDate(at));
|
|
21
|
+
}
|
|
22
|
+
function formatDay(at, now, labels, { locale, timeZone } = {}) {
|
|
23
|
+
const key = dayKey(at, timeZone);
|
|
24
|
+
const today = dayKey(now, timeZone);
|
|
25
|
+
if (key === today) return labels.today;
|
|
26
|
+
if (key === shiftDay(today, -1)) return labels.yesterday;
|
|
27
|
+
const sameYear = key.slice(0, 4) === today.slice(0, 4);
|
|
28
|
+
return new Intl.DateTimeFormat(locale, {
|
|
29
|
+
timeZone,
|
|
30
|
+
weekday: "long",
|
|
31
|
+
day: "numeric",
|
|
32
|
+
month: "long",
|
|
33
|
+
...sameYear ? {} : { year: "numeric" }
|
|
34
|
+
}).format(toDate(at));
|
|
35
|
+
}
|
|
36
|
+
function withDayBreaks(items, timeZone) {
|
|
37
|
+
let previous = null;
|
|
38
|
+
return items.map((item) => {
|
|
39
|
+
const key = dayKey(item.at, timeZone);
|
|
40
|
+
const dayStart = key !== previous;
|
|
41
|
+
previous = key;
|
|
42
|
+
return { item, dayStart };
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
export {
|
|
46
|
+
dayKey,
|
|
47
|
+
formatDay,
|
|
48
|
+
formatTime,
|
|
49
|
+
withDayBreaks
|
|
50
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { type ChatAuthorKind, type ChatDeliveryStatus, ChatThread, type ChatThreadItem, type ChatThreadLabels, type ChatThreadMessage, type ChatThreadNote, type ChatThreadPart, type ChatThreadProps, chatThreadLabels, } from "./chat-thread.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ComponentPropsWithoutRef } from "react";
|
|
2
|
-
export type ColsVariant = "rail" | "half" | "calc";
|
|
2
|
+
export type ColsVariant = "rail" | "half" | "calc" | "thirds";
|
|
3
3
|
export interface ColsProps extends ComponentPropsWithoutRef<"div"> {
|
|
4
4
|
/** Column proportions. Omit for the base main + side split. */
|
|
5
5
|
variant?: ColsVariant;
|
|
@@ -16,6 +16,13 @@ const variantClasses = {
|
|
|
16
16
|
"grid-cols-[minmax(0,1fr)_minmax(0,1.5fr)]",
|
|
17
17
|
"@min-[1500px]/page:grid-cols-[minmax(0,1fr)_minmax(0,2fr)]",
|
|
18
18
|
"@max-[940px]/page:grid-cols-[minmax(0,1fr)]"
|
|
19
|
+
),
|
|
20
|
+
thirds: cn(
|
|
21
|
+
"grid-cols-[repeat(3,minmax(0,1fr))]",
|
|
22
|
+
"@max-[1279px]/page:grid-cols-[repeat(2,minmax(0,1fr))]",
|
|
23
|
+
"@max-[1279px]/page:[&>:last-child:nth-child(odd)]:col-span-2",
|
|
24
|
+
"@max-[719px]/page:grid-cols-[minmax(0,1fr)]",
|
|
25
|
+
"@max-[719px]/page:[&>:last-child:nth-child(odd)]:col-span-1"
|
|
19
26
|
)
|
|
20
27
|
};
|
|
21
28
|
function Cols({ variant, className, ...props }) {
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import type { ClassNames } from "../../utils/class-names.js";
|
|
3
|
+
export type ContextRailPart = "root" | "grid" | "main" | "rail" | "summary" | "sheet";
|
|
4
|
+
/**
|
|
5
|
+
* Container widths (px) under which the rail collapses; the set is closed so every query is a
|
|
6
|
+
* literal class. `"never"` keeps the rail beside the work area at any width and `"always"`
|
|
7
|
+
* collapses it at any width.
|
|
8
|
+
*/
|
|
9
|
+
export type ContextRailBreakpoint = 720 | 960 | 1280 | "never" | "always";
|
|
10
|
+
export interface ContextRailWidths {
|
|
11
|
+
/** Rail width (px) from the collapse breakpoint up. */
|
|
12
|
+
m?: number;
|
|
13
|
+
/** From 1280 px of container width. */
|
|
14
|
+
w?: number;
|
|
15
|
+
/** From 1600 px of container width. */
|
|
16
|
+
xw?: number;
|
|
17
|
+
}
|
|
18
|
+
export interface ContextRailProps {
|
|
19
|
+
/** The work area. */
|
|
20
|
+
children: ReactNode;
|
|
21
|
+
/** Content of the rail. */
|
|
22
|
+
rail: ReactNode;
|
|
23
|
+
/** Rail width in px, or one width per breakpoint. Defaults to 360 / 400 / 440. */
|
|
24
|
+
width?: number | ContextRailWidths;
|
|
25
|
+
/** Distance (px) the sticky rail keeps from the top of the scroll container. Defaults to 0. */
|
|
26
|
+
stickyTop?: number;
|
|
27
|
+
/** Container width under which the rail collapses (`"never"` / `"always"` pin it). Defaults to 720. */
|
|
28
|
+
breakpoint?: ContextRailBreakpoint;
|
|
29
|
+
/**
|
|
30
|
+
* Collapsed behaviour: `"stack"` puts the rail below the work area; `"sheet"` hides it behind a
|
|
31
|
+
* `summary` bar that opens it as a bottom sheet.
|
|
32
|
+
*/
|
|
33
|
+
collapse?: "stack" | "sheet";
|
|
34
|
+
/** Compact bar shown while collapsed to a sheet (total plus the main action). It owns the button that opens the sheet. Inside an `AppShell` with a `bottomBar` it sits above that bar. */
|
|
35
|
+
summary?: ReactNode;
|
|
36
|
+
/** Label of the button that opens the sheet, and name of the sheet. */
|
|
37
|
+
sheetLabel?: string;
|
|
38
|
+
/** Accessible name of the rail region. */
|
|
39
|
+
railLabel?: string;
|
|
40
|
+
/** Controlled open state of the sheet. */
|
|
41
|
+
sheetOpen?: boolean;
|
|
42
|
+
onSheetOpenChange?: (open: boolean) => void;
|
|
43
|
+
className?: string;
|
|
44
|
+
/** Per-part classes merged with `cn`; consumer classes win. `className` still targets the root and is merged last. */
|
|
45
|
+
classNames?: ClassNames<ContextRailPart>;
|
|
46
|
+
}
|
|
47
|
+
/** Whether the rail is collapsed for a measured container width (`null` before the first measurement). */
|
|
48
|
+
export declare function isRailCollapsed(breakpoint: ContextRailBreakpoint, width: number | null): boolean;
|
|
49
|
+
export declare function resolveRailWidths(width: number | ContextRailWidths | undefined): {
|
|
50
|
+
m: number;
|
|
51
|
+
w: number;
|
|
52
|
+
xw: number;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Work area with a persistent side rail (cart, payment, selected table). The rail sticks to the
|
|
56
|
+
* top of the scroll container with its own scroll, and its width grows with the container.
|
|
57
|
+
* Under `breakpoint` it stacks below the work area, or with `collapse="sheet"` it leaves the page
|
|
58
|
+
* for a bottom sheet opened from the `summary` bar. `breakpoint="never"` keeps it beside the work
|
|
59
|
+
* area at any width, `"always"` collapses it at any width. Widths and cuts follow the container
|
|
60
|
+
* (`@container/rail`), not the viewport.
|
|
61
|
+
*/
|
|
62
|
+
export declare function ContextRail({ children, rail, width, stickyTop, breakpoint, collapse, summary, sheetLabel, railLabel, sheetOpen: sheetOpenProp, onSheetOpenChange, className, classNames, }: ContextRailProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useRef, useState } from "react";
|
|
4
|
+
import { useUiStrings } from "../../i18n/index.js";
|
|
5
|
+
import { X } from "../../icons/index.js";
|
|
6
|
+
import * as DialogPrimitive from "../../primitives/dialog/dialog.js";
|
|
7
|
+
import { cn } from "../../utils/cn.js";
|
|
8
|
+
import { useContainerWidth } from "../../utils/use-container-width.js";
|
|
9
|
+
const DEFAULT_WIDTHS = { m: 360, w: 400, xw: 440 };
|
|
10
|
+
const collapseClasses = {
|
|
11
|
+
720: {
|
|
12
|
+
grid: "@max-[719px]/rail:grid-cols-[minmax(0,1fr)]",
|
|
13
|
+
rail: "@max-[719px]/rail:static @max-[719px]/rail:max-h-none",
|
|
14
|
+
bar: "hidden @max-[719px]/rail:block",
|
|
15
|
+
hide: "@max-[719px]/rail:hidden"
|
|
16
|
+
},
|
|
17
|
+
960: {
|
|
18
|
+
grid: "@max-[959px]/rail:grid-cols-[minmax(0,1fr)]",
|
|
19
|
+
rail: "@max-[959px]/rail:static @max-[959px]/rail:max-h-none",
|
|
20
|
+
bar: "hidden @max-[959px]/rail:block",
|
|
21
|
+
hide: "@max-[959px]/rail:hidden"
|
|
22
|
+
},
|
|
23
|
+
1280: {
|
|
24
|
+
grid: "@max-[1279px]/rail:grid-cols-[minmax(0,1fr)]",
|
|
25
|
+
rail: "@max-[1279px]/rail:static @max-[1279px]/rail:max-h-none",
|
|
26
|
+
bar: "hidden @max-[1279px]/rail:block",
|
|
27
|
+
hide: "@max-[1279px]/rail:hidden"
|
|
28
|
+
},
|
|
29
|
+
never: { grid: "", rail: "", bar: "hidden", hide: "" },
|
|
30
|
+
always: {
|
|
31
|
+
grid: "grid-cols-[minmax(0,1fr)]",
|
|
32
|
+
rail: "static max-h-none",
|
|
33
|
+
bar: "block",
|
|
34
|
+
hide: "hidden"
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
function isRailCollapsed(breakpoint, width) {
|
|
38
|
+
if (breakpoint === "always") return true;
|
|
39
|
+
if (breakpoint === "never") return false;
|
|
40
|
+
return width !== null && width < breakpoint;
|
|
41
|
+
}
|
|
42
|
+
function resolveRailWidths(width) {
|
|
43
|
+
if (typeof width === "number") return { m: width, w: width, xw: width };
|
|
44
|
+
return { ...DEFAULT_WIDTHS, ...width };
|
|
45
|
+
}
|
|
46
|
+
function ContextRail({
|
|
47
|
+
children,
|
|
48
|
+
rail,
|
|
49
|
+
width,
|
|
50
|
+
stickyTop = 0,
|
|
51
|
+
breakpoint = 720,
|
|
52
|
+
collapse = "stack",
|
|
53
|
+
summary,
|
|
54
|
+
sheetLabel,
|
|
55
|
+
railLabel,
|
|
56
|
+
sheetOpen: sheetOpenProp,
|
|
57
|
+
onSheetOpenChange,
|
|
58
|
+
className,
|
|
59
|
+
classNames
|
|
60
|
+
}) {
|
|
61
|
+
const strings = useUiStrings();
|
|
62
|
+
const rootRef = useRef(null);
|
|
63
|
+
const measured = useContainerWidth(rootRef);
|
|
64
|
+
const collapsed = isRailCollapsed(breakpoint, measured);
|
|
65
|
+
const [openState, setOpenState] = useState(false);
|
|
66
|
+
const controlled = sheetOpenProp !== void 0;
|
|
67
|
+
const open = (controlled ? sheetOpenProp : openState) && collapsed;
|
|
68
|
+
const setOpen = (next) => {
|
|
69
|
+
if (!controlled) setOpenState(next);
|
|
70
|
+
onSheetOpenChange?.(next);
|
|
71
|
+
};
|
|
72
|
+
const widths = resolveRailWidths(width);
|
|
73
|
+
const classes = collapseClasses[breakpoint];
|
|
74
|
+
const sheet = collapse === "sheet";
|
|
75
|
+
const label = sheetLabel ?? railLabel;
|
|
76
|
+
const style = {
|
|
77
|
+
"--rail-m": `${widths.m}px`,
|
|
78
|
+
"--rail-w": `${widths.w}px`,
|
|
79
|
+
"--rail-xw": `${widths.xw}px`,
|
|
80
|
+
"--rail-top": `${stickyTop}px`
|
|
81
|
+
};
|
|
82
|
+
return /* @__PURE__ */ jsxs(
|
|
83
|
+
"div",
|
|
84
|
+
{
|
|
85
|
+
ref: rootRef,
|
|
86
|
+
"data-collapsed": collapsed ? "" : void 0,
|
|
87
|
+
style,
|
|
88
|
+
className: cn("@container/rail min-w-0", classNames?.root, className),
|
|
89
|
+
children: [
|
|
90
|
+
/* @__PURE__ */ jsxs(
|
|
91
|
+
"div",
|
|
92
|
+
{
|
|
93
|
+
className: cn(
|
|
94
|
+
"grid items-start gap-4 [--rail:var(--rail-m)] @min-[1280px]/rail:[--rail:var(--rail-w)] @min-[1600px]/rail:[--rail:var(--rail-xw)]",
|
|
95
|
+
breakpoint === "always" ? void 0 : "grid-cols-[minmax(0,1fr)_var(--rail)]",
|
|
96
|
+
classes.grid,
|
|
97
|
+
classNames?.grid
|
|
98
|
+
),
|
|
99
|
+
children: [
|
|
100
|
+
/* @__PURE__ */ jsx("div", { className: cn("min-w-0", classNames?.main), children }),
|
|
101
|
+
/* @__PURE__ */ jsx(
|
|
102
|
+
"aside",
|
|
103
|
+
{
|
|
104
|
+
"aria-label": railLabel,
|
|
105
|
+
className: cn(
|
|
106
|
+
"sticky top-(--rail-top) min-w-0 max-h-[calc(100dvh-var(--rail-top))] overflow-y-auto overscroll-contain",
|
|
107
|
+
classes.rail,
|
|
108
|
+
sheet && classes.hide,
|
|
109
|
+
classNames?.rail
|
|
110
|
+
),
|
|
111
|
+
children: sheet && collapsed ? null : rail
|
|
112
|
+
}
|
|
113
|
+
)
|
|
114
|
+
]
|
|
115
|
+
}
|
|
116
|
+
),
|
|
117
|
+
sheet && summary != null ? /* @__PURE__ */ jsx(
|
|
118
|
+
"div",
|
|
119
|
+
{
|
|
120
|
+
className: cn(
|
|
121
|
+
"sticky bottom-(--app-bottom-bar,0px) z-10 border-t-divider surface-card p-density",
|
|
122
|
+
classes.bar,
|
|
123
|
+
classNames?.summary
|
|
124
|
+
),
|
|
125
|
+
children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-3", children: [
|
|
126
|
+
/* @__PURE__ */ jsx("div", { className: "min-w-0 flex-1", children: summary }),
|
|
127
|
+
/* @__PURE__ */ jsx(
|
|
128
|
+
"button",
|
|
129
|
+
{
|
|
130
|
+
type: "button",
|
|
131
|
+
"aria-haspopup": "dialog",
|
|
132
|
+
"aria-expanded": open,
|
|
133
|
+
onClick: () => setOpen(true),
|
|
134
|
+
className: "shrink-0 rounded-button px-3 py-2 font-semibold text-accent-ink text-body focus-visible:focus-ring",
|
|
135
|
+
children: label ?? strings.actions
|
|
136
|
+
}
|
|
137
|
+
)
|
|
138
|
+
] })
|
|
139
|
+
}
|
|
140
|
+
) : null,
|
|
141
|
+
sheet ? /* @__PURE__ */ jsx(DialogPrimitive.Root, { open, onOpenChange: setOpen, children: /* @__PURE__ */ jsxs(DialogPrimitive.Portal, { children: [
|
|
142
|
+
/* @__PURE__ */ jsx(DialogPrimitive.Overlay, { className: "fixed inset-0 z-70 bg-scrim" }),
|
|
143
|
+
/* @__PURE__ */ jsxs(
|
|
144
|
+
DialogPrimitive.Content,
|
|
145
|
+
{
|
|
146
|
+
className: cn(
|
|
147
|
+
"fixed inset-x-0 bottom-0 z-70 flex max-h-[85dvh] flex-col overflow-y-auto rounded-t-card p-card outline-none surface-overlay shadow-overlay",
|
|
148
|
+
classNames?.sheet
|
|
149
|
+
),
|
|
150
|
+
children: [
|
|
151
|
+
/* @__PURE__ */ jsxs("div", { className: "mb-2 flex items-center justify-between gap-3", children: [
|
|
152
|
+
/* @__PURE__ */ jsx(DialogPrimitive.Title, { className: "m-0 font-semibold text-card-title text-ink", children: label ?? strings.actions }),
|
|
153
|
+
/* @__PURE__ */ jsx(
|
|
154
|
+
DialogPrimitive.Close,
|
|
155
|
+
{
|
|
156
|
+
"aria-label": strings.close,
|
|
157
|
+
className: "rounded-event p-1 text-ink-3 hover:text-ink focus-visible:focus-ring",
|
|
158
|
+
children: /* @__PURE__ */ jsx(X, { "aria-hidden": "true", className: "size-4" })
|
|
159
|
+
}
|
|
160
|
+
)
|
|
161
|
+
] }),
|
|
162
|
+
rail
|
|
163
|
+
]
|
|
164
|
+
}
|
|
165
|
+
)
|
|
166
|
+
] }) }) : null
|
|
167
|
+
]
|
|
168
|
+
}
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
export {
|
|
172
|
+
ContextRail,
|
|
173
|
+
isRailCollapsed,
|
|
174
|
+
resolveRailWidths
|
|
175
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ContextRail, type ContextRailBreakpoint, type ContextRailPart, type ContextRailProps, type ContextRailWidths, } from "./context-rail.js";
|