@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
|
@@ -2,10 +2,10 @@ import { createContext, useCallback, useContext, useEffect, useRef, useState } f
|
|
|
2
2
|
import type { ReactNode } from "react";
|
|
3
3
|
|
|
4
4
|
import { useKitLabels } from "../i18n/kit-labels";
|
|
5
|
-
import { typedMatches } from "./danger-confirm";
|
|
5
|
+
import { TypedConfirmField, typedMatches } from "./danger-confirm";
|
|
6
6
|
import type { TypedMatch } from "./danger-confirm";
|
|
7
7
|
import { DialogFrame } from "./dialog-frame";
|
|
8
|
-
import { Button
|
|
8
|
+
import { Button } from "./ui";
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* The `confirmDialog` namespace of `<UiKitProvider labels>`: the two buttons' fallback
|
|
@@ -300,15 +300,19 @@ function ConfirmDialogView({
|
|
|
300
300
|
confirmRef.current?.click();
|
|
301
301
|
}}
|
|
302
302
|
>
|
|
303
|
-
|
|
303
|
+
{/* The kit's one typed-confirmation field (0.23), DangerConfirm's too: the
|
|
304
|
+
keyboard told to leave the text alone, `data-matched` on the input. The
|
|
305
|
+
label is this namespace's (`confirmDialog.typed`), and `placeholder=""`
|
|
306
|
+
keeps out the `dangerConfirm.phrasePlaceholder` a provider may set for
|
|
307
|
+
the tile — this field never had one. */}
|
|
308
|
+
<TypedConfirmField
|
|
304
309
|
ref={typedRef}
|
|
310
|
+
target={target}
|
|
311
|
+
match={request.typedMatch ?? "caseless"}
|
|
305
312
|
label={typedLabel}
|
|
313
|
+
placeholder=""
|
|
306
314
|
value={typed}
|
|
307
|
-
|
|
308
|
-
autoCapitalize="off"
|
|
309
|
-
autoCorrect="off"
|
|
310
|
-
spellCheck={false}
|
|
311
|
-
onChange={(e) => setTyped(e.target.value)}
|
|
315
|
+
onValueChange={setTyped}
|
|
312
316
|
/>
|
|
313
317
|
</form>
|
|
314
318
|
)}
|
|
@@ -0,0 +1,556 @@
|
|
|
1
|
+
import { useCallback, useId, useMemo } from "react";
|
|
2
|
+
import type { ComponentPropsWithoutRef, ReactNode, Ref } from "react";
|
|
3
|
+
import { X } from "lucide-react";
|
|
4
|
+
import { cn } from "../lib/cn";
|
|
5
|
+
import { COUNTRY_CODES, countryName, normalizeCountryCode } from "../lib/countries";
|
|
6
|
+
import { FieldChevron, FIELD_FLOATING_PAD, FIELD_INVALID, FIELD_TRIGGER, FloatingField } from "./ui";
|
|
7
|
+
import { Tooltip } from "./tooltip";
|
|
8
|
+
import { CurrencyFlag } from "./currency-select";
|
|
9
|
+
import {
|
|
10
|
+
ComboboxPanel,
|
|
11
|
+
useComboboxCore,
|
|
12
|
+
useComboboxFieldError,
|
|
13
|
+
type ComboOption,
|
|
14
|
+
} from "./combobox-core";
|
|
15
|
+
import { assignRef, hasMessage, mergeDescribedBy } from "./choice-parts";
|
|
16
|
+
import { useCommitReason } from "./write-lock";
|
|
17
|
+
import {
|
|
18
|
+
DEFAULT_COMBOBOX_LABELS,
|
|
19
|
+
DEFAULT_COMMON_LABELS,
|
|
20
|
+
useKitLabels,
|
|
21
|
+
useKitLocale,
|
|
22
|
+
} from "../i18n/kit-labels";
|
|
23
|
+
|
|
24
|
+
// ── Labels ────────────────────────────────────────────────────────────────────
|
|
25
|
+
|
|
26
|
+
/** The words {@link CountrySelect} renders on its own behalf. The list's "no results",
|
|
27
|
+
* "loading" and result-count announcements are the shared `combobox` namespace's,
|
|
28
|
+
* as on every other searchable picker. */
|
|
29
|
+
export interface CountrySelectLabels {
|
|
30
|
+
/** What the field is, when the caller gives no `label`: the first half of the
|
|
31
|
+
* trigger's accessible name, the phone sheet's title, and the empty trigger's
|
|
32
|
+
* text. */
|
|
33
|
+
country: string;
|
|
34
|
+
/** The search box in the open list. */
|
|
35
|
+
search: string;
|
|
36
|
+
/** The heading between the `preferred` countries and all the others. Shown only
|
|
37
|
+
* when `preferred` puts something above it. */
|
|
38
|
+
others: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export const DEFAULT_COUNTRY_SELECT_LABELS: CountrySelectLabels = {
|
|
42
|
+
country: "Country",
|
|
43
|
+
search: "Search country",
|
|
44
|
+
others: "Other countries",
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
// ── Props ─────────────────────────────────────────────────────────────────────
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* `onChange` is the kit's — "a country was picked", carrying its code — rather than
|
|
51
|
+
* the div's form event. `id` and the `aria-*` wiring below go to the TRIGGER, which is
|
|
52
|
+
* the control a reader meets; everything else in `rest` dresses the wrapper.
|
|
53
|
+
*
|
|
54
|
+
* `Clearable` follows `clearable`, the way {@link EntityCombobox}'s `C` follows its
|
|
55
|
+
* `clearValue`: it is inferred from the prop, so `onChange` is `(code: string) => void`
|
|
56
|
+
* for the field as it always was (`onChange={setCountry}` over a `string` state still
|
|
57
|
+
* type-checks), and `(code: string | null) => void` once `clearable` is set — the
|
|
58
|
+
* `null` of a clear cannot reach a handler that was never told about it.
|
|
59
|
+
*/
|
|
60
|
+
export interface CountrySelectProps<Clearable extends boolean = false>
|
|
61
|
+
extends Omit<ComponentPropsWithoutRef<"div">, "onChange" | "defaultValue"> {
|
|
62
|
+
/** The chosen country as an ISO 3166-1 alpha-2 code ("CH"), in either case;
|
|
63
|
+
* `null`, `undefined` or `""` when none is. A code outside the list still shows
|
|
64
|
+
* its name — the list restricts what can be PICKED, not what can be shown. */
|
|
65
|
+
value: string | null | undefined;
|
|
66
|
+
/** A country was picked: its alpha-2 code, always upper-case. With `clearable`,
|
|
67
|
+
* also `null`: the "×" (or Delete on the trigger) emptied the field. */
|
|
68
|
+
onChange: (code: Clearable extends true ? string | null : string) => void;
|
|
69
|
+
/**
|
|
70
|
+
* Offer a clear "×" in place of the chevron while a country is chosen; it hands
|
|
71
|
+
* `onChange` `null` (the kit's later list: an optional country — a contact's
|
|
72
|
+
* nationality, a bank filter's "any country" — could be set but never unset again).
|
|
73
|
+
*
|
|
74
|
+
* The combobox family's clear, as {@link EntityCombobox} draws it: a pointer
|
|
75
|
+
* shortcut inside the trigger, out of the tab order so it is not a second stop
|
|
76
|
+
* between this field and the next, named by `clearLabel` (default: the
|
|
77
|
+
* `combobox.clear` label every picker in the family shares). The keyboard way is
|
|
78
|
+
* Delete or Backspace on the closed trigger. Not offered while `disabled` or locked
|
|
79
|
+
* (`commit` / `disabledReason`): a clear is a change like any other.
|
|
80
|
+
*/
|
|
81
|
+
clearable?: Clearable;
|
|
82
|
+
/** The clear "×"'s accessible name. Wins over `combobox.clear` from the
|
|
83
|
+
* {@link UiKitProvider}, as {@link EntityCombobox}'s `clearLabel` does. */
|
|
84
|
+
clearLabel?: string;
|
|
85
|
+
/**
|
|
86
|
+
* The TRIGGER — the focusable `<button>` a reader meets — as a React 19 ref prop,
|
|
87
|
+
* the way {@link MoneyField} takes its input's (kastlan: react-hook-form's
|
|
88
|
+
* focus-on-error calls `focus()` on whatever `field.ref` was handed, and without a
|
|
89
|
+
* ref the first field in error on an address form was never focused). See
|
|
90
|
+
* `RhfCountrySelect`, which passes it.
|
|
91
|
+
*/
|
|
92
|
+
ref?: Ref<HTMLButtonElement>;
|
|
93
|
+
/**
|
|
94
|
+
* Offer only these codes (any case; duplicates and malformed entries dropped).
|
|
95
|
+
* Default: every ISO 3166-1 country, {@link COUNTRY_CODES}. Sorted by name either
|
|
96
|
+
* way — the order given is not kept, because the reader looks a country up by its
|
|
97
|
+
* name in their own language, and any other order is one they cannot predict.
|
|
98
|
+
*
|
|
99
|
+
* keksdose's bank picker offers the fifteen countries its banks are in
|
|
100
|
+
* (DE AT CH FR IT ES NL BE PT PL SE DK FI GB IE). A code that is not in ISO's list
|
|
101
|
+
* is allowed here on purpose: `XK` (Kosovo) is the app's decision, not the kit's.
|
|
102
|
+
*/
|
|
103
|
+
countries?: readonly string[];
|
|
104
|
+
/**
|
|
105
|
+
* A short group shown FIRST, in the order given, above the alphabetical rest —
|
|
106
|
+
* kastlan's CH, LI, DE, AT, FR, IT, the six countries most of its customers live
|
|
107
|
+
* in, out of a list of 249. Each code appears once: a preferred country is not
|
|
108
|
+
* repeated in the rest. The rest gets a heading (`labels.others`) so the boundary
|
|
109
|
+
* is visible. Search keeps the split: matching preferred countries stay on top.
|
|
110
|
+
* Codes not in `countries` are ignored — `countries` decides what can be picked.
|
|
111
|
+
*/
|
|
112
|
+
preferred?: readonly string[];
|
|
113
|
+
/**
|
|
114
|
+
* Draw each country's flag as a flag-icons span (`fi fi-ch`), in the rows and on
|
|
115
|
+
* the trigger. Default `false`, because the kit ships no flag stylesheet — the same
|
|
116
|
+
* convention as `LanguageMenu`'s `country` and `CurrencySelect`: the host imports
|
|
117
|
+
* `flag-icons/css/flag-icons.min.css`, and without it a flag is an empty box.
|
|
118
|
+
*/
|
|
119
|
+
flags?: boolean;
|
|
120
|
+
/** The floating label, as on every field. A string also names the trigger
|
|
121
|
+
* ("Country: Switzerland"). */
|
|
122
|
+
label?: ReactNode;
|
|
123
|
+
/** As {@link Select}'s `hint`: plain TEXT is a caption under the field, attached
|
|
124
|
+
* through `aria-describedby`; a {@link FieldHint} rides the label line (or the
|
|
125
|
+
* field's end, when there is no label). */
|
|
126
|
+
hint?: ReactNode;
|
|
127
|
+
/** As {@link Input}'s `error`: rendered under the field, on the trigger's
|
|
128
|
+
* `aria-describedby`, and implies `invalid`. */
|
|
129
|
+
error?: ReactNode;
|
|
130
|
+
/** Required and unanswered — {@link FIELD_INVALID}, as on every field. */
|
|
131
|
+
invalid?: boolean;
|
|
132
|
+
/** The empty trigger's text. Default: nothing when the field has a `label` or an
|
|
133
|
+
* `aria-labelledby` (the label already says what goes here), else `labels.country`. */
|
|
134
|
+
placeholder?: string;
|
|
135
|
+
/** As on the other pickers: no focus, no list, the settled look. */
|
|
136
|
+
disabled?: boolean;
|
|
137
|
+
/**
|
|
138
|
+
* Why the country cannot be changed — {@link Button}'s `disabledReason`, for a field
|
|
139
|
+
* that saves itself. The trigger stays focusable and `aria-disabled`, the list does
|
|
140
|
+
* not open and `onChange` never fires; the reason is in the kit {@link Tooltip} and
|
|
141
|
+
* on the trigger's `aria-describedby`. Wins over `disabled`.
|
|
142
|
+
*/
|
|
143
|
+
disabledReason?: ReactNode;
|
|
144
|
+
/**
|
|
145
|
+
* This select SAVES on change (a settings row with no Save button). Under a locked
|
|
146
|
+
* {@link WriteLockProvider} it is locked the `disabledReason` way, with the lock's
|
|
147
|
+
* reason. A country field inside a form that has its own Save stays editable under
|
|
148
|
+
* the lock — leave this off there, and put `commit` on the Save.
|
|
149
|
+
*/
|
|
150
|
+
commit?: boolean;
|
|
151
|
+
/** The language the names are in. Default: the `<UiKitProvider locale>`, else
|
|
152
|
+
* English (see {@link countryName}). */
|
|
153
|
+
locale?: string;
|
|
154
|
+
/** Per-instance overrides of {@link CountrySelectLabels}, over the provider's
|
|
155
|
+
* `countrySelect` namespace, over English. */
|
|
156
|
+
labels?: Partial<CountrySelectLabels>;
|
|
157
|
+
/**
|
|
158
|
+
* Name the trigger by an element of the caller's — a form's own label above the
|
|
159
|
+
* field, which is how `RhfCountrySelect` names it. The trigger is then named by
|
|
160
|
+
* that element AND the chosen country (two references, as {@link DatePicker}'s
|
|
161
|
+
* trigger is named, so "Country Switzerland" needs no punctuation to translate),
|
|
162
|
+
* instead of the composed "label: country". An `aria-label` still wins. Before
|
|
163
|
+
* 0.23 this landed on the wrapper `<div>`, which has no role to be named.
|
|
164
|
+
*/
|
|
165
|
+
"aria-labelledby"?: string;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** Fold a name for search: no case, no accents — "osterreich" finds Österreich, "cote"
|
|
169
|
+
* finds Côte d'Ivoire. A keyboard without the letter must still reach the country. */
|
|
170
|
+
function fold(s: string): string {
|
|
171
|
+
return s.normalize("NFD").replace(/\p{M}/gu, "").toLowerCase();
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
interface Entry {
|
|
175
|
+
code: string;
|
|
176
|
+
name: string;
|
|
177
|
+
folded: string;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/** How well `e` answers `q` (already folded): the code itself (a two-letter query
|
|
181
|
+
* "ch" means Switzerland before it means Chad), then the start of the name, then
|
|
182
|
+
* anywhere in it. `-1` for no match. */
|
|
183
|
+
function rank(e: Entry, q: string): number {
|
|
184
|
+
if (e.code.toLowerCase() === q) return 0;
|
|
185
|
+
if (e.folded.startsWith(q)) return 1;
|
|
186
|
+
return e.folded.includes(q) ? 2 : -1;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/** Best rank first; a stable sort, so equal ranks keep the collated (or preferred)
|
|
190
|
+
* order they came in. */
|
|
191
|
+
function search(entries: Entry[], q: string): Entry[] {
|
|
192
|
+
return entries
|
|
193
|
+
.map((e) => ({ e, r: rank(e, q) }))
|
|
194
|
+
.filter((x) => x.r >= 0)
|
|
195
|
+
.sort((a, b) => a.r - b.r)
|
|
196
|
+
.map((x) => x.e);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function toOption(e: Entry, flags: boolean, group?: string): ComboOption<string> {
|
|
200
|
+
return {
|
|
201
|
+
value: e.code,
|
|
202
|
+
label: e.name,
|
|
203
|
+
icon: flags ? <CurrencyFlag country={e.code.toLowerCase()} /> : undefined,
|
|
204
|
+
group,
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
function collator(locale: string): Intl.Collator {
|
|
209
|
+
try {
|
|
210
|
+
return new Intl.Collator(locale);
|
|
211
|
+
} catch {
|
|
212
|
+
return new Intl.Collator();
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* A country picker: the value is the ISO 3166-1 alpha-2 code ("CH"), the names are the
|
|
218
|
+
* runtime's own (`Intl.DisplayNames`) in the provider's locale, sorted by that
|
|
219
|
+
* locale's collation. Requested by kastlan (customer and handover addresses, with its
|
|
220
|
+
* six neighbours on top) and keksdose (the bank picker's fifteen countries) — both
|
|
221
|
+
* apps carried a hand-written list of names in two languages.
|
|
222
|
+
*
|
|
223
|
+
* ## Built on the kit's searchable combobox
|
|
224
|
+
*
|
|
225
|
+
* 249 countries is not a menu, it is a lookup, and the list has to work on a phone. So
|
|
226
|
+
* this is the entity pickers' machinery — `useComboboxCore` and `ComboboxPanel`, which
|
|
227
|
+
* {@link EntityCombobox} is also made of — not a native `<select>`: the anchored panel
|
|
228
|
+
* with a search box on a pointer device, the full-screen sheet with its own search box
|
|
229
|
+
* on a phone (live #200), the same keyboard (APG listbox), the same announcements, the
|
|
230
|
+
* same group headings. Only the trigger is this component's own, because the trigger
|
|
231
|
+
* is where the write lock lives: `EntityCombobox`'s is a native `disabled` button,
|
|
232
|
+
* and a locked field has to stay focusable to say why.
|
|
233
|
+
*
|
|
234
|
+
* The search is this component's own too: it folds accents and case ("osterreich"
|
|
235
|
+
* finds Österreich), matches the code ("ch" ranks Switzerland first), and ranks
|
|
236
|
+
* name-starts above name-contains. The panel is handed those rows in place of the
|
|
237
|
+
* core's plain substring filter.
|
|
238
|
+
*
|
|
239
|
+
* Field anatomy as on every field: floating `label`, `hint`, `error`, `invalid`; the
|
|
240
|
+
* trigger is named "label: value" as the other trigger pickers are.
|
|
241
|
+
*
|
|
242
|
+
* Since 0.23 it takes a `ref` to the trigger (react-hook-form's focus-on-error, kastlan)
|
|
243
|
+
* and `clearable`, which hands `onChange` `null`.
|
|
244
|
+
*/
|
|
245
|
+
export function CountrySelect<Clearable extends boolean = false>({
|
|
246
|
+
value,
|
|
247
|
+
onChange,
|
|
248
|
+
countries,
|
|
249
|
+
preferred,
|
|
250
|
+
flags = false,
|
|
251
|
+
label,
|
|
252
|
+
hint,
|
|
253
|
+
error,
|
|
254
|
+
invalid,
|
|
255
|
+
placeholder,
|
|
256
|
+
disabled,
|
|
257
|
+
disabledReason: ownReason,
|
|
258
|
+
commit,
|
|
259
|
+
clearable,
|
|
260
|
+
clearLabel,
|
|
261
|
+
locale: localeProp,
|
|
262
|
+
labels: labelsProp,
|
|
263
|
+
className,
|
|
264
|
+
id,
|
|
265
|
+
ref,
|
|
266
|
+
"aria-label": ariaLabel,
|
|
267
|
+
"aria-labelledby": ariaLabelledBy,
|
|
268
|
+
"aria-describedby": ariaDescribedBy,
|
|
269
|
+
"aria-invalid": ariaInvalid,
|
|
270
|
+
"aria-required": ariaRequired,
|
|
271
|
+
...rest
|
|
272
|
+
}: CountrySelectProps<Clearable>) {
|
|
273
|
+
const text = useKitLabels("countrySelect", DEFAULT_COUNTRY_SELECT_LABELS, labelsProp);
|
|
274
|
+
const common = useKitLabels("common", DEFAULT_COMMON_LABELS);
|
|
275
|
+
// The clear's name is the family's (`combobox.clear`), as on EntityCombobox; a prop
|
|
276
|
+
// left `undefined` falls through to the provider rather than masking it.
|
|
277
|
+
const comboText = useKitLabels("combobox", DEFAULT_COMBOBOX_LABELS, { clear: clearLabel });
|
|
278
|
+
// English without a locale — see `countryName`.
|
|
279
|
+
const locale = useKitLocale(localeProp) ?? "en";
|
|
280
|
+
|
|
281
|
+
// ── The list ──────────────────────────────────────────────────────────────
|
|
282
|
+
// Keyed on the arrays' CONTENTS: `countries={["DE", "AT"]}` written inline is a new
|
|
283
|
+
// array every render, and resorting 249 names on every keystroke elsewhere in the
|
|
284
|
+
// form is work for nothing.
|
|
285
|
+
const countriesKey = countries?.join(",");
|
|
286
|
+
const preferredKey = preferred?.join(",");
|
|
287
|
+
const { top, rest: others } = useMemo(() => {
|
|
288
|
+
const seen = new Set<string>();
|
|
289
|
+
const pool: string[] = [];
|
|
290
|
+
for (const raw of countriesKey !== undefined ? countriesKey.split(",") : COUNTRY_CODES) {
|
|
291
|
+
const code = normalizeCountryCode(raw);
|
|
292
|
+
if (code && !seen.has(code)) {
|
|
293
|
+
seen.add(code);
|
|
294
|
+
pool.push(code);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
const entry = (code: string): Entry => {
|
|
298
|
+
const name = countryName(code, locale);
|
|
299
|
+
return { code, name, folded: fold(name) };
|
|
300
|
+
};
|
|
301
|
+
const firsts: Entry[] = [];
|
|
302
|
+
const picked = new Set<string>();
|
|
303
|
+
for (const raw of preferredKey ? preferredKey.split(",") : []) {
|
|
304
|
+
const code = normalizeCountryCode(raw);
|
|
305
|
+
if (code && seen.has(code) && !picked.has(code)) {
|
|
306
|
+
picked.add(code);
|
|
307
|
+
firsts.push(entry(code));
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
const compare = collator(locale).compare;
|
|
311
|
+
const sorted = pool
|
|
312
|
+
.filter((c) => !picked.has(c))
|
|
313
|
+
.map(entry)
|
|
314
|
+
.sort((a, b) => compare(a.name, b.name));
|
|
315
|
+
return { top: firsts, rest: sorted };
|
|
316
|
+
}, [countriesKey, preferredKey, locale]);
|
|
317
|
+
|
|
318
|
+
// `filter: false` — the panel is handed the rows `search` ranks below instead of
|
|
319
|
+
// the core's substring filter; the core still owns open, query, the highlighted row,
|
|
320
|
+
// anchoring and dismissal.
|
|
321
|
+
const allOptions = useMemo(
|
|
322
|
+
() => [...top, ...others].map((e) => toOption(e, flags)),
|
|
323
|
+
[top, others, flags],
|
|
324
|
+
);
|
|
325
|
+
const core = useComboboxCore<string>({ options: allOptions, filter: false });
|
|
326
|
+
const { open, setOpen, query, triggerRef, closeToTrigger } = core;
|
|
327
|
+
// The core anchors the panel to the trigger and hands focus back to it; the caller's
|
|
328
|
+
// `ref` wants the same element. One callback feeds both.
|
|
329
|
+
const setTrigger = useCallback(
|
|
330
|
+
(el: HTMLButtonElement | null) => {
|
|
331
|
+
triggerRef.current = el;
|
|
332
|
+
assignRef(ref, el);
|
|
333
|
+
},
|
|
334
|
+
[ref, triggerRef],
|
|
335
|
+
);
|
|
336
|
+
|
|
337
|
+
const q = fold(query.trim());
|
|
338
|
+
const results = useMemo(() => {
|
|
339
|
+
const firsts = q ? search(top, q) : top;
|
|
340
|
+
const below = q ? search(others, q) : others;
|
|
341
|
+
// The heading only where it separates something: with no preferred country in
|
|
342
|
+
// view it would head the whole list and divide nothing.
|
|
343
|
+
const heading = firsts.length > 0 ? text.others : undefined;
|
|
344
|
+
return [...firsts.map((e) => toOption(e, flags)), ...below.map((e) => toOption(e, flags, heading))];
|
|
345
|
+
}, [top, others, q, text.others, flags]);
|
|
346
|
+
|
|
347
|
+
// ── The lock ──────────────────────────────────────────────────────────────
|
|
348
|
+
const reason = useCommitReason(commit, ownReason);
|
|
349
|
+
const locked = hasMessage(reason);
|
|
350
|
+
const inert = locked || Boolean(disabled);
|
|
351
|
+
// A lock (or `disabled`) arriving while the list is up closes it — adjusted while
|
|
352
|
+
// rendering, as the core adjusts its own query, so no frame shows a list that can
|
|
353
|
+
// no longer be used.
|
|
354
|
+
if (inert && open) setOpen(false);
|
|
355
|
+
|
|
356
|
+
// ── The field ─────────────────────────────────────────────────────────────
|
|
357
|
+
const generated = useId();
|
|
358
|
+
const triggerId = id ?? generated;
|
|
359
|
+
const listboxId = `${generated}-listbox`;
|
|
360
|
+
const hintId = useId();
|
|
361
|
+
const reasonId = useId();
|
|
362
|
+
// Text is a caption under the field; a FieldHint rides the label line. See `hint`.
|
|
363
|
+
const textHint = (typeof hint === "string" && hint !== "") || typeof hint === "number";
|
|
364
|
+
const field = useComboboxFieldError(
|
|
365
|
+
error,
|
|
366
|
+
invalid || ariaInvalid === true || ariaInvalid === "true",
|
|
367
|
+
// The caller's, then the standing advice, then (inside) the error — the order every
|
|
368
|
+
// field keeps — and the lock's reason last, while there is one.
|
|
369
|
+
mergeDescribedBy(ariaDescribedBy, textHint && hintId),
|
|
370
|
+
);
|
|
371
|
+
|
|
372
|
+
const code = normalizeCountryCode(value);
|
|
373
|
+
const selectedName = code ? countryName(code, locale) : undefined;
|
|
374
|
+
// A field named by a label of the caller's (`aria-labelledby`) is a labelled field too:
|
|
375
|
+
// the label already says what goes here.
|
|
376
|
+
const emptyText = placeholder ?? (label === undefined && !ariaLabelledBy ? text.country : "");
|
|
377
|
+
const fieldName = typeof label === "string" ? label : text.country;
|
|
378
|
+
const valueId = `${generated}-value`;
|
|
379
|
+
// Named by the caller's element (a form's label) — then the shown text is the second
|
|
380
|
+
// reference, as the composed name below has the value second; but only when it IS a
|
|
381
|
+
// value or the caller's placeholder, never the `country` fallback word.
|
|
382
|
+
const labelledBy =
|
|
383
|
+
ariaLabel === undefined && ariaLabelledBy
|
|
384
|
+
? mergeDescribedBy(ariaLabelledBy, (selectedName !== undefined || Boolean(placeholder)) && valueId)
|
|
385
|
+
: undefined;
|
|
386
|
+
const name =
|
|
387
|
+
labelledBy !== undefined
|
|
388
|
+
? undefined
|
|
389
|
+
: (ariaLabel ??
|
|
390
|
+
(selectedName !== undefined
|
|
391
|
+
? common.fieldValue(fieldName, selectedName)
|
|
392
|
+
: placeholder
|
|
393
|
+
? common.fieldValue(fieldName, placeholder)
|
|
394
|
+
: fieldName));
|
|
395
|
+
|
|
396
|
+
const showClear = Boolean(clearable && code && !inert);
|
|
397
|
+
// `onChange` widened to take the clear's `null` — its type says so once `clearable`
|
|
398
|
+
// is set, and the clear is only ever offered then.
|
|
399
|
+
const emit = onChange as (code: string | null) => void;
|
|
400
|
+
const clear = () => {
|
|
401
|
+
if (!showClear) return;
|
|
402
|
+
emit(null);
|
|
403
|
+
};
|
|
404
|
+
|
|
405
|
+
const choose = (o: ComboOption<string>) => {
|
|
406
|
+
if (inert) return;
|
|
407
|
+
emit(o.value);
|
|
408
|
+
// Back to the trigger: the panel holding focus is about to unmount, and a keyboard
|
|
409
|
+
// user who has answered this field should stand on it, ready to Tab on.
|
|
410
|
+
closeToTrigger();
|
|
411
|
+
};
|
|
412
|
+
|
|
413
|
+
const trigger = (
|
|
414
|
+
<button
|
|
415
|
+
ref={setTrigger}
|
|
416
|
+
id={triggerId}
|
|
417
|
+
type="button"
|
|
418
|
+
// A closed choice that expands into the list below — the role every trigger
|
|
419
|
+
// picker in the kit wears (see EntityCombobox), and the one that supports
|
|
420
|
+
// `aria-invalid`.
|
|
421
|
+
role="combobox"
|
|
422
|
+
aria-haspopup="listbox"
|
|
423
|
+
aria-controls={listboxId}
|
|
424
|
+
aria-expanded={open}
|
|
425
|
+
aria-label={name}
|
|
426
|
+
aria-labelledby={labelledBy}
|
|
427
|
+
aria-invalid={field.isInvalid || undefined}
|
|
428
|
+
aria-required={ariaRequired}
|
|
429
|
+
aria-describedby={mergeDescribedBy(field.describedBy, locked && reasonId)}
|
|
430
|
+
// The focusable kind of disabled while locked (Button's rule): native `disabled`
|
|
431
|
+
// would take the field out of the tab order, and the reason with it.
|
|
432
|
+
disabled={locked ? undefined : disabled}
|
|
433
|
+
aria-disabled={locked || undefined}
|
|
434
|
+
onClick={(e) => {
|
|
435
|
+
if (inert) {
|
|
436
|
+
e.preventDefault();
|
|
437
|
+
return;
|
|
438
|
+
}
|
|
439
|
+
setOpen((o) => !o);
|
|
440
|
+
}}
|
|
441
|
+
// Down/Up opens the list from the closed trigger, per the APG; Enter and Space
|
|
442
|
+
// already do through the button's own click.
|
|
443
|
+
onKeyDown={(e) => {
|
|
444
|
+
if (inert) return;
|
|
445
|
+
if (e.key === "ArrowDown" || e.key === "ArrowUp") {
|
|
446
|
+
e.preventDefault();
|
|
447
|
+
setOpen(true);
|
|
448
|
+
} else if (showClear && !open && (e.key === "Delete" || e.key === "Backspace")) {
|
|
449
|
+
// The keyboard's clear: the "×" is out of the tab order (see `clearable`).
|
|
450
|
+
e.preventDefault();
|
|
451
|
+
clear();
|
|
452
|
+
}
|
|
453
|
+
}}
|
|
454
|
+
className={cn(
|
|
455
|
+
FIELD_TRIGGER,
|
|
456
|
+
// `peer` dims the floating label with a natively disabled trigger, as Select's.
|
|
457
|
+
"peer pe-9",
|
|
458
|
+
label !== undefined && FIELD_FLOATING_PAD,
|
|
459
|
+
inert && "cursor-not-allowed opacity-50",
|
|
460
|
+
field.isInvalid && FIELD_INVALID,
|
|
461
|
+
)}
|
|
462
|
+
>
|
|
463
|
+
<span className="flex min-w-0 items-center gap-2">
|
|
464
|
+
{flags && code && <CurrencyFlag country={code.toLowerCase()} />}
|
|
465
|
+
{/* A long name ("Saint Vincent and the Grenadines") truncates rather than
|
|
466
|
+
widening the field: the kit is checked at 390px. */}
|
|
467
|
+
<span
|
|
468
|
+
id={valueId}
|
|
469
|
+
className={cn("truncate", selectedName === undefined && "text-[var(--text-placeholder)]")}
|
|
470
|
+
>
|
|
471
|
+
{selectedName ?? emptyText}
|
|
472
|
+
</span>
|
|
473
|
+
</span>
|
|
474
|
+
{showClear ? (
|
|
475
|
+
/* eslint-disable-next-line jsx-a11y/click-events-have-key-events -- tabIndex -1 inside
|
|
476
|
+
the trigger <button>, so it never holds focus and a key handler here could never
|
|
477
|
+
fire; the keys go to the trigger, where Delete and Backspace clear. A pointer
|
|
478
|
+
shortcut, as on EntityCombobox. */
|
|
479
|
+
<span
|
|
480
|
+
role="button"
|
|
481
|
+
tabIndex={-1}
|
|
482
|
+
aria-label={comboText.clear}
|
|
483
|
+
onClick={(e) => {
|
|
484
|
+
e.stopPropagation();
|
|
485
|
+
clear();
|
|
486
|
+
}}
|
|
487
|
+
className="absolute end-2 top-1/2 -translate-y-1/2 rounded p-0.5 text-[var(--text-placeholder)] hover:text-[var(--text-secondary)]"
|
|
488
|
+
>
|
|
489
|
+
<X aria-hidden className="size-4" />
|
|
490
|
+
</span>
|
|
491
|
+
) : (
|
|
492
|
+
<FieldChevron />
|
|
493
|
+
)}
|
|
494
|
+
</button>
|
|
495
|
+
);
|
|
496
|
+
|
|
497
|
+
const control = locked ? (
|
|
498
|
+
// In a FRAGMENT, as Button does, so the Tooltip does not clone its bubble into the
|
|
499
|
+
// description as well — the hidden copy is what `aria-describedby` points at.
|
|
500
|
+
<Tooltip label={reason} className="flex w-full">
|
|
501
|
+
<>
|
|
502
|
+
{trigger}
|
|
503
|
+
<span id={reasonId} hidden>
|
|
504
|
+
{reason}
|
|
505
|
+
</span>
|
|
506
|
+
</>
|
|
507
|
+
</Tooltip>
|
|
508
|
+
) : (
|
|
509
|
+
trigger
|
|
510
|
+
);
|
|
511
|
+
|
|
512
|
+
const labelHint = textHint ? undefined : hasMessage(hint) ? hint : undefined;
|
|
513
|
+
const box =
|
|
514
|
+
label !== undefined ? (
|
|
515
|
+
<FloatingField htmlFor={triggerId} label={label} staticLabel hint={labelHint}>
|
|
516
|
+
{control}
|
|
517
|
+
</FloatingField>
|
|
518
|
+
) : labelHint !== undefined ? (
|
|
519
|
+
// No label line to ride: the "?" goes at the field's end, outside the box, as on
|
|
520
|
+
// an unlabelled Select.
|
|
521
|
+
<div className="flex items-center gap-1.5">
|
|
522
|
+
<div className="relative min-w-0 flex-1">{control}</div>
|
|
523
|
+
<span className="flex shrink-0 items-center">{labelHint}</span>
|
|
524
|
+
</div>
|
|
525
|
+
) : (
|
|
526
|
+
<div className="relative">{control}</div>
|
|
527
|
+
);
|
|
528
|
+
|
|
529
|
+
return (
|
|
530
|
+
// `rest` dresses the wrapper — a `data-tour` anchor, a test id. The name, the
|
|
531
|
+
// description and the invalid state are on the trigger above.
|
|
532
|
+
<div {...rest} className={className}>
|
|
533
|
+
{box}
|
|
534
|
+
{textHint && (
|
|
535
|
+
<p id={hintId} className="mt-1 text-[11px] leading-tight text-[var(--text-muted)]">
|
|
536
|
+
{hint}
|
|
537
|
+
</p>
|
|
538
|
+
)}
|
|
539
|
+
{field.errorEl}
|
|
540
|
+
<ComboboxPanel
|
|
541
|
+
// The core with the rows ranked above in place of its own filter's.
|
|
542
|
+
core={{ ...core, results }}
|
|
543
|
+
listboxId={listboxId}
|
|
544
|
+
// On a phone the list is a full-screen sheet, which needs the field's own
|
|
545
|
+
// name to say what it is asking for (live #200).
|
|
546
|
+
sheetTitle={label ?? text.country}
|
|
547
|
+
searchPlaceholder={text.search}
|
|
548
|
+
isSelected={(v) => v === code}
|
|
549
|
+
onChoose={choose}
|
|
550
|
+
showCreate={false}
|
|
551
|
+
onCreate={() => {}}
|
|
552
|
+
createContent={null}
|
|
553
|
+
/>
|
|
554
|
+
</div>
|
|
555
|
+
);
|
|
556
|
+
}
|