@canonical/react-ds-global-form 0.36.0 → 0.38.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 +40 -0
- package/dist/esm/density.css +320 -302
- package/dist/esm/docs/examples/density-examples.css +19 -14
- package/dist/esm/index.css +361 -335
- package/dist/esm/lib/_work_in_progress/DensityTestbed/baseline-system.css +71 -64
- package/dist/esm/lib/_work_in_progress/DensityTestbed/density.testbed.css +127 -123
- package/dist/esm/lib/common/Wrapper/ToggleWrapper.css +73 -54
- package/dist/esm/lib/common/Wrapper/styles.css +35 -31
- package/dist/esm/lib/component/ChoicesField/common/Option/Option.js +4 -1
- package/dist/esm/lib/component/ChoicesField/common/Option/Option.js.map +1 -1
- package/dist/esm/lib/component/ChoicesField/styles.css +195 -163
- package/dist/esm/lib/component/RangeField/common/RangeControl/styles.css +39 -35
- package/dist/esm/lib/component/RichChoicesField/styles.css +93 -89
- package/dist/esm/lib/index.js +2 -0
- package/dist/esm/lib/index.js.map +1 -1
- package/dist/esm/lib/subcomponent/CheckboxInput/styles.css +115 -111
- package/dist/esm/lib/subcomponent/ColorInput/styles.css +177 -173
- package/dist/esm/lib/subcomponent/ComboboxInput/SingleCombobox.js +2 -1
- package/dist/esm/lib/subcomponent/ComboboxInput/SingleCombobox.js.map +1 -1
- package/dist/esm/lib/subcomponent/ComboboxInput/common/List/List.js +1 -1
- package/dist/esm/lib/subcomponent/ComboboxInput/common/List/List.js.map +1 -1
- package/dist/esm/lib/subcomponent/ComboboxInput/common/List/styles.css +33 -29
- package/dist/esm/lib/subcomponent/ComboboxInput/common/ResetButton/styles.css +21 -17
- package/dist/esm/lib/subcomponent/ComboboxInput/styles.css +59 -55
- package/dist/esm/lib/subcomponent/ComboboxInput/utils/index.js +0 -1
- package/dist/esm/lib/subcomponent/ComboboxInput/utils/index.js.map +1 -1
- package/dist/esm/lib/subcomponent/DateInput/styles.css +23 -19
- package/dist/esm/lib/subcomponent/DateTimeInput/styles.css +24 -20
- package/dist/esm/lib/subcomponent/Field/Description/styles.css +9 -5
- package/dist/esm/lib/subcomponent/Field/Error/styles.css +9 -5
- package/dist/esm/lib/subcomponent/Field/Label/Label.js +2 -2
- package/dist/esm/lib/subcomponent/Field/Label/Label.js.map +1 -1
- package/dist/esm/lib/subcomponent/Field/Label/styles.css +25 -21
- package/dist/esm/lib/subcomponent/FileUploadInput/styles.css +125 -119
- package/dist/esm/lib/subcomponent/NumberInput/styles.css +32 -28
- package/dist/esm/lib/subcomponent/PasswordInput/styles.css +58 -54
- package/dist/esm/lib/subcomponent/PhoneInput/PhoneInput.js +44 -20
- package/dist/esm/lib/subcomponent/PhoneInput/PhoneInput.js.map +1 -1
- package/dist/esm/lib/subcomponent/PhoneInput/styles.css +53 -49
- package/dist/esm/lib/subcomponent/RadioInput/styles.css +70 -66
- package/dist/esm/lib/subcomponent/RangeInput/styles.css +74 -70
- package/dist/esm/lib/subcomponent/RatingInput/styles.css +132 -128
- package/dist/esm/lib/subcomponent/SelectInput/styles.css +44 -40
- package/dist/esm/lib/subcomponent/SwitchInput/styles.css +90 -86
- package/dist/esm/lib/subcomponent/TextInput/styles.css +30 -26
- package/dist/esm/lib/subcomponent/TextareaInput/styles.css +14 -10
- package/dist/esm/lib/subcomponent/TimeInput/styles.css +19 -15
- package/dist/esm/lib/utils/countries/index.js +3 -3
- package/dist/esm/lib/utils/countries/index.js.map +1 -1
- package/dist/esm/lib/utils/formatter/applyPattern.js +38 -0
- package/dist/esm/lib/utils/formatter/applyPattern.js.map +1 -0
- package/dist/esm/lib/utils/formatter/createFormatterRegisterOptions.js +22 -0
- package/dist/esm/lib/utils/formatter/createFormatterRegisterOptions.js.map +1 -0
- package/dist/esm/lib/utils/formatter/createPatternFormatter.js +25 -0
- package/dist/esm/lib/utils/formatter/createPatternFormatter.js.map +1 -0
- package/dist/esm/lib/utils/formatter/index.js +8 -0
- package/dist/esm/lib/utils/formatter/index.js.map +1 -0
- package/dist/esm/lib/utils/formatter/stripToDigits.js +12 -0
- package/dist/esm/lib/utils/formatter/stripToDigits.js.map +1 -0
- package/dist/esm/lib/utils/formatter/types.js +2 -0
- package/dist/esm/lib/utils/formatter/types.js.map +1 -0
- package/dist/esm/lib/utils/hooks/index.js +1 -0
- package/dist/esm/lib/utils/hooks/index.js.map +1 -1
- package/dist/esm/lib/utils/hooks/types.js +2 -0
- package/dist/esm/lib/utils/hooks/types.js.map +1 -0
- package/dist/esm/lib/utils/hooks/useFormattedValue.js +195 -0
- package/dist/esm/lib/utils/hooks/useFormattedValue.js.map +1 -0
- package/dist/esm/lib/utils/index.js +6 -2
- package/dist/esm/lib/utils/index.js.map +1 -1
- package/dist/esm/lib/utils/mergeRefs.js +25 -0
- package/dist/esm/lib/utils/mergeRefs.js.map +1 -0
- package/dist/esm/lib/utils/middleware/addRESTValidation.js +1 -1
- package/dist/esm/lib/utils/middleware/addRESTValidation.js.map +1 -1
- package/dist/types/lib/component/ChoicesField/common/Option/Option.d.ts.map +1 -1
- package/dist/types/lib/component/PhoneField/PhoneField.d.ts +2 -1
- package/dist/types/lib/component/PhoneField/PhoneField.d.ts.map +1 -1
- package/dist/types/lib/index.d.ts +4 -0
- package/dist/types/lib/index.d.ts.map +1 -1
- package/dist/types/lib/subcomponent/ComboboxInput/SingleCombobox.d.ts.map +1 -1
- package/dist/types/lib/subcomponent/ComboboxInput/utils/index.d.ts +0 -1
- package/dist/types/lib/subcomponent/ComboboxInput/utils/index.d.ts.map +1 -1
- package/dist/types/lib/subcomponent/PhoneInput/PhoneInput.d.ts +19 -2
- package/dist/types/lib/subcomponent/PhoneInput/PhoneInput.d.ts.map +1 -1
- package/dist/types/lib/subcomponent/PhoneInput/types.d.ts +20 -7
- package/dist/types/lib/subcomponent/PhoneInput/types.d.ts.map +1 -1
- package/dist/types/lib/utils/countries/index.d.ts +0 -3
- package/dist/types/lib/utils/countries/index.d.ts.map +1 -1
- package/dist/types/lib/utils/formatter/applyPattern.d.ts +17 -0
- package/dist/types/lib/utils/formatter/applyPattern.d.ts.map +1 -0
- package/dist/types/lib/utils/formatter/createFormatterRegisterOptions.d.ts +20 -0
- package/dist/types/lib/utils/formatter/createFormatterRegisterOptions.d.ts.map +1 -0
- package/dist/types/lib/utils/formatter/createPatternFormatter.d.ts +19 -0
- package/dist/types/lib/utils/formatter/createPatternFormatter.d.ts.map +1 -0
- package/dist/types/lib/utils/formatter/index.d.ts +6 -0
- package/dist/types/lib/utils/formatter/index.d.ts.map +1 -0
- package/dist/types/lib/utils/formatter/stripToDigits.d.ts +10 -0
- package/dist/types/lib/utils/formatter/stripToDigits.d.ts.map +1 -0
- package/dist/types/lib/utils/formatter/types.d.ts +30 -0
- package/dist/types/lib/utils/formatter/types.d.ts.map +1 -0
- package/dist/types/lib/utils/hooks/index.d.ts +2 -0
- package/dist/types/lib/utils/hooks/index.d.ts.map +1 -1
- package/dist/types/lib/utils/hooks/types.d.ts +33 -0
- package/dist/types/lib/utils/hooks/types.d.ts.map +1 -0
- package/dist/types/lib/utils/hooks/useFormattedValue.d.ts +30 -0
- package/dist/types/lib/utils/hooks/useFormattedValue.d.ts.map +1 -0
- package/dist/types/lib/utils/index.d.ts +2 -0
- package/dist/types/lib/utils/index.d.ts.map +1 -1
- package/dist/types/lib/utils/mergeRefs.d.ts +14 -0
- package/dist/types/lib/utils/mergeRefs.d.ts.map +1 -0
- package/package.json +17 -16
- package/dist/esm/lib/subcomponent/ComboboxInput/utils/mergeRefs.js +0 -12
- package/dist/esm/lib/subcomponent/ComboboxInput/utils/mergeRefs.js.map +0 -1
- package/dist/esm/lib/utils/countries/applyPhoneMask.js +0 -35
- package/dist/esm/lib/utils/countries/applyPhoneMask.js.map +0 -1
- package/dist/esm/lib/utils/countries/phoneRegisterOptions.js +0 -18
- package/dist/esm/lib/utils/countries/phoneRegisterOptions.js.map +0 -1
- package/dist/esm/lib/utils/countries/removePhoneMask.js +0 -12
- package/dist/esm/lib/utils/countries/removePhoneMask.js.map +0 -1
- package/dist/types/lib/subcomponent/ComboboxInput/utils/mergeRefs.d.ts +0 -3
- package/dist/types/lib/subcomponent/ComboboxInput/utils/mergeRefs.d.ts.map +0 -1
- package/dist/types/lib/utils/countries/applyPhoneMask.d.ts +0 -14
- package/dist/types/lib/utils/countries/applyPhoneMask.d.ts.map +0 -1
- package/dist/types/lib/utils/countries/phoneRegisterOptions.d.ts +0 -14
- package/dist/types/lib/utils/countries/phoneRegisterOptions.d.ts.map +0 -1
- package/dist/types/lib/utils/countries/removePhoneMask.d.ts +0 -10
- package/dist/types/lib/utils/countries/removePhoneMask.d.ts.map +0 -1
|
@@ -1,33 +1,37 @@
|
|
|
1
|
-
/*
|
|
1
|
+
/* Layer: ds.components.global (@canonical/styles README, "Cascade layers"). */
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
.ds.input.number {
|
|
6
|
-
direction: inherit;
|
|
7
|
-
display: flex;
|
|
8
|
-
align-items: stretch;
|
|
9
|
-
position: relative;
|
|
10
|
-
padding: 0;
|
|
3
|
+
@layer ds.components.global {
|
|
4
|
+
/* Generated by @canonical/summon-component:react v0.1.0 */
|
|
11
5
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
background: transparent;
|
|
17
|
-
color: inherit;
|
|
18
|
-
font-family: inherit;
|
|
19
|
-
outline: none;
|
|
20
|
-
/* Baseline engine provides font-size, line-height, padding via `.p` */
|
|
21
|
-
padding-inline: var(--form-input-padding-inline);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
& > .prefix,
|
|
25
|
-
& > .suffix {
|
|
6
|
+
/* Native numeric entry with shared input chrome and optional prefix/suffix
|
|
7
|
+
* slots for units. Mirrors the text input. */
|
|
8
|
+
.ds.input.number {
|
|
9
|
+
direction: inherit;
|
|
26
10
|
display: flex;
|
|
27
|
-
align-items:
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
11
|
+
align-items: stretch;
|
|
12
|
+
position: relative;
|
|
13
|
+
padding: 0;
|
|
14
|
+
|
|
15
|
+
& > input {
|
|
16
|
+
flex: 1;
|
|
17
|
+
min-width: 0;
|
|
18
|
+
border: none;
|
|
19
|
+
background: transparent;
|
|
20
|
+
color: inherit;
|
|
21
|
+
font-family: inherit;
|
|
22
|
+
outline: none;
|
|
23
|
+
/* Baseline engine provides font-size, line-height, padding via `.p` */
|
|
24
|
+
padding-inline: var(--form-input-padding-inline);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
& > .prefix,
|
|
28
|
+
& > .suffix {
|
|
29
|
+
display: flex;
|
|
30
|
+
align-items: center;
|
|
31
|
+
padding-inline: var(--form-field-inline-gap);
|
|
32
|
+
color: var(--color-text-muted);
|
|
33
|
+
white-space: nowrap;
|
|
34
|
+
user-select: none;
|
|
35
|
+
}
|
|
32
36
|
}
|
|
33
37
|
}
|
|
@@ -1,66 +1,70 @@
|
|
|
1
|
-
/*
|
|
1
|
+
/* Layer: ds.components.global (@canonical/styles README, "Cascade layers"). */
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
* from @canonical/ds-assets, masked so they take `currentColor`. */
|
|
6
|
-
.ds.input.password {
|
|
7
|
-
direction: inherit;
|
|
8
|
-
display: flex;
|
|
9
|
-
align-items: stretch;
|
|
10
|
-
position: relative;
|
|
11
|
-
padding: 0;
|
|
3
|
+
@layer ds.components.global {
|
|
4
|
+
/* Generated by @canonical/summon-component:react v0.1.0 */
|
|
12
5
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
color: inherit;
|
|
19
|
-
font-family: inherit;
|
|
20
|
-
outline: none;
|
|
21
|
-
/* Baseline engine provides font-size, line-height, padding via `.p` */
|
|
22
|
-
padding-inline: var(--form-input-padding-inline);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
& > .reveal-toggle {
|
|
6
|
+
/* Masked secret entry with a reveal/mask (eye) toggle in the suffix position;
|
|
7
|
+
* no prefix. Chrome mirrors the text input; the toggle uses the show/hide icons
|
|
8
|
+
* from @canonical/ds-assets, masked so they take `currentColor`. */
|
|
9
|
+
.ds.input.password {
|
|
10
|
+
direction: inherit;
|
|
26
11
|
display: flex;
|
|
27
|
-
align-items:
|
|
28
|
-
|
|
29
|
-
padding
|
|
30
|
-
border: none;
|
|
31
|
-
background: transparent;
|
|
32
|
-
color: var(--color-icon);
|
|
33
|
-
cursor: pointer;
|
|
12
|
+
align-items: stretch;
|
|
13
|
+
position: relative;
|
|
14
|
+
padding: 0;
|
|
34
15
|
|
|
35
|
-
& >
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
-
|
|
44
|
-
-
|
|
16
|
+
& > input {
|
|
17
|
+
flex: 1;
|
|
18
|
+
min-width: 0;
|
|
19
|
+
border: none;
|
|
20
|
+
background: transparent;
|
|
21
|
+
color: inherit;
|
|
22
|
+
font-family: inherit;
|
|
23
|
+
outline: none;
|
|
24
|
+
/* Baseline engine provides font-size, line-height, padding via `.p` */
|
|
25
|
+
padding-inline: var(--form-input-padding-inline);
|
|
26
|
+
}
|
|
45
27
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
28
|
+
& > .reveal-toggle {
|
|
29
|
+
display: flex;
|
|
30
|
+
align-items: center;
|
|
31
|
+
justify-content: center;
|
|
32
|
+
padding-inline: var(--form-field-inline-gap);
|
|
33
|
+
border: none;
|
|
34
|
+
background: transparent;
|
|
35
|
+
color: var(--color-icon);
|
|
36
|
+
cursor: pointer;
|
|
50
37
|
|
|
51
|
-
&
|
|
52
|
-
|
|
53
|
-
|
|
38
|
+
& > .reveal-icon {
|
|
39
|
+
width: var(--dimension-200); /* 16px */
|
|
40
|
+
height: var(--dimension-200);
|
|
41
|
+
background-color: currentColor;
|
|
42
|
+
mask-repeat: no-repeat;
|
|
43
|
+
mask-position: center;
|
|
44
|
+
mask-size: contain;
|
|
45
|
+
-webkit-mask-repeat: no-repeat;
|
|
46
|
+
-webkit-mask-position: center;
|
|
47
|
+
-webkit-mask-size: contain;
|
|
48
|
+
|
|
49
|
+
&[data-state="masked"] {
|
|
50
|
+
mask-image: url("/icons/show.svg#show");
|
|
51
|
+
-webkit-mask-image: url("/icons/show.svg#show");
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
&[data-state="revealed"] {
|
|
55
|
+
mask-image: url("/icons/hide.svg#hide");
|
|
56
|
+
-webkit-mask-image: url("/icons/hide.svg#hide");
|
|
57
|
+
}
|
|
54
58
|
}
|
|
55
|
-
}
|
|
56
59
|
|
|
57
|
-
|
|
58
|
-
|
|
60
|
+
/* No hover colour change: the reveal toggle keeps `--color-icon` in all
|
|
61
|
+
* pointer states (per design review). */
|
|
59
62
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
63
|
+
&:focus-visible {
|
|
64
|
+
outline: none;
|
|
65
|
+
box-shadow: 0 0 0 1px var(--color-focus-ring);
|
|
66
|
+
border-radius: var(--form-input-border-radius);
|
|
67
|
+
}
|
|
64
68
|
}
|
|
65
69
|
}
|
|
66
70
|
}
|
|
@@ -1,8 +1,23 @@
|
|
|
1
1
|
import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { invariant } from "@canonical/utils";
|
|
3
|
+
import { forwardRef, useCallback, useMemo, useState } from "react";
|
|
4
|
+
import { countries as defaultCountries, } from "../../utils/countries/index.js";
|
|
5
|
+
import createPatternFormatter from "../../utils/formatter/createPatternFormatter.js";
|
|
6
|
+
import useFormattedValue from "../../utils/hooks/useFormattedValue.js";
|
|
7
|
+
import mergeRefs from "../../utils/mergeRefs.js";
|
|
4
8
|
import "./styles.css";
|
|
5
9
|
const componentCssClassName = "ds input phone chrome";
|
|
10
|
+
// Every country lookup falls back to the first entry, so an empty dataset has no
|
|
11
|
+
// country to render at all. Asserted rather than silently read out of bounds, so
|
|
12
|
+
// the cause is named instead of surfacing later as a missing dial code.
|
|
13
|
+
const EMPTY_COUNTRIES_MESSAGE = "PhoneInput requires a non-empty `countries` list.";
|
|
14
|
+
// Digits plus every separator the bundled masks actually use — space, parens,
|
|
15
|
+
// hyphen and the dot that `##.##.##` needs. The constraint applies to the string
|
|
16
|
+
// on screen, which carries those separators whenever `mask` is on, so a
|
|
17
|
+
// digits-only pattern would reject a correctly formatted number outright.
|
|
18
|
+
// Parens are escaped because `pattern` is compiled with the `v` flag first,
|
|
19
|
+
// where they are reserved inside a character class.
|
|
20
|
+
const ALLOWED_NUMBER_CHARACTERS = "[0-9+\\(\\)\\-\\.\\s]*";
|
|
6
21
|
/**
|
|
7
22
|
* Derive the emoji flag for an ISO 3166-1 alpha-2 code by mapping each of its
|
|
8
23
|
* two letters to its regional-indicator symbol (U+1F1E6–U+1F1FF). Non-alpha-2
|
|
@@ -10,20 +25,20 @@ const componentCssClassName = "ds input phone chrome";
|
|
|
10
25
|
* returned unchanged rather than mapped into unrelated code points.
|
|
11
26
|
* @note Pure.
|
|
12
27
|
*/
|
|
13
|
-
function
|
|
28
|
+
function buildFlagEmoji(code) {
|
|
14
29
|
const upper = code.toUpperCase();
|
|
15
30
|
if (!/^[A-Z]{2}$/.test(upper))
|
|
16
31
|
return code;
|
|
17
32
|
return upper.replace(/[A-Z]/g, (char) => String.fromCodePoint(127397 + char.charCodeAt(0)));
|
|
18
33
|
}
|
|
19
34
|
/** Numeric dial code (e.g. "+44" -> 44) for sorting. @note Pure. */
|
|
20
|
-
function
|
|
35
|
+
function getDialCodeValue(dialCode) {
|
|
21
36
|
return Number.parseInt(dialCode.replace(/\D/g, ""), 10);
|
|
22
37
|
}
|
|
23
38
|
/** The selector label for a country after its dial code. @note Pure. */
|
|
24
|
-
function
|
|
39
|
+
function getCountryLabel(country, display) {
|
|
25
40
|
if (display === "flag")
|
|
26
|
-
return
|
|
41
|
+
return buildFlagEmoji(country.code);
|
|
27
42
|
if (display === "name")
|
|
28
43
|
return country.name;
|
|
29
44
|
return country.code;
|
|
@@ -37,13 +52,16 @@ function countryLabel(country, display) {
|
|
|
37
52
|
* (an E.164 string or a structured `{ countryCode, number }` object). It
|
|
38
53
|
* defaults defensively, so an undefined initial `value` renders the
|
|
39
54
|
* `defaultCountry` with an empty number.
|
|
55
|
+
*
|
|
56
|
+
* The forwarded ref reaches the national-number input — the field's focusable
|
|
57
|
+
* element, and what react-hook-form needs for `setFocus` and focus-on-error.
|
|
40
58
|
* @returns {React.ReactElement} - Rendered Phone
|
|
41
59
|
*
|
|
42
60
|
* `import { PhoneInput } from "@canonical/react-ds-global-form";`
|
|
43
61
|
*
|
|
44
62
|
* @implements ds:global.subcomponent.phone_input
|
|
45
63
|
*/
|
|
46
|
-
export const PhoneInput = ({ id, className, style, value, onChange, defaultCountry = "US", preferredCountries = [], filteredCountries, countries = defaultCountries, valueFormat = "e164", countryDisplay = "code", mask = false, disabled = false, })
|
|
64
|
+
export const PhoneInput = forwardRef(function PhoneInput({ id, className, style, name, value, onChange, onBlur, defaultCountry = "US", preferredCountries = [], filteredCountries, countries = defaultCountries, valueFormat = "e164", countryDisplay = "code", mask = false, disabled = false, }, ref) {
|
|
47
65
|
const [selectedCountry, setSelectedCountry] = useState(() => {
|
|
48
66
|
if (valueFormat === "structured" && value && typeof value === "object") {
|
|
49
67
|
return value.countryCode || defaultCountry;
|
|
@@ -51,7 +69,7 @@ export const PhoneInput = ({ id, className, style, value, onChange, defaultCount
|
|
|
51
69
|
return defaultCountry;
|
|
52
70
|
});
|
|
53
71
|
const sortedCountries = useMemo(() => {
|
|
54
|
-
const byDialCode = (a, b) =>
|
|
72
|
+
const byDialCode = (a, b) => getDialCodeValue(a.dialCode) - getDialCodeValue(b.dialCode) ||
|
|
55
73
|
a.name.localeCompare(b.name);
|
|
56
74
|
// 1. `filteredCountries` (if given) restricts the visible universe to a
|
|
57
75
|
// whitelist, kept in the order the consumer listed it. Otherwise the
|
|
@@ -79,7 +97,11 @@ export const PhoneInput = ({ id, className, style, value, onChange, defaultCount
|
|
|
79
97
|
preferredCountries.indexOf(b.code));
|
|
80
98
|
return [...preferred, ...rest];
|
|
81
99
|
}, [preferredCountries, filteredCountries, countries]);
|
|
82
|
-
const currentCountryData = useMemo(() =>
|
|
100
|
+
const currentCountryData = useMemo(() => {
|
|
101
|
+
const country = countries.find((c) => c.code === selectedCountry) ?? countries.at(0);
|
|
102
|
+
invariant(country, EMPTY_COUNTRIES_MESSAGE);
|
|
103
|
+
return country;
|
|
104
|
+
}, [selectedCountry, countries]);
|
|
83
105
|
const getCurrentNumber = useCallback(() => {
|
|
84
106
|
if (valueFormat === "structured" && value && typeof value === "object") {
|
|
85
107
|
return value.number || "";
|
|
@@ -91,7 +113,8 @@ export const PhoneInput = ({ id, className, style, value, onChange, defaultCount
|
|
|
91
113
|
return typeof value === "string" ? value : "";
|
|
92
114
|
}, [value, valueFormat, currentCountryData]);
|
|
93
115
|
const emitValue = useCallback((countryCode, number) => {
|
|
94
|
-
const country = countries.find((c) => c.code === countryCode) ?? countries
|
|
116
|
+
const country = countries.find((c) => c.code === countryCode) ?? countries.at(0);
|
|
117
|
+
invariant(country, EMPTY_COUNTRIES_MESSAGE);
|
|
95
118
|
// The emitted national number is always raw digits — the mask is purely a
|
|
96
119
|
// display concern, never part of the submitted value.
|
|
97
120
|
const digits = number.replace(/\D/g, "");
|
|
@@ -107,15 +130,16 @@ export const PhoneInput = ({ id, className, style, value, onChange, defaultCount
|
|
|
107
130
|
setSelectedCountry(code);
|
|
108
131
|
emitValue(code, getCurrentNumber());
|
|
109
132
|
}, [emitValue, getCurrentNumber]);
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
:
|
|
118
|
-
|
|
119
|
-
};
|
|
133
|
+
// The national number is stored as digits and displayed grouped per the
|
|
134
|
+
// selected country when `mask` is on. With `mask` off the formatter still
|
|
135
|
+
// normalises to digits, so the two modes differ only in decoration.
|
|
136
|
+
const formatter = createPatternFormatter(mask ? currentCountryData.format : undefined);
|
|
137
|
+
const number = useFormattedValue({
|
|
138
|
+
formatter,
|
|
139
|
+
model: formatter.parse(getCurrentNumber()),
|
|
140
|
+
onModelChange: (digits) => emitValue(selectedCountry, digits),
|
|
141
|
+
});
|
|
142
|
+
return (_jsxs("div", { id: id, style: style, className: [componentCssClassName, className].filter(Boolean).join(" "), children: [_jsx("select", { className: "country-select p", value: selectedCountry, onChange: handleCountryChange, disabled: disabled, autoComplete: "tel-country-code", "aria-label": "Country code", children: sortedCountries.map((country) => (_jsxs("option", { value: country.code, children: [country.dialCode, " ", getCountryLabel(country, countryDisplay)] }, country.code))) }), _jsx("input", { type: "tel", className: "number-input p", name: name, inputMode: "tel", autoComplete: "tel-national", pattern: ALLOWED_NUMBER_CHARACTERS, title: "Digits, and the spacing characters used by the number's format.", value: number.value, onChange: number.onChange, onCompositionStart: number.onCompositionStart, onCompositionEnd: number.onCompositionEnd, onBlur: onBlur, ref: mergeRefs(number.ref, ref), disabled: disabled, "aria-label": "Phone number" })] }));
|
|
143
|
+
});
|
|
120
144
|
export default PhoneInput;
|
|
121
145
|
//# sourceMappingURL=PhoneInput.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PhoneInput.js","sourceRoot":"","sources":["../../../../../src/lib/subcomponent/PhoneInput/PhoneInput.tsx"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"PhoneInput.js","sourceRoot":"","sources":["../../../../../src/lib/subcomponent/PhoneInput/PhoneInput.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAE7C,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACnE,OAAO,EAEL,SAAS,IAAI,gBAAgB,GAE9B,MAAM,gCAAgC,CA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AO,CAAC,IAAI,CAEhB,CACV,CAAC,GACK,EACT,gBACE,IAAI,EAAC,KAAK,EACV,SAAS,EAAC,gBAAgB,EAC1B,IAAI,EAAE,IAAI,EACV,SAAS,EAAC,KAAK,EACf,YAAY,EAAC,cAAc,EAC3B,OAAO,EAAE,yBAAyB,EAClC,KAAK,EAAC,iEAAiE,EACvE,KAAK,EAAE,MAAM,CAAC,KAAK,EACnB,QAAQ,EAAE,MAAM,CAAC,QAAQ,EACzB,kBAAkB,EAAE,MAAM,CAAC,kBAAkB,EAC7C,gBAAgB,EAAE,MAAM,CAAC,gBAAgB,EACzC,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,SAAS,CAAC,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,EAC/B,QAAQ,EAAE,QAAQ,gBACP,cAAc,GACzB,IACE,CACP,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,UAAU,CAAC"}
|
|
@@ -1,58 +1,62 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* The .chrome class on the wrapper provides shared border/focus styling.
|
|
3
|
-
* Internal elements share the visual space.
|
|
4
|
-
*/
|
|
5
|
-
.ds.input.phone {
|
|
6
|
-
display: flex;
|
|
7
|
-
align-items: stretch;
|
|
8
|
-
padding: 0;
|
|
1
|
+
/* Layer: ds.components.global (@canonical/styles README, "Cascade layers"). */
|
|
9
2
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
padding
|
|
19
|
-
border-inline-end: var(--form-input-border-width) solid
|
|
20
|
-
var(--form-input-border-color);
|
|
21
|
-
cursor: pointer;
|
|
22
|
-
white-space: nowrap;
|
|
23
|
-
min-width: 5.5rem;
|
|
3
|
+
@layer ds.components.global {
|
|
4
|
+
/* Phone — composite input: country selector + telephone number.
|
|
5
|
+
* The .chrome class on the wrapper provides shared border/focus styling.
|
|
6
|
+
* Internal elements share the visual space.
|
|
7
|
+
*/
|
|
8
|
+
.ds.input.phone {
|
|
9
|
+
display: flex;
|
|
10
|
+
align-items: stretch;
|
|
11
|
+
padding: 0;
|
|
24
12
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
13
|
+
& > .country-select {
|
|
14
|
+
appearance: none;
|
|
15
|
+
border: none;
|
|
16
|
+
background: transparent;
|
|
17
|
+
color: inherit;
|
|
18
|
+
font-family: inherit;
|
|
19
|
+
/* .p class provides font-size, line-height, baseline nudges */
|
|
20
|
+
padding-inline: var(--form-input-padding-inline);
|
|
21
|
+
padding-inline-end: var(--form-field-inline-gap);
|
|
22
|
+
border-inline-end: var(--form-input-border-width) solid
|
|
23
|
+
var(--form-input-border-color);
|
|
24
|
+
cursor: pointer;
|
|
25
|
+
white-space: nowrap;
|
|
26
|
+
min-width: 5.5rem;
|
|
27
|
+
|
|
28
|
+
&:focus-visible {
|
|
29
|
+
outline: none;
|
|
30
|
+
background-color: var(
|
|
31
|
+
--hover--color-foreground-input,
|
|
32
|
+
var(--color-foreground-input-hover)
|
|
33
|
+
);
|
|
34
|
+
}
|
|
32
35
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
&:disabled {
|
|
37
|
+
cursor: not-allowed;
|
|
38
|
+
color: var(--form-input-color-disabled);
|
|
39
|
+
/* The separator ("middle bar") between the two controls must adopt the
|
|
40
|
+
* disabled border colour too. */
|
|
41
|
+
border-inline-end-color: var(--form-input-border-color-disabled);
|
|
42
|
+
}
|
|
39
43
|
}
|
|
40
|
-
}
|
|
41
44
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
45
|
+
& > .number-input {
|
|
46
|
+
flex: 1;
|
|
47
|
+
min-width: 0;
|
|
48
|
+
border: none;
|
|
49
|
+
background: transparent;
|
|
50
|
+
color: inherit;
|
|
51
|
+
font-family: inherit;
|
|
52
|
+
outline: none;
|
|
53
|
+
/* .p class provides font-size, line-height, baseline nudges */
|
|
54
|
+
padding-inline: var(--form-input-padding-inline);
|
|
52
55
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
+
&:disabled {
|
|
57
|
+
cursor: not-allowed;
|
|
58
|
+
color: var(--form-input-color-disabled);
|
|
59
|
+
}
|
|
56
60
|
}
|
|
57
61
|
}
|
|
58
62
|
}
|
|
@@ -1,75 +1,79 @@
|
|
|
1
|
-
/*
|
|
1
|
+
/* Layer: ds.components.global (@canonical/styles README, "Cascade layers"). */
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
.ds.form-radio {
|
|
6
|
-
appearance: none;
|
|
7
|
-
box-sizing: border-box;
|
|
8
|
-
margin-inline: var(--form-input-padding-inline);
|
|
9
|
-
/* 16px control — a fixed element size, not a baseline multiple (the 4px-baseline
|
|
10
|
-
spike halved the old `--space-baseline × 2`). Stable --dimension-200 (16px). */
|
|
11
|
-
width: var(--dimension-200);
|
|
12
|
-
height: var(--dimension-200);
|
|
13
|
-
border: var(--dimension-stroke-thickness-medium) solid var(--color-border);
|
|
14
|
-
border-radius: 50%;
|
|
15
|
-
background-color: var(
|
|
16
|
-
--surface-color-foreground-radio-unselected,
|
|
17
|
-
var(--color-foreground-radio-unselected)
|
|
18
|
-
);
|
|
19
|
-
cursor: pointer;
|
|
20
|
-
transition:
|
|
21
|
-
background-color 150ms ease,
|
|
22
|
-
border-color 150ms ease;
|
|
3
|
+
@layer ds.components.global {
|
|
4
|
+
/* Generated by @canonical/summon-component:react v0.1.0 */
|
|
23
5
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
6
|
+
/* The atomic radio control: a circular native input with the design-system
|
|
7
|
+
* selection chrome. Carries no label — the host supplies it. */
|
|
8
|
+
.ds.form-radio {
|
|
9
|
+
appearance: none;
|
|
10
|
+
box-sizing: border-box;
|
|
11
|
+
margin-inline: var(--form-input-padding-inline);
|
|
12
|
+
/* 16px control — a fixed element size, not a baseline multiple (the 4px-baseline
|
|
13
|
+
spike halved the old `--space-baseline × 2`). Stable --dimension-200 (16px). */
|
|
14
|
+
width: var(--dimension-200);
|
|
15
|
+
height: var(--dimension-200);
|
|
16
|
+
border: var(--dimension-stroke-thickness-medium) solid var(--color-border);
|
|
17
|
+
border-radius: 50%;
|
|
18
|
+
background-color: var(
|
|
19
|
+
--surface-color-foreground-radio-unselected,
|
|
20
|
+
var(--color-foreground-radio-unselected)
|
|
30
21
|
);
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
)
|
|
36
|
-
40%,
|
|
37
|
-
var(
|
|
38
|
-
--surface-color-foreground-radio-unselected,
|
|
39
|
-
var(--color-foreground-radio-unselected)
|
|
40
|
-
)
|
|
41
|
-
41%
|
|
42
|
-
);
|
|
43
|
-
}
|
|
22
|
+
cursor: pointer;
|
|
23
|
+
transition:
|
|
24
|
+
background-color var(--motion-duration-fast) ease,
|
|
25
|
+
border-color var(--motion-duration-fast) ease;
|
|
44
26
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
27
|
+
&:checked {
|
|
28
|
+
/* Dot = selected token, ring fill = unselected token; both surface-provided
|
|
29
|
+
* (flat fallback) so the control adapts to OnSurface stepping. */
|
|
30
|
+
border-color: var(
|
|
31
|
+
--surface-color-foreground-radio-selected,
|
|
32
|
+
var(--color-foreground-radio-selected)
|
|
33
|
+
);
|
|
34
|
+
background: radial-gradient(
|
|
35
|
+
var(
|
|
36
|
+
--surface-color-foreground-radio-selected,
|
|
37
|
+
var(--color-foreground-radio-selected)
|
|
38
|
+
)
|
|
39
|
+
40%,
|
|
40
|
+
var(
|
|
41
|
+
--surface-color-foreground-radio-unselected,
|
|
42
|
+
var(--color-foreground-radio-unselected)
|
|
43
|
+
)
|
|
44
|
+
41%
|
|
45
|
+
);
|
|
46
|
+
}
|
|
48
47
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
&:checked:hover:not(:disabled) {
|
|
53
|
-
border-color: var(--hover--color-foreground-radio-selected);
|
|
54
|
-
background: radial-gradient(
|
|
55
|
-
var(--hover--color-foreground-radio-selected) 40%,
|
|
56
|
-
var(
|
|
57
|
-
--surface-color-foreground-radio-unselected,
|
|
58
|
-
var(--color-foreground-radio-unselected)
|
|
59
|
-
)
|
|
60
|
-
41%
|
|
61
|
-
);
|
|
62
|
-
}
|
|
48
|
+
&:hover:not(:disabled):not(:checked) {
|
|
49
|
+
background-color: var(--color-foreground-radio-unselected-hover);
|
|
50
|
+
}
|
|
63
51
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
52
|
+
/* Hover on a selected radio shifts only the dot's fill, not via a whole-element
|
|
53
|
+
* brightness filter (which would also dim the ring). Re-paint the gradient with
|
|
54
|
+
* the hovered selected shade from the `--hover--…-selected` channel. */
|
|
55
|
+
&:checked:hover:not(:disabled) {
|
|
56
|
+
border-color: var(--hover--color-foreground-radio-selected);
|
|
57
|
+
background: radial-gradient(
|
|
58
|
+
var(--hover--color-foreground-radio-selected) 40%,
|
|
59
|
+
var(
|
|
60
|
+
--surface-color-foreground-radio-unselected,
|
|
61
|
+
var(--color-foreground-radio-unselected)
|
|
62
|
+
)
|
|
63
|
+
41%
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
&:focus-visible {
|
|
68
|
+
outline: none;
|
|
69
|
+
border-color: var(--color-focus-ring);
|
|
70
|
+
box-shadow: 0 0 0 1px var(--color-focus-ring);
|
|
71
|
+
}
|
|
69
72
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
73
|
+
&:disabled {
|
|
74
|
+
border-color: var(--color-border-disabled);
|
|
75
|
+
background-color: var(--color-foreground-radio-unselected-disabled);
|
|
76
|
+
cursor: not-allowed;
|
|
77
|
+
}
|
|
74
78
|
}
|
|
75
79
|
}
|