@eifi1/ui-kit 0.21.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 +19 -14
- package/dist/components/account-chips.d.ts +10 -3
- package/dist/components/account-chips.js +5 -2
- package/dist/components/account-chips.js.map +1 -1
- package/dist/components/account-settings.d.ts +33 -2
- package/dist/components/account-settings.js +43 -21
- package/dist/components/account-settings.js.map +1 -1
- package/dist/components/amount-input.d.ts +53 -14
- package/dist/components/amount-input.js +17 -28
- package/dist/components/amount-input.js.map +1 -1
- package/dist/components/autocomplete.d.ts +29 -0
- package/dist/components/autocomplete.js +134 -104
- package/dist/components/autocomplete.js.map +1 -1
- package/dist/components/button-group.d.ts +19 -14
- package/dist/components/calculator.d.ts +19 -14
- package/dist/components/checkbox-group.d.ts +104 -0
- package/dist/components/checkbox-group.js +111 -0
- package/dist/components/checkbox-group.js.map +1 -0
- package/dist/components/checkbox.d.ts +19 -0
- package/dist/components/checkbox.js +30 -7
- package/dist/components/checkbox.js.map +1 -1
- package/dist/components/chip.d.ts +18 -0
- package/dist/components/chip.js +47 -10
- package/dist/components/chip.js.map +1 -1
- 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 +91 -2
- package/dist/components/combobox.js +454 -308
- package/dist/components/combobox.js.map +1 -1
- package/dist/components/confirm-dialog.d.ts +69 -161
- package/dist/components/confirm-dialog.js +7 -8
- package/dist/components/confirm-dialog.js.map +1 -1
- package/dist/components/copy-button.d.ts +16 -11
- package/dist/components/country-select.d.ts +167 -0
- package/dist/components/country-select.js +293 -0
- package/dist/components/country-select.js.map +1 -0
- package/dist/components/currency-select.d.ts +17 -1
- package/dist/components/currency-select.js +56 -23
- package/dist/components/currency-select.js.map +1 -1
- package/dist/components/danger-confirm.d.ts +69 -166
- package/dist/components/danger-confirm.js +144 -50
- package/dist/components/danger-confirm.js.map +1 -1
- package/dist/components/data-table-cells.d.ts +1 -2
- package/dist/components/data-table-filter-popover.d.ts +1 -2
- package/dist/components/data-table-filters.d.ts +1 -2
- package/dist/components/data-table-labels.d.ts +4 -97
- package/dist/components/data-table-labels.js +9 -1
- package/dist/components/data-table-labels.js.map +1 -1
- package/dist/components/data-table-pagination.d.ts +3 -1
- package/dist/components/data-table.d.ts +1 -2
- package/dist/components/data-table.js +98 -3
- package/dist/components/data-table.js.map +1 -1
- package/dist/components/date-picker.d.ts +66 -5
- package/dist/components/date-picker.js +378 -66
- package/dist/components/date-picker.js.map +1 -1
- package/dist/components/entity-combobox.d.ts +42 -1
- package/dist/components/entity-combobox.js +154 -113
- package/dist/components/entity-combobox.js.map +1 -1
- package/dist/components/facing-pair.d.ts +19 -14
- package/dist/components/field-parts.d.ts +224 -0
- package/dist/components/field-parts.js +156 -0
- package/dist/components/field-parts.js.map +1 -0
- 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 +19 -14
- package/dist/components/file-button.js +13 -3
- package/dist/components/file-button.js.map +1 -1
- package/dist/components/file-dropzone.d.ts +41 -15
- package/dist/components/file-dropzone.js +57 -34
- package/dist/components/file-dropzone.js.map +1 -1
- package/dist/components/form-actions.d.ts +18 -13
- package/dist/components/form-actions.js +69 -5
- package/dist/components/form-actions.js.map +1 -1
- package/dist/components/iban-input.d.ts +69 -0
- package/dist/components/iban-input.js +125 -0
- package/dist/components/iban-input.js.map +1 -0
- package/dist/components/icon-picker.d.ts +21 -2
- package/dist/components/icon-picker.js +19 -4
- package/dist/components/icon-picker.js.map +1 -1
- package/dist/components/inline-edit-field.d.ts +167 -0
- package/dist/components/inline-edit-field.js +293 -0
- package/dist/components/inline-edit-field.js.map +1 -0
- package/dist/components/language-select.d.ts +130 -0
- package/dist/components/language-select.js +18 -0
- package/dist/components/language-select.js.map +1 -0
- package/dist/components/line-items.d.ts +25 -3
- package/dist/components/line-items.js +55 -46
- package/dist/components/line-items.js.map +1 -1
- package/dist/components/list.d.ts +25 -0
- package/dist/components/list.js +16 -5
- package/dist/components/list.js.map +1 -1
- package/dist/components/money-field.d.ts +32 -14
- package/dist/components/money-field.js.map +1 -1
- package/dist/components/month-picker.d.ts +52 -4
- package/dist/components/month-picker.js +291 -86
- 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/multi-select.d.ts +8 -1
- package/dist/components/multi-select.js +9 -4
- package/dist/components/multi-select.js.map +1 -1
- package/dist/components/number-field.d.ts +34 -19
- package/dist/components/number-field.js +6 -20
- package/dist/components/number-field.js.map +1 -1
- package/dist/components/number-input.d.ts +79 -19
- package/dist/components/number-input.js +90 -38
- package/dist/components/number-input.js.map +1 -1
- package/dist/components/numpad-sheet.d.ts +19 -14
- package/dist/components/one-time-code-input.d.ts +100 -0
- package/dist/components/one-time-code-input.js +137 -0
- package/dist/components/one-time-code-input.js.map +1 -0
- package/dist/components/phone-input.d.ts +69 -0
- package/dist/components/phone-input.js +171 -0
- package/dist/components/phone-input.js.map +1 -0
- 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 +19 -14
- package/dist/components/settings-fields.d.ts +19 -14
- package/dist/components/share-card.d.ts +16 -11
- package/dist/components/sign-chip.d.ts +66 -0
- package/dist/components/sign-chip.js +39 -0
- package/dist/components/sign-chip.js.map +1 -0
- package/dist/components/swatch-picker.d.ts +43 -2
- package/dist/components/swatch-picker.js +80 -32
- package/dist/components/swatch-picker.js.map +1 -1
- package/dist/components/switch.d.ts +19 -0
- package/dist/components/switch.js +24 -6
- package/dist/components/switch.js.map +1 -1
- package/dist/components/text-link.d.ts +18 -13
- package/dist/components/tile-radio.d.ts +88 -13
- package/dist/components/tile-radio.js +28 -11
- package/dist/components/tile-radio.js.map +1 -1
- package/dist/components/time-input.d.ts +24 -15
- package/dist/components/time-input.js.map +1 -1
- package/dist/components/toggle-group.d.ts +47 -1
- package/dist/components/toggle-group.js +110 -69
- 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 +16 -11
- package/dist/components/ui.js +284 -88
- package/dist/components/ui.js.map +1 -1
- package/dist/components/use-table-state.d.ts +1 -2
- package/dist/{data-table-3mi2R3so.d.ts → data-table-labels-B7OdnM0S.d.ts} +140 -3
- package/dist/data-table.d.ts +1 -2
- package/dist/data-table.js +2 -1
- package/dist/data-table.js.map +1 -1
- package/dist/feedback/feedback-attachment.d.ts +1 -1
- package/dist/feedback/feedback-attachment.js +348 -41
- 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 -253
- package/dist/feedback/feedback-thread.js +46 -10
- package/dist/feedback/feedback-thread.js.map +1 -1
- package/dist/{kit-labels-D1J2_jyD.d.ts → feedback-BxeQVzwq.d.ts} +1206 -20
- package/dist/{feedback-attachment-WFiXJ8We.d.ts → feedback-attachment-fGAzZPf0.d.ts} +178 -11
- package/dist/feedback.d.ts +66 -2
- package/dist/hooks/use-file-drop.d.ts +19 -14
- package/dist/i18n/defaults.d.ts +19 -14
- package/dist/i18n/defaults.js +19 -2
- package/dist/i18n/defaults.js.map +1 -1
- package/dist/i18n/german.d.ts +19 -14
- package/dist/i18n/german.js +84 -5
- package/dist/i18n/german.js.map +1 -1
- package/dist/i18n/kit-labels.d.ts +15 -10
- package/dist/i18n/kit-labels.js +8 -2
- package/dist/i18n/kit-labels.js.map +1 -1
- package/dist/i18n/languages.d.ts +19 -14
- package/dist/i18n/locales/de-CH.d.ts +19 -14
- package/dist/i18n/locales/en.d.ts +19 -14
- package/dist/i18n/locales/en.js +16 -0
- package/dist/i18n/locales/en.js.map +1 -1
- package/dist/i18n/locales/es.d.ts +19 -14
- package/dist/i18n/locales/es.js +83 -5
- package/dist/i18n/locales/es.js.map +1 -1
- package/dist/i18n/locales/fr.d.ts +19 -14
- package/dist/i18n/locales/fr.js +82 -5
- package/dist/i18n/locales/fr.js.map +1 -1
- package/dist/i18n/locales/hu.d.ts +19 -14
- package/dist/i18n/locales/hu.js +85 -5
- package/dist/i18n/locales/hu.js.map +1 -1
- package/dist/i18n/locales/it.d.ts +19 -14
- package/dist/i18n/locales/it.js +84 -5
- package/dist/i18n/locales/it.js.map +1 -1
- package/dist/i18n/locales/zh.d.ts +19 -14
- package/dist/i18n/locales/zh.js +80 -5
- package/dist/i18n/locales/zh.js.map +1 -1
- package/dist/i18n/review.d.ts +19 -14
- package/dist/i18n/review.js +27 -1
- package/dist/i18n/review.js.map +1 -1
- package/dist/index.d.ts +21 -10
- package/dist/index.js +73 -2
- 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/countries.d.ts +43 -0
- package/dist/lib/countries.js +39 -0
- package/dist/lib/countries.js.map +1 -0
- package/dist/lib/decimal-marks.d.ts +46 -0
- package/dist/lib/decimal-marks.js +40 -0
- package/dist/lib/decimal-marks.js.map +1 -0
- package/dist/lib/iban.d.ts +98 -0
- package/dist/lib/iban.js +154 -0
- package/dist/lib/iban.js.map +1 -0
- package/dist/lib/isin.d.ts +30 -0
- package/dist/lib/isin.js +36 -0
- package/dist/lib/isin.js.map +1 -0
- package/dist/lib/phone.d.ts +69 -0
- package/dist/lib/phone.js +121 -0
- package/dist/lib/phone.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 +233 -18
- package/dist/rhf/fields.js +456 -3
- package/dist/rhf/fields.js.map +1 -1
- package/dist/rhf/form.d.ts +19 -14
- package/dist/rhf.d.ts +22 -15
- package/dist/rhf.js.map +1 -1
- package/dist/shell/app-shell.d.ts +18 -13
- package/dist/shell/top-bar-brand.d.ts +19 -14
- 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 +18 -13
- package/dist/table-text.d.ts +1 -1
- package/dist/tour/tour.js +20 -24
- package/dist/tour/tour.js.map +1 -1
- package/dist/wizard/stepper-nav.d.ts +49 -16
- package/dist/wizard/stepper-nav.js +4 -0
- package/dist/wizard/stepper-nav.js.map +1 -1
- package/dist/wizard.d.ts +19 -14
- package/package.json +1 -1
- package/src/components/account-chips.tsx +17 -3
- package/src/components/account-settings.tsx +92 -26
- package/src/components/amount-input.tsx +68 -56
- package/src/components/autocomplete.tsx +198 -114
- package/src/components/checkbox-group.tsx +229 -0
- package/src/components/checkbox.tsx +72 -8
- package/src/components/chip.tsx +80 -10
- package/src/components/column-mapper.tsx +666 -0
- package/src/components/combobox-core.tsx +82 -9
- package/src/components/combobox.tsx +661 -340
- package/src/components/confirm-dialog.tsx +12 -8
- package/src/components/country-select.tsx +556 -0
- package/src/components/currency-select.tsx +109 -33
- package/src/components/danger-confirm.tsx +429 -82
- package/src/components/data-table-labels.ts +16 -1
- package/src/components/data-table.tsx +175 -6
- package/src/components/date-picker.tsx +595 -71
- package/src/components/entity-combobox.tsx +235 -124
- package/src/components/field-parts.tsx +403 -0
- package/src/components/field-strip.tsx +149 -0
- package/src/components/file-button.tsx +36 -3
- package/src/components/file-dropzone.tsx +106 -38
- package/src/components/form-actions.tsx +147 -6
- package/src/components/iban-input.tsx +231 -0
- package/src/components/icon-picker.tsx +47 -6
- package/src/components/inline-edit-field.tsx +533 -0
- package/src/components/language-select.tsx +78 -0
- package/src/components/line-items.tsx +35 -2
- package/src/components/list.tsx +55 -6
- package/src/components/money-field.tsx +13 -0
- package/src/components/month-picker.tsx +400 -63
- package/src/components/multi-entity-combobox.tsx +207 -120
- package/src/components/multi-select.tsx +80 -58
- package/src/components/number-field.tsx +28 -46
- package/src/components/number-input.tsx +210 -43
- package/src/components/one-time-code-input.tsx +288 -0
- package/src/components/phone-input.tsx +299 -0
- package/src/components/reauth-dialog.tsx +17 -18
- package/src/components/sign-chip.tsx +103 -0
- package/src/components/swatch-picker.tsx +143 -31
- package/src/components/switch.tsx +58 -7
- package/src/components/tile-radio.tsx +145 -29
- package/src/components/time-input.tsx +8 -1
- package/src/components/toggle-group.tsx +206 -73
- package/src/components/trigger-aria.ts +5 -0
- package/src/components/ui.tsx +479 -138
- package/src/data-table.ts +2 -1
- package/src/feedback/feedback-attachment.tsx +597 -46
- package/src/feedback/feedback-dialog.tsx +9 -3
- package/src/feedback/feedback-inbox.tsx +3 -2
- package/src/feedback/feedback-thread.tsx +113 -9
- package/src/i18n/defaults.ts +18 -1
- package/src/i18n/german.ts +89 -0
- package/src/i18n/kit-labels.tsx +82 -2
- package/src/i18n/locales/en.ts +36 -4
- package/src/i18n/locales/es.ts +87 -0
- package/src/i18n/locales/fr.ts +87 -0
- package/src/i18n/locales/hu.ts +83 -0
- package/src/i18n/locales/it.ts +88 -0
- package/src/i18n/locales/zh.ts +76 -0
- package/src/i18n/review.ts +26 -0
- package/src/index.ts +71 -3
- package/src/lib/column-mapping.ts +234 -0
- package/src/lib/countries.ts +91 -0
- package/src/lib/decimal-marks.ts +99 -0
- package/src/lib/iban.ts +171 -0
- package/src/lib/isin.ts +62 -0
- package/src/lib/phone.ts +211 -0
- package/src/lib/table-text.ts +271 -0
- package/src/rhf/fields.tsx +860 -9
- package/src/rhf.ts +3 -1
- package/src/shell/topbar-action-menu.tsx +134 -38
- package/src/tour/tour.tsx +66 -28
- package/src/wizard/stepper-nav.tsx +35 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/components/account-settings.tsx"],"sourcesContent":["import { useId, useState } from \"react\";\nimport type { KeyboardEvent, ReactNode } from \"react\";\nimport { Button, Card, FIELD_WRITABLE_LOOK, Input } from \"./ui\";\nimport { UserAvatar } from \"./user-avatar\";\nimport { CopyButton } from \"./copy-button\";\nimport { QrCode } from \"./qr-code\";\nimport { DEFAULT_COMMON_LABELS, useKitLabels } from \"../i18n/kit-labels\";\nimport { useAccountSettingsLabels } from \"./account-settings-labels\";\nimport type {\n PasswordSettingLabels,\n ProfileSettingLabels,\n TwoFactorSettingLabels,\n} from \"./account-settings-labels\";\n\n// The label types moved beside the namespace's defaults (0.12.0); re-exported here so\n// every existing `import type { ProfileSettingLabels }` keeps resolving.\nexport type {\n AccountSettingsLabels,\n PasskeysSettingLabels,\n PasswordSettingLabels,\n ProfileSettingLabels,\n TwoFactorSettingLabels,\n} from \"./account-settings-labels\";\nexport { DEFAULT_ACCOUNT_SETTINGS_LABELS } from \"./account-settings-labels\";\n\n/**\n * App-agnostic account-settings SECTIONS (feedback #333). The presentation lives\n * in @hb/ui; each app injects its own auth-API handlers + translated labels and\n * arranges these next to its own app-specific cards (appearance, budgets, …).\n * Every section is a self-contained <Card> owning its transient form state.\n *\n * Every `labels` prop is optional since 0.12.0: the strings come from the provider's\n * `accountSettings` namespace, then English (see account-settings-labels.ts).\n */\n\nexport function ProfileSetting({\n name,\n email,\n role,\n memberSince,\n value,\n onChange,\n onSave,\n saving,\n labels: labelsProp,\n}: {\n name?: string | null;\n email?: string | null;\n role?: ReactNode;\n memberSince?: ReactNode;\n value: string;\n onChange: (value: string) => void;\n onSave: () => void;\n saving?: boolean;\n /** Prop > `<UiKitProvider labels={{ accountSettings: { profile } }}>` > English. */\n labels?: Partial<ProfileSettingLabels>;\n}) {\n const labels = useAccountSettingsLabels(\"profile\", labelsProp);\n const dirty = value.trim().length > 0 && value.trim() !== (name ?? \"\");\n // Generated, not the literal \"display-name\" it was: two of these on one page (an\n // admin editing someone else's profile beside their own) shared an id, and the\n // second label pointed at the first field.\n const inputId = useId();\n return (\n <Card className=\"p-4 space-y-3\">\n <div className=\"flex items-center gap-3\">\n <UserAvatar name={name} email={email} size=\"lg\" />\n <div className=\"min-w-0\">\n <div className=\"text-sm font-medium\">{labels.title}</div>\n <div className=\"truncate font-mono text-xs text-[var(--text-muted)]\">\n {/* `email` was a required key that nothing rendered; it names the address\n for a screen reader, which otherwise hears a bare string under a title. */}\n <span className=\"sr-only\">{labels.email}: </span>\n {email ?? \"—\"}\n </div>\n </div>\n </div>\n <div className=\"grid grid-cols-[max-content_1fr] gap-x-3 gap-y-1 text-sm\">\n <span className=\"text-[var(--text-muted)]\">{labels.role}</span>\n <span>{role ?? \"—\"}</span>\n <span className=\"text-[var(--text-muted)]\">{labels.memberSince}</span>\n <span>{memberSince ?? \"—\"}</span>\n </div>\n <Input\n id={inputId}\n label={labels.displayName}\n value={value}\n onChange={(e) => onChange(e.target.value)}\n maxLength={120}\n />\n <Button onClick={onSave} disabled={!dirty || saving}>\n {labels.save}\n </Button>\n </Card>\n );\n}\n\nexport function PasswordSetting({\n onSubmit,\n pending,\n minLength = 8,\n labels: labelsProp,\n}: {\n /** Called with the validated (current, new) pair; return a promise to auto-clear on success. */\n onSubmit: (currentPassword: string, newPassword: string) => void | Promise<unknown>;\n pending?: boolean;\n minLength?: number;\n /** Prop > `<UiKitProvider labels={{ accountSettings: { password } }}>` > English. */\n labels?: Partial<PasswordSettingLabels>;\n}) {\n const labels = useAccountSettingsLabels(\"password\", labelsProp);\n const [current, setCurrent] = useState(\"\");\n const [next, setNext] = useState(\"\");\n const [confirm, setConfirm] = useState(\"\");\n const [error, setError] = useState<string | null>(null);\n\n const submit = async () => {\n if (next.length < minLength) {\n setError(labels.tooShort);\n return;\n }\n if (next !== confirm) {\n setError(labels.mismatch);\n return;\n }\n setError(null);\n try {\n await onSubmit(current, next);\n setCurrent(\"\");\n setNext(\"\");\n setConfirm(\"\");\n } catch {\n // The app surfaces the failure (e.g. a toast); keep the fields for a retry.\n }\n };\n\n return (\n <Card className=\"p-4 space-y-3\">\n <div className=\"text-sm font-medium\">{labels.title}</div>\n <Input type=\"password\" autoComplete=\"current-password\" label={labels.current} value={current} onChange={(e) => setCurrent(e.target.value)} />\n <Input type=\"password\" autoComplete=\"new-password\" label={labels.next} value={next} onChange={(e) => setNext(e.target.value)} />\n <Input type=\"password\" autoComplete=\"new-password\" label={labels.confirm} value={confirm} onChange={(e) => setConfirm(e.target.value)} />\n {error && <p className=\"text-xs text-[var(--danger)]\">{error}</p>}\n <Button onClick={() => void submit()} disabled={!current || !next || !confirm || pending}>\n {labels.submit}\n </Button>\n </Card>\n );\n}\n\n/**\n * What the app's setup call returned.\n *\n * `otpauthUri` (0.12.0) is what an authenticator backend actually hands out; the kit\n * draws the QR code itself ({@link QrCode}) and reads the manual-entry key out of the\n * URI's `secret` parameter when `secret` is not given. The `qrSvg` shape — a\n * base64-encoded SVG image — is what the section took before, which made every app\n * render a QR library to a static string and base64 it only for the kit to draw it back.\n */\nexport type TwoFactorSetupData =\n | { qrSvg: string; secret: string }\n | { otpauthUri: string; secret?: string };\n\n/** The `secret` parameter of an `otpauth://` URI, or null. */\nfunction otpauthSecret(uri: string): string | null {\n const match = /[?&]secret=([^&#]*)/i.exec(uri);\n if (!match) return null;\n try {\n return decodeURIComponent(match[1]) || null;\n } catch {\n return match[1] || null;\n }\n}\n\n/** \"JBSW Y3DP EHPK 3PXP\": the key in groups of four, which is how an authenticator's\n * manual-entry screen shows it and how a person copies it by eye. */\nfunction groupSecret(secret: string): string {\n return secret.replace(/\\s+/g, \"\").replace(/(.{4})(?=.)/g, \"$1 \");\n}\n\nexport function TwoFactorSetting({\n enabled,\n setup,\n onStartSetup,\n onEnable,\n onDisable,\n busy,\n renderQr,\n labels: labelsProp,\n}: {\n enabled: boolean;\n /** What the app's setup call returned; null before setup starts. */\n setup: TwoFactorSetupData | null;\n onStartSetup: () => void;\n onEnable: (code: string) => void;\n onDisable: (password: string, code: string) => void;\n busy?: boolean;\n /** Draw the code yourself (a branded QR, a library you already ship). Given the\n * `otpauthUri`; the kit's own {@link QrCode} otherwise. Unused with `qrSvg`. */\n renderQr?: (otpauthUri: string) => ReactNode;\n /** Prop > `<UiKitProvider labels={{ accountSettings: { twoFactor } }}>` > English. */\n labels?: Partial<TwoFactorSettingLabels>;\n}) {\n const labels = useAccountSettingsLabels(\"twoFactor\", labelsProp);\n const [code, setCode] = useState(\"\");\n const [password, setPassword] = useState(\"\");\n // Browsers autofill one-time-code fields with the saved username; keep the\n // field readOnly until focus to block that. It therefore has to keep the LOOK of\n // an editable field (FIELD_WRITABLE_LOOK): this is the one place where readOnly\n // does not mean \"you may not type here\", and without the opt-out the field would\n // sit there greyed until the moment it is focused.\n const [otpReadonly, setOtpReadonly] = useState(true);\n const onOtpFocus = () => setOtpReadonly(false);\n // Only for the \"Status: Enabled\" composition — the punctuation between a field's\n // name and its value is the language's (see `CommonLabels.fieldValue`).\n const common = useKitLabels(\"common\", DEFAULT_COMMON_LABELS);\n const secret = setup\n ? (setup.secret ?? (\"otpauthUri\" in setup ? otpauthSecret(setup.otpauthUri) : null))\n : null;\n\n return (\n <Card className=\"p-4 space-y-3\">\n <div className=\"text-sm\">\n {common.fieldValue(labels.status, enabled ? labels.enabledText : labels.disabledText)}\n </div>\n\n {!enabled && !setup && (\n <Button onClick={onStartSetup} disabled={busy}>\n {labels.enable}\n </Button>\n )}\n\n {setup && (\n <div className=\"space-y-2\">\n <div className=\"text-xs text-[var(--text-secondary)]\">{labels.scanHint}</div>\n {/* `bg-white`, NOT `--bg-surface`, and it must stay that way: a QR code is\n read by a camera looking for maximum contrast between the modules and\n their quiet zone. On the dark theme a surface-coloured backing makes it\n slow to acquire, and on a warm light preset it lowers the contrast ratio\n the spec is written against. This is the one place in the kit where a\n literal colour is the correct answer. `data-private`: the code IS the\n second factor, and demo mode blurs it like any other secret. */}\n {\"otpauthUri\" in setup ? (\n // No backing of its own: QrCode draws its quiet zone white inside the SVG.\n <div data-private className=\"inline-block overflow-hidden rounded-md\">\n {renderQr ? (\n renderQr(setup.otpauthUri)\n ) : (\n <QrCode value={setup.otpauthUri} label={labels.qrAlt} className=\"size-48\" />\n )}\n </div>\n ) : (\n <div data-private className=\"inline-block rounded-md bg-white p-2\">\n <img\n alt={labels.qrAlt}\n src={`data:image/svg+xml;base64,${setup.qrSvg}`}\n className=\"h-48 w-48\"\n />\n </div>\n )}\n {secret && (\n <div className=\"space-y-1\">\n <div className=\"text-xs text-[var(--text-secondary)]\">{labels.secretHint}</div>\n <div className=\"flex items-center gap-1\">\n {/* `dir=\"ltr\"`: a base32 key is Latin letters and digits in a fixed\n order, and in an RTL page the groups would otherwise be laid out\n right to left. */}\n <code data-private dir=\"ltr\" className=\"break-all font-mono text-xs select-all\">\n {groupSecret(secret)}\n </code>\n <CopyButton text={secret} label={labels.copySecret} size=\"xs\" tone=\"muted\" />\n </div>\n </div>\n )}\n <Input\n inputMode=\"numeric\"\n autoComplete=\"one-time-code\"\n readOnly={otpReadonly}\n inputClassName={FIELD_WRITABLE_LOOK}\n onFocus={onOtpFocus}\n maxLength={8}\n label={labels.codeLabel}\n value={code}\n onChange={(e) => setCode(e.target.value)}\n onKeyDown={(e: KeyboardEvent<HTMLInputElement>) => {\n if (e.key === \"Enter\" && code && !busy) {\n e.preventDefault();\n onEnable(code);\n }\n }}\n />\n <Button onClick={() => onEnable(code)} disabled={!code || busy}>\n {labels.verify}\n </Button>\n </div>\n )}\n\n {enabled && (\n <div className=\"space-y-3 border-t border-[var(--border)] pt-3\">\n <div className=\"text-sm font-medium\">{labels.disableSection}</div>\n <Input type=\"password\" autoComplete=\"current-password\" label={labels.password} value={password} onChange={(e) => setPassword(e.target.value)} />\n <Input\n inputMode=\"numeric\"\n autoComplete=\"one-time-code\"\n readOnly={otpReadonly}\n inputClassName={FIELD_WRITABLE_LOOK}\n onFocus={onOtpFocus}\n maxLength={8}\n label={labels.codeLabel}\n value={code}\n onChange={(e) => setCode(e.target.value)}\n onKeyDown={(e: KeyboardEvent<HTMLInputElement>) => {\n if (e.key === \"Enter\" && password && code && !busy) {\n e.preventDefault();\n onDisable(password, code);\n }\n }}\n />\n <Button variant=\"danger\" onClick={() => onDisable(password, code)} disabled={!password || !code || busy}>\n {labels.disable}\n </Button>\n </div>\n )}\n </Card>\n );\n}\n"],"mappings":";AAkEQ,cAMI,YANJ;AAlER,SAAS,OAAO,gBAAgB;AAEhC,SAAS,QAAQ,MAAM,qBAAqB,aAAa;AACzD,SAAS,kBAAkB;AAC3B,SAAS,kBAAkB;AAC3B,SAAS,cAAc;AACvB,SAAS,uBAAuB,oBAAoB;AACpD,SAAS,gCAAgC;AAgBzC,SAAS,uCAAuC;AAYzC,SAAS,eAAe;AAAA,EAC7B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,QAAQ;AACV,GAWG;AACD,QAAM,SAAS,yBAAyB,WAAW,UAAU;AAC7D,QAAM,QAAQ,MAAM,KAAK,EAAE,SAAS,KAAK,MAAM,KAAK,OAAO,QAAQ;AAInE,QAAM,UAAU,MAAM;AACtB,SACE,qBAAC,QAAK,WAAU,iBACd;AAAA,yBAAC,SAAI,WAAU,2BACb;AAAA,0BAAC,cAAW,MAAY,OAAc,MAAK,MAAK;AAAA,MAChD,qBAAC,SAAI,WAAU,WACb;AAAA,4BAAC,SAAI,WAAU,uBAAuB,iBAAO,OAAM;AAAA,QACnD,qBAAC,SAAI,WAAU,uDAGb;AAAA,+BAAC,UAAK,WAAU,WAAW;AAAA,mBAAO;AAAA,YAAM;AAAA,aAAE;AAAA,UACzC,SAAS;AAAA,WACZ;AA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AAW;AAAA,UACX,OAAO,OAAO;AAAA,UACd,OAAO;AAAA,UACP,UAAU,CAAC,MAAM,QAAQ,EAAE,OAAO,KAAK;AAAA,UACvC,WAAW,CAAC,MAAuC;AACjD,gBAAI,EAAE,QAAQ,WAAW,QAAQ,CAAC,MAAM;AACtC,gBAAE,eAAe;AACjB,uBAAS,IAAI;AAAA,YACf;AAAA,UACF;AAAA;AAAA,MACF;AAAA,MACA,oBAAC,UAAO,SAAS,MAAM,SAAS,IAAI,GAAG,UAAU,CAAC,QAAQ,MACvD,iBAAO,QACV;AAAA,OACF;AAAA,IAGD,WACC,qBAAC,SAAI,WAAU,kDACb;AAAA,0BAAC,SAAI,WAAU,uBAAuB,iBAAO,gBAAe;AAAA,MAC5D,oBAAC,SAAM,MAAK,YAAW,cAAa,oBAAmB,OAAO,OAAO,UAAU,OAAO,UAAU,UAAU,CAAC,MAAM,YAAY,EAAE,OAAO,KAAK,GAAG;AAAA,MAC9I;AAAA,QAAC;AAAA;AAAA,UACC,WAAU;AAAA,UACV,cAAa;AAAA,UACb,UAAU;AAAA,UACV,gBAAgB;AAAA,UAChB,SAAS;AAAA,UACT,WAAW;AAAA,UACX,OAAO,OAAO;AAAA,UACd,OAAO;AAAA,UACP,UAAU,CAAC,MAAM,QAAQ,EAAE,OAAO,KAAK;AAAA,UACvC,WAAW,CAAC,MAAuC;AACjD,gBAAI,EAAE,QAAQ,WAAW,YAAY,QAAQ,CAAC,MAAM;AAClD,gBAAE,eAAe;AACjB,wBAAU,UAAU,IAAI;AAAA,YAC1B;AAAA,UACF;AAAA;AAAA,MACF;AAAA,MACA,oBAAC,UAAO,SAAQ,UAAS,SAAS,MAAM,UAAU,UAAU,IAAI,GAAG,UAAU,CAAC,YAAY,CAAC,QAAQ,MAChG,iBAAO,SACV;AAAA,OACF;AAAA,KAEJ;AAEJ;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/components/account-settings.tsx"],"sourcesContent":["import { useId, useState } from \"react\";\nimport type { KeyboardEvent, ReactNode } from \"react\";\nimport { Button, Card, Input } from \"./ui\";\nimport { UserAvatar } from \"./user-avatar\";\nimport { CopyButton } from \"./copy-button\";\nimport { QrCode } from \"./qr-code\";\nimport { OneTimeCodeInput } from \"./one-time-code-input\";\nimport {\n DEFAULT_PASSWORD_STRENGTH_LABELS,\n passwordByteLength,\n PasswordStrengthMeter,\n} from \"./password-strength\";\nimport type { PasswordStrengthMeterProps } from \"./password-strength\";\nimport { DEFAULT_COMMON_LABELS, useKitLabels } from \"../i18n/kit-labels\";\nimport { useAccountSettingsLabels } from \"./account-settings-labels\";\nimport type {\n PasswordSettingLabels,\n ProfileSettingLabels,\n TwoFactorSettingLabels,\n} from \"./account-settings-labels\";\n\n// The label types moved beside the namespace's defaults (0.12.0); re-exported here so\n// every existing `import type { ProfileSettingLabels }` keeps resolving.\nexport type {\n AccountSettingsLabels,\n PasskeysSettingLabels,\n PasswordSettingLabels,\n ProfileSettingLabels,\n TwoFactorSettingLabels,\n} from \"./account-settings-labels\";\nexport { DEFAULT_ACCOUNT_SETTINGS_LABELS } from \"./account-settings-labels\";\n\n/**\n * App-agnostic account-settings SECTIONS (feedback #333). The presentation lives\n * in @hb/ui; each app injects its own auth-API handlers + translated labels and\n * arranges these next to its own app-specific cards (appearance, budgets, …).\n * Every section is a self-contained <Card> owning its transient form state.\n *\n * Every `labels` prop is optional since 0.12.0: the strings come from the provider's\n * `accountSettings` namespace, then English (see account-settings-labels.ts).\n */\n\nexport function ProfileSetting({\n name,\n email,\n role,\n memberSince,\n value,\n onChange,\n onSave,\n saving,\n labels: labelsProp,\n}: {\n name?: string | null;\n email?: string | null;\n role?: ReactNode;\n memberSince?: ReactNode;\n value: string;\n onChange: (value: string) => void;\n onSave: () => void;\n saving?: boolean;\n /** Prop > `<UiKitProvider labels={{ accountSettings: { profile } }}>` > English. */\n labels?: Partial<ProfileSettingLabels>;\n}) {\n const labels = useAccountSettingsLabels(\"profile\", labelsProp);\n const dirty = value.trim().length > 0 && value.trim() !== (name ?? \"\");\n // Generated, not the literal \"display-name\" it was: two of these on one page (an\n // admin editing someone else's profile beside their own) shared an id, and the\n // second label pointed at the first field.\n const inputId = useId();\n return (\n <Card className=\"p-4 space-y-3\">\n <div className=\"flex items-center gap-3\">\n <UserAvatar name={name} email={email} size=\"lg\" />\n <div className=\"min-w-0\">\n <div className=\"text-sm font-medium\">{labels.title}</div>\n <div className=\"truncate font-mono text-xs text-[var(--text-muted)]\">\n {/* `email` was a required key that nothing rendered; it names the address\n for a screen reader, which otherwise hears a bare string under a title. */}\n <span className=\"sr-only\">{labels.email}: </span>\n {email ?? \"—\"}\n </div>\n </div>\n </div>\n <div className=\"grid grid-cols-[max-content_1fr] gap-x-3 gap-y-1 text-sm\">\n <span className=\"text-[var(--text-muted)]\">{labels.role}</span>\n <span>{role ?? \"—\"}</span>\n <span className=\"text-[var(--text-muted)]\">{labels.memberSince}</span>\n <span>{memberSince ?? \"—\"}</span>\n </div>\n <Input\n id={inputId}\n label={labels.displayName}\n value={value}\n onChange={(e) => onChange(e.target.value)}\n maxLength={120}\n />\n <Button onClick={onSave} disabled={!dirty || saving}>\n {labels.save}\n </Button>\n </Card>\n );\n}\n\n/**\n * What {@link PasswordSetting}'s `strength` takes besides `true`: the meter's own options,\n * minus the ones the card owns — `value` (the new password), `minLength` (the card's, so\n * the checklist's length rule and the submit's check are one number) and `maxBytes`\n * (the card's own prop, which the submit enforces as well).\n */\nexport type PasswordSettingStrength = Pick<PasswordStrengthMeterProps, \"score\" | \"showRequirements\" | \"labels\">;\n\nexport function PasswordSetting({\n onSubmit,\n pending,\n minLength = 8,\n strength,\n maxBytes,\n labels: labelsProp,\n}: {\n /** Called with the validated (current, new) pair; return a promise to auto-clear on success. */\n onSubmit: (currentPassword: string, newPassword: string) => void | Promise<unknown>;\n pending?: boolean;\n /** The shortest new password the card submits, in characters as a person counts them\n * (an emoji is one). Keep it in step with the server's own minimum. Default 8. */\n minLength?: number;\n /**\n * Show the {@link PasswordStrengthMeter} under the new-password field (0.22.0,\n * kastlan's input audit): the bar, the level in words and the checklist, with the\n * length rule drawn from `minLength`. `true` for the meter as it comes; an object for\n * its `score` (zxcvbn's, say), `showRequirements` or `labels`.\n *\n * Off by default, so a card that never asked for it does not grow one. The meter is\n * advisory, as everywhere in the kit: it blocks nothing — the card's own checks do\n * (`minLength`, the confirmation, `maxBytes`).\n */\n strength?: boolean | PasswordSettingStrength;\n /**\n * A byte ceiling on the new password — bcrypt reads at most 72 BYTES and ignores the\n * rest, which is kastlan's case: `maxBytes={72}`. A new password over it is refused\n * on submit with the meter's own \"too long\" sentence (the `passwordStrength`\n * namespace's `tooLong`), and the meter, when shown, warns while it is typed.\n *\n * Unset by default, and leave it unset for a secret with no ceiling: an invented one\n * talks people out of the long passphrase they chose.\n */\n maxBytes?: number;\n /** Prop > `<UiKitProvider labels={{ accountSettings: { password } }}>` > English. */\n labels?: Partial<PasswordSettingLabels>;\n}) {\n const labels = useAccountSettingsLabels(\"password\", labelsProp);\n const strengthOptions = typeof strength === \"object\" ? strength : undefined;\n // Only for `tooLong`: the sentence the meter shows is the one the refusal says.\n const strengthLabels = useKitLabels(\"passwordStrength\", DEFAULT_PASSWORD_STRENGTH_LABELS, strengthOptions?.labels);\n const [current, setCurrent] = useState(\"\");\n const [next, setNext] = useState(\"\");\n const [confirm, setConfirm] = useState(\"\");\n const [error, setError] = useState<string | null>(null);\n\n const submit = async () => {\n // Code points, not UTF-16 units — the count the meter's checklist and a server's\n // `len()` use. `next.length` counted an emoji as two, so four of them passed a\n // minimum of eight that the meter beside the field said they missed.\n if ([...next].length < minLength) {\n setError(labels.tooShort);\n return;\n }\n if (maxBytes !== undefined && passwordByteLength(next) > maxBytes) {\n setError(strengthLabels.tooLong(maxBytes));\n return;\n }\n if (next !== confirm) {\n setError(labels.mismatch);\n return;\n }\n setError(null);\n try {\n await onSubmit(current, next);\n setCurrent(\"\");\n setNext(\"\");\n setConfirm(\"\");\n } catch {\n // The app surfaces the failure (e.g. a toast); keep the fields for a retry.\n }\n };\n\n const nextField = (\n <Input type=\"password\" autoComplete=\"new-password\" label={labels.next} value={next} onChange={(e) => setNext(e.target.value)} />\n );\n\n return (\n <Card className=\"p-4 space-y-3\">\n <div className=\"text-sm font-medium\">{labels.title}</div>\n <Input type=\"password\" autoComplete=\"current-password\" label={labels.current} value={current} onChange={(e) => setCurrent(e.target.value)} />\n {strength ? (\n // One box for the field and its meter, so the card's `space-y-3` spaces the pair\n // from its neighbours and the meter keeps its own small gap under the field.\n <div>\n {nextField}\n <PasswordStrengthMeter\n value={next}\n minLength={minLength}\n maxBytes={maxBytes}\n score={strengthOptions?.score}\n showRequirements={strengthOptions?.showRequirements}\n labels={strengthOptions?.labels}\n />\n </div>\n ) : (\n nextField\n )}\n <Input type=\"password\" autoComplete=\"new-password\" label={labels.confirm} value={confirm} onChange={(e) => setConfirm(e.target.value)} />\n {error && <p className=\"text-xs text-[var(--danger)]\">{error}</p>}\n <Button onClick={() => void submit()} disabled={!current || !next || !confirm || pending}>\n {labels.submit}\n </Button>\n </Card>\n );\n}\n\n/**\n * What the app's setup call returned.\n *\n * `otpauthUri` (0.12.0) is what an authenticator backend actually hands out; the kit\n * draws the QR code itself ({@link QrCode}) and reads the manual-entry key out of the\n * URI's `secret` parameter when `secret` is not given. The `qrSvg` shape — a\n * base64-encoded SVG image — is what the section took before, which made every app\n * render a QR library to a static string and base64 it only for the kit to draw it back.\n */\nexport type TwoFactorSetupData =\n | { qrSvg: string; secret: string }\n | { otpauthUri: string; secret?: string };\n\n/** The `secret` parameter of an `otpauth://` URI, or null. */\nfunction otpauthSecret(uri: string): string | null {\n const match = /[?&]secret=([^&#]*)/i.exec(uri);\n if (!match) return null;\n try {\n return decodeURIComponent(match[1]) || null;\n } catch {\n return match[1] || null;\n }\n}\n\n/** \"JBSW Y3DP EHPK 3PXP\": the key in groups of four, which is how an authenticator's\n * manual-entry screen shows it and how a person copies it by eye. */\nfunction groupSecret(secret: string): string {\n return secret.replace(/\\s+/g, \"\").replace(/(.{4})(?=.)/g, \"$1 \");\n}\n\nexport function TwoFactorSetting({\n enabled,\n setup,\n onStartSetup,\n onEnable,\n onDisable,\n busy,\n renderQr,\n labels: labelsProp,\n}: {\n enabled: boolean;\n /** What the app's setup call returned; null before setup starts. */\n setup: TwoFactorSetupData | null;\n onStartSetup: () => void;\n onEnable: (code: string) => void;\n onDisable: (password: string, code: string) => void;\n busy?: boolean;\n /** Draw the code yourself (a branded QR, a library you already ship). Given the\n * `otpauthUri`; the kit's own {@link QrCode} otherwise. Unused with `qrSvg`. */\n renderQr?: (otpauthUri: string) => ReactNode;\n /** Prop > `<UiKitProvider labels={{ accountSettings: { twoFactor } }}>` > English. */\n labels?: Partial<TwoFactorSettingLabels>;\n}) {\n const labels = useAccountSettingsLabels(\"twoFactor\", labelsProp);\n const [code, setCode] = useState(\"\");\n const [password, setPassword] = useState(\"\");\n // Both code fields are a OneTimeCodeInput (0.22.0) — the field this card wrote by hand\n // twice — and keep what they did:\n // - `readOnlyUntilFocus`: browsers autofill a one-time-code field with the saved\n // username (the disable form has a current-password field right above it), and a\n // read-only field is never autofilled. The guard drops on focus, and the field\n // keeps the look of an editable one meanwhile (FIELD_WRITABLE_LOOK) — see the prop.\n // - `length={8}`: the `maxLength={8}` they had, so an authenticator issuing eight\n // digits still fits. What changed is that they now take digits only: \"123 456\"\n // pasted from an authenticator that groups its digits used to reach `onEnable`\n // with the space in it.\n // - one `code` state for both, as before.\n // Only for the \"Status: Enabled\" composition — the punctuation between a field's\n // name and its value is the language's (see `CommonLabels.fieldValue`).\n const common = useKitLabels(\"common\", DEFAULT_COMMON_LABELS);\n const secret = setup\n ? (setup.secret ?? (\"otpauthUri\" in setup ? otpauthSecret(setup.otpauthUri) : null))\n : null;\n\n return (\n <Card className=\"p-4 space-y-3\">\n <div className=\"text-sm\">\n {common.fieldValue(labels.status, enabled ? labels.enabledText : labels.disabledText)}\n </div>\n\n {!enabled && !setup && (\n <Button onClick={onStartSetup} disabled={busy}>\n {labels.enable}\n </Button>\n )}\n\n {setup && (\n <div className=\"space-y-2\">\n <div className=\"text-xs text-[var(--text-secondary)]\">{labels.scanHint}</div>\n {/* `bg-white`, NOT `--bg-surface`, and it must stay that way: a QR code is\n read by a camera looking for maximum contrast between the modules and\n their quiet zone. On the dark theme a surface-coloured backing makes it\n slow to acquire, and on a warm light preset it lowers the contrast ratio\n the spec is written against. This is the one place in the kit where a\n literal colour is the correct answer. `data-private`: the code IS the\n second factor, and demo mode blurs it like any other secret. */}\n {\"otpauthUri\" in setup ? (\n // No backing of its own: QrCode draws its quiet zone white inside the SVG.\n <div data-private className=\"inline-block overflow-hidden rounded-md\">\n {renderQr ? (\n renderQr(setup.otpauthUri)\n ) : (\n <QrCode value={setup.otpauthUri} label={labels.qrAlt} className=\"size-48\" />\n )}\n </div>\n ) : (\n <div data-private className=\"inline-block rounded-md bg-white p-2\">\n <img\n alt={labels.qrAlt}\n src={`data:image/svg+xml;base64,${setup.qrSvg}`}\n className=\"h-48 w-48\"\n />\n </div>\n )}\n {secret && (\n <div className=\"space-y-1\">\n <div className=\"text-xs text-[var(--text-secondary)]\">{labels.secretHint}</div>\n <div className=\"flex items-center gap-1\">\n {/* `dir=\"ltr\"`: a base32 key is Latin letters and digits in a fixed\n order, and in an RTL page the groups would otherwise be laid out\n right to left. */}\n <code data-private dir=\"ltr\" className=\"break-all font-mono text-xs select-all\">\n {groupSecret(secret)}\n </code>\n <CopyButton text={secret} label={labels.copySecret} size=\"xs\" tone=\"muted\" />\n </div>\n </div>\n )}\n <OneTimeCodeInput\n readOnlyUntilFocus\n length={8}\n label={labels.codeLabel}\n value={code}\n onChange={setCode}\n onKeyDown={(e: KeyboardEvent<HTMLInputElement>) => {\n if (e.key === \"Enter\" && code && !busy) {\n e.preventDefault();\n onEnable(code);\n }\n }}\n />\n <Button onClick={() => onEnable(code)} disabled={!code || busy}>\n {labels.verify}\n </Button>\n </div>\n )}\n\n {enabled && (\n <div className=\"space-y-3 border-t border-[var(--border)] pt-3\">\n <div className=\"text-sm font-medium\">{labels.disableSection}</div>\n <Input type=\"password\" autoComplete=\"current-password\" label={labels.password} value={password} onChange={(e) => setPassword(e.target.value)} />\n <OneTimeCodeInput\n readOnlyUntilFocus\n length={8}\n label={labels.codeLabel}\n value={code}\n onChange={setCode}\n onKeyDown={(e: KeyboardEvent<HTMLInputElement>) => {\n if (e.key === \"Enter\" && password && code && !busy) {\n e.preventDefault();\n onDisable(password, code);\n }\n }}\n />\n <Button variant=\"danger\" onClick={() => onDisable(password, code)} disabled={!password || !code || busy}>\n {labels.disable}\n </Button>\n </div>\n )}\n </Card>\n );\n}\n"],"mappings":";AAyEQ,cAMI,YANJ;AAzER,SAAS,OAAO,gBAAgB;AAEhC,SAAS,QAAQ,MAAM,aAAa;AACpC,SAAS,kBAAkB;AAC3B,SAAS,kBAAkB;AAC3B,SAAS,cAAc;AACvB,SAAS,wBAAwB;AACjC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,uBAAuB,oBAAoB;AACpD,SAAS,gCAAgC;AAgBzC,SAAS,uCAAuC;AAYzC,SAAS,eAAe;AAAA,EAC7B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,QAAQ;AACV,GAWG;AACD,QAAM,SAAS,yBAAyB,WAAW,UAAU;AAC7D,QAAM,QAAQ,MAAM,KAAK,EAAE,SAAS,KAAK,MAAM,KAAK,OAAO,QAAQ;AAInE,QAAM,UAAU,MAAM;AACtB,SACE,qBAAC,QAAK,WAAU,iBACd;AAAA,yBAAC,SAAI,WAAU,2BACb;AAAA,0BAAC,cAAW,MAAY,OAAc,MAAK,MAAK;AAAA,MAChD,qBAAC,SAAI,WAAU,WACb;AAAA,4BAAC,SAAI,WAAU,uBAAuB,iBAAO,OAAM;AAAA,QACnD,qBAAC,SAAI,WAAU,uDAGb;AAAA,+BAAC,UAAK,WAAU,WAAW;AAAA,mBA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F;AAAA;AAAA,MACF;AAAA,MACA,oBAAC,UAAO,SAAQ,UAAS,SAAS,MAAM,UAAU,UAAU,IAAI,GAAG,UAAU,CAAC,YAAY,CAAC,QAAQ,MAChG,iBAAO,SACV;AAAA,OACF;AAAA,KAEJ;AAEJ;","names":[]}
|
|
@@ -2,17 +2,21 @@ import * as react from 'react';
|
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
3
|
import { CalculatorButtonLabels } from './calculator.js';
|
|
4
4
|
import { NumberPadSheetLabels } from './numpad-sheet.js';
|
|
5
|
-
import '../
|
|
6
|
-
import '
|
|
5
|
+
import '../feedback-BxeQVzwq.js';
|
|
6
|
+
import '../feedback-attachment-fGAzZPf0.js';
|
|
7
|
+
import '../feedback/feedback-inbox.js';
|
|
8
|
+
import 'lucide-react';
|
|
9
|
+
import './tooltip.js';
|
|
10
|
+
import '../hooks/use-anchored-rect.js';
|
|
11
|
+
import '../lib/clipping.js';
|
|
12
|
+
import '../data-table-labels-B7OdnM0S.js';
|
|
13
|
+
import './data-table-sort.js';
|
|
14
|
+
import './swipeable-row.js';
|
|
7
15
|
import './mini-calendar.js';
|
|
8
16
|
import './calendar-heatmap.js';
|
|
9
17
|
import './popover.js';
|
|
10
18
|
import './chip.js';
|
|
11
|
-
import 'lucide-react';
|
|
12
19
|
import './field-sync.js';
|
|
13
|
-
import './tooltip.js';
|
|
14
|
-
import '../hooks/use-anchored-rect.js';
|
|
15
|
-
import '../lib/clipping.js';
|
|
16
20
|
import '../wizard/types.js';
|
|
17
21
|
import '../tour/tour.js';
|
|
18
22
|
import '../search/command-palette.js';
|
|
@@ -26,7 +30,6 @@ import './sparkline.js';
|
|
|
26
30
|
import './stat-tile.js';
|
|
27
31
|
import './signature-pad.js';
|
|
28
32
|
import './password-strength.js';
|
|
29
|
-
import './danger-confirm.js';
|
|
30
33
|
import './swatch-picker.js';
|
|
31
34
|
import './tile-radio.js';
|
|
32
35
|
import './icon-picker.js';
|
|
@@ -34,11 +37,7 @@ import './dialog-frame.js';
|
|
|
34
37
|
import './modal.js';
|
|
35
38
|
import '../hooks/use-search-param-state.js';
|
|
36
39
|
import './measured-grid.js';
|
|
37
|
-
import '../feedback-attachment-WFiXJ8We.js';
|
|
38
|
-
import '../feedback/feedback-thread.js';
|
|
39
|
-
import '../feedback/feedback-inbox.js';
|
|
40
40
|
import './account-settings-labels.js';
|
|
41
|
-
import './confirm-dialog.js';
|
|
42
41
|
import './floating-panel.js';
|
|
43
42
|
import './bulk-action-bar.js';
|
|
44
43
|
import './list.js';
|
|
@@ -57,14 +56,20 @@ import './write-lock.js';
|
|
|
57
56
|
import './legal.js';
|
|
58
57
|
import './account-chips.js';
|
|
59
58
|
import '../lib/format.js';
|
|
60
|
-
import '../data-table-3mi2R3so.js';
|
|
61
|
-
import './data-table-sort.js';
|
|
62
|
-
import './swipeable-row.js';
|
|
63
59
|
import './reauth-dialog.js';
|
|
64
60
|
import './server-wake.js';
|
|
65
61
|
import '../lib/server-wake.js';
|
|
66
62
|
import './translation-review-labels.js';
|
|
67
63
|
import '../lib/translation-review.js';
|
|
64
|
+
import './country-select.js';
|
|
65
|
+
import './inline-edit-field.js';
|
|
66
|
+
import '../lib/iban.js';
|
|
67
|
+
import '../lib/phone.js';
|
|
68
|
+
import './sign-chip.js';
|
|
69
|
+
import './column-mapper.js';
|
|
70
|
+
import '../lib/column-mapping.js';
|
|
71
|
+
import '../lib/table-text.js';
|
|
72
|
+
import './field-parts.js';
|
|
68
73
|
|
|
69
74
|
interface AmountInputProps {
|
|
70
75
|
value: string;
|
|
@@ -76,7 +81,41 @@ interface AmountInputProps {
|
|
|
76
81
|
disabled?: boolean;
|
|
77
82
|
/** Required and unanswered — {@link FIELD_INVALID}. See {@link Input}'s `invalid`. */
|
|
78
83
|
invalid?: boolean;
|
|
84
|
+
/**
|
|
85
|
+
* What is wrong with the amount, in the caller's own words — {@link Input}'s `error`
|
|
86
|
+
* (keksdose K4: "exceeds the outstanding balance" was a loose `<p>` beside the field
|
|
87
|
+
* that nothing pointed at). Rendered under the field, after a text `hint`; merged into
|
|
88
|
+
* `aria-describedby` after the caller's ids and the hint's; implies `invalid`, so the
|
|
89
|
+
* field paints as well as announces. `null`, `false` and `""` are no message.
|
|
90
|
+
* {@link MoneyField} takes it too.
|
|
91
|
+
*/
|
|
92
|
+
error?: ReactNode;
|
|
93
|
+
/**
|
|
94
|
+
* Show the desktop calculator trigger (default `true`). `false` for an amount in an
|
|
95
|
+
* ephemeral close-on-blur editor — a budget's assigned cell, a VAT cell (keksdose K6)
|
|
96
|
+
* — where a click on the icon blurs the field and tears the editor down before the
|
|
97
|
+
* popover can open. Typing a calculation ("200+50", then Enter) still evaluates, and
|
|
98
|
+
* a phone keeps its numpad, exactly as {@link NumberInput}'s `calculator={false}`.
|
|
99
|
+
*/
|
|
100
|
+
calculator?: boolean;
|
|
101
|
+
/** The field's WRAPPER — width, a margin, a flex share. The `<input>` is
|
|
102
|
+
* `inputClassName`'s. */
|
|
79
103
|
className?: string;
|
|
104
|
+
/**
|
|
105
|
+
* Classes for the `<input>` itself — {@link NumberInput}'s and {@link Input}'s prop of
|
|
106
|
+
* the same name, merged the same way: after the field's own base classes, so it can
|
|
107
|
+
* restyle the figure (`text-end` for a money column whose decimal points line up,
|
|
108
|
+
* `font-medium`, a tighter `py-1` in a table cell), and before the end padding the
|
|
109
|
+
* calculator and the currency chip reserve and before the invalid border, so neither
|
|
110
|
+
* can be taken away by accident.
|
|
111
|
+
*
|
|
112
|
+
* keksdose G7: the invoice's VAT cell right-aligns its figure, and with only
|
|
113
|
+
* `className` (the wrapper) it reached the element through `[&_input]:text-end` — a
|
|
114
|
+
* descendant selector that depends on the field's inner markup, which the kit is free
|
|
115
|
+
* to change, and that a reader of the call site has to decode. {@link MoneyField}
|
|
116
|
+
* passes it through, and `RhfMoneyField` takes it too.
|
|
117
|
+
*/
|
|
118
|
+
inputClassName?: string;
|
|
80
119
|
id?: string;
|
|
81
120
|
ariaLabel?: string;
|
|
82
121
|
/**
|
|
@@ -25,6 +25,8 @@ import {
|
|
|
25
25
|
sanitizeLive,
|
|
26
26
|
splitLeadingSign
|
|
27
27
|
} from "../lib/calc.js";
|
|
28
|
+
import { decimalMark, localizeMark, readTyped, showsTyped } from "../lib/decimal-marks.js";
|
|
29
|
+
import { hasMessage, mergeDescribedBy } from "./choice-parts.js";
|
|
28
30
|
function settleAmount(text, digits, min, max) {
|
|
29
31
|
const t = text.trim();
|
|
30
32
|
if (!/^-?\d*\.?\d*$/.test(t) || !/\d/.test(t)) return text;
|
|
@@ -39,24 +41,7 @@ function settleAmount(text, digits, min, max) {
|
|
|
39
41
|
const out = formatResult(n);
|
|
40
42
|
return Number(out) === Number(t) ? text : out;
|
|
41
43
|
}
|
|
42
|
-
|
|
43
|
-
try {
|
|
44
|
-
const part = new Intl.NumberFormat(locale).formatToParts(1.5).find((p) => p.type === "decimal");
|
|
45
|
-
return part?.value === "," ? "," : ".";
|
|
46
|
-
} catch {
|
|
47
|
-
return ".";
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
function normalizeTypedMarks(raw, mark) {
|
|
51
|
-
const other = mark === "," ? "." : ",";
|
|
52
|
-
return raw.replace(/[0-9.,]+/g, (operand) => {
|
|
53
|
-
const hasMark = operand.includes(mark);
|
|
54
|
-
const count = operand.split(other).length - 1;
|
|
55
|
-
if (count === 0) return operand;
|
|
56
|
-
const grouping = hasMark ? true : count > 1 || mark === "," && /^\d{1,3}(\.\d{3})+$/.test(operand);
|
|
57
|
-
return grouping ? operand.split(other).join("") : operand;
|
|
58
|
-
});
|
|
59
|
-
}
|
|
44
|
+
const FIELD_ERROR_CLASS = "mt-1 text-[11px] leading-tight text-[var(--danger)]";
|
|
60
45
|
const TONE_CLASS = {
|
|
61
46
|
neutral: "",
|
|
62
47
|
outflow: "text-money-neg",
|
|
@@ -71,16 +56,18 @@ function isResultOf(previous, text, settle) {
|
|
|
71
56
|
return n !== null && settle(formatResult(n)) === text.trim();
|
|
72
57
|
}
|
|
73
58
|
const AmountInput = forwardRef(
|
|
74
|
-
({ value, onChange, currency, onCurrencyChange, placeholder, label, disabled, invalid: invalidProp, className, id, ariaLabel, "aria-describedby": ariaDescribedBy, "aria-invalid": ariaInvalid, "aria-required": ariaRequired, hint, autoFocus, tone = "neutral", negative = false, onNegativeChange, variant = "field", align = "start", labels, currencyNames, digits: digitsProp, min, max, onCommit }, ref) => {
|
|
59
|
+
({ value, onChange, currency, onCurrencyChange, placeholder, label, disabled, invalid: invalidProp, error, calculator = true, className, inputClassName, id, ariaLabel, "aria-describedby": ariaDescribedBy, "aria-invalid": ariaInvalid, "aria-required": ariaRequired, hint, autoFocus, tone = "neutral", negative = false, onNegativeChange, variant = "field", align = "start", labels, currencyNames, digits: digitsProp, min, max, onCommit }, ref) => {
|
|
75
60
|
const generatedId = useId();
|
|
76
61
|
const fieldId = id ?? generatedId;
|
|
77
62
|
const hintId = useId();
|
|
63
|
+
const errorId = useId();
|
|
78
64
|
const textHint = typeof hint === "string" && hint !== "" || typeof hint === "number";
|
|
79
|
-
const
|
|
80
|
-
const
|
|
65
|
+
const hasError = hasMessage(error);
|
|
66
|
+
const describedBy = mergeDescribedBy(ariaDescribedBy, textHint && hintId, hasError && errorId);
|
|
67
|
+
const invalid = Boolean(invalidProp) || hasError || ariaInvalid === true || ariaInvalid === "true";
|
|
81
68
|
const editable = !!onCurrencyChange;
|
|
82
69
|
const isMobile = useMediaQuery(PHONE_QUERY, false);
|
|
83
|
-
const showCalc = !disabled && !isMobile;
|
|
70
|
+
const showCalc = calculator && !disabled && !isMobile;
|
|
84
71
|
const [focused, setFocused] = useState(false);
|
|
85
72
|
const showNumpad = isMobile && !disabled && focused;
|
|
86
73
|
const asDisplay = variant === "display" && isMobile;
|
|
@@ -100,11 +87,10 @@ const AmountInput = forwardRef(
|
|
|
100
87
|
const [draft, setDraft] = useState(null);
|
|
101
88
|
const displayDigits = digitsProp ?? currencyMinorDigits(currency);
|
|
102
89
|
const resting = focused ? shown : settleAmount(shown, displayDigits);
|
|
103
|
-
const derived =
|
|
104
|
-
const
|
|
105
|
-
const display = draft === null ? derived : draftAs === shown ? draft : (
|
|
90
|
+
const derived = localizeMark(resting, mark);
|
|
91
|
+
const display = draft === null ? derived : showsTyped(draft, mark, shown) ? draft : (
|
|
106
92
|
// The caller owns the sign: the typed "12" is shown as the "-12" it is.
|
|
107
|
-
signOwned && negative &&
|
|
93
|
+
signOwned && negative && shown.startsWith("-") && showsTyped(draft, mark, shown.slice(1)) ? `-${draft}` : derived
|
|
108
94
|
);
|
|
109
95
|
const digits = digitsProp ?? currencyMinorDigits(currency);
|
|
110
96
|
const settle = (text) => settleAmount(text, digits, min, max);
|
|
@@ -130,7 +116,7 @@ const AmountInput = forwardRef(
|
|
|
130
116
|
};
|
|
131
117
|
const typed = (raw) => {
|
|
132
118
|
setDraft(raw);
|
|
133
|
-
handleText(
|
|
119
|
+
handleText(readTyped(raw, mark));
|
|
134
120
|
};
|
|
135
121
|
const { open, setOpen, wrapperRef, panelRef, query, setQuery, inputRef } = useDropdownSearch();
|
|
136
122
|
const chipRef = useRef(null);
|
|
@@ -191,6 +177,8 @@ const AmountInput = forwardRef(
|
|
|
191
177
|
// (feedback #314). FLOATING_INPUT_CLASS already bundles the peer +
|
|
192
178
|
// transparent-placeholder bits.
|
|
193
179
|
asDisplay ? DISPLAY_INPUT_CLASS : label !== void 0 ? FLOATING_INPUT_CLASS : FIELD_BASE,
|
|
180
|
+
// The caller's, over the base and under everything below (see `inputClassName`).
|
|
181
|
+
inputClassName,
|
|
194
182
|
// Room for the trailing controls. showCalc is always false on a phone,
|
|
195
183
|
// so the display shape only ever has to clear the currency chip — and
|
|
196
184
|
// it clears it by the chip's actual width (a text-sm code plus a
|
|
@@ -226,7 +214,7 @@ const AmountInput = forwardRef(
|
|
|
226
214
|
showCalc && /* @__PURE__ */ jsx(
|
|
227
215
|
CalculatorButton,
|
|
228
216
|
{
|
|
229
|
-
value:
|
|
217
|
+
value: derived,
|
|
230
218
|
onChange: (result, expression) => {
|
|
231
219
|
setDraft(null);
|
|
232
220
|
const settled = settle(result);
|
|
@@ -318,6 +306,7 @@ const AmountInput = forwardRef(
|
|
|
318
306
|
}
|
|
319
307
|
),
|
|
320
308
|
textHint && /* @__PURE__ */ jsx("p", { id: hintId, className: "mt-1 text-[11px] leading-tight text-[var(--text-muted)]", children: hint }),
|
|
309
|
+
hasError && /* @__PURE__ */ jsx("p", { id: errorId, className: FIELD_ERROR_CLASS, children: error }),
|
|
321
310
|
showNumpad && /* @__PURE__ */ jsx(
|
|
322
311
|
NumberPadSheet,
|
|
323
312
|
{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/components/amount-input.tsx"],"sourcesContent":["import { forwardRef, useCallback, useId, useMemo, useRef, useState } from \"react\";\nimport { ChevronDown } from \"lucide-react\";\nimport type { ReactNode } from \"react\";\nimport { CURRENCIES, CurrencyFlag, currencyName, getCurrency } from \"./currency-select\";\nimport { FIELD_BASE, FIELD_DISPLAY, FIELD_INVALID, FLOATING_INPUT_CLASS, FloatingField, PHONE_QUERY } from \"./ui\";\nimport { cn } from \"../lib/cn\";\nimport { currencyMinorDigits } from \"../lib/format\";\nimport { useMediaQuery } from \"../hooks/use-media-query\";\nimport { CalculatorButton, type CalculatorButtonLabels } from \"./calculator\";\nimport { NumberPadSheet, type NumberPadSheetLabels } from \"./numpad-sheet\";\nimport { DropdownPanel, DropdownSearchHeader, useDropdownSearch } from \"./dropdown\";\nimport {\n DEFAULT_COMMON_LABELS,\n DEFAULT_CURRENCY_LABELS,\n useKitLabels,\n useKitLocale,\n type CurrencyLabels,\n} from \"../i18n/kit-labels\";\nimport {\n commitExpression,\n evaluateExpression,\n formatResult,\n isBareAmount,\n looksLikeExpression,\n sanitizeLive,\n splitLeadingSign,\n} from \"../lib/calc\";\n\ninterface AmountInputProps {\n value: string;\n onChange: (value: string) => void;\n currency?: string;\n onCurrencyChange?: (code: string) => void;\n placeholder?: string;\n label?: ReactNode;\n disabled?: boolean;\n /** Required and unanswered — {@link FIELD_INVALID}. See {@link Input}'s `invalid`. */\n invalid?: boolean;\n className?: string;\n id?: string;\n ariaLabel?: string;\n /**\n * Set on the `<input>`, with `id` above. Declared so `Field`'s render-prop spread —\n * `{(ids) => <AmountInput {...ids} … />}` — is typed and reaches the input: the\n * hint and error are described, a required amount is announced as required, and\n * `aria-invalid` paints {@link FIELD_INVALID} the way `invalid` does.\n */\n \"aria-describedby\"?: string;\n \"aria-invalid\"?: boolean | \"true\" | \"false\";\n \"aria-required\"?: boolean | \"true\" | \"false\";\n /** {@link NumberInput}'s `hint`, the same rule: a {@link FieldHint} \"?\" rides the\n * label's own line, beside the label (not at the far end, where the calculator and\n * the currency chip live); plain TEXT (a string or a number) is a caption UNDER\n * the field, attached through `aria-describedby` after the caller's own. A phone's\n * `variant=\"display\"` has no visible label, so a FieldHint is dropped there; a\n * caption still shows. */\n hint?: ReactNode;\n /** Every user-facing string this component and the two it composes own, so a\n * translating host can supply its own. Each key optional, and each a per-field\n * override of the kit-wide translation in `<UiKitProvider labels>`: `currency`\n * and `currencySearch` of its `currency` namespace, the rest of `calculator`.\n * `currency` names the picker chip, composed with the selected code through\n * `common.fieldValue`; the rest are pass-through. */\n labels?: {\n currency?: string;\n currencySearch?: string;\n /** Names the calculator TRIGGER this component renders. `calculator` below\n * names the controls inside the popover it opens. */\n calculatorTrigger?: string;\n pad?: NumberPadSheetLabels;\n calculator?: CalculatorButtonLabels;\n };\n /** Translated currency names for the chip's picker, keyed by ISO code. The same\n * sparse override `CurrencySelect` takes, and for the same reason: the names in\n * `CURRENCIES` are shipped data, so without this they are the one English word\n * left in a translated row. Not part of `labels` because it is keyed by DATA\n * rather than by a fixed set of slots, and an app passes the same map to both\n * pickers. */\n currencyNames?: Record<string, string>;\n /** Focus the field on mount — on mobile this also opens the numpad sheet, so a\n * new-transaction form can jump straight to amount entry (feedback #70). */\n autoFocus?: boolean;\n /**\n * Tint the typed figure by what it will DO (Keksdose feedback #167).\n *\n * The direction is chosen with a toggle beside the field rather than typed, so\n * the digits alone say nothing about which way the money goes — on the one screen\n * where getting that backwards is the expensive mistake. Colour says it\n * continuously, and it costs no layout. It stays the MAIN indication (live #201\n * rework: *\"The main indication shall still be the color\"*); {@link negative}\n * renders the sign as a second, quieter signal in front of the figure.\n *\n * Never the ONLY signal: the toggle it mirrors is right there, labelled, so this\n * is reinforcement rather than the sole carrier of the meaning.\n */\n tone?: \"neutral\" | \"outflow\" | \"inflow\";\n /**\n * The SIGN of the figure, owned by the caller's direction control (Keksdose live\n * #201 rework: *\"Outflow should be negative and inflow positive … the sign shall\n * be displayed but not necessarily be typed in\"*).\n *\n * `value` stays the MAGNITUDE. The minus is glued on at render time and stripped\n * off again before anything is reported back, so the caller never sees its own\n * prefix echoed and no code path can end up applying it twice. That is the whole\n * cure: there is exactly ONE place the sign lives, and it is not the text.\n *\n * Because it is rendered rather than stored it cannot be deleted (the next render\n * puts it back), a select-all-and-retype keeps the direction, and the caret needs\n * no minding.\n *\n * Since 0.15.5 it is drawn on its own too, for a read-only or disabled signed figure\n * (an \"Items total\" of −5.18): no `onNegativeChange` needed just to show the minus.\n */\n negative?: boolean;\n /**\n * A sign the user TYPED, or a calculation that resolved to a signed number.\n *\n * SET, never flip. A \"-\" means *\"this is an outflow\"*, so typing it twice says the\n * same thing twice — which is exactly what the rework asks for (*\"Subtracting\n * values twice resulting in inflow -> outflow and back to inflow seems not\n * reasonable\"*). \"+\" says the other direction.\n *\n * Its presence is what ARMS the whole sign behaviour. A field with no direction\n * control — an account's starting balance, a loan payment, a holding's cost —\n * passes neither prop and keeps a text that is the whole truth, minus included.\n */\n onNegativeChange?: (negative: boolean) => void;\n /**\n * How the field presents itself ON A PHONE (Keksdose feedback #176).\n *\n * `\"field\"` (default) is the labelled, bordered input used everywhere else.\n *\n * `\"display\"` keeps every mechanic — the same `<input>`, the same numpad sheet,\n * the same currency picker, the same commit/blur contract — and only drops the\n * chrome: no border, no fill, no floating label, the figure set at display size.\n * On a form whose whole point is one number, a bordered `text-sm` box draws the\n * amount at the same weight as the memo beside it; this makes it the headline\n * instead. It stays fully editable — the underline and the caret are what say so.\n *\n * Phone-only by construction: it keys off the same breakpoint as the numpad, so\n * from `md` up the field is byte-for-byte the normal one and a desktop grid keeps\n * its column rhythm.\n */\n variant?: \"field\" | \"display\";\n /**\n * Where the figure sits in its row, for `variant=\"display\"` only (Keksdose\n * feedback #176 rework).\n *\n * `\"start\"` (default) keeps it flush left, in the reading column the fields\n * below it share — and it is what the entry forms use, because a figure that\n * starts at a known edge is legible at any width: when the value outgrows the\n * field, the digits that scroll out of sight are the trailing ones, not the\n * magnitude (Keksdose feedback #430 rework).\n *\n * `\"center\"` makes it a centred headline. It centres in the width that REMAINS\n * after the trailing currency control, not in the whole box: the control is\n * pinned to the right edge, so a plain `text-center` would centre the figure\n * under it and the last digits would sit behind the chip. This used to mirror\n * the control's reservation onto the left instead, which centred correctly but\n * spent twice the control's width on padding — fatal on a 375px screen, where\n * it left a 36px figure 16px to live in.\n */\n align?: \"start\" | \"center\";\n /**\n * Decimals the committed amount is rounded to (kastlan 0.12: \"12.345\" and a\n * calculator's \"100/3\" reached a `Numeric(10,2)` column unrounded and failed with a\n * 422). Default: the currency's minor unit, from `Intl` (CHF and EUR 2, JPY 0). With\n * no `currency`, nothing is rounded unless this is set. Rounding is half away from\n * zero (12.345 → 12.35, -12.345 → -12.35) and happens when the figure settles: on\n * blur, on Enter, and on every result the calculator writes back. Keystrokes are left\n * alone, so \"12.3\" can still become \"12.34\".\n *\n * ⚠️ **A unit price or a rate needs `digits`.** The default is right for an amount of\n * money and silently wrong for a price per unit: a fund's NAV of 123.4567 or fuel at\n * 1.789 €/l is stored as 123.46 / 1.79, and no test fails (keksdose G2, a\n * `Numeric(18,6)` holding price and a `Numeric(18,4)` unit price). Pass the column's\n * scale: `digits={4}`, `digits={6}`.\n *\n * **Set `digits` for any sub-currency scale** — not only a price: any field whose\n * column holds more decimals than the currency's minor unit. A split line stored at\n * the ledger's 4dp (`Numeric(18,4)`) and loaded as 12.3456 is SHOWN as 12.35, and\n * committed as 12.35 as soon as the user tabs through it (blur settles) — so the form\n * no longer equals what the server holds: the lines stop summing to the 4dp total,\n * and Save is held (keksdose live #240). With a `currency`, every commit rounds to that currency's\n * minor unit unless `digits` says otherwise: pass the column's scale (`digits={4}`).\n */\n digits?: number;\n /** The smallest amount the field settles on. A lower figure is raised to it when it\n * settles, like `digits`. Compared with the signed figure. */\n min?: number;\n /** The largest amount the field settles on (a deposit release capped at the\n * balance). A higher figure is lowered to it when it settles. */\n max?: number;\n /**\n * The SETTLED figure, dot-decimal, sign included — fired on blur, on Enter, on the\n * numpad's \"=\" and on every result the calculator writes back, never on a keystroke\n * (\"1200+\" is not a figure yet). `onChange` still reports every keystroke; this is\n * for a host that stores a number and must not see drafts (kastlan 52; see\n * {@link MoneyField}, which is built on it).\n */\n onCommit?: (value: string) => void;\n}\n\n\n/**\n * A settled figure, rounded to `digits` (half away from zero) and clamped to\n * `min`/`max`. Only a plain number is touched. A half-typed draft or an expression\n * comes back as it was. Rounding works in decimal exponent notation, because\n * `Math.round(1.005 * 100)` is 100 (1.005 is 1.00499… in binary).\n */\nfunction settleAmount(text: string, digits: number | undefined, min?: number, max?: number): string {\n const t = text.trim();\n if (!/^-?\\d*\\.?\\d*$/.test(t) || !/\\d/.test(t)) return text;\n let n = Number(t);\n if (!Number.isFinite(n)) return text;\n if (digits !== undefined) {\n const magnitude = Number(`${Math.round(Number(`${Math.abs(n)}e${digits}`))}e-${digits}`);\n n = n < 0 ? -magnitude : magnitude;\n }\n if (min !== undefined && n < min) n = min;\n if (max !== undefined && n > max) n = max;\n const out = formatResult(n);\n // Unchanged figures keep their own spelling (\"12.50\" stays \"12.50\").\n return Number(out) === Number(t) ? text : out;\n}\n\n/**\n * The locale's decimal mark, as far as this field can type it: \",\" or \".\" (kastlan 40).\n * The same answer `NumberField` gives, for the same reason: a mark outside those two\n * (Arabic's \"٫\") is not one {@link sanitizeLive} lets through, so those locales keep\n * the dot rather than get a field that eats the key it shows.\n */\nfunction decimalMark(locale: string | undefined): \",\" | \".\" {\n try {\n const part = new Intl.NumberFormat(locale).formatToParts(1.5).find((p) => p.type === \"decimal\");\n return part?.value === \",\" ? \",\" : \".\";\n } catch {\n // An invalid tag throws a RangeError; a typo in a locale must not take the form down.\n return \".\";\n }\n}\n\n/**\n * Which typed mark is the decimal one (keksdose G1). {@link sanitizeLive} folds every\n * \",\" into \".\", so on its own it read the German \"1.234,56\" as 1.23456 — and the\n * settle then made that 1.23, final. This decides per operand, from the typist's own\n * text, before that fold:\n *\n * - both marks present: the one that is not the locale's is grouping, and goes;\n * - in a \",\" locale, only \".\" present: grouping when it cannot be a decimal as a\n * German reader writes it — twice (\"1.234.567\"), or in thousands shape (\"1.234\",\n * \"12.500\") — otherwise a decimal (\"1.5\", typed by a dot-decimal habit);\n * - in a \".\" locale, only \",\" present: grouping when it appears twice (\"1,234,567\");\n * once it stays a decimal, because Swiss and German typists write \"1,5\" in a\n * de-CH form (kastlan 40) and a unit price \"1,789\" is a decimal.\n *\n * Only a keystroke's text comes through here. A calculator result is dot-decimal\n * already, and \"1.234\" from `100/81.03…` is never a thousand.\n */\nfunction normalizeTypedMarks(raw: string, mark: \",\" | \".\"): string {\n const other = mark === \",\" ? \".\" : \",\";\n return raw.replace(/[0-9.,]+/g, (operand) => {\n const hasMark = operand.includes(mark);\n const count = operand.split(other).length - 1;\n if (count === 0) return operand;\n const grouping = hasMark\n ? true\n : count > 1 || (mark === \",\" && /^\\d{1,3}(\\.\\d{3})+$/.test(operand));\n return grouping ? operand.split(other).join(\"\") : operand;\n });\n}\n\n// The consuming app's ONE money palette (`--money-expense` / `--money-income`),\n// not a bespoke rose/emerald pairing: a figure being typed has to wear the same\n// colour the same figure will wear once it is a row in the table behind the form\n// (Keksdose dev#434). The utilities are unlayered and theme-aware, so no `dark:`\n// variant is needed and they win over the field's own text colour regardless of\n// where `cn` puts them.\nconst TONE_CLASS: Record<\"neutral\" | \"outflow\" | \"inflow\", string> = {\n neutral: \"\",\n outflow: \"text-money-neg\",\n inflow: \"text-money-pos\",\n};\n\n// The shared chrome-less treatment at money size. `tabular-nums` so digits don't\n// reflow the figure as they are typed; FIELD_DISPLAY's own muted placeholder\n// colour is what keeps an EMPTY form from painting its zero in the direction tint\n// (`tone` is computed from 0, which reads as an inflow).\nconst DISPLAY_INPUT_CLASS = cn(\n FIELD_DISPLAY,\n \"text-4xl font-semibold leading-tight tracking-tight tabular-nums\",\n);\n\n/**\n * Is `text` the ANSWER to `previous`, or something typed OVER it?\n *\n * \"The old text was a sum and the new one is bare\" cannot tell those apart, and both\n * gestures are ordinary: select-all-and-retype after a typo, or backspacing \"-20+\"\n * back down to a fresh figure. Read as an answer, they move the direction chip — so\n * an outflow of 7 quietly booked +7.00 (live #201 rework).\n *\n * The question that does separate them is arithmetic, not shape: evaluate what the\n * text replaced and see whether this IS that number. \"-12+30\" → \"18\" still is, so a\n * sum that comes out positive still takes the chip with it; \"-20+50\" → \"7\" is not,\n * and \"-20+\" evaluates to nothing at all.\n */\nfunction isResultOf(previous: string, text: string, settle: (text: string) => string): boolean {\n const n = evaluateExpression(previous);\n // Compared settled, since the field rounds what the calculator hands it.\n return n !== null && settle(formatResult(n)) === text.trim();\n}\n\nexport const AmountInput = forwardRef<HTMLInputElement, AmountInputProps>(\n ({ value, onChange, currency, onCurrencyChange, placeholder, label, disabled, invalid: invalidProp, className, id, ariaLabel, \"aria-describedby\": ariaDescribedBy, \"aria-invalid\": ariaInvalid, \"aria-required\": ariaRequired, hint, autoFocus, tone = \"neutral\", negative = false, onNegativeChange, variant = \"field\", align = \"start\", labels, currencyNames, digits: digitsProp, min, max, onCommit }, ref) => {\n const generatedId = useId();\n const fieldId = id ?? generatedId;\n const hintId = useId();\n // Text is a caption under the field; a FieldHint rides the label line. See `hint`.\n const textHint = (typeof hint === \"string\" && hint !== \"\") || typeof hint === \"number\";\n const describedBy = textHint ? (ariaDescribedBy ? `${ariaDescribedBy} ${hintId}` : hintId) : ariaDescribedBy;\n const invalid = Boolean(invalidProp) || ariaInvalid === true || ariaInvalid === \"true\";\n const editable = !!onCurrencyChange;\n // On phones we suppress the OS keyboard (inputMode=\"none\" below) and show our\n // own calculator numpad, so the desktop popover trigger is hidden. The\n // end padding keys off showCalc, so it tightens up automatically.\n const isMobile = useMediaQuery(PHONE_QUERY, false);\n const showCalc = !disabled && !isMobile;\n const [focused, setFocused] = useState(false);\n // On mobile, focusing the field opens the numpad bottom sheet in place of the\n // native keyboard (feedback #334) — a full calculator keypad, not just the old\n // operator bar. An internal ref lets the sheet's \"Done\" blur the input, which\n // commits + closes via the existing onBlur handler.\n const showNumpad = isMobile && !disabled && focused;\n // Gate the display treatment on the SAME `isMobile` the numpad uses rather than\n // on `max-md:` classes, so the two can never drift apart on the breakpoint —\n // and so the two shapes are separate class strings instead of one string\n // fighting itself through responsive overrides. `useMediaQuery` reads\n // synchronously on mount, so there is no field→figure flash.\n const asDisplay = variant === \"display\" && isMobile;\n const innerRef = useRef<HTMLInputElement>(null);\n const setRefs = useCallback(\n (el: HTMLInputElement | null) => {\n innerRef.current = el;\n if (typeof ref === \"function\") ref(el);\n else if (ref) ref.current = el;\n },\n [ref],\n );\n // The sign is DISPLAYED, not stored (live #201 rework). `value` is the\n // magnitude; the minus is glued on here and taken off again in handleText, so\n // the two can never disagree and the caller can never double-apply it. Only in\n // front of a bare amount: an expression being typed (\"12-30\") owns its own\n // minus and has to survive keystroke-for-keystroke.\n const signOwned = onNegativeChange !== undefined;\n // The sign is DRAWN whenever `negative` says so, handler or not (keksdose live #366):\n // a read-only or disabled total (\"−5.18\") used to need a dummy `onNegativeChange`\n // just to show its minus. Without the handler there is nothing to toggle — a typed\n // minus simply stays in the text, as in any field without a direction control.\n const shown = negative && isBareAmount(value) ? `-${value}` : value;\n // What the user SEES is `shown` with the locale's decimal mark (kastlan 40: a\n // fr-CH user typed \"1,5\" and watched it turn into \"1.5\" under their fingers). Display only — `value`, `onChange`, the sign split and the settle all\n // stay dot-decimal, because that string is the contract: RhfMoneyField's\n // `parseAmount`, every app's `Number(value)` and the calculator's evaluator read\n // it. The way back is free: {@link sanitizeLive} already folds a typed \",\" into\n // \".\", so a comma typed, pasted or tapped on the numpad lands as a dot.\n //\n // One character for one character, and no digit grouping: the caret stays where\n // the typist put it, and \"1.000\" cannot be read back as a thousand in one locale\n // and as one in the other. de-CH and it-CH are \".\" — CLDR says so, and this\n // follows `Intl` rather than a guess about a country.\n const locale = useKitLocale();\n const mark = decimalMark(locale);\n // While the typist is typing, the field shows THEIR text (\"1.234,5\" stays exactly\n // that), not the value re-spelt: re-spelling turned a grouping \".\" into a \",\" under\n // their fingers, after which no rule could tell the two apart (keksdose G1). The\n // draft is shown only while it still spells what the field holds; a value set from\n // outside, a calculator result or a commit falls back to the derived spelling.\n const [draft, setDraft] = useState<string | null>(null);\n // A value the HOST set (not one typed here) is shown at the currency's minor unit\n // while the field is not being edited: an FX estimate of 93.4213 showed four\n // decimals (keksdose live #356). Display only — `value` is the host's, untouched.\n const displayDigits = digitsProp ?? currencyMinorDigits(currency);\n const resting = focused ? shown : settleAmount(shown, displayDigits);\n const derived = mark === \",\" ? resting.replace(/\\./g, \",\") : resting;\n const draftAs = draft === null ? \"\" : sanitizeLive(normalizeTypedMarks(draft, mark));\n const display =\n draft === null\n ? derived\n : draftAs === shown\n ? draft\n : // The caller owns the sign: the typed \"12\" is shown as the \"-12\" it is.\n signOwned && negative && `-${draftAs}` === shown\n ? `-${draft}`\n : derived;\n // Every route into the field — typing, the numpad sheet, the desktop\n // calculator, the blur/Enter commit — funnels through here, so the split is\n // written once and the four entry paths cannot drift.\n //\n // `previous` is the text this one REPLACES, and it is what says whether a bare\n // figure arriving here is an answer or a magnitude. For the three paths that\n // edit the field's own text that is simply what the field was showing; the\n // desktop calculator keeps its expression in a popover the field never sees,\n // so it passes it in (see `CalculatorButton`'s `onChange`).\n const digits = digitsProp ?? currencyMinorDigits(currency);\n const settle = (text: string) => settleAmount(text, digits, min, max);\n const handleText = (raw: string, previous: string = shown) => {\n const text = sanitizeLive(raw);\n if (!signOwned) {\n onChange(text);\n return;\n }\n const { sign, rest } = splitLeadingSign(text);\n if (sign) {\n // SET, not flip: re-reporting the same sign on every keystroke is a no-op.\n onNegativeChange(sign === \"-\");\n } else if (looksLikeExpression(previous) && isBareAmount(text) && isResultOf(previous, text, settle)) {\n // A calculation that just RESOLVED states its sign in both directions. The\n // figure it ran on is the SIGNED one the user could see — \"-12+30\" is +18 —\n // so a positive result has to move the chip too, or the field would answer\n // that sum with \"-18\" and contradict the arithmetic it just showed.\n //\n // Only when it really resolved, though: see {@link isResultOf}. A bare figure\n // arriving on top of an expression is far more often a replacement than an\n // answer, and reading it as an answer flips the direction of money.\n onNegativeChange(false);\n }\n onChange(sign ? rest : text);\n };\n const commit = () => {\n setDraft(null);\n const settled = settle(commitExpression(shown));\n handleText(settled);\n onCommit?.(settled);\n };\n const typed = (raw: string) => {\n setDraft(raw);\n handleText(normalizeTypedMarks(raw, mark));\n };\n const { open, setOpen, wrapperRef, panelRef, query, setQuery, inputRef } = useDropdownSearch();\n // The chip the currency list hangs off (Keksdose dev#548). It is portalled now, so\n // the panel needs a real trigger rect rather than a relative parent — see\n // `DropdownPanel`'s note for what an `overflow` ancestor did to it before.\n const chipRef = useRef<HTMLButtonElement>(null);\n\n // The currency chip's strings are the `currency` namespace — the same two\n // `CurrencySelect` resolves, under this component's older key names. The\n // calculator and the numpad resolve `calculator` themselves; `labels.calculator`\n // and `labels.pad` are handed straight through to them as overrides.\n const currencyOverrides = useMemo(() => {\n const out: Partial<CurrencyLabels> = {};\n if (labels?.currency !== undefined) out.currency = labels.currency;\n if (labels?.currencySearch !== undefined) out.search = labels.currencySearch;\n return out;\n }, [labels?.currency, labels?.currencySearch]);\n const currencyText = useKitLabels(\"currency\", DEFAULT_CURRENCY_LABELS, currencyOverrides);\n const common = useKitLabels(\"common\", DEFAULT_COMMON_LABELS);\n\n const selected = getCurrency(currency);\n const filtered = useMemo(() => {\n const q = query.trim().toLocaleLowerCase(locale);\n if (!q) return CURRENCIES;\n return CURRENCIES.filter(\n (c) =>\n c.code.toLowerCase().includes(q) ||\n // The name the row SHOWS, so a translated list is searchable in the\n // language it is written in.\n currencyName(c, currencyNames, locale).toLocaleLowerCase(locale).includes(q) ||\n c.symbol.toLowerCase().includes(q),\n );\n }, [query, currencyNames, locale]);\n\n return (\n <div ref={wrapperRef} className={cn(\"w-full\", className)}>\n {/* Inner relative box holds the input + its absolutely-positioned\n trailing controls (calculator / currency), so those stay anchored to\n the INPUT even when the mobile math bar is rendered below (#334). It is\n the kit's FloatingField, which draws the label — floating, or sr-only in\n the display shape — and puts a FieldHint on the label's line, as it does\n for NumberInput. */}\n <FloatingField\n className=\"w-full\"\n htmlFor={fieldId}\n label={label}\n srOnlyLabel={asDisplay}\n hint={textHint ? undefined : hint}\n >\n <input\n ref={setRefs}\n id={fieldId}\n aria-label={ariaLabel}\n type=\"text\"\n // eslint-disable-next-line jsx-a11y/no-autofocus -- opt-in per call site (feedback #70)\n autoFocus={autoFocus}\n // On mobile suppress the OS keyboard so our numpad sheet owns entry; the\n // field keeps focus/caret. Desktop keeps the native decimal keypad.\n inputMode={isMobile ? \"none\" : \"decimal\"}\n autoComplete=\"off\"\n disabled={disabled}\n // The floating-label pattern needs a blank placeholder for its\n // peer-placeholder-shown trick. The display shape has no floating label,\n // so it spends the placeholder on what an empty borderless form actually\n // needs: a zero to aim at, at full size. The caller supplies it because\n // only the app knows the locale's decimal separator.\n placeholder={asDisplay ? (placeholder ?? \"0\") : label !== undefined ? \" \" : placeholder}\n value={display}\n onChange={(e) => typed(e.target.value)}\n onFocus={() => setFocused(true)}\n onBlur={() => {\n commit();\n setFocused(false);\n }}\n onKeyDown={(e) => {\n if (e.key === \"Enter\") commit();\n }}\n className={cn(\n // With a label, use the floating-input padding (pt-4 pb-1) like every\n // other labelled field so the value sits BELOW the floated label rather\n // than vertically centred where it overlaps the resting label\n // (feedback #314). FLOATING_INPUT_CLASS already bundles the peer +\n // transparent-placeholder bits.\n asDisplay ? DISPLAY_INPUT_CLASS : label !== undefined ? FLOATING_INPUT_CLASS : FIELD_BASE,\n // Room for the trailing controls. showCalc is always false on a phone,\n // so the display shape only ever has to clear the currency chip — and\n // it clears it by the chip's actual width (a text-sm code plus a\n // chevron, ~58px) rather than the 5rem the boxed shape reserves. On a\n // 375px screen those 16px are the difference between a readable figure\n // and a clipped one (feedback #430 rework).\n asDisplay\n ? currency ? (editable ? \"pe-16\" : \"pe-12\") : \"pe-0\"\n : showCalc\n ? currency ? (editable ? \"pe-24\" : \"pe-16\") : \"pe-10\"\n : currency ? (editable ? \"pe-20\" : \"pe-14\") : \"pe-3\",\n // Centred display shape: centre in what is LEFT of the currency chip.\n // `text-center` alone would centre the figure in the whole box, i.e.\n // partly underneath the chip; the padding above is what takes the chip\n // out of the centring, and nothing is added at the start because a\n // mirrored reservation would spend the width twice (see `align`).\n asDisplay && align === \"center\" && \"text-center\",\n // Last, so it wins over the base class's own text colour.\n TONE_CLASS[tone],\n invalid && FIELD_INVALID,\n )}\n aria-invalid={invalid || undefined}\n aria-describedby={describedBy}\n aria-required={ariaRequired}\n />\n {/* The label is FloatingField's, after these children (the floating trick\n reads the input through `peer-*`). The display shape drops it VISUALLY,\n not from the accessibility tree: a 36px tinted figure at the top of a\n transaction form is legibly the amount, but a screen reader still needs\n the name, and callers that pass `label` without `ariaLabel` would\n otherwise be left with none. */}\n {/* Trailing controls share one flex track so the calculator icon and the\n currency suffix/picker sit side by side without overlapping. */}\n {/* The display shape has no box to inset from, so the controls align to the\n figure's own end edge and its baseline strip (`bottom-1`, matching the\n input's pb-1) instead of floating inside a field. */}\n <div\n className={cn(\n \"absolute flex items-center gap-0.5\",\n // Logical `end-*`: the chip and the calculator are the figure's trailing\n // controls, so a right-to-left form carries them on the left.\n asDisplay ? \"bottom-1 end-0\" : \"inset-y-1 end-1\",\n )}\n >\n {showCalc && (\n <CalculatorButton\n // The mark the field shows, as NumberInput hands its calculator; the\n // evaluator reads either, and its result comes back dot-decimal.\n value={display}\n onChange={(result, expression) => {\n setDraft(null);\n const settled = settle(result);\n handleText(settled, expression);\n onCommit?.(settled);\n }}\n className=\"px-1.5\"\n ariaLabel={labels?.calculatorTrigger}\n labels={labels?.calculator}\n />\n )}\n {currency && !editable && (\n <span\n aria-hidden\n className={cn(\n \"pointer-events-none px-1 font-medium text-[var(--text-muted)]\",\n // A text-xs chip next to a 36px figure reads as a stray footnote.\n asDisplay ? \"text-sm\" : \"text-xs\",\n )}\n >\n {currency}\n </span>\n )}\n {currency && editable && (\n <button\n ref={chipRef}\n type=\"button\"\n onClick={() => setOpen((v) => !v)}\n aria-label={\n // \"Currency: EUR\" through `common.fieldValue`, not a template literal:\n // the colon-and-space is punctuation a translation has to own.\n selected ? common.fieldValue(currencyText.currency, selected.code) : currencyText.currency\n }\n className={cn(\n \"flex items-center gap-1 rounded px-2 py-1 font-medium text-[var(--text-secondary)] hover:bg-[var(--bg-hover)]\",\n asDisplay ? \"text-sm\" : \"text-xs\",\n )}\n >\n {currency}\n <ChevronDown className=\"size-3\" />\n </button>\n )}\n </div>\n {editable && open && (\n <DropdownPanel\n anchorRef={chipRef}\n panelRef={panelRef}\n empty={filtered.length === 0}\n header={\n <DropdownSearchHeader\n query={query}\n onQueryChange={setQuery}\n inputRef={inputRef}\n placeholder={currencyText.search}\n />\n }\n >\n {filtered.map((c) => {\n const active = c.code === selected?.code;\n return (\n <li key={c.code}>\n <button\n type=\"button\"\n onClick={() => {\n onCurrencyChange?.(c.code);\n setOpen(false);\n }}\n className={cn(\n \"flex w-full items-center gap-2 px-3 py-1.5 text-sm text-start hover:bg-[var(--bg-hover)]\",\n active && \"bg-[var(--bg-active)]\",\n )}\n >\n <CurrencyFlag country={c.country} />\n <span className=\"font-mono text-[var(--text-muted)] w-8 shrink-0 text-xs\">\n {c.symbol}\n </span>\n <span className=\"font-medium text-[var(--text-primary)]\">{c.code}</span>\n <span className=\"text-[var(--text-muted)] truncate text-xs\">{currencyName(c, currencyNames, locale)}</span>\n </button>\n </li>\n );\n })}\n </DropdownPanel>\n )}\n </FloatingField>\n {/* Outside the relative box, as NumberInput's caption is: the trailing\n controls are `inset-y-1` in it and would stretch down over a second line. */}\n {textHint && (\n <p id={hintId} className=\"mt-1 text-[11px] leading-tight text-[var(--text-muted)]\">\n {hint}\n </p>\n )}\n {showNumpad && (\n <NumberPadSheet\n // Localised like the field it mirrors. Keys are typing, read by the\n // locale's marks like the keyboard's; \"=\" is a result, dot-decimal.\n value={display}\n onChange={typed}\n onResult={(result) => {\n setDraft(null);\n const settled = settle(result);\n handleText(settled);\n onCommit?.(settled);\n }}\n onDone={() => innerRef.current?.blur()}\n label={label}\n labels={labels?.pad}\n decimalMark={mark}\n />\n )}\n </div>\n );\n },\n);\n\nAmountInput.displayName = \"AmountInput\";\n"],"mappings":";AAseQ,cA4GI,YA5GJ;AAteR,SAAS,YAAY,aAAa,OAAO,SAAS,QAAQ,gBAAgB;AAC1E,SAAS,mBAAmB;AAE5B,SAAS,YAAY,cAAc,cAAc,mBAAmB;AACpE,SAAS,YAAY,eAAe,eAAe,sBAAsB,eAAe,mBAAmB;AAC3G,SAAS,UAAU;AACnB,SAAS,2BAA2B;AACpC,SAAS,qBAAqB;AAC9B,SAAS,wBAAqD;AAC9D,SAAS,sBAAiD;AAC1D,SAAS,eAAe,sBAAsB,yBAAyB;AACvE;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAwLP,SAAS,aAAa,MAAc,QAA4B,KAAc,KAAsB;AAClG,QAAM,IAAI,KAAK,KAAK;AACpB,MAAI,CAAC,gBAAgB,KAAK,CAAC,KAAK,CAAC,KAAK,KAAK,CAAC,EAAG,QAAO;AACtD,MAAI,IAAI,OAAO,CAAC;AAChB,MAAI,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AA,MAGC,YACC,oBAAC,OAAE,IAAI,QAAQ,WAAU,2DACtB,gBACH;AAAA,MAED,cACC;AAAA,QAAC;AAAA;AAAA,UAGC,OAAO;AAAA,UACP,UAAU;AAAA,UACV,UAAU,CAAC,WAAW;AACpB,qBAAS,IAAI;AACb,kBAAM,UAAU,OAAO,MAAM;AAC7B,uBAAW,OAAO;AAClB,uBAAW,OAAO;AAAA,UACpB;AAAA,UACA,QAAQ,MAAM,SAAS,SAAS,KAAK;AAAA,UACrC;AAAA,UACA,QAAQ,QAAQ;AAAA,UAChB,aAAa;AAAA;AAAA,MACf;AAAA,OAEJ;AAAA,EAEJ;AACF;AAEA,YAAY,cAAc;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/components/amount-input.tsx"],"sourcesContent":["import { forwardRef, useCallback, useId, useMemo, useRef, useState } from \"react\";\nimport { ChevronDown } from \"lucide-react\";\nimport type { ReactNode } from \"react\";\nimport { CURRENCIES, CurrencyFlag, currencyName, getCurrency } from \"./currency-select\";\nimport { FIELD_BASE, FIELD_DISPLAY, FIELD_INVALID, FLOATING_INPUT_CLASS, FloatingField, PHONE_QUERY } from \"./ui\";\nimport { cn } from \"../lib/cn\";\nimport { currencyMinorDigits } from \"../lib/format\";\nimport { useMediaQuery } from \"../hooks/use-media-query\";\nimport { CalculatorButton, type CalculatorButtonLabels } from \"./calculator\";\nimport { NumberPadSheet, type NumberPadSheetLabels } from \"./numpad-sheet\";\nimport { DropdownPanel, DropdownSearchHeader, useDropdownSearch } from \"./dropdown\";\nimport {\n DEFAULT_COMMON_LABELS,\n DEFAULT_CURRENCY_LABELS,\n useKitLabels,\n useKitLocale,\n type CurrencyLabels,\n} from \"../i18n/kit-labels\";\nimport {\n commitExpression,\n evaluateExpression,\n formatResult,\n isBareAmount,\n looksLikeExpression,\n sanitizeLive,\n splitLeadingSign,\n} from \"../lib/calc\";\nimport { decimalMark, localizeMark, readTyped, showsTyped } from \"../lib/decimal-marks\";\nimport { hasMessage, mergeDescribedBy } from \"./choice-parts\";\n\ninterface AmountInputProps {\n value: string;\n onChange: (value: string) => void;\n currency?: string;\n onCurrencyChange?: (code: string) => void;\n placeholder?: string;\n label?: ReactNode;\n disabled?: boolean;\n /** Required and unanswered — {@link FIELD_INVALID}. See {@link Input}'s `invalid`. */\n invalid?: boolean;\n /**\n * What is wrong with the amount, in the caller's own words — {@link Input}'s `error`\n * (keksdose K4: \"exceeds the outstanding balance\" was a loose `<p>` beside the field\n * that nothing pointed at). Rendered under the field, after a text `hint`; merged into\n * `aria-describedby` after the caller's ids and the hint's; implies `invalid`, so the\n * field paints as well as announces. `null`, `false` and `\"\"` are no message.\n * {@link MoneyField} takes it too.\n */\n error?: ReactNode;\n /**\n * Show the desktop calculator trigger (default `true`). `false` for an amount in an\n * ephemeral close-on-blur editor — a budget's assigned cell, a VAT cell (keksdose K6)\n * — where a click on the icon blurs the field and tears the editor down before the\n * popover can open. Typing a calculation (\"200+50\", then Enter) still evaluates, and\n * a phone keeps its numpad, exactly as {@link NumberInput}'s `calculator={false}`.\n */\n calculator?: boolean;\n /** The field's WRAPPER — width, a margin, a flex share. The `<input>` is\n * `inputClassName`'s. */\n className?: string;\n /**\n * Classes for the `<input>` itself — {@link NumberInput}'s and {@link Input}'s prop of\n * the same name, merged the same way: after the field's own base classes, so it can\n * restyle the figure (`text-end` for a money column whose decimal points line up,\n * `font-medium`, a tighter `py-1` in a table cell), and before the end padding the\n * calculator and the currency chip reserve and before the invalid border, so neither\n * can be taken away by accident.\n *\n * keksdose G7: the invoice's VAT cell right-aligns its figure, and with only\n * `className` (the wrapper) it reached the element through `[&_input]:text-end` — a\n * descendant selector that depends on the field's inner markup, which the kit is free\n * to change, and that a reader of the call site has to decode. {@link MoneyField}\n * passes it through, and `RhfMoneyField` takes it too.\n */\n inputClassName?: string;\n id?: string;\n ariaLabel?: string;\n /**\n * Set on the `<input>`, with `id` above. Declared so `Field`'s render-prop spread —\n * `{(ids) => <AmountInput {...ids} … />}` — is typed and reaches the input: the\n * hint and error are described, a required amount is announced as required, and\n * `aria-invalid` paints {@link FIELD_INVALID} the way `invalid` does.\n */\n \"aria-describedby\"?: string;\n \"aria-invalid\"?: boolean | \"true\" | \"false\";\n \"aria-required\"?: boolean | \"true\" | \"false\";\n /** {@link NumberInput}'s `hint`, the same rule: a {@link FieldHint} \"?\" rides the\n * label's own line, beside the label (not at the far end, where the calculator and\n * the currency chip live); plain TEXT (a string or a number) is a caption UNDER\n * the field, attached through `aria-describedby` after the caller's own. A phone's\n * `variant=\"display\"` has no visible label, so a FieldHint is dropped there; a\n * caption still shows. */\n hint?: ReactNode;\n /** Every user-facing string this component and the two it composes own, so a\n * translating host can supply its own. Each key optional, and each a per-field\n * override of the kit-wide translation in `<UiKitProvider labels>`: `currency`\n * and `currencySearch` of its `currency` namespace, the rest of `calculator`.\n * `currency` names the picker chip, composed with the selected code through\n * `common.fieldValue`; the rest are pass-through. */\n labels?: {\n currency?: string;\n currencySearch?: string;\n /** Names the calculator TRIGGER this component renders. `calculator` below\n * names the controls inside the popover it opens. */\n calculatorTrigger?: string;\n pad?: NumberPadSheetLabels;\n calculator?: CalculatorButtonLabels;\n };\n /** Translated currency names for the chip's picker, keyed by ISO code. The same\n * sparse override `CurrencySelect` takes, and for the same reason: the names in\n * `CURRENCIES` are shipped data, so without this they are the one English word\n * left in a translated row. Not part of `labels` because it is keyed by DATA\n * rather than by a fixed set of slots, and an app passes the same map to both\n * pickers. */\n currencyNames?: Record<string, string>;\n /** Focus the field on mount — on mobile this also opens the numpad sheet, so a\n * new-transaction form can jump straight to amount entry (feedback #70). */\n autoFocus?: boolean;\n /**\n * Tint the typed figure by what it will DO (Keksdose feedback #167).\n *\n * The direction is chosen with a toggle beside the field rather than typed, so\n * the digits alone say nothing about which way the money goes — on the one screen\n * where getting that backwards is the expensive mistake. Colour says it\n * continuously, and it costs no layout. It stays the MAIN indication (live #201\n * rework: *\"The main indication shall still be the color\"*); {@link negative}\n * renders the sign as a second, quieter signal in front of the figure.\n *\n * Never the ONLY signal: the toggle it mirrors is right there, labelled, so this\n * is reinforcement rather than the sole carrier of the meaning.\n */\n tone?: \"neutral\" | \"outflow\" | \"inflow\";\n /**\n * The SIGN of the figure, owned by the caller's direction control (Keksdose live\n * #201 rework: *\"Outflow should be negative and inflow positive … the sign shall\n * be displayed but not necessarily be typed in\"*).\n *\n * `value` stays the MAGNITUDE. The minus is glued on at render time and stripped\n * off again before anything is reported back, so the caller never sees its own\n * prefix echoed and no code path can end up applying it twice. That is the whole\n * cure: there is exactly ONE place the sign lives, and it is not the text.\n *\n * Because it is rendered rather than stored it cannot be deleted (the next render\n * puts it back), a select-all-and-retype keeps the direction, and the caret needs\n * no minding.\n *\n * Since 0.15.5 it is drawn on its own too, for a read-only or disabled signed figure\n * (an \"Items total\" of −5.18): no `onNegativeChange` needed just to show the minus.\n */\n negative?: boolean;\n /**\n * A sign the user TYPED, or a calculation that resolved to a signed number.\n *\n * SET, never flip. A \"-\" means *\"this is an outflow\"*, so typing it twice says the\n * same thing twice — which is exactly what the rework asks for (*\"Subtracting\n * values twice resulting in inflow -> outflow and back to inflow seems not\n * reasonable\"*). \"+\" says the other direction.\n *\n * Its presence is what ARMS the whole sign behaviour. A field with no direction\n * control — an account's starting balance, a loan payment, a holding's cost —\n * passes neither prop and keeps a text that is the whole truth, minus included.\n */\n onNegativeChange?: (negative: boolean) => void;\n /**\n * How the field presents itself ON A PHONE (Keksdose feedback #176).\n *\n * `\"field\"` (default) is the labelled, bordered input used everywhere else.\n *\n * `\"display\"` keeps every mechanic — the same `<input>`, the same numpad sheet,\n * the same currency picker, the same commit/blur contract — and only drops the\n * chrome: no border, no fill, no floating label, the figure set at display size.\n * On a form whose whole point is one number, a bordered `text-sm` box draws the\n * amount at the same weight as the memo beside it; this makes it the headline\n * instead. It stays fully editable — the underline and the caret are what say so.\n *\n * Phone-only by construction: it keys off the same breakpoint as the numpad, so\n * from `md` up the field is byte-for-byte the normal one and a desktop grid keeps\n * its column rhythm.\n */\n variant?: \"field\" | \"display\";\n /**\n * Where the figure sits in its row, for `variant=\"display\"` only (Keksdose\n * feedback #176 rework).\n *\n * `\"start\"` (default) keeps it flush left, in the reading column the fields\n * below it share — and it is what the entry forms use, because a figure that\n * starts at a known edge is legible at any width: when the value outgrows the\n * field, the digits that scroll out of sight are the trailing ones, not the\n * magnitude (Keksdose feedback #430 rework).\n *\n * `\"center\"` makes it a centred headline. It centres in the width that REMAINS\n * after the trailing currency control, not in the whole box: the control is\n * pinned to the right edge, so a plain `text-center` would centre the figure\n * under it and the last digits would sit behind the chip. This used to mirror\n * the control's reservation onto the left instead, which centred correctly but\n * spent twice the control's width on padding — fatal on a 375px screen, where\n * it left a 36px figure 16px to live in.\n */\n align?: \"start\" | \"center\";\n /**\n * Decimals the committed amount is rounded to (kastlan 0.12: \"12.345\" and a\n * calculator's \"100/3\" reached a `Numeric(10,2)` column unrounded and failed with a\n * 422). Default: the currency's minor unit, from `Intl` (CHF and EUR 2, JPY 0). With\n * no `currency`, nothing is rounded unless this is set. Rounding is half away from\n * zero (12.345 → 12.35, -12.345 → -12.35) and happens when the figure settles: on\n * blur, on Enter, and on every result the calculator writes back. Keystrokes are left\n * alone, so \"12.3\" can still become \"12.34\".\n *\n * ⚠️ **A unit price or a rate needs `digits`.** The default is right for an amount of\n * money and silently wrong for a price per unit: a fund's NAV of 123.4567 or fuel at\n * 1.789 €/l is stored as 123.46 / 1.79, and no test fails (keksdose G2, a\n * `Numeric(18,6)` holding price and a `Numeric(18,4)` unit price). Pass the column's\n * scale: `digits={4}`, `digits={6}`.\n *\n * **Set `digits` for any sub-currency scale** — not only a price: any field whose\n * column holds more decimals than the currency's minor unit. A split line stored at\n * the ledger's 4dp (`Numeric(18,4)`) and loaded as 12.3456 is SHOWN as 12.35, and\n * committed as 12.35 as soon as the user tabs through it (blur settles) — so the form\n * no longer equals what the server holds: the lines stop summing to the 4dp total,\n * and Save is held (keksdose live #240). With a `currency`, every commit rounds to that currency's\n * minor unit unless `digits` says otherwise: pass the column's scale (`digits={4}`).\n */\n digits?: number;\n /** The smallest amount the field settles on. A lower figure is raised to it when it\n * settles, like `digits`. Compared with the signed figure. */\n min?: number;\n /** The largest amount the field settles on (a deposit release capped at the\n * balance). A higher figure is lowered to it when it settles. */\n max?: number;\n /**\n * The SETTLED figure, dot-decimal, sign included — fired on blur, on Enter, on the\n * numpad's \"=\" and on every result the calculator writes back, never on a keystroke\n * (\"1200+\" is not a figure yet). `onChange` still reports every keystroke; this is\n * for a host that stores a number and must not see drafts (kastlan 52; see\n * {@link MoneyField}, which is built on it).\n */\n onCommit?: (value: string) => void;\n}\n\n\n/**\n * A settled figure, rounded to `digits` (half away from zero) and clamped to\n * `min`/`max`. Only a plain number is touched. A half-typed draft or an expression\n * comes back as it was. Rounding works in decimal exponent notation, because\n * `Math.round(1.005 * 100)` is 100 (1.005 is 1.00499… in binary).\n */\nfunction settleAmount(text: string, digits: number | undefined, min?: number, max?: number): string {\n const t = text.trim();\n if (!/^-?\\d*\\.?\\d*$/.test(t) || !/\\d/.test(t)) return text;\n let n = Number(t);\n if (!Number.isFinite(n)) return text;\n if (digits !== undefined) {\n const magnitude = Number(`${Math.round(Number(`${Math.abs(n)}e${digits}`))}e-${digits}`);\n n = n < 0 ? -magnitude : magnitude;\n }\n if (min !== undefined && n < min) n = min;\n if (max !== undefined && n > max) n = max;\n const out = formatResult(n);\n // Unchanged figures keep their own spelling (\"12.50\" stays \"12.50\").\n return Number(out) === Number(t) ? text : out;\n}\n\n// The locale's decimal mark and the grouping parse (kastlan 40, keksdose G1) live in\n// `lib/decimal-marks.ts`, shared with NumberInput since 0.22 (keksdose K5).\n\n// The error line under a field — the type of `ui.tsx`'s (module-private) one, so an\n// AmountInput's message is indistinguishable from an Input's.\nconst FIELD_ERROR_CLASS = \"mt-1 text-[11px] leading-tight text-[var(--danger)]\";\n\n// The consuming app's ONE money palette (`--money-expense` / `--money-income`),\n// not a bespoke rose/emerald pairing: a figure being typed has to wear the same\n// colour the same figure will wear once it is a row in the table behind the form\n// (Keksdose dev#434). The utilities are unlayered and theme-aware, so no `dark:`\n// variant is needed and they win over the field's own text colour regardless of\n// where `cn` puts them.\nconst TONE_CLASS: Record<\"neutral\" | \"outflow\" | \"inflow\", string> = {\n neutral: \"\",\n outflow: \"text-money-neg\",\n inflow: \"text-money-pos\",\n};\n\n// The shared chrome-less treatment at money size. `tabular-nums` so digits don't\n// reflow the figure as they are typed; FIELD_DISPLAY's own muted placeholder\n// colour is what keeps an EMPTY form from painting its zero in the direction tint\n// (`tone` is computed from 0, which reads as an inflow).\nconst DISPLAY_INPUT_CLASS = cn(\n FIELD_DISPLAY,\n \"text-4xl font-semibold leading-tight tracking-tight tabular-nums\",\n);\n\n/**\n * Is `text` the ANSWER to `previous`, or something typed OVER it?\n *\n * \"The old text was a sum and the new one is bare\" cannot tell those apart, and both\n * gestures are ordinary: select-all-and-retype after a typo, or backspacing \"-20+\"\n * back down to a fresh figure. Read as an answer, they move the direction chip — so\n * an outflow of 7 quietly booked +7.00 (live #201 rework).\n *\n * The question that does separate them is arithmetic, not shape: evaluate what the\n * text replaced and see whether this IS that number. \"-12+30\" → \"18\" still is, so a\n * sum that comes out positive still takes the chip with it; \"-20+50\" → \"7\" is not,\n * and \"-20+\" evaluates to nothing at all.\n */\nfunction isResultOf(previous: string, text: string, settle: (text: string) => string): boolean {\n const n = evaluateExpression(previous);\n // Compared settled, since the field rounds what the calculator hands it.\n return n !== null && settle(formatResult(n)) === text.trim();\n}\n\nexport const AmountInput = forwardRef<HTMLInputElement, AmountInputProps>(\n ({ value, onChange, currency, onCurrencyChange, placeholder, label, disabled, invalid: invalidProp, error, calculator = true, className, inputClassName, id, ariaLabel, \"aria-describedby\": ariaDescribedBy, \"aria-invalid\": ariaInvalid, \"aria-required\": ariaRequired, hint, autoFocus, tone = \"neutral\", negative = false, onNegativeChange, variant = \"field\", align = \"start\", labels, currencyNames, digits: digitsProp, min, max, onCommit }, ref) => {\n const generatedId = useId();\n const fieldId = id ?? generatedId;\n const hintId = useId();\n const errorId = useId();\n // Text is a caption under the field; a FieldHint rides the label line. See `hint`.\n const textHint = (typeof hint === \"string\" && hint !== \"\") || typeof hint === \"number\";\n const hasError = hasMessage(error);\n // The standing advice first, the news second: the caller's ids, the caption, the error.\n const describedBy = mergeDescribedBy(ariaDescribedBy, textHint && hintId, hasError && errorId);\n const invalid = Boolean(invalidProp) || hasError || ariaInvalid === true || ariaInvalid === \"true\";\n const editable = !!onCurrencyChange;\n // On phones we suppress the OS keyboard (inputMode=\"none\" below) and show our\n // own calculator numpad, so the desktop popover trigger is hidden. The\n // end padding keys off showCalc, so it tightens up automatically.\n const isMobile = useMediaQuery(PHONE_QUERY, false);\n const showCalc = calculator && !disabled && !isMobile;\n const [focused, setFocused] = useState(false);\n // On mobile, focusing the field opens the numpad bottom sheet in place of the\n // native keyboard (feedback #334) — a full calculator keypad, not just the old\n // operator bar. An internal ref lets the sheet's \"Done\" blur the input, which\n // commits + closes via the existing onBlur handler.\n const showNumpad = isMobile && !disabled && focused;\n // Gate the display treatment on the SAME `isMobile` the numpad uses rather than\n // on `max-md:` classes, so the two can never drift apart on the breakpoint —\n // and so the two shapes are separate class strings instead of one string\n // fighting itself through responsive overrides. `useMediaQuery` reads\n // synchronously on mount, so there is no field→figure flash.\n const asDisplay = variant === \"display\" && isMobile;\n const innerRef = useRef<HTMLInputElement>(null);\n const setRefs = useCallback(\n (el: HTMLInputElement | null) => {\n innerRef.current = el;\n if (typeof ref === \"function\") ref(el);\n else if (ref) ref.current = el;\n },\n [ref],\n );\n // The sign is DISPLAYED, not stored (live #201 rework). `value` is the\n // magnitude; the minus is glued on here and taken off again in handleText, so\n // the two can never disagree and the caller can never double-apply it. Only in\n // front of a bare amount: an expression being typed (\"12-30\") owns its own\n // minus and has to survive keystroke-for-keystroke.\n const signOwned = onNegativeChange !== undefined;\n // The sign is DRAWN whenever `negative` says so, handler or not (keksdose live #366):\n // a read-only or disabled total (\"−5.18\") used to need a dummy `onNegativeChange`\n // just to show its minus. Without the handler there is nothing to toggle — a typed\n // minus simply stays in the text, as in any field without a direction control.\n const shown = negative && isBareAmount(value) ? `-${value}` : value;\n // What the user SEES is `shown` with the locale's decimal mark (kastlan 40: a\n // fr-CH user typed \"1,5\" and watched it turn into \"1.5\" under their fingers). Display only — `value`, `onChange`, the sign split and the settle all\n // stay dot-decimal, because that string is the contract: RhfMoneyField's\n // `parseAmount`, every app's `Number(value)` and the calculator's evaluator read\n // it. The way back is free: {@link sanitizeLive} already folds a typed \",\" into\n // \".\", so a comma typed, pasted or tapped on the numpad lands as a dot.\n //\n // One character for one character, and no digit grouping: the caret stays where\n // the typist put it, and \"1.000\" cannot be read back as a thousand in one locale\n // and as one in the other. de-CH and it-CH are \".\" — CLDR says so, and this\n // follows `Intl` rather than a guess about a country.\n const locale = useKitLocale();\n const mark = decimalMark(locale);\n // While the typist is typing, the field shows THEIR text (\"1.234,5\" stays exactly\n // that), not the value re-spelt: re-spelling turned a grouping \".\" into a \",\" under\n // their fingers, after which no rule could tell the two apart (keksdose G1). The\n // draft is shown only while it still spells what the field holds; a value set from\n // outside, a calculator result or a commit falls back to the derived spelling.\n const [draft, setDraft] = useState<string | null>(null);\n // A value the HOST set (not one typed here) is shown at the currency's minor unit\n // while the field is not being edited: an FX estimate of 93.4213 showed four\n // decimals (keksdose live #356). Display only — `value` is the host's, untouched.\n const displayDigits = digitsProp ?? currencyMinorDigits(currency);\n const resting = focused ? shown : settleAmount(shown, displayDigits);\n const derived = localizeMark(resting, mark);\n // The draft only while it says what the field holds AND holds nothing the live\n // sanitising would drop — a letter, a second decimal point — which would otherwise\n // stay on screen while the value said something else (see `showsTyped`).\n const display =\n draft === null\n ? derived\n : showsTyped(draft, mark, shown)\n ? draft\n : // The caller owns the sign: the typed \"12\" is shown as the \"-12\" it is.\n signOwned && negative && shown.startsWith(\"-\") && showsTyped(draft, mark, shown.slice(1))\n ? `-${draft}`\n : derived;\n // Every route into the field — typing, the numpad sheet, the desktop\n // calculator, the blur/Enter commit — funnels through here, so the split is\n // written once and the four entry paths cannot drift.\n //\n // `previous` is the text this one REPLACES, and it is what says whether a bare\n // figure arriving here is an answer or a magnitude. For the three paths that\n // edit the field's own text that is simply what the field was showing; the\n // desktop calculator keeps its expression in a popover the field never sees,\n // so it passes it in (see `CalculatorButton`'s `onChange`).\n const digits = digitsProp ?? currencyMinorDigits(currency);\n const settle = (text: string) => settleAmount(text, digits, min, max);\n const handleText = (raw: string, previous: string = shown) => {\n const text = sanitizeLive(raw);\n if (!signOwned) {\n onChange(text);\n return;\n }\n const { sign, rest } = splitLeadingSign(text);\n if (sign) {\n // SET, not flip: re-reporting the same sign on every keystroke is a no-op.\n onNegativeChange(sign === \"-\");\n } else if (looksLikeExpression(previous) && isBareAmount(text) && isResultOf(previous, text, settle)) {\n // A calculation that just RESOLVED states its sign in both directions. The\n // figure it ran on is the SIGNED one the user could see — \"-12+30\" is +18 —\n // so a positive result has to move the chip too, or the field would answer\n // that sum with \"-18\" and contradict the arithmetic it just showed.\n //\n // Only when it really resolved, though: see {@link isResultOf}. A bare figure\n // arriving on top of an expression is far more often a replacement than an\n // answer, and reading it as an answer flips the direction of money.\n onNegativeChange(false);\n }\n onChange(sign ? rest : text);\n };\n const commit = () => {\n setDraft(null);\n const settled = settle(commitExpression(shown));\n handleText(settled);\n onCommit?.(settled);\n };\n const typed = (raw: string) => {\n setDraft(raw);\n handleText(readTyped(raw, mark));\n };\n const { open, setOpen, wrapperRef, panelRef, query, setQuery, inputRef } = useDropdownSearch();\n // The chip the currency list hangs off (Keksdose dev#548). It is portalled now, so\n // the panel needs a real trigger rect rather than a relative parent — see\n // `DropdownPanel`'s note for what an `overflow` ancestor did to it before.\n const chipRef = useRef<HTMLButtonElement>(null);\n\n // The currency chip's strings are the `currency` namespace — the same two\n // `CurrencySelect` resolves, under this component's older key names. The\n // calculator and the numpad resolve `calculator` themselves; `labels.calculator`\n // and `labels.pad` are handed straight through to them as overrides.\n const currencyOverrides = useMemo(() => {\n const out: Partial<CurrencyLabels> = {};\n if (labels?.currency !== undefined) out.currency = labels.currency;\n if (labels?.currencySearch !== undefined) out.search = labels.currencySearch;\n return out;\n }, [labels?.currency, labels?.currencySearch]);\n const currencyText = useKitLabels(\"currency\", DEFAULT_CURRENCY_LABELS, currencyOverrides);\n const common = useKitLabels(\"common\", DEFAULT_COMMON_LABELS);\n\n const selected = getCurrency(currency);\n const filtered = useMemo(() => {\n const q = query.trim().toLocaleLowerCase(locale);\n if (!q) return CURRENCIES;\n return CURRENCIES.filter(\n (c) =>\n c.code.toLowerCase().includes(q) ||\n // The name the row SHOWS, so a translated list is searchable in the\n // language it is written in.\n currencyName(c, currencyNames, locale).toLocaleLowerCase(locale).includes(q) ||\n c.symbol.toLowerCase().includes(q),\n );\n }, [query, currencyNames, locale]);\n\n return (\n <div ref={wrapperRef} className={cn(\"w-full\", className)}>\n {/* Inner relative box holds the input + its absolutely-positioned\n trailing controls (calculator / currency), so those stay anchored to\n the INPUT even when the mobile math bar is rendered below (#334). It is\n the kit's FloatingField, which draws the label — floating, or sr-only in\n the display shape — and puts a FieldHint on the label's line, as it does\n for NumberInput. */}\n <FloatingField\n className=\"w-full\"\n htmlFor={fieldId}\n label={label}\n srOnlyLabel={asDisplay}\n hint={textHint ? undefined : hint}\n >\n <input\n ref={setRefs}\n id={fieldId}\n aria-label={ariaLabel}\n type=\"text\"\n // eslint-disable-next-line jsx-a11y/no-autofocus -- opt-in per call site (feedback #70)\n autoFocus={autoFocus}\n // On mobile suppress the OS keyboard so our numpad sheet owns entry; the\n // field keeps focus/caret. Desktop keeps the native decimal keypad.\n inputMode={isMobile ? \"none\" : \"decimal\"}\n autoComplete=\"off\"\n disabled={disabled}\n // The floating-label pattern needs a blank placeholder for its\n // peer-placeholder-shown trick. The display shape has no floating label,\n // so it spends the placeholder on what an empty borderless form actually\n // needs: a zero to aim at, at full size. The caller supplies it because\n // only the app knows the locale's decimal separator.\n placeholder={asDisplay ? (placeholder ?? \"0\") : label !== undefined ? \" \" : placeholder}\n value={display}\n onChange={(e) => typed(e.target.value)}\n onFocus={() => setFocused(true)}\n onBlur={() => {\n commit();\n setFocused(false);\n }}\n onKeyDown={(e) => {\n if (e.key === \"Enter\") commit();\n }}\n className={cn(\n // With a label, use the floating-input padding (pt-4 pb-1) like every\n // other labelled field so the value sits BELOW the floated label rather\n // than vertically centred where it overlaps the resting label\n // (feedback #314). FLOATING_INPUT_CLASS already bundles the peer +\n // transparent-placeholder bits.\n asDisplay ? DISPLAY_INPUT_CLASS : label !== undefined ? FLOATING_INPUT_CLASS : FIELD_BASE,\n // The caller's, over the base and under everything below (see `inputClassName`).\n inputClassName,\n // Room for the trailing controls. showCalc is always false on a phone,\n // so the display shape only ever has to clear the currency chip — and\n // it clears it by the chip's actual width (a text-sm code plus a\n // chevron, ~58px) rather than the 5rem the boxed shape reserves. On a\n // 375px screen those 16px are the difference between a readable figure\n // and a clipped one (feedback #430 rework).\n asDisplay\n ? currency ? (editable ? \"pe-16\" : \"pe-12\") : \"pe-0\"\n : showCalc\n ? currency ? (editable ? \"pe-24\" : \"pe-16\") : \"pe-10\"\n : currency ? (editable ? \"pe-20\" : \"pe-14\") : \"pe-3\",\n // Centred display shape: centre in what is LEFT of the currency chip.\n // `text-center` alone would centre the figure in the whole box, i.e.\n // partly underneath the chip; the padding above is what takes the chip\n // out of the centring, and nothing is added at the start because a\n // mirrored reservation would spend the width twice (see `align`).\n asDisplay && align === \"center\" && \"text-center\",\n // Last, so it wins over the base class's own text colour.\n TONE_CLASS[tone],\n invalid && FIELD_INVALID,\n )}\n aria-invalid={invalid || undefined}\n aria-describedby={describedBy}\n aria-required={ariaRequired}\n />\n {/* The label is FloatingField's, after these children (the floating trick\n reads the input through `peer-*`). The display shape drops it VISUALLY,\n not from the accessibility tree: a 36px tinted figure at the top of a\n transaction form is legibly the amount, but a screen reader still needs\n the name, and callers that pass `label` without `ariaLabel` would\n otherwise be left with none. */}\n {/* Trailing controls share one flex track so the calculator icon and the\n currency suffix/picker sit side by side without overlapping. */}\n {/* The display shape has no box to inset from, so the controls align to the\n figure's own end edge and its baseline strip (`bottom-1`, matching the\n input's pb-1) instead of floating inside a field. */}\n <div\n className={cn(\n \"absolute flex items-center gap-0.5\",\n // Logical `end-*`: the chip and the calculator are the figure's trailing\n // controls, so a right-to-left form carries them on the left.\n asDisplay ? \"bottom-1 end-0\" : \"inset-y-1 end-1\",\n )}\n >\n {showCalc && (\n <CalculatorButton\n // The mark the field shows but not the typist's grouping: the evaluator\n // reads either mark, and \"1.234,5\" is two of them. The result comes back\n // dot-decimal.\n value={derived}\n onChange={(result, expression) => {\n setDraft(null);\n const settled = settle(result);\n handleText(settled, expression);\n onCommit?.(settled);\n }}\n className=\"px-1.5\"\n ariaLabel={labels?.calculatorTrigger}\n labels={labels?.calculator}\n />\n )}\n {currency && !editable && (\n <span\n aria-hidden\n className={cn(\n \"pointer-events-none px-1 font-medium text-[var(--text-muted)]\",\n // A text-xs chip next to a 36px figure reads as a stray footnote.\n asDisplay ? \"text-sm\" : \"text-xs\",\n )}\n >\n {currency}\n </span>\n )}\n {currency && editable && (\n <button\n ref={chipRef}\n type=\"button\"\n onClick={() => setOpen((v) => !v)}\n aria-label={\n // \"Currency: EUR\" through `common.fieldValue`, not a template literal:\n // the colon-and-space is punctuation a translation has to own.\n selected ? common.fieldValue(currencyText.currency, selected.code) : currencyText.currency\n }\n className={cn(\n \"flex items-center gap-1 rounded px-2 py-1 font-medium text-[var(--text-secondary)] hover:bg-[var(--bg-hover)]\",\n asDisplay ? \"text-sm\" : \"text-xs\",\n )}\n >\n {currency}\n <ChevronDown className=\"size-3\" />\n </button>\n )}\n </div>\n {editable && open && (\n <DropdownPanel\n anchorRef={chipRef}\n panelRef={panelRef}\n empty={filtered.length === 0}\n header={\n <DropdownSearchHeader\n query={query}\n onQueryChange={setQuery}\n inputRef={inputRef}\n placeholder={currencyText.search}\n />\n }\n >\n {filtered.map((c) => {\n const active = c.code === selected?.code;\n return (\n <li key={c.code}>\n <button\n type=\"button\"\n onClick={() => {\n onCurrencyChange?.(c.code);\n setOpen(false);\n }}\n className={cn(\n \"flex w-full items-center gap-2 px-3 py-1.5 text-sm text-start hover:bg-[var(--bg-hover)]\",\n active && \"bg-[var(--bg-active)]\",\n )}\n >\n <CurrencyFlag country={c.country} />\n <span className=\"font-mono text-[var(--text-muted)] w-8 shrink-0 text-xs\">\n {c.symbol}\n </span>\n <span className=\"font-medium text-[var(--text-primary)]\">{c.code}</span>\n <span className=\"text-[var(--text-muted)] truncate text-xs\">{currencyName(c, currencyNames, locale)}</span>\n </button>\n </li>\n );\n })}\n </DropdownPanel>\n )}\n </FloatingField>\n {/* Outside the relative box, as NumberInput's caption is: the trailing\n controls are `inset-y-1` in it and would stretch down over a second line. */}\n {textHint && (\n <p id={hintId} className=\"mt-1 text-[11px] leading-tight text-[var(--text-muted)]\">\n {hint}\n </p>\n )}\n {/* The news after the standing advice, as Select orders them. The root is\n already a steady box, so the message coming and going remounts nothing. */}\n {hasError && (\n <p id={errorId} className={FIELD_ERROR_CLASS}>\n {error}\n </p>\n )}\n {showNumpad && (\n <NumberPadSheet\n // Localised like the field it mirrors. Keys are typing, read by the\n // locale's marks like the keyboard's; \"=\" is a result, dot-decimal.\n value={display}\n onChange={typed}\n onResult={(result) => {\n setDraft(null);\n const settled = settle(result);\n handleText(settled);\n onCommit?.(settled);\n }}\n onDone={() => innerRef.current?.blur()}\n label={label}\n labels={labels?.pad}\n decimalMark={mark}\n />\n )}\n </div>\n );\n },\n);\n\nAmountInput.displayName = \"AmountInput\";\n"],"mappings":";AAweQ,cA+GI,YA/GJ;AAxeR,SAAS,YAAY,aAAa,OAAO,SAAS,QAAQ,gBAAgB;AAC1E,SAAS,mBAAmB;AAE5B,SAAS,YAAY,cAAc,cAAc,mBAAmB;AACpE,SAAS,YAAY,eAAe,eAAe,sBAAsB,eAAe,mBAAmB;AAC3G,SAAS,UAAU;AACnB,SAAS,2BAA2B;AACpC,SAAS,qBAAqB;AAC9B,SA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I,QAAQ,WAAU,2DACtB,gBACH;AAAA,MAID,YACC,oBAAC,OAAE,IAAI,SAAS,WAAW,mBACxB,iBACH;AAAA,MAED,cACC;AAAA,QAAC;AAAA;AAAA,UAGC,OAAO;AAAA,UACP,UAAU;AAAA,UACV,UAAU,CAAC,WAAW;AACpB,qBAAS,IAAI;AACb,kBAAM,UAAU,OAAO,MAAM;AAC7B,uBAAW,OAAO;AAClB,uBAAW,OAAO;AAAA,UACpB;AAAA,UACA,QAAQ,MAAM,SAAS,SAAS,KAAK;AAAA,UACrC;AAAA,UACA,QAAQ,QAAQ;AAAA,UAChB,aAAa;AAAA;AAAA,MACf;AAAA,OAEJ;AAAA,EAEJ;AACF;AAEA,YAAY,cAAc;","names":[]}
|
|
@@ -80,6 +80,14 @@ interface AutocompleteProps<V extends string | number = string> extends Omit<Com
|
|
|
80
80
|
* its `aria-describedby`, implies `invalid`. Not a failed lookup — that is
|
|
81
81
|
* `loadErrorLabel`, shown in the list. */
|
|
82
82
|
error?: ReactNode;
|
|
83
|
+
/**
|
|
84
|
+
* Standing advice — {@link Combobox}'s `hint`, so this field reads like every other
|
|
85
|
+
* (keksdose K4): plain TEXT is a caption under the field on the input's
|
|
86
|
+
* `aria-describedby`, before any error; a {@link FieldHint} "?" rides the label line,
|
|
87
|
+
* or with no label sits at the field's end edge, outside the box. Not the list's
|
|
88
|
+
* `status` line, which talks about the lookup, not the field.
|
|
89
|
+
*/
|
|
90
|
+
hint?: ReactNode;
|
|
83
91
|
/**
|
|
84
92
|
* The caller's own line in the list, replacing the automatic one (loading / failed
|
|
85
93
|
* / no results). For what only the caller knows: "offline", "the address service
|
|
@@ -93,6 +101,27 @@ interface AutocompleteProps<V extends string | number = string> extends Omit<Com
|
|
|
93
101
|
loadErrorLabel?: string;
|
|
94
102
|
/** Classes for the `<input>` itself; `className` styles the wrapper. */
|
|
95
103
|
inputClassName?: string;
|
|
104
|
+
/**
|
|
105
|
+
* Why the field cannot be changed — {@link Button}'s `disabledReason`, the Combobox
|
|
106
|
+
* family's write lock (keksdose G2, 0.23), for a field whose pick SAVES: an address
|
|
107
|
+
* search whose taken row writes the address, a lookup that links a record.
|
|
108
|
+
*
|
|
109
|
+
* With a reason the input stays focusable and `aria-disabled`, is `readOnly` (the
|
|
110
|
+
* settled grey FIELD_BASE gives a `[readonly]` field), opens no list and asks no
|
|
111
|
+
* `loadOptions` — whatever `open` says — and nothing reaches `onChange`, `onSelect` or
|
|
112
|
+
* `onOpenChange(true)`. Enter is swallowed, so a locked field does not submit the form
|
|
113
|
+
* around it, and a caller's `onKeyDown` does not hear it; every other key still
|
|
114
|
+
* reaches the caller (an Escape that closes its panel) and the caret. The reason is in
|
|
115
|
+
* the kit {@link Tooltip} and on the input's `aria-describedby`. Wins over `disabled`.
|
|
116
|
+
*/
|
|
117
|
+
disabledReason?: ReactNode;
|
|
118
|
+
/**
|
|
119
|
+
* This field COMMITS. Under a locked {@link WriteLockProvider} it is locked the
|
|
120
|
+
* `disabledReason` way with the lock's reason (which wins over its own). A search
|
|
121
|
+
* whose result is only draft state — the form's Save writes it — leaves this off and
|
|
122
|
+
* stays live under the lock. No provider, or an unlocked one: no effect.
|
|
123
|
+
*/
|
|
124
|
+
commit?: boolean;
|
|
96
125
|
}
|
|
97
126
|
/**
|
|
98
127
|
* An inline, async-capable text field with a suggestion list under it — the
|