@jcsoftdev/ui 0.3.0 → 0.5.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 +200 -1
- package/README.md +56 -3
- package/bin/ui-theme.mjs +13 -2
- package/dist/atoms/button/button.d.ts +8 -1
- package/dist/atoms/button/button.js +10 -3
- package/dist/atoms/checkbox/checkbox.js +3 -1
- package/dist/atoms/chip/chip.d.ts +11 -3
- package/dist/atoms/chip/chip.js +8 -1
- package/dist/atoms/chip/index.d.ts +1 -1
- package/dist/atoms/chip/index.js +2 -0
- 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/due-chip/due-chip.d.ts +31 -0
- package/dist/atoms/due-chip/due-chip.js +41 -0
- package/dist/atoms/due-chip/index.d.ts +2 -0
- package/dist/atoms/due-chip/index.js +6 -0
- package/dist/atoms/due-chip/model.d.ts +25 -0
- package/dist/atoms/due-chip/model.js +44 -0
- package/dist/atoms/icon-button/icon-button.d.ts +22 -0
- package/dist/atoms/icon-button/icon-button.js +38 -0
- package/dist/atoms/icon-button/index.d.ts +1 -0
- package/dist/atoms/icon-button/index.js +8 -0
- package/dist/atoms/index.d.ts +6 -0
- package/dist/atoms/index.js +6 -0
- package/dist/atoms/internal/hit-area.d.ts +6 -0
- package/dist/atoms/internal/hit-area.js +4 -0
- package/dist/atoms/kbd/index.d.ts +1 -0
- package/dist/atoms/kbd/index.js +4 -0
- package/dist/atoms/kbd/kbd.d.ts +7 -0
- package/dist/atoms/kbd/kbd.js +17 -0
- package/dist/atoms/radio-group/radio-group.js +6 -2
- package/dist/atoms/seal/index.d.ts +1 -0
- package/dist/atoms/seal/index.js +4 -0
- package/dist/atoms/seal/seal.d.ts +30 -0
- package/dist/atoms/seal/seal.js +71 -0
- package/dist/atoms/spinner/index.d.ts +1 -0
- package/dist/atoms/spinner/index.js +5 -0
- package/dist/atoms/spinner/spinner.d.ts +19 -0
- package/dist/atoms/spinner/spinner.js +31 -0
- package/dist/atoms/switch/switch.js +3 -1
- 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/calendar/date-calendar/date-calendar.d.ts +32 -0
- package/dist/calendar/date-calendar/date-calendar.js +189 -0
- package/dist/calendar/date-calendar/index.d.ts +1 -0
- package/dist/calendar/date-calendar/index.js +6 -0
- package/dist/calendar/index.d.ts +1 -0
- package/dist/calendar/index.js +1 -0
- package/dist/calendar/internal/date-utils.d.ts +26 -0
- package/dist/calendar/internal/date-utils.js +95 -1
- package/dist/containers/aside/aside.d.ts +14 -0
- package/dist/containers/aside/aside.js +25 -0
- package/dist/containers/aside/index.d.ts +1 -0
- package/dist/containers/aside/index.js +5 -0
- package/dist/containers/banner/banner.d.ts +4 -1
- package/dist/containers/banner/banner.js +9 -1
- package/dist/containers/description-list/description-list.d.ts +29 -6
- package/dist/containers/description-list/description-list.js +47 -6
- package/dist/containers/feed/feed.d.ts +23 -0
- package/dist/containers/feed/feed.js +77 -0
- package/dist/containers/feed/index.d.ts +2 -0
- package/dist/containers/feed/index.js +10 -0
- package/dist/containers/feed/model.d.ts +19 -0
- package/dist/containers/feed/model.js +38 -0
- package/dist/containers/index.d.ts +6 -0
- package/dist/containers/index.js +6 -0
- package/dist/containers/kpi/kpi.d.ts +50 -8
- package/dist/containers/kpi/kpi.js +91 -39
- package/dist/containers/list-detail/index.d.ts +1 -0
- package/dist/containers/list-detail/index.js +20 -0
- package/dist/containers/list-detail/list-detail.d.ts +55 -0
- package/dist/containers/list-detail/list-detail.js +221 -0
- package/dist/containers/note/index.d.ts +1 -0
- package/dist/containers/note/index.js +4 -0
- package/dist/containers/note/note.d.ts +13 -0
- package/dist/containers/note/note.js +27 -0
- package/dist/containers/section/index.d.ts +1 -0
- package/dist/containers/section/index.js +6 -0
- package/dist/containers/section/section.d.ts +68 -0
- package/dist/containers/section/section.js +198 -0
- package/dist/containers/shortcuts/index.d.ts +1 -0
- package/dist/containers/shortcuts/index.js +8 -0
- package/dist/containers/shortcuts/shortcuts.d.ts +18 -0
- package/dist/containers/shortcuts/shortcuts.js +50 -0
- package/dist/containers/table/selection.d.ts +9 -0
- package/dist/containers/table/selection.js +20 -0
- package/dist/containers/table/table.d.ts +66 -4
- package/dist/containers/table/table.js +128 -7
- package/dist/containers/timeline/index.d.ts +1 -1
- package/dist/containers/timeline/index.js +4 -2
- package/dist/containers/timeline/timeline.d.ts +32 -5
- package/dist/containers/timeline/timeline.js +154 -90
- package/dist/forms/chip-group/chip-group.d.ts +54 -0
- package/dist/forms/chip-group/chip-group.js +114 -0
- package/dist/forms/chip-group/index.d.ts +1 -0
- package/dist/forms/chip-group/index.js +6 -0
- package/dist/forms/combobox/combobox.d.ts +60 -0
- package/dist/forms/combobox/combobox.js +281 -0
- package/dist/forms/combobox/index.d.ts +1 -0
- package/dist/forms/combobox/index.js +6 -0
- package/dist/forms/date-picker/date-picker.d.ts +40 -0
- package/dist/forms/date-picker/date-picker.js +183 -0
- package/dist/forms/date-picker/date-time-picker.d.ts +43 -0
- package/dist/forms/date-picker/date-time-picker.js +121 -0
- package/dist/forms/date-picker/index.d.ts +2 -0
- package/dist/forms/date-picker/index.js +10 -0
- package/dist/forms/date-picker/model.d.ts +35 -0
- package/dist/forms/date-picker/model.js +83 -0
- package/dist/forms/dropzone/dropzone.d.ts +30 -2
- package/dist/forms/dropzone/dropzone.js +153 -23
- package/dist/forms/field/field.d.ts +16 -10
- package/dist/forms/field/field.js +41 -5
- package/dist/forms/index.d.ts +5 -0
- package/dist/forms/index.js +5 -0
- package/dist/forms/input/index.d.ts +1 -1
- package/dist/forms/input/index.js +4 -1
- package/dist/forms/input/input.d.ts +21 -5
- package/dist/forms/input/input.js +75 -9
- package/dist/forms/input-icon/input-icon.d.ts +1 -1
- package/dist/forms/internal/listbox-items.d.ts +18 -0
- package/dist/forms/internal/listbox-items.js +88 -0
- package/dist/forms/internal/listbox.d.ts +44 -0
- package/dist/forms/internal/listbox.js +74 -0
- package/dist/forms/number-stepper/model.d.ts +16 -0
- package/dist/forms/number-stepper/model.js +23 -0
- package/dist/forms/number-stepper/number-stepper.d.ts +36 -6
- package/dist/forms/number-stepper/number-stepper.js +86 -37
- 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-menu/index.d.ts +1 -0
- package/dist/forms/select-menu/index.js +6 -0
- package/dist/forms/select-menu/select-menu.d.ts +35 -0
- package/dist/forms/select-menu/select-menu.js +230 -0
- package/dist/i18n/strings.d.ts +153 -0
- package/dist/i18n/strings.js +86 -2
- package/dist/i18n/ui-strings-provider.d.ts +1 -1
- package/dist/i18n/ui-strings-provider.js +6 -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/navigation/index.d.ts +1 -0
- package/dist/navigation/index.js +1 -0
- package/dist/navigation/stepper/index.d.ts +1 -1
- package/dist/navigation/stepper/index.js +3 -1
- package/dist/navigation/stepper/stepper.d.ts +8 -0
- package/dist/navigation/stepper/stepper.js +68 -45
- package/dist/navigation/tabs/index.d.ts +1 -0
- package/dist/navigation/tabs/index.js +6 -0
- package/dist/navigation/tabs/tabs-nav.d.ts +37 -0
- package/dist/navigation/tabs/tabs-nav.js +57 -0
- package/dist/navigation/wizard/index.d.ts +1 -0
- package/dist/navigation/wizard/index.js +6 -0
- package/dist/navigation/wizard/model.d.ts +33 -0
- package/dist/navigation/wizard/model.js +34 -0
- package/dist/navigation/wizard/wizard.d.ts +45 -0
- package/dist/navigation/wizard/wizard.js +169 -0
- package/dist/overlays/alert-dialog/alert-dialog.d.ts +103 -0
- package/dist/overlays/alert-dialog/alert-dialog.js +342 -0
- package/dist/overlays/alert-dialog/index.d.ts +1 -0
- package/dist/overlays/alert-dialog/index.js +26 -0
- package/dist/overlays/dropdown-menu/dropdown-menu.d.ts +17 -1
- package/dist/overlays/dropdown-menu/dropdown-menu.js +12 -4
- package/dist/overlays/dropdown-menu/index.d.ts +1 -1
- package/dist/overlays/dropdown-menu/index.js +8 -2
- package/dist/overlays/index.d.ts +2 -0
- package/dist/overlays/index.js +2 -0
- package/dist/overlays/testing/index.d.ts +5 -0
- package/dist/overlays/testing/index.js +4 -0
- package/dist/overlays/toaster/index.d.ts +2 -1
- package/dist/overlays/toaster/index.js +4 -2
- package/dist/overlays/toaster/toast-store.d.ts +6 -2
- package/dist/overlays/toaster/toast.d.ts +3 -0
- package/dist/overlays/toaster/toast.js +3 -0
- package/dist/overlays/toaster/toaster.d.ts +3 -0
- package/dist/overlays/toaster/toaster.js +36 -3
- package/dist/overlays/tooltip/index.d.ts +1 -0
- package/dist/overlays/tooltip/index.js +4 -0
- package/dist/overlays/tooltip/model.d.ts +10 -0
- package/dist/overlays/tooltip/model.js +13 -0
- package/dist/overlays/tooltip/tooltip.d.ts +41 -0
- package/dist/overlays/tooltip/tooltip.js +116 -0
- package/dist/primitives/use-dismissable-layer.js +1 -1
- package/dist/states/error-state/error-state.d.ts +6 -1
- package/dist/states/error-state/error-state.js +13 -9
- package/dist/states/skeleton/skeleton.d.ts +8 -2
- package/dist/states/skeleton/skeleton.js +44 -2
- 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 +12 -1
- package/src/atoms/button/button.tsx +25 -3
- package/src/atoms/checkbox/checkbox.tsx +3 -1
- package/src/atoms/chip/chip.tsx +18 -3
- package/src/atoms/chip/index.ts +2 -0
- package/src/atoms/divider/divider.tsx +40 -0
- package/src/atoms/divider/index.ts +1 -0
- package/src/atoms/due-chip/due-chip.tsx +75 -0
- package/src/atoms/due-chip/index.ts +2 -0
- package/src/atoms/due-chip/model.ts +67 -0
- package/src/atoms/icon-button/icon-button.tsx +58 -0
- package/src/atoms/icon-button/index.ts +6 -0
- package/src/atoms/index.ts +6 -0
- package/src/atoms/internal/hit-area.ts +7 -0
- package/src/atoms/kbd/index.ts +1 -0
- package/src/atoms/kbd/kbd.tsx +20 -0
- package/src/atoms/radio-group/radio-group.tsx +8 -2
- package/src/atoms/seal/index.ts +1 -0
- package/src/atoms/seal/seal.tsx +107 -0
- package/src/atoms/spinner/index.ts +1 -0
- package/src/atoms/spinner/spinner.tsx +49 -0
- package/src/atoms/switch/switch.tsx +3 -1
- 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/calendar/date-calendar/date-calendar.tsx +230 -0
- package/src/calendar/date-calendar/index.ts +5 -0
- package/src/calendar/index.ts +1 -0
- package/src/calendar/internal/date-utils.ts +115 -0
- package/src/containers/aside/aside.tsx +40 -0
- package/src/containers/aside/index.ts +1 -0
- package/src/containers/banner/banner.tsx +18 -1
- package/src/containers/description-list/description-list.tsx +85 -9
- package/src/containers/feed/feed.tsx +99 -0
- package/src/containers/feed/index.ts +8 -0
- package/src/containers/feed/model.ts +54 -0
- package/src/containers/index.ts +6 -0
- package/src/containers/kpi/kpi.tsx +161 -62
- package/src/containers/list-detail/index.ts +15 -0
- package/src/containers/list-detail/list-detail.tsx +293 -0
- package/src/containers/note/index.ts +1 -0
- package/src/containers/note/note.tsx +38 -0
- package/src/containers/section/index.ts +11 -0
- package/src/containers/section/section.tsx +281 -0
- package/src/containers/shortcuts/index.ts +6 -0
- package/src/containers/shortcuts/shortcuts.tsx +92 -0
- package/src/containers/table/selection.ts +26 -0
- package/src/containers/table/table.tsx +215 -13
- package/src/containers/timeline/index.ts +3 -0
- package/src/containers/timeline/timeline.tsx +204 -93
- package/src/forms/chip-group/chip-group.tsx +184 -0
- package/src/forms/chip-group/index.ts +8 -0
- package/src/forms/combobox/combobox.tsx +359 -0
- package/src/forms/combobox/index.ts +7 -0
- package/src/forms/date-picker/date-picker.tsx +239 -0
- package/src/forms/date-picker/date-time-picker.tsx +178 -0
- package/src/forms/date-picker/index.ts +10 -0
- package/src/forms/date-picker/model.ts +108 -0
- package/src/forms/dropzone/dropzone.tsx +217 -35
- package/src/forms/field/field.tsx +72 -7
- package/src/forms/index.ts +5 -0
- package/src/forms/input/index.ts +8 -1
- package/src/forms/input/input.tsx +99 -12
- package/src/forms/input-icon/input-icon.tsx +1 -1
- package/src/forms/internal/listbox-items.tsx +103 -0
- package/src/forms/internal/listbox.ts +124 -0
- package/src/forms/number-stepper/model.ts +35 -0
- package/src/forms/number-stepper/number-stepper.tsx +132 -42
- package/src/forms/password-input/index.ts +1 -0
- package/src/forms/password-input/password-input.tsx +57 -0
- package/src/forms/select-menu/index.ts +7 -0
- package/src/forms/select-menu/select-menu.tsx +280 -0
- package/src/i18n/strings.ts +153 -0
- package/src/i18n/ui-strings-provider.tsx +15 -4
- 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/navigation/index.ts +1 -0
- package/src/navigation/stepper/index.ts +7 -1
- package/src/navigation/stepper/stepper.tsx +41 -5
- package/src/navigation/tabs/index.ts +7 -0
- package/src/navigation/tabs/tabs-nav.tsx +131 -0
- package/src/navigation/wizard/index.ts +7 -0
- package/src/navigation/wizard/model.ts +61 -0
- package/src/navigation/wizard/wizard.tsx +222 -0
- package/src/overlays/alert-dialog/alert-dialog.tsx +486 -0
- package/src/overlays/alert-dialog/index.ts +19 -0
- package/src/overlays/dropdown-menu/dropdown-menu.tsx +29 -4
- package/src/overlays/dropdown-menu/index.ts +3 -0
- package/src/overlays/index.ts +2 -0
- package/src/overlays/testing/index.ts +5 -0
- package/src/overlays/toaster/index.ts +2 -0
- package/src/overlays/toaster/toast-store.ts +6 -2
- package/src/overlays/toaster/toast.ts +6 -0
- package/src/overlays/toaster/toaster.tsx +44 -2
- package/src/overlays/tooltip/index.ts +1 -0
- package/src/overlays/tooltip/model.ts +18 -0
- package/src/overlays/tooltip/tooltip.tsx +166 -0
- package/src/primitives/use-dismissable-layer.ts +7 -2
- package/src/states/error-state/error-state.tsx +19 -8
- package/src/states/skeleton/skeleton.tsx +68 -2
- package/styles/tailwind.css +33 -30
- package/styles/theme.css +33 -30
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type ComponentPropsWithoutRef, createContext, type ReactNode, useContext } from "react";
|
|
2
2
|
import type { ClassNames } from "../../utils/class-names.js";
|
|
3
3
|
import { cn } from "../../utils/cn.js";
|
|
4
4
|
import { customToneStyle, isCustomTone } from "../../utils/tone.js";
|
|
@@ -36,16 +36,29 @@ export type KpiPart =
|
|
|
36
36
|
| "label"
|
|
37
37
|
| "dot"
|
|
38
38
|
| "icon"
|
|
39
|
+
| "trailing"
|
|
39
40
|
| "value"
|
|
40
41
|
| "suffix"
|
|
41
42
|
| "trend"
|
|
42
43
|
| "description";
|
|
43
44
|
|
|
45
|
+
interface KpiContextValue {
|
|
46
|
+
tone: KpiTone;
|
|
47
|
+
dot: boolean;
|
|
48
|
+
classNames: ClassNames<KpiPart> | undefined;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const KpiContext = createContext<KpiContextValue>({
|
|
52
|
+
tone: "neutral",
|
|
53
|
+
dot: false,
|
|
54
|
+
classNames: undefined,
|
|
55
|
+
});
|
|
56
|
+
|
|
44
57
|
export interface KpiProps extends Omit<ComponentPropsWithoutRef<"div">, "children"> {
|
|
45
|
-
/** Short label describing the metric. */
|
|
46
|
-
label
|
|
47
|
-
/** Highlighted number, already formatted by the consumer. */
|
|
48
|
-
value
|
|
58
|
+
/** Short label describing the metric. Optional when you compose `Kpi.Label` as children. */
|
|
59
|
+
label?: ReactNode;
|
|
60
|
+
/** Highlighted number, already formatted by the consumer. Optional when you compose `Kpi.Value`. */
|
|
61
|
+
value?: ReactNode;
|
|
49
62
|
/** Small suffix next to the number, e.g. "/12". */
|
|
50
63
|
suffix?: ReactNode;
|
|
51
64
|
/** Optional subtext. */
|
|
@@ -55,43 +68,54 @@ export interface KpiProps extends Omit<ComponentPropsWithoutRef<"div">, "childre
|
|
|
55
68
|
tone?: KpiTone;
|
|
56
69
|
/** Leading dot on the label, in the tone's colour. */
|
|
57
70
|
dot?: boolean;
|
|
58
|
-
/**
|
|
71
|
+
/** Decorative icon at the end of the label row (`aria-hidden`). */
|
|
59
72
|
icon?: ReactNode;
|
|
73
|
+
/** Interactive or labelled content at the end of the label row (a menu, a link); not hidden from assistive tech. */
|
|
74
|
+
trailing?: ReactNode;
|
|
60
75
|
/** Change indicator next to the value, e.g. a `TrendChip`. */
|
|
61
76
|
trend?: ReactNode;
|
|
77
|
+
/** Draws the tile as a card: border and radius. Off by default, so tiles in a `KpiGroup` stay flush. */
|
|
78
|
+
card?: boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Compose the tile from `Kpi.Label`, `Kpi.Value` and `Kpi.Description` instead of (or after)
|
|
81
|
+
* the props. They are laid out in the tile's column in the order written.
|
|
82
|
+
*/
|
|
83
|
+
children?: ReactNode;
|
|
62
84
|
/** Per-part classes merged with `cn`; consumer classes win. `className` still targets the root and is merged last. */
|
|
63
85
|
classNames?: ClassNames<KpiPart>;
|
|
64
86
|
}
|
|
65
87
|
|
|
66
|
-
export
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
88
|
+
export interface KpiLabelProps extends ComponentPropsWithoutRef<"span"> {
|
|
89
|
+
/** Decorative icon at the end of the row (`aria-hidden`). */
|
|
90
|
+
icon?: ReactNode;
|
|
91
|
+
/** Interactive or labelled content at the end of the row. */
|
|
92
|
+
trailing?: ReactNode;
|
|
93
|
+
/** Overrides the tile's `dot`. */
|
|
94
|
+
dot?: boolean;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** Label row of a composed `Kpi`: the label, then an optional icon and trailing slot at the end. */
|
|
98
|
+
export function KpiLabel({
|
|
74
99
|
icon,
|
|
75
|
-
|
|
100
|
+
trailing,
|
|
101
|
+
dot: dotProp,
|
|
76
102
|
className,
|
|
77
|
-
|
|
78
|
-
style,
|
|
103
|
+
children,
|
|
79
104
|
...props
|
|
80
|
-
}:
|
|
81
|
-
const tone:
|
|
82
|
-
const
|
|
83
|
-
const
|
|
84
|
-
? "text-(--tone-c-ink)"
|
|
85
|
-
: (valueToneClasses[tone as KpiBuiltinTone] ?? valueToneClasses.neutral);
|
|
86
|
-
const dotTone = custom
|
|
105
|
+
}: KpiLabelProps) {
|
|
106
|
+
const { tone, dot: tileDot, classNames } = useContext(KpiContext);
|
|
107
|
+
const dot = dotProp ?? tileDot;
|
|
108
|
+
const dotTone = isCustomTone(tone, builtinTones)
|
|
87
109
|
? "bg-(--tone-c)"
|
|
88
110
|
: (dotToneClasses[tone as KpiBuiltinTone] ?? dotToneClasses.neutral);
|
|
89
111
|
const labelNode = (
|
|
90
112
|
<span
|
|
113
|
+
{...props}
|
|
91
114
|
className={cn(
|
|
92
|
-
"break-words font-semibold text-fs-120 text-ink-2",
|
|
115
|
+
"min-w-0 break-words font-semibold text-fs-120 text-ink-2",
|
|
93
116
|
dot && "inline-flex items-center gap-1.5",
|
|
94
117
|
classNames?.label,
|
|
118
|
+
className,
|
|
95
119
|
)}
|
|
96
120
|
>
|
|
97
121
|
{dot ? (
|
|
@@ -100,18 +124,55 @@ export function Kpi({
|
|
|
100
124
|
className={cn("size-1.5 shrink-0 rounded-pill", dotTone, classNames?.dot)}
|
|
101
125
|
/>
|
|
102
126
|
) : null}
|
|
103
|
-
{
|
|
127
|
+
{children}
|
|
104
128
|
</span>
|
|
105
129
|
);
|
|
130
|
+
if (!icon && !trailing) return labelNode;
|
|
131
|
+
return (
|
|
132
|
+
<div className={cn("flex items-center justify-between gap-2", classNames?.header)}>
|
|
133
|
+
{labelNode}
|
|
134
|
+
<span className="flex shrink-0 items-center gap-1.5">
|
|
135
|
+
{icon ? (
|
|
136
|
+
<span
|
|
137
|
+
aria-hidden="true"
|
|
138
|
+
className={cn("shrink-0 text-ink-3 [&_svg]:size-4", classNames?.icon)}
|
|
139
|
+
>
|
|
140
|
+
{icon}
|
|
141
|
+
</span>
|
|
142
|
+
) : null}
|
|
143
|
+
{trailing ? <span className={cn("shrink-0", classNames?.trailing)}>{trailing}</span> : null}
|
|
144
|
+
</span>
|
|
145
|
+
</div>
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export interface KpiValueProps extends ComponentPropsWithoutRef<"span"> {
|
|
150
|
+
/** Small suffix next to the number. */
|
|
151
|
+
suffix?: ReactNode;
|
|
152
|
+
/** Change indicator next to the value. */
|
|
153
|
+
trend?: ReactNode;
|
|
154
|
+
/** Monospaced digits at a steady weight, for amounts and codes. */
|
|
155
|
+
mono?: boolean;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** The highlighted number of a composed `Kpi`, coloured by the tile's tone. */
|
|
159
|
+
export function KpiValue({ suffix, trend, mono, className, children, ...props }: KpiValueProps) {
|
|
160
|
+
const { tone, classNames } = useContext(KpiContext);
|
|
161
|
+
const valueTone = isCustomTone(tone, builtinTones)
|
|
162
|
+
? "text-(--tone-c-ink)"
|
|
163
|
+
: (valueToneClasses[tone as KpiBuiltinTone] ?? valueToneClasses.neutral);
|
|
106
164
|
const valueNode = (
|
|
107
165
|
<span
|
|
166
|
+
{...props}
|
|
108
167
|
className={cn(
|
|
109
168
|
"break-words text-kpi-number tabular-nums @max-[9rem]/kpi:text-fs-220",
|
|
169
|
+
mono && "font-mono tracking-normal",
|
|
110
170
|
valueTone,
|
|
111
171
|
classNames?.value,
|
|
172
|
+
className,
|
|
112
173
|
)}
|
|
113
174
|
>
|
|
114
|
-
{
|
|
175
|
+
{children}
|
|
115
176
|
{suffix ? (
|
|
116
177
|
<small
|
|
117
178
|
className={cn(
|
|
@@ -124,42 +185,80 @@ export function Kpi({
|
|
|
124
185
|
) : null}
|
|
125
186
|
</span>
|
|
126
187
|
);
|
|
188
|
+
if (!trend) return valueNode;
|
|
127
189
|
return (
|
|
128
|
-
<div
|
|
129
|
-
{
|
|
130
|
-
|
|
131
|
-
className={cn(
|
|
132
|
-
"@container/kpi flex min-w-0 flex-col gap-0.5 bg-surface px-4.5 py-3.5",
|
|
133
|
-
classNames?.root,
|
|
134
|
-
className,
|
|
135
|
-
)}
|
|
136
|
-
>
|
|
137
|
-
{icon ? (
|
|
138
|
-
<div className={cn("flex items-center justify-between gap-2", classNames?.header)}>
|
|
139
|
-
{labelNode}
|
|
140
|
-
<span
|
|
141
|
-
aria-hidden="true"
|
|
142
|
-
className={cn("shrink-0 text-ink-3 [&_svg]:size-4", classNames?.icon)}
|
|
143
|
-
>
|
|
144
|
-
{icon}
|
|
145
|
-
</span>
|
|
146
|
-
</div>
|
|
147
|
-
) : (
|
|
148
|
-
labelNode
|
|
149
|
-
)}
|
|
150
|
-
{trend ? (
|
|
151
|
-
<div className="flex flex-wrap items-baseline gap-x-2 gap-y-1">
|
|
152
|
-
{valueNode}
|
|
153
|
-
<span className={cn("shrink-0", classNames?.trend)}>{trend}</span>
|
|
154
|
-
</div>
|
|
155
|
-
) : (
|
|
156
|
-
valueNode
|
|
157
|
-
)}
|
|
158
|
-
{description ? (
|
|
159
|
-
<span className={cn("break-words text-fs-120 text-ink-3", classNames?.description)}>
|
|
160
|
-
{description}
|
|
161
|
-
</span>
|
|
162
|
-
) : null}
|
|
190
|
+
<div className="flex flex-wrap items-baseline gap-x-2 gap-y-1">
|
|
191
|
+
{valueNode}
|
|
192
|
+
<span className={cn("shrink-0", classNames?.trend)}>{trend}</span>
|
|
163
193
|
</div>
|
|
164
194
|
);
|
|
165
195
|
}
|
|
196
|
+
|
|
197
|
+
export interface KpiDescriptionProps extends ComponentPropsWithoutRef<"span"> {}
|
|
198
|
+
|
|
199
|
+
export function KpiDescription({ className, ...props }: KpiDescriptionProps) {
|
|
200
|
+
const { classNames } = useContext(KpiContext);
|
|
201
|
+
return (
|
|
202
|
+
<span
|
|
203
|
+
{...props}
|
|
204
|
+
className={cn("break-words text-fs-120 text-ink-3", classNames?.description, className)}
|
|
205
|
+
/>
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* One metric: a label, a big number and an optional description. Fill it with props, or compose
|
|
211
|
+
* `Kpi.Label`, `Kpi.Value` and `Kpi.Description` as children when the parts need their own
|
|
212
|
+
* slots (a menu beside the label, a monospaced amount). `card` adds a border and radius.
|
|
213
|
+
*/
|
|
214
|
+
export function Kpi({
|
|
215
|
+
label,
|
|
216
|
+
value,
|
|
217
|
+
suffix,
|
|
218
|
+
description,
|
|
219
|
+
variant = "default",
|
|
220
|
+
tone: toneProp,
|
|
221
|
+
dot = false,
|
|
222
|
+
icon,
|
|
223
|
+
trailing,
|
|
224
|
+
trend,
|
|
225
|
+
card = false,
|
|
226
|
+
children,
|
|
227
|
+
className,
|
|
228
|
+
classNames,
|
|
229
|
+
style,
|
|
230
|
+
...props
|
|
231
|
+
}: KpiProps) {
|
|
232
|
+
const tone: KpiTone = toneProp ?? (variant === "danger" ? "danger" : "neutral");
|
|
233
|
+
return (
|
|
234
|
+
<KpiContext.Provider value={{ tone, dot, classNames }}>
|
|
235
|
+
<div
|
|
236
|
+
{...props}
|
|
237
|
+
style={customToneStyle(tone, builtinTones, style)}
|
|
238
|
+
className={cn(
|
|
239
|
+
"@container/kpi flex min-w-0 flex-col gap-0.5 bg-surface px-4.5 py-3.5",
|
|
240
|
+
card && "rounded-card border border-line",
|
|
241
|
+
classNames?.root,
|
|
242
|
+
className,
|
|
243
|
+
)}
|
|
244
|
+
>
|
|
245
|
+
{label !== undefined ? (
|
|
246
|
+
<KpiLabel icon={icon} trailing={trailing}>
|
|
247
|
+
{label}
|
|
248
|
+
</KpiLabel>
|
|
249
|
+
) : null}
|
|
250
|
+
{value !== undefined ? (
|
|
251
|
+
<KpiValue suffix={suffix} trend={trend}>
|
|
252
|
+
{value}
|
|
253
|
+
</KpiValue>
|
|
254
|
+
) : null}
|
|
255
|
+
{description ? <KpiDescription>{description}</KpiDescription> : null}
|
|
256
|
+
{children}
|
|
257
|
+
</div>
|
|
258
|
+
</KpiContext.Provider>
|
|
259
|
+
);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
Kpi.Label = KpiLabel;
|
|
263
|
+
Kpi.Value = KpiValue;
|
|
264
|
+
Kpi.Description = KpiDescription;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export {
|
|
2
|
+
ListDetail,
|
|
3
|
+
ListDetailDetail,
|
|
4
|
+
ListDetailDetailHeader,
|
|
5
|
+
type ListDetailDetailHeaderProps,
|
|
6
|
+
type ListDetailDetailProps,
|
|
7
|
+
ListDetailItem,
|
|
8
|
+
type ListDetailItemProps,
|
|
9
|
+
ListDetailList,
|
|
10
|
+
type ListDetailListProps,
|
|
11
|
+
ListDetailMeta,
|
|
12
|
+
type ListDetailProps,
|
|
13
|
+
ListDetailTitle,
|
|
14
|
+
useListDetail,
|
|
15
|
+
} from "./list-detail.js";
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
type ComponentPropsWithoutRef,
|
|
5
|
+
createContext,
|
|
6
|
+
type ReactNode,
|
|
7
|
+
useCallback,
|
|
8
|
+
useContext,
|
|
9
|
+
useEffect,
|
|
10
|
+
useId,
|
|
11
|
+
useLayoutEffect,
|
|
12
|
+
useMemo,
|
|
13
|
+
useRef,
|
|
14
|
+
useState,
|
|
15
|
+
} from "react";
|
|
16
|
+
import { useUiStrings } from "../../i18n/index.js";
|
|
17
|
+
import { ChevronLeft } from "../../icons/index.js";
|
|
18
|
+
import { cn } from "../../utils/cn.js";
|
|
19
|
+
import { composeHandlers } from "../../utils/compose.js";
|
|
20
|
+
import { useControllableState } from "../../utils/use-controllable-state.js";
|
|
21
|
+
|
|
22
|
+
interface ListDetailContextValue {
|
|
23
|
+
value: string | null;
|
|
24
|
+
select: (value: string | null) => void;
|
|
25
|
+
label: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const ListDetailContext = createContext<ListDetailContextValue | null>(null);
|
|
29
|
+
|
|
30
|
+
function useListDetailContext(part: string): ListDetailContextValue {
|
|
31
|
+
const context = useContext(ListDetailContext);
|
|
32
|
+
if (!context) throw new Error(`\`${part}\` must be used within \`ListDetail\``);
|
|
33
|
+
return context;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** The selected item id (`null` while none) and a way to change it, for content inside the detail pane. */
|
|
37
|
+
export function useListDetail() {
|
|
38
|
+
const { value, select } = useListDetailContext("useListDetail");
|
|
39
|
+
return { value, select, isSelected: (candidate: string) => candidate === value };
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface ListDetailProps
|
|
43
|
+
extends Omit<ComponentPropsWithoutRef<"div">, "defaultValue" | "onChange"> {
|
|
44
|
+
/** Controlled selected item id; `null` means none (the single-pane view then shows the list). */
|
|
45
|
+
value?: string | null | undefined;
|
|
46
|
+
defaultValue?: string | null | undefined;
|
|
47
|
+
/**
|
|
48
|
+
* Called with the id the user chose. It is never called with `null`: going back to the list
|
|
49
|
+
* calls `onBack` instead, so a handler that loads the selected record never sees "no record".
|
|
50
|
+
*/
|
|
51
|
+
onValueChange?: ((value: string) => void) | undefined;
|
|
52
|
+
/**
|
|
53
|
+
* Called when the back action (or `select(null)` from `useListDetail`) clears the selection.
|
|
54
|
+
* Uncontrolled, the list shows again on its own; controlled, set `value` to `null` here.
|
|
55
|
+
*/
|
|
56
|
+
onBack?: (() => void) | undefined;
|
|
57
|
+
/** Names the list of items. */
|
|
58
|
+
"aria-label": string;
|
|
59
|
+
children: ReactNode;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Master-detail: a list of items beside the detail of the selected one. Under 641px of its own
|
|
64
|
+
* width it collapses to a single pane: the list until an item is chosen, then the detail with a
|
|
65
|
+
* back action (focus follows the change). Panes render flush to the container's inline edges.
|
|
66
|
+
*/
|
|
67
|
+
export function ListDetail({
|
|
68
|
+
value: valueProp,
|
|
69
|
+
defaultValue = null,
|
|
70
|
+
onValueChange,
|
|
71
|
+
onBack,
|
|
72
|
+
"aria-label": label,
|
|
73
|
+
className,
|
|
74
|
+
children,
|
|
75
|
+
...props
|
|
76
|
+
}: ListDetailProps) {
|
|
77
|
+
const [value, setValue] = useControllableState<string | null>({
|
|
78
|
+
prop: valueProp,
|
|
79
|
+
defaultProp: defaultValue,
|
|
80
|
+
onChange: (next) => {
|
|
81
|
+
if (next !== null) onValueChange?.(next);
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
const onBackRef = useRef(onBack);
|
|
85
|
+
onBackRef.current = onBack;
|
|
86
|
+
const select = useCallback(
|
|
87
|
+
(next: string | null) => {
|
|
88
|
+
setValue(next);
|
|
89
|
+
if (next === null) onBackRef.current?.();
|
|
90
|
+
},
|
|
91
|
+
[setValue],
|
|
92
|
+
);
|
|
93
|
+
const rootRef = useRef<HTMLDivElement>(null);
|
|
94
|
+
const previous = useRef<string | null>(value);
|
|
95
|
+
|
|
96
|
+
useEffect(() => {
|
|
97
|
+
const before = previous.current;
|
|
98
|
+
previous.current = value;
|
|
99
|
+
const root = rootRef.current;
|
|
100
|
+
if (before === value || !root) return;
|
|
101
|
+
if (value === null && before !== null) {
|
|
102
|
+
root.querySelector<HTMLElement>(`[data-list-detail-item="${CSS.escape(before)}"]`)?.focus();
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
const detail = root.querySelector<HTMLElement>('[data-list-detail-pane="detail"]');
|
|
106
|
+
// Only when the detail replaced the list (single pane): beside the list, focus stays put.
|
|
107
|
+
const back = detail?.querySelector<HTMLElement>("[data-list-detail-back]");
|
|
108
|
+
if (detail && back && back.getClientRects().length > 0) detail.focus();
|
|
109
|
+
}, [value]);
|
|
110
|
+
|
|
111
|
+
const context = useMemo(() => ({ value, select, label }), [value, select, label]);
|
|
112
|
+
|
|
113
|
+
return (
|
|
114
|
+
<ListDetailContext.Provider value={context}>
|
|
115
|
+
<div {...props} ref={rootRef} className={cn("@container/list-detail min-w-0", className)}>
|
|
116
|
+
<div
|
|
117
|
+
data-view={value === null ? "list" : "detail"}
|
|
118
|
+
className={cn(
|
|
119
|
+
"group/ld grid grid-cols-1 border-t-divider",
|
|
120
|
+
"@min-[641px]/list-detail:grid-cols-2",
|
|
121
|
+
"[&>*]:min-w-0",
|
|
122
|
+
)}
|
|
123
|
+
>
|
|
124
|
+
{children}
|
|
125
|
+
</div>
|
|
126
|
+
</div>
|
|
127
|
+
</ListDetailContext.Provider>
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export type ListDetailListProps = Omit<ComponentPropsWithoutRef<"ul">, "aria-label">;
|
|
132
|
+
|
|
133
|
+
export function ListDetailList({ className, ...props }: ListDetailListProps) {
|
|
134
|
+
const { label } = useListDetailContext("ListDetailList");
|
|
135
|
+
return (
|
|
136
|
+
<ul
|
|
137
|
+
data-list-detail-pane="list"
|
|
138
|
+
aria-label={label}
|
|
139
|
+
className={cn(
|
|
140
|
+
"m-0 flex list-none flex-col p-0",
|
|
141
|
+
"@min-[641px]/list-detail:border-r-divider",
|
|
142
|
+
"group-data-[view=detail]/ld:@max-[640px]/list-detail:hidden",
|
|
143
|
+
className,
|
|
144
|
+
)}
|
|
145
|
+
{...props}
|
|
146
|
+
/>
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export interface ListDetailItemProps extends Omit<ComponentPropsWithoutRef<"button">, "value"> {
|
|
151
|
+
value: string;
|
|
152
|
+
/** End slot: a count, a status chip, a time. */
|
|
153
|
+
trailing?: ReactNode;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export function ListDetailItem({
|
|
157
|
+
value,
|
|
158
|
+
trailing,
|
|
159
|
+
className,
|
|
160
|
+
children,
|
|
161
|
+
onClick,
|
|
162
|
+
...props
|
|
163
|
+
}: ListDetailItemProps) {
|
|
164
|
+
const { value: selected, select } = useListDetailContext("ListDetailItem");
|
|
165
|
+
const isSelected = selected === value;
|
|
166
|
+
return (
|
|
167
|
+
<li>
|
|
168
|
+
<button
|
|
169
|
+
type="button"
|
|
170
|
+
data-list-detail-item={value}
|
|
171
|
+
aria-current={isSelected ? "true" : undefined}
|
|
172
|
+
onClick={composeHandlers(onClick, () => select(value))}
|
|
173
|
+
className={cn(
|
|
174
|
+
"grid min-h-11 w-full cursor-pointer grid-cols-[minmax(0,1fr)_auto] items-center gap-3 border-b-divider py-2.5 text-start hover:bg-surface-2 focus-visible:-outline-offset-2 focus-visible:focus-ring aria-[current=true]:bg-accent-soft",
|
|
175
|
+
className,
|
|
176
|
+
)}
|
|
177
|
+
{...props}
|
|
178
|
+
>
|
|
179
|
+
<span className="min-w-0">{children}</span>
|
|
180
|
+
{trailing !== undefined ? (
|
|
181
|
+
<span className="min-w-0 justify-self-end">{trailing}</span>
|
|
182
|
+
) : null}
|
|
183
|
+
</button>
|
|
184
|
+
</li>
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export function ListDetailTitle({ className, ...props }: ComponentPropsWithoutRef<"span">) {
|
|
189
|
+
return <span className={cn("block font-medium text-ink", className)} {...props} />;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export function ListDetailMeta({ className, ...props }: ComponentPropsWithoutRef<"span">) {
|
|
193
|
+
return <span className={cn("block text-meta text-ink-3", className)} {...props} />;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
interface DetailTitleValue {
|
|
197
|
+
titleId: string;
|
|
198
|
+
register: () => () => void;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
const DetailTitleContext = createContext<DetailTitleValue | null>(null);
|
|
202
|
+
|
|
203
|
+
export interface ListDetailDetailProps extends ComponentPropsWithoutRef<"section"> {
|
|
204
|
+
/** Label of the back action shown in the single-pane view. Defaults to the localized "Back to list". */
|
|
205
|
+
backLabel?: string;
|
|
206
|
+
/** Hides the back action (the consumer then provides its own way back). */
|
|
207
|
+
hideBack?: boolean;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/** The detail pane. A labelled region named by its `ListDetailDetailHeader` title or an `aria-label`. */
|
|
211
|
+
export function ListDetailDetail({
|
|
212
|
+
backLabel,
|
|
213
|
+
hideBack = false,
|
|
214
|
+
className,
|
|
215
|
+
children,
|
|
216
|
+
...props
|
|
217
|
+
}: ListDetailDetailProps) {
|
|
218
|
+
const strings = useUiStrings();
|
|
219
|
+
const { select } = useListDetailContext("ListDetailDetail");
|
|
220
|
+
const titleId = useId();
|
|
221
|
+
const [titled, setTitled] = useState(0);
|
|
222
|
+
const register = useCallback(() => {
|
|
223
|
+
setTitled((count) => count + 1);
|
|
224
|
+
return () => setTitled((count) => count - 1);
|
|
225
|
+
}, []);
|
|
226
|
+
const context = useMemo(() => ({ titleId, register }), [titleId, register]);
|
|
227
|
+
return (
|
|
228
|
+
<DetailTitleContext.Provider value={context}>
|
|
229
|
+
<section
|
|
230
|
+
data-list-detail-pane="detail"
|
|
231
|
+
tabIndex={-1}
|
|
232
|
+
aria-labelledby={titled > 0 && props["aria-label"] === undefined ? titleId : undefined}
|
|
233
|
+
{...props}
|
|
234
|
+
className={cn(
|
|
235
|
+
"flex min-w-0 flex-col outline-none",
|
|
236
|
+
"group-data-[view=list]/ld:@max-[640px]/list-detail:hidden",
|
|
237
|
+
className,
|
|
238
|
+
)}
|
|
239
|
+
>
|
|
240
|
+
{hideBack ? null : (
|
|
241
|
+
<button
|
|
242
|
+
type="button"
|
|
243
|
+
data-list-detail-back=""
|
|
244
|
+
onClick={() => select(null)}
|
|
245
|
+
className={cn(
|
|
246
|
+
"inline-flex min-h-11 cursor-pointer items-center gap-1 self-start text-control text-ink-2 hover:text-ink focus-visible:focus-ring",
|
|
247
|
+
"@min-[641px]/list-detail:hidden",
|
|
248
|
+
)}
|
|
249
|
+
>
|
|
250
|
+
<ChevronLeft aria-hidden="true" className="size-4" />
|
|
251
|
+
{backLabel ?? strings.backToList}
|
|
252
|
+
</button>
|
|
253
|
+
)}
|
|
254
|
+
{children}
|
|
255
|
+
</section>
|
|
256
|
+
</DetailTitleContext.Provider>
|
|
257
|
+
);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
export interface ListDetailDetailHeaderProps
|
|
261
|
+
extends Omit<ComponentPropsWithoutRef<"div">, "title"> {
|
|
262
|
+
title: ReactNode;
|
|
263
|
+
description?: ReactNode;
|
|
264
|
+
actions?: ReactNode;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
export function ListDetailDetailHeader({
|
|
268
|
+
title,
|
|
269
|
+
description,
|
|
270
|
+
actions,
|
|
271
|
+
className,
|
|
272
|
+
...props
|
|
273
|
+
}: ListDetailDetailHeaderProps) {
|
|
274
|
+
const detail = useContext(DetailTitleContext);
|
|
275
|
+
const register = detail?.register;
|
|
276
|
+
useLayoutEffect(() => register?.(), [register]);
|
|
277
|
+
return (
|
|
278
|
+
<div
|
|
279
|
+
className={cn("flex flex-wrap items-start justify-between gap-3 pt-4 pb-3", className)}
|
|
280
|
+
{...props}
|
|
281
|
+
>
|
|
282
|
+
<div className="min-w-0">
|
|
283
|
+
<h3 id={detail?.titleId} className="m-0 font-semibold text-body text-ink">
|
|
284
|
+
{title}
|
|
285
|
+
</h3>
|
|
286
|
+
{description !== undefined ? (
|
|
287
|
+
<p className="m-0 mt-0.5 text-meta text-ink-3">{description}</p>
|
|
288
|
+
) : null}
|
|
289
|
+
</div>
|
|
290
|
+
{actions !== undefined ? <div className="flex flex-wrap gap-2">{actions}</div> : null}
|
|
291
|
+
</div>
|
|
292
|
+
);
|
|
293
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Note, type NoteProps, type NoteTone } from "./note.js";
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { ComponentPropsWithoutRef } from "react";
|
|
2
|
+
import { cn } from "../../utils/cn.js";
|
|
3
|
+
|
|
4
|
+
export type NoteTone = "neutral" | "info" | "success" | "warning" | "danger";
|
|
5
|
+
|
|
6
|
+
const toneClasses: Record<NoteTone, string> = {
|
|
7
|
+
neutral: "text-ink-3",
|
|
8
|
+
info: "text-info",
|
|
9
|
+
success: "text-success",
|
|
10
|
+
warning: "text-warning",
|
|
11
|
+
danger: "text-danger",
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export interface NoteProps extends ComponentPropsWithoutRef<"p"> {
|
|
15
|
+
/** Colors the text. Defaults to `neutral`. */
|
|
16
|
+
tone?: NoteTone;
|
|
17
|
+
/** Hairline above the note, to hang it under a block it explains. */
|
|
18
|
+
divider?: boolean;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Small annotated text under a block: explains a rule, a caveat or an empty state. Flush to its
|
|
23
|
+
* container's inline edges; tone only changes the text color, so it never carries meaning alone.
|
|
24
|
+
*/
|
|
25
|
+
export function Note({ tone = "neutral", divider = false, className, ...props }: NoteProps) {
|
|
26
|
+
return (
|
|
27
|
+
<p
|
|
28
|
+
data-tone={tone}
|
|
29
|
+
className={cn(
|
|
30
|
+
"m-0 text-meta",
|
|
31
|
+
divider && "border-t-divider pt-2.5",
|
|
32
|
+
toneClasses[tone],
|
|
33
|
+
className,
|
|
34
|
+
)}
|
|
35
|
+
{...props}
|
|
36
|
+
/>
|
|
37
|
+
);
|
|
38
|
+
}
|