@42-central/ui-react 0.20.1 → 0.20.2
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/dist/{chunk-MKKQE3TM.js → chunk-2BNIHOMT.js} +3 -3
- package/dist/{chunk-MKKQE3TM.js.map → chunk-2BNIHOMT.js.map} +1 -1
- package/dist/{chunk-LBAE6FP6.js → chunk-37VQGKD6.js} +4 -4
- package/dist/{chunk-LBAE6FP6.js.map → chunk-37VQGKD6.js.map} +1 -1
- package/dist/{chunk-SXNAUSEB.js → chunk-45TG7H5Q.js} +3 -3
- package/dist/{chunk-SXNAUSEB.js.map → chunk-45TG7H5Q.js.map} +1 -1
- package/dist/{chunk-NJPHZBLI.js → chunk-5CNVVA7I.js} +4 -4
- package/dist/{chunk-NJPHZBLI.js.map → chunk-5CNVVA7I.js.map} +1 -1
- package/dist/{chunk-BNWQ7IAZ.js → chunk-C74TV64U.js} +5 -5
- package/dist/{chunk-BNWQ7IAZ.js.map → chunk-C74TV64U.js.map} +1 -1
- package/dist/{chunk-RCF7HTG5.js → chunk-FDCPMUJK.js} +4 -4
- package/dist/{chunk-RCF7HTG5.js.map → chunk-FDCPMUJK.js.map} +1 -1
- package/dist/{chunk-E63VD25L.js → chunk-HQPU73WV.js} +4 -4
- package/dist/{chunk-E63VD25L.js.map → chunk-HQPU73WV.js.map} +1 -1
- package/dist/{chunk-POKLPMSB.js → chunk-LFQDB5OD.js} +3 -3
- package/dist/{chunk-POKLPMSB.js.map → chunk-LFQDB5OD.js.map} +1 -1
- package/dist/{chunk-5HUEBSIS.js → chunk-N66NC6QK.js} +120 -24
- package/dist/chunk-N66NC6QK.js.map +1 -0
- package/dist/{chunk-IOYZC7SA.js → chunk-UCCJUFOG.js} +3 -3
- package/dist/{chunk-IOYZC7SA.js.map → chunk-UCCJUFOG.js.map} +1 -1
- package/dist/{chunk-KMZENCEP.js → chunk-UVQXRDRO.js} +3 -3
- package/dist/{chunk-KMZENCEP.js.map → chunk-UVQXRDRO.js.map} +1 -1
- package/dist/chunk-V6PY7C6S.js +18 -0
- package/dist/chunk-V6PY7C6S.js.map +1 -0
- package/dist/{chunk-TWLJQE75.js → chunk-WXL5RP6P.js} +3 -3
- package/dist/{chunk-TWLJQE75.js.map → chunk-WXL5RP6P.js.map} +1 -1
- package/dist/{chunk-VTDBWU6H.js → chunk-YZJUPYPO.js} +3 -3
- package/dist/{chunk-VTDBWU6H.js.map → chunk-YZJUPYPO.js.map} +1 -1
- package/dist/{chunk-3BXKTWWD.js → chunk-Z4MBCKG5.js} +4 -4
- package/dist/{chunk-3BXKTWWD.js.map → chunk-Z4MBCKG5.js.map} +1 -1
- package/dist/components/autocomplete/index.js +3 -2
- package/dist/components/autocomplete/index.js.map +1 -1
- package/dist/components/camera/index.js +5 -4
- package/dist/components/code-block/chrome.js +4 -4
- package/dist/components/code-block/index.js +5 -5
- package/dist/components/combobox/index.js +3 -2
- package/dist/components/combobox-list/index.js +5 -4
- package/dist/components/data-table/index.js +12 -12
- package/dist/components/date-picker/index.js +6 -5
- package/dist/components/date-picker/index.js.map +1 -1
- package/dist/components/hover-card/hover-card.d.ts +44 -26
- package/dist/components/hover-card/hover-card.d.ts.map +1 -1
- package/dist/components/hover-card/index.js +35 -53
- package/dist/components/hover-card/index.js.map +1 -1
- package/dist/components/menu/index.js +3 -3
- package/dist/components/multi-combobox-list/index.js +5 -4
- package/dist/components/multi-select/index.js +3 -2
- package/dist/components/multi-select/index.js.map +1 -1
- package/dist/components/number-input/index.js +3 -2
- package/dist/components/photo-capture/index.js +5 -4
- package/dist/components/photo-capture/index.js.map +1 -1
- package/dist/components/popover/index.d.ts +1 -1
- package/dist/components/popover/index.d.ts.map +1 -1
- package/dist/components/popover/index.js +2 -1
- package/dist/components/popover/popover.d.ts +44 -29
- package/dist/components/popover/popover.d.ts.map +1 -1
- package/dist/components/schedule/index.js +2 -2
- package/dist/components/select/index.js +4 -3
- package/dist/components/spotlight/index.js +3 -2
- package/dist/components/spotlight/index.js.map +1 -1
- package/dist/components/tags-input/index.js +2 -1
- package/dist/components/tags-input/index.js.map +1 -1
- package/dist/components/time-input/index.js +4 -3
- package/dist/components/time-input/index.js.map +1 -1
- package/dist/components/tooltip/index.js +2 -2
- package/dist/components/tree-multi-select/index.js +3 -2
- package/dist/components/tree-multi-select/index.js.map +1 -1
- package/dist/components/tree-select/index.js +3 -2
- package/dist/components/tree-select/index.js.map +1 -1
- package/dist/lib/placement.d.ts +42 -1
- package/dist/lib/placement.d.ts.map +1 -1
- package/dist/lib/slide-on-switch.d.ts +69 -0
- package/dist/lib/slide-on-switch.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/components/hover-card/hover-card.tsx +89 -167
- package/src/components/popover/index.ts +2 -0
- package/src/components/popover/popover.test.tsx +131 -0
- package/src/components/popover/popover.tsx +191 -53
- package/src/lib/placement.test.ts +37 -0
- package/src/lib/placement.ts +60 -1
- package/src/lib/slide-on-switch.ts +99 -0
- package/dist/chunk-5HUEBSIS.js.map +0 -1
- package/dist/chunk-G52U24GR.js +0 -10
- package/dist/chunk-G52U24GR.js.map +0 -1
|
@@ -5,7 +5,8 @@ import { inputSlot, inputControlClasses, inputShell } from '../../chunk-45QRQKRC
|
|
|
5
5
|
import { FieldShell, fieldA11yProps } from '../../chunk-VD6PB3VA.js';
|
|
6
6
|
import '../../chunk-2LI3VPDP.js';
|
|
7
7
|
import '../../chunk-IPYHTCFL.js';
|
|
8
|
-
import { popoverClearTrigger } from '../../chunk-
|
|
8
|
+
import { popoverClearTrigger } from '../../chunk-N66NC6QK.js';
|
|
9
|
+
import '../../chunk-V6PY7C6S.js';
|
|
9
10
|
import '../../chunk-7P32XCEU.js';
|
|
10
11
|
import '../../chunk-H7WOMZXO.js';
|
|
11
12
|
import '../../chunk-6N6J2DOE.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/tags-input/tags-input.tsx"],"names":["Ark"],"mappings":";;;;;;;;;;;;;;;;;;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CAAG,mBAAA,EAAqB,iBAAA,EAAmB,YAAY,KAAK;AAAA;AAAA;AACzE,eAAA,EACF,CAAA;AAAA,cACC,WAAW,IAAA,oBAAQ,GAAA,CAAC,MAAA,EAAA,EAAK,SAAA,EAAW,WAAY,QAAA,EAAA,OAAA,EAAQ,CAAA;AAAA,cACxD,SAAA,IAAa,CAAC,QAAA,IAAY,CAAC,QAAA,wBACzBA,WAAA,CAAI,OAAA,EAAJ,EACE,QAAA,EAAA,CAAC,GAAA,KAAQ;AACR,gBAAA,MAAM,SAAA,GAAY,GAAA,CAAI,KAAA,CAAM,MAAA,GAAS,CAAA;AACrC,gBAAA;AAAA;AAAA;AAAA;AAAA,kCAIE,GAAA;AAAA,oBAACA,WAAA,CAAI,YAAA;AAAA,oBAAJ;AAAA,sBACC,MAAA,EAAQ,KAAA;AAAA,sBACR,eAAa,CAAC,SAAA;AAAA,sBACd,QAAA,EAAU,YAAY,CAAA,GAAI,EAAA;AAAA,sBAC1B,SAAA,EAAW,EAAA,CAAG,mBAAA,EAAqB,CAAC,aAAa,WAAW,CAAA;AAAA,sBAE5D,8BAAC,SAAA,EAAA,EAAU;AAAA;AAAA;AACb;AAAA,cAEJ,CAAA,EACF;AAAA;AAAA;AAAA,SAEJ;AAAA,wBAEA,GAAA,CAACA,WAAA,CAAI,WAAA,EAAJ,EAAgB;AAAA;AAAA;AAAA,GACnB;AAGF,EAAA,uBACE,GAAA;AAAA,IAAC,UAAA;AAAA,IAAA;AAAA,MACC,KAAA;AAAA,MACA,WAAA;AAAA,MACA,KAAA;AAAA,MACA,QAAA;AAAA,MACA,QAAA;AAAA,MACA,IAAA;AAAA,MACA,WAAW,UAAA,EAAY,KAAA;AAAA,MAEtB,QAAA,EAAA;AAAA;AAAA,GACH;AAEJ","file":"index.js","sourcesContent":["\"use client\"\n\nimport { useFieldContext } from \"@ark-ui/react/field\"\nimport { TagsInput as Ark } from \"@ark-ui/react/tags-input\"\nimport { type ComponentProps, type FocusEvent, type ReactNode, type Ref, useState } from \"react\"\nimport { cn } from \"../../lib/cn\"\nimport type { Color } from \"../../lib/colors\"\nimport { props } from \"../../lib/props\"\nimport type { WithTestId } from \"../../lib/test-id\"\nimport { type FieldProps, FieldShell, fieldA11yProps } from \"../field/field\"\nimport {\n type InputSize,\n type InputVariant,\n inputControlClasses,\n inputShell,\n inputSlot,\n} from \"../input/input\"\nimport { pill, pillRemove } from \"../pill/pill\"\nimport {\n PillOverflowCounter,\n type PillsInputTranslations,\n pillsContent,\n pillsShell,\n usePillOverflow,\n} from \"../pills-input/pills-input\"\nimport { CloseIcon } from \"../popover/icons\"\nimport { popoverClearTrigger } from \"../popover/popover\"\n\n/**\n * TagsInput — free-form, creatable tags on Ark UI's TagsInput machine. Unlike\n * MultiSelect there's no fixed option list: the user types and presses Enter (or\n * a delimiter) to mint a tag. Each tag renders as a Pill-styled preview with a\n * delete button; tags are editable (double-click) and paste-aware.\n *\n * - `value` is `string[]`. `maxTags`, `allowDuplicates`, `splitChars`\n * (delimiter), and `addOnPaste` map straight to the Ark machine.\n * - Reuses the wrapping pills shell, the Pill chip styling, and the input\n * control reset, so it sits visually alongside MultiSelect.\n * - Label / description / error come from the built-in `Field`.\n */\n\ntype TagsInputClassNames = {\n field?: string\n control?: string\n input?: string\n tag?: string\n tagRemove?: string\n}\n\nexport type TagsInputProps = Pick<FieldProps, \"label\" | \"description\" | \"error\" | \"required\"> &\n WithTestId & {\n /** Controlled tags. */\n value?: string[]\n /** Uncontrolled initial tags. */\n defaultValue?: string[]\n /** Fires with the full tag list on every add / remove / edit. */\n onChange?: (value: string[]) => void\n /** Placeholder shown while the field is empty. */\n placeholder?: string\n /** Show a button that clears all tags. */\n clearable?: boolean\n /** Cap the number of tags. */\n maxTags?: number\n /** Cap the tags at N rows while the field doesn't have focus; the rest collapse into a\n * \"+N\" counter. They stay in the accessibility tree, and every tag shows again as soon as\n * focus enters the field (Tab, a click, or the counter itself). */\n maxLines?: number\n /** Inline-start adornment (icon, label). */\n startSlot?: ReactNode\n /** Inline-end adornment — rendered before the clear button. */\n endSlot?: ReactNode\n /** Allow the same tag more than once. */\n allowDuplicates?: boolean\n /** Character (or pattern) that splits typed/pasted text into tags. */\n splitChars?: string | RegExp\n /** Add tags when text is pasted. */\n addOnPaste?: boolean\n size?: InputSize\n variant?: InputVariant\n color?: Color\n disabled?: boolean\n readOnly?: boolean\n /** Red invalid state, independent of (and OR'd with) `error`. */\n invalid?: boolean\n /** Name for the hidden inputs (form submission). */\n name?: string\n /** Forwarded to the main input; drives touched/blurred validation. */\n onBlur?: (event: FocusEvent<HTMLInputElement>) => void\n /** Lands on the main `<input>` for focus-on-error. */\n ref?: Ref<HTMLInputElement>\n className?: string\n classNames?: TagsInputClassNames\n /** Overrides the English wording — Ark's own (the clear and per-tag delete buttons' names\n * and the screen-reader announcements; unset keys keep Ark's defaults) and `PillsInput`'s\n * `overflowCount` for the `maxLines` \"+N\" counter (accepted for parity with the other pill\n * controls; TagsInput keeps every tag readable, so the counter stays hidden from screen\n * readers). */\n translations?: TagsInputTranslations\n }\n\n/** Ark's own TagsInput `translations` type, derived structurally rather than imported from\n * `@zag-js/tags-input` (already all-optional, with Ark's English defaults behind every key),\n * plus `PillsInput`'s `overflowCount`. */\nexport type TagsInputTranslations = NonNullable<ComponentProps<typeof Ark.Root>[\"translations\"]> &\n PillsInputTranslations\n\n/**\n * The real, visible typing `<input>`, split out so it reads the `Field`\n * context from *inside* the wrapping `FieldShell` — `TagsInput` itself\n * renders that shell, so calling `useFieldContext()` at its own top level\n * would run too early.\n */\nconst TagsInputField = ({\n ref,\n onBlur,\n invalid,\n placeholder,\n className,\n testId,\n}: {\n ref?: Ref<HTMLInputElement>\n onBlur?: (event: FocusEvent<HTMLInputElement>) => void\n invalid: boolean\n placeholder?: string\n className?: string\n} & WithTestId) => {\n const field = useFieldContext()\n return (\n <Ark.Input\n data-overflow-field\n ref={ref}\n onBlur={onBlur}\n {...fieldA11yProps(field)}\n placeholder={placeholder}\n {...props({ \"aria-invalid\": invalid, \"data-testid\": testId })}\n className={className}\n />\n )\n}\n\nexport const TagsInput = ({\n value,\n defaultValue,\n onChange,\n placeholder,\n clearable,\n maxTags,\n maxLines,\n startSlot = null,\n endSlot = null,\n allowDuplicates,\n splitChars,\n addOnPaste,\n size = \"md\",\n variant = \"default\",\n color,\n disabled,\n readOnly,\n required,\n invalid,\n name,\n onBlur,\n ref,\n label,\n description,\n error,\n className,\n classNames,\n testId,\n translations,\n}: TagsInputProps) => {\n // `overflowCount` is the counter's own; the rest are Ark's.\n const { overflowCount, ...arkTranslations } = translations ?? {}\n // Red state is driven independently of the `Field` error slot so a form\n // library can flip it from `fieldState.invalid` (see FormControlProps).\n const isInvalid = invalid || error != null\n // Ark owns the tag state; the line-cap only needs its length to re-measure\n // on add / remove. A controlled `value` gives it directly; uncontrolled, we\n // mirror the length Ark reports.\n const [uncontrolledCount, setUncontrolledCount] = useState((defaultValue ?? []).length)\n const tagCount = value?.length ?? uncontrolledCount\n const { containerRef, visibleCount, hiddenCount, measuring } = usePillOverflow({\n maxLines,\n count: tagCount,\n })\n // The cap only applies while focus is elsewhere. A tag past it is still in the\n // DOM (visually hidden, so a screen reader reads every tag), and focus entering\n // the field shows them all, so the keyboard can reach, edit and delete each one.\n const [expanded, setExpanded] = useState(false)\n const collapsed = hiddenCount > 0 && !expanded\n\n const control = (\n <Ark.Root\n value={value}\n defaultValue={defaultValue}\n onValueChange={(details) => {\n setUncontrolledCount(details.value.length)\n onChange?.(details.value)\n }}\n max={maxTags}\n allowDuplicates={allowDuplicates}\n delimiter={splitChars}\n addOnPaste={addOnPaste}\n disabled={disabled}\n readOnly={readOnly}\n name={name}\n translations={arkTranslations}\n data-color={color}\n onFocus={() => setExpanded(true)}\n onBlur={(event) => {\n if (!event.currentTarget.contains(event.relatedTarget)) setExpanded(false)\n }}\n className={cn(\"w-full group/input\", className)}\n >\n <Ark.Control\n className={cn(inputShell({ size, variant }), pillsShell, classNames?.control)}\n {...props({\n \"data-invalid\": isInvalid,\n \"data-with-start-slot\": startSlot != null,\n // Reserved for the whole time the field is clearable, not just\n // while it has tags — otherwise the clear button mounting/\n // unmounting shifts the field's width.\n \"data-with-end-slot\": endSlot != null || (Boolean(clearable) && !disabled && !readOnly),\n })}\n >\n {startSlot != null && (\n <span className={inputSlot} aria-hidden>\n {startSlot}\n </span>\n )}\n <div ref={containerRef} className={pillsContent({ size })}>\n <Ark.Context>\n {(api) =>\n api.value.map((val, index) => (\n <Ark.Item\n key={val}\n index={index}\n value={val}\n data-overflow-item\n // No per-tag object identity to carry a `testId` field (tags are\n // freeform strings) — derive one from position instead.\n {...props({ \"data-testid\": testId && `${testId}-tag-${index}` })}\n className={cn(\n \"flex flex-row items-center justify-center\",\n collapsed && index >= visibleCount && \"sr-only\",\n )}\n >\n <Ark.ItemPreview className={cn(pill({ size }), \"pe-0.5\", classNames?.tag)}>\n <Ark.ItemText className=\"truncate\">{val}</Ark.ItemText>\n {!readOnly && (\n <Ark.ItemDeleteTrigger\n className={cn(pillRemove({ size }), classNames?.tagRemove)}\n >\n <CloseIcon />\n </Ark.ItemDeleteTrigger>\n )}\n </Ark.ItemPreview>\n <Ark.ItemInput className={cn(inputControlClasses, \"w-auto\")} />\n </Ark.Item>\n ))\n }\n </Ark.Context>\n {/* Mounted during the measuring pass so the hook can size the last-row\n reservation off the real counter, but kept `invisible` then (still\n measurable) so it never paints on the SSR HTML before the first\n measure. Only mounts while measuring when a cap is configured. */}\n {(collapsed || (measuring && maxLines != null)) && (\n // Hidden from assistive tech, `overflowCount` included: the tags it\n // stands for are read out themselves, so announcing \"3 more items\"\n // too would count them twice. A click on it lands on the field (Ark\n // focuses the input on any press in the root), which shows them.\n <span aria-hidden=\"true\" className=\"contents\">\n <PillOverflowCounter\n count={measuring ? tagCount : hiddenCount}\n size={size}\n className={cn(\"cursor-pointer\", measuring && \"invisible\")}\n translations={{ overflowCount }}\n />\n </span>\n )}\n <TagsInputField\n ref={ref}\n onBlur={onBlur}\n invalid={isInvalid}\n placeholder={placeholder}\n testId={testId}\n className={cn(inputControlClasses, \"w-auto min-w-16\", classNames?.input)}\n />\n </div>\n {endSlot != null && <span className={inputSlot}>{endSlot}</span>}\n {clearable && !disabled && !readOnly && (\n <Ark.Context>\n {(api) => {\n const showClear = api.value.length > 0\n return (\n // The machine's own `getClearTriggerProps` sets `hidden` off\n // `empty` — override it so the button stays mounted (and its\n // box reserved) even when there's nothing to clear yet.\n <Ark.ClearTrigger\n hidden={false}\n aria-hidden={!showClear}\n tabIndex={showClear ? 0 : -1}\n className={cn(popoverClearTrigger, !showClear && \"invisible\")}\n >\n <CloseIcon />\n </Ark.ClearTrigger>\n )\n }}\n </Ark.Context>\n )}\n </Ark.Control>\n\n <Ark.HiddenInput />\n </Ark.Root>\n )\n\n return (\n <FieldShell\n label={label}\n description={description}\n error={error}\n required={required}\n disabled={disabled}\n size={size}\n className={classNames?.field}\n >\n {control}\n </FieldShell>\n )\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/components/tags-input/tags-input.tsx"],"names":["Ark"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAgHA,IAAM,iBAAiB,CAAC;AAAA,EACtB,GAAA;AAAA,EACA,MAAA;AAAA,EACA,OAAA;AAAA,EACA,WAAA;AAAA,EACA,SAAA;AAAA,EACA;AACF,CAAA,KAMmB;AACjB,EAAA,MAAM,QAAQ,eAAA,EAAgB;AAC9B,EAAA,uBACE,GAAA;AAAA,IAACA,WAAA,CAAI,KAAA;AAAA,IAAJ;AAAA,MACC,qBAAA,EAAmB,IAAA;AAAA,MACnB,GAAA;AAAA,MACA,MAAA;AAAA,MACC,GAAG,eAAe,KAAK,CAAA;AAAA,MACxB,WAAA;AAAA,MACC,GAAG,KAAA,CAAM,EAAE,gBAAgB,OAAA,EAAS,aAAA,EAAe,QAAQ,CAAA;AAAA,MAC5D;AAAA;AAAA,GACF;AAEJ,CAAA;AAEO,IAAM,YAAY,CAAC;AAAA,EACxB,KAAA;AAAA,EACA,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sBACd,QAAA,EAAU,YAAY,CAAA,GAAI,EAAA;AAAA,sBAC1B,SAAA,EAAW,EAAA,CAAG,mBAAA,EAAqB,CAAC,aAAa,WAAW,CAAA;AAAA,sBAE5D,8BAAC,SAAA,EAAA,EAAU;AAAA;AAAA;AACb;AAAA,cAEJ,CAAA,EACF;AAAA;AAAA;AAAA,SAEJ;AAAA,wBAEA,GAAA,CAACA,WAAA,CAAI,WAAA,EAAJ,EAAgB;AAAA;AAAA;AAAA,GACnB;AAGF,EAAA,uBACE,GAAA;AAAA,IAAC,UAAA;AAAA,IAAA;AAAA,MACC,KAAA;AAAA,MACA,WAAA;AAAA,MACA,KAAA;AAAA,MACA,QAAA;AAAA,MACA,QAAA;AAAA,MACA,IAAA;AAAA,MACA,WAAW,UAAA,EAAY,KAAA;AAAA,MAEtB,QAAA,EAAA;AAAA;AAAA,GACH;AAEJ","file":"index.js","sourcesContent":["\"use client\"\n\nimport { useFieldContext } from \"@ark-ui/react/field\"\nimport { TagsInput as Ark } from \"@ark-ui/react/tags-input\"\nimport { type ComponentProps, type FocusEvent, type ReactNode, type Ref, useState } from \"react\"\nimport { cn } from \"../../lib/cn\"\nimport type { Color } from \"../../lib/colors\"\nimport { props } from \"../../lib/props\"\nimport type { WithTestId } from \"../../lib/test-id\"\nimport { type FieldProps, FieldShell, fieldA11yProps } from \"../field/field\"\nimport {\n type InputSize,\n type InputVariant,\n inputControlClasses,\n inputShell,\n inputSlot,\n} from \"../input/input\"\nimport { pill, pillRemove } from \"../pill/pill\"\nimport {\n PillOverflowCounter,\n type PillsInputTranslations,\n pillsContent,\n pillsShell,\n usePillOverflow,\n} from \"../pills-input/pills-input\"\nimport { CloseIcon } from \"../popover/icons\"\nimport { popoverClearTrigger } from \"../popover/popover\"\n\n/**\n * TagsInput — free-form, creatable tags on Ark UI's TagsInput machine. Unlike\n * MultiSelect there's no fixed option list: the user types and presses Enter (or\n * a delimiter) to mint a tag. Each tag renders as a Pill-styled preview with a\n * delete button; tags are editable (double-click) and paste-aware.\n *\n * - `value` is `string[]`. `maxTags`, `allowDuplicates`, `splitChars`\n * (delimiter), and `addOnPaste` map straight to the Ark machine.\n * - Reuses the wrapping pills shell, the Pill chip styling, and the input\n * control reset, so it sits visually alongside MultiSelect.\n * - Label / description / error come from the built-in `Field`.\n */\n\ntype TagsInputClassNames = {\n field?: string\n control?: string\n input?: string\n tag?: string\n tagRemove?: string\n}\n\nexport type TagsInputProps = Pick<FieldProps, \"label\" | \"description\" | \"error\" | \"required\"> &\n WithTestId & {\n /** Controlled tags. */\n value?: string[]\n /** Uncontrolled initial tags. */\n defaultValue?: string[]\n /** Fires with the full tag list on every add / remove / edit. */\n onChange?: (value: string[]) => void\n /** Placeholder shown while the field is empty. */\n placeholder?: string\n /** Show a button that clears all tags. */\n clearable?: boolean\n /** Cap the number of tags. */\n maxTags?: number\n /** Cap the tags at N rows while the field doesn't have focus; the rest collapse into a\n * \"+N\" counter. They stay in the accessibility tree, and every tag shows again as soon as\n * focus enters the field (Tab, a click, or the counter itself). */\n maxLines?: number\n /** Inline-start adornment (icon, label). */\n startSlot?: ReactNode\n /** Inline-end adornment — rendered before the clear button. */\n endSlot?: ReactNode\n /** Allow the same tag more than once. */\n allowDuplicates?: boolean\n /** Character (or pattern) that splits typed/pasted text into tags. */\n splitChars?: string | RegExp\n /** Add tags when text is pasted. */\n addOnPaste?: boolean\n size?: InputSize\n variant?: InputVariant\n color?: Color\n disabled?: boolean\n readOnly?: boolean\n /** Red invalid state, independent of (and OR'd with) `error`. */\n invalid?: boolean\n /** Name for the hidden inputs (form submission). */\n name?: string\n /** Forwarded to the main input; drives touched/blurred validation. */\n onBlur?: (event: FocusEvent<HTMLInputElement>) => void\n /** Lands on the main `<input>` for focus-on-error. */\n ref?: Ref<HTMLInputElement>\n className?: string\n classNames?: TagsInputClassNames\n /** Overrides the English wording — Ark's own (the clear and per-tag delete buttons' names\n * and the screen-reader announcements; unset keys keep Ark's defaults) and `PillsInput`'s\n * `overflowCount` for the `maxLines` \"+N\" counter (accepted for parity with the other pill\n * controls; TagsInput keeps every tag readable, so the counter stays hidden from screen\n * readers). */\n translations?: TagsInputTranslations\n }\n\n/** Ark's own TagsInput `translations` type, derived structurally rather than imported from\n * `@zag-js/tags-input` (already all-optional, with Ark's English defaults behind every key),\n * plus `PillsInput`'s `overflowCount`. */\nexport type TagsInputTranslations = NonNullable<ComponentProps<typeof Ark.Root>[\"translations\"]> &\n PillsInputTranslations\n\n/**\n * The real, visible typing `<input>`, split out so it reads the `Field`\n * context from *inside* the wrapping `FieldShell` — `TagsInput` itself\n * renders that shell, so calling `useFieldContext()` at its own top level\n * would run too early.\n */\nconst TagsInputField = ({\n ref,\n onBlur,\n invalid,\n placeholder,\n className,\n testId,\n}: {\n ref?: Ref<HTMLInputElement>\n onBlur?: (event: FocusEvent<HTMLInputElement>) => void\n invalid: boolean\n placeholder?: string\n className?: string\n} & WithTestId) => {\n const field = useFieldContext()\n return (\n <Ark.Input\n data-overflow-field\n ref={ref}\n onBlur={onBlur}\n {...fieldA11yProps(field)}\n placeholder={placeholder}\n {...props({ \"aria-invalid\": invalid, \"data-testid\": testId })}\n className={className}\n />\n )\n}\n\nexport const TagsInput = ({\n value,\n defaultValue,\n onChange,\n placeholder,\n clearable,\n maxTags,\n maxLines,\n startSlot = null,\n endSlot = null,\n allowDuplicates,\n splitChars,\n addOnPaste,\n size = \"md\",\n variant = \"default\",\n color,\n disabled,\n readOnly,\n required,\n invalid,\n name,\n onBlur,\n ref,\n label,\n description,\n error,\n className,\n classNames,\n testId,\n translations,\n}: TagsInputProps) => {\n // `overflowCount` is the counter's own; the rest are Ark's.\n const { overflowCount, ...arkTranslations } = translations ?? {}\n // Red state is driven independently of the `Field` error slot so a form\n // library can flip it from `fieldState.invalid` (see FormControlProps).\n const isInvalid = invalid || error != null\n // Ark owns the tag state; the line-cap only needs its length to re-measure\n // on add / remove. A controlled `value` gives it directly; uncontrolled, we\n // mirror the length Ark reports.\n const [uncontrolledCount, setUncontrolledCount] = useState((defaultValue ?? []).length)\n const tagCount = value?.length ?? uncontrolledCount\n const { containerRef, visibleCount, hiddenCount, measuring } = usePillOverflow({\n maxLines,\n count: tagCount,\n })\n // The cap only applies while focus is elsewhere. A tag past it is still in the\n // DOM (visually hidden, so a screen reader reads every tag), and focus entering\n // the field shows them all, so the keyboard can reach, edit and delete each one.\n const [expanded, setExpanded] = useState(false)\n const collapsed = hiddenCount > 0 && !expanded\n\n const control = (\n <Ark.Root\n value={value}\n defaultValue={defaultValue}\n onValueChange={(details) => {\n setUncontrolledCount(details.value.length)\n onChange?.(details.value)\n }}\n max={maxTags}\n allowDuplicates={allowDuplicates}\n delimiter={splitChars}\n addOnPaste={addOnPaste}\n disabled={disabled}\n readOnly={readOnly}\n name={name}\n translations={arkTranslations}\n data-color={color}\n onFocus={() => setExpanded(true)}\n onBlur={(event) => {\n if (!event.currentTarget.contains(event.relatedTarget)) setExpanded(false)\n }}\n className={cn(\"w-full group/input\", className)}\n >\n <Ark.Control\n className={cn(inputShell({ size, variant }), pillsShell, classNames?.control)}\n {...props({\n \"data-invalid\": isInvalid,\n \"data-with-start-slot\": startSlot != null,\n // Reserved for the whole time the field is clearable, not just\n // while it has tags — otherwise the clear button mounting/\n // unmounting shifts the field's width.\n \"data-with-end-slot\": endSlot != null || (Boolean(clearable) && !disabled && !readOnly),\n })}\n >\n {startSlot != null && (\n <span className={inputSlot} aria-hidden>\n {startSlot}\n </span>\n )}\n <div ref={containerRef} className={pillsContent({ size })}>\n <Ark.Context>\n {(api) =>\n api.value.map((val, index) => (\n <Ark.Item\n key={val}\n index={index}\n value={val}\n data-overflow-item\n // No per-tag object identity to carry a `testId` field (tags are\n // freeform strings) — derive one from position instead.\n {...props({ \"data-testid\": testId && `${testId}-tag-${index}` })}\n className={cn(\n \"flex flex-row items-center justify-center\",\n collapsed && index >= visibleCount && \"sr-only\",\n )}\n >\n <Ark.ItemPreview className={cn(pill({ size }), \"pe-0.5\", classNames?.tag)}>\n <Ark.ItemText className=\"truncate\">{val}</Ark.ItemText>\n {!readOnly && (\n <Ark.ItemDeleteTrigger\n className={cn(pillRemove({ size }), classNames?.tagRemove)}\n >\n <CloseIcon />\n </Ark.ItemDeleteTrigger>\n )}\n </Ark.ItemPreview>\n <Ark.ItemInput className={cn(inputControlClasses, \"w-auto\")} />\n </Ark.Item>\n ))\n }\n </Ark.Context>\n {/* Mounted during the measuring pass so the hook can size the last-row\n reservation off the real counter, but kept `invisible` then (still\n measurable) so it never paints on the SSR HTML before the first\n measure. Only mounts while measuring when a cap is configured. */}\n {(collapsed || (measuring && maxLines != null)) && (\n // Hidden from assistive tech, `overflowCount` included: the tags it\n // stands for are read out themselves, so announcing \"3 more items\"\n // too would count them twice. A click on it lands on the field (Ark\n // focuses the input on any press in the root), which shows them.\n <span aria-hidden=\"true\" className=\"contents\">\n <PillOverflowCounter\n count={measuring ? tagCount : hiddenCount}\n size={size}\n className={cn(\"cursor-pointer\", measuring && \"invisible\")}\n translations={{ overflowCount }}\n />\n </span>\n )}\n <TagsInputField\n ref={ref}\n onBlur={onBlur}\n invalid={isInvalid}\n placeholder={placeholder}\n testId={testId}\n className={cn(inputControlClasses, \"w-auto min-w-16\", classNames?.input)}\n />\n </div>\n {endSlot != null && <span className={inputSlot}>{endSlot}</span>}\n {clearable && !disabled && !readOnly && (\n <Ark.Context>\n {(api) => {\n const showClear = api.value.length > 0\n return (\n // The machine's own `getClearTriggerProps` sets `hidden` off\n // `empty` — override it so the button stays mounted (and its\n // box reserved) even when there's nothing to clear yet.\n <Ark.ClearTrigger\n hidden={false}\n aria-hidden={!showClear}\n tabIndex={showClear ? 0 : -1}\n className={cn(popoverClearTrigger, !showClear && \"invisible\")}\n >\n <CloseIcon />\n </Ark.ClearTrigger>\n )\n }}\n </Ark.Context>\n )}\n </Ark.Control>\n\n <Ark.HiddenInput />\n </Ark.Root>\n )\n\n return (\n <FieldShell\n label={label}\n description={description}\n error={error}\n required={required}\n disabled={disabled}\n size={size}\n className={classNames?.field}\n >\n {control}\n </FieldShell>\n )\n}\n"]}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { resolveHourCycle, toDisplayHour, TimeRow, fromDisplayHour } from '../../chunk-
|
|
2
|
+
import { resolveHourCycle, toDisplayHour, TimeRow, fromDisplayHour } from '../../chunk-LFQDB5OD.js';
|
|
3
3
|
import '../../chunk-C4NFRSOR.js';
|
|
4
|
-
import '../../chunk-
|
|
4
|
+
import '../../chunk-UVQXRDRO.js';
|
|
5
5
|
import '../../chunk-45QRQKRC.js';
|
|
6
6
|
import { FieldShell, fieldA11yProps } from '../../chunk-VD6PB3VA.js';
|
|
7
7
|
import '../../chunk-HBWV5EPU.js';
|
|
8
8
|
import '../../chunk-IPYHTCFL.js';
|
|
9
|
-
import '../../chunk-
|
|
9
|
+
import '../../chunk-N66NC6QK.js';
|
|
10
|
+
import '../../chunk-V6PY7C6S.js';
|
|
10
11
|
import '../../chunk-7P32XCEU.js';
|
|
11
12
|
import '../../chunk-H7WOMZXO.js';
|
|
12
13
|
import '../../chunk-6N6J2DOE.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/time-input/time-input.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AA6EA,IAAM,YAAA,GAA4B,EAAE,IAAA,EAAM,IAAA,EAAM,QAAQ,IAAA,EAAM,MAAA,EAAQ,IAAA,EAAM,MAAA,EAAQ,IAAA,EAAK;AAGzF,IAAM,SAAA,GAAY,CAAC,KAAA,EAAkB,KAAA,KAAkC;AACrE,EAAA,IAAI,KAAA,IAAS,MAAM,OAAO,YAAA;AAC1B,EAAA,MAAM,EAAE,IAAA,EAAM,MAAA,KAAW,aAAA,CAAc,KAAA,CAAM,MAAM,KAAK,CAAA;AACxD,EAAA,OAAO,EAAE,MAAM,MAAA,EAAQ,KAAA,CAAM,QAAQ,MAAA,EAAQ,KAAA,CAAM,MAAA,IAAU,IAAA,EAAM,MAAA,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AAA;AAAA,YACA;AAAA;AAAA,SACF;AAAA,QACC,IAAA,wBAAS,OAAA,EAAA,EAAM,IAAA,EAAK,UAAS,IAAA,EAAY,KAAA,EAAO,SAAA,CAAU,SAAS,CAAA,EAAG;AAAA,OAAA,EACzE;AAAA;AAAA,GACF;AAEJ","file":"index.js","sourcesContent":["\"use client\"\n\nimport { useFieldContext } from \"@ark-ui/react/field\"\nimport { useLocaleContext } from \"@ark-ui/react/locale\"\nimport type { FormControlProps } from \"../../lib/form-control\"\nimport { props } from \"../../lib/props\"\nimport type { Size } from \"../../lib/sizes\"\nimport type { WithTestId } from \"../../lib/test-id\"\nimport { useUncontrolled } from \"../../lib/use-uncontrolled\"\nimport { type FieldProps, FieldShell, fieldA11yProps } from \"../field/field\"\nimport type { InputVariant } from \"../input/input\"\nimport { fromDisplayHour, type HourCycle, resolveHourCycle, toDisplayHour } from \"./hour-cycle\"\nimport { TimeRow, type TimeRowProps, type TimeRowTranslations } from \"./time-row\"\n\n/**\n * TimeInput — a standalone HOUR/MINUTE (+ SECOND) + AM/PM time entry, composed\n * from the kit's `NumberInput` + `SegmentGroup` (Ark ships no time-picker\n * machine, only a countdown timer). It's the same time row `DatePicker`\n * embeds in its popover for `withTime`.\n *\n * - Value is `{ hour, minute, second? } | null` — `hour` is always stored in\n * 24h, regardless of display. There's no built-in range: a \"start\" /\n * \"end\" pair reads better as two labelled `TimeInput`s (e.g. \"Start\n * time\" / \"End time\") than as one control with no visual differentiation\n * between its two halves — compose that at the call site.\n * - 12h vs 24h is locale-driven by default (`Intl.DateTimeFormat`'s\n * `hourCycle`); override with `format` or `hourCycle`.\n * - Label / description / error come from the built-in `Field` wrapper.\n * - `name` wires a hidden `HH:mm[:ss]` input into native form submission —\n * the machine-backed controls in this kit have a real hidden part for\n * this; a composed field like this one has none, so it's hand-rolled.\n *\n * Palette / shape forward straight through to the underlying `NumberInput` /\n * `SegmentGroup` instances, so it matches the rest of the family for free.\n */\n\ntype TimeInputClassNames = {\n field?: string\n hour?: string\n minute?: string\n second?: string\n period?: string\n}\n\nexport type TimeValue = { hour: number; minute: number; second?: number } | null\n\nexport type TimeInputProps = Omit<FormControlProps<TimeValue, HTMLInputElement>, \"id\"> &\n Pick<FieldProps, \"label\" | \"description\" | \"error\" | \"required\"> &\n WithTestId & {\n /** Force 12-hour or 24-hour display, overriding the locale default. */\n format?: 12 | 24\n /** Force a specific hour cycle, overriding the locale default and `format`: `h11` shows\n * 0–11, `h12` 1–12, `h23` 0–23, `h24` 1–24 (midnight is `24`). */\n hourCycle?: HourCycle\n /** Minute stepper increment. Default `1`. */\n minuteStep?: number\n /** Add a SECOND field alongside HOUR/MINUTE. */\n withSeconds?: boolean\n /** Placeholder shown in each empty Hour/Minute/Second field. Default `\"--\"`. */\n placeholder?: string\n /** Locale used to resolve 12h vs 24h. Defaults to the active locale context. */\n locale?: string\n /** Overrides the sr-only Hour/Minute/Second/Period accessible names. English by default. */\n translations?: TimeRowTranslations\n size?: Size\n variant?: InputVariant\n className?: string\n classNames?: TimeInputClassNames\n }\n\ntype DisplayTime = {\n hour: number | null\n minute: number | null\n second: number | null\n period: \"AM\" | \"PM\" | null\n}\n\nconst emptyDisplay: DisplayTime = { hour: null, minute: null, second: null, period: null }\n\n/** Derive display-space fields (the cycle's own hours, + period) from a stored 24h value. */\nconst toDisplay = (value: TimeValue, cycle: HourCycle): DisplayTime => {\n if (value == null) return emptyDisplay\n const { hour, period } = toDisplayHour(value.hour, cycle)\n return { hour, minute: value.minute, second: value.second ?? null, period }\n}\n\n/** Merge a display-space edit back into a stored 24h value. Missing fields\n * default to midnight (or noon, once PM is picked) rather than nulling the whole\n * value out from under a field the user hasn't touched yet — `TimeInput`\n * has no `clearable` affordance in v1, so a value only ever moves from\n * `null` to a complete `{ hour, minute }`, never partway back. */\nconst fromDisplay = (display: DisplayTime, cycle: HourCycle): Exclude<TimeValue, null> => {\n const hour = fromDisplayHour(display.hour, display.period, cycle)\n const minute = display.minute ?? 0\n return display.second != null ? { hour, minute, second: display.second } : { hour, minute }\n}\n\n/**\n * The `TimeRow`, split out so it reads the `Field` context from *inside* the wrapping\n * `FieldShell` — `TimeInput` itself renders that shell, so calling `useFieldContext()` at its own\n * top level would run too early. The row is the field's real control: its `role=\"group\"` takes\n * the field label as its name and the helper / error text as its description. Outside a\n * `Field` (no label, description, error or `required`) there is no context and nothing to wire.\n */\nconst TimeInputRow = ({ labelled, ...rowProps }: TimeRowProps & { labelled: boolean }) => {\n const field = useFieldContext()\n const a11y = fieldA11yProps(field)\n return (\n <TimeRow\n {...rowProps}\n // A `Field` with only a description or error renders no `<label>` to point at.\n aria-labelledby={labelled ? a11y[\"aria-labelledby\"] : undefined}\n aria-describedby={a11y[\"aria-describedby\"]}\n />\n )\n}\n\nexport const TimeInput = ({\n value,\n defaultValue,\n onChange,\n format,\n hourCycle,\n minuteStep,\n withSeconds,\n placeholder,\n locale,\n translations,\n size = \"md\",\n variant = \"default\",\n disabled,\n readOnly,\n invalid,\n required,\n name,\n onBlur,\n ref,\n label,\n description,\n error,\n className,\n classNames,\n testId,\n}: TimeInputProps) => {\n const { locale: contextLocale } = useLocaleContext()\n const resolvedLocale = locale ?? contextLocale\n const resolvedCycle = resolveHourCycle({ locale: resolvedLocale, format, hourCycle })\n const isInvalid = invalid || error != null\n\n const [committed, setCommitted] = useUncontrolled<TimeValue>({\n value,\n defaultValue,\n finalValue: null,\n onChange,\n })\n\n const patch = (partial: Partial<DisplayTime>) => {\n const current = toDisplay(committed, resolvedCycle)\n setCommitted(fromDisplay({ ...current, ...partial }, resolvedCycle))\n }\n\n const display = toDisplay(committed, resolvedCycle)\n\n /** `HH:mm` / `HH:mm:ss`, zero-padded — the format a `<input type=\"time\">` /\n * server would expect from a hidden field. */\n const serialize = (time: TimeValue): string => {\n if (time == null) return \"\"\n const pad = (n: number) => String(n).padStart(2, \"0\")\n return time.second != null\n ? `${pad(time.hour)}:${pad(time.minute)}:${pad(time.second)}`\n : `${pad(time.hour)}:${pad(time.minute)}`\n }\n\n return (\n <FieldShell\n label={label}\n description={description}\n error={error}\n required={required}\n disabled={disabled}\n size={size}\n className={classNames?.field}\n // Hour / Minute / [Second] / AM-PM: no single input for the label's `for` to point at.\n composite\n >\n {/* No single focusable control to route `testId` to — Hour/Minute/[Second] +\n AM/PM are each their own field — so it lands on the wrapping shell. */}\n <div className={className} {...props({ \"data-testid\": testId })}>\n <TimeInputRow\n labelled={label != null}\n hour={display.hour}\n minute={display.minute}\n second={display.second}\n onHourChange={(hour) => patch({ hour })}\n onMinuteChange={(minute) => patch({ minute })}\n onSecondChange={withSeconds ? (second) => patch({ second }) : undefined}\n period={display.period}\n onPeriodChange={(period) => patch({ period })}\n hourCycle={resolvedCycle}\n minuteStep={minuteStep}\n withSeconds={withSeconds}\n placeholder={placeholder}\n locale={resolvedLocale}\n translations={translations}\n size={size}\n variant={variant}\n disabled={disabled}\n readOnly={readOnly}\n invalid={isInvalid}\n ref={ref}\n onBlur={onBlur}\n classNames={classNames}\n />\n {name && <input type=\"hidden\" name={name} value={serialize(committed)} />}\n </div>\n </FieldShell>\n )\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/components/time-input/time-input.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AA6EA,IAAM,YAAA,GAA4B,EAAE,IAAA,EAAM,IAAA,EAAM,QAAQ,IAAA,EAAM,MAAA,EAAQ,IAAA,EAAM,MAAA,EAAQ,IAAA,EAAK;AAGzF,IAAM,SAAA,GAAY,CAAC,KAAA,EAAkB,KAAA,KAAkC;AACrE,EAAA,IAAI,KAAA,IAAS,MAAM,OAAO,YAAA;AAC1B,EAAA,MAAM,EAAE,IAAA,EAAM,MAAA,KAAW,aAAA,CAAc,KAAA,CAAM,MAAM,KAAK,CAAA;AACxD,EAAA,OAAO,EAAE,MAAM,MAAA,EAAQ,KAAA,CAAM,QAAQ,MAAA,EAAQ,KAAA,CAAM,MAAA,IAAU,IAAA,EAAM,MAAA,EAAO;AAC5E,CAAA;AAO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AAA,SACF;AAAA,QACC,IAAA,wBAAS,OAAA,EAAA,EAAM,IAAA,EAAK,UAAS,IAAA,EAAY,KAAA,EAAO,SAAA,CAAU,SAAS,CAAA,EAAG;AAAA,OAAA,EACzE;AAAA;AAAA,GACF;AAEJ","file":"index.js","sourcesContent":["\"use client\"\n\nimport { useFieldContext } from \"@ark-ui/react/field\"\nimport { useLocaleContext } from \"@ark-ui/react/locale\"\nimport type { FormControlProps } from \"../../lib/form-control\"\nimport { props } from \"../../lib/props\"\nimport type { Size } from \"../../lib/sizes\"\nimport type { WithTestId } from \"../../lib/test-id\"\nimport { useUncontrolled } from \"../../lib/use-uncontrolled\"\nimport { type FieldProps, FieldShell, fieldA11yProps } from \"../field/field\"\nimport type { InputVariant } from \"../input/input\"\nimport { fromDisplayHour, type HourCycle, resolveHourCycle, toDisplayHour } from \"./hour-cycle\"\nimport { TimeRow, type TimeRowProps, type TimeRowTranslations } from \"./time-row\"\n\n/**\n * TimeInput — a standalone HOUR/MINUTE (+ SECOND) + AM/PM time entry, composed\n * from the kit's `NumberInput` + `SegmentGroup` (Ark ships no time-picker\n * machine, only a countdown timer). It's the same time row `DatePicker`\n * embeds in its popover for `withTime`.\n *\n * - Value is `{ hour, minute, second? } | null` — `hour` is always stored in\n * 24h, regardless of display. There's no built-in range: a \"start\" /\n * \"end\" pair reads better as two labelled `TimeInput`s (e.g. \"Start\n * time\" / \"End time\") than as one control with no visual differentiation\n * between its two halves — compose that at the call site.\n * - 12h vs 24h is locale-driven by default (`Intl.DateTimeFormat`'s\n * `hourCycle`); override with `format` or `hourCycle`.\n * - Label / description / error come from the built-in `Field` wrapper.\n * - `name` wires a hidden `HH:mm[:ss]` input into native form submission —\n * the machine-backed controls in this kit have a real hidden part for\n * this; a composed field like this one has none, so it's hand-rolled.\n *\n * Palette / shape forward straight through to the underlying `NumberInput` /\n * `SegmentGroup` instances, so it matches the rest of the family for free.\n */\n\ntype TimeInputClassNames = {\n field?: string\n hour?: string\n minute?: string\n second?: string\n period?: string\n}\n\nexport type TimeValue = { hour: number; minute: number; second?: number } | null\n\nexport type TimeInputProps = Omit<FormControlProps<TimeValue, HTMLInputElement>, \"id\"> &\n Pick<FieldProps, \"label\" | \"description\" | \"error\" | \"required\"> &\n WithTestId & {\n /** Force 12-hour or 24-hour display, overriding the locale default. */\n format?: 12 | 24\n /** Force a specific hour cycle, overriding the locale default and `format`: `h11` shows\n * 0–11, `h12` 1–12, `h23` 0–23, `h24` 1–24 (midnight is `24`). */\n hourCycle?: HourCycle\n /** Minute stepper increment. Default `1`. */\n minuteStep?: number\n /** Add a SECOND field alongside HOUR/MINUTE. */\n withSeconds?: boolean\n /** Placeholder shown in each empty Hour/Minute/Second field. Default `\"--\"`. */\n placeholder?: string\n /** Locale used to resolve 12h vs 24h. Defaults to the active locale context. */\n locale?: string\n /** Overrides the sr-only Hour/Minute/Second/Period accessible names. English by default. */\n translations?: TimeRowTranslations\n size?: Size\n variant?: InputVariant\n className?: string\n classNames?: TimeInputClassNames\n }\n\ntype DisplayTime = {\n hour: number | null\n minute: number | null\n second: number | null\n period: \"AM\" | \"PM\" | null\n}\n\nconst emptyDisplay: DisplayTime = { hour: null, minute: null, second: null, period: null }\n\n/** Derive display-space fields (the cycle's own hours, + period) from a stored 24h value. */\nconst toDisplay = (value: TimeValue, cycle: HourCycle): DisplayTime => {\n if (value == null) return emptyDisplay\n const { hour, period } = toDisplayHour(value.hour, cycle)\n return { hour, minute: value.minute, second: value.second ?? null, period }\n}\n\n/** Merge a display-space edit back into a stored 24h value. Missing fields\n * default to midnight (or noon, once PM is picked) rather than nulling the whole\n * value out from under a field the user hasn't touched yet — `TimeInput`\n * has no `clearable` affordance in v1, so a value only ever moves from\n * `null` to a complete `{ hour, minute }`, never partway back. */\nconst fromDisplay = (display: DisplayTime, cycle: HourCycle): Exclude<TimeValue, null> => {\n const hour = fromDisplayHour(display.hour, display.period, cycle)\n const minute = display.minute ?? 0\n return display.second != null ? { hour, minute, second: display.second } : { hour, minute }\n}\n\n/**\n * The `TimeRow`, split out so it reads the `Field` context from *inside* the wrapping\n * `FieldShell` — `TimeInput` itself renders that shell, so calling `useFieldContext()` at its own\n * top level would run too early. The row is the field's real control: its `role=\"group\"` takes\n * the field label as its name and the helper / error text as its description. Outside a\n * `Field` (no label, description, error or `required`) there is no context and nothing to wire.\n */\nconst TimeInputRow = ({ labelled, ...rowProps }: TimeRowProps & { labelled: boolean }) => {\n const field = useFieldContext()\n const a11y = fieldA11yProps(field)\n return (\n <TimeRow\n {...rowProps}\n // A `Field` with only a description or error renders no `<label>` to point at.\n aria-labelledby={labelled ? a11y[\"aria-labelledby\"] : undefined}\n aria-describedby={a11y[\"aria-describedby\"]}\n />\n )\n}\n\nexport const TimeInput = ({\n value,\n defaultValue,\n onChange,\n format,\n hourCycle,\n minuteStep,\n withSeconds,\n placeholder,\n locale,\n translations,\n size = \"md\",\n variant = \"default\",\n disabled,\n readOnly,\n invalid,\n required,\n name,\n onBlur,\n ref,\n label,\n description,\n error,\n className,\n classNames,\n testId,\n}: TimeInputProps) => {\n const { locale: contextLocale } = useLocaleContext()\n const resolvedLocale = locale ?? contextLocale\n const resolvedCycle = resolveHourCycle({ locale: resolvedLocale, format, hourCycle })\n const isInvalid = invalid || error != null\n\n const [committed, setCommitted] = useUncontrolled<TimeValue>({\n value,\n defaultValue,\n finalValue: null,\n onChange,\n })\n\n const patch = (partial: Partial<DisplayTime>) => {\n const current = toDisplay(committed, resolvedCycle)\n setCommitted(fromDisplay({ ...current, ...partial }, resolvedCycle))\n }\n\n const display = toDisplay(committed, resolvedCycle)\n\n /** `HH:mm` / `HH:mm:ss`, zero-padded — the format a `<input type=\"time\">` /\n * server would expect from a hidden field. */\n const serialize = (time: TimeValue): string => {\n if (time == null) return \"\"\n const pad = (n: number) => String(n).padStart(2, \"0\")\n return time.second != null\n ? `${pad(time.hour)}:${pad(time.minute)}:${pad(time.second)}`\n : `${pad(time.hour)}:${pad(time.minute)}`\n }\n\n return (\n <FieldShell\n label={label}\n description={description}\n error={error}\n required={required}\n disabled={disabled}\n size={size}\n className={classNames?.field}\n // Hour / Minute / [Second] / AM-PM: no single input for the label's `for` to point at.\n composite\n >\n {/* No single focusable control to route `testId` to — Hour/Minute/[Second] +\n AM/PM are each their own field — so it lands on the wrapping shell. */}\n <div className={className} {...props({ \"data-testid\": testId })}>\n <TimeInputRow\n labelled={label != null}\n hour={display.hour}\n minute={display.minute}\n second={display.second}\n onHourChange={(hour) => patch({ hour })}\n onMinuteChange={(minute) => patch({ minute })}\n onSecondChange={withSeconds ? (second) => patch({ second }) : undefined}\n period={display.period}\n onPeriodChange={(period) => patch({ period })}\n hourCycle={resolvedCycle}\n minuteStep={minuteStep}\n withSeconds={withSeconds}\n placeholder={placeholder}\n locale={resolvedLocale}\n translations={translations}\n size={size}\n variant={variant}\n disabled={disabled}\n readOnly={readOnly}\n invalid={isInvalid}\n ref={ref}\n onBlur={onBlur}\n classNames={classNames}\n />\n {name && <input type=\"hidden\" name={name} value={serialize(committed)} />}\n </div>\n </FieldShell>\n )\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import '../../chunk-ZP6EBROY.js';
|
|
3
|
-
export { Tooltip } from '../../chunk-
|
|
4
|
-
import '../../chunk-
|
|
3
|
+
export { Tooltip } from '../../chunk-YZJUPYPO.js';
|
|
4
|
+
import '../../chunk-V6PY7C6S.js';
|
|
5
5
|
import '../../chunk-7P32XCEU.js';
|
|
6
6
|
import '../../chunk-WYCMIIRR.js';
|
|
7
7
|
import '../../chunk-C6NVU4F7.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { buildMaps, filterTree, flattenTree, useTreeRovingFocus, TreeTrigger, TreeSearch, TreeBody, renderTree, isLeaf, TreeLabel, TreeRails, treeRow, treeItemAria } from '../../chunk-
|
|
2
|
+
import { buildMaps, filterTree, flattenTree, useTreeRovingFocus, TreeTrigger, TreeSearch, TreeBody, renderTree, isLeaf, TreeLabel, TreeRails, treeRow, treeItemAria } from '../../chunk-WXL5RP6P.js';
|
|
3
3
|
import { usePillOverflow, PillOverflowCounter, pillsContent, pillsShell } from '../../chunk-O5W3QWJ6.js';
|
|
4
4
|
import { Pill } from '../../chunk-6M6YZ3PQ.js';
|
|
5
5
|
import { controlIndicator } from '../../chunk-NLOBBJAA.js';
|
|
@@ -8,7 +8,8 @@ import { placeholderColor, inputShell } from '../../chunk-45QRQKRC.js';
|
|
|
8
8
|
import { FieldShell } from '../../chunk-VD6PB3VA.js';
|
|
9
9
|
import '../../chunk-2LI3VPDP.js';
|
|
10
10
|
import '../../chunk-IPYHTCFL.js';
|
|
11
|
-
import { Popover } from '../../chunk-
|
|
11
|
+
import { Popover } from '../../chunk-N66NC6QK.js';
|
|
12
|
+
import '../../chunk-V6PY7C6S.js';
|
|
12
13
|
import '../../chunk-7P32XCEU.js';
|
|
13
14
|
import '../../chunk-H7WOMZXO.js';
|
|
14
15
|
import '../../chunk-6N6J2DOE.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/tree-multi-select/tree-multi-select.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAmEA,IAAM,aAAA,GAAgB,CAAC,IAAA,EAAoB,GAAA,GAAgB,EAAC,KAAgB;AAC1E,EAAA,IAAI,MAAA,CAAO,IAAI,CAAA,EAAG;AAChB,IAAA,IAAI,CAAC,IAAA,CAAK,QAAA,EAAU,GAAA,CAAI,IAAA,CAAK,KAAK,KAAK,CAAA;AACvC,IAAA,OAAO,GAAA;AAAA,EACT;AACA,EAAA,IAAI,IAAA,CAAK,UAAU,KAAA,MAAW,KAAA,IAAS,KAAK,QAAA,EAAU,aAAA,CAAc,OAAO,GAAG,CAAA;AAC9E,EAAA,OAAO,GAAA;AACT,CAAA;AAGA,IAAM,YAAA,GAAe,CAAC,IAAA,EAAoB,QAAA,KAAqC;AAC7E,EAAA,MAAM,MAAA,GAAS,cA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Q,OAAA,EAAR,EAAgB,cAAY,KAAA,EAAO,SAAA,EAAW,YAAY,OAAA,EACxD,QAAA,EAAA;AAAA,UAAA,UAAA,oBACC,GAAA;AAAA,YAAC,UAAA;AAAA,YAAA;AAAA,cACC,GAAA,EAAK,SAAA;AAAA,cACL,KAAA,EAAO,MAAA;AAAA,cACP,QAAA,EAAU,SAAA;AAAA,cACV,SAAA,EAAW,eAAA;AAAA,cACX,WAAA,EAAa,iBAAA;AAAA,cACb,OAAO,oBAAA,CAAqB,WAAA;AAAA,cAC5B,WAAW,UAAA,EAAY;AAAA;AAAA,WACzB;AAAA,0BAGF,GAAA;AAAA,YAAC,QAAA;AAAA,YAAA;AAAA,cACC,EAAA,EAAI,MAAA;AAAA,cACJ,OAAA,EAAS,KAAK,MAAA,KAAW,CAAA;AAAA,cACzB,KAAA;AAAA,cACA,eAAA,EAAe,IAAA;AAAA,cACf,SAAA,EAAW,aAAA;AAAA,cAEV,QAAA,EAAA,UAAA;AAAA;AAAA;AAAA,gBAGC,YAAA;AAAA,gBACA;AAAA;AACF;AAAA;AACF,SAAA,EACF,CAAA;AAAA,QAIC,IAAA,IAAQ,IAAA,IAAQ,KAAA,CAAM,GAAA,CAAI,CAAC,CAAA,qBAAM,GAAA,CAAC,OAAA,EAAA,EAAc,IAAA,EAAK,QAAA,EAAS,IAAA,EAAY,KAAA,EAAO,CAAA,EAAA,EAApC,CAAuC,CAAE;AAAA;AAAA;AAAA,GACzF;AAGF,EAAA,uBACE,GAAA;AAAA,IAAC,UAAA;AAAA,IAAA;AAAA,MACC,KAAA;AAAA,MACA,WAAA;AAAA,MACA,KAAA;AAAA,MACA,QAAA;AAAA,MACA,QAAA;AAAA,MACA,IAAA;AAAA,MACA,WAAW,UAAA,EAAY,KAAA;AAAA,MAEtB,QAAA,EAAA;AAAA;AAAA,GACH;AAEJ","file":"index.js","sourcesContent":["\"use client\"\n\nimport { type FocusEvent, type ReactNode, type Ref, useId, useMemo, useState } from \"react\"\nimport { cn } from \"../../lib/cn\"\nimport type { Color } from \"../../lib/colors\"\nimport { type IconMap, mergeIcons } from \"../../lib/icons\"\nimport { props } from \"../../lib/props\"\nimport { type ClearSectionMode, useLabelSearch } from \"../../lib/select-data\"\nimport type { WithTestId } from \"../../lib/test-id\"\nimport {\n buildMaps,\n filterTree,\n flattenTree,\n isLeaf,\n type RenderTreeMultiSelectItem,\n type TreeNodeData,\n type TreePayload,\n type TreeSelectData,\n type TreeValue,\n} from \"../../lib/tree-data\"\nimport { useUncontrolled } from \"../../lib/use-uncontrolled\"\nimport { controlIndicator } from \"../checkbox/control\"\nimport { type FieldProps, FieldShell } from \"../field/field\"\nimport { type InputSize, type InputVariant, inputShell, placeholderColor } from \"../input/input\"\nimport type { MultiSelectTranslations } from \"../multi-select/multi-select\"\nimport { Pill } from \"../pill/pill\"\nimport {\n PillOverflowCounter,\n pillsContent,\n pillsShell,\n usePillOverflow,\n} from \"../pills-input/pills-input\"\nimport { CheckIcon, ChevronIcon, CloseIcon, MinusIcon } from \"../popover/icons\"\nimport { Popover } from \"../popover/popover\"\nimport {\n renderTree,\n TreeBody,\n TreeLabel,\n type TreePosition,\n TreeRails,\n TreeSearch,\n TreeTrigger,\n treeItemAria,\n treeRow,\n useTreeRovingFocus,\n} from \"../tree-select/tree-popover\"\nimport type { TreeSelectTranslations } from \"../tree-select/tree-select\"\n\n/**\n * TreeMultiSelect — pick several values from hierarchical data, shown as a fully\n * expanded checkbox tree inside a Popover. There is no expand/collapse: every\n * node is always visible. Top-level rows sit flush; their descendants are\n * connected by indent guide lines. Each row carries a checkbox; checking a\n * branch cascades to all its leaves, and a branch with a partial selection\n * reads as indeterminate. With `searchable`, a search field at the top of the\n * popover filters the tree without competing with the trigger's pills.\n *\n * - `data` is a tree of `{ value, label, disabled?, children? }`.\n * - `value` is the selected **leaf** values (`string[]`); branch state is\n * derived. The trigger renders them as removable pills, like MultiSelect.\n * - Label / description / error come from the built-in `Field`.\n * - For a single-value tree picker, use `TreeSelect`.\n */\n\ntype NodeState = \"checked\" | \"indeterminate\" | \"unchecked\"\n\n/** Every *enabled* leaf value under `node` (the node itself when it's a leaf). */\nconst getLeafValues = (node: TreeNodeData, acc: string[] = []): string[] => {\n if (isLeaf(node)) {\n if (!node.disabled) acc.push(node.value)\n return acc\n }\n if (node.children) for (const child of node.children) getLeafValues(child, acc)\n return acc\n}\n\n/** Tri-state of a node, derived from the set of selected leaf values. */\nconst getNodeState = (node: TreeNodeData, selected: Set<string>): NodeState => {\n const leaves = getLeafValues(node)\n if (leaves.length === 0) return \"unchecked\"\n let on = 0\n for (const v of leaves) if (selected.has(v)) on++\n if (on === 0) return \"unchecked\"\n return on === leaves.length ? \"checked\" : \"indeterminate\"\n}\n\n/** Toggle a node: fully-checked clears its leaves, otherwise selects them all. */\nconst toggleNode = (node: TreeNodeData, current: string[]): string[] => {\n const leaves = getLeafValues(node)\n if (leaves.length === 0) return current\n const set = new Set(current)\n const fullyChecked = leaves.every((v) => set.has(v))\n for (const v of leaves) fullyChecked ? set.delete(v) : set.add(v)\n return [...set]\n}\n\ntype TreeMultiSelectClassNames = {\n field?: string\n trigger?: string\n popover?: string\n search?: string\n node?: string\n label?: string\n checkbox?: string\n pill?: string\n}\n\nexport type TreeMultiSelectIconSlot = \"check\" | \"indeterminate\" | \"chevron\" | \"clear\"\nexport type TreeMultiSelectIcons = IconMap<TreeMultiSelectIconSlot>\n\n/** The default icons: the row checkbox's check and partial mark, and the trigger's chevron\n * and clear ×. */\nconst DEFAULT_ICONS: Record<TreeMultiSelectIconSlot, ReactNode> = {\n check: <CheckIcon />,\n indeterminate: <MinusIcon />,\n chevron: <ChevronIcon />,\n clear: <CloseIcon />,\n}\n\nexport type TreeMultiSelectProps<Data extends TreeSelectData = TreeNodeData[]> = Pick<\n FieldProps,\n \"label\" | \"description\" | \"error\" | \"required\"\n> &\n WithTestId & {\n /** Hierarchical options. */\n data: Data\n /** Controlled selection — the selected leaf values. */\n value?: TreeValue<Data>[]\n /** Uncontrolled initial selection. */\n defaultValue?: TreeValue<Data>[]\n /** Fires with the full leaf selection on every toggle / removal. */\n onChange?: (value: TreeValue<Data>[]) => void\n /**\n * Render each node's content yourself. Receives the node and its live\n * `{ checked, indeterminate, leaf, disabled, depth }` state; the component keeps\n * the row (treeitem role, indent rails, roving focus, click), the callback fills\n * the content after the rails — including any checkbox. Omit it for the default\n * checkbox + label.\n */\n renderItem?: RenderTreeMultiSelectItem<TreePayload<Data>>\n /** Show a button that clears the whole selection. */\n clearable?: boolean\n /** Whether the clear button replaces the chevron (`\"replace\"`, default) or sits beside it (`\"both\"`). */\n clearSectionMode?: ClearSectionMode\n /** Show a search field that filters the tree. Default `false`. */\n searchable?: boolean\n /** Placeholder for the search field. */\n searchPlaceholder?: string\n /** Message shown when the search matches nothing. */\n empty?: ReactNode\n /** Placeholder shown while nothing is selected. */\n placeholder?: string\n /** Cap the pills at N rows; the rest collapse into a static \"+N\" counter. */\n maxLines?: number\n /** Inline-start adornment (icon, label). */\n startSlot?: ReactNode\n /** Inline-end adornment — rendered before the clear button / chevron. */\n endSlot?: ReactNode\n size?: InputSize\n variant?: InputVariant\n color?: Color\n disabled?: boolean\n /** Keeps full contrast but blocks opening and toggling. */\n readOnly?: boolean\n /** Red invalid state, independent of (and OR'd with) `error`. */\n invalid?: boolean\n /** Wires hidden inputs into native form submission. */\n name?: string\n /** Forwarded to the trigger; drives touched/blurred validation. */\n onBlur?: (event: FocusEvent<HTMLDivElement>) => void\n /** Lands on the trigger `<div role=\"combobox\">` for focus-on-error. */\n ref?: Ref<HTMLDivElement>\n className?: string\n classNames?: TreeMultiSelectClassNames\n /** Overrides the control's accessible names — see `TreeMultiSelectTranslations`. A partial\n * override keeps the other defaults. */\n translations?: TreeMultiSelectTranslations\n /** Replaces the default icons: `check` and `indeterminate` (a row's checkbox), `chevron`\n * and `clear` (the trigger). A missing key keeps its default. A `renderItem` row draws\n * its own checkbox. */\n icons?: TreeMultiSelectIcons\n }\n\n/** `TreeSelect`'s keys — `clearTriggerLabel` (here the clear-all button, default\n * `\"Clear all\"`) and `searchLabel` (default `\"Search\"`) — plus `MultiSelect`'s `removeValue`:\n * a value pill's remove-button name, given the value's label (default `` label => `Remove ${label}` ``). */\nexport type TreeMultiSelectTranslations = TreeSelectTranslations &\n Pick<MultiSelectTranslations, \"removeValue\" | \"overflowCount\">\n\nconst TREE_MULTI_SELECT_DEFAULT_TRANSLATIONS = {\n clearTriggerLabel: \"Clear all\",\n searchLabel: \"Search\",\n removeValue: (label) => `Remove ${label}`,\n} as const satisfies TreeMultiSelectTranslations\n\nexport const TreeMultiSelect = <const Data extends TreeSelectData = TreeNodeData[]>({\n data,\n value: valueProp,\n defaultValue,\n onChange,\n renderItem,\n clearable = false,\n clearSectionMode = \"replace\",\n searchable = false,\n searchPlaceholder = \"Search…\",\n empty = \"Nothing found\",\n placeholder = \"Pick values\",\n maxLines,\n startSlot,\n endSlot,\n size = \"md\",\n variant = \"default\",\n color,\n disabled,\n readOnly,\n required,\n invalid,\n name,\n onBlur,\n ref,\n label,\n description,\n error,\n className,\n classNames,\n testId,\n translations,\n icons: iconsProp,\n}: TreeMultiSelectProps<Data>) => {\n const icons = mergeIcons(DEFAULT_ICONS, iconsProp)\n const resolvedTranslations = { ...TREE_MULTI_SELECT_DEFAULT_TRANSLATIONS, ...translations }\n const [value, setValue] = useUncontrolled<TreeValue<Data>[]>({\n value: valueProp,\n defaultValue: defaultValue ?? [],\n onChange,\n finalValue: [],\n })\n const [open, setOpen] = useState(false)\n const treeId = useId()\n const [search, setSearch] = useState(\"\")\n\n // Red state is driven independently of the `Field` error slot so a form\n // library can flip it from `fieldState.invalid` (see FormControlProps).\n const isInvalid = invalid || error != null\n\n const { labelMap, nodeMap } = useMemo(() => buildMaps(data), [data])\n const labelSearch = useLabelSearch()\n const selectedSet = useMemo(() => new Set(value), [value])\n const filteredData = useMemo(\n () => (searchable ? filterTree(data, search, labelSearch.matches) : data),\n [data, search, searchable, labelSearch],\n )\n const flat = useMemo(() => flattenTree(filteredData, !!disabled), [filteredData, disabled])\n const enabledValues = useMemo(() => flat.filter((f) => !f.disabled).map((f) => f.value), [flat])\n\n const toggle = (node: TreeNodeData) => setValue(toggleNode(node, value) as TreeValue<Data>[])\n const removeValue = (v: string) => setValue(value.filter((x) => x !== v))\n\n const { activeValue, setActiveValue, searchRef, rowProps, onTreeKeyDown, onSearchKeyDown } =\n useTreeRovingFocus({\n values: enabledValues,\n labelOf: (v) => labelMap.get(v) ?? v,\n open,\n searchable,\n onActivate: (v) => {\n const node = nodeMap.get(v)\n if (node && !(disabled || readOnly || node.disabled)) toggle(node)\n },\n })\n\n const { containerRef, visibleCount, hiddenCount } = usePillOverflow({\n maxLines,\n count: value.length,\n })\n\n const renderNode = (node: TreeNodeData<TreePayload<Data>>, position: TreePosition) => {\n // Render structure comes from the (possibly filtered) node, but cascade\n // state is derived from the original node so hidden leaves still count.\n const source = nodeMap.get(node.value) ?? node\n const state = getNodeState(source, selectedSet)\n const checked = state === \"checked\"\n const mixed = state === \"indeterminate\"\n const nodeDisabled = disabled || node.disabled\n const rowTestId = node.testId ?? `item-${node.value}`\n\n // Content after the indent rails. A custom `renderItem` owns the whole slot\n // (incl. the checkbox); otherwise render the presentational checkbox + label.\n const content = renderItem ? (\n renderItem(node, {\n checked,\n indeterminate: mixed,\n leaf: isLeaf(source),\n disabled: !!nodeDisabled,\n depth: position.depth,\n })\n ) : (\n <>\n {/* Presentational checkbox: state lives on the row's aria-checked. It\n borrows Checkbox's own box, driven by `data-state` the way Ark\n drives the real one, so checked and indeterminate match Checkbox. */}\n <span\n aria-hidden\n data-state={checked ? \"checked\" : mixed ? \"indeterminate\" : \"unchecked\"}\n className={cn(controlIndicator({ size, variant: \"filled\" }), classNames?.checkbox)}\n >\n {checked && icons.check}\n {mixed && icons.indeterminate}\n </span>\n\n <TreeLabel className={classNames?.label}>{node.label}</TreeLabel>\n </>\n )\n\n return (\n // biome-ignore lint/a11y/useKeyWithClickEvents: row activation (Enter/Space) is handled centrally by the tree container's onKeyDown via roving focus, not co-located per row.\n <div\n role=\"treeitem\"\n {...treeItemAria(position)}\n aria-checked={mixed ? \"mixed\" : checked}\n {...props({\n \"aria-disabled\": nodeDisabled,\n \"data-checked\": checked,\n \"data-mixed\": mixed,\n \"data-disabled\": nodeDisabled,\n })}\n data-testid={rowTestId}\n tabIndex={node.value === activeValue ? 0 : -1}\n {...rowProps(node.value)}\n onClick={() => {\n if (nodeDisabled || readOnly) return\n setActiveValue(node.value)\n toggle(source)\n }}\n className={cn(treeRow({ size }), classNames?.node)}\n >\n <TreeRails {...position} />\n {content}\n </div>\n )\n }\n\n const control = (\n <Popover.Root\n open={open}\n onOpenChange={(details) => {\n if (disabled || readOnly) return\n setOpen(details.open)\n if (!details.open) setSearch(\"\")\n }}\n // We move focus into the search field / active row ourselves (with\n // preventScroll); Ark's autofocus would scroll the page to the top.\n autoFocus={false}\n width=\"target\"\n >\n <TreeTrigger\n ref={ref}\n open={open}\n disabled={disabled}\n readOnly={readOnly}\n invalid={isInvalid}\n color={color}\n testId={testId}\n startSlot={startSlot}\n endSlot={endSlot}\n onClear={\n clearable && value.length > 0 && !disabled && !readOnly ? () => setValue([]) : undefined\n }\n clearLabel={resolvedTranslations.clearTriggerLabel}\n clearSectionMode={clearSectionMode}\n icons={icons}\n onOpen={() => setOpen(true)}\n // Ark points this at the popover's dialog wrapper; point it at the\n // tree itself instead. The content stays mounted while closed, so the\n // (hidden) tree is a valid target then too, as in the APG combobox.\n // With no tree (search matched nothing), Ark's own target stands.\n aria-controls={flat.length > 0 ? treeId : undefined}\n onBlur={onBlur}\n className={cn(\n inputShell({ size, variant }),\n pillsShell,\n \"cursor-pointer\",\n className,\n classNames?.trigger,\n )}\n >\n <div ref={containerRef} className={pillsContent({ size })}>\n {value.length === 0 ? (\n <span className={cn(\"min-w-0 flex-1 truncate\", placeholderColor)}>{placeholder}</span>\n ) : (\n <>\n {value.slice(0, visibleCount).map((v) => (\n <Pill\n key={v}\n size={size}\n disabled={disabled}\n withRemoveButton={!disabled && !readOnly}\n onRemove={() => removeValue(v)}\n removeLabel={resolvedTranslations.removeValue(labelMap.get(v) ?? v)}\n className={classNames?.pill}\n data-overflow-item\n >\n {labelMap.get(v) ?? v}\n </Pill>\n ))}\n {hiddenCount > 0 && (\n <PillOverflowCounter\n count={hiddenCount}\n size={size}\n translations={resolvedTranslations}\n />\n )}\n </>\n )}\n </div>\n </TreeTrigger>\n\n <Popover.Content data-color={color} className={classNames?.popover}>\n {searchable && (\n <TreeSearch\n ref={searchRef}\n value={search}\n onChange={setSearch}\n onKeyDown={onSearchKeyDown}\n placeholder={searchPlaceholder}\n label={resolvedTranslations.searchLabel}\n className={classNames?.search}\n />\n )}\n\n <TreeBody\n id={treeId}\n isEmpty={flat.length === 0}\n empty={empty}\n multiselectable\n onKeyDown={onTreeKeyDown}\n >\n {renderTree(\n // `filterTree` only removes non-matching nodes — it can't change\n // their payload shape, so this is the same shape as `data`'s.\n filteredData as TreeNodeData<TreePayload<Data>>[],\n renderNode,\n )}\n </TreeBody>\n </Popover.Content>\n\n {/* Hidden inputs (one per value) for native `<form>` submission; form\n libraries instead read the value via `onChange`. */}\n {name != null && value.map((v) => <input key={v} type=\"hidden\" name={name} value={v} />)}\n </Popover.Root>\n )\n\n return (\n <FieldShell\n label={label}\n description={description}\n error={error}\n required={required}\n disabled={disabled}\n size={size}\n className={classNames?.field}\n >\n {control}\n </FieldShell>\n )\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/components/tree-multi-select/tree-multi-select.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAmEA,IAAM,aAAA,GAAgB,CAAC,IAAA,EAAoB,GAAA,GAAgB,EAAC,KAAgB;AAC1E,EAAA,IAAI,MAAA,CAAO,IAAI,CAAA,EAAG;AAChB,IAAA,IAAI,CAAC,IAAA,CAAK,QAAA,EAAU,GAAA,CAAI,IAAA,CAAK,KAAK,KAAK,CAAA;AACvC,IAAA,OAAO,GAAA;A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AA;AAAA,MACA,KAAA;AAAA,MACA,QAAA;AAAA,MACA,QAAA;AAAA,MACA,IAAA;AAAA,MACA,WAAW,UAAA,EAAY,KAAA;AAAA,MAEtB,QAAA,EAAA;AAAA;AAAA,GACH;AAEJ","file":"index.js","sourcesContent":["\"use client\"\n\nimport { type FocusEvent, type ReactNode, type Ref, useId, useMemo, useState } from \"react\"\nimport { cn } from \"../../lib/cn\"\nimport type { Color } from \"../../lib/colors\"\nimport { type IconMap, mergeIcons } from \"../../lib/icons\"\nimport { props } from \"../../lib/props\"\nimport { type ClearSectionMode, useLabelSearch } from \"../../lib/select-data\"\nimport type { WithTestId } from \"../../lib/test-id\"\nimport {\n buildMaps,\n filterTree,\n flattenTree,\n isLeaf,\n type RenderTreeMultiSelectItem,\n type TreeNodeData,\n type TreePayload,\n type TreeSelectData,\n type TreeValue,\n} from \"../../lib/tree-data\"\nimport { useUncontrolled } from \"../../lib/use-uncontrolled\"\nimport { controlIndicator } from \"../checkbox/control\"\nimport { type FieldProps, FieldShell } from \"../field/field\"\nimport { type InputSize, type InputVariant, inputShell, placeholderColor } from \"../input/input\"\nimport type { MultiSelectTranslations } from \"../multi-select/multi-select\"\nimport { Pill } from \"../pill/pill\"\nimport {\n PillOverflowCounter,\n pillsContent,\n pillsShell,\n usePillOverflow,\n} from \"../pills-input/pills-input\"\nimport { CheckIcon, ChevronIcon, CloseIcon, MinusIcon } from \"../popover/icons\"\nimport { Popover } from \"../popover/popover\"\nimport {\n renderTree,\n TreeBody,\n TreeLabel,\n type TreePosition,\n TreeRails,\n TreeSearch,\n TreeTrigger,\n treeItemAria,\n treeRow,\n useTreeRovingFocus,\n} from \"../tree-select/tree-popover\"\nimport type { TreeSelectTranslations } from \"../tree-select/tree-select\"\n\n/**\n * TreeMultiSelect — pick several values from hierarchical data, shown as a fully\n * expanded checkbox tree inside a Popover. There is no expand/collapse: every\n * node is always visible. Top-level rows sit flush; their descendants are\n * connected by indent guide lines. Each row carries a checkbox; checking a\n * branch cascades to all its leaves, and a branch with a partial selection\n * reads as indeterminate. With `searchable`, a search field at the top of the\n * popover filters the tree without competing with the trigger's pills.\n *\n * - `data` is a tree of `{ value, label, disabled?, children? }`.\n * - `value` is the selected **leaf** values (`string[]`); branch state is\n * derived. The trigger renders them as removable pills, like MultiSelect.\n * - Label / description / error come from the built-in `Field`.\n * - For a single-value tree picker, use `TreeSelect`.\n */\n\ntype NodeState = \"checked\" | \"indeterminate\" | \"unchecked\"\n\n/** Every *enabled* leaf value under `node` (the node itself when it's a leaf). */\nconst getLeafValues = (node: TreeNodeData, acc: string[] = []): string[] => {\n if (isLeaf(node)) {\n if (!node.disabled) acc.push(node.value)\n return acc\n }\n if (node.children) for (const child of node.children) getLeafValues(child, acc)\n return acc\n}\n\n/** Tri-state of a node, derived from the set of selected leaf values. */\nconst getNodeState = (node: TreeNodeData, selected: Set<string>): NodeState => {\n const leaves = getLeafValues(node)\n if (leaves.length === 0) return \"unchecked\"\n let on = 0\n for (const v of leaves) if (selected.has(v)) on++\n if (on === 0) return \"unchecked\"\n return on === leaves.length ? \"checked\" : \"indeterminate\"\n}\n\n/** Toggle a node: fully-checked clears its leaves, otherwise selects them all. */\nconst toggleNode = (node: TreeNodeData, current: string[]): string[] => {\n const leaves = getLeafValues(node)\n if (leaves.length === 0) return current\n const set = new Set(current)\n const fullyChecked = leaves.every((v) => set.has(v))\n for (const v of leaves) fullyChecked ? set.delete(v) : set.add(v)\n return [...set]\n}\n\ntype TreeMultiSelectClassNames = {\n field?: string\n trigger?: string\n popover?: string\n search?: string\n node?: string\n label?: string\n checkbox?: string\n pill?: string\n}\n\nexport type TreeMultiSelectIconSlot = \"check\" | \"indeterminate\" | \"chevron\" | \"clear\"\nexport type TreeMultiSelectIcons = IconMap<TreeMultiSelectIconSlot>\n\n/** The default icons: the row checkbox's check and partial mark, and the trigger's chevron\n * and clear ×. */\nconst DEFAULT_ICONS: Record<TreeMultiSelectIconSlot, ReactNode> = {\n check: <CheckIcon />,\n indeterminate: <MinusIcon />,\n chevron: <ChevronIcon />,\n clear: <CloseIcon />,\n}\n\nexport type TreeMultiSelectProps<Data extends TreeSelectData = TreeNodeData[]> = Pick<\n FieldProps,\n \"label\" | \"description\" | \"error\" | \"required\"\n> &\n WithTestId & {\n /** Hierarchical options. */\n data: Data\n /** Controlled selection — the selected leaf values. */\n value?: TreeValue<Data>[]\n /** Uncontrolled initial selection. */\n defaultValue?: TreeValue<Data>[]\n /** Fires with the full leaf selection on every toggle / removal. */\n onChange?: (value: TreeValue<Data>[]) => void\n /**\n * Render each node's content yourself. Receives the node and its live\n * `{ checked, indeterminate, leaf, disabled, depth }` state; the component keeps\n * the row (treeitem role, indent rails, roving focus, click), the callback fills\n * the content after the rails — including any checkbox. Omit it for the default\n * checkbox + label.\n */\n renderItem?: RenderTreeMultiSelectItem<TreePayload<Data>>\n /** Show a button that clears the whole selection. */\n clearable?: boolean\n /** Whether the clear button replaces the chevron (`\"replace\"`, default) or sits beside it (`\"both\"`). */\n clearSectionMode?: ClearSectionMode\n /** Show a search field that filters the tree. Default `false`. */\n searchable?: boolean\n /** Placeholder for the search field. */\n searchPlaceholder?: string\n /** Message shown when the search matches nothing. */\n empty?: ReactNode\n /** Placeholder shown while nothing is selected. */\n placeholder?: string\n /** Cap the pills at N rows; the rest collapse into a static \"+N\" counter. */\n maxLines?: number\n /** Inline-start adornment (icon, label). */\n startSlot?: ReactNode\n /** Inline-end adornment — rendered before the clear button / chevron. */\n endSlot?: ReactNode\n size?: InputSize\n variant?: InputVariant\n color?: Color\n disabled?: boolean\n /** Keeps full contrast but blocks opening and toggling. */\n readOnly?: boolean\n /** Red invalid state, independent of (and OR'd with) `error`. */\n invalid?: boolean\n /** Wires hidden inputs into native form submission. */\n name?: string\n /** Forwarded to the trigger; drives touched/blurred validation. */\n onBlur?: (event: FocusEvent<HTMLDivElement>) => void\n /** Lands on the trigger `<div role=\"combobox\">` for focus-on-error. */\n ref?: Ref<HTMLDivElement>\n className?: string\n classNames?: TreeMultiSelectClassNames\n /** Overrides the control's accessible names — see `TreeMultiSelectTranslations`. A partial\n * override keeps the other defaults. */\n translations?: TreeMultiSelectTranslations\n /** Replaces the default icons: `check` and `indeterminate` (a row's checkbox), `chevron`\n * and `clear` (the trigger). A missing key keeps its default. A `renderItem` row draws\n * its own checkbox. */\n icons?: TreeMultiSelectIcons\n }\n\n/** `TreeSelect`'s keys — `clearTriggerLabel` (here the clear-all button, default\n * `\"Clear all\"`) and `searchLabel` (default `\"Search\"`) — plus `MultiSelect`'s `removeValue`:\n * a value pill's remove-button name, given the value's label (default `` label => `Remove ${label}` ``). */\nexport type TreeMultiSelectTranslations = TreeSelectTranslations &\n Pick<MultiSelectTranslations, \"removeValue\" | \"overflowCount\">\n\nconst TREE_MULTI_SELECT_DEFAULT_TRANSLATIONS = {\n clearTriggerLabel: \"Clear all\",\n searchLabel: \"Search\",\n removeValue: (label) => `Remove ${label}`,\n} as const satisfies TreeMultiSelectTranslations\n\nexport const TreeMultiSelect = <const Data extends TreeSelectData = TreeNodeData[]>({\n data,\n value: valueProp,\n defaultValue,\n onChange,\n renderItem,\n clearable = false,\n clearSectionMode = \"replace\",\n searchable = false,\n searchPlaceholder = \"Search…\",\n empty = \"Nothing found\",\n placeholder = \"Pick values\",\n maxLines,\n startSlot,\n endSlot,\n size = \"md\",\n variant = \"default\",\n color,\n disabled,\n readOnly,\n required,\n invalid,\n name,\n onBlur,\n ref,\n label,\n description,\n error,\n className,\n classNames,\n testId,\n translations,\n icons: iconsProp,\n}: TreeMultiSelectProps<Data>) => {\n const icons = mergeIcons(DEFAULT_ICONS, iconsProp)\n const resolvedTranslations = { ...TREE_MULTI_SELECT_DEFAULT_TRANSLATIONS, ...translations }\n const [value, setValue] = useUncontrolled<TreeValue<Data>[]>({\n value: valueProp,\n defaultValue: defaultValue ?? [],\n onChange,\n finalValue: [],\n })\n const [open, setOpen] = useState(false)\n const treeId = useId()\n const [search, setSearch] = useState(\"\")\n\n // Red state is driven independently of the `Field` error slot so a form\n // library can flip it from `fieldState.invalid` (see FormControlProps).\n const isInvalid = invalid || error != null\n\n const { labelMap, nodeMap } = useMemo(() => buildMaps(data), [data])\n const labelSearch = useLabelSearch()\n const selectedSet = useMemo(() => new Set(value), [value])\n const filteredData = useMemo(\n () => (searchable ? filterTree(data, search, labelSearch.matches) : data),\n [data, search, searchable, labelSearch],\n )\n const flat = useMemo(() => flattenTree(filteredData, !!disabled), [filteredData, disabled])\n const enabledValues = useMemo(() => flat.filter((f) => !f.disabled).map((f) => f.value), [flat])\n\n const toggle = (node: TreeNodeData) => setValue(toggleNode(node, value) as TreeValue<Data>[])\n const removeValue = (v: string) => setValue(value.filter((x) => x !== v))\n\n const { activeValue, setActiveValue, searchRef, rowProps, onTreeKeyDown, onSearchKeyDown } =\n useTreeRovingFocus({\n values: enabledValues,\n labelOf: (v) => labelMap.get(v) ?? v,\n open,\n searchable,\n onActivate: (v) => {\n const node = nodeMap.get(v)\n if (node && !(disabled || readOnly || node.disabled)) toggle(node)\n },\n })\n\n const { containerRef, visibleCount, hiddenCount } = usePillOverflow({\n maxLines,\n count: value.length,\n })\n\n const renderNode = (node: TreeNodeData<TreePayload<Data>>, position: TreePosition) => {\n // Render structure comes from the (possibly filtered) node, but cascade\n // state is derived from the original node so hidden leaves still count.\n const source = nodeMap.get(node.value) ?? node\n const state = getNodeState(source, selectedSet)\n const checked = state === \"checked\"\n const mixed = state === \"indeterminate\"\n const nodeDisabled = disabled || node.disabled\n const rowTestId = node.testId ?? `item-${node.value}`\n\n // Content after the indent rails. A custom `renderItem` owns the whole slot\n // (incl. the checkbox); otherwise render the presentational checkbox + label.\n const content = renderItem ? (\n renderItem(node, {\n checked,\n indeterminate: mixed,\n leaf: isLeaf(source),\n disabled: !!nodeDisabled,\n depth: position.depth,\n })\n ) : (\n <>\n {/* Presentational checkbox: state lives on the row's aria-checked. It\n borrows Checkbox's own box, driven by `data-state` the way Ark\n drives the real one, so checked and indeterminate match Checkbox. */}\n <span\n aria-hidden\n data-state={checked ? \"checked\" : mixed ? \"indeterminate\" : \"unchecked\"}\n className={cn(controlIndicator({ size, variant: \"filled\" }), classNames?.checkbox)}\n >\n {checked && icons.check}\n {mixed && icons.indeterminate}\n </span>\n\n <TreeLabel className={classNames?.label}>{node.label}</TreeLabel>\n </>\n )\n\n return (\n // biome-ignore lint/a11y/useKeyWithClickEvents: row activation (Enter/Space) is handled centrally by the tree container's onKeyDown via roving focus, not co-located per row.\n <div\n role=\"treeitem\"\n {...treeItemAria(position)}\n aria-checked={mixed ? \"mixed\" : checked}\n {...props({\n \"aria-disabled\": nodeDisabled,\n \"data-checked\": checked,\n \"data-mixed\": mixed,\n \"data-disabled\": nodeDisabled,\n })}\n data-testid={rowTestId}\n tabIndex={node.value === activeValue ? 0 : -1}\n {...rowProps(node.value)}\n onClick={() => {\n if (nodeDisabled || readOnly) return\n setActiveValue(node.value)\n toggle(source)\n }}\n className={cn(treeRow({ size }), classNames?.node)}\n >\n <TreeRails {...position} />\n {content}\n </div>\n )\n }\n\n const control = (\n <Popover.Root\n open={open}\n onOpenChange={(details) => {\n if (disabled || readOnly) return\n setOpen(details.open)\n if (!details.open) setSearch(\"\")\n }}\n // We move focus into the search field / active row ourselves (with\n // preventScroll); Ark's autofocus would scroll the page to the top.\n autoFocus={false}\n width=\"target\"\n >\n <TreeTrigger\n ref={ref}\n open={open}\n disabled={disabled}\n readOnly={readOnly}\n invalid={isInvalid}\n color={color}\n testId={testId}\n startSlot={startSlot}\n endSlot={endSlot}\n onClear={\n clearable && value.length > 0 && !disabled && !readOnly ? () => setValue([]) : undefined\n }\n clearLabel={resolvedTranslations.clearTriggerLabel}\n clearSectionMode={clearSectionMode}\n icons={icons}\n onOpen={() => setOpen(true)}\n // Ark points this at the popover's dialog wrapper; point it at the\n // tree itself instead. The content stays mounted while closed, so the\n // (hidden) tree is a valid target then too, as in the APG combobox.\n // With no tree (search matched nothing), Ark's own target stands.\n aria-controls={flat.length > 0 ? treeId : undefined}\n onBlur={onBlur}\n className={cn(\n inputShell({ size, variant }),\n pillsShell,\n \"cursor-pointer\",\n className,\n classNames?.trigger,\n )}\n >\n <div ref={containerRef} className={pillsContent({ size })}>\n {value.length === 0 ? (\n <span className={cn(\"min-w-0 flex-1 truncate\", placeholderColor)}>{placeholder}</span>\n ) : (\n <>\n {value.slice(0, visibleCount).map((v) => (\n <Pill\n key={v}\n size={size}\n disabled={disabled}\n withRemoveButton={!disabled && !readOnly}\n onRemove={() => removeValue(v)}\n removeLabel={resolvedTranslations.removeValue(labelMap.get(v) ?? v)}\n className={classNames?.pill}\n data-overflow-item\n >\n {labelMap.get(v) ?? v}\n </Pill>\n ))}\n {hiddenCount > 0 && (\n <PillOverflowCounter\n count={hiddenCount}\n size={size}\n translations={resolvedTranslations}\n />\n )}\n </>\n )}\n </div>\n </TreeTrigger>\n\n <Popover.Content data-color={color} className={classNames?.popover}>\n {searchable && (\n <TreeSearch\n ref={searchRef}\n value={search}\n onChange={setSearch}\n onKeyDown={onSearchKeyDown}\n placeholder={searchPlaceholder}\n label={resolvedTranslations.searchLabel}\n className={classNames?.search}\n />\n )}\n\n <TreeBody\n id={treeId}\n isEmpty={flat.length === 0}\n empty={empty}\n multiselectable\n onKeyDown={onTreeKeyDown}\n >\n {renderTree(\n // `filterTree` only removes non-matching nodes — it can't change\n // their payload shape, so this is the same shape as `data`'s.\n filteredData as TreeNodeData<TreePayload<Data>>[],\n renderNode,\n )}\n </TreeBody>\n </Popover.Content>\n\n {/* Hidden inputs (one per value) for native `<form>` submission; form\n libraries instead read the value via `onChange`. */}\n {name != null && value.map((v) => <input key={v} type=\"hidden\" name={name} value={v} />)}\n </Popover.Root>\n )\n\n return (\n <FieldShell\n label={label}\n description={description}\n error={error}\n required={required}\n disabled={disabled}\n size={size}\n className={classNames?.field}\n >\n {control}\n </FieldShell>\n )\n}\n"]}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { buildMaps, filterTree, flattenTree, isLeaf, useTreeRovingFocus, TreeTrigger, TreeSearch, TreeBody, renderTree, TreeLabel, TreeRails, treeRow, treeItemAria } from '../../chunk-
|
|
2
|
+
import { buildMaps, filterTree, flattenTree, isLeaf, useTreeRovingFocus, TreeTrigger, TreeSearch, TreeBody, renderTree, TreeLabel, TreeRails, treeRow, treeItemAria } from '../../chunk-WXL5RP6P.js';
|
|
3
3
|
import { useLabelSearch } from '../../chunk-7TDHT3QD.js';
|
|
4
4
|
import { placeholderColor, inputShell } from '../../chunk-45QRQKRC.js';
|
|
5
5
|
import { FieldShell } from '../../chunk-VD6PB3VA.js';
|
|
6
|
-
import { Popover, popoverIndicator } from '../../chunk-
|
|
6
|
+
import { Popover, popoverIndicator } from '../../chunk-N66NC6QK.js';
|
|
7
|
+
import '../../chunk-V6PY7C6S.js';
|
|
7
8
|
import '../../chunk-7P32XCEU.js';
|
|
8
9
|
import '../../chunk-H7WOMZXO.js';
|
|
9
10
|
import { useUncontrolled } from '../../chunk-PMUCGFY5.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/tree-select/tree-select.tsx"],"names":["label"],"mappings":";;;;;;;;;;;;;;;;;;AAqEA,IAAM,aAAA,GAAuD;AAAA,EAC3D,KAAA,sBAAQ,SAAA,EAAA,EAAU,CAAA;AAAA,EAClB,OAAA,sBAAU,WAAA,EAAA,EAAY,CAAA;AAAA,EACtB,KAAA,sBAAQ,SAAA,EAAA,EAAU;AACpB,CAAA;AAqEA,IAAM,gCAAA,GAAmC;AAAA,EACvC,iBAAA,EAAmB,OAAA;AAAA,EACnB,WAAA,EAAa;AACf,CAAA;AAEO,IAAM,aAAa,CAAqD;AAAA,EAC7E,IAAA;AAAA,EACA,KAAA,EAAO,SAAA;AAAA,EACP,YAAA;AAAA,EACA,QAAA;AAAA,EACA,UAAA;AAAA,EACA,SAAA,GAAY,KAAA;AAAA,EACZ,gBAAA,GAAmB,SAAA;AAAA,EACnB,UAAA,GAAa,KAAA;AAAA,EACb,iBAAA,G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AK,SAAA,EAAW,gBAAA,EAAmB,uBAAY,CAAA,EAEpD;AAAA;AAAA,SACF;AAAA,wBAEA,IAAA,CAAC,QAAQ,OAAA,EAAR,EAAgB,cAAY,KAAA,EAAO,SAAA,EAAW,YAAY,OAAA,EACxD,QAAA,EAAA;AAAA,UAAA,UAAA,oBACC,GAAA;AAAA,YAAC,UAAA;AAAA,YAAA;AAAA,cACC,GAAA,EAAK,SAAA;AAAA,cACL,KAAA,EAAO,MAAA;AAAA,cACP,QAAA,EAAU,SAAA;AAAA,cACV,SAAA,EAAW,eAAA;AAAA,cACX,WAAA,EAAa,iBAAA;AAAA,cACb,OAAO,oBAAA,CAAqB,WAAA;AAAA,cAC5B,WAAW,UAAA,EAAY;AAAA;AAAA,WACzB;AAAA,0BAGF,GAAA,CAAC,QAAA,EAAA,EAAS,EAAA,EAAI,MAAA,EAAQ,OAAA,EAAS,KAAK,MAAA,KAAW,CAAA,EAAG,KAAA,EAAc,SAAA,EAAW,aAAA,EACxE,QAAA,EAAA,UAAA;AAAA;AAAA;AAAA,YAGC,YAAA;AAAA,YACA;AAAA,WACF,EACF;AAAA,SAAA,EACF,CAAA;AAAA,QAIC,IAAA,IAAQ,wBAAQ,GAAA,CAAC,OAAA,EAAA,EAAM,MAAK,QAAA,EAAS,IAAA,EAAY,KAAA,EAAO,KAAA,IAAS,EAAA,EAAI;AAAA;AAAA;AAAA,GACxE;AAGF,EAAA,uBACE,GAAA;AAAA,IAAC,UAAA;AAAA,IAAA;AAAA,MACC,KAAA;AAAA,MACA,WAAA;AAAA,MACA,KAAA;AAAA,MACA,QAAA;AAAA,MACA,QAAA;AAAA,MACA,IAAA;AAAA,MACA,WAAW,UAAA,EAAY,KAAA;AAAA,MAEtB,QAAA,EAAA;AAAA;AAAA,GACH;AAEJ","file":"index.js","sourcesContent":["\"use client\"\n\nimport { type FocusEvent, type ReactNode, type Ref, useId, useMemo, useState } from \"react\"\nimport { cn } from \"../../lib/cn\"\nimport type { Color } from \"../../lib/colors\"\nimport { type IconMap, mergeIcons } from \"../../lib/icons\"\nimport { props } from \"../../lib/props\"\nimport { type ClearSectionMode, useLabelSearch } from \"../../lib/select-data\"\nimport type { WithTestId } from \"../../lib/test-id\"\nimport {\n buildMaps,\n filterTree,\n flattenTree,\n isLeaf,\n type RenderTreeSelectItem,\n type TreeNodeData,\n type TreePayload,\n type TreeSelectData,\n type TreeValue,\n} from \"../../lib/tree-data\"\nimport { useUncontrolled } from \"../../lib/use-uncontrolled\"\nimport type { ComboboxTranslations } from \"../combobox/combobox\"\nimport { type FieldProps, FieldShell } from \"../field/field\"\nimport { type InputSize, type InputVariant, inputShell, placeholderColor } from \"../input/input\"\nimport { CheckIcon, ChevronIcon, CloseIcon } from \"../popover/icons\"\nimport { Popover, popoverIndicator } from \"../popover/popover\"\nimport {\n renderTree,\n TreeBody,\n TreeLabel,\n type TreePosition,\n TreeRails,\n TreeSearch,\n TreeTrigger,\n treeItemAria,\n treeRow,\n useTreeRovingFocus,\n} from \"./tree-popover\"\n\n/**\n * TreeSelect — pick a *single* value from hierarchical data, shown as a fully\n * expanded tree inside a Popover. There is no expand/collapse: every node is\n * always visible. Top-level rows sit flush; their descendants are connected by\n * indent guide lines. With `searchable`, a search field at the top of the popover\n * filters the tree.\n *\n * - `data` is a tree of `{ value, label, disabled?, children? }`.\n * - **Leaves only** are selectable — a node with children is an organizational\n * branch, not a value. Picking a leaf marks it with a check and closes the\n * popover, like `Select`.\n * - `value` is a single `string | null`; the trigger shows the selected leaf's\n * label as text. `clearable` swaps the chevron for a clear button.\n * - Label / description / error come from the built-in `Field`.\n * - For multiple values, use `TreeMultiSelect`.\n */\n\ntype TreeSelectClassNames = {\n field?: string\n trigger?: string\n popover?: string\n search?: string\n node?: string\n label?: string\n}\n\nexport type TreeSelectIconSlot = \"check\" | \"chevron\" | \"clear\"\nexport type TreeSelectIcons = IconMap<TreeSelectIconSlot>\n\n/** The default icons: the selected leaf's check, and the trigger's chevron and clear ×. */\nconst DEFAULT_ICONS: Record<TreeSelectIconSlot, ReactNode> = {\n check: <CheckIcon />,\n chevron: <ChevronIcon />,\n clear: <CloseIcon />,\n}\n\nexport type TreeSelectProps<Data extends TreeSelectData = TreeNodeData[]> = Pick<\n FieldProps,\n \"label\" | \"description\" | \"error\" | \"required\"\n> &\n WithTestId & {\n /** Hierarchical options. */\n data: Data\n /** Controlled selection — the selected leaf value (or `null`). */\n value?: TreeValue<Data> | null\n /** Uncontrolled initial selection. */\n defaultValue?: TreeValue<Data> | null\n /** Fires with the selected leaf value, or `null` when cleared. */\n onChange?: (value: TreeValue<Data> | null) => void\n /**\n * Render each node's content yourself. Receives the node and its live\n * `{ selected, leaf, disabled, depth }` state; the component keeps the row\n * (treeitem role, indent rails, roving focus, click), the callback fills the\n * content after the rails — including any selected check. Omit it for the\n * default label + check.\n */\n renderItem?: RenderTreeSelectItem<TreePayload<Data>>\n /** Show a clear button (and allow deselecting) once a value is set. */\n clearable?: boolean\n /** Whether the clear button replaces the chevron (`\"replace\"`, default) or sits beside it (`\"both\"`). */\n clearSectionMode?: ClearSectionMode\n /** Show a search field that filters the tree. Default `false`. */\n searchable?: boolean\n /** Placeholder for the search field. */\n searchPlaceholder?: string\n /** Message shown when the search matches nothing. */\n empty?: ReactNode\n /** Placeholder shown while no value is selected. */\n placeholder?: string\n /** Inline-start adornment (icon, label). */\n startSlot?: ReactNode\n /** Inline-end adornment — rendered before the clear button / chevron. */\n endSlot?: ReactNode\n size?: InputSize\n variant?: InputVariant\n color?: Color\n disabled?: boolean\n /** Keeps full contrast but blocks opening and selection. */\n readOnly?: boolean\n /** Red invalid state, independent of (and OR'd with) `error`. */\n invalid?: boolean\n /** Wires a hidden input into native form submission. */\n name?: string\n /** Forwarded to the trigger; drives touched/blurred validation. */\n onBlur?: (event: FocusEvent<HTMLDivElement>) => void\n /** Lands on the trigger `<div role=\"combobox\">` for focus-on-error. */\n ref?: Ref<HTMLDivElement>\n className?: string\n classNames?: TreeSelectClassNames\n /** Overrides the clear button's (`clearTriggerLabel`, default `\"Clear\"`) and the search\n * field's (`searchLabel`, default `\"Search\"`) accessible names. A partial override keeps the\n * other default. */\n translations?: TreeSelectTranslations\n /** Replaces the default icons: `check` (the selected leaf), `chevron` and `clear` (the\n * trigger). A missing key keeps its default. A `renderItem` row draws its own check. */\n icons?: TreeSelectIcons\n }\n\n/** The combobox family's `clearTriggerLabel`, plus the popover search field's `searchLabel`. */\nexport type TreeSelectTranslations = Pick<ComboboxTranslations, \"clearTriggerLabel\"> & {\n searchLabel?: string\n}\n\nconst TREE_SELECT_DEFAULT_TRANSLATIONS = {\n clearTriggerLabel: \"Clear\",\n searchLabel: \"Search\",\n} as const satisfies TreeSelectTranslations\n\nexport const TreeSelect = <const Data extends TreeSelectData = TreeNodeData[]>({\n data,\n value: valueProp,\n defaultValue,\n onChange,\n renderItem,\n clearable = false,\n clearSectionMode = \"replace\",\n searchable = false,\n searchPlaceholder = \"Search…\",\n empty = \"Nothing found\",\n placeholder = \"Pick a value\",\n startSlot,\n endSlot,\n size = \"md\",\n variant = \"default\",\n color,\n disabled,\n readOnly,\n required,\n invalid,\n name,\n onBlur,\n ref,\n label,\n description,\n error,\n className,\n classNames,\n testId,\n translations,\n icons: iconsProp,\n}: TreeSelectProps<Data>) => {\n const icons = mergeIcons(DEFAULT_ICONS, iconsProp)\n const resolvedTranslations = { ...TREE_SELECT_DEFAULT_TRANSLATIONS, ...translations }\n const [value, setValue] = useUncontrolled<TreeValue<Data> | null>({\n value: valueProp,\n defaultValue: defaultValue ?? null,\n onChange,\n finalValue: null,\n })\n const [open, setOpen] = useState(false)\n const treeId = useId()\n const [search, setSearch] = useState(\"\")\n\n // Red state is driven independently of the `Field` error slot so a form\n // library can flip it from `fieldState.invalid` (see FormControlProps).\n const isInvalid = invalid || error != null\n\n const { labelMap, nodeMap } = useMemo(() => buildMaps(data), [data])\n const labelSearch = useLabelSearch()\n const filteredData = useMemo(\n () => (searchable ? filterTree(data, search, labelSearch.matches) : data),\n [data, search, searchable, labelSearch],\n )\n const flat = useMemo(() => flattenTree(filteredData, !!disabled), [filteredData, disabled])\n // Only enabled *leaves* take part in selection + roving focus; branches organize.\n const enabledLeaves = useMemo(\n () =>\n flat\n .filter(\n (f) => !f.disabled && isLeaf(nodeMap.get(f.value) ?? { value: f.value, label: f.value }),\n )\n .map((f) => f.value),\n [flat, nodeMap],\n )\n\n const selectLeaf = (node: TreeNodeData) => {\n setValue(node.value as TreeValue<Data>)\n setOpen(false)\n setSearch(\"\")\n }\n\n const { activeValue, setActiveValue, searchRef, rowProps, onTreeKeyDown, onSearchKeyDown } =\n useTreeRovingFocus({\n values: enabledLeaves,\n labelOf: (v) => labelMap.get(v) ?? v,\n open,\n searchable,\n onActivate: (v) => {\n const node = nodeMap.get(v)\n if (node && !(disabled || readOnly || node.disabled)) selectLeaf(node)\n },\n })\n\n const renderNode = (node: TreeNodeData<TreePayload<Data>>, position: TreePosition) => {\n const source = nodeMap.get(node.value) ?? node\n const leaf = isLeaf(source)\n const selected = leaf && value === node.value\n const nodeDisabled = disabled || node.disabled\n const rowTestId = node.testId ?? `item-${node.value}`\n const label = <TreeLabel className={classNames?.label}>{node.label}</TreeLabel>\n\n // Content after the indent rails. A custom `renderItem` owns the whole slot\n // (incl. any check); otherwise leaves show label + check, branches the label.\n const content = renderItem ? (\n renderItem(node, { selected, leaf, disabled: !!nodeDisabled, depth: position.depth })\n ) : leaf ? (\n <>\n {label}\n {selected && (\n <span aria-hidden className={popoverIndicator}>\n {icons.check}\n </span>\n )}\n </>\n ) : (\n label\n )\n\n return leaf ? (\n // biome-ignore lint/a11y/useKeyWithClickEvents: row activation (Enter/Space) is handled centrally by the tree container's onKeyDown via roving focus, not co-located per row.\n <div\n role=\"treeitem\"\n {...treeItemAria(position)}\n aria-selected={selected}\n {...props({ \"aria-disabled\": nodeDisabled, \"data-disabled\": nodeDisabled })}\n data-testid={rowTestId}\n tabIndex={node.value === activeValue ? 0 : -1}\n {...rowProps(node.value)}\n onClick={() => {\n if (nodeDisabled || readOnly) return\n setActiveValue(node.value)\n selectLeaf(source)\n }}\n className={cn(treeRow({ size }), selected && \"font-medium\", classNames?.node)}\n >\n <TreeRails {...position} />\n {content}\n </div>\n ) : (\n // Present as a treeitem for well-formed levels; `tabIndex={-1}` keeps it\n // out of the tab order, and roving focus + arrow nav stay on leaves.\n <div\n role=\"treeitem\"\n {...treeItemAria(position)}\n aria-expanded\n {...props({ \"aria-disabled\": nodeDisabled })}\n data-testid={rowTestId}\n tabIndex={-1}\n className={cn(treeRow({ size, interactive: false }), classNames?.node)}\n >\n <TreeRails {...position} />\n {content}\n </div>\n )\n }\n\n const control = (\n <Popover.Root\n open={open}\n onOpenChange={(details) => {\n if (disabled || readOnly) return\n setOpen(details.open)\n if (!details.open) setSearch(\"\")\n }}\n // We move focus into the search field / active row ourselves (with\n // preventScroll); Ark's autofocus would scroll the page to the top.\n autoFocus={false}\n width=\"target\"\n >\n <TreeTrigger\n ref={ref}\n open={open}\n disabled={disabled}\n readOnly={readOnly}\n invalid={isInvalid}\n color={color}\n testId={testId}\n startSlot={startSlot}\n endSlot={endSlot}\n onClear={\n clearable && value != null && !disabled && !readOnly ? () => setValue(null) : undefined\n }\n clearLabel={resolvedTranslations.clearTriggerLabel}\n clearSectionMode={clearSectionMode}\n icons={icons}\n onOpen={() => setOpen(true)}\n // Ark points this at the popover's dialog wrapper; point it at the\n // tree itself instead. The content stays mounted while closed, so the\n // (hidden) tree is a valid target then too, as in the APG combobox.\n // With no tree (search matched nothing), Ark's own target stands.\n aria-controls={flat.length > 0 ? treeId : undefined}\n onBlur={onBlur}\n className={cn(\n inputShell({ size, variant }),\n \"cursor-pointer\",\n className,\n classNames?.trigger,\n )}\n >\n <span className=\"min-w-0 flex-1 truncate text-start\">\n {value != null ? (\n (labelMap.get(value) ?? value)\n ) : (\n <span className={placeholderColor}>{placeholder}</span>\n )}\n </span>\n </TreeTrigger>\n\n <Popover.Content data-color={color} className={classNames?.popover}>\n {searchable && (\n <TreeSearch\n ref={searchRef}\n value={search}\n onChange={setSearch}\n onKeyDown={onSearchKeyDown}\n placeholder={searchPlaceholder}\n label={resolvedTranslations.searchLabel}\n className={classNames?.search}\n />\n )}\n\n <TreeBody id={treeId} isEmpty={flat.length === 0} empty={empty} onKeyDown={onTreeKeyDown}>\n {renderTree(\n // `filterTree` only removes non-matching nodes — it can't change\n // their payload shape, so this is the same shape as `data`'s.\n filteredData as TreeNodeData<TreePayload<Data>>[],\n renderNode,\n )}\n </TreeBody>\n </Popover.Content>\n\n {/* Hidden input for native `<form>` submission; form libraries instead\n read the value via `onChange`. */}\n {name != null && <input type=\"hidden\" name={name} value={value ?? \"\"} />}\n </Popover.Root>\n )\n\n return (\n <FieldShell\n label={label}\n description={description}\n error={error}\n required={required}\n disabled={disabled}\n size={size}\n className={classNames?.field}\n >\n {control}\n </FieldShell>\n )\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/components/tree-select/tree-select.tsx"],"names":["label"],"mappings":";;;;;;;;;;;;;;;;;;;AAqEA,IAAM,aAAA,GAAuD;AAAA,EAC3D,KAAA,sBAAQ,SAAA,EAAA,EAAU,CAAA;AAAA,EAClB,OAAA,sBAAU,WAAA,EAAA,EAAY,CAAA;AAAA,EACtB,KAAA,sBAAQ,SAAA,EAAA,EAAU;AACpB,CAAA;AAqEA,IAAM,gCAAA,GAAmC;AAAA,EACvC,iBAAA,EAAmB,OAAA;AAAA,EACnB,WAAA,EAAa;AACf,CAAA;AAEO,IAAM,aAAa,CAAqD;AAAA,EAC7E,IAAA;AAAA,EACA,KAAA,EAAO,SAAA;AAAA,EACP,YAAA;AAAA,EACA,QAAA;AAAA,EACA,UAAA;AAAA,EACA,SAAA,GAAY,KAAA;AAAA,EACZ,gBAAA,GAAmB,SAAA;AAAA,EACnB,UAAA,GAAa,KAAA;AAAA,EACb,iBAAA,GAAoB,cAAA;AAAA,EACpB,KAAA,GAAQ,eAAA;AAAA,EACR,WAAA,GAAc,cAAA;AAAA,EACd,SAAA;A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C,QAAQ,OAAA,EAAR,EAAgB,cAAY,KAAA,EAAO,SAAA,EAAW,YAAY,OAAA,EACxD,QAAA,EAAA;AAAA,UAAA,UAAA,oBACC,GAAA;AAAA,YAAC,UAAA;AAAA,YAAA;AAAA,cACC,GAAA,EAAK,SAAA;AAAA,cACL,KAAA,EAAO,MAAA;AAAA,cACP,QAAA,EAAU,SAAA;AAAA,cACV,SAAA,EAAW,eAAA;AAAA,cACX,WAAA,EAAa,iBAAA;AAAA,cACb,OAAO,oBAAA,CAAqB,WAAA;AAAA,cAC5B,WAAW,UAAA,EAAY;AAAA;AAAA,WACzB;AAAA,0BAGF,GAAA,CAAC,QAAA,EAAA,EAAS,EAAA,EAAI,MAAA,EAAQ,OAAA,EAAS,KAAK,MAAA,KAAW,CAAA,EAAG,KAAA,EAAc,SAAA,EAAW,aAAA,EACxE,QAAA,EAAA,UAAA;AAAA;AAAA;AAAA,YAGC,YAAA;AAAA,YACA;AAAA,WACF,EACF;AAAA,SAAA,EACF,CAAA;AAAA,QAIC,IAAA,IAAQ,wBAAQ,GAAA,CAAC,OAAA,EAAA,EAAM,MAAK,QAAA,EAAS,IAAA,EAAY,KAAA,EAAO,KAAA,IAAS,EAAA,EAAI;AAAA;AAAA;AAAA,GACxE;AAGF,EAAA,uBACE,GAAA;AAAA,IAAC,UAAA;AAAA,IAAA;AAAA,MACC,KAAA;AAAA,MACA,WAAA;AAAA,MACA,KAAA;AAAA,MACA,QAAA;AAAA,MACA,QAAA;AAAA,MACA,IAAA;AAAA,MACA,WAAW,UAAA,EAAY,KAAA;AAAA,MAEtB,QAAA,EAAA;AAAA;AAAA,GACH;AAEJ","file":"index.js","sourcesContent":["\"use client\"\n\nimport { type FocusEvent, type ReactNode, type Ref, useId, useMemo, useState } from \"react\"\nimport { cn } from \"../../lib/cn\"\nimport type { Color } from \"../../lib/colors\"\nimport { type IconMap, mergeIcons } from \"../../lib/icons\"\nimport { props } from \"../../lib/props\"\nimport { type ClearSectionMode, useLabelSearch } from \"../../lib/select-data\"\nimport type { WithTestId } from \"../../lib/test-id\"\nimport {\n buildMaps,\n filterTree,\n flattenTree,\n isLeaf,\n type RenderTreeSelectItem,\n type TreeNodeData,\n type TreePayload,\n type TreeSelectData,\n type TreeValue,\n} from \"../../lib/tree-data\"\nimport { useUncontrolled } from \"../../lib/use-uncontrolled\"\nimport type { ComboboxTranslations } from \"../combobox/combobox\"\nimport { type FieldProps, FieldShell } from \"../field/field\"\nimport { type InputSize, type InputVariant, inputShell, placeholderColor } from \"../input/input\"\nimport { CheckIcon, ChevronIcon, CloseIcon } from \"../popover/icons\"\nimport { Popover, popoverIndicator } from \"../popover/popover\"\nimport {\n renderTree,\n TreeBody,\n TreeLabel,\n type TreePosition,\n TreeRails,\n TreeSearch,\n TreeTrigger,\n treeItemAria,\n treeRow,\n useTreeRovingFocus,\n} from \"./tree-popover\"\n\n/**\n * TreeSelect — pick a *single* value from hierarchical data, shown as a fully\n * expanded tree inside a Popover. There is no expand/collapse: every node is\n * always visible. Top-level rows sit flush; their descendants are connected by\n * indent guide lines. With `searchable`, a search field at the top of the popover\n * filters the tree.\n *\n * - `data` is a tree of `{ value, label, disabled?, children? }`.\n * - **Leaves only** are selectable — a node with children is an organizational\n * branch, not a value. Picking a leaf marks it with a check and closes the\n * popover, like `Select`.\n * - `value` is a single `string | null`; the trigger shows the selected leaf's\n * label as text. `clearable` swaps the chevron for a clear button.\n * - Label / description / error come from the built-in `Field`.\n * - For multiple values, use `TreeMultiSelect`.\n */\n\ntype TreeSelectClassNames = {\n field?: string\n trigger?: string\n popover?: string\n search?: string\n node?: string\n label?: string\n}\n\nexport type TreeSelectIconSlot = \"check\" | \"chevron\" | \"clear\"\nexport type TreeSelectIcons = IconMap<TreeSelectIconSlot>\n\n/** The default icons: the selected leaf's check, and the trigger's chevron and clear ×. */\nconst DEFAULT_ICONS: Record<TreeSelectIconSlot, ReactNode> = {\n check: <CheckIcon />,\n chevron: <ChevronIcon />,\n clear: <CloseIcon />,\n}\n\nexport type TreeSelectProps<Data extends TreeSelectData = TreeNodeData[]> = Pick<\n FieldProps,\n \"label\" | \"description\" | \"error\" | \"required\"\n> &\n WithTestId & {\n /** Hierarchical options. */\n data: Data\n /** Controlled selection — the selected leaf value (or `null`). */\n value?: TreeValue<Data> | null\n /** Uncontrolled initial selection. */\n defaultValue?: TreeValue<Data> | null\n /** Fires with the selected leaf value, or `null` when cleared. */\n onChange?: (value: TreeValue<Data> | null) => void\n /**\n * Render each node's content yourself. Receives the node and its live\n * `{ selected, leaf, disabled, depth }` state; the component keeps the row\n * (treeitem role, indent rails, roving focus, click), the callback fills the\n * content after the rails — including any selected check. Omit it for the\n * default label + check.\n */\n renderItem?: RenderTreeSelectItem<TreePayload<Data>>\n /** Show a clear button (and allow deselecting) once a value is set. */\n clearable?: boolean\n /** Whether the clear button replaces the chevron (`\"replace\"`, default) or sits beside it (`\"both\"`). */\n clearSectionMode?: ClearSectionMode\n /** Show a search field that filters the tree. Default `false`. */\n searchable?: boolean\n /** Placeholder for the search field. */\n searchPlaceholder?: string\n /** Message shown when the search matches nothing. */\n empty?: ReactNode\n /** Placeholder shown while no value is selected. */\n placeholder?: string\n /** Inline-start adornment (icon, label). */\n startSlot?: ReactNode\n /** Inline-end adornment — rendered before the clear button / chevron. */\n endSlot?: ReactNode\n size?: InputSize\n variant?: InputVariant\n color?: Color\n disabled?: boolean\n /** Keeps full contrast but blocks opening and selection. */\n readOnly?: boolean\n /** Red invalid state, independent of (and OR'd with) `error`. */\n invalid?: boolean\n /** Wires a hidden input into native form submission. */\n name?: string\n /** Forwarded to the trigger; drives touched/blurred validation. */\n onBlur?: (event: FocusEvent<HTMLDivElement>) => void\n /** Lands on the trigger `<div role=\"combobox\">` for focus-on-error. */\n ref?: Ref<HTMLDivElement>\n className?: string\n classNames?: TreeSelectClassNames\n /** Overrides the clear button's (`clearTriggerLabel`, default `\"Clear\"`) and the search\n * field's (`searchLabel`, default `\"Search\"`) accessible names. A partial override keeps the\n * other default. */\n translations?: TreeSelectTranslations\n /** Replaces the default icons: `check` (the selected leaf), `chevron` and `clear` (the\n * trigger). A missing key keeps its default. A `renderItem` row draws its own check. */\n icons?: TreeSelectIcons\n }\n\n/** The combobox family's `clearTriggerLabel`, plus the popover search field's `searchLabel`. */\nexport type TreeSelectTranslations = Pick<ComboboxTranslations, \"clearTriggerLabel\"> & {\n searchLabel?: string\n}\n\nconst TREE_SELECT_DEFAULT_TRANSLATIONS = {\n clearTriggerLabel: \"Clear\",\n searchLabel: \"Search\",\n} as const satisfies TreeSelectTranslations\n\nexport const TreeSelect = <const Data extends TreeSelectData = TreeNodeData[]>({\n data,\n value: valueProp,\n defaultValue,\n onChange,\n renderItem,\n clearable = false,\n clearSectionMode = \"replace\",\n searchable = false,\n searchPlaceholder = \"Search…\",\n empty = \"Nothing found\",\n placeholder = \"Pick a value\",\n startSlot,\n endSlot,\n size = \"md\",\n variant = \"default\",\n color,\n disabled,\n readOnly,\n required,\n invalid,\n name,\n onBlur,\n ref,\n label,\n description,\n error,\n className,\n classNames,\n testId,\n translations,\n icons: iconsProp,\n}: TreeSelectProps<Data>) => {\n const icons = mergeIcons(DEFAULT_ICONS, iconsProp)\n const resolvedTranslations = { ...TREE_SELECT_DEFAULT_TRANSLATIONS, ...translations }\n const [value, setValue] = useUncontrolled<TreeValue<Data> | null>({\n value: valueProp,\n defaultValue: defaultValue ?? null,\n onChange,\n finalValue: null,\n })\n const [open, setOpen] = useState(false)\n const treeId = useId()\n const [search, setSearch] = useState(\"\")\n\n // Red state is driven independently of the `Field` error slot so a form\n // library can flip it from `fieldState.invalid` (see FormControlProps).\n const isInvalid = invalid || error != null\n\n const { labelMap, nodeMap } = useMemo(() => buildMaps(data), [data])\n const labelSearch = useLabelSearch()\n const filteredData = useMemo(\n () => (searchable ? filterTree(data, search, labelSearch.matches) : data),\n [data, search, searchable, labelSearch],\n )\n const flat = useMemo(() => flattenTree(filteredData, !!disabled), [filteredData, disabled])\n // Only enabled *leaves* take part in selection + roving focus; branches organize.\n const enabledLeaves = useMemo(\n () =>\n flat\n .filter(\n (f) => !f.disabled && isLeaf(nodeMap.get(f.value) ?? { value: f.value, label: f.value }),\n )\n .map((f) => f.value),\n [flat, nodeMap],\n )\n\n const selectLeaf = (node: TreeNodeData) => {\n setValue(node.value as TreeValue<Data>)\n setOpen(false)\n setSearch(\"\")\n }\n\n const { activeValue, setActiveValue, searchRef, rowProps, onTreeKeyDown, onSearchKeyDown } =\n useTreeRovingFocus({\n values: enabledLeaves,\n labelOf: (v) => labelMap.get(v) ?? v,\n open,\n searchable,\n onActivate: (v) => {\n const node = nodeMap.get(v)\n if (node && !(disabled || readOnly || node.disabled)) selectLeaf(node)\n },\n })\n\n const renderNode = (node: TreeNodeData<TreePayload<Data>>, position: TreePosition) => {\n const source = nodeMap.get(node.value) ?? node\n const leaf = isLeaf(source)\n const selected = leaf && value === node.value\n const nodeDisabled = disabled || node.disabled\n const rowTestId = node.testId ?? `item-${node.value}`\n const label = <TreeLabel className={classNames?.label}>{node.label}</TreeLabel>\n\n // Content after the indent rails. A custom `renderItem` owns the whole slot\n // (incl. any check); otherwise leaves show label + check, branches the label.\n const content = renderItem ? (\n renderItem(node, { selected, leaf, disabled: !!nodeDisabled, depth: position.depth })\n ) : leaf ? (\n <>\n {label}\n {selected && (\n <span aria-hidden className={popoverIndicator}>\n {icons.check}\n </span>\n )}\n </>\n ) : (\n label\n )\n\n return leaf ? (\n // biome-ignore lint/a11y/useKeyWithClickEvents: row activation (Enter/Space) is handled centrally by the tree container's onKeyDown via roving focus, not co-located per row.\n <div\n role=\"treeitem\"\n {...treeItemAria(position)}\n aria-selected={selected}\n {...props({ \"aria-disabled\": nodeDisabled, \"data-disabled\": nodeDisabled })}\n data-testid={rowTestId}\n tabIndex={node.value === activeValue ? 0 : -1}\n {...rowProps(node.value)}\n onClick={() => {\n if (nodeDisabled || readOnly) return\n setActiveValue(node.value)\n selectLeaf(source)\n }}\n className={cn(treeRow({ size }), selected && \"font-medium\", classNames?.node)}\n >\n <TreeRails {...position} />\n {content}\n </div>\n ) : (\n // Present as a treeitem for well-formed levels; `tabIndex={-1}` keeps it\n // out of the tab order, and roving focus + arrow nav stay on leaves.\n <div\n role=\"treeitem\"\n {...treeItemAria(position)}\n aria-expanded\n {...props({ \"aria-disabled\": nodeDisabled })}\n data-testid={rowTestId}\n tabIndex={-1}\n className={cn(treeRow({ size, interactive: false }), classNames?.node)}\n >\n <TreeRails {...position} />\n {content}\n </div>\n )\n }\n\n const control = (\n <Popover.Root\n open={open}\n onOpenChange={(details) => {\n if (disabled || readOnly) return\n setOpen(details.open)\n if (!details.open) setSearch(\"\")\n }}\n // We move focus into the search field / active row ourselves (with\n // preventScroll); Ark's autofocus would scroll the page to the top.\n autoFocus={false}\n width=\"target\"\n >\n <TreeTrigger\n ref={ref}\n open={open}\n disabled={disabled}\n readOnly={readOnly}\n invalid={isInvalid}\n color={color}\n testId={testId}\n startSlot={startSlot}\n endSlot={endSlot}\n onClear={\n clearable && value != null && !disabled && !readOnly ? () => setValue(null) : undefined\n }\n clearLabel={resolvedTranslations.clearTriggerLabel}\n clearSectionMode={clearSectionMode}\n icons={icons}\n onOpen={() => setOpen(true)}\n // Ark points this at the popover's dialog wrapper; point it at the\n // tree itself instead. The content stays mounted while closed, so the\n // (hidden) tree is a valid target then too, as in the APG combobox.\n // With no tree (search matched nothing), Ark's own target stands.\n aria-controls={flat.length > 0 ? treeId : undefined}\n onBlur={onBlur}\n className={cn(\n inputShell({ size, variant }),\n \"cursor-pointer\",\n className,\n classNames?.trigger,\n )}\n >\n <span className=\"min-w-0 flex-1 truncate text-start\">\n {value != null ? (\n (labelMap.get(value) ?? value)\n ) : (\n <span className={placeholderColor}>{placeholder}</span>\n )}\n </span>\n </TreeTrigger>\n\n <Popover.Content data-color={color} className={classNames?.popover}>\n {searchable && (\n <TreeSearch\n ref={searchRef}\n value={search}\n onChange={setSearch}\n onKeyDown={onSearchKeyDown}\n placeholder={searchPlaceholder}\n label={resolvedTranslations.searchLabel}\n className={classNames?.search}\n />\n )}\n\n <TreeBody id={treeId} isEmpty={flat.length === 0} empty={empty} onKeyDown={onTreeKeyDown}>\n {renderTree(\n // `filterTree` only removes non-matching nodes — it can't change\n // their payload shape, so this is the same shape as `data`'s.\n filteredData as TreeNodeData<TreePayload<Data>>[],\n renderNode,\n )}\n </TreeBody>\n </Popover.Content>\n\n {/* Hidden input for native `<form>` submission; form libraries instead\n read the value via `onChange`. */}\n {name != null && <input type=\"hidden\" name={name} value={value ?? \"\"} />}\n </Popover.Root>\n )\n\n return (\n <FieldShell\n label={label}\n description={description}\n error={error}\n required={required}\n disabled={disabled}\n size={size}\n className={classNames?.field}\n >\n {control}\n </FieldShell>\n )\n}\n"]}
|
package/dist/lib/placement.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import type { Popover as ArkPopover } from "@ark-ui/react/popover";
|
|
1
2
|
/**
|
|
2
|
-
* Shared by Menu/Tooltip (and any future floating-panel component with the
|
|
3
|
+
* Shared by Menu/Tooltip/HoverCard/Popover (and any future floating-panel component with the
|
|
3
4
|
* same contract): `position` accepts a component's own physical placement
|
|
4
5
|
* union `P` (Ark/Floating UI's vocabulary) plus the logical, RTL-aware
|
|
5
6
|
* horizontal sides `start` / `end`, resolved to `left` / `right` by direction.
|
|
@@ -13,4 +14,44 @@ export type LogicalPosition<P extends string> = P | "start" | "end";
|
|
|
13
14
|
* defeats ts-pattern's pattern-inference machinery.
|
|
14
15
|
*/
|
|
15
16
|
export declare function resolveLogicalPlacement<P extends string>(position: LogicalPosition<P>, dir: "ltr" | "rtl"): P;
|
|
17
|
+
/** Ark's positioning options — the same zag `PositioningOptions` for every
|
|
18
|
+
* floating machine (Popover, HoverCard, Menu, Tooltip). */
|
|
19
|
+
export type Positioning = NonNullable<ArkPopover.RootProps["positioning"]>;
|
|
20
|
+
/** Physical placements Ark understands — `bottom`, `top-start`, … */
|
|
21
|
+
export type Placement = NonNullable<Positioning["placement"]>;
|
|
22
|
+
/**
|
|
23
|
+
* The placement props Popover and HoverCard share, so a consumer can swap
|
|
24
|
+
* one for the other (or `HoverCard.Group` for `Popover.Group`) without
|
|
25
|
+
* rewriting where the panel goes. Built into Ark's `positioning` by
|
|
26
|
+
* `toPositioning`.
|
|
27
|
+
*/
|
|
28
|
+
export type PlacementProps = {
|
|
29
|
+
/** Panel placement relative to the trigger — Ark's physical placements,
|
|
30
|
+
* plus the RTL-aware `start` / `end` sides. Defaults to `"bottom"`. */
|
|
31
|
+
position?: LogicalPosition<Placement>;
|
|
32
|
+
/** Gap in px between the trigger and the panel. */
|
|
33
|
+
gutter?: number;
|
|
34
|
+
/** Fine placement, in px: `mainAxis` is the gap from the trigger (it replaces `gutter` when
|
|
35
|
+
* set), `crossAxis` slides the panel along the trigger's edge. Floating UI's `offset()`. */
|
|
36
|
+
offset?: {
|
|
37
|
+
mainAxis?: number | undefined;
|
|
38
|
+
crossAxis?: number | undefined;
|
|
39
|
+
} | undefined;
|
|
40
|
+
/** Hide the panel (`visibility: hidden`, no pointer events) once the
|
|
41
|
+
* trigger is fully clipped by its own scrolling ancestor, and restore it
|
|
42
|
+
* once back in view — Floating UI's `hide()` middleware
|
|
43
|
+
* (`strategy: "referenceHidden"`), already wired into Ark's positioning
|
|
44
|
+
* engine. Rides the positioner's existing scroll/resize listeners, so no
|
|
45
|
+
* extra observer is needed. Default `true` — a panel that can't see its
|
|
46
|
+
* own trigger is never in a state worth keeping visible; pass `false` to
|
|
47
|
+
* keep following the trigger's last known position. */
|
|
48
|
+
hideWhenDetached?: boolean;
|
|
49
|
+
/** Ark's full positioning options (`flip`, `slide`, `overlap`, `boundary`,
|
|
50
|
+
* `getAnchorElement`, …), for placements the props above can't express.
|
|
51
|
+
* Applied over them, so a key set here wins. */
|
|
52
|
+
positioning?: Positioning;
|
|
53
|
+
};
|
|
54
|
+
/** Build Ark's `positioning` from `PlacementProps` — `start` / `end`
|
|
55
|
+
* resolved for `dir`, `sameWidth` from the panel's `width`. */
|
|
56
|
+
export declare const toPositioning: ({ position, gutter, offset, hideWhenDetached, positioning }: PlacementProps, dir: "ltr" | "rtl", width: "target" | "auto") => Positioning;
|
|
16
57
|
//# sourceMappingURL=placement.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"placement.d.ts","sourceRoot":"","sources":["../../src/lib/placement.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS,MAAM,IAAI,CAAC,GAAG,OAAO,GAAG,KAAK,CAAA;AAEnE;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,CAAC,SAAS,MAAM,EACtD,QAAQ,EAAE,eAAe,CAAC,CAAC,CAAC,EAC5B,GAAG,EAAE,KAAK,GAAG,KAAK,GACjB,CAAC,CAIH"}
|
|
1
|
+
{"version":3,"file":"placement.d.ts","sourceRoot":"","sources":["../../src/lib/placement.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAElE;;;;;GAKG;AACH,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS,MAAM,IAAI,CAAC,GAAG,OAAO,GAAG,KAAK,CAAA;AAEnE;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,CAAC,SAAS,MAAM,EACtD,QAAQ,EAAE,eAAe,CAAC,CAAC,CAAC,EAC5B,GAAG,EAAE,KAAK,GAAG,KAAK,GACjB,CAAC,CAIH;AAED;4DAC4D;AAC5D,MAAM,MAAM,WAAW,GAAG,WAAW,CAAC,UAAU,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC,CAAA;AAE1E,qEAAqE;AACrE,MAAM,MAAM,SAAS,GAAG,WAAW,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC,CAAA;AAE7D;;;;;GAKG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B;4EACwE;IACxE,QAAQ,CAAC,EAAE,eAAe,CAAC,SAAS,CAAC,CAAA;IACrC,mDAAmD;IACnD,MAAM,CAAC,EAAE,MAAM,CAAA;IACf;iGAC6F;IAC7F,MAAM,CAAC,EACH;QACE,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;QAC7B,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;KAC/B,GACD,SAAS,CAAA;IACb;;;;;;;4DAOwD;IACxD,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B;;qDAEiD;IACjD,WAAW,CAAC,EAAE,WAAW,CAAA;CAC1B,CAAA;AAED;gEACgE;AAChE,eAAO,MAAM,aAAa,gEACuD,cAAc,OACxF,KAAK,GAAG,KAAK,SACX,QAAQ,GAAG,MAAM,KACvB,WAOD,CAAA"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { type ElementType, type ReactElement, type ReactNode } from "react";
|
|
2
|
+
import type { Positioning } from "./placement";
|
|
3
|
+
/**
|
|
4
|
+
* Shared by `HoverCard.Group` and `Popover.Group`: several named triggers on
|
|
5
|
+
* one Ark machine, one panel that slides from the active trigger to the next.
|
|
6
|
+
*/
|
|
7
|
+
/** Slide transition for a group's shared positioner. Ark sets the
|
|
8
|
+
* positioner's `transform: translate3d(var(--x), var(--y), 0)` inline
|
|
9
|
+
* (`@zag-js/popper`); animating `transform` itself makes the browser
|
|
10
|
+
* interpolate that translate between two trigger anchors when the group's
|
|
11
|
+
* active trigger changes. Passed as `style` (not a class) so it merges with,
|
|
12
|
+
* rather than replaces, Ark's own inline `transform`/`position` (Ark's
|
|
13
|
+
* `mergeProps` shallow-merges style objects); the same override-the-real-style
|
|
14
|
+
* technique `Tabs.Indicator` / `SegmentGroup` use for their sliding pill.
|
|
15
|
+
*
|
|
16
|
+
* Only applied once `useSlideAfterPlaced` reports `sliding`, never on an
|
|
17
|
+
* open's first placement: before it, the positioner sits at its unplaced
|
|
18
|
+
* origin (far off the trigger), and animating *that* jump reads as the panel
|
|
19
|
+
* flying in across the page instead of just appearing. A standalone `Root`
|
|
20
|
+
* never gets this at all: it also repositions on scroll/resize
|
|
21
|
+
* (`autoUpdate`), where an animated `transform` would look laggy rather than
|
|
22
|
+
* responsive. */
|
|
23
|
+
export declare const slideStyle: {
|
|
24
|
+
readonly transitionProperty: "transform";
|
|
25
|
+
readonly transitionDuration: "200ms";
|
|
26
|
+
readonly transitionTimingFunction: "cubic-bezier(0.32, 0.72, 0, 1)";
|
|
27
|
+
};
|
|
28
|
+
type UpdatePosition = NonNullable<Positioning["updatePosition"]>;
|
|
29
|
+
/**
|
|
30
|
+
* `sliding` turns true once an open's first placement has been applied, and
|
|
31
|
+
* false on every close. Waiting for the placement itself, not a frame count:
|
|
32
|
+
* the first one after an open can take several frames (the panel mounts,
|
|
33
|
+
* zag defers to the next frame, floating-ui computes asynchronously), and a
|
|
34
|
+
* transition switched on before it lands slides the panel in from its
|
|
35
|
+
* unplaced origin.
|
|
36
|
+
*
|
|
37
|
+
* Feed every open change to `onOpenChange`, and pass `updatePosition(...)`
|
|
38
|
+
* as the machine's `positioning.updatePosition` — zag calls it for every
|
|
39
|
+
* placement, with its own `updatePosition` to run. A consumer's own
|
|
40
|
+
* `updatePosition`, if any, is wrapped rather than replaced.
|
|
41
|
+
*/
|
|
42
|
+
export declare const useSlideAfterPlaced: () => {
|
|
43
|
+
sliding: boolean;
|
|
44
|
+
onOpenChange: (next: boolean) => void;
|
|
45
|
+
updatePosition: (custom?: UpdatePosition) => UpdatePosition;
|
|
46
|
+
};
|
|
47
|
+
/** Split a group's children into its `Content` parts (matched by `type`)
|
|
48
|
+
* and everything else (the triggers), one level deep. */
|
|
49
|
+
export declare const splitGroupChildren: <P extends {
|
|
50
|
+
value?: string;
|
|
51
|
+
}>(children: ReactNode, content: ElementType<P>) => {
|
|
52
|
+
contents: ReactElement<P, string | import("react").JSXElementConstructor<any>>[];
|
|
53
|
+
triggers: (string | number | bigint | Iterable<ReactNode> | Promise<string | number | bigint | boolean | Iterable<ReactNode> | ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | import("react").ReactPortal | null | undefined> | ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | import("react").ReactPortal)[];
|
|
54
|
+
};
|
|
55
|
+
/** The `Content` whose `value` matches the active trigger, under one forced,
|
|
56
|
+
* stable `key` — overriding whatever each was authored with (e.g.
|
|
57
|
+
* `key={person.handle}` in a `.map()`). The slot only ever renders one at a
|
|
58
|
+
* time, but a *different* key switching in reads to React as a different
|
|
59
|
+
* component, unmounting the real Positioner/Content DOM tree and mounting a
|
|
60
|
+
* fresh one instead of updating it in place. That fresh mount breaks the
|
|
61
|
+
* "one shared, sliding panel" contract: its position starts unset again, so
|
|
62
|
+
* every switch would look like the panel jumping in from the top. */
|
|
63
|
+
export declare const activeGroupContent: (contents: ReactElement<{
|
|
64
|
+
value?: string;
|
|
65
|
+
}>[], triggerValue: string | null) => ReactElement<{
|
|
66
|
+
value?: string;
|
|
67
|
+
}, string | import("react").JSXElementConstructor<any>> | null;
|
|
68
|
+
export {};
|
|
69
|
+
//# sourceMappingURL=slide-on-switch.d.ts.map
|