@eifi1/ui-kit 0.22.0 → 0.24.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 +8 -7
- package/dist/components/amount-input.d.ts +34 -7
- package/dist/components/amount-input.js +14 -10
- package/dist/components/amount-input.js.map +1 -1
- package/dist/components/autocomplete.d.ts +26 -0
- package/dist/components/autocomplete.js +164 -137
- package/dist/components/autocomplete.js.map +1 -1
- package/dist/components/button-group.d.ts +8 -7
- package/dist/components/calculator.d.ts +8 -7
- package/dist/components/column-mapper.d.ts +235 -0
- package/dist/components/column-mapper.js +411 -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 +113 -3
- package/dist/components/combobox.js +456 -313
- package/dist/components/combobox.js.map +1 -1
- package/dist/components/confirm-dialog.d.ts +8 -7
- package/dist/components/confirm-dialog.js +7 -8
- package/dist/components/confirm-dialog.js.map +1 -1
- package/dist/components/copy-button.d.ts +5 -4
- package/dist/components/country-select.d.ts +50 -7
- package/dist/components/country-select.js +65 -9
- package/dist/components/country-select.js.map +1 -1
- package/dist/components/danger-confirm.d.ts +8 -7
- package/dist/components/danger-confirm.js +64 -7
- package/dist/components/danger-confirm.js.map +1 -1
- package/dist/components/date-picker.d.ts +41 -0
- package/dist/components/date-picker.js +269 -8
- package/dist/components/date-picker.js.map +1 -1
- package/dist/components/entity-combobox.d.ts +48 -2
- package/dist/components/entity-combobox.js +159 -114
- package/dist/components/entity-combobox.js.map +1 -1
- package/dist/components/facing-pair.d.ts +8 -7
- package/dist/components/field-parts.d.ts +116 -6
- package/dist/components/field-parts.js +84 -0
- package/dist/components/field-parts.js.map +1 -1
- package/dist/components/field-strip.d.ts +105 -0
- package/dist/components/field-strip.js +46 -0
- package/dist/components/field-strip.js.map +1 -0
- package/dist/components/file-button.d.ts +8 -7
- package/dist/components/file-dropzone.d.ts +8 -7
- package/dist/components/form-actions.d.ts +8 -7
- package/dist/components/form-actions.js +23 -3
- package/dist/components/form-actions.js.map +1 -1
- package/dist/components/iban-input.d.ts +8 -7
- package/dist/components/icon-picker.d.ts +10 -1
- package/dist/components/icon-picker.js +12 -4
- package/dist/components/icon-picker.js.map +1 -1
- package/dist/components/language-select.d.ts +8 -7
- package/dist/components/money-field.d.ts +11 -7
- package/dist/components/money-field.js.map +1 -1
- package/dist/components/month-picker.js +2 -1
- package/dist/components/month-picker.js.map +1 -1
- package/dist/components/multi-entity-combobox.d.ts +31 -2
- package/dist/components/multi-entity-combobox.js +152 -103
- package/dist/components/multi-entity-combobox.js.map +1 -1
- package/dist/components/number-field.d.ts +8 -7
- package/dist/components/number-input.d.ts +8 -7
- package/dist/components/numpad-sheet.d.ts +8 -7
- package/dist/components/phone-input.d.ts +8 -7
- 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 +8 -7
- package/dist/components/settings-fields.d.ts +8 -7
- package/dist/components/share-card.d.ts +8 -7
- package/dist/components/swatch-picker.d.ts +17 -1
- package/dist/components/swatch-picker.js +10 -4
- package/dist/components/swatch-picker.js.map +1 -1
- package/dist/components/text-link.d.ts +8 -7
- package/dist/components/tile-radio.d.ts +20 -0
- package/dist/components/tile-radio.js +25 -8
- package/dist/components/tile-radio.js.map +1 -1
- package/dist/components/time-input.d.ts +8 -7
- package/dist/components/toggle-group.js +2 -2
- package/dist/components/toggle-group.js.map +1 -1
- package/dist/components/trigger-aria.d.ts +3 -0
- package/dist/components/trigger-aria.js +3 -1
- package/dist/components/trigger-aria.js.map +1 -1
- package/dist/components/ui.d.ts +5 -4
- package/dist/components/ui.js +60 -28
- package/dist/components/ui.js.map +1 -1
- package/dist/feedback/feedback-attachment.d.ts +66 -1
- package/dist/feedback/feedback-attachment.js +185 -65
- package/dist/feedback/feedback-attachment.js.map +1 -1
- package/dist/feedback/feedback-dialog.d.ts +66 -1
- package/dist/feedback/feedback-dialog.js.map +1 -1
- package/dist/feedback/feedback-inbox.d.ts +67 -252
- package/dist/feedback/feedback-inbox.js.map +1 -1
- package/dist/feedback/feedback-thread.d.ts +66 -287
- package/dist/feedback/feedback-thread.js +16 -3
- package/dist/feedback/feedback-thread.js.map +1 -1
- package/dist/{kit-labels-R8mIAc9N.d.ts → feedback-DOwPu-Il.d.ts} +1273 -30
- package/dist/feedback.d.ts +65 -3
- package/dist/hooks/use-file-drop.d.ts +8 -7
- package/dist/i18n/defaults.d.ts +8 -7
- package/dist/i18n/defaults.js +3 -1
- package/dist/i18n/defaults.js.map +1 -1
- package/dist/i18n/german.d.ts +8 -7
- package/dist/i18n/german.js +36 -2
- package/dist/i18n/german.js.map +1 -1
- package/dist/i18n/kit-labels.d.ts +5 -4
- package/dist/i18n/kit-labels.js.map +1 -1
- package/dist/i18n/languages.d.ts +8 -7
- package/dist/i18n/locales/de-CH.d.ts +8 -7
- package/dist/i18n/locales/en.d.ts +8 -7
- package/dist/i18n/locales/en.js +7 -0
- package/dist/i18n/locales/en.js.map +1 -1
- package/dist/i18n/locales/es.d.ts +8 -7
- package/dist/i18n/locales/es.js +37 -2
- package/dist/i18n/locales/es.js.map +1 -1
- package/dist/i18n/locales/fr.d.ts +8 -7
- package/dist/i18n/locales/fr.js +36 -2
- package/dist/i18n/locales/fr.js.map +1 -1
- package/dist/i18n/locales/hu.d.ts +8 -7
- package/dist/i18n/locales/hu.js +38 -2
- package/dist/i18n/locales/hu.js.map +1 -1
- package/dist/i18n/locales/it.d.ts +8 -7
- package/dist/i18n/locales/it.js +37 -2
- package/dist/i18n/locales/it.js.map +1 -1
- package/dist/i18n/locales/zh.d.ts +8 -7
- package/dist/i18n/locales/zh.js +34 -2
- package/dist/i18n/locales/zh.js.map +1 -1
- package/dist/i18n/review.d.ts +8 -7
- package/dist/i18n/review.js +20 -1
- package/dist/i18n/review.js.map +1 -1
- package/dist/index.d.ts +6 -4
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -1
- package/dist/lib/column-mapping.d.ts +81 -0
- package/dist/lib/column-mapping.js +108 -0
- package/dist/lib/column-mapping.js.map +1 -0
- package/dist/lib/strip-fade.d.ts +2 -2
- package/dist/lib/strip-fade.js.map +1 -1
- 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 +142 -13
- package/dist/rhf/fields.js +185 -3
- package/dist/rhf/fields.js.map +1 -1
- package/dist/rhf/form.d.ts +8 -7
- package/dist/rhf.d.ts +9 -8
- package/dist/rhf.js.map +1 -1
- package/dist/shell/app-shell.d.ts +8 -7
- package/dist/shell/top-bar-brand.d.ts +8 -7
- 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 +8 -7
- package/dist/table-text.d.ts +1 -1
- package/dist/wizard/stepper-nav.d.ts +38 -9
- package/dist/wizard/stepper-nav.js +4 -0
- package/dist/wizard/stepper-nav.js.map +1 -1
- package/dist/wizard.d.ts +8 -7
- package/package.json +1 -1
- package/src/components/amount-input.tsx +50 -14
- package/src/components/autocomplete.tsx +188 -116
- package/src/components/column-mapper.tsx +768 -0
- package/src/components/combobox-core.tsx +82 -9
- package/src/components/combobox.tsx +655 -335
- package/src/components/confirm-dialog.tsx +12 -8
- package/src/components/country-select.tsx +135 -22
- package/src/components/danger-confirm.tsx +274 -24
- package/src/components/date-picker.tsx +423 -10
- package/src/components/entity-combobox.tsx +243 -129
- package/src/components/field-parts.tsx +224 -5
- package/src/components/field-strip.tsx +149 -0
- package/src/components/form-actions.tsx +52 -5
- package/src/components/icon-picker.tsx +23 -4
- package/src/components/money-field.tsx +3 -0
- package/src/components/month-picker.tsx +2 -1
- package/src/components/multi-entity-combobox.tsx +221 -121
- package/src/components/reauth-dialog.tsx +17 -18
- package/src/components/swatch-picker.tsx +29 -5
- package/src/components/tile-radio.tsx +74 -13
- package/src/components/toggle-group.tsx +2 -2
- package/src/components/trigger-aria.ts +5 -0
- package/src/components/ui.tsx +114 -33
- package/src/feedback/feedback-attachment.tsx +372 -72
- package/src/feedback/feedback-dialog.tsx +7 -3
- package/src/feedback/feedback-inbox.tsx +3 -2
- package/src/feedback/feedback-thread.tsx +112 -9
- package/src/i18n/defaults.ts +2 -0
- package/src/i18n/german.ts +42 -0
- package/src/i18n/kit-labels.tsx +4 -0
- package/src/i18n/locales/en.ts +27 -5
- package/src/i18n/locales/es.ts +41 -0
- package/src/i18n/locales/fr.ts +42 -0
- package/src/i18n/locales/hu.ts +37 -0
- package/src/i18n/locales/it.ts +41 -0
- package/src/i18n/locales/zh.ts +32 -0
- package/src/i18n/review.ts +19 -0
- package/src/index.ts +18 -0
- package/src/lib/column-mapping.ts +234 -0
- package/src/lib/strip-fade.ts +2 -2
- package/src/lib/table-text.ts +271 -0
- package/src/rhf/fields.tsx +421 -6
- package/src/rhf.ts +2 -1
- package/src/shell/topbar-action-menu.tsx +134 -38
- package/src/wizard/stepper-nav.tsx +35 -1
- package/dist/components/field-anatomy.d.ts +0 -95
- package/dist/components/field-anatomy.js +0 -84
- package/dist/components/field-anatomy.js.map +0 -1
- package/dist/feedback-attachment-NhUm7Zga.d.ts +0 -367
- package/src/components/field-anatomy.tsx +0 -190
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
|
-
import { ComponentPropsWithoutRef, ReactNode } from 'react';
|
|
2
|
+
import { ComponentPropsWithoutRef, Ref, ReactNode } from 'react';
|
|
3
3
|
|
|
4
4
|
/** The words {@link CountrySelect} renders on its own behalf. The list's "no results",
|
|
5
5
|
* "loading" and result-count announcements are the shared `combobox` namespace's,
|
|
@@ -20,14 +20,45 @@ declare const DEFAULT_COUNTRY_SELECT_LABELS: CountrySelectLabels;
|
|
|
20
20
|
* `onChange` is the kit's — "a country was picked", carrying its code — rather than
|
|
21
21
|
* the div's form event. `id` and the `aria-*` wiring below go to the TRIGGER, which is
|
|
22
22
|
* the control a reader meets; everything else in `rest` dresses the wrapper.
|
|
23
|
+
*
|
|
24
|
+
* `Clearable` follows `clearable`, the way {@link EntityCombobox}'s `C` follows its
|
|
25
|
+
* `clearValue`: it is inferred from the prop, so `onChange` is `(code: string) => void`
|
|
26
|
+
* for the field as it always was (`onChange={setCountry}` over a `string` state still
|
|
27
|
+
* type-checks), and `(code: string | null) => void` once `clearable` is set — the
|
|
28
|
+
* `null` of a clear cannot reach a handler that was never told about it.
|
|
23
29
|
*/
|
|
24
|
-
interface CountrySelectProps extends Omit<ComponentPropsWithoutRef<"div">, "onChange" | "defaultValue"> {
|
|
30
|
+
interface CountrySelectProps<Clearable extends boolean = false> extends Omit<ComponentPropsWithoutRef<"div">, "onChange" | "defaultValue"> {
|
|
25
31
|
/** The chosen country as an ISO 3166-1 alpha-2 code ("CH"), in either case;
|
|
26
32
|
* `null`, `undefined` or `""` when none is. A code outside the list still shows
|
|
27
33
|
* its name — the list restricts what can be PICKED, not what can be shown. */
|
|
28
34
|
value: string | null | undefined;
|
|
29
|
-
/** A country was picked: its alpha-2 code, always upper-case.
|
|
30
|
-
|
|
35
|
+
/** A country was picked: its alpha-2 code, always upper-case. With `clearable`,
|
|
36
|
+
* also `null`: the "×" (or Delete on the trigger) emptied the field. */
|
|
37
|
+
onChange: (code: Clearable extends true ? string | null : string) => void;
|
|
38
|
+
/**
|
|
39
|
+
* Offer a clear "×" in place of the chevron while a country is chosen; it hands
|
|
40
|
+
* `onChange` `null` (the kit's later list: an optional country — a contact's
|
|
41
|
+
* nationality, a bank filter's "any country" — could be set but never unset again).
|
|
42
|
+
*
|
|
43
|
+
* The combobox family's clear, as {@link EntityCombobox} draws it: a pointer
|
|
44
|
+
* shortcut inside the trigger, out of the tab order so it is not a second stop
|
|
45
|
+
* between this field and the next, named by `clearLabel` (default: the
|
|
46
|
+
* `combobox.clear` label every picker in the family shares). The keyboard way is
|
|
47
|
+
* Delete or Backspace on the closed trigger. Not offered while `disabled` or locked
|
|
48
|
+
* (`commit` / `disabledReason`): a clear is a change like any other.
|
|
49
|
+
*/
|
|
50
|
+
clearable?: Clearable;
|
|
51
|
+
/** The clear "×"'s accessible name. Wins over `combobox.clear` from the
|
|
52
|
+
* {@link UiKitProvider}, as {@link EntityCombobox}'s `clearLabel` does. */
|
|
53
|
+
clearLabel?: string;
|
|
54
|
+
/**
|
|
55
|
+
* The TRIGGER — the focusable `<button>` a reader meets — as a React 19 ref prop,
|
|
56
|
+
* the way {@link MoneyField} takes its input's (kastlan: react-hook-form's
|
|
57
|
+
* focus-on-error calls `focus()` on whatever `field.ref` was handed, and without a
|
|
58
|
+
* ref the first field in error on an address form was never focused). See
|
|
59
|
+
* `RhfCountrySelect`, which passes it.
|
|
60
|
+
*/
|
|
61
|
+
ref?: Ref<HTMLButtonElement>;
|
|
31
62
|
/**
|
|
32
63
|
* Offer only these codes (any case; duplicates and malformed entries dropped).
|
|
33
64
|
* Default: every ISO 3166-1 country, {@link COUNTRY_CODES}. Sorted by name either
|
|
@@ -67,8 +98,8 @@ interface CountrySelectProps extends Omit<ComponentPropsWithoutRef<"div">, "onCh
|
|
|
67
98
|
error?: ReactNode;
|
|
68
99
|
/** Required and unanswered — {@link FIELD_INVALID}, as on every field. */
|
|
69
100
|
invalid?: boolean;
|
|
70
|
-
/** The empty trigger's text. Default: nothing when the field has a `label`
|
|
71
|
-
* label already says what goes here), else `labels.country`. */
|
|
101
|
+
/** The empty trigger's text. Default: nothing when the field has a `label` or an
|
|
102
|
+
* `aria-labelledby` (the label already says what goes here), else `labels.country`. */
|
|
72
103
|
placeholder?: string;
|
|
73
104
|
/** As on the other pickers: no focus, no list, the settled look. */
|
|
74
105
|
disabled?: boolean;
|
|
@@ -92,6 +123,15 @@ interface CountrySelectProps extends Omit<ComponentPropsWithoutRef<"div">, "onCh
|
|
|
92
123
|
/** Per-instance overrides of {@link CountrySelectLabels}, over the provider's
|
|
93
124
|
* `countrySelect` namespace, over English. */
|
|
94
125
|
labels?: Partial<CountrySelectLabels>;
|
|
126
|
+
/**
|
|
127
|
+
* Name the trigger by an element of the caller's — a form's own label above the
|
|
128
|
+
* field, which is how `RhfCountrySelect` names it. The trigger is then named by
|
|
129
|
+
* that element AND the chosen country (two references, as {@link DatePicker}'s
|
|
130
|
+
* trigger is named, so "Country Switzerland" needs no punctuation to translate),
|
|
131
|
+
* instead of the composed "label: country". An `aria-label` still wins. Before
|
|
132
|
+
* 0.23 this landed on the wrapper `<div>`, which has no role to be named.
|
|
133
|
+
*/
|
|
134
|
+
"aria-labelledby"?: string;
|
|
95
135
|
}
|
|
96
136
|
/**
|
|
97
137
|
* A country picker: the value is the ISO 3166-1 alpha-2 code ("CH"), the names are the
|
|
@@ -118,7 +158,10 @@ interface CountrySelectProps extends Omit<ComponentPropsWithoutRef<"div">, "onCh
|
|
|
118
158
|
*
|
|
119
159
|
* Field anatomy as on every field: floating `label`, `hint`, `error`, `invalid`; the
|
|
120
160
|
* trigger is named "label: value" as the other trigger pickers are.
|
|
161
|
+
*
|
|
162
|
+
* Since 0.23 it takes a `ref` to the trigger (react-hook-form's focus-on-error, kastlan)
|
|
163
|
+
* and `clearable`, which hands `onChange` `null`.
|
|
121
164
|
*/
|
|
122
|
-
declare function CountrySelect({ value, onChange, countries, preferred, flags, label, hint, error, invalid, placeholder, disabled, disabledReason: ownReason, commit, locale: localeProp, labels: labelsProp, className, id, "aria-label": ariaLabel, "aria-describedby": ariaDescribedBy, "aria-invalid": ariaInvalid, "aria-required": ariaRequired, ...rest }: CountrySelectProps): react.JSX.Element;
|
|
165
|
+
declare function CountrySelect<Clearable extends boolean = false>({ value, onChange, countries, preferred, flags, label, hint, error, invalid, placeholder, disabled, disabledReason: ownReason, commit, clearable, clearLabel, locale: localeProp, labels: labelsProp, className, id, ref, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, "aria-describedby": ariaDescribedBy, "aria-invalid": ariaInvalid, "aria-required": ariaRequired, ...rest }: CountrySelectProps<Clearable>): react.JSX.Element;
|
|
123
166
|
|
|
124
167
|
export { CountrySelect, type CountrySelectLabels, type CountrySelectProps, DEFAULT_COUNTRY_SELECT_LABELS };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { useId, useMemo } from "react";
|
|
3
|
+
import { useCallback, useId, useMemo } from "react";
|
|
4
|
+
import { X } from "lucide-react";
|
|
4
5
|
import { cn } from "../lib/cn.js";
|
|
5
6
|
import { COUNTRY_CODES, countryName, normalizeCountryCode } from "../lib/countries.js";
|
|
6
7
|
import { FieldChevron, FIELD_FLOATING_PAD, FIELD_INVALID, FIELD_TRIGGER, FloatingField } from "./ui.js";
|
|
@@ -11,9 +12,14 @@ import {
|
|
|
11
12
|
useComboboxCore,
|
|
12
13
|
useComboboxFieldError
|
|
13
14
|
} from "./combobox-core.js";
|
|
14
|
-
import { hasMessage, mergeDescribedBy } from "./choice-parts.js";
|
|
15
|
+
import { assignRef, hasMessage, mergeDescribedBy } from "./choice-parts.js";
|
|
15
16
|
import { useCommitReason } from "./write-lock.js";
|
|
16
|
-
import {
|
|
17
|
+
import {
|
|
18
|
+
DEFAULT_COMBOBOX_LABELS,
|
|
19
|
+
DEFAULT_COMMON_LABELS,
|
|
20
|
+
useKitLabels,
|
|
21
|
+
useKitLocale
|
|
22
|
+
} from "../i18n/kit-labels.js";
|
|
17
23
|
const DEFAULT_COUNTRY_SELECT_LABELS = {
|
|
18
24
|
country: "Country",
|
|
19
25
|
search: "Search country",
|
|
@@ -59,11 +65,15 @@ function CountrySelect({
|
|
|
59
65
|
disabled,
|
|
60
66
|
disabledReason: ownReason,
|
|
61
67
|
commit,
|
|
68
|
+
clearable,
|
|
69
|
+
clearLabel,
|
|
62
70
|
locale: localeProp,
|
|
63
71
|
labels: labelsProp,
|
|
64
72
|
className,
|
|
65
73
|
id,
|
|
74
|
+
ref,
|
|
66
75
|
"aria-label": ariaLabel,
|
|
76
|
+
"aria-labelledby": ariaLabelledBy,
|
|
67
77
|
"aria-describedby": ariaDescribedBy,
|
|
68
78
|
"aria-invalid": ariaInvalid,
|
|
69
79
|
"aria-required": ariaRequired,
|
|
@@ -71,6 +81,7 @@ function CountrySelect({
|
|
|
71
81
|
}) {
|
|
72
82
|
const text = useKitLabels("countrySelect", DEFAULT_COUNTRY_SELECT_LABELS, labelsProp);
|
|
73
83
|
const common = useKitLabels("common", DEFAULT_COMMON_LABELS);
|
|
84
|
+
const comboText = useKitLabels("combobox", DEFAULT_COMBOBOX_LABELS, { clear: clearLabel });
|
|
74
85
|
const locale = useKitLocale(localeProp) ?? "en";
|
|
75
86
|
const countriesKey = countries?.join(",");
|
|
76
87
|
const preferredKey = preferred?.join(",");
|
|
@@ -107,6 +118,13 @@ function CountrySelect({
|
|
|
107
118
|
);
|
|
108
119
|
const core = useComboboxCore({ options: allOptions, filter: false });
|
|
109
120
|
const { open, setOpen, query, triggerRef, closeToTrigger } = core;
|
|
121
|
+
const setTrigger = useCallback(
|
|
122
|
+
(el) => {
|
|
123
|
+
triggerRef.current = el;
|
|
124
|
+
assignRef(ref, el);
|
|
125
|
+
},
|
|
126
|
+
[ref, triggerRef]
|
|
127
|
+
);
|
|
110
128
|
const q = fold(query.trim());
|
|
111
129
|
const results = useMemo(() => {
|
|
112
130
|
const firsts = q ? search(top, q) : top;
|
|
@@ -133,18 +151,26 @@ function CountrySelect({
|
|
|
133
151
|
);
|
|
134
152
|
const code = normalizeCountryCode(value);
|
|
135
153
|
const selectedName = code ? countryName(code, locale) : void 0;
|
|
136
|
-
const emptyText = placeholder ?? (label === void 0 ? text.country : "");
|
|
154
|
+
const emptyText = placeholder ?? (label === void 0 && !ariaLabelledBy ? text.country : "");
|
|
137
155
|
const fieldName = typeof label === "string" ? label : text.country;
|
|
138
|
-
const
|
|
156
|
+
const valueId = `${generated}-value`;
|
|
157
|
+
const labelledBy = ariaLabel === void 0 && ariaLabelledBy ? mergeDescribedBy(ariaLabelledBy, (selectedName !== void 0 || Boolean(placeholder)) && valueId) : void 0;
|
|
158
|
+
const name = labelledBy !== void 0 ? void 0 : ariaLabel ?? (selectedName !== void 0 ? common.fieldValue(fieldName, selectedName) : placeholder ? common.fieldValue(fieldName, placeholder) : fieldName);
|
|
159
|
+
const showClear = Boolean(clearable && code && !inert);
|
|
160
|
+
const emit = onChange;
|
|
161
|
+
const clear = () => {
|
|
162
|
+
if (!showClear) return;
|
|
163
|
+
emit(null);
|
|
164
|
+
};
|
|
139
165
|
const choose = (o) => {
|
|
140
166
|
if (inert) return;
|
|
141
|
-
|
|
167
|
+
emit(o.value);
|
|
142
168
|
closeToTrigger();
|
|
143
169
|
};
|
|
144
170
|
const trigger = /* @__PURE__ */ jsxs(
|
|
145
171
|
"button",
|
|
146
172
|
{
|
|
147
|
-
ref:
|
|
173
|
+
ref: setTrigger,
|
|
148
174
|
id: triggerId,
|
|
149
175
|
type: "button",
|
|
150
176
|
role: "combobox",
|
|
@@ -152,6 +178,7 @@ function CountrySelect({
|
|
|
152
178
|
"aria-controls": listboxId,
|
|
153
179
|
"aria-expanded": open,
|
|
154
180
|
"aria-label": name,
|
|
181
|
+
"aria-labelledby": labelledBy,
|
|
155
182
|
"aria-invalid": field.isInvalid || void 0,
|
|
156
183
|
"aria-required": ariaRequired,
|
|
157
184
|
"aria-describedby": mergeDescribedBy(field.describedBy, locked && reasonId),
|
|
@@ -169,6 +196,9 @@ function CountrySelect({
|
|
|
169
196
|
if (e.key === "ArrowDown" || e.key === "ArrowUp") {
|
|
170
197
|
e.preventDefault();
|
|
171
198
|
setOpen(true);
|
|
199
|
+
} else if (showClear && !open && (e.key === "Delete" || e.key === "Backspace")) {
|
|
200
|
+
e.preventDefault();
|
|
201
|
+
clear();
|
|
172
202
|
}
|
|
173
203
|
},
|
|
174
204
|
className: cn(
|
|
@@ -182,9 +212,35 @@ function CountrySelect({
|
|
|
182
212
|
children: [
|
|
183
213
|
/* @__PURE__ */ jsxs("span", { className: "flex min-w-0 items-center gap-2", children: [
|
|
184
214
|
flags && code && /* @__PURE__ */ jsx(CurrencyFlag, { country: code.toLowerCase() }),
|
|
185
|
-
/* @__PURE__ */ jsx(
|
|
215
|
+
/* @__PURE__ */ jsx(
|
|
216
|
+
"span",
|
|
217
|
+
{
|
|
218
|
+
id: valueId,
|
|
219
|
+
className: cn("truncate", selectedName === void 0 && "text-[var(--text-placeholder)]"),
|
|
220
|
+
children: selectedName ?? emptyText
|
|
221
|
+
}
|
|
222
|
+
)
|
|
186
223
|
] }),
|
|
187
|
-
|
|
224
|
+
showClear ? (
|
|
225
|
+
/* eslint-disable-next-line jsx-a11y/click-events-have-key-events -- tabIndex -1 inside
|
|
226
|
+
the trigger <button>, so it never holds focus and a key handler here could never
|
|
227
|
+
fire; the keys go to the trigger, where Delete and Backspace clear. A pointer
|
|
228
|
+
shortcut, as on EntityCombobox. */
|
|
229
|
+
/* @__PURE__ */ jsx(
|
|
230
|
+
"span",
|
|
231
|
+
{
|
|
232
|
+
role: "button",
|
|
233
|
+
tabIndex: -1,
|
|
234
|
+
"aria-label": comboText.clear,
|
|
235
|
+
onClick: (e) => {
|
|
236
|
+
e.stopPropagation();
|
|
237
|
+
clear();
|
|
238
|
+
},
|
|
239
|
+
className: "absolute end-2 top-1/2 -translate-y-1/2 rounded p-0.5 text-[var(--text-placeholder)] hover:text-[var(--text-secondary)]",
|
|
240
|
+
children: /* @__PURE__ */ jsx(X, { "aria-hidden": true, className: "size-4" })
|
|
241
|
+
}
|
|
242
|
+
)
|
|
243
|
+
) : /* @__PURE__ */ jsx(FieldChevron, {})
|
|
188
244
|
]
|
|
189
245
|
}
|
|
190
246
|
);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/components/country-select.tsx"],"sourcesContent":["import { useId, useMemo } from \"react\";\nimport type { ComponentPropsWithoutRef, ReactNode } from \"react\";\nimport { cn } from \"../lib/cn\";\nimport { COUNTRY_CODES, countryName, normalizeCountryCode } from \"../lib/countries\";\nimport { FieldChevron, FIELD_FLOATING_PAD, FIELD_INVALID, FIELD_TRIGGER, FloatingField } from \"./ui\";\nimport { Tooltip } from \"./tooltip\";\nimport { CurrencyFlag } from \"./currency-select\";\nimport {\n ComboboxPanel,\n useComboboxCore,\n useComboboxFieldError,\n type ComboOption,\n} from \"./combobox-core\";\nimport { hasMessage, mergeDescribedBy } from \"./choice-parts\";\nimport { useCommitReason } from \"./write-lock\";\nimport { DEFAULT_COMMON_LABELS, useKitLabels, useKitLocale } from \"../i18n/kit-labels\";\n\n// ── Labels ────────────────────────────────────────────────────────────────────\n\n/** The words {@link CountrySelect} renders on its own behalf. The list's \"no results\",\n * \"loading\" and result-count announcements are the shared `combobox` namespace's,\n * as on every other searchable picker. */\nexport interface CountrySelectLabels {\n /** What the field is, when the caller gives no `label`: the first half of the\n * trigger's accessible name, the phone sheet's title, and the empty trigger's\n * text. */\n country: string;\n /** The search box in the open list. */\n search: string;\n /** The heading between the `preferred` countries and all the others. Shown only\n * when `preferred` puts something above it. */\n others: string;\n}\n\nexport const DEFAULT_COUNTRY_SELECT_LABELS: CountrySelectLabels = {\n country: \"Country\",\n search: \"Search country\",\n others: \"Other countries\",\n};\n\n// ── Props ─────────────────────────────────────────────────────────────────────\n\n/**\n * `onChange` is the kit's — \"a country was picked\", carrying its code — rather than\n * the div's form event. `id` and the `aria-*` wiring below go to the TRIGGER, which is\n * the control a reader meets; everything else in `rest` dresses the wrapper.\n */\nexport interface CountrySelectProps\n extends Omit<ComponentPropsWithoutRef<\"div\">, \"onChange\" | \"defaultValue\"> {\n /** The chosen country as an ISO 3166-1 alpha-2 code (\"CH\"), in either case;\n * `null`, `undefined` or `\"\"` when none is. A code outside the list still shows\n * its name — the list restricts what can be PICKED, not what can be shown. */\n value: string | null | undefined;\n /** A country was picked: its alpha-2 code, always upper-case. */\n onChange: (code: string) => void;\n /**\n * Offer only these codes (any case; duplicates and malformed entries dropped).\n * Default: every ISO 3166-1 country, {@link COUNTRY_CODES}. Sorted by name either\n * way — the order given is not kept, because the reader looks a country up by its\n * name in their own language, and any other order is one they cannot predict.\n *\n * keksdose's bank picker offers the fifteen countries its banks are in\n * (DE AT CH FR IT ES NL BE PT PL SE DK FI GB IE). A code that is not in ISO's list\n * is allowed here on purpose: `XK` (Kosovo) is the app's decision, not the kit's.\n */\n countries?: readonly string[];\n /**\n * A short group shown FIRST, in the order given, above the alphabetical rest —\n * kastlan's CH, LI, DE, AT, FR, IT, the six countries most of its customers live\n * in, out of a list of 249. Each code appears once: a preferred country is not\n * repeated in the rest. The rest gets a heading (`labels.others`) so the boundary\n * is visible. Search keeps the split: matching preferred countries stay on top.\n * Codes not in `countries` are ignored — `countries` decides what can be picked.\n */\n preferred?: readonly string[];\n /**\n * Draw each country's flag as a flag-icons span (`fi fi-ch`), in the rows and on\n * the trigger. Default `false`, because the kit ships no flag stylesheet — the same\n * convention as `LanguageMenu`'s `country` and `CurrencySelect`: the host imports\n * `flag-icons/css/flag-icons.min.css`, and without it a flag is an empty box.\n */\n flags?: boolean;\n /** The floating label, as on every field. A string also names the trigger\n * (\"Country: Switzerland\"). */\n label?: ReactNode;\n /** As {@link Select}'s `hint`: plain TEXT is a caption under the field, attached\n * through `aria-describedby`; a {@link FieldHint} rides the label line (or the\n * field's end, when there is no label). */\n hint?: ReactNode;\n /** As {@link Input}'s `error`: rendered under the field, on the trigger's\n * `aria-describedby`, and implies `invalid`. */\n error?: ReactNode;\n /** Required and unanswered — {@link FIELD_INVALID}, as on every field. */\n invalid?: boolean;\n /** The empty trigger's text. Default: nothing when the field has a `label` (the\n * label already says what goes here), else `labels.country`. */\n placeholder?: string;\n /** As on the other pickers: no focus, no list, the settled look. */\n disabled?: boolean;\n /**\n * Why the country cannot be changed — {@link Button}'s `disabledReason`, for a field\n * that saves itself. The trigger stays focusable and `aria-disabled`, the list does\n * not open and `onChange` never fires; the reason is in the kit {@link Tooltip} and\n * on the trigger's `aria-describedby`. Wins over `disabled`.\n */\n disabledReason?: ReactNode;\n /**\n * This select SAVES on change (a settings row with no Save button). Under a locked\n * {@link WriteLockProvider} it is locked the `disabledReason` way, with the lock's\n * reason. A country field inside a form that has its own Save stays editable under\n * the lock — leave this off there, and put `commit` on the Save.\n */\n commit?: boolean;\n /** The language the names are in. Default: the `<UiKitProvider locale>`, else\n * English (see {@link countryName}). */\n locale?: string;\n /** Per-instance overrides of {@link CountrySelectLabels}, over the provider's\n * `countrySelect` namespace, over English. */\n labels?: Partial<CountrySelectLabels>;\n}\n\n/** Fold a name for search: no case, no accents — \"osterreich\" finds Österreich, \"cote\"\n * finds Côte d'Ivoire. A keyboard without the letter must still reach the country. */\nfunction fold(s: string): string {\n return s.normalize(\"NFD\").replace(/\\p{M}/gu, \"\").toLowerCase();\n}\n\ninterface Entry {\n code: string;\n name: string;\n folded: string;\n}\n\n/** How well `e` answers `q` (already folded): the code itself (a two-letter query\n * \"ch\" means Switzerland before it means Chad), then the start of the name, then\n * anywhere in it. `-1` for no match. */\nfunction rank(e: Entry, q: string): number {\n if (e.code.toLowerCase() === q) return 0;\n if (e.folded.startsWith(q)) return 1;\n return e.folded.includes(q) ? 2 : -1;\n}\n\n/** Best rank first; a stable sort, so equal ranks keep the collated (or preferred)\n * order they came in. */\nfunction search(entries: Entry[], q: string): Entry[] {\n return entries\n .map((e) => ({ e, r: rank(e, q) }))\n .filter((x) => x.r >= 0)\n .sort((a, b) => a.r - b.r)\n .map((x) => x.e);\n}\n\nfunction toOption(e: Entry, flags: boolean, group?: string): ComboOption<string> {\n return {\n value: e.code,\n label: e.name,\n icon: flags ? <CurrencyFlag country={e.code.toLowerCase()} /> : undefined,\n group,\n };\n}\n\nfunction collator(locale: string): Intl.Collator {\n try {\n return new Intl.Collator(locale);\n } catch {\n return new Intl.Collator();\n }\n}\n\n/**\n * A country picker: the value is the ISO 3166-1 alpha-2 code (\"CH\"), the names are the\n * runtime's own (`Intl.DisplayNames`) in the provider's locale, sorted by that\n * locale's collation. Requested by kastlan (customer and handover addresses, with its\n * six neighbours on top) and keksdose (the bank picker's fifteen countries) — both\n * apps carried a hand-written list of names in two languages.\n *\n * ## Built on the kit's searchable combobox\n *\n * 249 countries is not a menu, it is a lookup, and the list has to work on a phone. So\n * this is the entity pickers' machinery — `useComboboxCore` and `ComboboxPanel`, which\n * {@link EntityCombobox} is also made of — not a native `<select>`: the anchored panel\n * with a search box on a pointer device, the full-screen sheet with its own search box\n * on a phone (live #200), the same keyboard (APG listbox), the same announcements, the\n * same group headings. Only the trigger is this component's own, because the trigger\n * is where the write lock lives: `EntityCombobox`'s is a native `disabled` button,\n * and a locked field has to stay focusable to say why.\n *\n * The search is this component's own too: it folds accents and case (\"osterreich\"\n * finds Österreich), matches the code (\"ch\" ranks Switzerland first), and ranks\n * name-starts above name-contains. The panel is handed those rows in place of the\n * core's plain substring filter.\n *\n * Field anatomy as on every field: floating `label`, `hint`, `error`, `invalid`; the\n * trigger is named \"label: value\" as the other trigger pickers are.\n */\nexport function CountrySelect({\n value,\n onChange,\n countries,\n preferred,\n flags = false,\n label,\n hint,\n error,\n invalid,\n placeholder,\n disabled,\n disabledReason: ownReason,\n commit,\n locale: localeProp,\n labels: labelsProp,\n className,\n id,\n \"aria-label\": ariaLabel,\n \"aria-describedby\": ariaDescribedBy,\n \"aria-invalid\": ariaInvalid,\n \"aria-required\": ariaRequired,\n ...rest\n}: CountrySelectProps) {\n const text = useKitLabels(\"countrySelect\", DEFAULT_COUNTRY_SELECT_LABELS, labelsProp);\n const common = useKitLabels(\"common\", DEFAULT_COMMON_LABELS);\n // English without a locale — see `countryName`.\n const locale = useKitLocale(localeProp) ?? \"en\";\n\n // ── The list ──────────────────────────────────────────────────────────────\n // Keyed on the arrays' CONTENTS: `countries={[\"DE\", \"AT\"]}` written inline is a new\n // array every render, and resorting 249 names on every keystroke elsewhere in the\n // form is work for nothing.\n const countriesKey = countries?.join(\",\");\n const preferredKey = preferred?.join(\",\");\n const { top, rest: others } = useMemo(() => {\n const seen = new Set<string>();\n const pool: string[] = [];\n for (const raw of countriesKey !== undefined ? countriesKey.split(\",\") : COUNTRY_CODES) {\n const code = normalizeCountryCode(raw);\n if (code && !seen.has(code)) {\n seen.add(code);\n pool.push(code);\n }\n }\n const entry = (code: string): Entry => {\n const name = countryName(code, locale);\n return { code, name, folded: fold(name) };\n };\n const firsts: Entry[] = [];\n const picked = new Set<string>();\n for (const raw of preferredKey ? preferredKey.split(\",\") : []) {\n const code = normalizeCountryCode(raw);\n if (code && seen.has(code) && !picked.has(code)) {\n picked.add(code);\n firsts.push(entry(code));\n }\n }\n const compare = collator(locale).compare;\n const sorted = pool\n .filter((c) => !picked.has(c))\n .map(entry)\n .sort((a, b) => compare(a.name, b.name));\n return { top: firsts, rest: sorted };\n }, [countriesKey, preferredKey, locale]);\n\n // `filter: false` — the panel is handed the rows `search` ranks below instead of\n // the core's substring filter; the core still owns open, query, the highlighted row,\n // anchoring and dismissal.\n const allOptions = useMemo(\n () => [...top, ...others].map((e) => toOption(e, flags)),\n [top, others, flags],\n );\n const core = useComboboxCore<string>({ options: allOptions, filter: false });\n const { open, setOpen, query, triggerRef, closeToTrigger } = core;\n\n const q = fold(query.trim());\n const results = useMemo(() => {\n const firsts = q ? search(top, q) : top;\n const below = q ? search(others, q) : others;\n // The heading only where it separates something: with no preferred country in\n // view it would head the whole list and divide nothing.\n const heading = firsts.length > 0 ? text.others : undefined;\n return [...firsts.map((e) => toOption(e, flags)), ...below.map((e) => toOption(e, flags, heading))];\n }, [top, others, q, text.others, flags]);\n\n // ── The lock ──────────────────────────────────────────────────────────────\n const reason = useCommitReason(commit, ownReason);\n const locked = hasMessage(reason);\n const inert = locked || Boolean(disabled);\n // A lock (or `disabled`) arriving while the list is up closes it — adjusted while\n // rendering, as the core adjusts its own query, so no frame shows a list that can\n // no longer be used.\n if (inert && open) setOpen(false);\n\n // ── The field ─────────────────────────────────────────────────────────────\n const generated = useId();\n const triggerId = id ?? generated;\n const listboxId = `${generated}-listbox`;\n const hintId = useId();\n const reasonId = 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 field = useComboboxFieldError(\n error,\n invalid || ariaInvalid === true || ariaInvalid === \"true\",\n // The caller's, then the standing advice, then (inside) the error — the order every\n // field keeps — and the lock's reason last, while there is one.\n mergeDescribedBy(ariaDescribedBy, textHint && hintId),\n );\n\n const code = normalizeCountryCode(value);\n const selectedName = code ? countryName(code, locale) : undefined;\n const emptyText = placeholder ?? (label === undefined ? text.country : \"\");\n const fieldName = typeof label === \"string\" ? label : text.country;\n const name =\n ariaLabel ??\n (selectedName !== undefined\n ? common.fieldValue(fieldName, selectedName)\n : placeholder\n ? common.fieldValue(fieldName, placeholder)\n : fieldName);\n\n const choose = (o: ComboOption<string>) => {\n if (inert) return;\n onChange(o.value);\n // Back to the trigger: the panel holding focus is about to unmount, and a keyboard\n // user who has answered this field should stand on it, ready to Tab on.\n closeToTrigger();\n };\n\n const trigger = (\n <button\n ref={triggerRef}\n id={triggerId}\n type=\"button\"\n // A closed choice that expands into the list below — the role every trigger\n // picker in the kit wears (see EntityCombobox), and the one that supports\n // `aria-invalid`.\n role=\"combobox\"\n aria-haspopup=\"listbox\"\n aria-controls={listboxId}\n aria-expanded={open}\n aria-label={name}\n aria-invalid={field.isInvalid || undefined}\n aria-required={ariaRequired}\n aria-describedby={mergeDescribedBy(field.describedBy, locked && reasonId)}\n // The focusable kind of disabled while locked (Button's rule): native `disabled`\n // would take the field out of the tab order, and the reason with it.\n disabled={locked ? undefined : disabled}\n aria-disabled={locked || undefined}\n onClick={(e) => {\n if (inert) {\n e.preventDefault();\n return;\n }\n setOpen((o) => !o);\n }}\n // Down/Up opens the list from the closed trigger, per the APG; Enter and Space\n // already do through the button's own click.\n onKeyDown={(e) => {\n if (inert) return;\n if (e.key === \"ArrowDown\" || e.key === \"ArrowUp\") {\n e.preventDefault();\n setOpen(true);\n }\n }}\n className={cn(\n FIELD_TRIGGER,\n // `peer` dims the floating label with a natively disabled trigger, as Select's.\n \"peer pe-9\",\n label !== undefined && FIELD_FLOATING_PAD,\n inert && \"cursor-not-allowed opacity-50\",\n field.isInvalid && FIELD_INVALID,\n )}\n >\n <span className=\"flex min-w-0 items-center gap-2\">\n {flags && code && <CurrencyFlag country={code.toLowerCase()} />}\n {/* A long name (\"Saint Vincent and the Grenadines\") truncates rather than\n widening the field: the kit is checked at 390px. */}\n <span className={cn(\"truncate\", selectedName === undefined && \"text-[var(--text-placeholder)]\")}>\n {selectedName ?? emptyText}\n </span>\n </span>\n <FieldChevron />\n </button>\n );\n\n const control = locked ? (\n // In a FRAGMENT, as Button does, so the Tooltip does not clone its bubble into the\n // description as well — the hidden copy is what `aria-describedby` points at.\n <Tooltip label={reason} className=\"flex w-full\">\n <>\n {trigger}\n <span id={reasonId} hidden>\n {reason}\n </span>\n </>\n </Tooltip>\n ) : (\n trigger\n );\n\n const labelHint = textHint ? undefined : hasMessage(hint) ? hint : undefined;\n const box =\n label !== undefined ? (\n <FloatingField htmlFor={triggerId} label={label} staticLabel hint={labelHint}>\n {control}\n </FloatingField>\n ) : labelHint !== undefined ? (\n // No label line to ride: the \"?\" goes at the field's end, outside the box, as on\n // an unlabelled Select.\n <div className=\"flex items-center gap-1.5\">\n <div className=\"relative min-w-0 flex-1\">{control}</div>\n <span className=\"flex shrink-0 items-center\">{labelHint}</span>\n </div>\n ) : (\n <div className=\"relative\">{control}</div>\n );\n\n return (\n // `rest` dresses the wrapper — a `data-tour` anchor, a test id. The name, the\n // description and the invalid state are on the trigger above.\n <div {...rest} className={className}>\n {box}\n {textHint && (\n <p id={hintId} className=\"mt-1 text-[11px] leading-tight text-[var(--text-muted)]\">\n {hint}\n </p>\n )}\n {field.errorEl}\n <ComboboxPanel\n // The core with the rows ranked above in place of its own filter's.\n core={{ ...core, results }}\n listboxId={listboxId}\n // On a phone the list is a full-screen sheet, which needs the field's own\n // name to say what it is asking for (live #200).\n sheetTitle={label ?? text.country}\n searchPlaceholder={text.search}\n isSelected={(v) => v === code}\n onChoose={choose}\n showCreate={false}\n onCreate={() => {}}\n createContent={null}\n />\n </div>\n );\n}\n"],"mappings":";AA4JkB,SAuOZ,UAvOY,KAuNZ,YAvNY;AA5JlB,SAAS,OAAO,eAAe;AAE/B,SAAS,UAAU;AACnB,SAAS,eAAe,aAAa,4BAA4B;AACjE,SAAS,cAAc,oBAAoB,eAAe,eAAe,qBAAqB;AAC9F,SAAS,eAAe;AACxB,SAAS,oBAAoB;AAC7B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,YAAY,wBAAwB;AAC7C,SAAS,uBAAuB;AAChC,SAAS,uBAAuB,cAAc,oBAAoB;AAmB3D,MAAM,gCAAqD;AAAA,EAChE,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,QAAQ;AACV;AAqFA,SAAS,KAAK,GAAmB;AAC/B,SAAO,EAAE,UAAU,KAAK,EAAE,QAAQ,WAAW,EAAE,EAAE,YAAY;AAC/D;AAWA,SAAS,KAAK,GAAU,GAAmB;AACzC,MAAI,EAAE,KAAK,YAAY,MAAM,EAAG,QAAO;AACvC,MAAI,EAAE,OAAO,WAAW,CAAC,EAAG,QAAO;AACnC,SAAO,EAAE,OAAO,SAAS,CAAC,IAAI,IAAI;AACpC;AAIA,SAAS,OAAO,SAAkB,GAAoB;AACpD,SAAO,QACJ,IAAI,CAAC,OAAO,EAAE,GAAG,GAAG,KAAK,GAAG,CAAC,EAAE,EAAE,EACjC,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC,EACtB,KAAK,CAAC,GAAG,MAAM,EAAE,IAAI,EAAE,CAAC,EACxB,IAAI,CAAC,MAAM,EAAE,CAAC;AACnB;AAEA,SAAS,SAAS,GAAU,OAAgB,OAAqC;AAC/E,SAAO;AAAA,IACL,OAAO,EAAE;AAAA,IACT,O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U;AAAA,OAC1D;AAAA,MAEA,oBAAC,SAAI,WAAU,YAAY,mBAAQ;AAGvC;AAAA;AAAA;AAAA,IAGE,qBAAC,SAAK,GAAG,MAAM,WACZ;AAAA;AAAA,MACA,YACC,oBAAC,OAAE,IAAI,QAAQ,WAAU,2DACtB,gBACH;AAAA,MAED,MAAM;AAAA,MACP;AAAA,QAAC;AAAA;AAAA,UAEC,MAAM,EAAE,GAAG,MAAM,QAAQ;AAAA,UACzB;AAAA,UAGA,YAAY,SAAS,KAAK;AAAA,UAC1B,mBAAmB,KAAK;AAAA,UACxB,YAAY,CAAC,MAAM,MAAM;AAAA,UACzB,UAAU;AAAA,UACV,YAAY;AAAA,UACZ,UAAU,MAAM;AAAA,UAAC;AAAA,UACjB,eAAe;AAAA;AAAA,MACjB;AAAA,OACF;AAAA;AAEJ;","names":["code","name"]}
|
|
1
|
+
{"version":3,"sources":["../../src/components/country-select.tsx"],"sourcesContent":["import { useCallback, useId, useMemo } from \"react\";\nimport type { ComponentPropsWithoutRef, ReactNode, Ref } from \"react\";\nimport { X } from \"lucide-react\";\nimport { cn } from \"../lib/cn\";\nimport { COUNTRY_CODES, countryName, normalizeCountryCode } from \"../lib/countries\";\nimport { FieldChevron, FIELD_FLOATING_PAD, FIELD_INVALID, FIELD_TRIGGER, FloatingField } from \"./ui\";\nimport { Tooltip } from \"./tooltip\";\nimport { CurrencyFlag } from \"./currency-select\";\nimport {\n ComboboxPanel,\n useComboboxCore,\n useComboboxFieldError,\n type ComboOption,\n} from \"./combobox-core\";\nimport { assignRef, hasMessage, mergeDescribedBy } from \"./choice-parts\";\nimport { useCommitReason } from \"./write-lock\";\nimport {\n DEFAULT_COMBOBOX_LABELS,\n DEFAULT_COMMON_LABELS,\n useKitLabels,\n useKitLocale,\n} from \"../i18n/kit-labels\";\n\n// ── Labels ────────────────────────────────────────────────────────────────────\n\n/** The words {@link CountrySelect} renders on its own behalf. The list's \"no results\",\n * \"loading\" and result-count announcements are the shared `combobox` namespace's,\n * as on every other searchable picker. */\nexport interface CountrySelectLabels {\n /** What the field is, when the caller gives no `label`: the first half of the\n * trigger's accessible name, the phone sheet's title, and the empty trigger's\n * text. */\n country: string;\n /** The search box in the open list. */\n search: string;\n /** The heading between the `preferred` countries and all the others. Shown only\n * when `preferred` puts something above it. */\n others: string;\n}\n\nexport const DEFAULT_COUNTRY_SELECT_LABELS: CountrySelectLabels = {\n country: \"Country\",\n search: \"Search country\",\n others: \"Other countries\",\n};\n\n// ── Props ─────────────────────────────────────────────────────────────────────\n\n/**\n * `onChange` is the kit's — \"a country was picked\", carrying its code — rather than\n * the div's form event. `id` and the `aria-*` wiring below go to the TRIGGER, which is\n * the control a reader meets; everything else in `rest` dresses the wrapper.\n *\n * `Clearable` follows `clearable`, the way {@link EntityCombobox}'s `C` follows its\n * `clearValue`: it is inferred from the prop, so `onChange` is `(code: string) => void`\n * for the field as it always was (`onChange={setCountry}` over a `string` state still\n * type-checks), and `(code: string | null) => void` once `clearable` is set — the\n * `null` of a clear cannot reach a handler that was never told about it.\n */\nexport interface CountrySelectProps<Clearable extends boolean = false>\n extends Omit<ComponentPropsWithoutRef<\"div\">, \"onChange\" | \"defaultValue\"> {\n /** The chosen country as an ISO 3166-1 alpha-2 code (\"CH\"), in either case;\n * `null`, `undefined` or `\"\"` when none is. A code outside the list still shows\n * its name — the list restricts what can be PICKED, not what can be shown. */\n value: string | null | undefined;\n /** A country was picked: its alpha-2 code, always upper-case. With `clearable`,\n * also `null`: the \"×\" (or Delete on the trigger) emptied the field. */\n onChange: (code: Clearable extends true ? string | null : string) => void;\n /**\n * Offer a clear \"×\" in place of the chevron while a country is chosen; it hands\n * `onChange` `null` (the kit's later list: an optional country — a contact's\n * nationality, a bank filter's \"any country\" — could be set but never unset again).\n *\n * The combobox family's clear, as {@link EntityCombobox} draws it: a pointer\n * shortcut inside the trigger, out of the tab order so it is not a second stop\n * between this field and the next, named by `clearLabel` (default: the\n * `combobox.clear` label every picker in the family shares). The keyboard way is\n * Delete or Backspace on the closed trigger. Not offered while `disabled` or locked\n * (`commit` / `disabledReason`): a clear is a change like any other.\n */\n clearable?: Clearable;\n /** The clear \"×\"'s accessible name. Wins over `combobox.clear` from the\n * {@link UiKitProvider}, as {@link EntityCombobox}'s `clearLabel` does. */\n clearLabel?: string;\n /**\n * The TRIGGER — the focusable `<button>` a reader meets — as a React 19 ref prop,\n * the way {@link MoneyField} takes its input's (kastlan: react-hook-form's\n * focus-on-error calls `focus()` on whatever `field.ref` was handed, and without a\n * ref the first field in error on an address form was never focused). See\n * `RhfCountrySelect`, which passes it.\n */\n ref?: Ref<HTMLButtonElement>;\n /**\n * Offer only these codes (any case; duplicates and malformed entries dropped).\n * Default: every ISO 3166-1 country, {@link COUNTRY_CODES}. Sorted by name either\n * way — the order given is not kept, because the reader looks a country up by its\n * name in their own language, and any other order is one they cannot predict.\n *\n * keksdose's bank picker offers the fifteen countries its banks are in\n * (DE AT CH FR IT ES NL BE PT PL SE DK FI GB IE). A code that is not in ISO's list\n * is allowed here on purpose: `XK` (Kosovo) is the app's decision, not the kit's.\n */\n countries?: readonly string[];\n /**\n * A short group shown FIRST, in the order given, above the alphabetical rest —\n * kastlan's CH, LI, DE, AT, FR, IT, the six countries most of its customers live\n * in, out of a list of 249. Each code appears once: a preferred country is not\n * repeated in the rest. The rest gets a heading (`labels.others`) so the boundary\n * is visible. Search keeps the split: matching preferred countries stay on top.\n * Codes not in `countries` are ignored — `countries` decides what can be picked.\n */\n preferred?: readonly string[];\n /**\n * Draw each country's flag as a flag-icons span (`fi fi-ch`), in the rows and on\n * the trigger. Default `false`, because the kit ships no flag stylesheet — the same\n * convention as `LanguageMenu`'s `country` and `CurrencySelect`: the host imports\n * `flag-icons/css/flag-icons.min.css`, and without it a flag is an empty box.\n */\n flags?: boolean;\n /** The floating label, as on every field. A string also names the trigger\n * (\"Country: Switzerland\"). */\n label?: ReactNode;\n /** As {@link Select}'s `hint`: plain TEXT is a caption under the field, attached\n * through `aria-describedby`; a {@link FieldHint} rides the label line (or the\n * field's end, when there is no label). */\n hint?: ReactNode;\n /** As {@link Input}'s `error`: rendered under the field, on the trigger's\n * `aria-describedby`, and implies `invalid`. */\n error?: ReactNode;\n /** Required and unanswered — {@link FIELD_INVALID}, as on every field. */\n invalid?: boolean;\n /** The empty trigger's text. Default: nothing when the field has a `label` or an\n * `aria-labelledby` (the label already says what goes here), else `labels.country`. */\n placeholder?: string;\n /** As on the other pickers: no focus, no list, the settled look. */\n disabled?: boolean;\n /**\n * Why the country cannot be changed — {@link Button}'s `disabledReason`, for a field\n * that saves itself. The trigger stays focusable and `aria-disabled`, the list does\n * not open and `onChange` never fires; the reason is in the kit {@link Tooltip} and\n * on the trigger's `aria-describedby`. Wins over `disabled`.\n */\n disabledReason?: ReactNode;\n /**\n * This select SAVES on change (a settings row with no Save button). Under a locked\n * {@link WriteLockProvider} it is locked the `disabledReason` way, with the lock's\n * reason. A country field inside a form that has its own Save stays editable under\n * the lock — leave this off there, and put `commit` on the Save.\n */\n commit?: boolean;\n /** The language the names are in. Default: the `<UiKitProvider locale>`, else\n * English (see {@link countryName}). */\n locale?: string;\n /** Per-instance overrides of {@link CountrySelectLabels}, over the provider's\n * `countrySelect` namespace, over English. */\n labels?: Partial<CountrySelectLabels>;\n /**\n * Name the trigger by an element of the caller's — a form's own label above the\n * field, which is how `RhfCountrySelect` names it. The trigger is then named by\n * that element AND the chosen country (two references, as {@link DatePicker}'s\n * trigger is named, so \"Country Switzerland\" needs no punctuation to translate),\n * instead of the composed \"label: country\". An `aria-label` still wins. Before\n * 0.23 this landed on the wrapper `<div>`, which has no role to be named.\n */\n \"aria-labelledby\"?: string;\n}\n\n/** Fold a name for search: no case, no accents — \"osterreich\" finds Österreich, \"cote\"\n * finds Côte d'Ivoire. A keyboard without the letter must still reach the country. */\nfunction fold(s: string): string {\n return s.normalize(\"NFD\").replace(/\\p{M}/gu, \"\").toLowerCase();\n}\n\ninterface Entry {\n code: string;\n name: string;\n folded: string;\n}\n\n/** How well `e` answers `q` (already folded): the code itself (a two-letter query\n * \"ch\" means Switzerland before it means Chad), then the start of the name, then\n * anywhere in it. `-1` for no match. */\nfunction rank(e: Entry, q: string): number {\n if (e.code.toLowerCase() === q) return 0;\n if (e.folded.startsWith(q)) return 1;\n return e.folded.includes(q) ? 2 : -1;\n}\n\n/** Best rank first; a stable sort, so equal ranks keep the collated (or preferred)\n * order they came in. */\nfunction search(entries: Entry[], q: string): Entry[] {\n return entries\n .map((e) => ({ e, r: rank(e, q) }))\n .filter((x) => x.r >= 0)\n .sort((a, b) => a.r - b.r)\n .map((x) => x.e);\n}\n\nfunction toOption(e: Entry, flags: boolean, group?: string): ComboOption<string> {\n return {\n value: e.code,\n label: e.name,\n icon: flags ? <CurrencyFlag country={e.code.toLowerCase()} /> : undefined,\n group,\n };\n}\n\nfunction collator(locale: string): Intl.Collator {\n try {\n return new Intl.Collator(locale);\n } catch {\n return new Intl.Collator();\n }\n}\n\n/**\n * A country picker: the value is the ISO 3166-1 alpha-2 code (\"CH\"), the names are the\n * runtime's own (`Intl.DisplayNames`) in the provider's locale, sorted by that\n * locale's collation. Requested by kastlan (customer and handover addresses, with its\n * six neighbours on top) and keksdose (the bank picker's fifteen countries) — both\n * apps carried a hand-written list of names in two languages.\n *\n * ## Built on the kit's searchable combobox\n *\n * 249 countries is not a menu, it is a lookup, and the list has to work on a phone. So\n * this is the entity pickers' machinery — `useComboboxCore` and `ComboboxPanel`, which\n * {@link EntityCombobox} is also made of — not a native `<select>`: the anchored panel\n * with a search box on a pointer device, the full-screen sheet with its own search box\n * on a phone (live #200), the same keyboard (APG listbox), the same announcements, the\n * same group headings. Only the trigger is this component's own, because the trigger\n * is where the write lock lives: `EntityCombobox`'s is a native `disabled` button,\n * and a locked field has to stay focusable to say why.\n *\n * The search is this component's own too: it folds accents and case (\"osterreich\"\n * finds Österreich), matches the code (\"ch\" ranks Switzerland first), and ranks\n * name-starts above name-contains. The panel is handed those rows in place of the\n * core's plain substring filter.\n *\n * Field anatomy as on every field: floating `label`, `hint`, `error`, `invalid`; the\n * trigger is named \"label: value\" as the other trigger pickers are.\n *\n * Since 0.23 it takes a `ref` to the trigger (react-hook-form's focus-on-error, kastlan)\n * and `clearable`, which hands `onChange` `null`.\n */\nexport function CountrySelect<Clearable extends boolean = false>({\n value,\n onChange,\n countries,\n preferred,\n flags = false,\n label,\n hint,\n error,\n invalid,\n placeholder,\n disabled,\n disabledReason: ownReason,\n commit,\n clearable,\n clearLabel,\n locale: localeProp,\n labels: labelsProp,\n className,\n id,\n ref,\n \"aria-label\": ariaLabel,\n \"aria-labelledby\": ariaLabelledBy,\n \"aria-describedby\": ariaDescribedBy,\n \"aria-invalid\": ariaInvalid,\n \"aria-required\": ariaRequired,\n ...rest\n}: CountrySelectProps<Clearable>) {\n const text = useKitLabels(\"countrySelect\", DEFAULT_COUNTRY_SELECT_LABELS, labelsProp);\n const common = useKitLabels(\"common\", DEFAULT_COMMON_LABELS);\n // The clear's name is the family's (`combobox.clear`), as on EntityCombobox; a prop\n // left `undefined` falls through to the provider rather than masking it.\n const comboText = useKitLabels(\"combobox\", DEFAULT_COMBOBOX_LABELS, { clear: clearLabel });\n // English without a locale — see `countryName`.\n const locale = useKitLocale(localeProp) ?? \"en\";\n\n // ── The list ──────────────────────────────────────────────────────────────\n // Keyed on the arrays' CONTENTS: `countries={[\"DE\", \"AT\"]}` written inline is a new\n // array every render, and resorting 249 names on every keystroke elsewhere in the\n // form is work for nothing.\n const countriesKey = countries?.join(\",\");\n const preferredKey = preferred?.join(\",\");\n const { top, rest: others } = useMemo(() => {\n const seen = new Set<string>();\n const pool: string[] = [];\n for (const raw of countriesKey !== undefined ? countriesKey.split(\",\") : COUNTRY_CODES) {\n const code = normalizeCountryCode(raw);\n if (code && !seen.has(code)) {\n seen.add(code);\n pool.push(code);\n }\n }\n const entry = (code: string): Entry => {\n const name = countryName(code, locale);\n return { code, name, folded: fold(name) };\n };\n const firsts: Entry[] = [];\n const picked = new Set<string>();\n for (const raw of preferredKey ? preferredKey.split(\",\") : []) {\n const code = normalizeCountryCode(raw);\n if (code && seen.has(code) && !picked.has(code)) {\n picked.add(code);\n firsts.push(entry(code));\n }\n }\n const compare = collator(locale).compare;\n const sorted = pool\n .filter((c) => !picked.has(c))\n .map(entry)\n .sort((a, b) => compare(a.name, b.name));\n return { top: firsts, rest: sorted };\n }, [countriesKey, preferredKey, locale]);\n\n // `filter: false` — the panel is handed the rows `search` ranks below instead of\n // the core's substring filter; the core still owns open, query, the highlighted row,\n // anchoring and dismissal.\n const allOptions = useMemo(\n () => [...top, ...others].map((e) => toOption(e, flags)),\n [top, others, flags],\n );\n const core = useComboboxCore<string>({ options: allOptions, filter: false });\n const { open, setOpen, query, triggerRef, closeToTrigger } = core;\n // The core anchors the panel to the trigger and hands focus back to it; the caller's\n // `ref` wants the same element. One callback feeds both.\n const setTrigger = useCallback(\n (el: HTMLButtonElement | null) => {\n triggerRef.current = el;\n assignRef(ref, el);\n },\n [ref, triggerRef],\n );\n\n const q = fold(query.trim());\n const results = useMemo(() => {\n const firsts = q ? search(top, q) : top;\n const below = q ? search(others, q) : others;\n // The heading only where it separates something: with no preferred country in\n // view it would head the whole list and divide nothing.\n const heading = firsts.length > 0 ? text.others : undefined;\n return [...firsts.map((e) => toOption(e, flags)), ...below.map((e) => toOption(e, flags, heading))];\n }, [top, others, q, text.others, flags]);\n\n // ── The lock ──────────────────────────────────────────────────────────────\n const reason = useCommitReason(commit, ownReason);\n const locked = hasMessage(reason);\n const inert = locked || Boolean(disabled);\n // A lock (or `disabled`) arriving while the list is up closes it — adjusted while\n // rendering, as the core adjusts its own query, so no frame shows a list that can\n // no longer be used.\n if (inert && open) setOpen(false);\n\n // ── The field ─────────────────────────────────────────────────────────────\n const generated = useId();\n const triggerId = id ?? generated;\n const listboxId = `${generated}-listbox`;\n const hintId = useId();\n const reasonId = 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 field = useComboboxFieldError(\n error,\n invalid || ariaInvalid === true || ariaInvalid === \"true\",\n // The caller's, then the standing advice, then (inside) the error — the order every\n // field keeps — and the lock's reason last, while there is one.\n mergeDescribedBy(ariaDescribedBy, textHint && hintId),\n );\n\n const code = normalizeCountryCode(value);\n const selectedName = code ? countryName(code, locale) : undefined;\n // A field named by a label of the caller's (`aria-labelledby`) is a labelled field too:\n // the label already says what goes here.\n const emptyText = placeholder ?? (label === undefined && !ariaLabelledBy ? text.country : \"\");\n const fieldName = typeof label === \"string\" ? label : text.country;\n const valueId = `${generated}-value`;\n // Named by the caller's element (a form's label) — then the shown text is the second\n // reference, as the composed name below has the value second; but only when it IS a\n // value or the caller's placeholder, never the `country` fallback word.\n const labelledBy =\n ariaLabel === undefined && ariaLabelledBy\n ? mergeDescribedBy(ariaLabelledBy, (selectedName !== undefined || Boolean(placeholder)) && valueId)\n : undefined;\n const name =\n labelledBy !== undefined\n ? undefined\n : (ariaLabel ??\n (selectedName !== undefined\n ? common.fieldValue(fieldName, selectedName)\n : placeholder\n ? common.fieldValue(fieldName, placeholder)\n : fieldName));\n\n const showClear = Boolean(clearable && code && !inert);\n // `onChange` widened to take the clear's `null` — its type says so once `clearable`\n // is set, and the clear is only ever offered then.\n const emit = onChange as (code: string | null) => void;\n const clear = () => {\n if (!showClear) return;\n emit(null);\n };\n\n const choose = (o: ComboOption<string>) => {\n if (inert) return;\n emit(o.value);\n // Back to the trigger: the panel holding focus is about to unmount, and a keyboard\n // user who has answered this field should stand on it, ready to Tab on.\n closeToTrigger();\n };\n\n const trigger = (\n <button\n ref={setTrigger}\n id={triggerId}\n type=\"button\"\n // A closed choice that expands into the list below — the role every trigger\n // picker in the kit wears (see EntityCombobox), and the one that supports\n // `aria-invalid`.\n role=\"combobox\"\n aria-haspopup=\"listbox\"\n aria-controls={listboxId}\n aria-expanded={open}\n aria-label={name}\n aria-labelledby={labelledBy}\n aria-invalid={field.isInvalid || undefined}\n aria-required={ariaRequired}\n aria-describedby={mergeDescribedBy(field.describedBy, locked && reasonId)}\n // The focusable kind of disabled while locked (Button's rule): native `disabled`\n // would take the field out of the tab order, and the reason with it.\n disabled={locked ? undefined : disabled}\n aria-disabled={locked || undefined}\n onClick={(e) => {\n if (inert) {\n e.preventDefault();\n return;\n }\n setOpen((o) => !o);\n }}\n // Down/Up opens the list from the closed trigger, per the APG; Enter and Space\n // already do through the button's own click.\n onKeyDown={(e) => {\n if (inert) return;\n if (e.key === \"ArrowDown\" || e.key === \"ArrowUp\") {\n e.preventDefault();\n setOpen(true);\n } else if (showClear && !open && (e.key === \"Delete\" || e.key === \"Backspace\")) {\n // The keyboard's clear: the \"×\" is out of the tab order (see `clearable`).\n e.preventDefault();\n clear();\n }\n }}\n className={cn(\n FIELD_TRIGGER,\n // `peer` dims the floating label with a natively disabled trigger, as Select's.\n \"peer pe-9\",\n label !== undefined && FIELD_FLOATING_PAD,\n inert && \"cursor-not-allowed opacity-50\",\n field.isInvalid && FIELD_INVALID,\n )}\n >\n <span className=\"flex min-w-0 items-center gap-2\">\n {flags && code && <CurrencyFlag country={code.toLowerCase()} />}\n {/* A long name (\"Saint Vincent and the Grenadines\") truncates rather than\n widening the field: the kit is checked at 390px. */}\n <span\n id={valueId}\n className={cn(\"truncate\", selectedName === undefined && \"text-[var(--text-placeholder)]\")}\n >\n {selectedName ?? emptyText}\n </span>\n </span>\n {showClear ? (\n /* eslint-disable-next-line jsx-a11y/click-events-have-key-events -- tabIndex -1 inside\n the trigger <button>, so it never holds focus and a key handler here could never\n fire; the keys go to the trigger, where Delete and Backspace clear. A pointer\n shortcut, as on EntityCombobox. */\n <span\n role=\"button\"\n tabIndex={-1}\n aria-label={comboText.clear}\n onClick={(e) => {\n e.stopPropagation();\n clear();\n }}\n className=\"absolute end-2 top-1/2 -translate-y-1/2 rounded p-0.5 text-[var(--text-placeholder)] hover:text-[var(--text-secondary)]\"\n >\n <X aria-hidden className=\"size-4\" />\n </span>\n ) : (\n <FieldChevron />\n )}\n </button>\n );\n\n const control = locked ? (\n // In a FRAGMENT, as Button does, so the Tooltip does not clone its bubble into the\n // description as well — the hidden copy is what `aria-describedby` points at.\n <Tooltip label={reason} className=\"flex w-full\">\n <>\n {trigger}\n <span id={reasonId} hidden>\n {reason}\n </span>\n </>\n </Tooltip>\n ) : (\n trigger\n );\n\n const labelHint = textHint ? undefined : hasMessage(hint) ? hint : undefined;\n const box =\n label !== undefined ? (\n <FloatingField htmlFor={triggerId} label={label} staticLabel hint={labelHint}>\n {control}\n </FloatingField>\n ) : labelHint !== undefined ? (\n // No label line to ride: the \"?\" goes at the field's end, outside the box, as on\n // an unlabelled Select.\n <div className=\"flex items-center gap-1.5\">\n <div className=\"relative min-w-0 flex-1\">{control}</div>\n <span className=\"flex shrink-0 items-center\">{labelHint}</span>\n </div>\n ) : (\n <div className=\"relative\">{control}</div>\n );\n\n return (\n // `rest` dresses the wrapper — a `data-tour` anchor, a test id. The name, the\n // description and the invalid state are on the trigger above.\n <div {...rest} className={className}>\n {box}\n {textHint && (\n <p id={hintId} className=\"mt-1 text-[11px] leading-tight text-[var(--text-muted)]\">\n {hint}\n </p>\n )}\n {field.errorEl}\n <ComboboxPanel\n // The core with the rows ranked above in place of its own filter's.\n core={{ ...core, results }}\n listboxId={listboxId}\n // On a phone the list is a full-screen sheet, which needs the field's own\n // name to say what it is asking for (live #200).\n sheetTitle={label ?? text.country}\n searchPlaceholder={text.search}\n isSelected={(v) => v === code}\n onChoose={choose}\n showCreate={false}\n onCreate={() => {}}\n createContent={null}\n />\n </div>\n );\n}\n"],"mappings":";AA0MkB,SA0SZ,UA1SY,KAoQZ,YApQY;AA1MlB,SAAS,aAAa,OAAO,eAAe;AAE5C,SAAS,SAAS;AAClB,SAAS,UAAU;AACnB,SAAS,eAAe,aAAa,4BAA4B;AACjE,SAAS,cAAc,oBAAoB,eAAe,eAAe,qBAAqB;AAC9F,SAAS,eAAe;AACxB,SAAS,oBAAoB;AAC7B;AAAA,EACE;AAAA,EACA;AAAA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
|
+
export { T as CurrentPasswordInput, U as CurrentPasswordInputLabels, V as CurrentPasswordInputProps, a3 as DEFAULT_DANGER_CONFIRM_LABELS, an as DangerConfirm, ao as DangerConfirmLabels, ap as DangerConfirmProps, aq as DangerConfirmValues, ar as DangerConsequence, cw as TypedConfirmField, cx as TypedConfirmFieldLabels, cy as TypedConfirmFieldProps, cz as TypedMatch, cP as typedMatches, d0 as usePromisePending } from '../feedback-DOwPu-Il.js';
|
|
3
|
+
import './tooltip.js';
|
|
4
|
+
import '../hooks/use-anchored-rect.js';
|
|
5
|
+
import '../lib/clipping.js';
|
|
3
6
|
import '../data-table-labels-B7OdnM0S.js';
|
|
4
7
|
import './data-table-sort.js';
|
|
5
8
|
import './swipeable-row.js';
|
|
@@ -9,9 +12,6 @@ import './popover.js';
|
|
|
9
12
|
import './chip.js';
|
|
10
13
|
import 'lucide-react';
|
|
11
14
|
import './field-sync.js';
|
|
12
|
-
import './tooltip.js';
|
|
13
|
-
import '../hooks/use-anchored-rect.js';
|
|
14
|
-
import '../lib/clipping.js';
|
|
15
15
|
import '../wizard/types.js';
|
|
16
16
|
import '../tour/tour.js';
|
|
17
17
|
import '../search/command-palette.js';
|
|
@@ -32,9 +32,6 @@ import './dialog-frame.js';
|
|
|
32
32
|
import './modal.js';
|
|
33
33
|
import '../hooks/use-search-param-state.js';
|
|
34
34
|
import './measured-grid.js';
|
|
35
|
-
import '../feedback-attachment-NhUm7Zga.js';
|
|
36
|
-
import '../feedback/feedback-thread.js';
|
|
37
|
-
import '../feedback/feedback-inbox.js';
|
|
38
35
|
import './account-settings-labels.js';
|
|
39
36
|
import './floating-panel.js';
|
|
40
37
|
import './bulk-action-bar.js';
|
|
@@ -64,3 +61,7 @@ import './inline-edit-field.js';
|
|
|
64
61
|
import '../lib/iban.js';
|
|
65
62
|
import '../lib/phone.js';
|
|
66
63
|
import './sign-chip.js';
|
|
64
|
+
import './column-mapper.js';
|
|
65
|
+
import '../lib/column-mapping.js';
|
|
66
|
+
import '../lib/table-text.js';
|
|
67
|
+
import './field-parts.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { forwardRef, useCallback, useEffect, useId, useRef, useState } from "react";
|
|
3
|
+
import { Children, forwardRef, useCallback, useEffect, useId, useRef, useState } from "react";
|
|
4
4
|
import { cn } from "../lib/cn.js";
|
|
5
5
|
import { useKitLabels } from "../i18n/kit-labels.js";
|
|
6
6
|
import { Button, Input, Label, Spinner } from "./ui.js";
|
|
@@ -128,8 +128,32 @@ const DEFAULT_DANGER_CONFIRM_LABELS = {
|
|
|
128
128
|
prompt: "This cannot be undone.",
|
|
129
129
|
password: "Password",
|
|
130
130
|
phrase: (phrase) => `Type \u201C${phrase}\u201D to confirm`,
|
|
131
|
-
acknowledge: "I have read what this does and want to continue."
|
|
131
|
+
acknowledge: "I have read what this does and want to continue.",
|
|
132
|
+
needsPhrase: (phrase) => `Type \u201C${phrase}\u201D to confirm`,
|
|
133
|
+
needsAcknowledge: "Tick the box to confirm",
|
|
134
|
+
needsPassword: "Enter your password to confirm"
|
|
132
135
|
};
|
|
136
|
+
const SLOT_FIELD = [
|
|
137
|
+
'input:not([type="hidden"])',
|
|
138
|
+
"select",
|
|
139
|
+
"textarea",
|
|
140
|
+
...["combobox", "listbox", "radio", "checkbox", "switch", "slider", "spinbutton", "textbox"].map(
|
|
141
|
+
(role) => `[role="${role}"]`
|
|
142
|
+
)
|
|
143
|
+
].map((selector) => `${selector}:not(:disabled):not([tabindex="-1"]):not([aria-hidden="true"])`).join(", ");
|
|
144
|
+
function firstSlotField(slot) {
|
|
145
|
+
if (!slot) return null;
|
|
146
|
+
for (const el of slot.querySelectorAll(SLOT_FIELD)) {
|
|
147
|
+
if (el.closest("[hidden], [inert]")) continue;
|
|
148
|
+
if (el instanceof HTMLInputElement && el.type === "radio" && !el.checked && el.name) {
|
|
149
|
+
const group = el.form?.elements.namedItem(el.name);
|
|
150
|
+
const checked = group instanceof RadioNodeList && Array.from(group).some((r) => r instanceof HTMLInputElement && r.checked);
|
|
151
|
+
if (checked) continue;
|
|
152
|
+
}
|
|
153
|
+
return el;
|
|
154
|
+
}
|
|
155
|
+
return null;
|
|
156
|
+
}
|
|
133
157
|
function DangerConfirm({
|
|
134
158
|
onConfirm,
|
|
135
159
|
requirePassword,
|
|
@@ -139,6 +163,9 @@ function DangerConfirm({
|
|
|
139
163
|
phraseMatch = "trim",
|
|
140
164
|
prompt,
|
|
141
165
|
tone = "danger",
|
|
166
|
+
confirmVariant,
|
|
167
|
+
confirmDisabledReason,
|
|
168
|
+
children,
|
|
142
169
|
armLabel,
|
|
143
170
|
confirmLabel,
|
|
144
171
|
busy: busyProp,
|
|
@@ -165,8 +192,11 @@ function DangerConfirm({
|
|
|
165
192
|
const reasonId = useId();
|
|
166
193
|
const armId = useId();
|
|
167
194
|
const cancelId = useId();
|
|
195
|
+
const confirmId = useId();
|
|
168
196
|
const firstFieldRef = useRef(null);
|
|
197
|
+
const slotRef = useRef(null);
|
|
169
198
|
const moveFocus = useRef(false);
|
|
199
|
+
const confirmed = useRef(false);
|
|
170
200
|
const [wasArmed, setWasArmed] = useState(armed);
|
|
171
201
|
if (wasArmed !== armed) {
|
|
172
202
|
setWasArmed(armed);
|
|
@@ -184,12 +214,27 @@ function DangerConfirm({
|
|
|
184
214
|
moveFocus.current = false;
|
|
185
215
|
if (!changed) return;
|
|
186
216
|
if (armed) {
|
|
187
|
-
if (byUser)
|
|
217
|
+
if (byUser) {
|
|
218
|
+
(firstSlotField(slotRef.current) ?? firstFieldRef.current ?? document.getElementById(cancelId))?.focus();
|
|
219
|
+
}
|
|
188
220
|
return;
|
|
189
221
|
}
|
|
222
|
+
confirmed.current = false;
|
|
190
223
|
const lost = document.activeElement === null || document.activeElement === document.body;
|
|
191
224
|
if (byUser || lost) document.getElementById(armId)?.focus();
|
|
192
225
|
}, [armed, armId, cancelId]);
|
|
226
|
+
const wasBusy = useRef(busy);
|
|
227
|
+
useEffect(() => {
|
|
228
|
+
const settled = wasBusy.current && !busy;
|
|
229
|
+
wasBusy.current = busy;
|
|
230
|
+
if (!settled) return;
|
|
231
|
+
const ours = confirmed.current;
|
|
232
|
+
confirmed.current = false;
|
|
233
|
+
if (!ours || !armed) return;
|
|
234
|
+
if (document.activeElement === null || document.activeElement === document.body) {
|
|
235
|
+
document.getElementById(confirmId)?.focus();
|
|
236
|
+
}
|
|
237
|
+
}, [busy, armed, confirmId]);
|
|
193
238
|
const setArmed = (next) => {
|
|
194
239
|
moveFocus.current = true;
|
|
195
240
|
if (armedProp === void 0) setArmedState(next);
|
|
@@ -201,11 +246,21 @@ function DangerConfirm({
|
|
|
201
246
|
const passwordOk = !requirePassword || password !== "";
|
|
202
247
|
const phraseOk = phrase === void 0 || typedMatches(typed, phrase, phraseMatch);
|
|
203
248
|
const acknowledgeOk = !asksAcknowledge || acknowledged;
|
|
204
|
-
const
|
|
249
|
+
const callerHeld = hasContent(confirmDisabledReason);
|
|
250
|
+
const hasFields = Children.toArray(children).some(hasContent);
|
|
251
|
+
const canConfirm = passwordOk && phraseOk && acknowledgeOk && !callerHeld && !busy;
|
|
252
|
+
const guardReason = !acknowledgeOk ? labels.needsAcknowledge : !phraseOk ? typeof labels.needsPhrase === "function" ? labels.needsPhrase(phrase ?? "") : labels.needsPhrase : !passwordOk ? labels.needsPassword : void 0;
|
|
253
|
+
const confirmReason = locked ? lockedReason : busy ? void 0 : callerHeld ? confirmDisabledReason : guardReason;
|
|
205
254
|
const submit = (e) => {
|
|
206
255
|
e.preventDefault();
|
|
207
256
|
if (!canConfirm || locked) return;
|
|
208
|
-
|
|
257
|
+
const values = {
|
|
258
|
+
...phrase !== void 0 && { typed: phraseMatch === "exact" ? typed : typed.trim() },
|
|
259
|
+
...requirePassword && { password },
|
|
260
|
+
...asksAcknowledge && { acknowledged: true }
|
|
261
|
+
};
|
|
262
|
+
confirmed.current = true;
|
|
263
|
+
run(onConfirm(values.password, values), () => setArmed(false));
|
|
209
264
|
};
|
|
210
265
|
const firstField = asksAcknowledge ? "acknowledge" : phrase !== void 0 ? "phrase" : "password";
|
|
211
266
|
const lines = (consequences ?? []).map(
|
|
@@ -255,6 +310,7 @@ function DangerConfirm({
|
|
|
255
310
|
children: [
|
|
256
311
|
/* @__PURE__ */ jsx("p", { id: promptId, className: cn("text-xs font-medium", toneText), children: prompt ?? labels.prompt }),
|
|
257
312
|
lines.length > 0 && /* @__PURE__ */ jsx("ul", { id: consequencesId, className: "list-disc space-y-1 ps-5 text-xs text-[var(--text-secondary)]", children: lines.map((line) => /* @__PURE__ */ jsx("li", { className: line.severe ? "text-[var(--danger)]" : void 0, children: line.text }, line.key)) }),
|
|
313
|
+
hasFields && /* @__PURE__ */ jsx("div", { ref: slotRef, className: "space-y-2", children }),
|
|
258
314
|
asksAcknowledge && /* @__PURE__ */ jsx(
|
|
259
315
|
Checkbox,
|
|
260
316
|
{
|
|
@@ -293,10 +349,11 @@ function DangerConfirm({
|
|
|
293
349
|
/* @__PURE__ */ jsxs(
|
|
294
350
|
Button,
|
|
295
351
|
{
|
|
352
|
+
id: confirmId,
|
|
296
353
|
type: "submit",
|
|
297
|
-
variant: tone === "warning" ? "primary" : "danger",
|
|
354
|
+
variant: confirmVariant ?? (tone === "warning" ? "primary" : "danger"),
|
|
298
355
|
disabled: !canConfirm,
|
|
299
|
-
disabledReason:
|
|
356
|
+
disabledReason: confirmReason,
|
|
300
357
|
"aria-busy": busy || void 0,
|
|
301
358
|
children: [
|
|
302
359
|
busy && /* @__PURE__ */ jsx(Spinner, { label: null, className: "h-4 w-4" }),
|