@jcsoftdev/ui 0.4.0 → 0.6.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 +434 -0
- package/README.md +26 -4
- package/bin/ui-theme.mjs +40 -6
- package/dist/ai/code-block/code-block.js +1 -1
- package/dist/atoms/big-date/big-date.js +2 -2
- package/dist/atoms/button/button.d.ts +14 -2
- package/dist/atoms/button/button.js +12 -5
- package/dist/atoms/chip/chip.d.ts +5 -0
- package/dist/atoms/chip/chip.js +3 -3
- package/dist/atoms/divider/divider.d.ts +15 -0
- package/dist/atoms/divider/divider.js +27 -0
- package/dist/atoms/divider/index.d.ts +1 -0
- package/dist/atoms/divider/index.js +1 -0
- package/dist/atoms/icon-button/icon-button.d.ts +1 -1
- package/dist/atoms/icon-button/icon-button.js +1 -1
- package/dist/atoms/index.d.ts +1 -0
- package/dist/atoms/index.js +1 -0
- 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/auth/auth-illustration/auth-illustration.d.ts +35 -0
- package/dist/auth/auth-illustration/auth-illustration.js +72 -0
- package/dist/auth/auth-illustration/index.d.ts +3 -0
- package/dist/auth/auth-illustration/index.js +11 -0
- package/dist/auth/auth-illustration/look.d.ts +30 -0
- package/dist/auth/auth-illustration/look.js +0 -0
- package/dist/auth/auth-illustration/model.d.ts +133 -0
- package/dist/auth/auth-illustration/model.js +202 -0
- package/dist/auth/auth-illustration/use-art-pointer.d.ts +9 -0
- package/dist/auth/auth-illustration/use-art-pointer.js +69 -0
- package/dist/auth/auth-layout/auth-layout.d.ts +80 -0
- package/dist/auth/auth-layout/auth-layout.js +190 -0
- package/dist/auth/auth-layout/index.d.ts +1 -0
- package/dist/auth/auth-layout/index.js +1 -0
- package/dist/auth/character/character.d.ts +12 -0
- package/dist/auth/character/character.js +333 -0
- package/dist/auth/character/index.d.ts +1 -0
- package/dist/auth/character/index.js +1 -0
- package/dist/auth/index.d.ts +4 -0
- package/dist/auth/index.js +4 -0
- package/dist/auth/internal/auth-context.d.ts +17 -0
- package/dist/auth/internal/auth-context.js +10 -0
- package/dist/auth/internal/auth-styles.d.ts +1 -0
- package/dist/auth/internal/auth-styles.js +29 -0
- package/dist/auth/internal/portal-glyphs.d.ts +6 -0
- package/dist/auth/internal/portal-glyphs.js +39 -0
- package/dist/auth/login-form/context.d.ts +51 -0
- package/dist/auth/login-form/context.js +12 -0
- package/dist/auth/login-form/index.d.ts +2 -0
- package/dist/auth/login-form/index.js +23 -0
- package/dist/auth/login-form/login-form.d.ts +66 -0
- package/dist/auth/login-form/login-form.js +233 -0
- package/dist/auth/login-form/parts.d.ts +71 -0
- package/dist/auth/login-form/parts.js +371 -0
- package/dist/auth/looks/auth-illustration-any.d.ts +16 -0
- package/dist/auth/looks/auth-illustration-any.js +24 -0
- package/dist/auth/looks/index.d.ts +1 -0
- package/dist/auth/looks/index.js +1 -0
- package/dist/auth/mosaic/index.d.ts +1 -0
- package/dist/auth/mosaic/index.js +1 -0
- package/dist/auth/mosaic/mosaic.d.ts +11 -0
- package/dist/auth/mosaic/mosaic.js +195 -0
- package/dist/auth/slabs/index.d.ts +1 -0
- package/dist/auth/slabs/index.js +1 -0
- package/dist/auth/slabs/slabs.d.ts +13 -0
- package/dist/auth/slabs/slabs.js +136 -0
- package/dist/auth/stack/index.d.ts +1 -0
- package/dist/auth/stack/index.js +1 -0
- package/dist/auth/stack/stack.d.ts +6 -0
- package/dist/auth/stack/stack.js +222 -0
- package/dist/auth/statement/index.d.ts +1 -0
- package/dist/auth/statement/index.js +1 -0
- package/dist/auth/statement/statement.d.ts +13 -0
- package/dist/auth/statement/statement.js +99 -0
- 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 +101 -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 +109 -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 +28 -2
- package/dist/containers/responsive-list/responsive-list.js +134 -25
- 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 +4 -0
- package/dist/forms/index.js +4 -0
- package/dist/forms/input/input.d.ts +6 -2
- package/dist/forms/input/input.js +6 -2
- 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/password-input/index.d.ts +1 -0
- package/dist/forms/password-input/index.js +1 -0
- package/dist/forms/password-input/password-input.d.ts +16 -0
- package/dist/forms/password-input/password-input.js +45 -0
- 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 +150 -0
- package/dist/i18n/strings.js +80 -2
- package/dist/icons/eye.d.ts +2 -0
- package/dist/icons/eye.js +11 -0
- package/dist/icons/graduation-cap.d.ts +2 -0
- package/dist/icons/graduation-cap.js +12 -0
- package/dist/icons/house.d.ts +2 -0
- package/dist/icons/house.js +11 -0
- package/dist/icons/index.d.ts +4 -0
- package/dist/icons/index.js +8 -0
- package/dist/icons/mail.d.ts +2 -0
- package/dist/icons/mail.js +11 -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.js +10 -2
- 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/toaster.d.ts +28 -2
- package/dist/overlays/toaster/toaster.js +73 -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.js +1 -1
- package/dist/utils/class-tokens.generated.js +4 -6
- 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/icons/svg/eye.svg +4 -0
- package/icons/svg/graduation-cap.svg +5 -0
- package/icons/svg/house.svg +4 -0
- package/icons/svg/mail.svg +4 -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/big-date/big-date.tsx +2 -2
- package/src/atoms/button/button.tsx +33 -6
- package/src/atoms/chip/chip.tsx +8 -3
- package/src/atoms/divider/divider.tsx +40 -0
- package/src/atoms/divider/index.ts +1 -0
- package/src/atoms/icon-button/icon-button.tsx +2 -2
- package/src/atoms/index.ts +1 -0
- 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/auth/auth-illustration/auth-illustration.tsx +100 -0
- package/src/auth/auth-illustration/index.ts +8 -0
- package/src/auth/auth-illustration/look.ts +32 -0
- package/src/auth/auth-illustration/model.ts +330 -0
- package/src/auth/auth-illustration/use-art-pointer.ts +78 -0
- package/src/auth/auth-layout/auth-layout.tsx +282 -0
- package/src/auth/auth-layout/index.ts +1 -0
- package/src/auth/character/character.tsx +346 -0
- package/src/auth/character/index.ts +1 -0
- package/src/auth/index.ts +4 -0
- package/src/auth/internal/auth-context.ts +26 -0
- package/src/auth/internal/auth-styles.tsx +39 -0
- package/src/auth/internal/portal-glyphs.tsx +32 -0
- package/src/auth/login-form/context.ts +78 -0
- package/src/auth/login-form/index.ts +21 -0
- package/src/auth/login-form/login-form.tsx +330 -0
- package/src/auth/login-form/parts.tsx +457 -0
- package/src/auth/looks/auth-illustration-any.tsx +38 -0
- package/src/auth/looks/index.ts +1 -0
- package/src/auth/mosaic/index.ts +1 -0
- package/src/auth/mosaic/mosaic.tsx +255 -0
- package/src/auth/slabs/index.ts +1 -0
- package/src/auth/slabs/slabs.tsx +181 -0
- package/src/auth/stack/index.ts +1 -0
- package/src/auth/stack/stack.tsx +267 -0
- package/src/auth/statement/index.ts +1 -0
- package/src/auth/statement/statement.tsx +122 -0
- 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 +146 -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 +157 -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 +183 -46
- 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 +4 -0
- package/src/forms/input/input.tsx +12 -3
- package/src/forms/internal/listbox-items.tsx +3 -4
- package/src/forms/native-select/native-select.tsx +1 -1
- package/src/forms/password-input/index.ts +1 -0
- package/src/forms/password-input/password-input.tsx +57 -0
- 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 +150 -0
- package/src/icons/eye.tsx +12 -0
- package/src/icons/graduation-cap.tsx +13 -0
- package/src/icons/house.tsx +12 -0
- package/src/icons/index.ts +4 -0
- package/src/icons/mail.tsx +12 -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 +7 -2
- 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/toaster.tsx +113 -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 +1 -1
- package/src/utils/class-tokens.generated.ts +4 -6
- 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,266 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { type ComponentPropsWithoutRef, 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
|
+
|
|
18
|
+
export {
|
|
19
|
+
clampPage,
|
|
20
|
+
formatPageRange,
|
|
21
|
+
formatRange,
|
|
22
|
+
type PageItem,
|
|
23
|
+
pageCount,
|
|
24
|
+
pageItems,
|
|
25
|
+
pageRange,
|
|
26
|
+
} from "./range.js";
|
|
27
|
+
|
|
28
|
+
export interface PaginationLabels {
|
|
29
|
+
nav: string;
|
|
30
|
+
rowsPerPage: string;
|
|
31
|
+
/** `{first}`, `{last}` and `{total}` are replaced. */
|
|
32
|
+
range: string;
|
|
33
|
+
first: string;
|
|
34
|
+
previous: string;
|
|
35
|
+
next: string;
|
|
36
|
+
last: string;
|
|
37
|
+
/** Range text of the `pages` variant; `{first}`, `{last}` and `{total}` are replaced. */
|
|
38
|
+
showing: string;
|
|
39
|
+
/** Visible label of the previous button of the `pages` variant. */
|
|
40
|
+
previousLabel: string;
|
|
41
|
+
/** Visible label of the next button of the `pages` variant. */
|
|
42
|
+
nextLabel: string;
|
|
43
|
+
/** Name of a page number button; `{page}` is replaced. */
|
|
44
|
+
pageNumber: string;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface PaginationProps extends Omit<ComponentPropsWithoutRef<"nav">, "onChange"> {
|
|
48
|
+
/** Total rows across every page. */
|
|
49
|
+
total: number;
|
|
50
|
+
/** Controlled 1-based page. Pair it with `onPageChange`. */
|
|
51
|
+
page?: number;
|
|
52
|
+
/** Initial page when uncontrolled. Default 1. */
|
|
53
|
+
defaultPage?: number;
|
|
54
|
+
onPageChange?: (page: number) => void;
|
|
55
|
+
/** Controlled rows per page. Pair it with `onPageSizeChange`. */
|
|
56
|
+
pageSize?: number;
|
|
57
|
+
/** Initial rows per page when uncontrolled. Default: the first of `pageSizeOptions`. */
|
|
58
|
+
defaultPageSize?: number;
|
|
59
|
+
onPageSizeChange?: (pageSize: number) => void;
|
|
60
|
+
/** Choices of the page size picker. Default `[10, 25, 50, 100]`; a single option hides the picker. */
|
|
61
|
+
pageSizeOptions?: readonly number[];
|
|
62
|
+
/** Texts (localized by default through `UiStrings`). */
|
|
63
|
+
labels?: Partial<PaginationLabels>;
|
|
64
|
+
/**
|
|
65
|
+
* `default`: rows per page, the range and first/previous/next/last icon buttons. `pages`: the
|
|
66
|
+
* range ("Showing 1–25 of 134") and Previous, page number and Next buttons; it shows the page size
|
|
67
|
+
* picker only when `pageSizeOptions` is passed with more than one option.
|
|
68
|
+
*/
|
|
69
|
+
variant?: "default" | "pages";
|
|
70
|
+
/** Renders nothing while every row fits on one page. Default `true` for `pages`, `false` otherwise. */
|
|
71
|
+
hideOnSinglePage?: boolean;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const DEFAULT_OPTIONS = [10, 25, 50, 100] as const;
|
|
75
|
+
|
|
76
|
+
const stepButton =
|
|
77
|
+
"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";
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Footer of a list or table: rows per page, the range shown ("11–20 of 134") and first, previous,
|
|
81
|
+
* next and last buttons. Pages are 1-based. It does not slice your rows: use `page` and `pageSize`
|
|
82
|
+
* to do that, or to request the page from your API. Changing the page size returns to page 1.
|
|
83
|
+
*/
|
|
84
|
+
export function Pagination({
|
|
85
|
+
total,
|
|
86
|
+
page,
|
|
87
|
+
defaultPage = 1,
|
|
88
|
+
onPageChange,
|
|
89
|
+
pageSize,
|
|
90
|
+
defaultPageSize,
|
|
91
|
+
onPageSizeChange,
|
|
92
|
+
pageSizeOptions: pageSizeOptionsProp,
|
|
93
|
+
labels,
|
|
94
|
+
variant = "default",
|
|
95
|
+
hideOnSinglePage = variant === "pages",
|
|
96
|
+
className,
|
|
97
|
+
...props
|
|
98
|
+
}: PaginationProps) {
|
|
99
|
+
const pageSizeOptions = pageSizeOptionsProp ?? DEFAULT_OPTIONS;
|
|
100
|
+
const strings = useUiStrings();
|
|
101
|
+
const selectId = useId();
|
|
102
|
+
const [size, setSize] = useControllableState<number>({
|
|
103
|
+
prop: pageSize,
|
|
104
|
+
defaultProp: defaultPageSize ?? pageSizeOptions[0] ?? DEFAULT_OPTIONS[0],
|
|
105
|
+
onChange: onPageSizeChange,
|
|
106
|
+
});
|
|
107
|
+
const [current, setPage] = useControllableState<number>({
|
|
108
|
+
prop: page,
|
|
109
|
+
defaultProp: defaultPage,
|
|
110
|
+
onChange: onPageChange,
|
|
111
|
+
});
|
|
112
|
+
const text: PaginationLabels = {
|
|
113
|
+
nav: labels?.nav ?? strings.pagination,
|
|
114
|
+
rowsPerPage: labels?.rowsPerPage ?? strings.rowsPerPage,
|
|
115
|
+
range: labels?.range ?? strings.pageRange,
|
|
116
|
+
first: labels?.first ?? strings.firstPage,
|
|
117
|
+
previous: labels?.previous ?? strings.previousPage,
|
|
118
|
+
next: labels?.next ?? strings.nextPage,
|
|
119
|
+
last: labels?.last ?? strings.lastPage,
|
|
120
|
+
showing: labels?.showing ?? strings.showingRange,
|
|
121
|
+
previousLabel: labels?.previousLabel ?? strings.previous,
|
|
122
|
+
nextLabel: labels?.nextLabel ?? strings.next,
|
|
123
|
+
pageNumber: labels?.pageNumber ?? strings.pageNumber,
|
|
124
|
+
};
|
|
125
|
+
const pages = pageCount(total, size);
|
|
126
|
+
const at = clampPage(current, pages);
|
|
127
|
+
const { first, last } = pageRange(at, size, total);
|
|
128
|
+
const format = useMemo(() => new Intl.NumberFormat(strings.locale), [strings.locale]);
|
|
129
|
+
const sizes = [...new Set([...pageSizeOptions, size])].sort((a, b) => a - b);
|
|
130
|
+
const atStart = at <= 1;
|
|
131
|
+
const atEnd = at >= pages;
|
|
132
|
+
if (hideOnSinglePage && pages <= 1) return null;
|
|
133
|
+
const picker =
|
|
134
|
+
sizes.length > 1 && (variant === "default" || pageSizeOptionsProp !== undefined) ? (
|
|
135
|
+
<span className="flex items-center gap-2">
|
|
136
|
+
<label htmlFor={selectId}>{text.rowsPerPage}</label>
|
|
137
|
+
<select
|
|
138
|
+
id={selectId}
|
|
139
|
+
value={size}
|
|
140
|
+
onChange={(event) => {
|
|
141
|
+
setSize(Number(event.target.value));
|
|
142
|
+
setPage(1);
|
|
143
|
+
}}
|
|
144
|
+
className="h-control-sm rounded-input border-control bg-surface-control px-1.5 text-fs-120 text-ink"
|
|
145
|
+
>
|
|
146
|
+
{sizes.map((option) => (
|
|
147
|
+
<option key={option} value={option}>
|
|
148
|
+
{option}
|
|
149
|
+
</option>
|
|
150
|
+
))}
|
|
151
|
+
</select>
|
|
152
|
+
</span>
|
|
153
|
+
) : null;
|
|
154
|
+
if (variant === "pages") {
|
|
155
|
+
return (
|
|
156
|
+
<nav
|
|
157
|
+
aria-label={text.nav}
|
|
158
|
+
className={cn(
|
|
159
|
+
"flex min-w-0 flex-wrap items-center justify-between gap-x-4 gap-y-2 py-2 text-fs-120 text-ink-2",
|
|
160
|
+
className,
|
|
161
|
+
)}
|
|
162
|
+
{...props}
|
|
163
|
+
>
|
|
164
|
+
<span aria-live="polite" className="tabular-nums">
|
|
165
|
+
{formatRange(text.showing, {
|
|
166
|
+
first: format.format(first),
|
|
167
|
+
last: format.format(last),
|
|
168
|
+
total: format.format(Math.max(0, total)),
|
|
169
|
+
})}
|
|
170
|
+
</span>
|
|
171
|
+
<span className="flex flex-wrap items-center gap-x-4 gap-y-2">
|
|
172
|
+
{picker}
|
|
173
|
+
<span className="flex items-center gap-1">
|
|
174
|
+
<Button size="sm" disabled={atStart} onClick={() => setPage(at - 1)}>
|
|
175
|
+
{text.previousLabel}
|
|
176
|
+
</Button>
|
|
177
|
+
{pageItems(at, pages).map((item, index) =>
|
|
178
|
+
item === "gap" ? (
|
|
179
|
+
<span
|
|
180
|
+
// biome-ignore lint/suspicious/noArrayIndexKey: a gap has no identity besides its slot
|
|
181
|
+
key={`gap-${index}`}
|
|
182
|
+
aria-hidden="true"
|
|
183
|
+
className="w-6 text-center text-ink-3"
|
|
184
|
+
>
|
|
185
|
+
…
|
|
186
|
+
</span>
|
|
187
|
+
) : (
|
|
188
|
+
<Button
|
|
189
|
+
key={item}
|
|
190
|
+
size="sm"
|
|
191
|
+
variant={item === at ? "secondary" : "ghost"}
|
|
192
|
+
aria-current={item === at ? "page" : undefined}
|
|
193
|
+
aria-label={text.pageNumber.replace("{page}", String(item))}
|
|
194
|
+
onClick={() => setPage(item)}
|
|
195
|
+
className="min-w-control-sm px-2 tabular-nums"
|
|
196
|
+
>
|
|
197
|
+
{format.format(item)}
|
|
198
|
+
</Button>
|
|
199
|
+
),
|
|
200
|
+
)}
|
|
201
|
+
<Button size="sm" disabled={atEnd} onClick={() => setPage(at + 1)}>
|
|
202
|
+
{text.nextLabel}
|
|
203
|
+
</Button>
|
|
204
|
+
</span>
|
|
205
|
+
</span>
|
|
206
|
+
</nav>
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
return (
|
|
210
|
+
<nav
|
|
211
|
+
aria-label={text.nav}
|
|
212
|
+
className={cn(
|
|
213
|
+
"@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",
|
|
214
|
+
className,
|
|
215
|
+
)}
|
|
216
|
+
{...props}
|
|
217
|
+
>
|
|
218
|
+
{picker}
|
|
219
|
+
<span aria-live="polite" className="tabular-nums">
|
|
220
|
+
{formatPageRange(text.range, {
|
|
221
|
+
first: format.format(first),
|
|
222
|
+
last: format.format(last),
|
|
223
|
+
total: format.format(Math.max(0, total)),
|
|
224
|
+
})}
|
|
225
|
+
</span>
|
|
226
|
+
<span className="flex items-center">
|
|
227
|
+
<button
|
|
228
|
+
type="button"
|
|
229
|
+
className={stepButton}
|
|
230
|
+
aria-label={text.first}
|
|
231
|
+
disabled={atStart}
|
|
232
|
+
onClick={() => setPage(1)}
|
|
233
|
+
>
|
|
234
|
+
<ChevronsLeft aria-hidden="true" />
|
|
235
|
+
</button>
|
|
236
|
+
<button
|
|
237
|
+
type="button"
|
|
238
|
+
className={stepButton}
|
|
239
|
+
aria-label={text.previous}
|
|
240
|
+
disabled={atStart}
|
|
241
|
+
onClick={() => setPage(at - 1)}
|
|
242
|
+
>
|
|
243
|
+
<ChevronLeft aria-hidden="true" />
|
|
244
|
+
</button>
|
|
245
|
+
<button
|
|
246
|
+
type="button"
|
|
247
|
+
className={stepButton}
|
|
248
|
+
aria-label={text.next}
|
|
249
|
+
disabled={atEnd}
|
|
250
|
+
onClick={() => setPage(at + 1)}
|
|
251
|
+
>
|
|
252
|
+
<ChevronRight aria-hidden="true" />
|
|
253
|
+
</button>
|
|
254
|
+
<button
|
|
255
|
+
type="button"
|
|
256
|
+
className={stepButton}
|
|
257
|
+
aria-label={text.last}
|
|
258
|
+
disabled={atEnd}
|
|
259
|
+
onClick={() => setPage(pages)}
|
|
260
|
+
>
|
|
261
|
+
<ChevronsRight aria-hidden="true" />
|
|
262
|
+
</button>
|
|
263
|
+
</span>
|
|
264
|
+
</nav>
|
|
265
|
+
);
|
|
266
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/** Number of pages for `total` rows; at least 1 so an empty list still has a first page. */
|
|
2
|
+
export function pageCount(total: number, pageSize: number): number {
|
|
3
|
+
if (pageSize <= 0) return 1;
|
|
4
|
+
return Math.max(1, Math.ceil(Math.max(0, total) / pageSize));
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
/** Keeps a 1-based page inside `1..pages`. */
|
|
8
|
+
export function clampPage(page: number, pages: number): number {
|
|
9
|
+
return Math.min(Math.max(1, Math.trunc(page) || 1), pages);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** 1-based first and last row shown on `page`; `{ first: 0, last: 0 }` when there are no rows. */
|
|
13
|
+
export function pageRange(
|
|
14
|
+
page: number,
|
|
15
|
+
pageSize: number,
|
|
16
|
+
total: number,
|
|
17
|
+
): { first: number; last: number } {
|
|
18
|
+
if (total <= 0 || pageSize <= 0) return { first: 0, last: 0 };
|
|
19
|
+
const current = clampPage(page, pageCount(total, pageSize));
|
|
20
|
+
return { first: (current - 1) * pageSize + 1, last: Math.min(total, current * pageSize) };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Fills the `{first}`, `{last}` and `{total}` placeholders of the `pageRange` UI string. */
|
|
24
|
+
export function formatPageRange(
|
|
25
|
+
template: string,
|
|
26
|
+
values: { first: string; last: string; total: string },
|
|
27
|
+
): string {
|
|
28
|
+
return template
|
|
29
|
+
.replace("{first}", values.first)
|
|
30
|
+
.replace("{last}", values.last)
|
|
31
|
+
.replace("{total}", values.total);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** A page number button, or a gap between two runs of them. */
|
|
35
|
+
export type PageItem = number | "gap";
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* The page buttons to show: the first and last page, the current one with `siblings` on each side,
|
|
39
|
+
* and a `"gap"` where pages are left out. A gap never hides a single page (that page shows instead),
|
|
40
|
+
* so the list keeps the same length while the current page moves through the middle.
|
|
41
|
+
*/
|
|
42
|
+
export function pageItems(page: number, pages: number, siblings = 1): PageItem[] {
|
|
43
|
+
const total = Math.max(1, Math.trunc(pages));
|
|
44
|
+
const current = clampPage(page, total);
|
|
45
|
+
const slots = siblings * 2 + 5;
|
|
46
|
+
if (total <= slots) return Array.from({ length: total }, (_, i) => i + 1);
|
|
47
|
+
const start = Math.max(Math.min(current - siblings, total - siblings * 2 - 2), 3);
|
|
48
|
+
const end = Math.min(Math.max(current + siblings, siblings * 2 + 3), total - 2);
|
|
49
|
+
const middle = Array.from({ length: end - start + 1 }, (_, i) => start + i);
|
|
50
|
+
return [
|
|
51
|
+
1,
|
|
52
|
+
start > 3 ? ("gap" as const) : 2,
|
|
53
|
+
...middle,
|
|
54
|
+
end < total - 2 ? ("gap" as const) : total - 1,
|
|
55
|
+
total,
|
|
56
|
+
];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** Fills `{first}` and `{last}` (and `{total}` when given) in a range template. */
|
|
60
|
+
export function formatRange(
|
|
61
|
+
template: string,
|
|
62
|
+
values: { first: string; last: string; total?: string },
|
|
63
|
+
): string {
|
|
64
|
+
return template
|
|
65
|
+
.replace("{first}", values.first)
|
|
66
|
+
.replace("{last}", values.last)
|
|
67
|
+
.replace("{total}", values.total ?? "");
|
|
68
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useMemo, useState } from "react";
|
|
4
|
+
import { clampPage, pageCount } from "./range.js";
|
|
5
|
+
|
|
6
|
+
export interface PaginationState<T> {
|
|
7
|
+
/** Current 1-based page, always inside `1..pageCount`. */
|
|
8
|
+
page: number;
|
|
9
|
+
pageCount: number;
|
|
10
|
+
/** Rows across every page. */
|
|
11
|
+
total: number;
|
|
12
|
+
pageSize: number;
|
|
13
|
+
/** The rows of the current page. */
|
|
14
|
+
items: readonly T[];
|
|
15
|
+
setPage: (page: number) => void;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Client-side paging over an already filtered and sorted list. The page is clamped, so a search
|
|
20
|
+
* that shrinks the list lands on the last page that still exists instead of an empty one, and it
|
|
21
|
+
* returns to the first page whenever `resetKey` changes (the search text, a filter, the sort).
|
|
22
|
+
* Pair it with `<Pagination variant="pages">`.
|
|
23
|
+
*/
|
|
24
|
+
export function usePagination<T>(
|
|
25
|
+
rows: readonly T[],
|
|
26
|
+
resetKey: unknown = "",
|
|
27
|
+
pageSize = 25,
|
|
28
|
+
): PaginationState<T> {
|
|
29
|
+
const [requested, setPage] = useState(1);
|
|
30
|
+
const [key, setKey] = useState(resetKey);
|
|
31
|
+
// Reset during render rather than in an effect, so the first page shows without a stale frame.
|
|
32
|
+
if (!Object.is(key, resetKey)) {
|
|
33
|
+
setKey(resetKey);
|
|
34
|
+
setPage(1);
|
|
35
|
+
}
|
|
36
|
+
const total = rows.length;
|
|
37
|
+
const pages = pageCount(total, pageSize);
|
|
38
|
+
const page = Object.is(key, resetKey) ? clampPage(requested, pages) : 1;
|
|
39
|
+
const items = useMemo(
|
|
40
|
+
() => rows.slice((page - 1) * pageSize, page * pageSize),
|
|
41
|
+
[rows, page, pageSize],
|
|
42
|
+
);
|
|
43
|
+
return { page, pageCount: pages, total, pageSize, items, setPage };
|
|
44
|
+
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import type { ReactNode } from "react";
|
|
3
|
+
import type { KeyboardEvent, MouseEvent, ReactNode } from "react";
|
|
4
4
|
import { useUiStrings } from "../../i18n/index.js";
|
|
5
5
|
import type { ClassNames } from "../../utils/class-names.js";
|
|
6
6
|
import { cn } from "../../utils/cn.js";
|
|
7
|
+
import { focusRowByKey } from "../../utils/list-navigation.js";
|
|
7
8
|
import {
|
|
8
9
|
Table,
|
|
9
10
|
TableBody,
|
|
@@ -13,6 +14,36 @@ import {
|
|
|
13
14
|
TableRow,
|
|
14
15
|
} from "../table/table.js";
|
|
15
16
|
|
|
17
|
+
/** Container widths (px) from which `layout="auto"` shows the table. The set is closed so every query is a literal class. */
|
|
18
|
+
export type ResponsiveListBreakpoint = 480 | 640 | 672 | 768 | 960 | 1280;
|
|
19
|
+
|
|
20
|
+
const tableClasses: Record<ResponsiveListBreakpoint, { table: string; cards: string }> = {
|
|
21
|
+
480: {
|
|
22
|
+
table: "hidden @min-[480px]/responsive-list:block",
|
|
23
|
+
cards: "@min-[480px]/responsive-list:hidden",
|
|
24
|
+
},
|
|
25
|
+
640: {
|
|
26
|
+
table: "hidden @min-[640px]/responsive-list:block",
|
|
27
|
+
cards: "@min-[640px]/responsive-list:hidden",
|
|
28
|
+
},
|
|
29
|
+
672: {
|
|
30
|
+
table: "hidden @min-[42rem]/responsive-list:block",
|
|
31
|
+
cards: "@min-[42rem]/responsive-list:hidden",
|
|
32
|
+
},
|
|
33
|
+
768: {
|
|
34
|
+
table: "hidden @min-[768px]/responsive-list:block",
|
|
35
|
+
cards: "@min-[768px]/responsive-list:hidden",
|
|
36
|
+
},
|
|
37
|
+
960: {
|
|
38
|
+
table: "hidden @min-[960px]/responsive-list:block",
|
|
39
|
+
cards: "@min-[960px]/responsive-list:hidden",
|
|
40
|
+
},
|
|
41
|
+
1280: {
|
|
42
|
+
table: "hidden @min-[1280px]/responsive-list:block",
|
|
43
|
+
cards: "@min-[1280px]/responsive-list:hidden",
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
|
|
16
47
|
export interface ResponsiveListColumn<T> {
|
|
17
48
|
key: string;
|
|
18
49
|
header: string;
|
|
@@ -45,12 +76,36 @@ export interface ResponsiveListProps<T> {
|
|
|
45
76
|
/** Header of the actions column. Defaults to the localized "Actions". */
|
|
46
77
|
actionsHeader?: string;
|
|
47
78
|
rowClassName?: (item: T) => string | undefined;
|
|
79
|
+
/**
|
|
80
|
+
* `"auto"` (default) is a table from `breakpoint` of the list's own container width up and cards
|
|
81
|
+
* below it. `"cards"` always renders the cards, for a list that sits in a narrow pane (a master
|
|
82
|
+
* list next to its detail).
|
|
83
|
+
*/
|
|
84
|
+
layout?: "auto" | "cards";
|
|
85
|
+
/** Container width (px) from which `layout="auto"` shows the table. Defaults to 672 (42rem). */
|
|
86
|
+
breakpoint?: ResponsiveListBreakpoint;
|
|
87
|
+
/**
|
|
88
|
+
* `"visible"` (default) shows each field label in the cards. `"hidden"` keeps them for screen
|
|
89
|
+
* readers only, for cards whose values explain themselves (a price, a status).
|
|
90
|
+
*/
|
|
91
|
+
cardLabels?: "visible" | "hidden";
|
|
92
|
+
/** Key of the selected row, or `null`/`undefined` for none. Only used together with `onSelect`. */
|
|
93
|
+
selectedKey?: string | null;
|
|
94
|
+
/**
|
|
95
|
+
* Makes rows selectable (click, Enter or Space) and adds keyboard navigation (arrows, Home, End).
|
|
96
|
+
* Without `renderActions` the cards are a `listbox` of `option`s and the table a `grid` whose
|
|
97
|
+
* rows carry `aria-selected`; with it the rows keep plain list/table semantics and the selected
|
|
98
|
+
* one gets `aria-current="true"`, because actions cannot live inside an option.
|
|
99
|
+
*/
|
|
100
|
+
onSelect?: (key: string, item: T) => void;
|
|
101
|
+
/** Arrow keys select the row they land on, not only move focus. Off by default. */
|
|
102
|
+
selectOnFocus?: boolean;
|
|
48
103
|
className?: string;
|
|
49
104
|
/** Per-part classes merged with `cn`; consumer classes win. `className` still targets the root and is merged last. */
|
|
50
105
|
classNames?: ClassNames<ResponsiveListPart>;
|
|
51
106
|
}
|
|
52
107
|
|
|
53
|
-
/** A table
|
|
108
|
+
/** A table from `breakpoint` of its own width up and a stack of cards below it, from one column definition. */
|
|
54
109
|
export function ResponsiveList<T>({
|
|
55
110
|
caption,
|
|
56
111
|
items,
|
|
@@ -59,65 +114,136 @@ export function ResponsiveList<T>({
|
|
|
59
114
|
renderActions,
|
|
60
115
|
actionsHeader,
|
|
61
116
|
rowClassName,
|
|
117
|
+
layout = "auto",
|
|
118
|
+
breakpoint = 672,
|
|
119
|
+
cardLabels = "visible",
|
|
120
|
+
selectedKey,
|
|
121
|
+
onSelect,
|
|
122
|
+
selectOnFocus = false,
|
|
62
123
|
className,
|
|
63
124
|
classNames,
|
|
64
125
|
}: ResponsiveListProps<T>) {
|
|
65
126
|
const strings = useUiStrings();
|
|
66
127
|
const primary = columns.find((column) => column.primary) ?? columns[0];
|
|
67
128
|
const details = columns.filter((column) => column !== primary);
|
|
129
|
+
const selectable = onSelect !== undefined;
|
|
130
|
+
const listbox = selectable && !renderActions;
|
|
131
|
+
const firstKey = items[0] ? rowKey(items[0]) : undefined;
|
|
132
|
+
const stopKey =
|
|
133
|
+
selectedKey != null && items.some((item) => rowKey(item) === selectedKey)
|
|
134
|
+
? selectedKey
|
|
135
|
+
: firstKey;
|
|
136
|
+
|
|
137
|
+
const rowProps = (item: T, kind: "grid" | "card") => {
|
|
138
|
+
if (!selectable) return {};
|
|
139
|
+
const key = rowKey(item);
|
|
140
|
+
const selected = key === selectedKey;
|
|
141
|
+
const select = () => onSelect(key, item);
|
|
142
|
+
return {
|
|
143
|
+
tabIndex: key === stopKey ? 0 : -1,
|
|
144
|
+
"data-selected": selected ? "true" : undefined,
|
|
145
|
+
...(kind === "grid" || listbox
|
|
146
|
+
? { "aria-selected": selected }
|
|
147
|
+
: { "aria-current": selected ? ("true" as const) : undefined }),
|
|
148
|
+
...(kind === "card" && listbox ? { role: "option" as const } : {}),
|
|
149
|
+
onClick: (event: MouseEvent<HTMLElement>) => {
|
|
150
|
+
if (
|
|
151
|
+
(event.target as HTMLElement).closest(
|
|
152
|
+
"a, button, input, select, textarea, [data-row-actions]",
|
|
153
|
+
)
|
|
154
|
+
)
|
|
155
|
+
return;
|
|
156
|
+
select();
|
|
157
|
+
},
|
|
158
|
+
onKeyDown: (event: KeyboardEvent<HTMLElement>) => {
|
|
159
|
+
if (event.target !== event.currentTarget) return;
|
|
160
|
+
if (event.key === "Enter" || event.key === " ") {
|
|
161
|
+
event.preventDefault();
|
|
162
|
+
select();
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
const scope = event.currentTarget.closest("[data-row-scope]");
|
|
166
|
+
if (!scope || event.altKey || event.ctrlKey || event.metaKey) return;
|
|
167
|
+
const row = focusRowByKey(scope, event.currentTarget, event.key);
|
|
168
|
+
if (!row) return;
|
|
169
|
+
event.preventDefault();
|
|
170
|
+
if (selectOnFocus) {
|
|
171
|
+
const nextKey = row.getAttribute("data-row-key");
|
|
172
|
+
const next = items.find((candidate) => rowKey(candidate) === nextKey);
|
|
173
|
+
if (next) onSelect(rowKey(next), next);
|
|
174
|
+
}
|
|
175
|
+
},
|
|
176
|
+
};
|
|
177
|
+
};
|
|
68
178
|
|
|
69
179
|
return (
|
|
70
180
|
<div className={cn("@container/responsive-list min-w-0", classNames?.root, className)}>
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
<
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
))}
|
|
86
|
-
{renderActions ? (
|
|
87
|
-
<TableHeaderCell scope="col" alignRight>
|
|
88
|
-
{actionsHeader ?? strings.actions}
|
|
89
|
-
</TableHeaderCell>
|
|
90
|
-
) : null}
|
|
91
|
-
</TableRow>
|
|
92
|
-
</TableHead>
|
|
93
|
-
<TableBody>
|
|
94
|
-
{items.map((item) => (
|
|
95
|
-
<TableRow
|
|
96
|
-
key={rowKey(item)}
|
|
97
|
-
data-row-key={rowKey(item)}
|
|
98
|
-
className={rowClassName?.(item)}
|
|
99
|
-
>
|
|
181
|
+
{layout === "auto" ? (
|
|
182
|
+
<div
|
|
183
|
+
className={cn(
|
|
184
|
+
"rounded-card border-card shadow-card surface-card",
|
|
185
|
+
tableClasses[breakpoint].table,
|
|
186
|
+
classNames?.tableWrapper,
|
|
187
|
+
)}
|
|
188
|
+
>
|
|
189
|
+
<Table
|
|
190
|
+
{...(selectable ? { role: "grid", "aria-label": caption, "data-row-scope": "" } : {})}
|
|
191
|
+
>
|
|
192
|
+
<caption className="sr-only">{caption}</caption>
|
|
193
|
+
<TableHead>
|
|
194
|
+
<TableRow className="hover:bg-transparent">
|
|
100
195
|
{columns.map((column) => (
|
|
101
|
-
<
|
|
102
|
-
{column.
|
|
103
|
-
</
|
|
196
|
+
<TableHeaderCell key={column.key} scope="col" alignRight={column.align === "end"}>
|
|
197
|
+
{column.header}
|
|
198
|
+
</TableHeaderCell>
|
|
104
199
|
))}
|
|
105
200
|
{renderActions ? (
|
|
106
|
-
<
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
</div>
|
|
110
|
-
</TableCell>
|
|
201
|
+
<TableHeaderCell scope="col" alignRight>
|
|
202
|
+
{actionsHeader ?? strings.actions}
|
|
203
|
+
</TableHeaderCell>
|
|
111
204
|
) : null}
|
|
112
205
|
</TableRow>
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
206
|
+
</TableHead>
|
|
207
|
+
<TableBody>
|
|
208
|
+
{items.map((item) => (
|
|
209
|
+
<TableRow
|
|
210
|
+
key={rowKey(item)}
|
|
211
|
+
data-row-key={rowKey(item)}
|
|
212
|
+
className={cn(
|
|
213
|
+
rowClassName?.(item),
|
|
214
|
+
selectable &&
|
|
215
|
+
"cursor-pointer focus-visible:focus-ring data-[selected=true]:bg-accent-soft",
|
|
216
|
+
)}
|
|
217
|
+
{...rowProps(item, "grid")}
|
|
218
|
+
>
|
|
219
|
+
{columns.map((column) => (
|
|
220
|
+
<TableCell key={column.key} alignRight={column.align === "end"}>
|
|
221
|
+
{column.cell(item)}
|
|
222
|
+
</TableCell>
|
|
223
|
+
))}
|
|
224
|
+
{renderActions ? (
|
|
225
|
+
<TableCell alignRight>
|
|
226
|
+
<div
|
|
227
|
+
data-row-actions=""
|
|
228
|
+
className={cn("flex flex-wrap justify-end gap-2", classNames?.actions)}
|
|
229
|
+
>
|
|
230
|
+
{renderActions(item)}
|
|
231
|
+
</div>
|
|
232
|
+
</TableCell>
|
|
233
|
+
) : null}
|
|
234
|
+
</TableRow>
|
|
235
|
+
))}
|
|
236
|
+
</TableBody>
|
|
237
|
+
</Table>
|
|
238
|
+
</div>
|
|
239
|
+
) : null}
|
|
117
240
|
<ul
|
|
118
241
|
aria-label={caption}
|
|
242
|
+
{...(listbox ? { role: "listbox" } : {})}
|
|
243
|
+
{...(selectable ? { "data-row-scope": "" } : {})}
|
|
119
244
|
className={cn(
|
|
120
|
-
"m-0 flex list-none flex-col gap-density p-0
|
|
245
|
+
"m-0 flex list-none flex-col gap-density p-0",
|
|
246
|
+
layout === "auto" && tableClasses[breakpoint].cards,
|
|
121
247
|
classNames?.cards,
|
|
122
248
|
)}
|
|
123
249
|
>
|
|
@@ -127,9 +253,12 @@ export function ResponsiveList<T>({
|
|
|
127
253
|
data-row-key={rowKey(item)}
|
|
128
254
|
className={cn(
|
|
129
255
|
"flex min-w-0 flex-col gap-3 rounded-card border-card p-card shadow-card surface-card",
|
|
256
|
+
selectable &&
|
|
257
|
+
"cursor-pointer focus-visible:focus-ring data-[selected=true]:bg-accent-soft data-[selected=true]:shadow-selected",
|
|
130
258
|
rowClassName?.(item),
|
|
131
259
|
classNames?.card,
|
|
132
260
|
)}
|
|
261
|
+
{...rowProps(item, "card")}
|
|
133
262
|
>
|
|
134
263
|
<div
|
|
135
264
|
className={cn(
|
|
@@ -146,15 +275,23 @@ export function ResponsiveList<T>({
|
|
|
146
275
|
key={column.key}
|
|
147
276
|
className={cn(
|
|
148
277
|
"flex items-baseline justify-between gap-4",
|
|
278
|
+
cardLabels === "hidden" && "justify-start",
|
|
149
279
|
classNames?.cardDetail,
|
|
150
280
|
)}
|
|
151
281
|
>
|
|
152
|
-
<dt
|
|
282
|
+
<dt
|
|
283
|
+
className={cn(
|
|
284
|
+
"shrink-0 text-ink-3 text-meta",
|
|
285
|
+
cardLabels === "hidden" && "sr-only",
|
|
286
|
+
classNames?.cardLabel,
|
|
287
|
+
)}
|
|
288
|
+
>
|
|
153
289
|
{column.header}
|
|
154
290
|
</dt>
|
|
155
291
|
<dd
|
|
156
292
|
className={cn(
|
|
157
293
|
"m-0 min-w-0 text-right text-body text-ink [overflow-wrap:anywhere]",
|
|
294
|
+
cardLabels === "hidden" && "text-left",
|
|
158
295
|
classNames?.cardValue,
|
|
159
296
|
)}
|
|
160
297
|
>
|
|
@@ -165,7 +302,7 @@ export function ResponsiveList<T>({
|
|
|
165
302
|
</dl>
|
|
166
303
|
) : null}
|
|
167
304
|
{renderActions ? (
|
|
168
|
-
<div className={cn("flex flex-wrap gap-2", classNames?.actions)}>
|
|
305
|
+
<div data-row-actions="" className={cn("flex flex-wrap gap-2", classNames?.actions)}>
|
|
169
306
|
{renderActions(item)}
|
|
170
307
|
</div>
|
|
171
308
|
) : null}
|