@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,216 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useId, useMemo } from "react";
|
|
4
|
+
import { Button } from "../../atoms/button/button.js";
|
|
5
|
+
import { useUiStrings } from "../../i18n/index.js";
|
|
6
|
+
import { ChevronLeft, ChevronRight, ChevronsLeft, ChevronsRight } from "../../icons/index.js";
|
|
7
|
+
import { cn } from "../../utils/cn.js";
|
|
8
|
+
import { useControllableState } from "../../utils/use-controllable-state.js";
|
|
9
|
+
import {
|
|
10
|
+
clampPage,
|
|
11
|
+
formatPageRange,
|
|
12
|
+
formatRange,
|
|
13
|
+
pageCount,
|
|
14
|
+
pageItems,
|
|
15
|
+
pageRange
|
|
16
|
+
} from "./range.js";
|
|
17
|
+
import {
|
|
18
|
+
clampPage as clampPage2,
|
|
19
|
+
formatPageRange as formatPageRange2,
|
|
20
|
+
formatRange as formatRange2,
|
|
21
|
+
pageCount as pageCount2,
|
|
22
|
+
pageItems as pageItems2,
|
|
23
|
+
pageRange as pageRange2
|
|
24
|
+
} from "./range.js";
|
|
25
|
+
const DEFAULT_OPTIONS = [10, 25, 50, 100];
|
|
26
|
+
const stepButton = "grid size-8 place-items-center rounded-control text-ink-2 hover:bg-surface-2 hover:text-ink focus-visible:focus-ring disabled:pointer-events-none disabled:opacity-35 [&_svg]:size-4";
|
|
27
|
+
function Pagination({
|
|
28
|
+
total,
|
|
29
|
+
page,
|
|
30
|
+
defaultPage = 1,
|
|
31
|
+
onPageChange,
|
|
32
|
+
pageSize,
|
|
33
|
+
defaultPageSize,
|
|
34
|
+
onPageSizeChange,
|
|
35
|
+
pageSizeOptions: pageSizeOptionsProp,
|
|
36
|
+
labels,
|
|
37
|
+
variant = "default",
|
|
38
|
+
hideOnSinglePage = variant === "pages",
|
|
39
|
+
className,
|
|
40
|
+
...props
|
|
41
|
+
}) {
|
|
42
|
+
const pageSizeOptions = pageSizeOptionsProp ?? DEFAULT_OPTIONS;
|
|
43
|
+
const strings = useUiStrings();
|
|
44
|
+
const selectId = useId();
|
|
45
|
+
const [size, setSize] = useControllableState({
|
|
46
|
+
prop: pageSize,
|
|
47
|
+
defaultProp: defaultPageSize ?? pageSizeOptions[0] ?? DEFAULT_OPTIONS[0],
|
|
48
|
+
onChange: onPageSizeChange
|
|
49
|
+
});
|
|
50
|
+
const [current, setPage] = useControllableState({
|
|
51
|
+
prop: page,
|
|
52
|
+
defaultProp: defaultPage,
|
|
53
|
+
onChange: onPageChange
|
|
54
|
+
});
|
|
55
|
+
const text = {
|
|
56
|
+
nav: labels?.nav ?? strings.pagination,
|
|
57
|
+
rowsPerPage: labels?.rowsPerPage ?? strings.rowsPerPage,
|
|
58
|
+
range: labels?.range ?? strings.pageRange,
|
|
59
|
+
first: labels?.first ?? strings.firstPage,
|
|
60
|
+
previous: labels?.previous ?? strings.previousPage,
|
|
61
|
+
next: labels?.next ?? strings.nextPage,
|
|
62
|
+
last: labels?.last ?? strings.lastPage,
|
|
63
|
+
showing: labels?.showing ?? strings.showingRange,
|
|
64
|
+
previousLabel: labels?.previousLabel ?? strings.previous,
|
|
65
|
+
nextLabel: labels?.nextLabel ?? strings.next,
|
|
66
|
+
pageNumber: labels?.pageNumber ?? strings.pageNumber
|
|
67
|
+
};
|
|
68
|
+
const pages = pageCount(total, size);
|
|
69
|
+
const at = clampPage(current, pages);
|
|
70
|
+
const { first, last } = pageRange(at, size, total);
|
|
71
|
+
const format = useMemo(() => new Intl.NumberFormat(strings.locale), [strings.locale]);
|
|
72
|
+
const sizes = [.../* @__PURE__ */ new Set([...pageSizeOptions, size])].sort((a, b) => a - b);
|
|
73
|
+
const atStart = at <= 1;
|
|
74
|
+
const atEnd = at >= pages;
|
|
75
|
+
if (hideOnSinglePage && pages <= 1) return null;
|
|
76
|
+
const picker = sizes.length > 1 && (variant === "default" || pageSizeOptionsProp !== void 0) ? /* @__PURE__ */ jsxs("span", { className: "flex items-center gap-2", children: [
|
|
77
|
+
/* @__PURE__ */ jsx("label", { htmlFor: selectId, children: text.rowsPerPage }),
|
|
78
|
+
/* @__PURE__ */ jsx(
|
|
79
|
+
"select",
|
|
80
|
+
{
|
|
81
|
+
id: selectId,
|
|
82
|
+
value: size,
|
|
83
|
+
onChange: (event) => {
|
|
84
|
+
setSize(Number(event.target.value));
|
|
85
|
+
setPage(1);
|
|
86
|
+
},
|
|
87
|
+
className: "h-control-sm rounded-input border-control bg-surface-control px-1.5 text-fs-120 text-ink",
|
|
88
|
+
children: sizes.map((option) => /* @__PURE__ */ jsx("option", { value: option, children: option }, option))
|
|
89
|
+
}
|
|
90
|
+
)
|
|
91
|
+
] }) : null;
|
|
92
|
+
if (variant === "pages") {
|
|
93
|
+
return /* @__PURE__ */ jsxs(
|
|
94
|
+
"nav",
|
|
95
|
+
{
|
|
96
|
+
"aria-label": text.nav,
|
|
97
|
+
className: cn(
|
|
98
|
+
"flex min-w-0 flex-wrap items-center justify-between gap-x-4 gap-y-2 py-2 text-fs-120 text-ink-2",
|
|
99
|
+
className
|
|
100
|
+
),
|
|
101
|
+
...props,
|
|
102
|
+
children: [
|
|
103
|
+
/* @__PURE__ */ jsx("span", { "aria-live": "polite", className: "tabular-nums", children: formatRange(text.showing, {
|
|
104
|
+
first: format.format(first),
|
|
105
|
+
last: format.format(last),
|
|
106
|
+
total: format.format(Math.max(0, total))
|
|
107
|
+
}) }),
|
|
108
|
+
/* @__PURE__ */ jsxs("span", { className: "flex flex-wrap items-center gap-x-4 gap-y-2", children: [
|
|
109
|
+
picker,
|
|
110
|
+
/* @__PURE__ */ jsxs("span", { className: "flex items-center gap-1", children: [
|
|
111
|
+
/* @__PURE__ */ jsx(Button, { size: "sm", disabled: atStart, onClick: () => setPage(at - 1), children: text.previousLabel }),
|
|
112
|
+
pageItems(at, pages).map(
|
|
113
|
+
(item, index) => item === "gap" ? /* @__PURE__ */ jsx(
|
|
114
|
+
"span",
|
|
115
|
+
{
|
|
116
|
+
"aria-hidden": "true",
|
|
117
|
+
className: "w-6 text-center text-ink-3",
|
|
118
|
+
children: "\u2026"
|
|
119
|
+
},
|
|
120
|
+
`gap-${index}`
|
|
121
|
+
) : /* @__PURE__ */ jsx(
|
|
122
|
+
Button,
|
|
123
|
+
{
|
|
124
|
+
size: "sm",
|
|
125
|
+
variant: item === at ? "secondary" : "ghost",
|
|
126
|
+
"aria-current": item === at ? "page" : void 0,
|
|
127
|
+
"aria-label": text.pageNumber.replace("{page}", String(item)),
|
|
128
|
+
onClick: () => setPage(item),
|
|
129
|
+
className: "min-w-control-sm px-2 tabular-nums",
|
|
130
|
+
children: format.format(item)
|
|
131
|
+
},
|
|
132
|
+
item
|
|
133
|
+
)
|
|
134
|
+
),
|
|
135
|
+
/* @__PURE__ */ jsx(Button, { size: "sm", disabled: atEnd, onClick: () => setPage(at + 1), children: text.nextLabel })
|
|
136
|
+
] })
|
|
137
|
+
] })
|
|
138
|
+
]
|
|
139
|
+
}
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
return /* @__PURE__ */ jsxs(
|
|
143
|
+
"nav",
|
|
144
|
+
{
|
|
145
|
+
"aria-label": text.nav,
|
|
146
|
+
className: cn(
|
|
147
|
+
"@container/pagination flex min-w-0 flex-wrap items-center justify-end gap-x-4 gap-y-1 px-2 py-1.5 text-fs-120 text-ink-2",
|
|
148
|
+
className
|
|
149
|
+
),
|
|
150
|
+
...props,
|
|
151
|
+
children: [
|
|
152
|
+
picker,
|
|
153
|
+
/* @__PURE__ */ jsx("span", { "aria-live": "polite", className: "tabular-nums", children: formatPageRange(text.range, {
|
|
154
|
+
first: format.format(first),
|
|
155
|
+
last: format.format(last),
|
|
156
|
+
total: format.format(Math.max(0, total))
|
|
157
|
+
}) }),
|
|
158
|
+
/* @__PURE__ */ jsxs("span", { className: "flex items-center", children: [
|
|
159
|
+
/* @__PURE__ */ jsx(
|
|
160
|
+
"button",
|
|
161
|
+
{
|
|
162
|
+
type: "button",
|
|
163
|
+
className: stepButton,
|
|
164
|
+
"aria-label": text.first,
|
|
165
|
+
disabled: atStart,
|
|
166
|
+
onClick: () => setPage(1),
|
|
167
|
+
children: /* @__PURE__ */ jsx(ChevronsLeft, { "aria-hidden": "true" })
|
|
168
|
+
}
|
|
169
|
+
),
|
|
170
|
+
/* @__PURE__ */ jsx(
|
|
171
|
+
"button",
|
|
172
|
+
{
|
|
173
|
+
type: "button",
|
|
174
|
+
className: stepButton,
|
|
175
|
+
"aria-label": text.previous,
|
|
176
|
+
disabled: atStart,
|
|
177
|
+
onClick: () => setPage(at - 1),
|
|
178
|
+
children: /* @__PURE__ */ jsx(ChevronLeft, { "aria-hidden": "true" })
|
|
179
|
+
}
|
|
180
|
+
),
|
|
181
|
+
/* @__PURE__ */ jsx(
|
|
182
|
+
"button",
|
|
183
|
+
{
|
|
184
|
+
type: "button",
|
|
185
|
+
className: stepButton,
|
|
186
|
+
"aria-label": text.next,
|
|
187
|
+
disabled: atEnd,
|
|
188
|
+
onClick: () => setPage(at + 1),
|
|
189
|
+
children: /* @__PURE__ */ jsx(ChevronRight, { "aria-hidden": "true" })
|
|
190
|
+
}
|
|
191
|
+
),
|
|
192
|
+
/* @__PURE__ */ jsx(
|
|
193
|
+
"button",
|
|
194
|
+
{
|
|
195
|
+
type: "button",
|
|
196
|
+
className: stepButton,
|
|
197
|
+
"aria-label": text.last,
|
|
198
|
+
disabled: atEnd,
|
|
199
|
+
onClick: () => setPage(pages),
|
|
200
|
+
children: /* @__PURE__ */ jsx(ChevronsRight, { "aria-hidden": "true" })
|
|
201
|
+
}
|
|
202
|
+
)
|
|
203
|
+
] })
|
|
204
|
+
]
|
|
205
|
+
}
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
export {
|
|
209
|
+
Pagination,
|
|
210
|
+
clampPage2 as clampPage,
|
|
211
|
+
formatPageRange2 as formatPageRange,
|
|
212
|
+
formatRange2 as formatRange,
|
|
213
|
+
pageCount2 as pageCount,
|
|
214
|
+
pageItems2 as pageItems,
|
|
215
|
+
pageRange2 as pageRange
|
|
216
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/** Number of pages for `total` rows; at least 1 so an empty list still has a first page. */
|
|
2
|
+
export declare function pageCount(total: number, pageSize: number): number;
|
|
3
|
+
/** Keeps a 1-based page inside `1..pages`. */
|
|
4
|
+
export declare function clampPage(page: number, pages: number): number;
|
|
5
|
+
/** 1-based first and last row shown on `page`; `{ first: 0, last: 0 }` when there are no rows. */
|
|
6
|
+
export declare function pageRange(page: number, pageSize: number, total: number): {
|
|
7
|
+
first: number;
|
|
8
|
+
last: number;
|
|
9
|
+
};
|
|
10
|
+
/** Fills the `{first}`, `{last}` and `{total}` placeholders of the `pageRange` UI string. */
|
|
11
|
+
export declare function formatPageRange(template: string, values: {
|
|
12
|
+
first: string;
|
|
13
|
+
last: string;
|
|
14
|
+
total: string;
|
|
15
|
+
}): string;
|
|
16
|
+
/** A page number button, or a gap between two runs of them. */
|
|
17
|
+
export type PageItem = number | "gap";
|
|
18
|
+
/**
|
|
19
|
+
* The page buttons to show: the first and last page, the current one with `siblings` on each side,
|
|
20
|
+
* and a `"gap"` where pages are left out. A gap never hides a single page (that page shows instead),
|
|
21
|
+
* so the list keeps the same length while the current page moves through the middle.
|
|
22
|
+
*/
|
|
23
|
+
export declare function pageItems(page: number, pages: number, siblings?: number): PageItem[];
|
|
24
|
+
/** Fills `{first}` and `{last}` (and `{total}` when given) in a range template. */
|
|
25
|
+
export declare function formatRange(template: string, values: {
|
|
26
|
+
first: string;
|
|
27
|
+
last: string;
|
|
28
|
+
total?: string;
|
|
29
|
+
}): string;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
function pageCount(total, pageSize) {
|
|
2
|
+
if (pageSize <= 0) return 1;
|
|
3
|
+
return Math.max(1, Math.ceil(Math.max(0, total) / pageSize));
|
|
4
|
+
}
|
|
5
|
+
function clampPage(page, pages) {
|
|
6
|
+
return Math.min(Math.max(1, Math.trunc(page) || 1), pages);
|
|
7
|
+
}
|
|
8
|
+
function pageRange(page, pageSize, total) {
|
|
9
|
+
if (total <= 0 || pageSize <= 0) return { first: 0, last: 0 };
|
|
10
|
+
const current = clampPage(page, pageCount(total, pageSize));
|
|
11
|
+
return { first: (current - 1) * pageSize + 1, last: Math.min(total, current * pageSize) };
|
|
12
|
+
}
|
|
13
|
+
function formatPageRange(template, values) {
|
|
14
|
+
return template.replace("{first}", values.first).replace("{last}", values.last).replace("{total}", values.total);
|
|
15
|
+
}
|
|
16
|
+
function pageItems(page, pages, siblings = 1) {
|
|
17
|
+
const total = Math.max(1, Math.trunc(pages));
|
|
18
|
+
const current = clampPage(page, total);
|
|
19
|
+
const slots = siblings * 2 + 5;
|
|
20
|
+
if (total <= slots) return Array.from({ length: total }, (_, i) => i + 1);
|
|
21
|
+
const start = Math.max(Math.min(current - siblings, total - siblings * 2 - 2), 3);
|
|
22
|
+
const end = Math.min(Math.max(current + siblings, siblings * 2 + 3), total - 2);
|
|
23
|
+
const middle = Array.from({ length: end - start + 1 }, (_, i) => start + i);
|
|
24
|
+
return [
|
|
25
|
+
1,
|
|
26
|
+
start > 3 ? "gap" : 2,
|
|
27
|
+
...middle,
|
|
28
|
+
end < total - 2 ? "gap" : total - 1,
|
|
29
|
+
total
|
|
30
|
+
];
|
|
31
|
+
}
|
|
32
|
+
function formatRange(template, values) {
|
|
33
|
+
return template.replace("{first}", values.first).replace("{last}", values.last).replace("{total}", values.total ?? "");
|
|
34
|
+
}
|
|
35
|
+
export {
|
|
36
|
+
clampPage,
|
|
37
|
+
formatPageRange,
|
|
38
|
+
formatRange,
|
|
39
|
+
pageCount,
|
|
40
|
+
pageItems,
|
|
41
|
+
pageRange
|
|
42
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface PaginationState<T> {
|
|
2
|
+
/** Current 1-based page, always inside `1..pageCount`. */
|
|
3
|
+
page: number;
|
|
4
|
+
pageCount: number;
|
|
5
|
+
/** Rows across every page. */
|
|
6
|
+
total: number;
|
|
7
|
+
pageSize: number;
|
|
8
|
+
/** The rows of the current page. */
|
|
9
|
+
items: readonly T[];
|
|
10
|
+
setPage: (page: number) => void;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Client-side paging over an already filtered and sorted list. The page is clamped, so a search
|
|
14
|
+
* that shrinks the list lands on the last page that still exists instead of an empty one, and it
|
|
15
|
+
* returns to the first page whenever `resetKey` changes (the search text, a filter, the sort).
|
|
16
|
+
* Pair it with `<Pagination variant="pages">`.
|
|
17
|
+
*/
|
|
18
|
+
export declare function usePagination<T>(rows: readonly T[], resetKey?: unknown, pageSize?: number): PaginationState<T>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useMemo, useState } from "react";
|
|
3
|
+
import { clampPage, pageCount } from "./range.js";
|
|
4
|
+
function usePagination(rows, resetKey = "", pageSize = 25) {
|
|
5
|
+
const [requested, setPage] = useState(1);
|
|
6
|
+
const [key, setKey] = useState(resetKey);
|
|
7
|
+
if (!Object.is(key, resetKey)) {
|
|
8
|
+
setKey(resetKey);
|
|
9
|
+
setPage(1);
|
|
10
|
+
}
|
|
11
|
+
const total = rows.length;
|
|
12
|
+
const pages = pageCount(total, pageSize);
|
|
13
|
+
const page = Object.is(key, resetKey) ? clampPage(requested, pages) : 1;
|
|
14
|
+
const items = useMemo(
|
|
15
|
+
() => rows.slice((page - 1) * pageSize, page * pageSize),
|
|
16
|
+
[rows, page, pageSize]
|
|
17
|
+
);
|
|
18
|
+
return { page, pageCount: pages, total, pageSize, items, setPage };
|
|
19
|
+
}
|
|
20
|
+
export {
|
|
21
|
+
usePagination
|
|
22
|
+
};
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
2
|
import type { ClassNames } from "../../utils/class-names.js";
|
|
3
|
+
/** Container widths (px) from which `layout="auto"` shows the table. The set is closed so every query is a literal class. */
|
|
4
|
+
export type ResponsiveListBreakpoint = 480 | 640 | 672 | 768 | 960 | 1280;
|
|
3
5
|
export interface ResponsiveListColumn<T> {
|
|
4
6
|
key: string;
|
|
5
7
|
header: string;
|
|
@@ -20,9 +22,33 @@ export interface ResponsiveListProps<T> {
|
|
|
20
22
|
/** Header of the actions column. Defaults to the localized "Actions". */
|
|
21
23
|
actionsHeader?: string;
|
|
22
24
|
rowClassName?: (item: T) => string | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* `"auto"` (default) is a table from `breakpoint` of the list's own container width up and cards
|
|
27
|
+
* below it. `"cards"` always renders the cards, for a list that sits in a narrow pane (a master
|
|
28
|
+
* list next to its detail).
|
|
29
|
+
*/
|
|
30
|
+
layout?: "auto" | "cards";
|
|
31
|
+
/** Container width (px) from which `layout="auto"` shows the table. Defaults to 672 (42rem). */
|
|
32
|
+
breakpoint?: ResponsiveListBreakpoint;
|
|
33
|
+
/**
|
|
34
|
+
* `"visible"` (default) shows each field label in the cards. `"hidden"` keeps them for screen
|
|
35
|
+
* readers only, for cards whose values explain themselves (a price, a status).
|
|
36
|
+
*/
|
|
37
|
+
cardLabels?: "visible" | "hidden";
|
|
38
|
+
/** Key of the selected row, or `null`/`undefined` for none. Only used together with `onSelect`. */
|
|
39
|
+
selectedKey?: string | null;
|
|
40
|
+
/**
|
|
41
|
+
* Makes rows selectable (click, Enter or Space) and adds keyboard navigation (arrows, Home, End).
|
|
42
|
+
* Without `renderActions` the cards are a `listbox` of `option`s and the table a `grid` whose
|
|
43
|
+
* rows carry `aria-selected`; with it the rows keep plain list/table semantics and the selected
|
|
44
|
+
* one gets `aria-current="true"`, because actions cannot live inside an option.
|
|
45
|
+
*/
|
|
46
|
+
onSelect?: (key: string, item: T) => void;
|
|
47
|
+
/** Arrow keys select the row they land on, not only move focus. Off by default. */
|
|
48
|
+
selectOnFocus?: boolean;
|
|
23
49
|
className?: string;
|
|
24
50
|
/** Per-part classes merged with `cn`; consumer classes win. `className` still targets the root and is merged last. */
|
|
25
51
|
classNames?: ClassNames<ResponsiveListPart>;
|
|
26
52
|
}
|
|
27
|
-
/** A table
|
|
28
|
-
export declare function ResponsiveList<T>({ caption, items, columns, rowKey, renderActions, actionsHeader, rowClassName, className, classNames, }: ResponsiveListProps<T>): import("react").JSX.Element;
|
|
53
|
+
/** A table from `breakpoint` of its own width up and a stack of cards below it, from one column definition. */
|
|
54
|
+
export declare function ResponsiveList<T>({ caption, items, columns, rowKey, renderActions, actionsHeader, rowClassName, layout, breakpoint, cardLabels, selectedKey, onSelect, selectOnFocus, className, classNames, }: ResponsiveListProps<T>): import("react").JSX.Element;
|