@eifi1/ui-kit 0.22.0 → 0.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +42 -25
- package/dist/chart.d.ts +11 -8
- package/dist/components/amount-input.d.ts +28 -8
- package/dist/components/amount-input.js +3 -1
- package/dist/components/amount-input.js.map +1 -1
- package/dist/components/autocomplete.d.ts +21 -0
- package/dist/components/autocomplete.js +128 -103
- package/dist/components/autocomplete.js.map +1 -1
- package/dist/components/button-group.d.ts +11 -8
- package/dist/components/calculator.d.ts +11 -8
- package/dist/components/column-mapper.d.ts +182 -0
- package/dist/components/column-mapper.js +375 -0
- package/dist/components/column-mapper.js.map +1 -0
- package/dist/components/combobox-core.d.ts +39 -2
- package/dist/components/combobox-core.js +29 -6
- package/dist/components/combobox-core.js.map +1 -1
- package/dist/components/combobox.d.ts +80 -2
- package/dist/components/combobox.js +448 -311
- package/dist/components/combobox.js.map +1 -1
- package/dist/components/confirm-dialog.d.ts +11 -8
- package/dist/components/confirm-dialog.js +7 -8
- package/dist/components/confirm-dialog.js.map +1 -1
- package/dist/components/copy-button.d.ts +8 -5
- package/dist/components/country-select.d.ts +50 -7
- package/dist/components/country-select.js +65 -9
- package/dist/components/country-select.js.map +1 -1
- package/dist/components/danger-confirm.d.ts +11 -8
- package/dist/components/danger-confirm.js +13 -3
- package/dist/components/danger-confirm.js.map +1 -1
- package/dist/components/date-picker.d.ts +41 -0
- package/dist/components/date-picker.js +269 -8
- package/dist/components/date-picker.js.map +1 -1
- package/dist/components/entity-combobox.d.ts +35 -1
- package/dist/components/entity-combobox.js +148 -112
- package/dist/components/entity-combobox.js.map +1 -1
- package/dist/components/facing-pair.d.ts +11 -8
- package/dist/components/field-parts.d.ts +116 -6
- package/dist/components/field-parts.js +84 -0
- package/dist/components/field-parts.js.map +1 -1
- package/dist/components/field-strip.d.ts +105 -0
- package/dist/components/field-strip.js +46 -0
- package/dist/components/field-strip.js.map +1 -0
- package/dist/components/file-button.d.ts +11 -8
- package/dist/components/file-dropzone.d.ts +11 -8
- package/dist/components/form-actions.d.ts +10 -7
- package/dist/components/form-actions.js +8 -2
- package/dist/components/form-actions.js.map +1 -1
- package/dist/components/iban-input.d.ts +11 -8
- package/dist/components/icon-picker.d.ts +10 -1
- package/dist/components/icon-picker.js +12 -4
- package/dist/components/icon-picker.js.map +1 -1
- package/dist/components/language-select.d.ts +11 -8
- package/dist/components/money-field.d.ts +14 -8
- package/dist/components/money-field.js.map +1 -1
- package/dist/components/month-picker.js +2 -1
- package/dist/components/month-picker.js.map +1 -1
- package/dist/components/multi-entity-combobox.d.ts +26 -1
- package/dist/components/multi-entity-combobox.js +143 -102
- package/dist/components/multi-entity-combobox.js.map +1 -1
- package/dist/components/number-field.d.ts +11 -8
- package/dist/components/number-input.d.ts +11 -8
- package/dist/components/numpad-sheet.d.ts +11 -8
- package/dist/components/phone-input.d.ts +11 -8
- package/dist/components/reauth-dialog.d.ts +2 -2
- package/dist/components/reauth-dialog.js +6 -8
- package/dist/components/reauth-dialog.js.map +1 -1
- package/dist/components/series-chart.d.ts +11 -8
- package/dist/components/settings-fields.d.ts +11 -8
- package/dist/components/share-card.d.ts +10 -7
- package/dist/components/swatch-picker.d.ts +17 -1
- package/dist/components/swatch-picker.js +10 -4
- package/dist/components/swatch-picker.js.map +1 -1
- package/dist/components/text-link.d.ts +10 -7
- package/dist/components/tile-radio.d.ts +20 -0
- package/dist/components/tile-radio.js +25 -8
- package/dist/components/tile-radio.js.map +1 -1
- package/dist/components/time-input.d.ts +11 -8
- package/dist/components/toggle-group.js +2 -2
- package/dist/components/toggle-group.js.map +1 -1
- package/dist/components/trigger-aria.d.ts +3 -0
- package/dist/components/trigger-aria.js +3 -1
- package/dist/components/trigger-aria.js.map +1 -1
- package/dist/components/ui.d.ts +8 -5
- package/dist/components/ui.js +5 -11
- package/dist/components/ui.js.map +1 -1
- package/dist/feedback/feedback-attachment.d.ts +1 -1
- package/dist/feedback/feedback-attachment.js +156 -56
- package/dist/feedback/feedback-attachment.js.map +1 -1
- package/dist/feedback/feedback-dialog.d.ts +1 -1
- package/dist/feedback/feedback-dialog.js.map +1 -1
- package/dist/feedback/feedback-inbox.d.ts +3 -2
- package/dist/feedback/feedback-inbox.js.map +1 -1
- package/dist/feedback/feedback-thread.d.ts +68 -287
- package/dist/feedback/feedback-thread.js +8 -1
- package/dist/feedback/feedback-thread.js.map +1 -1
- package/dist/{kit-labels-R8mIAc9N.d.ts → feedback-BxeQVzwq.d.ts} +405 -22
- package/dist/{feedback-attachment-NhUm7Zga.d.ts → feedback-attachment-fGAzZPf0.d.ts} +112 -10
- package/dist/feedback.d.ts +66 -2
- package/dist/hooks/use-file-drop.d.ts +11 -8
- package/dist/i18n/defaults.d.ts +11 -8
- package/dist/i18n/defaults.js +3 -1
- package/dist/i18n/defaults.js.map +1 -1
- package/dist/i18n/german.d.ts +11 -8
- package/dist/i18n/german.js +36 -2
- package/dist/i18n/german.js.map +1 -1
- package/dist/i18n/kit-labels.d.ts +7 -4
- package/dist/i18n/kit-labels.js.map +1 -1
- package/dist/i18n/languages.d.ts +11 -8
- package/dist/i18n/locales/de-CH.d.ts +11 -8
- package/dist/i18n/locales/en.d.ts +11 -8
- package/dist/i18n/locales/en.js +7 -0
- package/dist/i18n/locales/en.js.map +1 -1
- package/dist/i18n/locales/es.d.ts +11 -8
- package/dist/i18n/locales/es.js +37 -2
- package/dist/i18n/locales/es.js.map +1 -1
- package/dist/i18n/locales/fr.d.ts +11 -8
- package/dist/i18n/locales/fr.js +36 -2
- package/dist/i18n/locales/fr.js.map +1 -1
- package/dist/i18n/locales/hu.d.ts +11 -8
- package/dist/i18n/locales/hu.js +38 -2
- package/dist/i18n/locales/hu.js.map +1 -1
- package/dist/i18n/locales/it.d.ts +11 -8
- package/dist/i18n/locales/it.js +37 -2
- package/dist/i18n/locales/it.js.map +1 -1
- package/dist/i18n/locales/zh.d.ts +11 -8
- package/dist/i18n/locales/zh.js +34 -2
- package/dist/i18n/locales/zh.js.map +1 -1
- package/dist/i18n/review.d.ts +11 -8
- package/dist/i18n/review.js +20 -1
- package/dist/i18n/review.js.map +1 -1
- package/dist/index.d.ts +7 -3
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -1
- package/dist/lib/column-mapping.d.ts +81 -0
- package/dist/lib/column-mapping.js +108 -0
- package/dist/lib/column-mapping.js.map +1 -0
- package/dist/lib/table-text.d.ts +109 -1
- package/dist/lib/table-text.js +122 -1
- package/dist/lib/table-text.js.map +1 -1
- package/dist/rhf/fields.d.ts +89 -11
- package/dist/rhf/fields.js +124 -0
- package/dist/rhf/fields.js.map +1 -1
- package/dist/rhf/form.d.ts +11 -8
- package/dist/rhf.d.ts +12 -9
- package/dist/rhf.js.map +1 -1
- package/dist/shell/app-shell.d.ts +10 -7
- package/dist/shell/top-bar-brand.d.ts +11 -8
- package/dist/shell/topbar-action-menu.d.ts +36 -3
- package/dist/shell/topbar-action-menu.js +74 -33
- package/dist/shell/topbar-action-menu.js.map +1 -1
- package/dist/shell.d.ts +10 -7
- package/dist/table-text.d.ts +1 -1
- package/dist/wizard/stepper-nav.d.ts +41 -10
- package/dist/wizard/stepper-nav.js +4 -0
- package/dist/wizard/stepper-nav.js.map +1 -1
- package/dist/wizard.d.ts +11 -8
- package/package.json +1 -1
- package/src/components/amount-input.tsx +20 -1
- package/src/components/autocomplete.tsx +172 -111
- package/src/components/column-mapper.tsx +666 -0
- package/src/components/combobox-core.tsx +82 -9
- package/src/components/combobox.tsx +614 -332
- package/src/components/confirm-dialog.tsx +12 -8
- package/src/components/country-select.tsx +135 -22
- package/src/components/danger-confirm.tsx +91 -12
- package/src/components/date-picker.tsx +423 -10
- package/src/components/entity-combobox.tsx +217 -126
- package/src/components/field-parts.tsx +224 -5
- package/src/components/field-strip.tsx +149 -0
- package/src/components/form-actions.tsx +32 -4
- package/src/components/icon-picker.tsx +23 -4
- package/src/components/money-field.tsx +3 -0
- package/src/components/month-picker.tsx +2 -1
- package/src/components/multi-entity-combobox.tsx +207 -120
- package/src/components/reauth-dialog.tsx +17 -18
- package/src/components/swatch-picker.tsx +29 -5
- package/src/components/tile-radio.tsx +74 -13
- package/src/components/toggle-group.tsx +2 -2
- package/src/components/trigger-aria.ts +5 -0
- package/src/components/ui.tsx +7 -33
- package/src/feedback/feedback-attachment.tsx +308 -61
- package/src/feedback/feedback-dialog.tsx +7 -3
- package/src/feedback/feedback-inbox.tsx +3 -2
- package/src/feedback/feedback-thread.tsx +47 -4
- package/src/i18n/defaults.ts +2 -0
- package/src/i18n/german.ts +42 -0
- package/src/i18n/kit-labels.tsx +4 -0
- package/src/i18n/locales/en.ts +27 -5
- package/src/i18n/locales/es.ts +41 -0
- package/src/i18n/locales/fr.ts +42 -0
- package/src/i18n/locales/hu.ts +37 -0
- package/src/i18n/locales/it.ts +41 -0
- package/src/i18n/locales/zh.ts +32 -0
- package/src/i18n/review.ts +19 -0
- package/src/index.ts +18 -0
- package/src/lib/column-mapping.ts +234 -0
- package/src/lib/table-text.ts +271 -0
- package/src/rhf/fields.tsx +254 -0
- package/src/rhf.ts +2 -1
- package/src/shell/topbar-action-menu.tsx +134 -38
- package/src/wizard/stepper-nav.tsx +35 -1
- package/dist/components/field-anatomy.d.ts +0 -95
- package/dist/components/field-anatomy.js +0 -84
- package/dist/components/field-anatomy.js.map +0 -1
- package/src/components/field-anatomy.tsx +0 -190
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/components/danger-confirm.tsx"],"sourcesContent":["import { forwardRef, useCallback, useEffect, useId, useRef, useState } from \"react\";\nimport type { ChangeEvent, ComponentPropsWithoutRef, FormEvent, ReactNode } from \"react\";\nimport { cn } from \"../lib/cn\";\nimport { useKitLabels } from \"../i18n/kit-labels\";\nimport { Button, Input, Label, Spinner } from \"./ui\";\nimport type { InputProps } from \"./ui\";\nimport { Checkbox } from \"./checkbox\";\nimport { Tooltip } from \"./tooltip\";\nimport { useCommitReason } from \"./write-lock\";\n\n/**\n * How typed text is compared with the text it has to repeat — shared by\n * `DangerConfirm`'s `phraseMatch` and `useConfirm`'s `typedMatch`.\n *\n * - `\"trim\"` ignores spaces around the typed text — a phone keyboard's autocomplete\n * likes to add one. Case counts: \"delete\" is not \"DELETE\".\n * - `\"exact\"` compares character for character, spaces included.\n * - `\"caseless\"` trims AND ignores case: for an e-mail address, whose domain is\n * case-insensitive and whose local part every real mail server treats so. Both apps'\n * \"type the account's address\" rules (keksdose's `TYPE_EMAIL`, Kurvenschmiede's\n * `TypedConfirm`) compared `trim().toLowerCase()`, and a capital the user's keyboard\n * put at the start must not make the right row look like the wrong one.\n */\nexport type TypedMatch = \"trim\" | \"exact\" | \"caseless\";\n\n/** Whether `typed` repeats `target` under `mode` — see {@link TypedMatch}. Exported for\n * a caller that draws its own field (a dialog that also picks a recipient) and wants\n * the same rule as the kit's. */\nexport function typedMatches(typed: string, target: string, mode: TypedMatch = \"trim\"): boolean {\n if (mode === \"exact\") return typed === target;\n if (mode === \"trim\") return typed.trim() === target;\n // `toLowerCase`, not `toLocaleLowerCase`: the comparison must not change with the\n // reader's locale (a Turkish dotless i would otherwise fail an ASCII address).\n return typed.trim().toLowerCase() === target.trim().toLowerCase();\n}\n\n/**\n * Busy-while-a-promise-runs, for an action that MAY return one: `run(result, onResolved)`\n * marks the caller pending until `result` settles, calls `onResolved` if it fulfilled,\n * and only clears the flag if it rejected — the caller shows why and the user retries.\n * Nothing runs after unmount. Shared by `DangerConfirm` and `ReauthDialog`, whose\n * contract is the same: resolve = done, reject = stay put.\n *\n * @internal\n */\nexport function usePromisePending() {\n const [pending, setPending] = useState(false);\n const mounted = useRef(true);\n useEffect(() => {\n mounted.current = true;\n return () => {\n mounted.current = false;\n };\n }, []);\n const run = useCallback((result: unknown, onResolved: () => void): boolean => {\n if (!result || typeof (result as Promise<unknown>).then !== \"function\") return false;\n setPending(true);\n (result as Promise<unknown>).then(\n () => {\n if (!mounted.current) return;\n setPending(false);\n onResolved();\n },\n () => {\n if (mounted.current) setPending(false);\n },\n );\n return true;\n }, []);\n return { pending, run };\n}\n\n/** A label that is really there — `null`, `false` and `\"\"` are what a caller's\n * `cond && reason` evaluates to on the path where there is none. */\nfunction hasContent(node: ReactNode): boolean {\n return node !== undefined && node !== null && node !== false && node !== \"\";\n}\n\n/** The one word {@link CurrentPasswordInput} says on its own behalf — the\n * `dangerConfirm.password` label, shared with DangerConfirm's password field, so an\n * app translates \"Password\" once. */\nexport type CurrentPasswordInputLabels = Pick<DangerConfirmLabels, \"password\">;\n\n/**\n * Everything {@link Input} takes except what makes this field what it is: `type` is\n * always `\"password\"` and `autoComplete` always `\"current-password\"`.\n */\nexport interface CurrentPasswordInputProps extends Omit<InputProps, \"type\" | \"autoComplete\" | \"label\"> {\n /**\n * The visible label. Default `dangerConfirm.password` (\"Password\") — unless the field\n * is named another way (`aria-label` / `aria-labelledby`), which then stays the only\n * name. Pass the app's own word on a sign-in form (\"Password\", \"Your password\"), or\n * `null` for a field whose `<label htmlFor>` is drawn elsewhere (a form library's\n * `FormLabel`), which would otherwise be labelled twice.\n */\n label?: ReactNode;\n /** The value as a string — the `(next) => …` shape, so a caller holding it in\n * `useState` need not unwrap `event.target.value`. Fires alongside `onChange`,\n * never instead of it, so a form library's `onChange` keeps working. */\n onValueChange?: (value: string) => void;\n /**\n * A check is running (the sign-in request, the re-auth). The field turns `readOnly`,\n * NOT `disabled`: the field being submitted is usually the focused one (Enter was\n * pressed in it), and disabling a focused field drops focus to `<body>` — the user\n * lands nowhere when the \"wrong password\" answer comes back.\n */\n busy?: boolean;\n /** Per-instance override of `dangerConfirm.password`. */\n labels?: Partial<CurrentPasswordInputLabels>;\n}\n\n/**\n * The \"prove it is you\" field: a password input that a password manager fills with\n * the CURRENT password and never offers to generate a new one for.\n *\n * It is the field of a sign-in form, a re-auth step ({@link ReauthDialog} draws the same\n * field), and {@link DangerConfirm}'s `requirePassword`. Public since 0.22 for kastlan's\n * sign-in and re-auth (kastlan 1), which wrote `type=\"password\"` +\n * `autoComplete=\"current-password\"` by hand — and a sign-in field that forgets the\n * second half gets the browser's \"suggest a strong password\" offer on the one form where\n * a NEW password is never what is wanted. The reverse matters as much: a field that sets\n * a NEW password (a passphrase, a sign-up) must NOT be this one — keksdose #170 keeps\n * its passphrase doors on `new-password` / `off` for that reason.\n *\n * Everything else is {@link Input}: the reveal toggle, `error` (under the field,\n * `aria-describedby`, `aria-invalid`), `invalid`, `name`, `id`, `autoFocus`, `required`.\n * The ref is the `<input>`, so it works with `@eifi1/ui-kit/rhf`'s `FormControl` /\n * a `register()` spread, and controlled or uncontrolled.\n *\n * ```tsx\n * <CurrentPasswordInput name=\"password\" label={t(\"password\")} error={errors.password?.message}\n * busy={isSubmitting} {...register(\"password\")} />\n * ```\n */\nexport const CurrentPasswordInput = forwardRef<HTMLInputElement, CurrentPasswordInputProps>(\n function CurrentPasswordInput({ label, onValueChange, onChange, busy, readOnly, labels: labelsProp, ...rest }, ref) {\n const labels = useKitLabels(\"dangerConfirm\", DEFAULT_DANGER_CONFIRM_LABELS, labelsProp);\n const namedOtherwise = rest[\"aria-label\"] !== undefined || rest[\"aria-labelledby\"] !== undefined;\n return (\n <Input\n {...rest}\n ref={ref}\n // After the spread: a props object spread at the field must not turn it into a\n // text field, or into one the password manager offers a new password for.\n type=\"password\"\n autoComplete=\"current-password\"\n label={label === undefined ? (namedOtherwise ? undefined : labels.password) : hasContent(label) ? label : undefined}\n readOnly={Boolean(busy) || readOnly}\n onChange={(e) => {\n onChange?.(e);\n onValueChange?.(e.target.value);\n }}\n />\n );\n },\n);\nCurrentPasswordInput.displayName = \"CurrentPasswordInput\";\n\n/** The words {@link TypedConfirmField} says on its own behalf — the `dangerConfirm`\n * namespace's `phrase` and `phrasePlaceholder`, shared with DangerConfirm's own field,\n * so the sentence \"Type “X” to confirm\" is translated once. */\nexport type TypedConfirmFieldLabels = Pick<DangerConfirmLabels, \"phrase\" | \"phrasePlaceholder\">;\n\nexport interface TypedConfirmFieldProps\n extends Omit<InputProps, \"type\" | \"value\" | \"defaultValue\" | \"label\" | \"placeholder\"> {\n /** The text to repeat — a word (\"DELETE\"), a name, an e-mail address. */\n target: string;\n /** How the typed text is compared with `target` — {@link TypedMatch}. Default\n * `\"trim\"`, as {@link typedMatches}; `\"caseless\"` for an address or an\n * acknowledgement word a user may type in any case. */\n match?: TypedMatch;\n /** Controlled value. Left out, the field keeps its own (start: `defaultValue`). */\n value?: string;\n defaultValue?: string;\n /** The typed text as a string, on every keystroke. Fires alongside `onChange`. */\n onValueChange?: (value: string) => void;\n /**\n * The typed text started or stopped matching `target` — fired from the keystroke\n * that flipped it, so an uncontrolled field can still drive the button it guards. A\n * controlled caller that resets the value itself (on a close) knows the answer\n * already, and gets no call for that; it can also compute it with {@link typedMatches}.\n */\n onMatchedChange?: (matched: boolean) => void;\n /** The label. Default `dangerConfirm.phrase(target)` — \"Type “DELETE” to confirm\". */\n label?: ReactNode;\n /** Text inside the empty field. Default `dangerConfirm.phrasePlaceholder` (unset).\n * Given, the label moves ABOVE the field: a floating label occupies the empty\n * field, which is exactly where a placeholder shows. `\"\"` means none. */\n placeholder?: string;\n /** The guarded action is running: the field turns `readOnly` (not `disabled`, which\n * would drop the focus Enter left in it). */\n busy?: boolean;\n labels?: Partial<TypedConfirmFieldLabels>;\n}\n\n/**\n * The \"type this to confirm\" field — {@link DangerConfirm}'s `phrase` field and\n * `useConfirm({ requireTyped })`'s, on its own (keksdose K7).\n *\n * keksdose writes it by hand four times: the privacy enrol, upgrade and sweep dialogs\n * (type the acknowledgement word, then the key doors appear) and the admin's \"type the\n * user's address\" (`UserActionConfirm`), each an `Input` plus its own\n * `trim().toUpperCase()` / `toLowerCase()` comparison. None of those places is an\n * arm → confirm tile or a modal confirm — what is guarded is a whole form, or the\n * next step of a dialog — so the field had to stand alone. What it brings over a plain\n * `Input`: one match rule ({@link typedMatches}, which lower-cases locale-independently\n * on purpose), the label worded from the target in the app's language, and the\n * attributes a phone keyboard needs to leave the text alone (no autocomplete, no\n * auto-capital, no autocorrect, no spellcheck — a keyboard that \"corrects\" an e-mail\n * address makes the guard unpassable).\n *\n * The field reports whether it matches (`onMatchedChange`, and `data-matched` on the\n * `<input>` for styling); what the match unlocks is the caller's. The ref is the\n * `<input>`.\n *\n * ```tsx\n * const [ok, setOk] = useState(false);\n * <TypedConfirmField target={t(\"privacy.enroll_ack_word\")} match=\"caseless\" onMatchedChange={setOk} />\n * {ok && <KeyDoorsForm … />}\n * ```\n */\nexport const TypedConfirmField = forwardRef<HTMLInputElement, TypedConfirmFieldProps>(function TypedConfirmField(\n {\n target,\n match = \"trim\",\n value: valueProp,\n defaultValue = \"\",\n onValueChange,\n onMatchedChange,\n onChange,\n label: labelProp,\n placeholder: placeholderProp,\n busy,\n readOnly,\n labels: labelsProp,\n id,\n className,\n ...rest\n },\n ref,\n) {\n const labels = useKitLabels(\"dangerConfirm\", DEFAULT_DANGER_CONFIRM_LABELS, labelsProp);\n const [own, setOwn] = useState(defaultValue);\n const value = valueProp ?? own;\n const matched = typedMatches(value, target, match);\n const generated = useId();\n const fieldId = id ?? generated;\n const label =\n labelProp !== undefined\n ? labelProp\n : typeof labels.phrase === \"function\"\n ? labels.phrase(target)\n : labels.phrase;\n const fromLabels =\n labels.phrasePlaceholder === undefined\n ? undefined\n : typeof labels.phrasePlaceholder === \"function\"\n ? labels.phrasePlaceholder(target)\n : labels.phrasePlaceholder;\n const placeholder = placeholderProp ?? fromLabels;\n\n const fieldProps = {\n ...rest,\n ref,\n id: fieldId,\n value,\n autoComplete: \"off\",\n autoCapitalize: \"off\",\n autoCorrect: \"off\",\n spellCheck: false,\n readOnly: Boolean(busy) || readOnly,\n \"data-matched\": matched || undefined,\n onChange: (e: ChangeEvent<HTMLInputElement>) => {\n onChange?.(e);\n const next = e.target.value;\n if (valueProp === undefined) setOwn(next);\n onValueChange?.(next);\n const nextMatched = typedMatches(next, target, match);\n if (nextMatched !== matched) onMatchedChange?.(nextMatched);\n },\n };\n\n if (placeholder) {\n return (\n // A static label above, so the placeholder has the empty field to itself.\n <div className={cn(\"space-y-1.5\", className)}>\n <Label htmlFor={fieldId}>{label}</Label>\n <Input {...fieldProps} placeholder={placeholder} />\n </div>\n );\n }\n return <Input {...fieldProps} label={label} className={className} />;\n});\nTypedConfirmField.displayName = \"TypedConfirmField\";\n\n/**\n * Every string the tile renders — the `dangerConfirm` namespace of\n * `<UiKitProvider labels>`, overridable per instance through `labels`. The arm and\n * confirm buttons are usually worded per action (\"Delete budget\"), which is what the\n * `armLabel` / `confirmLabel` props are for; these are the fallbacks.\n */\nexport interface DangerConfirmLabels {\n /** The button that arms the tile. */\n arm: string;\n /** The button that runs the action once the guards are satisfied. */\n confirm: string;\n cancel: string;\n /** The warning above the fields, when no `prompt` is given. */\n prompt: string;\n /** Label of the password field (`requirePassword`). */\n password: string;\n /** Label of the type-to-confirm field. A FUNCTION of the phrase by default, like\n * every message that carries a value: where the phrase sits in the sentence moves\n * with the language. A plain STRING is taken as the finished label — for an app\n * whose catalogue already words it (\"Type DELETE to confirm\") and would otherwise\n * wrap it as `() => label`. */\n phrase: string | ((phrase: string) => string);\n /** Placeholder of the type-to-confirm field — a string, or a function of the\n * phrase (`(p) => p` echoes it). Optional and unset by default: the field keeps its\n * floating label, as before. Given, the label moves ABOVE the field (a floating\n * label occupies the empty field, which is exactly where a placeholder shows) and\n * the placeholder fills the field. An empty string means none. */\n phrasePlaceholder?: string | ((phrase: string) => string);\n /** 0.22: the checkbox `requireAcknowledge={true}` shows — \"I have read what this does\n * and want to continue\" (keksdose's `admin.users.confirm_ack`). */\n acknowledge: string;\n}\n\n/** `satisfies` rather than a type annotation, so `DEFAULT_DANGER_CONFIRM_LABELS.phrase`\n * stays callable for a caller that composes its own label from it. */\nexport const DEFAULT_DANGER_CONFIRM_LABELS = {\n arm: \"Delete…\",\n confirm: \"Delete\",\n cancel: \"Cancel\",\n prompt: \"This cannot be undone.\",\n password: \"Password\",\n phrase: (phrase: string) => `Type “${phrase}” to confirm`,\n acknowledge: \"I have read what this does and want to continue.\",\n} satisfies DangerConfirmLabels;\n\n/**\n * One line of {@link DangerConfirmProps.consequences}: what the action will do. A plain\n * string, or this, for a key of its own and the `severe` mark.\n */\nexport interface DangerConsequence {\n /** React key — keksdose keys its lines by what they say (\"api_tokens\", \"only_door\").\n * Default: the text when it is a string, else the position. */\n key?: string;\n text: ReactNode;\n /** \"There is no way back\" — painted in the danger colour rather than the list's\n * muted one. keksdose reserves it for the one line that loses something for good. */\n severe?: boolean;\n}\n\nexport interface DangerConfirmProps extends Omit<ComponentPropsWithoutRef<\"div\">, \"onChange\"> {\n /**\n * Runs the action, with the entered password when `requirePassword` is on.\n *\n * Return a promise and the tile manages itself: busy until it settles, disarmed\n * (fields wiped) when it resolves, still armed when it rejects — so the user can\n * correct a wrong password and retry. The rejection is not swallowed for you to\n * miss: handle it (and show why) in the caller, as with any mutation.\n */\n onConfirm: (password?: string) => void | Promise<unknown>;\n /** Show a password field; confirm stays disabled until it is filled. */\n requirePassword?: boolean;\n /**\n * Show an \"I understand\" checkbox; confirm stays disabled until it is ticked\n * (keksdose K7). `true` words it with `labels.acknowledge`; any other node IS the\n * checkbox's label (\"I understand Anna will be signed out everywhere\").\n *\n * The guard for an action whose risk is MIS-TARGETING less than carelessness:\n * keksdose's admin password reset asks for a typed address when the account has an\n * encrypted door to lose, and a tick otherwise (`UserActionConfirm`), and its plan\n * editor asks for the tick alone (`UserPlanEditor`). Both were hand-built beside this\n * tile because it had no tick. It combines with `phrase` and `requirePassword`: every\n * guard given must be satisfied.\n */\n requireAcknowledge?: ReactNode;\n /**\n * What the action will do, said before it happens — a list under the prompt, shown\n * once armed (keksdose K7, `UserActionConfirm`'s consequences). Strings, or\n * {@link DangerConsequence}s for a `severe` line in the danger colour.\n *\n * Derive them from the row's own facts rather than reciting the worst case: an admin\n * who reads the same paragraph on every row stops reading it (keksdose dev#488).\n */\n consequences?: readonly (string | DangerConsequence)[];\n /** Show a \"type <phrase> to confirm\" field; confirm stays disabled until the field\n * matches (case-sensitive; surrounding spaces ignored unless `phraseMatch=\"exact\"`). */\n phrase?: string;\n /**\n * How the typed text is compared with `phrase`. `\"trim\"` (default) ignores spaces\n * around it — a phone keyboard's autocomplete likes to add one. `\"exact\"` compares\n * character for character, spaces included, for an app whose contract is \"type\n * exactly this\". `\"caseless\"` (0.18) also ignores case — for a phrase that is an\n * e-mail address (keksdose's \"type the user's address\" admin rule). See\n * {@link TypedMatch}.\n */\n phraseMatch?: TypedMatch;\n /** The warning above the fields. Defaults to `labels.prompt`. */\n prompt?: ReactNode;\n /** `\"danger\"` (default) for what cannot be undone; `\"warning\"` for what can, at a\n * cost (loading demo data over your own). Colours the prompt and the confirm. */\n tone?: \"danger\" | \"warning\";\n /** Visible text of the arm button; defaults to `labels.arm`. */\n armLabel?: ReactNode;\n /** Visible text of the confirm button; defaults to `labels.confirm`. */\n confirmLabel?: ReactNode;\n /** The action is running: confirm shows a spinner and nothing can be pressed. For a\n * caller that tracks the mutation itself (a `useMutation`'s `isPending`); a\n * promise returned from `onConfirm` does the same on its own. */\n busy?: boolean;\n /** The arm button is disabled. */\n disabled?: boolean;\n /**\n * Why the action is not available — a read-only demo, a write lock, a missing\n * permission. Disables the arm button like `disabled`, and SAYS so: the sentence is\n * shown under the button and attached to it with `aria-describedby`, and the button\n * stays focusable (`aria-disabled`) so a keyboard user can land on it and hear why.\n *\n * On the ARM button rather than the confirm: arming asks for a password, and asking\n * for a password for a write that can never land is the worse of the two. A tile that\n * is ALREADY armed when the reason arrives (controlled `armed`, or a lock that landed\n * while it was open) keeps its fields but its confirm takes the reason the same way\n * — focusable, `aria-disabled`, the reason in its tooltip — and Enter does nothing.\n */\n lockedReason?: ReactNode;\n /**\n * This tile COMMITS — the 0.18 write-lock opt-in that {@link Button} has (keksdose\n * K3). Under a locked {@link WriteLockProvider} the lock's reason becomes\n * `lockedReason` (and wins over one of the tile's own), so a page that mounts the\n * provider no longer threads `lockedReason={lock.locked ? lock.reason : undefined}`\n * into every tile. No provider, or an unlocked one: no effect.\n */\n commit?: boolean;\n /** Controlled armed state. The parent can then collapse the tile from a mutation's\n * own `onSuccess` without returning a promise. */\n armed?: boolean;\n /** Called with the next armed state — on arm, cancel, and a resolved `onConfirm`. */\n onArmedChange?: (armed: boolean) => void;\n /** User-facing strings; see {@link DangerConfirmLabels}. */\n labels?: Partial<DangerConfirmLabels>;\n}\n\n/**\n * An \"arm → confirm\" tile for destructive actions: one button, which expands into a\n * warning, an optional list of consequences, an optional \"I understand\" tick, an\n * optional type-to-confirm field, an optional password field and a confirm that stays\n * disabled until every guard is satisfied.\n *\n * Keksdose hand-rolled it three times (load demo data, wipe everything, reset a\n * budget) and then as `shared/components/danger-confirm.tsx`; the only app-specific\n * part was its write-lock hook, which is `lockedReason` here.\n *\n * The fields are a `<form>`, so Enter confirms once the guards allow it. They are\n * wiped every time the tile disarms — a password must not sit in a collapsed tile.\n * Arming moves focus to the first field (or Cancel, when there is none — never to the\n * destructive button itself), and disarming moves it back to the arm button, so the\n * keyboard user is never left on an element that just vanished.\n */\nexport function DangerConfirm({\n onConfirm,\n requirePassword,\n requireAcknowledge,\n consequences,\n phrase,\n phraseMatch = \"trim\",\n prompt,\n tone = \"danger\",\n armLabel,\n confirmLabel,\n busy: busyProp,\n disabled,\n lockedReason: ownLockedReason,\n commit,\n armed: armedProp,\n onArmedChange,\n labels: labelsProp,\n className,\n ...rest\n}: DangerConfirmProps) {\n const labels = useKitLabels(\"dangerConfirm\", DEFAULT_DANGER_CONFIRM_LABELS, labelsProp);\n const lockedReason = useCommitReason(commit, ownLockedReason);\n const [armedState, setArmedState] = useState(false);\n const armed = armedProp ?? armedState;\n const [password, setPassword] = useState(\"\");\n const [typed, setTyped] = useState(\"\");\n const [acknowledged, setAcknowledged] = useState(false);\n const { pending, run } = usePromisePending();\n const busy = Boolean(busyProp) || pending;\n // `readOnly` rather than `disabled` on the fields while busy: disabling the field\n // that has focus (Enter was pressed in it) drops focus to <body>.\n const promptId = useId();\n const consequencesId = useId();\n const reasonId = useId();\n\n // The kit's Button takes no ref, so the two buttons focus is moved to are found by id.\n const armId = useId();\n const cancelId = useId();\n const firstFieldRef = useRef<HTMLInputElement>(null);\n // Focus moves only after a transition — never on mount, so a tile that renders armed\n // (controlled) does not take the page's focus merely by existing.\n const moveFocus = useRef(false);\n\n // A disarm from anywhere (cancel, a resolved confirm, the parent) wipes the fields.\n // During render, like NumberField's draft, so no frame shows a collapsed tile that\n // still holds a password.\n const [wasArmed, setWasArmed] = useState(armed);\n if (wasArmed !== armed) {\n setWasArmed(armed);\n if (!armed) {\n setPassword(\"\");\n setTyped(\"\");\n setAcknowledged(false);\n }\n }\n\n const prevArmed = useRef(armed);\n useEffect(() => {\n const changed = prevArmed.current !== armed;\n prevArmed.current = armed;\n const byUser = moveFocus.current;\n moveFocus.current = false;\n if (!changed) return;\n if (armed) {\n if (byUser) (firstFieldRef.current ?? document.getElementById(cancelId))?.focus();\n return;\n }\n // A controlled parent collapsing the tile from its own `onSuccess` did not go\n // through `setArmed`; if focus went down with the form, bring it back too.\n const lost = document.activeElement === null || document.activeElement === document.body;\n if (byUser || lost) document.getElementById(armId)?.focus();\n }, [armed, armId, cancelId]);\n\n const setArmed = (next: boolean) => {\n moveFocus.current = true;\n if (armedProp === undefined) setArmedState(next);\n onArmedChange?.(next);\n };\n\n const locked = hasContent(lockedReason);\n // `true` words the tick with the namespace; any other node is its label; `false`,\n // `null` and `\"\"` are no tick at all.\n const acknowledgeLabel: ReactNode =\n requireAcknowledge === true ? labels.acknowledge : hasContent(requireAcknowledge) ? requireAcknowledge : null;\n const asksAcknowledge = acknowledgeLabel !== null;\n const passwordOk = !requirePassword || password !== \"\";\n const phraseOk = phrase === undefined || typedMatches(typed, phrase, phraseMatch);\n const acknowledgeOk = !asksAcknowledge || acknowledged;\n const canConfirm = passwordOk && phraseOk && acknowledgeOk && !busy;\n\n const submit = (e: FormEvent) => {\n e.preventDefault();\n // `locked` too: Enter in a field submits the form without the button's say.\n if (!canConfirm || locked) return;\n // Disarms when it resolves; a rejection leaves it armed, fields kept: the caller\n // shows why, the user retries.\n run(onConfirm(requirePassword ? password : undefined), () => setArmed(false));\n };\n\n // The first field takes focus on arm: the tick, then the phrase, then the password —\n // the order they are drawn in.\n const firstField = asksAcknowledge ? \"acknowledge\" : phrase !== undefined ? \"phrase\" : \"password\";\n const lines = (consequences ?? []).map((item, index) =>\n typeof item === \"string\"\n ? { key: item, text: item as ReactNode, severe: false }\n : { key: item.key ?? String(index), text: item.text, severe: Boolean(item.severe) },\n );\n\n const toneText = tone === \"warning\" ? \"text-[var(--warning)]\" : \"text-[var(--danger)]\";\n\n if (!armed) {\n const arm = (\n <Button\n id={armId}\n type=\"button\"\n variant={tone === \"warning\" ? \"secondary\" : \"danger\"}\n disabled={disabled}\n aria-disabled={locked || undefined}\n aria-describedby={locked ? reasonId : undefined}\n onClick={() => {\n if (!locked) setArmed(true);\n }}\n className=\"aria-disabled:cursor-not-allowed aria-disabled:opacity-50\"\n >\n {armLabel ?? labels.arm}\n </Button>\n );\n return (\n <div {...rest} className={cn(\"space-y-1\", className)}>\n {locked ? (\n // The reason on the button itself too, where the pointer that tried it is —\n // the line below can sit out of view in a long settings card. Portalled, so\n // a card that scrolls neither clips it nor grows by it.\n //\n // The button in a FRAGMENT on purpose: Tooltip clones an element child to\n // add the bubble to its `aria-describedby`, and the button is already\n // described by the visible line below — the same sentence twice, read out\n // on every focus. A fragment is left as it is, so the bubble stays visual.\n <Tooltip label={lockedReason} portal>\n <>{arm}</>\n </Tooltip>\n ) : (\n arm\n )}\n {locked && (\n <p id={reasonId} className=\"text-xs text-[var(--text-muted)]\">\n {lockedReason}\n </p>\n )}\n </div>\n );\n }\n\n return (\n <div {...rest} className={cn(\"space-y-2\", className)}>\n <form\n className=\"space-y-2\"\n aria-describedby={lines.length > 0 ? `${promptId} ${consequencesId}` : promptId}\n aria-busy={busy || undefined}\n onSubmit={submit}\n noValidate\n >\n <p id={promptId} className={cn(\"text-xs font-medium\", toneText)}>\n {prompt ?? labels.prompt}\n </p>\n {lines.length > 0 && (\n <ul id={consequencesId} className=\"list-disc space-y-1 ps-5 text-xs text-[var(--text-secondary)]\">\n {lines.map((line) => (\n <li key={line.key} className={line.severe ? \"text-[var(--danger)]\" : undefined}>\n {line.text}\n </li>\n ))}\n </ul>\n )}\n {asksAcknowledge && (\n <Checkbox\n ref={firstField === \"acknowledge\" ? firstFieldRef : undefined}\n label={acknowledgeLabel}\n checked={acknowledged}\n // Not `disabled` while busy, for the same reason the fields are readOnly:\n // the box may hold the focus. A change while busy is simply not taken.\n onCheckedChange={(next) => {\n if (!busy) setAcknowledged(next);\n }}\n />\n )}\n {phrase !== undefined && (\n <TypedConfirmField\n ref={firstField === \"phrase\" ? firstFieldRef : undefined}\n target={phrase}\n match={phraseMatch}\n value={typed}\n onValueChange={setTyped}\n busy={busy}\n // Already resolved through this tile's own `labels` prop; handed on so a\n // per-instance phrase wording reaches the field.\n labels={{ phrase: labels.phrase, phrasePlaceholder: labels.phrasePlaceholder }}\n />\n )}\n {requirePassword && (\n <CurrentPasswordInput\n ref={firstField === \"password\" ? firstFieldRef : undefined}\n label={labels.password}\n value={password}\n busy={busy}\n onValueChange={setPassword}\n />\n )}\n <div className=\"flex flex-wrap gap-2\">\n <Button id={cancelId} type=\"button\" variant=\"ghost\" disabled={busy} onClick={() => setArmed(false)}>\n {labels.cancel}\n </Button>\n <Button\n type=\"submit\"\n variant={tone === \"warning\" ? \"primary\" : \"danger\"}\n disabled={!canConfirm}\n // Armed, then locked (or rendered armed under a lock): the confirm says why\n // the way Button does — focusable, `aria-disabled`, the reason in its\n // tooltip and description — and the fields stay as typed.\n disabledReason={locked ? lockedReason : undefined}\n aria-busy={busy || undefined}\n >\n {busy && <Spinner label={null} className=\"h-4 w-4\" />}\n {confirmLabel ?? labels.confirm}\n </Button>\n </div>\n {locked && <p className=\"text-xs text-[var(--text-muted)]\">{lockedReason}</p>}\n </form>\n </div>\n );\n}\n"],"mappings":";AA2IM,SA8cM,UA9cN,K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OAAO,OAAO;AAAA,YACd,OAAO;AAAA,YACP;AAAA,YACA,eAAe;AAAA;AAAA,QACjB;AAAA,QAEF,qBAAC,SAAI,WAAU,wBACb;AAAA,8BAAC,UAAO,IAAI,UAAU,MAAK,UAAS,SAAQ,SAAQ,UAAU,MAAM,SAAS,MAAM,SAAS,KAAK,GAC9F,iBAAO,QACV;AAAA,UACA;AAAA,YAAC;AAAA;AAAA,cACC,MAAK;AAAA,cACL,SAAS,SAAS,YAAY,YAAY;AAAA,cAC1C,UAAU,CAAC;AAAA,cAIX,gBAAgB,SAAS,eAAe;AAAA,cACxC,aAAW,QAAQ;AAAA,cAElB;AAAA,wBAAQ,oBAAC,WAAQ,OAAO,MAAM,WAAU,WAAU;AAAA,gBAClD,gBAAgB,OAAO;AAAA;AAAA;AAAA,UAC1B;AAAA,WACF;AAAA,QACC,UAAU,oBAAC,OAAE,WAAU,oCAAoC,wBAAa;AAAA;AAAA;AAAA,EAC3E,GACF;AAEJ;","names":["CurrentPasswordInput","TypedConfirmField"]}
|
|
1
|
+
{"version":3,"sources":["../../src/components/danger-confirm.tsx"],"sourcesContent":["import { forwardRef, useCallback, useEffect, useId, useRef, useState } from \"react\";\nimport type { ChangeEvent, ComponentPropsWithoutRef, FormEvent, ReactNode } from \"react\";\nimport { cn } from \"../lib/cn\";\nimport { useKitLabels } from \"../i18n/kit-labels\";\nimport { Button, Input, Label, Spinner } from \"./ui\";\nimport type { InputProps } from \"./ui\";\nimport { Checkbox } from \"./checkbox\";\nimport { Tooltip } from \"./tooltip\";\nimport { useCommitReason } from \"./write-lock\";\n\n/**\n * How typed text is compared with the text it has to repeat — shared by\n * `DangerConfirm`'s `phraseMatch` and `useConfirm`'s `typedMatch`.\n *\n * - `\"trim\"` ignores spaces around the typed text — a phone keyboard's autocomplete\n * likes to add one. Case counts: \"delete\" is not \"DELETE\".\n * - `\"exact\"` compares character for character, spaces included.\n * - `\"caseless\"` trims AND ignores case: for an e-mail address, whose domain is\n * case-insensitive and whose local part every real mail server treats so. Both apps'\n * \"type the account's address\" rules (keksdose's `TYPE_EMAIL`, Kurvenschmiede's\n * `TypedConfirm`) compared `trim().toLowerCase()`, and a capital the user's keyboard\n * put at the start must not make the right row look like the wrong one.\n */\nexport type TypedMatch = \"trim\" | \"exact\" | \"caseless\";\n\n/** Whether `typed` repeats `target` under `mode` — see {@link TypedMatch}. Exported for\n * a caller that draws its own field (a dialog that also picks a recipient) and wants\n * the same rule as the kit's. */\nexport function typedMatches(typed: string, target: string, mode: TypedMatch = \"trim\"): boolean {\n if (mode === \"exact\") return typed === target;\n if (mode === \"trim\") return typed.trim() === target;\n // `toLowerCase`, not `toLocaleLowerCase`: the comparison must not change with the\n // reader's locale (a Turkish dotless i would otherwise fail an ASCII address).\n return typed.trim().toLowerCase() === target.trim().toLowerCase();\n}\n\n/**\n * Busy-while-a-promise-runs, for an action that MAY return one: `run(result, onResolved)`\n * marks the caller pending until `result` settles, calls `onResolved` if it fulfilled,\n * and only clears the flag if it rejected — the caller shows why and the user retries.\n * Nothing runs after unmount. Shared by `DangerConfirm` and `ReauthDialog`, whose\n * contract is the same: resolve = done, reject = stay put.\n *\n * @internal\n */\nexport function usePromisePending() {\n const [pending, setPending] = useState(false);\n const mounted = useRef(true);\n useEffect(() => {\n mounted.current = true;\n return () => {\n mounted.current = false;\n };\n }, []);\n const run = useCallback((result: unknown, onResolved: () => void): boolean => {\n if (!result || typeof (result as Promise<unknown>).then !== \"function\") return false;\n setPending(true);\n (result as Promise<unknown>).then(\n () => {\n if (!mounted.current) return;\n setPending(false);\n onResolved();\n },\n () => {\n if (mounted.current) setPending(false);\n },\n );\n return true;\n }, []);\n return { pending, run };\n}\n\n/** A label that is really there — `null`, `false` and `\"\"` are what a caller's\n * `cond && reason` evaluates to on the path where there is none. */\nfunction hasContent(node: ReactNode): boolean {\n return node !== undefined && node !== null && node !== false && node !== \"\";\n}\n\n/** The one word {@link CurrentPasswordInput} says on its own behalf — the\n * `dangerConfirm.password` label, shared with DangerConfirm's password field, so an\n * app translates \"Password\" once. */\nexport type CurrentPasswordInputLabels = Pick<DangerConfirmLabels, \"password\">;\n\n/**\n * Everything {@link Input} takes except what makes this field what it is: `type` is\n * always `\"password\"` and `autoComplete` always `\"current-password\"`.\n */\nexport interface CurrentPasswordInputProps extends Omit<InputProps, \"type\" | \"autoComplete\" | \"label\"> {\n /**\n * The visible label. Default `dangerConfirm.password` (\"Password\") — unless the field\n * is named another way (`aria-label` / `aria-labelledby`), which then stays the only\n * name. Pass the app's own word on a sign-in form (\"Password\", \"Your password\"), or\n * `null` for a field whose `<label htmlFor>` is drawn elsewhere (a form library's\n * `FormLabel`), which would otherwise be labelled twice.\n */\n label?: ReactNode;\n /** The value as a string — the `(next) => …` shape, so a caller holding it in\n * `useState` need not unwrap `event.target.value`. Fires alongside `onChange`,\n * never instead of it, so a form library's `onChange` keeps working. */\n onValueChange?: (value: string) => void;\n /**\n * A check is running (the sign-in request, the re-auth). The field turns `readOnly`,\n * NOT `disabled`: the field being submitted is usually the focused one (Enter was\n * pressed in it), and disabling a focused field drops focus to `<body>` — the user\n * lands nowhere when the \"wrong password\" answer comes back.\n */\n busy?: boolean;\n /** Per-instance override of `dangerConfirm.password`. */\n labels?: Partial<CurrentPasswordInputLabels>;\n}\n\n/**\n * The \"prove it is you\" field: a password input that a password manager fills with\n * the CURRENT password and never offers to generate a new one for.\n *\n * It is the field of a sign-in form, a re-auth step ({@link ReauthDialog} draws the same\n * field), and {@link DangerConfirm}'s `requirePassword`. Public since 0.22 for kastlan's\n * sign-in and re-auth (kastlan 1), which wrote `type=\"password\"` +\n * `autoComplete=\"current-password\"` by hand — and a sign-in field that forgets the\n * second half gets the browser's \"suggest a strong password\" offer on the one form where\n * a NEW password is never what is wanted. The reverse matters as much: a field that sets\n * a NEW password (a passphrase, a sign-up) must NOT be this one — keksdose #170 keeps\n * its passphrase doors on `new-password` / `off` for that reason.\n *\n * Everything else is {@link Input}: the reveal toggle, `error` (under the field,\n * `aria-describedby`, `aria-invalid`), `invalid`, `name`, `id`, `autoFocus`, `required`.\n * The ref is the `<input>`, so it works with `@eifi1/ui-kit/rhf`'s `FormControl` /\n * a `register()` spread, and controlled or uncontrolled.\n *\n * ```tsx\n * <CurrentPasswordInput name=\"password\" label={t(\"password\")} error={errors.password?.message}\n * busy={isSubmitting} {...register(\"password\")} />\n * ```\n */\nexport const CurrentPasswordInput = forwardRef<HTMLInputElement, CurrentPasswordInputProps>(\n function CurrentPasswordInput({ label, onValueChange, onChange, busy, readOnly, labels: labelsProp, ...rest }, ref) {\n const labels = useKitLabels(\"dangerConfirm\", DEFAULT_DANGER_CONFIRM_LABELS, labelsProp);\n const namedOtherwise = rest[\"aria-label\"] !== undefined || rest[\"aria-labelledby\"] !== undefined;\n return (\n <Input\n {...rest}\n ref={ref}\n // After the spread: a props object spread at the field must not turn it into a\n // text field, or into one the password manager offers a new password for.\n type=\"password\"\n autoComplete=\"current-password\"\n label={label === undefined ? (namedOtherwise ? undefined : labels.password) : hasContent(label) ? label : undefined}\n readOnly={Boolean(busy) || readOnly}\n onChange={(e) => {\n onChange?.(e);\n onValueChange?.(e.target.value);\n }}\n />\n );\n },\n);\nCurrentPasswordInput.displayName = \"CurrentPasswordInput\";\n\n/** The words {@link TypedConfirmField} says on its own behalf — the `dangerConfirm`\n * namespace's `phrase` and `phrasePlaceholder`, shared with DangerConfirm's own field,\n * so the sentence \"Type “X” to confirm\" is translated once. */\nexport type TypedConfirmFieldLabels = Pick<DangerConfirmLabels, \"phrase\" | \"phrasePlaceholder\">;\n\nexport interface TypedConfirmFieldProps\n extends Omit<InputProps, \"type\" | \"value\" | \"defaultValue\" | \"label\" | \"placeholder\"> {\n /** The text to repeat — a word (\"DELETE\"), a name, an e-mail address. */\n target: string;\n /** How the typed text is compared with `target` — {@link TypedMatch}. Default\n * `\"trim\"`, as {@link typedMatches}; `\"caseless\"` for an address or an\n * acknowledgement word a user may type in any case. */\n match?: TypedMatch;\n /** Controlled value. Left out, the field keeps its own (start: `defaultValue`). */\n value?: string;\n defaultValue?: string;\n /** The typed text as a string, on every keystroke. Fires alongside `onChange`. */\n onValueChange?: (value: string) => void;\n /**\n * The typed text started or stopped matching `target` — fired from the keystroke\n * that flipped it, so an uncontrolled field can still drive the button it guards. A\n * controlled caller that resets the value itself (on a close) knows the answer\n * already, and gets no call for that; it can also compute it with {@link typedMatches}.\n */\n onMatchedChange?: (matched: boolean) => void;\n /** The label. Default `dangerConfirm.phrase(target)` — \"Type “DELETE” to confirm\". */\n label?: ReactNode;\n /** Text inside the empty field. Default `dangerConfirm.phrasePlaceholder` (unset).\n * Given, the label moves ABOVE the field: a floating label occupies the empty\n * field, which is exactly where a placeholder shows. `\"\"` means none. */\n placeholder?: string;\n /** The guarded action is running: the field turns `readOnly` (not `disabled`, which\n * would drop the focus Enter left in it). */\n busy?: boolean;\n labels?: Partial<TypedConfirmFieldLabels>;\n}\n\n/**\n * The \"type this to confirm\" field — {@link DangerConfirm}'s `phrase` field and\n * `useConfirm({ requireTyped })`'s, on its own (keksdose K7).\n *\n * keksdose writes it by hand four times: the privacy enrol, upgrade and sweep dialogs\n * (type the acknowledgement word, then the key doors appear) and the admin's \"type the\n * user's address\" (`UserActionConfirm`), each an `Input` plus its own\n * `trim().toUpperCase()` / `toLowerCase()` comparison. None of those places is an\n * arm → confirm tile or a modal confirm — what is guarded is a whole form, or the\n * next step of a dialog — so the field had to stand alone. What it brings over a plain\n * `Input`: one match rule ({@link typedMatches}, which lower-cases locale-independently\n * on purpose), the label worded from the target in the app's language, and the\n * attributes a phone keyboard needs to leave the text alone (no autocomplete, no\n * auto-capital, no autocorrect, no spellcheck — a keyboard that \"corrects\" an e-mail\n * address makes the guard unpassable).\n *\n * The field reports whether it matches (`onMatchedChange`, and `data-matched` on the\n * `<input>` for styling); what the match unlocks is the caller's. The ref is the\n * `<input>`.\n *\n * ```tsx\n * const [ok, setOk] = useState(false);\n * <TypedConfirmField target={t(\"privacy.enroll_ack_word\")} match=\"caseless\" onMatchedChange={setOk} />\n * {ok && <KeyDoorsForm … />}\n * ```\n */\nexport const TypedConfirmField = forwardRef<HTMLInputElement, TypedConfirmFieldProps>(function TypedConfirmField(\n {\n target,\n match = \"trim\",\n value: valueProp,\n defaultValue = \"\",\n onValueChange,\n onMatchedChange,\n onChange,\n label: labelProp,\n placeholder: placeholderProp,\n busy,\n readOnly,\n labels: labelsProp,\n id,\n className,\n ...rest\n },\n ref,\n) {\n const labels = useKitLabels(\"dangerConfirm\", DEFAULT_DANGER_CONFIRM_LABELS, labelsProp);\n const [own, setOwn] = useState(defaultValue);\n const value = valueProp ?? own;\n const matched = typedMatches(value, target, match);\n const generated = useId();\n const fieldId = id ?? generated;\n const label =\n labelProp !== undefined\n ? labelProp\n : typeof labels.phrase === \"function\"\n ? labels.phrase(target)\n : labels.phrase;\n const fromLabels =\n labels.phrasePlaceholder === undefined\n ? undefined\n : typeof labels.phrasePlaceholder === \"function\"\n ? labels.phrasePlaceholder(target)\n : labels.phrasePlaceholder;\n const placeholder = placeholderProp ?? fromLabels;\n\n const fieldProps = {\n ...rest,\n ref,\n id: fieldId,\n value,\n autoComplete: \"off\",\n autoCapitalize: \"off\",\n autoCorrect: \"off\",\n spellCheck: false,\n readOnly: Boolean(busy) || readOnly,\n \"data-matched\": matched || undefined,\n onChange: (e: ChangeEvent<HTMLInputElement>) => {\n onChange?.(e);\n const next = e.target.value;\n if (valueProp === undefined) setOwn(next);\n onValueChange?.(next);\n const nextMatched = typedMatches(next, target, match);\n if (nextMatched !== matched) onMatchedChange?.(nextMatched);\n },\n };\n\n if (placeholder) {\n return (\n // A static label above, so the placeholder has the empty field to itself.\n <div className={cn(\"space-y-1.5\", className)}>\n <Label htmlFor={fieldId}>{label}</Label>\n <Input {...fieldProps} placeholder={placeholder} />\n </div>\n );\n }\n return <Input {...fieldProps} label={label} className={className} />;\n});\nTypedConfirmField.displayName = \"TypedConfirmField\";\n\n/**\n * Every string the tile renders — the `dangerConfirm` namespace of\n * `<UiKitProvider labels>`, overridable per instance through `labels`. The arm and\n * confirm buttons are usually worded per action (\"Delete budget\"), which is what the\n * `armLabel` / `confirmLabel` props are for; these are the fallbacks.\n */\nexport interface DangerConfirmLabels {\n /** The button that arms the tile. */\n arm: string;\n /** The button that runs the action once the guards are satisfied. */\n confirm: string;\n cancel: string;\n /** The warning above the fields, when no `prompt` is given. */\n prompt: string;\n /** Label of the password field (`requirePassword`). */\n password: string;\n /** Label of the type-to-confirm field. A FUNCTION of the phrase by default, like\n * every message that carries a value: where the phrase sits in the sentence moves\n * with the language. A plain STRING is taken as the finished label — for an app\n * whose catalogue already words it (\"Type DELETE to confirm\") and would otherwise\n * wrap it as `() => label`. */\n phrase: string | ((phrase: string) => string);\n /** Placeholder of the type-to-confirm field — a string, or a function of the\n * phrase (`(p) => p` echoes it). Optional and unset by default: the field keeps its\n * floating label, as before. Given, the label moves ABOVE the field (a floating\n * label occupies the empty field, which is exactly where a placeholder shows) and\n * the placeholder fills the field. An empty string means none. */\n phrasePlaceholder?: string | ((phrase: string) => string);\n /** 0.22: the checkbox `requireAcknowledge={true}` shows — \"I have read what this does\n * and want to continue\" (keksdose's `admin.users.confirm_ack`). */\n acknowledge: string;\n /**\n * 0.23: why the armed confirm is held while the typed phrase does not match yet — in\n * the confirm's tooltip and its description (keksdose G4a). A FUNCTION of the phrase\n * by default (\"Type “DELETE” to confirm\"), or a finished STRING, as `phrase`.\n */\n needsPhrase: string | ((phrase: string) => string);\n /** 0.23: why the armed confirm is held while the `requireAcknowledge` box is unticked\n * — \"Tick the box to confirm\". */\n needsAcknowledge: string;\n /** 0.23: why the armed confirm is held while the `requirePassword` field is empty —\n * \"Enter your password to confirm\". */\n needsPassword: string;\n}\n\n/** `satisfies` rather than a type annotation, so `DEFAULT_DANGER_CONFIRM_LABELS.phrase`\n * stays callable for a caller that composes its own label from it. */\nexport const DEFAULT_DANGER_CONFIRM_LABELS = {\n arm: \"Delete…\",\n confirm: \"Delete\",\n cancel: \"Cancel\",\n prompt: \"This cannot be undone.\",\n password: \"Password\",\n phrase: (phrase: string) => `Type “${phrase}” to confirm`,\n acknowledge: \"I have read what this does and want to continue.\",\n needsPhrase: (phrase: string) => `Type “${phrase}” to confirm`,\n needsAcknowledge: \"Tick the box to confirm\",\n needsPassword: \"Enter your password to confirm\",\n} satisfies DangerConfirmLabels;\n\n/**\n * What the guards were answered with — the second argument of\n * {@link DangerConfirmProps.onConfirm} (0.23, keksdose G4b). A key is there only when its\n * guard was asked for, so the object can go into a request body as it is.\n */\nexport interface DangerConfirmValues {\n /**\n * The text typed into the `phrase` field — as the match rule compared it: trimmed\n * under `phraseMatch` `\"trim\"` and `\"caseless\"` (the spaces a phone keyboard adds are\n * not part of it), exactly as typed under `\"exact\"`. The case is the user's, even\n * under `\"caseless\"`: a server that re-checks applies its own rule to it. Absent\n * without a `phrase`.\n */\n typed?: string;\n /** The entered password — the same value as the first argument. Absent without\n * `requirePassword`. */\n password?: string;\n /** `true` when the `requireAcknowledge` box was shown — it was ticked, since the\n * confirm is held until it is. Absent without one. */\n acknowledged?: true;\n}\n\n/**\n * One line of {@link DangerConfirmProps.consequences}: what the action will do. A plain\n * string, or this, for a key of its own and the `severe` mark.\n */\nexport interface DangerConsequence {\n /** React key — keksdose keys its lines by what they say (\"api_tokens\", \"only_door\").\n * Default: the text when it is a string, else the position. */\n key?: string;\n text: ReactNode;\n /** \"There is no way back\" — painted in the danger colour rather than the list's\n * muted one. keksdose reserves it for the one line that loses something for good. */\n severe?: boolean;\n}\n\nexport interface DangerConfirmProps extends Omit<ComponentPropsWithoutRef<\"div\">, \"onChange\"> {\n /**\n * Runs the action, with the entered password when `requirePassword` is on.\n *\n * Return a promise and the tile manages itself: busy until it settles, disarmed\n * (fields wiped) when it resolves, still armed when it rejects — so the user can\n * correct a wrong password and retry. The rejection is not swallowed for you to\n * miss: handle it (and show why) in the caller, as with any mutation.\n *\n * 0.23: the second argument is what every guard was answered with — the typed phrase,\n * the password, the tick ({@link DangerConfirmValues}). keksdose G4b: its admin\n * actions send the address the admin TYPED, and the server re-checks it against the\n * account (`assert_confirmed`), so a client that put the wrong row's id in the request\n * is refused rather than obeyed; the tile kept the text to itself.\n *\n * onConfirm={(_password, { typed }) =>\n * reset.mutateAsync({ id, confirm: { acknowledged: true, confirm_email: typed ?? null } })}\n *\n * A second argument rather than one object in place of the password: every\n * `(password) => …` and `() => …` handler, and a `mutation.mutate` passed as it is,\n * keeps working unchanged, and a handler that needs one guard's answer names it.\n */\n onConfirm: (password: string | undefined, values: DangerConfirmValues) => void | Promise<unknown>;\n /** Show a password field; confirm is held until it is filled. */\n requirePassword?: boolean;\n /**\n * Show an \"I understand\" checkbox; confirm is held until it is ticked\n * (keksdose K7). `true` words it with `labels.acknowledge`; any other node IS the\n * checkbox's label (\"I understand Anna will be signed out everywhere\").\n *\n * The guard for an action whose risk is MIS-TARGETING less than carelessness:\n * keksdose's admin password reset asks for a typed address when the account has an\n * encrypted door to lose, and a tick otherwise (`UserActionConfirm`), and its plan\n * editor asks for the tick alone (`UserPlanEditor`). Both were hand-built beside this\n * tile because it had no tick. It combines with `phrase` and `requirePassword`: every\n * guard given must be satisfied.\n */\n requireAcknowledge?: ReactNode;\n /**\n * What the action will do, said before it happens — a list under the prompt, shown\n * once armed (keksdose K7, `UserActionConfirm`'s consequences). Strings, or\n * {@link DangerConsequence}s for a `severe` line in the danger colour.\n *\n * Derive them from the row's own facts rather than reciting the worst case: an admin\n * who reads the same paragraph on every row stops reading it (keksdose dev#488).\n */\n consequences?: readonly (string | DangerConsequence)[];\n /** Show a \"type <phrase> to confirm\" field; confirm is held until the field matches\n * (case-sensitive; surrounding spaces ignored unless `phraseMatch=\"exact\"`). */\n phrase?: string;\n /**\n * How the typed text is compared with `phrase`. `\"trim\"` (default) ignores spaces\n * around it — a phone keyboard's autocomplete likes to add one. `\"exact\"` compares\n * character for character, spaces included, for an app whose contract is \"type\n * exactly this\". `\"caseless\"` (0.18) also ignores case — for a phrase that is an\n * e-mail address (keksdose's \"type the user's address\" admin rule). See\n * {@link TypedMatch}.\n */\n phraseMatch?: TypedMatch;\n /** The warning above the fields. Defaults to `labels.prompt`. */\n prompt?: ReactNode;\n /** `\"danger\"` (default) for what cannot be undone; `\"warning\"` for what can, at a\n * cost (loading demo data over your own). Colours the prompt and the confirm. */\n tone?: \"danger\" | \"warning\";\n /** Visible text of the arm button; defaults to `labels.arm`. */\n armLabel?: ReactNode;\n /** Visible text of the confirm button; defaults to `labels.confirm`. */\n confirmLabel?: ReactNode;\n /** The action is running: confirm shows a spinner and nothing can be pressed. For a\n * caller that tracks the mutation itself (a `useMutation`'s `isPending`); a\n * promise returned from `onConfirm` does the same on its own. */\n busy?: boolean;\n /** The arm button is disabled. */\n disabled?: boolean;\n /**\n * Why the action is not available — a read-only demo, a write lock, a missing\n * permission. Disables the arm button like `disabled`, and SAYS so: the sentence is\n * shown under the button and attached to it with `aria-describedby`, and the button\n * stays focusable (`aria-disabled`) so a keyboard user can land on it and hear why.\n *\n * On the ARM button rather than the confirm: arming asks for a password, and asking\n * for a password for a write that can never land is the worse of the two. A tile that\n * is ALREADY armed when the reason arrives (controlled `armed`, or a lock that landed\n * while it was open) keeps its fields but its confirm takes the reason the same way\n * — focusable, `aria-disabled`, the reason in its tooltip — and Enter does nothing.\n */\n lockedReason?: ReactNode;\n /**\n * This tile COMMITS — the 0.18 write-lock opt-in that {@link Button} has (keksdose\n * K3). Under a locked {@link WriteLockProvider} the lock's reason becomes\n * `lockedReason` (and wins over one of the tile's own), so a page that mounts the\n * provider no longer threads `lockedReason={lock.locked ? lock.reason : undefined}`\n * into every tile. No provider, or an unlocked one: no effect.\n */\n commit?: boolean;\n /** Controlled armed state. The parent can then collapse the tile from a mutation's\n * own `onSuccess` without returning a promise. */\n armed?: boolean;\n /** Called with the next armed state — on arm, cancel, and a resolved `onConfirm`. */\n onArmedChange?: (armed: boolean) => void;\n /** User-facing strings; see {@link DangerConfirmLabels}. */\n labels?: Partial<DangerConfirmLabels>;\n}\n\n/**\n * An \"arm → confirm\" tile for destructive actions: one button, which expands into a\n * warning, an optional list of consequences, an optional \"I understand\" tick, an\n * optional type-to-confirm field, an optional password field and a confirm that is held\n * until every guard is satisfied.\n *\n * A held confirm SAYS which guard is still open (0.23, keksdose G4a): it is\n * `aria-disabled` rather than `disabled` — still focusable, so a keyboard user can land\n * on it — with the reason in the kit {@link Tooltip} and its description (\"Type\n * “DELETE” to confirm\", \"Tick the box to confirm\", \"Enter your password to confirm\";\n * `labels.needs*`), the first open guard in the order they are drawn. FormActions'\n * `submitDisabledReason` does the same for a form's Save. Pressing it, or Enter in a\n * field, does nothing. A lock's reason wins over a guard's; while the action runs the\n * confirm is plainly disabled, its spinner saying why.\n *\n * Keksdose hand-rolled it three times (load demo data, wipe everything, reset a\n * budget) and then as `shared/components/danger-confirm.tsx`; the only app-specific\n * part was its write-lock hook, which is `lockedReason` here.\n *\n * The fields are a `<form>`, so Enter confirms once the guards allow it. They are\n * wiped every time the tile disarms — a password must not sit in a collapsed tile.\n * Arming moves focus to the first field (or Cancel, when there is none — never to the\n * destructive button itself), and disarming moves it back to the arm button, so the\n * keyboard user is never left on an element that just vanished.\n */\nexport function DangerConfirm({\n onConfirm,\n requirePassword,\n requireAcknowledge,\n consequences,\n phrase,\n phraseMatch = \"trim\",\n prompt,\n tone = \"danger\",\n armLabel,\n confirmLabel,\n busy: busyProp,\n disabled,\n lockedReason: ownLockedReason,\n commit,\n armed: armedProp,\n onArmedChange,\n labels: labelsProp,\n className,\n ...rest\n}: DangerConfirmProps) {\n const labels = useKitLabels(\"dangerConfirm\", DEFAULT_DANGER_CONFIRM_LABELS, labelsProp);\n const lockedReason = useCommitReason(commit, ownLockedReason);\n const [armedState, setArmedState] = useState(false);\n const armed = armedProp ?? armedState;\n const [password, setPassword] = useState(\"\");\n const [typed, setTyped] = useState(\"\");\n const [acknowledged, setAcknowledged] = useState(false);\n const { pending, run } = usePromisePending();\n const busy = Boolean(busyProp) || pending;\n // `readOnly` rather than `disabled` on the fields while busy: disabling the field\n // that has focus (Enter was pressed in it) drops focus to <body>.\n const promptId = useId();\n const consequencesId = useId();\n const reasonId = useId();\n\n // The kit's Button takes no ref, so the two buttons focus is moved to are found by id.\n const armId = useId();\n const cancelId = useId();\n const firstFieldRef = useRef<HTMLInputElement>(null);\n // Focus moves only after a transition — never on mount, so a tile that renders armed\n // (controlled) does not take the page's focus merely by existing.\n const moveFocus = useRef(false);\n\n // A disarm from anywhere (cancel, a resolved confirm, the parent) wipes the fields.\n // During render, like NumberField's draft, so no frame shows a collapsed tile that\n // still holds a password.\n const [wasArmed, setWasArmed] = useState(armed);\n if (wasArmed !== armed) {\n setWasArmed(armed);\n if (!armed) {\n setPassword(\"\");\n setTyped(\"\");\n setAcknowledged(false);\n }\n }\n\n const prevArmed = useRef(armed);\n useEffect(() => {\n const changed = prevArmed.current !== armed;\n prevArmed.current = armed;\n const byUser = moveFocus.current;\n moveFocus.current = false;\n if (!changed) return;\n if (armed) {\n if (byUser) (firstFieldRef.current ?? document.getElementById(cancelId))?.focus();\n return;\n }\n // A controlled parent collapsing the tile from its own `onSuccess` did not go\n // through `setArmed`; if focus went down with the form, bring it back too.\n const lost = document.activeElement === null || document.activeElement === document.body;\n if (byUser || lost) document.getElementById(armId)?.focus();\n }, [armed, armId, cancelId]);\n\n const setArmed = (next: boolean) => {\n moveFocus.current = true;\n if (armedProp === undefined) setArmedState(next);\n onArmedChange?.(next);\n };\n\n const locked = hasContent(lockedReason);\n // `true` words the tick with the namespace; any other node is its label; `false`,\n // `null` and `\"\"` are no tick at all.\n const acknowledgeLabel: ReactNode =\n requireAcknowledge === true ? labels.acknowledge : hasContent(requireAcknowledge) ? requireAcknowledge : null;\n const asksAcknowledge = acknowledgeLabel !== null;\n const passwordOk = !requirePassword || password !== \"\";\n const phraseOk = phrase === undefined || typedMatches(typed, phrase, phraseMatch);\n const acknowledgeOk = !asksAcknowledge || acknowledged;\n const canConfirm = passwordOk && phraseOk && acknowledgeOk && !busy;\n // The first guard still open, in the order the fields are drawn — the one the user\n // meets next, so the sentence points at it.\n const guardReason: string | undefined = !acknowledgeOk\n ? labels.needsAcknowledge\n : !phraseOk\n ? typeof labels.needsPhrase === \"function\"\n ? labels.needsPhrase(phrase ?? \"\")\n : labels.needsPhrase\n : !passwordOk\n ? labels.needsPassword\n : undefined;\n // The lock first (no guard can lift it); none while busy, when the guards were met and\n // the spinner is the state.\n const confirmReason: ReactNode = locked ? lockedReason : busy ? undefined : guardReason;\n\n const submit = (e: FormEvent) => {\n e.preventDefault();\n // `locked` too: Enter in a field submits the form without the button's say.\n if (!canConfirm || locked) return;\n const values: DangerConfirmValues = {\n ...(phrase !== undefined && { typed: phraseMatch === \"exact\" ? typed : typed.trim() }),\n ...(requirePassword && { password }),\n ...(asksAcknowledge && { acknowledged: true as const }),\n };\n // Disarms when it resolves; a rejection leaves it armed, fields kept: the caller\n // shows why, the user retries.\n run(onConfirm(values.password, values), () => setArmed(false));\n };\n\n // The first field takes focus on arm: the tick, then the phrase, then the password —\n // the order they are drawn in.\n const firstField = asksAcknowledge ? \"acknowledge\" : phrase !== undefined ? \"phrase\" : \"password\";\n const lines = (consequences ?? []).map((item, index) =>\n typeof item === \"string\"\n ? { key: item, text: item as ReactNode, severe: false }\n : { key: item.key ?? String(index), text: item.text, severe: Boolean(item.severe) },\n );\n\n const toneText = tone === \"warning\" ? \"text-[var(--warning)]\" : \"text-[var(--danger)]\";\n\n if (!armed) {\n const arm = (\n <Button\n id={armId}\n type=\"button\"\n variant={tone === \"warning\" ? \"secondary\" : \"danger\"}\n disabled={disabled}\n aria-disabled={locked || undefined}\n aria-describedby={locked ? reasonId : undefined}\n onClick={() => {\n if (!locked) setArmed(true);\n }}\n className=\"aria-disabled:cursor-not-allowed aria-disabled:opacity-50\"\n >\n {armLabel ?? labels.arm}\n </Button>\n );\n return (\n <div {...rest} className={cn(\"space-y-1\", className)}>\n {locked ? (\n // The reason on the button itself too, where the pointer that tried it is —\n // the line below can sit out of view in a long settings card. Portalled, so\n // a card that scrolls neither clips it nor grows by it.\n //\n // The button in a FRAGMENT on purpose: Tooltip clones an element child to\n // add the bubble to its `aria-describedby`, and the button is already\n // described by the visible line below — the same sentence twice, read out\n // on every focus. A fragment is left as it is, so the bubble stays visual.\n <Tooltip label={lockedReason} portal>\n <>{arm}</>\n </Tooltip>\n ) : (\n arm\n )}\n {locked && (\n <p id={reasonId} className=\"text-xs text-[var(--text-muted)]\">\n {lockedReason}\n </p>\n )}\n </div>\n );\n }\n\n return (\n <div {...rest} className={cn(\"space-y-2\", className)}>\n <form\n className=\"space-y-2\"\n aria-describedby={lines.length > 0 ? `${promptId} ${consequencesId}` : promptId}\n aria-busy={busy || undefined}\n onSubmit={submit}\n noValidate\n >\n <p id={promptId} className={cn(\"text-xs font-medium\", toneText)}>\n {prompt ?? labels.prompt}\n </p>\n {lines.length > 0 && (\n <ul id={consequencesId} className=\"list-disc space-y-1 ps-5 text-xs text-[var(--text-secondary)]\">\n {lines.map((line) => (\n <li key={line.key} className={line.severe ? \"text-[var(--danger)]\" : undefined}>\n {line.text}\n </li>\n ))}\n </ul>\n )}\n {asksAcknowledge && (\n <Checkbox\n ref={firstField === \"acknowledge\" ? firstFieldRef : undefined}\n label={acknowledgeLabel}\n checked={acknowledged}\n // Not `disabled` while busy, for the same reason the fields are readOnly:\n // the box may hold the focus. A change while busy is simply not taken.\n onCheckedChange={(next) => {\n if (!busy) setAcknowledged(next);\n }}\n />\n )}\n {phrase !== undefined && (\n <TypedConfirmField\n ref={firstField === \"phrase\" ? firstFieldRef : undefined}\n target={phrase}\n match={phraseMatch}\n value={typed}\n onValueChange={setTyped}\n busy={busy}\n // Already resolved through this tile's own `labels` prop; handed on so a\n // per-instance phrase wording reaches the field.\n labels={{ phrase: labels.phrase, phrasePlaceholder: labels.phrasePlaceholder }}\n />\n )}\n {requirePassword && (\n <CurrentPasswordInput\n ref={firstField === \"password\" ? firstFieldRef : undefined}\n label={labels.password}\n value={password}\n busy={busy}\n onValueChange={setPassword}\n />\n )}\n <div className=\"flex flex-wrap gap-2\">\n <Button id={cancelId} type=\"button\" variant=\"ghost\" disabled={busy} onClick={() => setArmed(false)}>\n {labels.cancel}\n </Button>\n <Button\n type=\"submit\"\n variant={tone === \"warning\" ? \"primary\" : \"danger\"}\n disabled={!canConfirm}\n // Held by a guard, or armed and then locked (or rendered armed under a lock):\n // the confirm says why the way Button does — focusable, `aria-disabled`, the\n // reason in its tooltip and description, a press swallowed (the submit with\n // it) — and the fields stay as typed. Only busy is the native `disabled`.\n disabledReason={confirmReason}\n aria-busy={busy || undefined}\n >\n {busy && <Spinner label={null} className=\"h-4 w-4\" />}\n {confirmLabel ?? labels.confirm}\n </Button>\n </div>\n {locked && <p className=\"text-xs text-[var(--text-muted)]\">{lockedReason}</p>}\n </form>\n </div>\n );\n}\n"],"mappings":";AA2IM,SA4hBM,UA5hBN,KAkJA,YAlJA;AA3IN,SAAS,YAAY,aAAa,WAAW,OAAO,QAAQ,gBAAgB;AAE5E,SAAS,UAAU;AACnB,SAAS,oBAAoB;AAC7B,SAAS,QAAQ,OAAO,OAAO,eAAe;AAE9C,SAAS,gBAAgB;AACzB,SAAS,eAAe;AACxB,SAAS,uBAAuB;AAoBzB,SAAS,aAAa,OAAe,QAAgB,OAAmB,QAAiB;AAC9F,MAAI,SAAS,QAAS,QAAO,UAAU;AACvC,MAAI,SAAS,OAAQ,QAAO,MAAM,KAAK,MAAM;AAG7C,SAAO,MAAM,KAAK,EAAE,YAAY,MAAM,OAAO,KAAK,EAAE,YAAY;AAClE;AAWO,SAAS,oBAAoB;AAClC,QAAM,CAAC,SAAS,UAAU,IAAI,SAAS,KAAK;AAC5C,QAAM,UAAU,OAAO,IAAI;AAC3B,YAAU,MAAM;AACd,YAAQ,UAAU;AAClB,WAAO,MAAM;AACX,cAAQ,UAAU;AAAA,IACpB;AAAA,EACF,GAAG,CAAC,CAAC;AACL,QAAM,MAAM,YAAY,CAAC,QAAiB,eAAoC;AAC5E,QAAI,CAAC,UAAU,OAAQ,OAA4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AA,YAAC;AAAA;AAAA,cACC,MAAK;AAAA,cACL,SAAS,SAAS,YAAY,YAAY;AAAA,cAC1C,UAAU,CAAC;AAAA,cAKX,gBAAgB;AAAA,cAChB,aAAW,QAAQ;AAAA,cAElB;AAAA,wBAAQ,oBAAC,WAAQ,OAAO,MAAM,WAAU,WAAU;AAAA,gBAClD,gBAAgB,OAAO;AAAA;AAAA;AAAA,UAC1B;AAAA,WACF;AAAA,QACC,UAAU,oBAAC,OAAE,WAAU,oCAAoC,wBAAa;AAAA;AAAA;AAAA,EAC3E,GACF;AAEJ;","names":["CurrentPasswordInput","TypedConfirmField"]}
|
|
@@ -62,6 +62,47 @@ interface DatePickerBaseProps extends Omit<ComponentPropsWithoutRef<"div">, "onC
|
|
|
62
62
|
* ships English defaults, which a translating host has to be able to replace.
|
|
63
63
|
* Usually unnecessary now: the calendar reads `miniCalendar` from the provider. */
|
|
64
64
|
calendarLabels?: MiniCalendarProps["labels"];
|
|
65
|
+
/**
|
|
66
|
+
* Make the panel's caption ("July 2026") a button that opens the year's twelve
|
|
67
|
+
* months, with ‹ › stepping a year; picking a month returns to its days. Far dates
|
|
68
|
+
* stop being a march of month arrows.
|
|
69
|
+
*
|
|
70
|
+
* kastlan is why: its service-charge period runs July to June, and with one month on
|
|
71
|
+
* screen and ‹ › the only way across, the end of the period was eleven clicks past
|
|
72
|
+
* the start — so kastlan kept two date fields instead of `RhfDateRangePicker`. With
|
|
73
|
+
* the jump the whole period is open, caption, Jul, 1, caption, next year, Jun, 30.
|
|
74
|
+
*
|
|
75
|
+
* What it adds, for the keyboard and a screen reader:
|
|
76
|
+
* - the caption is a disclosure button (`aria-expanded`). Its name is the month it
|
|
77
|
+
* shows, so speech input can say what it sees; it is `aria-live`, as the
|
|
78
|
+
* calendar's caption was, so paging months still says where you landed; and it is
|
|
79
|
+
* described by `monthPicker.panel` ("Choose a month").
|
|
80
|
+
* - the month grid is `MonthPicker`'s grid: one tab stop, arrows walk the months
|
|
81
|
+
* (across the year's edge), Home/End the row, PageUp/PageDown a year, Enter or a
|
|
82
|
+
* click picks. Focus opens on the month on show and comes back on its days — the
|
|
83
|
+
* selected day if it is in that month, else the 1st. Months outside `min`/`max`
|
|
84
|
+
* are `aria-disabled`, and a year arrow is once the whole year beyond is.
|
|
85
|
+
* - Escape in the month grid goes back to the days without closing the panel (focus
|
|
86
|
+
* on the caption); in the days, Escape closes the panel as before.
|
|
87
|
+
*
|
|
88
|
+
* No new strings: the month arrows keep `miniCalendar.previousMonth` / `nextMonth`
|
|
89
|
+
* (`calendarLabels`), and the month grid speaks with `MonthPicker`'s words —
|
|
90
|
+
* `monthPicker.previousYear` / `nextYear` / `month` / `panel` — because it is that
|
|
91
|
+
* grid, and a host that translated it once should not have to again.
|
|
92
|
+
*
|
|
93
|
+
* Off by default: the caption becomes one more stop in the panel's tab order, which a
|
|
94
|
+
* 0.x minor does not spring on a form. Works in the popover and in
|
|
95
|
+
* `DateRangePicker`'s phone sheet alike, beside presets and in `commit="apply"`
|
|
96
|
+
* (a preset picked while the months are open goes back to the days, on its start).
|
|
97
|
+
*
|
|
98
|
+
* Why not a two-month panel (`months={2}`) instead, or beside it: for a twelve-month
|
|
99
|
+
* period it still pages six times where this takes one year step, and two
|
|
100
|
+
* `MiniCalendar`s side by side each follow the value on their own — picking the end
|
|
101
|
+
* in the right-hand month would pull the left one onto it — so the calendar would
|
|
102
|
+
* have to learn to share a month first. Not worth that for a saving of one arrow on a
|
|
103
|
+
* range across a single month boundary.
|
|
104
|
+
*/
|
|
105
|
+
monthJump?: boolean;
|
|
65
106
|
}
|
|
66
107
|
/**
|
|
67
108
|
* Everything the kit's own trigger button carries, handed to a custom one
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { useEffect, useId, useMemo, useRef, useState } from "react";
|
|
4
|
-
import { Calendar, CalendarClock, ChevronLeft, ChevronRight, X } from "lucide-react";
|
|
4
|
+
import { Calendar, CalendarClock, ChevronDown, ChevronLeft, ChevronRight, X } from "lucide-react";
|
|
5
5
|
import { cn } from "../lib/cn.js";
|
|
6
|
-
import { dirOf } from "../lib/direction.js";
|
|
7
|
-
import { addDaysIso, parseIsoDate } from "../lib/dates.js";
|
|
6
|
+
import { dirOf, horizontalStep } from "../lib/direction.js";
|
|
7
|
+
import { addDaysIso, monthKey, pad, parseIsoDate } from "../lib/dates.js";
|
|
8
8
|
import {
|
|
9
9
|
DEFAULT_DATE_PICKER_LABELS,
|
|
10
10
|
DEFAULT_PICKER_SHEET_LABELS,
|
|
@@ -14,10 +14,11 @@ import {
|
|
|
14
14
|
} from "../i18n/kit-labels.js";
|
|
15
15
|
import { splitTriggerAria } from "./trigger-aria.js";
|
|
16
16
|
import { Button, FIELD_BASE, FIELD_TRIGGER, FIELD_FLOATING_PAD, FIELD_INVALID, PHONE_QUERY } from "./ui.js";
|
|
17
|
-
import { FieldBox, FieldLabelLine, useFieldMessages } from "./field-
|
|
17
|
+
import { FieldBox, FieldLabelLine, useFieldMessages } from "./field-parts.js";
|
|
18
18
|
import { FullBleedDialog } from "./full-bleed-dialog.js";
|
|
19
19
|
import { useMediaQuery } from "../hooks/use-media-query.js";
|
|
20
|
-
import { MiniCalendar } from "./mini-calendar.js";
|
|
20
|
+
import { DEFAULT_MINI_CALENDAR_LABELS, MiniCalendar } from "./mini-calendar.js";
|
|
21
|
+
import { DEFAULT_MONTH_PICKER_LABELS } from "./month-picker.js";
|
|
21
22
|
import { Popover } from "./popover.js";
|
|
22
23
|
import { Tooltip } from "./tooltip.js";
|
|
23
24
|
function formatDate(iso, locale, options) {
|
|
@@ -270,6 +271,263 @@ function StepButton({
|
|
|
270
271
|
}
|
|
271
272
|
) });
|
|
272
273
|
}
|
|
274
|
+
const monthIndex = (key) => Number(key.slice(0, 4)) * 12 + Number(key.slice(5, 7)) - 1;
|
|
275
|
+
const keyOfIndex = (index) => `${String(Math.floor(index / 12)).padStart(4, "0")}-${pad(index % 12 + 1)}`;
|
|
276
|
+
const shiftKey = (key, delta) => keyOfIndex(monthIndex(key) + delta);
|
|
277
|
+
const firstOfKey = (key) => new Date(Number(key.slice(0, 4)), Number(key.slice(5, 7)) - 1, 1);
|
|
278
|
+
const upperFirst = (text, locale) => text.charAt(0).toLocaleUpperCase(locale) + text.slice(1);
|
|
279
|
+
const MONTH_COLUMNS = 3;
|
|
280
|
+
function openingMonth(from, to, lo, hi) {
|
|
281
|
+
const start = parseIsoDate(from) ?? parseIsoDate(to) ?? /* @__PURE__ */ new Date();
|
|
282
|
+
if (lo && start < lo) return monthKey(lo);
|
|
283
|
+
if (hi && start > hi) return monthKey(hi);
|
|
284
|
+
return monthKey(start);
|
|
285
|
+
}
|
|
286
|
+
function PanelCalendar({ monthJump, ...calendar }) {
|
|
287
|
+
return monthJump ? /* @__PURE__ */ jsx(JumpCalendar, { ...calendar }) : /* @__PURE__ */ jsx(MiniCalendar, { ...calendar });
|
|
288
|
+
}
|
|
289
|
+
function JumpCalendar({
|
|
290
|
+
from = "",
|
|
291
|
+
to = "",
|
|
292
|
+
mode = "range",
|
|
293
|
+
locale,
|
|
294
|
+
min,
|
|
295
|
+
max,
|
|
296
|
+
labels,
|
|
297
|
+
onSelect,
|
|
298
|
+
focusOnOpen
|
|
299
|
+
}) {
|
|
300
|
+
const calendarText = useKitLabels("miniCalendar", DEFAULT_MINI_CALENDAR_LABELS, labels);
|
|
301
|
+
const monthText = useKitLabels("monthPicker", DEFAULT_MONTH_PICKER_LABELS);
|
|
302
|
+
const id = useId();
|
|
303
|
+
const captionId = `${id}-caption`;
|
|
304
|
+
const hintId = `${id}-hint`;
|
|
305
|
+
const captionRef = useRef(null);
|
|
306
|
+
const monthsRef = useRef(null);
|
|
307
|
+
const lo = min ? parseIsoDate(min) : null;
|
|
308
|
+
const hi = max ? parseIsoDate(max) : null;
|
|
309
|
+
const minKey = lo ? monthKey(lo) : null;
|
|
310
|
+
const maxKey = hi ? monthKey(hi) : null;
|
|
311
|
+
const outOfBounds = (key) => Boolean(minKey && key < minKey || maxKey && key > maxKey);
|
|
312
|
+
const clampKey = (key) => minKey && key < minKey ? minKey : maxKey && key > maxKey ? maxKey : key;
|
|
313
|
+
const [view, setView] = useState("days");
|
|
314
|
+
const [shown, setShown] = useState(() => openingMonth(from, to, lo, hi));
|
|
315
|
+
const [dayGrid, setDayGrid] = useState(() => ({ key: 0, focus: Boolean(focusOnOpen) }));
|
|
316
|
+
const [active, setActive] = useState(shown);
|
|
317
|
+
const [lastValue, setLastValue] = useState({ from, to });
|
|
318
|
+
if (lastValue.from !== from || lastValue.to !== to) {
|
|
319
|
+
const changed = lastValue.from !== from ? from : to;
|
|
320
|
+
setLastValue({ from, to });
|
|
321
|
+
const next = parseIsoDate(changed) ?? parseIsoDate(from) ?? parseIsoDate(to);
|
|
322
|
+
const key = next ? monthKey(next) : null;
|
|
323
|
+
if (key && (key !== shown || view === "months")) {
|
|
324
|
+
setShown(key);
|
|
325
|
+
setView("days");
|
|
326
|
+
setDayGrid((d) => ({ key: d.key + 1, month: key, focus: false }));
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
const pendingFocus = useRef(null);
|
|
330
|
+
useEffect(() => {
|
|
331
|
+
const key = pendingFocus.current;
|
|
332
|
+
if (!key) return;
|
|
333
|
+
pendingFocus.current = null;
|
|
334
|
+
monthsRef.current?.querySelector(`[data-month="${key}"]`)?.focus();
|
|
335
|
+
});
|
|
336
|
+
const showMonth = (key) => {
|
|
337
|
+
setShown(key);
|
|
338
|
+
setDayGrid((d) => ({ ...d, month: key }));
|
|
339
|
+
};
|
|
340
|
+
const openMonths = () => {
|
|
341
|
+
const start = clampKey(shown);
|
|
342
|
+
pendingFocus.current = start;
|
|
343
|
+
setActive(start);
|
|
344
|
+
setView("months");
|
|
345
|
+
};
|
|
346
|
+
const closeMonths = (focusCaption) => {
|
|
347
|
+
setView("days");
|
|
348
|
+
setDayGrid((d) => ({ ...d, month: shown, focus: false }));
|
|
349
|
+
if (focusCaption) captionRef.current?.focus();
|
|
350
|
+
};
|
|
351
|
+
const pick = (key) => {
|
|
352
|
+
setShown(key);
|
|
353
|
+
setView("days");
|
|
354
|
+
setDayGrid((d) => ({ key: d.key + 1, month: key, focus: true }));
|
|
355
|
+
};
|
|
356
|
+
const moveActive = (key, focus) => {
|
|
357
|
+
if (focus) pendingFocus.current = key;
|
|
358
|
+
setActive(key);
|
|
359
|
+
};
|
|
360
|
+
const inDays = view === "days";
|
|
361
|
+
const escapeToDays = (e) => {
|
|
362
|
+
if (e.key !== "Escape" || inDays) return;
|
|
363
|
+
e.preventDefault();
|
|
364
|
+
e.stopPropagation();
|
|
365
|
+
closeMonths(true);
|
|
366
|
+
};
|
|
367
|
+
const onMonthKeyDown = (e) => {
|
|
368
|
+
if (e.key === "Escape") return escapeToDays(e);
|
|
369
|
+
const step = horizontalStep(e.key, e.currentTarget);
|
|
370
|
+
const col = monthIndex(active) % 12 % MONTH_COLUMNS;
|
|
371
|
+
let delta;
|
|
372
|
+
switch (step ? "horizontal" : e.key) {
|
|
373
|
+
case "horizontal":
|
|
374
|
+
delta = step;
|
|
375
|
+
break;
|
|
376
|
+
case "ArrowUp":
|
|
377
|
+
delta = -MONTH_COLUMNS;
|
|
378
|
+
break;
|
|
379
|
+
case "ArrowDown":
|
|
380
|
+
delta = MONTH_COLUMNS;
|
|
381
|
+
break;
|
|
382
|
+
case "Home":
|
|
383
|
+
delta = -col;
|
|
384
|
+
break;
|
|
385
|
+
case "End":
|
|
386
|
+
delta = MONTH_COLUMNS - 1 - col;
|
|
387
|
+
break;
|
|
388
|
+
case "PageUp":
|
|
389
|
+
delta = -12;
|
|
390
|
+
break;
|
|
391
|
+
case "PageDown":
|
|
392
|
+
delta = 12;
|
|
393
|
+
break;
|
|
394
|
+
default:
|
|
395
|
+
return;
|
|
396
|
+
}
|
|
397
|
+
e.preventDefault();
|
|
398
|
+
if (delta !== 0) moveActive(shiftKey(active, delta), true);
|
|
399
|
+
};
|
|
400
|
+
const year = Number(active.slice(0, 4));
|
|
401
|
+
const prevYearBlocked = Boolean(minKey && year - 1 < Number(minKey.slice(0, 4)));
|
|
402
|
+
const nextYearBlocked = Boolean(maxKey && year + 1 > Number(maxKey.slice(0, 4)));
|
|
403
|
+
const prevBlocked = !inDays && prevYearBlocked;
|
|
404
|
+
const nextBlocked = !inDays && nextYearBlocked;
|
|
405
|
+
const longName = useMemo(() => new Intl.DateTimeFormat(locale, { month: "long", year: "numeric" }), [locale]);
|
|
406
|
+
const shortNames = useMemo(() => {
|
|
407
|
+
const fmt = new Intl.DateTimeFormat(locale, { month: "short" });
|
|
408
|
+
return Array.from({ length: 12 }, (_, i) => upperFirst(fmt.format(new Date(2e3, i, 1)), locale));
|
|
409
|
+
}, [locale]);
|
|
410
|
+
const caption = inDays ? upperFirst(longName.format(firstOfKey(shown)), locale) : new Intl.DateTimeFormat(locale, { year: "numeric" }).format(new Date(year, 0, 1));
|
|
411
|
+
const fromDate = parseIsoDate(from);
|
|
412
|
+
const toDate = parseIsoDate(to);
|
|
413
|
+
const fromKey = fromDate ? monthKey(fromDate) : null;
|
|
414
|
+
const toKey = toDate ? monthKey(toDate) : null;
|
|
415
|
+
const low = fromKey ?? toKey;
|
|
416
|
+
const high = toKey ?? fromKey;
|
|
417
|
+
const currentKey = monthKey(/* @__PURE__ */ new Date());
|
|
418
|
+
const arrow = "rounded p-1 text-[var(--text-muted)] hover:bg-[var(--bg-hover)] aria-disabled:cursor-not-allowed aria-disabled:opacity-30 aria-disabled:hover:bg-transparent";
|
|
419
|
+
return /* @__PURE__ */ jsxs("div", { className: "select-none", children: [
|
|
420
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-1 pb-1", children: [
|
|
421
|
+
/* @__PURE__ */ jsx(
|
|
422
|
+
"button",
|
|
423
|
+
{
|
|
424
|
+
type: "button",
|
|
425
|
+
"aria-label": inDays ? calendarText.previousMonth : monthText.previousYear,
|
|
426
|
+
"aria-disabled": prevBlocked || void 0,
|
|
427
|
+
onClick: () => {
|
|
428
|
+
if (inDays) showMonth(shiftKey(shown, -1));
|
|
429
|
+
else if (!prevBlocked) moveActive(shiftKey(active, -12), false);
|
|
430
|
+
},
|
|
431
|
+
onKeyDown: escapeToDays,
|
|
432
|
+
className: arrow,
|
|
433
|
+
children: /* @__PURE__ */ jsx(ChevronLeft, { className: "size-4 rtl:-scale-x-100", "aria-hidden": true })
|
|
434
|
+
}
|
|
435
|
+
),
|
|
436
|
+
/* @__PURE__ */ jsxs(
|
|
437
|
+
"button",
|
|
438
|
+
{
|
|
439
|
+
ref: captionRef,
|
|
440
|
+
type: "button",
|
|
441
|
+
"aria-expanded": !inDays,
|
|
442
|
+
"aria-describedby": inDays ? hintId : void 0,
|
|
443
|
+
onClick: inDays ? openMonths : () => closeMonths(false),
|
|
444
|
+
onKeyDown: escapeToDays,
|
|
445
|
+
className: "inline-flex min-w-0 items-center gap-1 rounded px-1.5 py-0.5 text-xs font-medium text-[var(--text-secondary)] hover:bg-[var(--bg-hover)]",
|
|
446
|
+
children: [
|
|
447
|
+
/* @__PURE__ */ jsx("span", { id: captionId, "aria-live": "polite", className: "truncate", children: caption }),
|
|
448
|
+
/* @__PURE__ */ jsx(
|
|
449
|
+
ChevronDown,
|
|
450
|
+
{
|
|
451
|
+
"aria-hidden": true,
|
|
452
|
+
className: cn("size-3.5 shrink-0 text-[var(--text-muted)]", !inDays && "rotate-180")
|
|
453
|
+
}
|
|
454
|
+
)
|
|
455
|
+
]
|
|
456
|
+
}
|
|
457
|
+
),
|
|
458
|
+
/* @__PURE__ */ jsx(
|
|
459
|
+
"button",
|
|
460
|
+
{
|
|
461
|
+
type: "button",
|
|
462
|
+
"aria-label": inDays ? calendarText.nextMonth : monthText.nextYear,
|
|
463
|
+
"aria-disabled": nextBlocked || void 0,
|
|
464
|
+
onClick: () => {
|
|
465
|
+
if (inDays) showMonth(shiftKey(shown, 1));
|
|
466
|
+
else if (!nextBlocked) moveActive(shiftKey(active, 12), false);
|
|
467
|
+
},
|
|
468
|
+
onKeyDown: escapeToDays,
|
|
469
|
+
className: arrow,
|
|
470
|
+
children: /* @__PURE__ */ jsx(ChevronRight, { className: "size-4 rtl:-scale-x-100", "aria-hidden": true })
|
|
471
|
+
}
|
|
472
|
+
)
|
|
473
|
+
] }),
|
|
474
|
+
/* @__PURE__ */ jsx("span", { id: hintId, hidden: true, children: monthText.panel }),
|
|
475
|
+
inDays ? /* @__PURE__ */ jsx(
|
|
476
|
+
MiniCalendar,
|
|
477
|
+
{
|
|
478
|
+
mode,
|
|
479
|
+
from,
|
|
480
|
+
to,
|
|
481
|
+
locale,
|
|
482
|
+
min,
|
|
483
|
+
max,
|
|
484
|
+
labels,
|
|
485
|
+
onSelect,
|
|
486
|
+
focusOnOpen: dayGrid.focus,
|
|
487
|
+
hideNavigation: true,
|
|
488
|
+
month: dayGrid.month,
|
|
489
|
+
onMonthChange: showMonth
|
|
490
|
+
},
|
|
491
|
+
dayGrid.key
|
|
492
|
+
) : /* @__PURE__ */ jsx("div", { ref: monthsRef, role: "grid", "aria-labelledby": captionId, className: "grid gap-1", children: Array.from({ length: 12 / MONTH_COLUMNS }, (_, row) => /* @__PURE__ */ jsx("div", { role: "row", className: "grid grid-cols-3 gap-1", children: Array.from({ length: MONTH_COLUMNS }, (_2, c) => {
|
|
493
|
+
const index = row * MONTH_COLUMNS + c;
|
|
494
|
+
const key = keyOfIndex(year * 12 + index);
|
|
495
|
+
const disabled = outOfBounds(key);
|
|
496
|
+
const selected = low !== null && high !== null && key >= low && key <= high;
|
|
497
|
+
const end = key === fromKey || key === toKey;
|
|
498
|
+
const current = key === currentKey;
|
|
499
|
+
return /* @__PURE__ */ jsx(
|
|
500
|
+
"button",
|
|
501
|
+
{
|
|
502
|
+
type: "button",
|
|
503
|
+
role: "gridcell",
|
|
504
|
+
"data-month": key,
|
|
505
|
+
tabIndex: key === active ? 0 : -1,
|
|
506
|
+
"aria-label": monthText.month(longName.format(firstOfKey(key))),
|
|
507
|
+
"aria-selected": selected,
|
|
508
|
+
"aria-disabled": disabled || void 0,
|
|
509
|
+
"aria-current": current ? "date" : void 0,
|
|
510
|
+
onClick: () => {
|
|
511
|
+
if (!disabled) pick(key);
|
|
512
|
+
},
|
|
513
|
+
onKeyDown: onMonthKeyDown,
|
|
514
|
+
className: cn(
|
|
515
|
+
// 44px rows: the touch-target size, and four of them stand as tall
|
|
516
|
+
// as a month of days, so the panel does not jump as the views swap.
|
|
517
|
+
"h-11 rounded px-1 text-sm tabular-nums transition-colors",
|
|
518
|
+
"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset",
|
|
519
|
+
// A --brand ring on a --brand fill exists only in the DOM.
|
|
520
|
+
end && !disabled ? "focus-visible:ring-[var(--brand-contrast)]" : "focus-visible:ring-[var(--brand)]",
|
|
521
|
+
disabled ? "cursor-not-allowed text-[var(--text-placeholder)]" : end ? "bg-[var(--brand)] text-[var(--brand-contrast)] hover:bg-[var(--brand-hover)]" : selected ? "bg-[var(--brand-bg)] font-medium text-[var(--brand-muted)] hover:bg-[var(--brand-bg-hover)]" : "text-[var(--text-primary)] hover:bg-[var(--bg-hover)]",
|
|
522
|
+
current && !selected && !disabled && "ring-1 ring-inset ring-[var(--border-strong)]"
|
|
523
|
+
),
|
|
524
|
+
children: shortNames[index]
|
|
525
|
+
},
|
|
526
|
+
c
|
|
527
|
+
);
|
|
528
|
+
}) }, row)) })
|
|
529
|
+
] });
|
|
530
|
+
}
|
|
273
531
|
function useDatePickerLabels(clearLabel, stepLabels, todayLabel) {
|
|
274
532
|
const prev = stepLabels?.prev;
|
|
275
533
|
const next = stepLabels?.next;
|
|
@@ -306,6 +564,7 @@ function DatePicker(props) {
|
|
|
306
564
|
todayLabel,
|
|
307
565
|
className,
|
|
308
566
|
calendarLabels,
|
|
567
|
+
monthJump,
|
|
309
568
|
label,
|
|
310
569
|
clearable,
|
|
311
570
|
clearLabel,
|
|
@@ -348,8 +607,9 @@ function DatePicker(props) {
|
|
|
348
607
|
triggerText: value ? render(value) : placeholder ?? "",
|
|
349
608
|
onClear: () => onChange(""),
|
|
350
609
|
children: (close) => /* @__PURE__ */ jsx(
|
|
351
|
-
|
|
610
|
+
PanelCalendar,
|
|
352
611
|
{
|
|
612
|
+
monthJump,
|
|
353
613
|
mode: "single",
|
|
354
614
|
focusOnOpen: true,
|
|
355
615
|
from: value,
|
|
@@ -515,7 +775,7 @@ function RangePanel({
|
|
|
515
775
|
const complete = Boolean(draft.from && draft.to);
|
|
516
776
|
const summary = drafting && renderDraftSummary ? renderDraftSummary({ from: draft.from, to: draft.to, preset: presets?.[marked] }) : null;
|
|
517
777
|
const picker = /* @__PURE__ */ jsx(
|
|
518
|
-
|
|
778
|
+
PanelCalendar,
|
|
519
779
|
{
|
|
520
780
|
...calendarProps,
|
|
521
781
|
focusOnOpen: true,
|
|
@@ -596,6 +856,7 @@ function DateRangePicker(props) {
|
|
|
596
856
|
sheetBackCloses,
|
|
597
857
|
renderDraftSummary,
|
|
598
858
|
calendarLabels,
|
|
859
|
+
monthJump,
|
|
599
860
|
label,
|
|
600
861
|
clearable,
|
|
601
862
|
clearLabel,
|
|
@@ -668,7 +929,7 @@ function DateRangePicker(props) {
|
|
|
668
929
|
frame,
|
|
669
930
|
sheet,
|
|
670
931
|
commitRange,
|
|
671
|
-
calendarProps: { locale, min, max, labels: calendarLabels },
|
|
932
|
+
calendarProps: { locale, min, max, labels: calendarLabels, monthJump },
|
|
672
933
|
labels: text,
|
|
673
934
|
renderDraftSummary
|
|
674
935
|
}
|