@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
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { type ReactNode, useId, useMemo } from "react";
|
|
2
|
+
import { Check } from "../../icons/index.js";
|
|
3
|
+
import { cn } from "../../utils/cn.js";
|
|
4
|
+
import { isGroup, type ListboxItem, type ListboxOption } from "./listbox.js";
|
|
5
|
+
|
|
6
|
+
export const LISTBOX_SURFACE =
|
|
7
|
+
"z-85 min-w-(--ui-popper-anchor-width) max-h-[min(20rem,var(--ui-popper-available-height))] max-w-(--ui-popper-available-width) overflow-y-auto overscroll-contain rounded-popover surface-overlay p-1.5 text-ink shadow-overlay";
|
|
8
|
+
|
|
9
|
+
const OPTION =
|
|
10
|
+
"flex min-h-[max(2rem,var(--touch-target))] w-full cursor-pointer items-center gap-2 rounded-event px-2.5 py-1.5 text-body text-ink outline-none data-[highlighted]:bg-surface-2 data-[disabled]:cursor-not-allowed data-[disabled]:opacity-50";
|
|
11
|
+
|
|
12
|
+
export function optionDomId(base: string, index: number): string {
|
|
13
|
+
return `${base}-opt-${index}`;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface ListboxItemsProps<O extends ListboxOption> {
|
|
17
|
+
items: readonly ListboxItem<O>[];
|
|
18
|
+
/** Options in display order; an option's position here is its id and `activeIndex` slot. */
|
|
19
|
+
flat: readonly O[];
|
|
20
|
+
idBase: string;
|
|
21
|
+
isSelected: (option: O) => boolean;
|
|
22
|
+
activeIndex: number;
|
|
23
|
+
onActivate: (index: number) => void;
|
|
24
|
+
onPick: (option: O) => void;
|
|
25
|
+
optionClassName?: string | undefined;
|
|
26
|
+
groupClassName?: string | undefined;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Renders options (and optional group headings) with the WAI-ARIA listbox roles. */
|
|
30
|
+
export function ListboxItems<O extends ListboxOption>({
|
|
31
|
+
items,
|
|
32
|
+
flat,
|
|
33
|
+
idBase,
|
|
34
|
+
isSelected,
|
|
35
|
+
activeIndex,
|
|
36
|
+
onActivate,
|
|
37
|
+
onPick,
|
|
38
|
+
optionClassName,
|
|
39
|
+
groupClassName,
|
|
40
|
+
}: ListboxItemsProps<O>): ReactNode {
|
|
41
|
+
const headingBase = useId();
|
|
42
|
+
const indexes = useMemo(() => new Map(flat.map((option, index) => [option, index])), [flat]);
|
|
43
|
+
|
|
44
|
+
const renderOption = (option: O) => {
|
|
45
|
+
const index = indexes.get(option) ?? -1;
|
|
46
|
+
const selected = isSelected(option);
|
|
47
|
+
return (
|
|
48
|
+
// biome-ignore lint/a11y/useFocusableInteractive: options are never focused; the owner keeps focus and points at one with aria-activedescendant.
|
|
49
|
+
// biome-ignore lint/a11y/useKeyWithClickEvents: the owner (trigger or input) handles every key.
|
|
50
|
+
<div
|
|
51
|
+
key={`${index}-${option.value}`}
|
|
52
|
+
id={optionDomId(idBase, index)}
|
|
53
|
+
role="option"
|
|
54
|
+
aria-selected={selected}
|
|
55
|
+
aria-disabled={option.disabled || undefined}
|
|
56
|
+
data-selected={selected ? "" : undefined}
|
|
57
|
+
data-disabled={option.disabled ? "" : undefined}
|
|
58
|
+
data-highlighted={index === activeIndex ? "" : undefined}
|
|
59
|
+
// Focus stays on the trigger or the input; the press must not move it.
|
|
60
|
+
onPointerDown={(event) => event.preventDefault()}
|
|
61
|
+
onMouseDown={(event) => event.preventDefault()}
|
|
62
|
+
onPointerMove={() => {
|
|
63
|
+
if (!option.disabled && index !== activeIndex) onActivate(index);
|
|
64
|
+
}}
|
|
65
|
+
onClick={() => {
|
|
66
|
+
if (!option.disabled) onPick(option);
|
|
67
|
+
}}
|
|
68
|
+
className={cn(OPTION, optionClassName)}
|
|
69
|
+
>
|
|
70
|
+
<span className="flex min-w-0 flex-1 flex-col">
|
|
71
|
+
<span className={cn("truncate", selected && "font-semibold")}>{option.label}</span>
|
|
72
|
+
{option.description ? (
|
|
73
|
+
<span className="truncate text-ink-3 text-meta">{option.description}</span>
|
|
74
|
+
) : null}
|
|
75
|
+
</span>
|
|
76
|
+
{selected ? (
|
|
77
|
+
<Check aria-hidden="true" className="size-3.5 shrink-0 text-accent-ink" />
|
|
78
|
+
) : null}
|
|
79
|
+
</div>
|
|
80
|
+
);
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
return items.map((item, position) => {
|
|
84
|
+
if (!isGroup(item)) return renderOption(item);
|
|
85
|
+
const headingId = `${headingBase}-g${position}`;
|
|
86
|
+
return (
|
|
87
|
+
// biome-ignore lint/a11y/useSemanticElements: a fieldset inside a listbox breaks the listbox > group > option structure.
|
|
88
|
+
<div key={`group-${item.label}`} role="group" aria-labelledby={headingId}>
|
|
89
|
+
<div
|
|
90
|
+
id={headingId}
|
|
91
|
+
role="presentation"
|
|
92
|
+
className={cn(
|
|
93
|
+
"px-2.5 pt-2 pb-1 font-semibold text-ink-3 text-meta uppercase tracking-wide",
|
|
94
|
+
groupClassName,
|
|
95
|
+
)}
|
|
96
|
+
>
|
|
97
|
+
{item.label}
|
|
98
|
+
</div>
|
|
99
|
+
{item.options.map(renderOption)}
|
|
100
|
+
</div>
|
|
101
|
+
);
|
|
102
|
+
});
|
|
103
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/** Pure rules shared by `SelectMenu` and `Combobox`: option shapes, navigation, typeahead and filtering. */
|
|
2
|
+
|
|
3
|
+
export interface ListboxOption {
|
|
4
|
+
value: string;
|
|
5
|
+
label: string;
|
|
6
|
+
description?: string;
|
|
7
|
+
disabled?: boolean;
|
|
8
|
+
/** Extra words matched by a `Combobox` search, never shown. */
|
|
9
|
+
keywords?: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface ListboxGroup<O extends ListboxOption = ListboxOption> {
|
|
13
|
+
label: string;
|
|
14
|
+
options: O[];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export type ListboxItem<O extends ListboxOption = ListboxOption> = O | ListboxGroup<O>;
|
|
18
|
+
|
|
19
|
+
export function isGroup<O extends ListboxOption>(item: ListboxItem<O>): item is ListboxGroup<O> {
|
|
20
|
+
return "options" in item;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Options in display order with the group headings removed. */
|
|
24
|
+
export function flattenItems<O extends ListboxOption>(items: readonly ListboxItem<O>[]): O[] {
|
|
25
|
+
return items.flatMap((item) => (isGroup(item) ? item.options : [item]));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export type ListboxMove = "next" | "prev" | "first" | "last";
|
|
29
|
+
|
|
30
|
+
/** Index of the enabled option a key moves to, or `current` when nothing is reachable. The list does not wrap. */
|
|
31
|
+
export function moveActive(
|
|
32
|
+
options: readonly ListboxOption[],
|
|
33
|
+
current: number,
|
|
34
|
+
move: ListboxMove,
|
|
35
|
+
): number {
|
|
36
|
+
const enabled = (index: number) => options[index] !== undefined && !options[index]?.disabled;
|
|
37
|
+
if (move === "first") {
|
|
38
|
+
for (let i = 0; i < options.length; i++) if (enabled(i)) return i;
|
|
39
|
+
return current;
|
|
40
|
+
}
|
|
41
|
+
if (move === "last") {
|
|
42
|
+
for (let i = options.length - 1; i >= 0; i--) if (enabled(i)) return i;
|
|
43
|
+
return current;
|
|
44
|
+
}
|
|
45
|
+
const step = move === "next" ? 1 : -1;
|
|
46
|
+
for (let i = current + step; i >= 0 && i < options.length; i += step) if (enabled(i)) return i;
|
|
47
|
+
return current;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const fold = (text: string) => text.normalize("NFD").replace(/\p{M}/gu, "").toLocaleLowerCase();
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Option a typed prefix lands on. A single repeated character cycles through the options that
|
|
54
|
+
* start with it; a longer prefix keeps matching from the active option.
|
|
55
|
+
*/
|
|
56
|
+
export function typeaheadIndex(
|
|
57
|
+
options: readonly ListboxOption[],
|
|
58
|
+
query: string,
|
|
59
|
+
active: number,
|
|
60
|
+
): number {
|
|
61
|
+
if (!query) return -1;
|
|
62
|
+
const needle = fold(query);
|
|
63
|
+
const repeated = needle.length > 1 && [...needle].every((char) => char === needle[0]);
|
|
64
|
+
const search = repeated ? needle.slice(0, 1) : needle;
|
|
65
|
+
const start = needle.length === 1 || repeated ? active + 1 : active;
|
|
66
|
+
for (let offset = 0; offset < options.length; offset++) {
|
|
67
|
+
const index = (start + offset + options.length) % options.length;
|
|
68
|
+
const option = options[index];
|
|
69
|
+
if (option && !option.disabled && fold(option.label).startsWith(search)) return index;
|
|
70
|
+
}
|
|
71
|
+
return -1;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** Typeahead buffer: characters typed within `timeout` ms of each other form one prefix. */
|
|
75
|
+
export function nextTypeahead(
|
|
76
|
+
state: { buffer: string; at: number },
|
|
77
|
+
key: string,
|
|
78
|
+
now: number,
|
|
79
|
+
timeout = 600,
|
|
80
|
+
): { buffer: string; at: number } {
|
|
81
|
+
const buffer = now - state.at > timeout ? key : state.buffer + key;
|
|
82
|
+
return { buffer, at: now };
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** True for a key that types a character (not a shortcut or a named key). */
|
|
86
|
+
export function isTypeaheadKey(event: {
|
|
87
|
+
key: string;
|
|
88
|
+
ctrlKey: boolean;
|
|
89
|
+
metaKey: boolean;
|
|
90
|
+
altKey: boolean;
|
|
91
|
+
}): boolean {
|
|
92
|
+
return event.key.length === 1 && !event.ctrlKey && !event.metaKey && !event.altKey;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** Accent- and case-insensitive match against label, description and keywords. */
|
|
96
|
+
export function matchesQuery(option: ListboxOption, query: string): boolean {
|
|
97
|
+
const needle = fold(query.trim());
|
|
98
|
+
if (!needle) return true;
|
|
99
|
+
return fold(`${option.label} ${option.description ?? ""} ${option.keywords ?? ""}`).includes(
|
|
100
|
+
needle,
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** Keeps matching options, dropping groups left empty and capping the number of options shown. */
|
|
105
|
+
export function filterItems<O extends ListboxOption>(
|
|
106
|
+
items: readonly ListboxItem<O>[],
|
|
107
|
+
predicate: (option: O) => boolean,
|
|
108
|
+
limit = Number.POSITIVE_INFINITY,
|
|
109
|
+
): ListboxItem<O>[] {
|
|
110
|
+
let left = limit;
|
|
111
|
+
const result: ListboxItem<O>[] = [];
|
|
112
|
+
for (const item of items) {
|
|
113
|
+
if (left <= 0) break;
|
|
114
|
+
if (isGroup(item)) {
|
|
115
|
+
const options = item.options.filter(predicate).slice(0, left);
|
|
116
|
+
left -= options.length;
|
|
117
|
+
if (options.length > 0) result.push({ ...item, options });
|
|
118
|
+
} else if (predicate(item)) {
|
|
119
|
+
result.push(item);
|
|
120
|
+
left -= 1;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return result;
|
|
124
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { snapToStep } from "../slider/model.js";
|
|
2
|
+
|
|
3
|
+
/** A typed number: dot or comma decimal, `NaN` for empty or unreadable text ("", "-"). */
|
|
4
|
+
export function parseNumber(text: string): number {
|
|
5
|
+
const trimmed = text.trim().replace(",", ".");
|
|
6
|
+
return trimmed === "" ? Number.NaN : Number(trimmed);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The text after stepping `text` by `direction` steps, kept within `min`/`max` and on the step grid.
|
|
11
|
+
* An empty or unreadable text goes to `min` when there is one, else to one step in `direction`.
|
|
12
|
+
*/
|
|
13
|
+
export function stepText(
|
|
14
|
+
text: string,
|
|
15
|
+
direction: 1 | -1,
|
|
16
|
+
limits: { min: number; max: number; step: number },
|
|
17
|
+
): string {
|
|
18
|
+
const { min, max, step } = limits;
|
|
19
|
+
const parsed = parseNumber(text);
|
|
20
|
+
if (Number.isNaN(parsed)) {
|
|
21
|
+
return String(snapToStep(Number.isFinite(min) ? min : direction * step, min, max, step));
|
|
22
|
+
}
|
|
23
|
+
return String(snapToStep(parsed + direction * step, min, max, step));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Whether another step in `direction` would stay within the limits, for the buttons. */
|
|
27
|
+
export function canStep(
|
|
28
|
+
text: string,
|
|
29
|
+
direction: 1 | -1,
|
|
30
|
+
limits: { min: number; max: number },
|
|
31
|
+
): boolean {
|
|
32
|
+
const parsed = parseNumber(text);
|
|
33
|
+
if (Number.isNaN(parsed)) return true;
|
|
34
|
+
return direction === 1 ? parsed < limits.max : parsed > limits.min;
|
|
35
|
+
}
|
|
@@ -1,17 +1,22 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
type ChangeEvent,
|
|
5
|
+
type ChangeEventHandler,
|
|
6
|
+
type KeyboardEvent,
|
|
7
|
+
useId,
|
|
8
|
+
useRef,
|
|
9
|
+
useState,
|
|
10
|
+
} from "react";
|
|
4
11
|
import { Minus, Plus } from "../../icons/index.js";
|
|
5
12
|
import type { ClassNames } from "../../utils/class-names.js";
|
|
6
13
|
import { cn } from "../../utils/cn.js";
|
|
7
14
|
import { snapToStep } from "../slider/model.js";
|
|
15
|
+
import { canStep, parseNumber, stepText } from "./model.js";
|
|
8
16
|
|
|
9
17
|
export type NumberStepperPart = "root" | "decrement" | "increment" | "input" | "unit";
|
|
10
18
|
|
|
11
|
-
|
|
12
|
-
value?: number;
|
|
13
|
-
defaultValue?: number;
|
|
14
|
-
onValueChange?: (value: number) => void;
|
|
19
|
+
interface NumberStepperBaseProps {
|
|
15
20
|
min?: number;
|
|
16
21
|
max?: number;
|
|
17
22
|
step?: number;
|
|
@@ -19,37 +24,85 @@ export interface NumberStepperProps {
|
|
|
19
24
|
/** Text after the number, e.g. "min" or "unid."; read by screen readers through aria-valuetext. */
|
|
20
25
|
unit?: string;
|
|
21
26
|
name?: string;
|
|
27
|
+
/** Id of the text input; `Field` sets it so the label points at the control. */
|
|
28
|
+
id?: string;
|
|
29
|
+
placeholder?: string;
|
|
30
|
+
required?: boolean;
|
|
31
|
+
invalid?: boolean;
|
|
22
32
|
"aria-label"?: string;
|
|
23
33
|
"aria-labelledby"?: string;
|
|
34
|
+
"aria-describedby"?: string;
|
|
35
|
+
"aria-invalid"?: boolean;
|
|
24
36
|
className?: string;
|
|
25
37
|
/** Per-part classes merged with `cn`; consumer classes win. `className` still targets the root and is merged last. */
|
|
26
38
|
classNames?: ClassNames<NumberStepperPart>;
|
|
27
39
|
}
|
|
28
40
|
|
|
29
|
-
/**
|
|
30
|
-
export
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
41
|
+
/** Numeric mode (default): the value is a finite number, typing is committed on blur or Enter and snapped to `step`. */
|
|
42
|
+
export interface NumberStepperNumberProps extends NumberStepperBaseProps {
|
|
43
|
+
mode?: "number";
|
|
44
|
+
value?: number;
|
|
45
|
+
defaultValue?: number;
|
|
46
|
+
onValueChange?: (value: number) => void;
|
|
47
|
+
onChange?: never;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* String mode: the caller owns the text. Typing is never rewritten, the field may be empty, and every
|
|
52
|
+
* change (typing, the buttons, ArrowUp/ArrowDown) reports both `onChange(event)` with the new text in
|
|
53
|
+
* `event.target.value` and `onValueChange(text)`. `min`, `max` and `step` bound the stepping and the ARIA range.
|
|
54
|
+
*/
|
|
55
|
+
export interface NumberStepperStringProps extends NumberStepperBaseProps {
|
|
56
|
+
mode: "string";
|
|
57
|
+
value?: string;
|
|
58
|
+
defaultValue?: string;
|
|
59
|
+
onValueChange?: (value: string) => void;
|
|
60
|
+
onChange?: ChangeEventHandler<HTMLInputElement>;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export type NumberStepperProps = NumberStepperNumberProps | NumberStepperStringProps;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Counter with minus/plus buttons and a typeable value; ArrowUp/ArrowDown step it, Home/End jump.
|
|
67
|
+
* Numeric by default; `mode="string"` hands the text to the caller (empty state, change event).
|
|
68
|
+
*/
|
|
69
|
+
export function NumberStepper(props: NumberStepperProps) {
|
|
70
|
+
const {
|
|
71
|
+
min = Number.NEGATIVE_INFINITY,
|
|
72
|
+
max = Number.POSITIVE_INFINITY,
|
|
73
|
+
step = 1,
|
|
74
|
+
disabled,
|
|
75
|
+
unit,
|
|
76
|
+
name,
|
|
77
|
+
id: idProp,
|
|
78
|
+
placeholder,
|
|
79
|
+
required,
|
|
80
|
+
invalid,
|
|
81
|
+
className,
|
|
82
|
+
classNames,
|
|
83
|
+
"aria-label": ariaLabel,
|
|
84
|
+
"aria-labelledby": ariaLabelledBy,
|
|
85
|
+
"aria-describedby": ariaDescribedBy,
|
|
86
|
+
"aria-invalid": ariaInvalid,
|
|
87
|
+
} = props;
|
|
88
|
+
const autoId = useId();
|
|
89
|
+
const id = idProp ?? autoId;
|
|
90
|
+
const inputRef = useRef<HTMLInputElement | null>(null);
|
|
91
|
+
const isString = props.mode === "string";
|
|
92
|
+
const [innerNumber, setInnerNumber] = useState(isString ? 0 : (props.defaultValue ?? 0));
|
|
93
|
+
const [innerText, setInnerText] = useState(isString ? (props.defaultValue ?? "") : "");
|
|
47
94
|
const [draft, setDraft] = useState<string | null>(null);
|
|
95
|
+
const controlled = props.value !== undefined;
|
|
96
|
+
const number = isString
|
|
97
|
+
? parseNumber(controlledText(props, innerText))
|
|
98
|
+
: (props.value ?? innerNumber);
|
|
99
|
+
const text = isString ? controlledText(props, innerText) : String(number);
|
|
48
100
|
|
|
49
101
|
const apply = (raw: number) => {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
if (
|
|
102
|
+
if (isString) return;
|
|
103
|
+
const next = Number.isFinite(raw) ? snapToStep(raw, min, max, step) : number;
|
|
104
|
+
if (!controlled) setInnerNumber(next);
|
|
105
|
+
if (next !== number) props.onValueChange?.(next);
|
|
53
106
|
};
|
|
54
107
|
|
|
55
108
|
const commitDraft = () => {
|
|
@@ -59,24 +112,51 @@ export function NumberStepper({
|
|
|
59
112
|
if (draft.trim() !== "") apply(parsed);
|
|
60
113
|
};
|
|
61
114
|
|
|
115
|
+
// String mode reports through a real change event, so `onChange(e)` works for the buttons too.
|
|
116
|
+
const setText = (next: string) => {
|
|
117
|
+
const input = inputRef.current;
|
|
118
|
+
const setter = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, "value")?.set;
|
|
119
|
+
if (!input || !setter) return;
|
|
120
|
+
setter.call(input, next);
|
|
121
|
+
input.dispatchEvent(new Event("input", { bubbles: true }));
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
const move = (direction: 1 | -1) => {
|
|
125
|
+
if (isString) setText(stepText(text, direction, { min, max, step }));
|
|
126
|
+
else apply(number + direction * step);
|
|
127
|
+
};
|
|
128
|
+
|
|
62
129
|
const onKeyDown = (event: KeyboardEvent<HTMLInputElement>) => {
|
|
63
|
-
if (event.key === "ArrowUp")
|
|
64
|
-
else if (event.key === "ArrowDown")
|
|
65
|
-
else if (event.key === "Home" && Number.isFinite(min))
|
|
66
|
-
|
|
67
|
-
|
|
130
|
+
if (event.key === "ArrowUp") move(1);
|
|
131
|
+
else if (event.key === "ArrowDown") move(-1);
|
|
132
|
+
else if (event.key === "Home" && Number.isFinite(min)) {
|
|
133
|
+
if (isString) setText(String(min));
|
|
134
|
+
else apply(min);
|
|
135
|
+
} else if (event.key === "End" && Number.isFinite(max)) {
|
|
136
|
+
if (isString) setText(String(max));
|
|
137
|
+
else apply(max);
|
|
138
|
+
} else if (event.key === "Enter" && !isString) commitDraft();
|
|
68
139
|
else return;
|
|
69
140
|
if (event.key !== "Enter") event.preventDefault();
|
|
70
141
|
};
|
|
71
142
|
|
|
143
|
+
const onChange = (event: ChangeEvent<HTMLInputElement>) => {
|
|
144
|
+
if (props.mode !== "string") return setDraft(event.target.value);
|
|
145
|
+
if (!controlled) setInnerText(event.target.value);
|
|
146
|
+
props.onChange?.(event);
|
|
147
|
+
props.onValueChange?.(event.target.value);
|
|
148
|
+
};
|
|
149
|
+
|
|
72
150
|
const button =
|
|
73
151
|
"grid h-full w-9 shrink-0 place-items-center text-ink-2 outline-none hover:bg-surface-sunken hover:text-ink focus-visible:focus-ring disabled:cursor-not-allowed disabled:opacity-40";
|
|
152
|
+
const valid = !Number.isNaN(number);
|
|
74
153
|
|
|
75
154
|
return (
|
|
76
155
|
<div
|
|
77
156
|
className={cn(
|
|
78
157
|
"inline-flex h-input min-w-32 max-w-full items-stretch overflow-hidden rounded-input border-control bg-surface-control",
|
|
79
158
|
disabled && "opacity-60",
|
|
159
|
+
(invalid || ariaInvalid) && "border-danger",
|
|
80
160
|
classNames?.root,
|
|
81
161
|
className,
|
|
82
162
|
)}
|
|
@@ -86,30 +166,36 @@ export function NumberStepper({
|
|
|
86
166
|
tabIndex={-1}
|
|
87
167
|
aria-label="Disminuir"
|
|
88
168
|
aria-controls={id}
|
|
89
|
-
disabled={disabled ||
|
|
90
|
-
onClick={() =>
|
|
169
|
+
disabled={disabled || !canStep(text, -1, { min, max })}
|
|
170
|
+
onClick={() => move(-1)}
|
|
91
171
|
className={cn(button, "pressable", classNames?.decrement)}
|
|
92
172
|
>
|
|
93
173
|
<Minus aria-hidden="true" className="size-3.5" />
|
|
94
174
|
</button>
|
|
95
175
|
<input
|
|
176
|
+
ref={inputRef}
|
|
96
177
|
id={id}
|
|
97
178
|
name={name}
|
|
98
179
|
role="spinbutton"
|
|
99
180
|
inputMode="decimal"
|
|
181
|
+
placeholder={placeholder}
|
|
182
|
+
required={required}
|
|
100
183
|
disabled={disabled}
|
|
101
|
-
aria-valuenow={
|
|
184
|
+
aria-valuenow={valid ? number : undefined}
|
|
102
185
|
aria-valuemin={Number.isFinite(min) ? min : undefined}
|
|
103
186
|
aria-valuemax={Number.isFinite(max) ? max : undefined}
|
|
104
|
-
aria-valuetext={unit ? `${
|
|
105
|
-
aria-label={
|
|
106
|
-
aria-labelledby={
|
|
107
|
-
|
|
108
|
-
|
|
187
|
+
aria-valuetext={unit && valid ? `${number} ${unit}` : undefined}
|
|
188
|
+
aria-label={ariaLabel}
|
|
189
|
+
aria-labelledby={ariaLabelledBy}
|
|
190
|
+
aria-describedby={ariaDescribedBy}
|
|
191
|
+
aria-invalid={ariaInvalid ?? (invalid || undefined)}
|
|
192
|
+
aria-required={required || undefined}
|
|
193
|
+
value={draft ?? text}
|
|
194
|
+
onChange={onChange}
|
|
109
195
|
onBlur={commitDraft}
|
|
110
196
|
onKeyDown={onKeyDown}
|
|
111
197
|
className={cn(
|
|
112
|
-
"w-14 min-w-0 flex-1 bg-transparent px-1 text-center text-control text-ink tabular-nums outline-none focus-visible:focus-ring",
|
|
198
|
+
"w-14 min-w-0 flex-1 bg-transparent px-1 text-center text-control text-ink tabular-nums outline-none placeholder:text-ink-3 focus-visible:focus-ring",
|
|
113
199
|
classNames?.input,
|
|
114
200
|
)}
|
|
115
201
|
/>
|
|
@@ -126,8 +212,8 @@ export function NumberStepper({
|
|
|
126
212
|
tabIndex={-1}
|
|
127
213
|
aria-label="Aumentar"
|
|
128
214
|
aria-controls={id}
|
|
129
|
-
disabled={disabled ||
|
|
130
|
-
onClick={() =>
|
|
215
|
+
disabled={disabled || !canStep(text, 1, { min, max })}
|
|
216
|
+
onClick={() => move(1)}
|
|
131
217
|
className={cn(button, "pressable", classNames?.increment)}
|
|
132
218
|
>
|
|
133
219
|
<Plus aria-hidden="true" className="size-3.5" />
|
|
@@ -135,3 +221,7 @@ export function NumberStepper({
|
|
|
135
221
|
</div>
|
|
136
222
|
);
|
|
137
223
|
}
|
|
224
|
+
|
|
225
|
+
function controlledText(props: NumberStepperProps, inner: string): string {
|
|
226
|
+
return props.mode === "string" ? (props.value ?? inner) : inner;
|
|
227
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./password-input.js";
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { IconButton } from "../../atoms/icon-button/icon-button.js";
|
|
4
|
+
import { useUiStrings } from "../../i18n/index.js";
|
|
5
|
+
import { Eye, EyeOff } from "../../icons/index.js";
|
|
6
|
+
import { useControllableState } from "../../utils/use-controllable-state.js";
|
|
7
|
+
import { Input, type InputProps } from "../input/input.js";
|
|
8
|
+
|
|
9
|
+
export interface PasswordInputProps extends Omit<InputProps, "type" | "end"> {
|
|
10
|
+
/** Whether the password is shown as text. Controlled; omit it for an uncontrolled field. */
|
|
11
|
+
revealed?: boolean;
|
|
12
|
+
/** Initial visibility of an uncontrolled field. Defaults to hidden. */
|
|
13
|
+
defaultRevealed?: boolean;
|
|
14
|
+
onRevealedChange?: (revealed: boolean) => void;
|
|
15
|
+
/** Accessible name of the reveal toggle; defaults to the UI string `showPassword`. */
|
|
16
|
+
revealLabel?: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Password field with a reveal toggle at its end. The toggle keeps one name and reports the
|
|
21
|
+
* state through `aria-pressed`, so a screen reader hears "Show password, pressed" rather than a
|
|
22
|
+
* label that flips. Toggling never moves focus out of the field's row and never submits a form.
|
|
23
|
+
*/
|
|
24
|
+
export function PasswordInput({
|
|
25
|
+
revealed: revealedProp,
|
|
26
|
+
defaultRevealed = false,
|
|
27
|
+
onRevealedChange,
|
|
28
|
+
revealLabel,
|
|
29
|
+
autoComplete = "current-password",
|
|
30
|
+
...props
|
|
31
|
+
}: PasswordInputProps) {
|
|
32
|
+
const strings = useUiStrings();
|
|
33
|
+
const [revealed, setRevealed] = useControllableState({
|
|
34
|
+
prop: revealedProp,
|
|
35
|
+
defaultProp: defaultRevealed,
|
|
36
|
+
onChange: onRevealedChange,
|
|
37
|
+
});
|
|
38
|
+
return (
|
|
39
|
+
<Input
|
|
40
|
+
{...props}
|
|
41
|
+
type={revealed ? "text" : "password"}
|
|
42
|
+
autoComplete={autoComplete}
|
|
43
|
+
end={
|
|
44
|
+
<IconButton
|
|
45
|
+
label={revealLabel ?? strings.showPassword}
|
|
46
|
+
aria-pressed={revealed}
|
|
47
|
+
variant="ghost"
|
|
48
|
+
size="sm"
|
|
49
|
+
className="-mr-1.5"
|
|
50
|
+
onClick={() => setRevealed((current) => !current)}
|
|
51
|
+
>
|
|
52
|
+
{revealed ? <EyeOff /> : <Eye />}
|
|
53
|
+
</IconButton>
|
|
54
|
+
}
|
|
55
|
+
/>
|
|
56
|
+
);
|
|
57
|
+
}
|