@jcsoftdev/ui 0.5.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 +337 -0
- package/README.md +25 -3
- 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 +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 +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 +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/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 +86 -0
- package/dist/i18n/strings.js +46 -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/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 +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 +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 +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/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 +86 -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,63 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { type AnimationEvent, type Key, useCallback, useEffect, useRef, useState } from "react";
|
|
4
|
+
import { usePrefersReducedMotion } from "../utils/reduced-motion.js";
|
|
5
|
+
|
|
6
|
+
type Pulse = "a" | "b";
|
|
7
|
+
|
|
8
|
+
/** Props for a highlighted row: spread them on the row element (`tr`, `li`, `div`). */
|
|
9
|
+
export interface HighlightRowProps {
|
|
10
|
+
"data-motion-pulse"?: Pulse;
|
|
11
|
+
onAnimationEnd: (event: AnimationEvent<HTMLElement>) => void;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface HighlightRow<K extends Key> {
|
|
15
|
+
/** Pulses the row with this key, e.g. after it was updated. Calling it again restarts the pulse. */
|
|
16
|
+
highlight: (key: K) => void;
|
|
17
|
+
/** Props for the row with this key. Render `<MotionStyles />` or any motion component once on the page. */
|
|
18
|
+
rowProps: (key: K) => HighlightRowProps;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* A brief background pulse (accent tint fading out over 1.6 `--motion-duration`s) on rows that
|
|
23
|
+
* were inserted or updated. Pass the current row keys to pulse every key that appears after the
|
|
24
|
+
* first render automatically; call `highlight(key)` for updates. The rows on the first render
|
|
25
|
+
* (and in server HTML) never pulse, and under reduced motion nothing pulses.
|
|
26
|
+
* In a `tr` the cells carry the pulse, so it shows through cell backgrounds.
|
|
27
|
+
*/
|
|
28
|
+
export function useHighlightRow<K extends Key>(keys?: readonly K[]): HighlightRow<K> {
|
|
29
|
+
const reduced = usePrefersReducedMotion();
|
|
30
|
+
const [pulses, setPulses] = useState<ReadonlyMap<K, Pulse>>(() => new Map());
|
|
31
|
+
const known = useRef<ReadonlySet<K> | null>(null);
|
|
32
|
+
|
|
33
|
+
const highlight = useCallback(
|
|
34
|
+
(key: K) => {
|
|
35
|
+
if (reduced) return;
|
|
36
|
+
setPulses((map) => new Map(map).set(key, map.get(key) === "a" ? "b" : "a"));
|
|
37
|
+
},
|
|
38
|
+
[reduced],
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
if (!keys) return;
|
|
43
|
+
const previous = known.current;
|
|
44
|
+
known.current = new Set(keys);
|
|
45
|
+
if (!previous) return;
|
|
46
|
+
for (const key of keys) if (!previous.has(key)) highlight(key);
|
|
47
|
+
}, [keys, highlight]);
|
|
48
|
+
|
|
49
|
+
const rowProps = (key: K): HighlightRowProps => ({
|
|
50
|
+
"data-motion-pulse": pulses.get(key),
|
|
51
|
+
onAnimationEnd: (event) => {
|
|
52
|
+
if (!event.animationName.startsWith("ui-motion-pulse")) return;
|
|
53
|
+
setPulses((map) => {
|
|
54
|
+
if (!map.has(key)) return map;
|
|
55
|
+
const next = new Map(map);
|
|
56
|
+
next.delete(key);
|
|
57
|
+
return next;
|
|
58
|
+
});
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
return { highlight, rowProps };
|
|
63
|
+
}
|
|
@@ -176,7 +176,7 @@ export function TabsTrigger({
|
|
|
176
176
|
}
|
|
177
177
|
})}
|
|
178
178
|
className={cn(
|
|
179
|
-
"inline-flex shrink-0 cursor-pointer items-center gap-1.5 whitespace-nowrap border-b-2 border-transparent px-2.5 @max-[420px]/tabs:px-2 pt-2.75 pb-2.5 text-control text-ink-3 hover:text-ink focus-visible:-outline-offset-2 data-[state=active]:border-accent-word data-[state=active]:text-ink",
|
|
179
|
+
"inline-flex min-h-(--touch-target) shrink-0 cursor-pointer items-center gap-1.5 whitespace-nowrap border-b-2 border-transparent px-2.5 @max-[420px]/tabs:px-2 pt-2.75 pb-2.5 text-control text-ink-3 hover:text-ink focus-visible:-outline-offset-2 data-[state=active]:border-accent-word data-[state=active]:text-ink",
|
|
180
180
|
className,
|
|
181
181
|
)}
|
|
182
182
|
>
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
useRef,
|
|
9
9
|
useState,
|
|
10
10
|
} from "react";
|
|
11
|
-
import { Button } from "../../atoms/button/button.js";
|
|
11
|
+
import { Button, type ButtonSize } from "../../atoms/button/button.js";
|
|
12
12
|
import { useUiStrings } from "../../i18n/index.js";
|
|
13
13
|
import type { ClassNames } from "../../utils/class-names.js";
|
|
14
14
|
import { cn } from "../../utils/cn.js";
|
|
@@ -59,6 +59,8 @@ export interface WizardProps
|
|
|
59
59
|
backLabel?: string | undefined;
|
|
60
60
|
nextLabel?: string | undefined;
|
|
61
61
|
finishLabel?: string | undefined;
|
|
62
|
+
/** Size of the Back and Next/Finish buttons. Default `md` (38px, the height of a default field). */
|
|
63
|
+
buttonSize?: ButtonSize | undefined;
|
|
62
64
|
/** Per-part classes merged with `cn`; consumer classes win. `className` still targets the root. */
|
|
63
65
|
classNames?: ClassNames<WizardPart>;
|
|
64
66
|
}
|
|
@@ -79,6 +81,7 @@ export function Wizard({
|
|
|
79
81
|
onComplete,
|
|
80
82
|
backLabel,
|
|
81
83
|
nextLabel,
|
|
84
|
+
buttonSize = "md",
|
|
82
85
|
finishLabel,
|
|
83
86
|
className,
|
|
84
87
|
classNames,
|
|
@@ -200,6 +203,7 @@ export function Wizard({
|
|
|
200
203
|
>
|
|
201
204
|
<Button
|
|
202
205
|
variant="secondary"
|
|
206
|
+
size={buttonSize}
|
|
203
207
|
disabled={index === 0 || pending !== null}
|
|
204
208
|
onClick={() => goTo(index - 1)}
|
|
205
209
|
className={classNames?.back}
|
|
@@ -208,6 +212,7 @@ export function Wizard({
|
|
|
208
212
|
</Button>
|
|
209
213
|
<Button
|
|
210
214
|
variant="primary"
|
|
215
|
+
size={buttonSize}
|
|
211
216
|
loading={pending !== null}
|
|
212
217
|
loadingLabel={strings.processing}
|
|
213
218
|
disabled={blocked}
|
|
@@ -20,6 +20,7 @@ import * as DialogPrimitive from "../../primitives/dialog/dialog.js";
|
|
|
20
20
|
import type { ClassNames } from "../../utils/class-names.js";
|
|
21
21
|
import { cn } from "../../utils/cn.js";
|
|
22
22
|
import { type Material, materialClass } from "../../utils/material.js";
|
|
23
|
+
import { DIALOG_MOTION, OVERLAY_MOTION } from "../../utils/overlay-motion.js";
|
|
23
24
|
import { useControllableState } from "../../utils/use-controllable-state.js";
|
|
24
25
|
import {
|
|
25
26
|
PreviousFocusProvider,
|
|
@@ -278,7 +279,9 @@ function AlertDialogPanel({
|
|
|
278
279
|
const previousFocusRef = usePreviousFocus();
|
|
279
280
|
return (
|
|
280
281
|
<DialogPrimitive.Portal container={container}>
|
|
281
|
-
<DialogPrimitive.Overlay
|
|
282
|
+
<DialogPrimitive.Overlay
|
|
283
|
+
className={cn("fixed inset-0 z-70 bg-scrim", OVERLAY_MOTION, classNames?.overlay)}
|
|
284
|
+
/>
|
|
282
285
|
<DialogPrimitive.Content
|
|
283
286
|
ref={panelRef}
|
|
284
287
|
role="alertdialog"
|
|
@@ -290,6 +293,7 @@ function AlertDialogPanel({
|
|
|
290
293
|
onCloseAutoFocus={(event) => restoreFocusOnClose(event, previousFocusRef)}
|
|
291
294
|
className={cn(
|
|
292
295
|
"@container/dialog fixed top-[9dvh] left-1/2 z-70 flex max-h-[84dvh] w-[min(420px,100%)] max-w-full -translate-x-1/2 flex-col overflow-auto rounded-dialog outline-none surface-overlay shadow-overlay",
|
|
296
|
+
DIALOG_MOTION,
|
|
293
297
|
materialClass(material, "surface-solid"),
|
|
294
298
|
classNames?.root,
|
|
295
299
|
className,
|
|
@@ -18,6 +18,7 @@ import { Check } from "../../icons/index.js";
|
|
|
18
18
|
import * as MenuPrimitive from "../../primitives/menu/menu.js";
|
|
19
19
|
import { cn } from "../../utils/cn.js";
|
|
20
20
|
import { type Material, materialClass } from "../../utils/material.js";
|
|
21
|
+
import { ITEM_MOTION, POPPER_MOTION } from "../../utils/overlay-motion.js";
|
|
21
22
|
|
|
22
23
|
interface ContextMenuState {
|
|
23
24
|
open: (x: number, y: number) => void;
|
|
@@ -192,6 +193,7 @@ export function ContextMenuContent({
|
|
|
192
193
|
}}
|
|
193
194
|
className={cn(
|
|
194
195
|
"z-85 max-h-(--ui-popper-available-height) min-w-48 max-w-(--ui-popper-available-width) overflow-y-auto rounded-popover border-card surface-overlay p-1.5 text-ink shadow-overlay",
|
|
196
|
+
POPPER_MOTION,
|
|
195
197
|
materialClass(material, "surface-solid"),
|
|
196
198
|
className,
|
|
197
199
|
)}
|
|
@@ -201,8 +203,7 @@ export function ContextMenuContent({
|
|
|
201
203
|
);
|
|
202
204
|
}
|
|
203
205
|
|
|
204
|
-
const itemBase =
|
|
205
|
-
"relative flex min-h-control-sm w-full cursor-pointer select-none items-center gap-density-sm rounded-button px-control-x text-body outline-none data-disabled:pointer-events-none data-disabled:opacity-50 data-highlighted:bg-surface-2 [&_svg]:size-4 [&_svg]:shrink-0";
|
|
206
|
+
const itemBase = `relative flex min-h-control-sm w-full cursor-pointer select-none items-center gap-density-sm rounded-button px-control-x text-body outline-none data-disabled:pointer-events-none data-disabled:opacity-50 data-highlighted:bg-surface-2 [&_svg]:size-4 [&_svg]:shrink-0 ${ITEM_MOTION}`;
|
|
206
207
|
|
|
207
208
|
export interface ContextMenuItemProps extends MenuPrimitive.MenuItemProps {
|
|
208
209
|
/** Destructive action styling. */
|
|
@@ -7,6 +7,7 @@ import * as DialogPrimitive from "../../primitives/dialog/dialog.js";
|
|
|
7
7
|
import type { ClassNames } from "../../utils/class-names.js";
|
|
8
8
|
import { cn } from "../../utils/cn.js";
|
|
9
9
|
import { type Material, materialClass } from "../../utils/material.js";
|
|
10
|
+
import { DIALOG_MOTION, OVERLAY_MOTION } from "../../utils/overlay-motion.js";
|
|
10
11
|
import {
|
|
11
12
|
PreviousFocusProvider,
|
|
12
13
|
restoreFocusOnClose,
|
|
@@ -80,11 +81,14 @@ export function DialogContent({
|
|
|
80
81
|
const strings = useUiStrings();
|
|
81
82
|
return (
|
|
82
83
|
<DialogPrimitive.Portal container={container}>
|
|
83
|
-
<DialogPrimitive.Overlay
|
|
84
|
+
<DialogPrimitive.Overlay
|
|
85
|
+
className={cn("fixed inset-0 z-70 bg-scrim", OVERLAY_MOTION, classNames?.overlay)}
|
|
86
|
+
/>
|
|
84
87
|
<DialogPrimitive.Content
|
|
85
88
|
className={cn(
|
|
86
89
|
"@container/dialog fixed top-[9dvh] left-1/2 z-70 flex max-h-[84dvh] max-w-full -translate-x-1/2 flex-col overflow-auto rounded-dialog outline-none surface-overlay shadow-overlay",
|
|
87
90
|
widthClasses[width],
|
|
91
|
+
DIALOG_MOTION,
|
|
88
92
|
materialClass(material, "surface-solid"),
|
|
89
93
|
classNames?.root,
|
|
90
94
|
className,
|
|
@@ -112,7 +116,8 @@ export function DialogContent({
|
|
|
112
116
|
<DialogPrimitive.Close
|
|
113
117
|
aria-label={closeLabel ?? strings.close}
|
|
114
118
|
className={cn(
|
|
115
|
-
|
|
119
|
+
// A 30px square (44px under touch) centred where the 24px button was, so the glyph stays put.
|
|
120
|
+
"absolute top-[calc(0.5625rem-0.4375rem*var(--touch))] right-[calc(0.5625rem-0.4375rem*var(--touch))] flex size-control-sm items-center justify-center rounded-event text-ink-3 hover:text-ink",
|
|
116
121
|
classNames?.close,
|
|
117
122
|
)}
|
|
118
123
|
>
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import type
|
|
3
|
+
import { type ComponentPropsWithoutRef, type PointerEvent, useRef } from "react";
|
|
4
4
|
import { useUiStrings } from "../../i18n/index.js";
|
|
5
5
|
import { X } from "../../icons/index.js";
|
|
6
6
|
import * as DialogPrimitive from "../../primitives/dialog/dialog.js";
|
|
7
7
|
import type { ClassNames } from "../../utils/class-names.js";
|
|
8
8
|
import { cn } from "../../utils/cn.js";
|
|
9
9
|
import { type Material, materialClass } from "../../utils/material.js";
|
|
10
|
+
import { DRAWER_MOTION, OVERLAY_MOTION, SHEET_MOTION } from "../../utils/overlay-motion.js";
|
|
10
11
|
import {
|
|
11
12
|
PreviousFocusProvider,
|
|
12
13
|
restoreFocusOnClose,
|
|
@@ -42,7 +43,22 @@ export function DrawerDescription({
|
|
|
42
43
|
return <DialogPrimitive.Description className={cn("m-0 text-ink-2", className)} {...props} />;
|
|
43
44
|
}
|
|
44
45
|
|
|
45
|
-
export type DrawerContentPart = "root" | "overlay" | "close";
|
|
46
|
+
export type DrawerContentPart = "root" | "overlay" | "close" | "handle";
|
|
47
|
+
|
|
48
|
+
export type DrawerSide = "right" | "bottom";
|
|
49
|
+
|
|
50
|
+
const SWIPE_CLOSE_PX = 60;
|
|
51
|
+
|
|
52
|
+
const sideClasses: Record<DrawerSide, string> = {
|
|
53
|
+
right: "inset-y-0 right-0 h-full w-[min(430px,100%)] max-w-full",
|
|
54
|
+
bottom:
|
|
55
|
+
"inset-x-0 bottom-0 max-h-[min(85dvh,100%)] w-full rounded-t-card pb-[env(safe-area-inset-bottom)]",
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
/** Classes of the content box for a side; exported for tests and for wrappers that restyle it. */
|
|
59
|
+
export function drawerSideClass(side: DrawerSide): string {
|
|
60
|
+
return sideClasses[side];
|
|
61
|
+
}
|
|
46
62
|
|
|
47
63
|
export interface DrawerContentProps extends DialogPrimitive.DialogContentProps {
|
|
48
64
|
/** Per-part classes merged with `cn`; consumer classes win. `className` still targets the content and is merged last. */
|
|
@@ -58,15 +74,28 @@ export interface DrawerContentProps extends DialogPrimitive.DialogContentProps {
|
|
|
58
74
|
blocking?: boolean;
|
|
59
75
|
/** Accessible label of the close button. */
|
|
60
76
|
closeLabel?: string;
|
|
77
|
+
/**
|
|
78
|
+
* Edge the panel is anchored to. `"right"` (default) is a side panel up to 430 px wide;
|
|
79
|
+
* `"bottom"` is a bottom sheet across the width, padded by the safe-area inset and capped at
|
|
80
|
+
* 85dvh with its own scroll. Focus is trapped and Escape closes it on both.
|
|
81
|
+
*/
|
|
82
|
+
side?: DrawerSide;
|
|
83
|
+
/**
|
|
84
|
+
* Shows a grab handle at the top of a `side="bottom"` sheet. It is decorative (hidden from
|
|
85
|
+
* assistive tech); dragging it down closes the sheet unless `blocking`. Ignored on other sides.
|
|
86
|
+
*/
|
|
87
|
+
handle?: boolean;
|
|
61
88
|
}
|
|
62
89
|
|
|
63
|
-
/**
|
|
90
|
+
/** Side panel (right) or bottom sheet for secondary flows. */
|
|
64
91
|
export function DrawerContent({
|
|
65
92
|
className,
|
|
66
93
|
classNames,
|
|
67
94
|
material,
|
|
68
95
|
blocking = false,
|
|
69
96
|
closeLabel,
|
|
97
|
+
side = "right",
|
|
98
|
+
handle = false,
|
|
70
99
|
children,
|
|
71
100
|
onEscapeKeyDown,
|
|
72
101
|
onPointerDownOutside,
|
|
@@ -76,12 +105,31 @@ export function DrawerContent({
|
|
|
76
105
|
}: DrawerContentProps) {
|
|
77
106
|
const previousFocusRef = usePreviousFocus();
|
|
78
107
|
const strings = useUiStrings();
|
|
108
|
+
const closeRef = useRef<HTMLButtonElement>(null);
|
|
109
|
+
const swipe = useRef<number | null>(null);
|
|
110
|
+
const bottom = side === "bottom";
|
|
111
|
+
const showHandle = bottom && handle;
|
|
112
|
+
const swipeStart = (event: PointerEvent<HTMLDivElement>) => {
|
|
113
|
+
swipe.current = event.clientY;
|
|
114
|
+
event.currentTarget.setPointerCapture?.(event.pointerId);
|
|
115
|
+
};
|
|
116
|
+
const swipeEnd = (event: PointerEvent<HTMLDivElement>) => {
|
|
117
|
+
const from = swipe.current;
|
|
118
|
+
swipe.current = null;
|
|
119
|
+
if (from !== null && !blocking && event.clientY - from >= SWIPE_CLOSE_PX) {
|
|
120
|
+
closeRef.current?.click();
|
|
121
|
+
}
|
|
122
|
+
};
|
|
79
123
|
return (
|
|
80
124
|
<DialogPrimitive.Portal>
|
|
81
|
-
<DialogPrimitive.Overlay
|
|
125
|
+
<DialogPrimitive.Overlay
|
|
126
|
+
className={cn("fixed inset-0 z-70 bg-scrim", OVERLAY_MOTION, classNames?.overlay)}
|
|
127
|
+
/>
|
|
82
128
|
<DialogPrimitive.Content
|
|
83
129
|
className={cn(
|
|
84
|
-
"@container/drawer fixed
|
|
130
|
+
"@container/drawer fixed z-70 flex flex-col overflow-y-auto outline-none surface-overlay shadow-overlay",
|
|
131
|
+
sideClasses[side],
|
|
132
|
+
side === "bottom" ? SHEET_MOTION : DRAWER_MOTION,
|
|
85
133
|
materialClass(material, "surface-solid"),
|
|
86
134
|
classNames?.root,
|
|
87
135
|
className,
|
|
@@ -104,12 +152,26 @@ export function DrawerContent({
|
|
|
104
152
|
}}
|
|
105
153
|
{...props}
|
|
106
154
|
>
|
|
155
|
+
{showHandle ? (
|
|
156
|
+
<div
|
|
157
|
+
aria-hidden="true"
|
|
158
|
+
onPointerDown={swipeStart}
|
|
159
|
+
onPointerUp={swipeEnd}
|
|
160
|
+
onPointerCancel={() => {
|
|
161
|
+
swipe.current = null;
|
|
162
|
+
}}
|
|
163
|
+
className={cn("flex shrink-0 touch-none justify-center pt-2 pb-1", classNames?.handle)}
|
|
164
|
+
>
|
|
165
|
+
<span className="h-1 w-9 rounded-pill bg-line-strong" />
|
|
166
|
+
</div>
|
|
167
|
+
) : null}
|
|
107
168
|
{children}
|
|
108
169
|
{!blocking && (
|
|
109
170
|
<DialogPrimitive.Close
|
|
171
|
+
ref={closeRef}
|
|
110
172
|
aria-label={closeLabel ?? strings.close}
|
|
111
173
|
className={cn(
|
|
112
|
-
"absolute top-
|
|
174
|
+
"absolute top-[calc(0.5625rem-0.4375rem*var(--touch))] right-[calc(0.5625rem-0.4375rem*var(--touch))] flex size-control-sm items-center justify-center rounded-event text-ink-3 hover:text-ink",
|
|
113
175
|
classNames?.close,
|
|
114
176
|
)}
|
|
115
177
|
>
|
|
@@ -5,6 +5,7 @@ import { Check, ChevronRight } from "../../icons/index.js";
|
|
|
5
5
|
import * as MenuPrimitive from "../../primitives/menu/menu.js";
|
|
6
6
|
import { cn } from "../../utils/cn.js";
|
|
7
7
|
import { type Material, materialClass } from "../../utils/material.js";
|
|
8
|
+
import { ITEM_MOTION, POPPER_MOTION } from "../../utils/overlay-motion.js";
|
|
8
9
|
|
|
9
10
|
export const DropdownMenu = MenuPrimitive.Root;
|
|
10
11
|
export const DropdownMenuTrigger = MenuPrimitive.Trigger;
|
|
@@ -27,10 +28,10 @@ export const dropdownMenuSurfaceClasses = "rounded-popover surface-overlay p-1.5
|
|
|
27
28
|
|
|
28
29
|
/** The default look of a menu item, for your own `DropdownMenuItem asChild` or `MenuPrimitive.Item`. */
|
|
29
30
|
export const dropdownMenuItemClasses =
|
|
30
|
-
"flex w-full cursor-pointer items-center gap-2 rounded-event px-2.5 py-1.75 text-body text-ink outline-none data-highlighted:bg-surface-2";
|
|
31
|
+
"flex min-h-(--touch-target) w-full cursor-pointer items-center gap-2 rounded-event px-2.5 py-1.75 text-body text-ink outline-none data-highlighted:bg-surface-2";
|
|
31
32
|
|
|
32
|
-
const surface = `${placement} ${dropdownMenuSurfaceClasses}`;
|
|
33
|
-
const itemBase = dropdownMenuItemClasses
|
|
33
|
+
const surface = `${placement} ${POPPER_MOTION} ${dropdownMenuSurfaceClasses}`;
|
|
34
|
+
const itemBase = `${dropdownMenuItemClasses} ${ITEM_MOTION}`;
|
|
34
35
|
|
|
35
36
|
export interface DropdownMenuContentProps extends MenuPrimitive.MenuContentProps {
|
|
36
37
|
/** Portal target. Defaults to `document.body`; pass an element to keep a scoped `data-style`. */
|
|
@@ -67,7 +68,7 @@ export function DropdownMenuContent({
|
|
|
67
68
|
collisionPadding={collisionPadding}
|
|
68
69
|
className={
|
|
69
70
|
bare
|
|
70
|
-
? cn(placement, className)
|
|
71
|
+
? cn(placement, POPPER_MOTION, className)
|
|
71
72
|
: cn(surface, materialClass(material, "surface-solid"), className)
|
|
72
73
|
}
|
|
73
74
|
{...props}
|
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
import * as PopoverPrimitive from "../../primitives/popover/popover.js";
|
|
18
18
|
import { cn } from "../../utils/cn.js";
|
|
19
19
|
import { type Material, materialClass } from "../../utils/material.js";
|
|
20
|
+
import { POPPER_MOTION } from "../../utils/overlay-motion.js";
|
|
20
21
|
import { Slot } from "../../utils/slot.js";
|
|
21
22
|
|
|
22
23
|
interface HoverCardContextValue {
|
|
@@ -187,6 +188,7 @@ export function HoverCardContent({
|
|
|
187
188
|
}}
|
|
188
189
|
className={cn(
|
|
189
190
|
"z-85 w-72 max-w-(--ui-popper-available-width) rounded-popover border-card surface-overlay p-card text-body text-ink shadow-overlay",
|
|
191
|
+
POPPER_MOTION,
|
|
190
192
|
materialClass(material, "surface-solid"),
|
|
191
193
|
className,
|
|
192
194
|
)}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import * as PopoverPrimitive from "../../primitives/popover/popover.js";
|
|
4
4
|
import { cn } from "../../utils/cn.js";
|
|
5
5
|
import { type Material, materialClass } from "../../utils/material.js";
|
|
6
|
+
import { POPPER_MOTION } from "../../utils/overlay-motion.js";
|
|
6
7
|
|
|
7
8
|
export const Popover = PopoverPrimitive.Root;
|
|
8
9
|
export const PopoverTrigger = PopoverPrimitive.Trigger;
|
|
@@ -38,6 +39,7 @@ export function PopoverContent({
|
|
|
38
39
|
collisionPadding={collisionPadding}
|
|
39
40
|
className={cn(
|
|
40
41
|
"z-85 min-w-[min(14.375rem,var(--ui-popper-available-width))] max-h-(--ui-popper-available-height) max-w-(--ui-popper-available-width) overflow-y-auto rounded-popover surface-overlay p-1.5 text-ink shadow-overlay",
|
|
42
|
+
POPPER_MOTION,
|
|
41
43
|
materialClass(material, "surface-solid"),
|
|
42
44
|
className,
|
|
43
45
|
)}
|
|
@@ -2,9 +2,11 @@ export type { ToastTone } from "./toast-store.js";
|
|
|
2
2
|
export {
|
|
3
3
|
type ToastAction,
|
|
4
4
|
Toaster,
|
|
5
|
+
type ToasterOffset,
|
|
5
6
|
type ToasterPart,
|
|
6
7
|
type ToasterPosition,
|
|
7
8
|
type ToasterProps,
|
|
9
|
+
type ToasterResponsivePosition,
|
|
8
10
|
type ToastOptions,
|
|
9
11
|
toast,
|
|
10
12
|
toastToneClasses,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
|
+
type CSSProperties,
|
|
4
5
|
type KeyboardEvent,
|
|
5
6
|
type PointerEvent,
|
|
6
7
|
useEffect,
|
|
@@ -36,12 +37,28 @@ export type ToasterPosition =
|
|
|
36
37
|
| "bottom-center"
|
|
37
38
|
| "bottom-right";
|
|
38
39
|
|
|
40
|
+
/**
|
|
41
|
+
* One position, or one per viewport width: `base` always applies, `sm` from 640 px and `lg` from
|
|
42
|
+
* 1024 px of viewport width (a toast is anchored to the viewport, so these are media queries).
|
|
43
|
+
*/
|
|
44
|
+
export type ToasterResponsivePosition =
|
|
45
|
+
| ToasterPosition
|
|
46
|
+
| { base: ToasterPosition; sm?: ToasterPosition; lg?: ToasterPosition };
|
|
47
|
+
|
|
48
|
+
/** Distance from the viewport edges: a number is px, a string is any CSS length (`calc(env(safe-area-inset-bottom) + 4rem)`). */
|
|
49
|
+
export type ToasterOffset = number | string | { x?: number | string; y?: number | string };
|
|
50
|
+
|
|
39
51
|
export type ToasterPart = "root" | "list" | "toast" | "title" | "description" | "action";
|
|
40
52
|
|
|
41
53
|
export interface ToasterProps {
|
|
42
54
|
/** Per-part classes merged with `cn`; consumer classes win. `className` still targets the root and is merged last. */
|
|
43
55
|
classNames?: ClassNames<ToasterPart>;
|
|
44
|
-
position?:
|
|
56
|
+
position?: ToasterResponsivePosition;
|
|
57
|
+
/**
|
|
58
|
+
* Distance from the edges the region is anchored to. Defaults to 1rem on both axes; `y` is
|
|
59
|
+
* measured from the top or the bottom edge, whichever the position uses.
|
|
60
|
+
*/
|
|
61
|
+
offset?: ToasterOffset;
|
|
45
62
|
/** Default auto dismiss delay in ms; `Infinity` disables it. */
|
|
46
63
|
duration?: number;
|
|
47
64
|
/** Toasts shown at once; older ones wait until a newer one leaves. */
|
|
@@ -94,14 +111,97 @@ const EXIT_MS = 200;
|
|
|
94
111
|
const SWIPE_THRESHOLD = 60;
|
|
95
112
|
|
|
96
113
|
const POSITION: Record<ToasterPosition, string> = {
|
|
97
|
-
"top-left":
|
|
98
|
-
|
|
99
|
-
"top-
|
|
100
|
-
|
|
101
|
-
"
|
|
102
|
-
|
|
114
|
+
"top-left":
|
|
115
|
+
"top-[var(--toast-y,1rem)] bottom-auto left-[var(--toast-x,1rem)] right-auto translate-x-0 items-start",
|
|
116
|
+
"top-center":
|
|
117
|
+
"top-[var(--toast-y,1rem)] bottom-auto left-1/2 right-auto -translate-x-1/2 items-center",
|
|
118
|
+
"top-right":
|
|
119
|
+
"top-[var(--toast-y,1rem)] bottom-auto right-[var(--toast-x,1rem)] left-auto translate-x-0 items-end",
|
|
120
|
+
"bottom-left":
|
|
121
|
+
"bottom-[var(--toast-y,calc(var(--app-bottom-bar,0px)_+_1rem))] top-auto left-[var(--toast-x,1rem)] right-auto translate-x-0 items-start",
|
|
122
|
+
"bottom-center":
|
|
123
|
+
"bottom-[var(--toast-y,calc(var(--app-bottom-bar,0px)_+_1rem))] top-auto left-1/2 right-auto -translate-x-1/2 items-center",
|
|
124
|
+
"bottom-right":
|
|
125
|
+
"bottom-[var(--toast-y,calc(var(--app-bottom-bar,0px)_+_1rem))] top-auto right-[var(--toast-x,1rem)] left-auto translate-x-0 items-end",
|
|
103
126
|
};
|
|
104
127
|
|
|
128
|
+
const POSITION_SM: Record<ToasterPosition, string> = {
|
|
129
|
+
"top-left":
|
|
130
|
+
"min-[640px]:top-[var(--toast-y,1rem)] min-[640px]:bottom-auto min-[640px]:left-[var(--toast-x,1rem)] min-[640px]:right-auto min-[640px]:translate-x-0 min-[640px]:items-start",
|
|
131
|
+
"top-center":
|
|
132
|
+
"min-[640px]:top-[var(--toast-y,1rem)] min-[640px]:bottom-auto min-[640px]:left-1/2 min-[640px]:right-auto min-[640px]:-translate-x-1/2 min-[640px]:items-center",
|
|
133
|
+
"top-right":
|
|
134
|
+
"min-[640px]:top-[var(--toast-y,1rem)] min-[640px]:bottom-auto min-[640px]:right-[var(--toast-x,1rem)] min-[640px]:left-auto min-[640px]:translate-x-0 min-[640px]:items-end",
|
|
135
|
+
"bottom-left":
|
|
136
|
+
"min-[640px]:bottom-[var(--toast-y,calc(var(--app-bottom-bar,0px)_+_1rem))] min-[640px]:top-auto min-[640px]:left-[var(--toast-x,1rem)] min-[640px]:right-auto min-[640px]:translate-x-0 min-[640px]:items-start",
|
|
137
|
+
"bottom-center":
|
|
138
|
+
"min-[640px]:bottom-[var(--toast-y,calc(var(--app-bottom-bar,0px)_+_1rem))] min-[640px]:top-auto min-[640px]:left-1/2 min-[640px]:right-auto min-[640px]:-translate-x-1/2 min-[640px]:items-center",
|
|
139
|
+
"bottom-right":
|
|
140
|
+
"min-[640px]:bottom-[var(--toast-y,calc(var(--app-bottom-bar,0px)_+_1rem))] min-[640px]:top-auto min-[640px]:right-[var(--toast-x,1rem)] min-[640px]:left-auto min-[640px]:translate-x-0 min-[640px]:items-end",
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
const POSITION_LG: Record<ToasterPosition, string> = {
|
|
144
|
+
"top-left":
|
|
145
|
+
"min-[1024px]:top-[var(--toast-y,1rem)] min-[1024px]:bottom-auto min-[1024px]:left-[var(--toast-x,1rem)] min-[1024px]:right-auto min-[1024px]:translate-x-0 min-[1024px]:items-start",
|
|
146
|
+
"top-center":
|
|
147
|
+
"min-[1024px]:top-[var(--toast-y,1rem)] min-[1024px]:bottom-auto min-[1024px]:left-1/2 min-[1024px]:right-auto min-[1024px]:-translate-x-1/2 min-[1024px]:items-center",
|
|
148
|
+
"top-right":
|
|
149
|
+
"min-[1024px]:top-[var(--toast-y,1rem)] min-[1024px]:bottom-auto min-[1024px]:right-[var(--toast-x,1rem)] min-[1024px]:left-auto min-[1024px]:translate-x-0 min-[1024px]:items-end",
|
|
150
|
+
"bottom-left":
|
|
151
|
+
"min-[1024px]:bottom-[var(--toast-y,calc(var(--app-bottom-bar,0px)_+_1rem))] min-[1024px]:top-auto min-[1024px]:left-[var(--toast-x,1rem)] min-[1024px]:right-auto min-[1024px]:translate-x-0 min-[1024px]:items-start",
|
|
152
|
+
"bottom-center":
|
|
153
|
+
"min-[1024px]:bottom-[var(--toast-y,calc(var(--app-bottom-bar,0px)_+_1rem))] min-[1024px]:top-auto min-[1024px]:left-1/2 min-[1024px]:right-auto min-[1024px]:-translate-x-1/2 min-[1024px]:items-center",
|
|
154
|
+
"bottom-right":
|
|
155
|
+
"min-[1024px]:bottom-[var(--toast-y,calc(var(--app-bottom-bar,0px)_+_1rem))] min-[1024px]:top-auto min-[1024px]:right-[var(--toast-x,1rem)] min-[1024px]:left-auto min-[1024px]:translate-x-0 min-[1024px]:items-end",
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
const LIST_ORDER: Record<ToasterVertical, string> = {
|
|
159
|
+
top: "flex-col-reverse",
|
|
160
|
+
bottom: "flex-col",
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
const LIST_ORDER_SM: Record<ToasterVertical, string> = {
|
|
164
|
+
top: "min-[640px]:flex-col-reverse",
|
|
165
|
+
bottom: "min-[640px]:flex-col",
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
const LIST_ORDER_LG: Record<ToasterVertical, string> = {
|
|
169
|
+
top: "min-[1024px]:flex-col-reverse",
|
|
170
|
+
bottom: "min-[1024px]:flex-col",
|
|
171
|
+
};
|
|
172
|
+
type ToasterVertical = "top" | "bottom";
|
|
173
|
+
|
|
174
|
+
const verticalOf = (position: ToasterPosition): ToasterVertical =>
|
|
175
|
+
position.startsWith("top") ? "top" : "bottom";
|
|
176
|
+
|
|
177
|
+
function sideValue(value: number | string | undefined): string | undefined {
|
|
178
|
+
return typeof value === "number" ? `${value}px` : value;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/** Region classes, list direction and offset variables for a position and an offset. */
|
|
182
|
+
export function toasterPlacement(
|
|
183
|
+
position: ToasterResponsivePosition,
|
|
184
|
+
offset?: ToasterOffset,
|
|
185
|
+
): { region: string; list: string; style: CSSProperties } {
|
|
186
|
+
const base = typeof position === "string" ? position : position.base;
|
|
187
|
+
const sm = typeof position === "string" ? undefined : position.sm;
|
|
188
|
+
const lg = typeof position === "string" ? undefined : position.lg;
|
|
189
|
+
const x = sideValue(typeof offset === "object" ? offset.x : offset);
|
|
190
|
+
const y = sideValue(typeof offset === "object" ? offset.y : offset);
|
|
191
|
+
return {
|
|
192
|
+
region: cn(POSITION[base], sm && POSITION_SM[sm], lg && POSITION_LG[lg]),
|
|
193
|
+
list: cn(
|
|
194
|
+
LIST_ORDER[verticalOf(base)],
|
|
195
|
+
sm && LIST_ORDER_SM[verticalOf(sm)],
|
|
196
|
+
lg && LIST_ORDER_LG[verticalOf(lg)],
|
|
197
|
+
),
|
|
198
|
+
style: {
|
|
199
|
+
...(x !== undefined ? { "--toast-x": x } : {}),
|
|
200
|
+
...(y !== undefined ? { "--toast-y": y } : {}),
|
|
201
|
+
} as CSSProperties,
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
|
|
105
205
|
function documentDir(): "ltr" | "rtl" | undefined {
|
|
106
206
|
if (typeof document === "undefined") return undefined;
|
|
107
207
|
const value = document.documentElement.getAttribute("dir");
|
|
@@ -252,7 +352,7 @@ function ToastItem({ record, duration, reducedMotion, classNames }: ToastItemPro
|
|
|
252
352
|
<button
|
|
253
353
|
type="button"
|
|
254
354
|
className={cn(
|
|
255
|
-
"h-8 shrink-0 rounded-button px-3 font-bold focus-ring",
|
|
355
|
+
"h-8 shrink-0 rounded-button px-3 font-bold focus-visible:focus-ring",
|
|
256
356
|
toneActionClasses[tone],
|
|
257
357
|
classNames?.action,
|
|
258
358
|
)}
|
|
@@ -274,6 +374,7 @@ function ToastItem({ record, duration, reducedMotion, classNames }: ToastItemPro
|
|
|
274
374
|
*/
|
|
275
375
|
export function Toaster({
|
|
276
376
|
position = "bottom-center",
|
|
377
|
+
offset,
|
|
277
378
|
duration = 6000,
|
|
278
379
|
visibleToasts = 2,
|
|
279
380
|
className,
|
|
@@ -287,7 +388,7 @@ export function Toaster({
|
|
|
287
388
|
const records = useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
|
|
288
389
|
const regionRef = useRef<HTMLElement>(null);
|
|
289
390
|
const shown = selectVisible(records, visibleToasts);
|
|
290
|
-
const
|
|
391
|
+
const placement = toasterPlacement(position, offset);
|
|
291
392
|
|
|
292
393
|
useEffect(() => {
|
|
293
394
|
const onKey = (event: globalThis.KeyboardEvent) => {
|
|
@@ -306,20 +407,15 @@ export function Toaster({
|
|
|
306
407
|
data-ui-layer-branch=""
|
|
307
408
|
aria-label={label ?? strings.notifications}
|
|
308
409
|
tabIndex={-1}
|
|
410
|
+
style={placement.style}
|
|
309
411
|
className={cn(
|
|
310
412
|
"pointer-events-none fixed z-[1000] flex outline-none",
|
|
311
|
-
|
|
413
|
+
placement.region,
|
|
312
414
|
classNames?.root,
|
|
313
415
|
className,
|
|
314
416
|
)}
|
|
315
417
|
>
|
|
316
|
-
<div
|
|
317
|
-
className={cn(
|
|
318
|
-
"m-0 flex list-none gap-2 p-0",
|
|
319
|
-
fromTop ? "flex-col-reverse" : "flex-col",
|
|
320
|
-
classNames?.list,
|
|
321
|
-
)}
|
|
322
|
-
>
|
|
418
|
+
<div className={cn("m-0 flex list-none gap-2 p-0", placement.list, classNames?.list)}>
|
|
323
419
|
{shown.map((record) => (
|
|
324
420
|
<ToastItem
|
|
325
421
|
key={record.id}
|
|
@@ -16,6 +16,7 @@ import type { Align, Side } from "../../primitives/popper/geometry.js";
|
|
|
16
16
|
import type { ClassNames } from "../../utils/class-names.js";
|
|
17
17
|
import { cn } from "../../utils/cn.js";
|
|
18
18
|
import { type Material, materialClass } from "../../utils/material.js";
|
|
19
|
+
import { POPPER_MOTION } from "../../utils/overlay-motion.js";
|
|
19
20
|
import { Slot } from "../../utils/slot.js";
|
|
20
21
|
import { useControllableState } from "../../utils/use-controllable-state.js";
|
|
21
22
|
import { opensOnFocus, opensOnHover } from "./model.js";
|
|
@@ -152,6 +153,7 @@ export function Tooltip({
|
|
|
152
153
|
onMouseLeave={() => schedule(false, closeDelay)}
|
|
153
154
|
className={cn(
|
|
154
155
|
"z-85 flex w-max max-w-[min(16rem,var(--ui-popper-available-width))] items-center gap-2 rounded-popover surface-overlay px-2.5 py-1.5 text-meta text-ink shadow-overlay",
|
|
156
|
+
POPPER_MOTION,
|
|
155
157
|
materialClass(material, "surface-solid"),
|
|
156
158
|
classNames?.content,
|
|
157
159
|
className,
|
|
@@ -66,6 +66,16 @@ export function exitDuration(node: Element): number {
|
|
|
66
66
|
return Math.max(animated, transitioned);
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
+
/** Whether an exit-relevant animation or transition on the node itself is still running. */
|
|
70
|
+
function stillRunning(node: Element): boolean {
|
|
71
|
+
if (typeof node.getAnimations !== "function") return false;
|
|
72
|
+
return node.getAnimations().some((animation) => {
|
|
73
|
+
if (animation.playState !== "running") return false;
|
|
74
|
+
const property = (animation as Animation & { transitionProperty?: string }).transitionProperty;
|
|
75
|
+
return property === undefined || EXIT_PROPERTIES.has(property);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
69
79
|
function prefersReducedMotion(): boolean {
|
|
70
80
|
return typeof window.matchMedia === "function"
|
|
71
81
|
? window.matchMedia("(prefers-reduced-motion: reduce)").matches
|
|
@@ -95,6 +105,9 @@ export function usePresence(present: boolean, ref: RefObject<HTMLElement | null>
|
|
|
95
105
|
if (event.target !== node) return;
|
|
96
106
|
const property = (event as TransitionEvent).propertyName;
|
|
97
107
|
if (event.type === "transitionend" && !EXIT_PROPERTIES.has(property)) return;
|
|
108
|
+
// A built-in exit transition and a consumer's own (longer) exit animation can run together:
|
|
109
|
+
// wait for the last one, not the first to end.
|
|
110
|
+
if (stillRunning(node)) return;
|
|
98
111
|
finish();
|
|
99
112
|
};
|
|
100
113
|
node.addEventListener("animationend", onEnd);
|