@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.
Files changed (126) hide show
  1. package/README.md +40 -0
  2. package/dist/esm/density.css +320 -302
  3. package/dist/esm/docs/examples/density-examples.css +19 -14
  4. package/dist/esm/index.css +361 -335
  5. package/dist/esm/lib/_work_in_progress/DensityTestbed/baseline-system.css +71 -64
  6. package/dist/esm/lib/_work_in_progress/DensityTestbed/density.testbed.css +127 -123
  7. package/dist/esm/lib/common/Wrapper/ToggleWrapper.css +73 -54
  8. package/dist/esm/lib/common/Wrapper/styles.css +35 -31
  9. package/dist/esm/lib/component/ChoicesField/common/Option/Option.js +4 -1
  10. package/dist/esm/lib/component/ChoicesField/common/Option/Option.js.map +1 -1
  11. package/dist/esm/lib/component/ChoicesField/styles.css +195 -163
  12. package/dist/esm/lib/component/RangeField/common/RangeControl/styles.css +39 -35
  13. package/dist/esm/lib/component/RichChoicesField/styles.css +93 -89
  14. package/dist/esm/lib/index.js +2 -0
  15. package/dist/esm/lib/index.js.map +1 -1
  16. package/dist/esm/lib/subcomponent/CheckboxInput/styles.css +115 -111
  17. package/dist/esm/lib/subcomponent/ColorInput/styles.css +177 -173
  18. package/dist/esm/lib/subcomponent/ComboboxInput/SingleCombobox.js +2 -1
  19. package/dist/esm/lib/subcomponent/ComboboxInput/SingleCombobox.js.map +1 -1
  20. package/dist/esm/lib/subcomponent/ComboboxInput/common/List/List.js +1 -1
  21. package/dist/esm/lib/subcomponent/ComboboxInput/common/List/List.js.map +1 -1
  22. package/dist/esm/lib/subcomponent/ComboboxInput/common/List/styles.css +33 -29
  23. package/dist/esm/lib/subcomponent/ComboboxInput/common/ResetButton/styles.css +21 -17
  24. package/dist/esm/lib/subcomponent/ComboboxInput/styles.css +59 -55
  25. package/dist/esm/lib/subcomponent/ComboboxInput/utils/index.js +0 -1
  26. package/dist/esm/lib/subcomponent/ComboboxInput/utils/index.js.map +1 -1
  27. package/dist/esm/lib/subcomponent/DateInput/styles.css +23 -19
  28. package/dist/esm/lib/subcomponent/DateTimeInput/styles.css +24 -20
  29. package/dist/esm/lib/subcomponent/Field/Description/styles.css +9 -5
  30. package/dist/esm/lib/subcomponent/Field/Error/styles.css +9 -5
  31. package/dist/esm/lib/subcomponent/Field/Label/Label.js +2 -2
  32. package/dist/esm/lib/subcomponent/Field/Label/Label.js.map +1 -1
  33. package/dist/esm/lib/subcomponent/Field/Label/styles.css +25 -21
  34. package/dist/esm/lib/subcomponent/FileUploadInput/styles.css +125 -119
  35. package/dist/esm/lib/subcomponent/NumberInput/styles.css +32 -28
  36. package/dist/esm/lib/subcomponent/PasswordInput/styles.css +58 -54
  37. package/dist/esm/lib/subcomponent/PhoneInput/PhoneInput.js +44 -20
  38. package/dist/esm/lib/subcomponent/PhoneInput/PhoneInput.js.map +1 -1
  39. package/dist/esm/lib/subcomponent/PhoneInput/styles.css +53 -49
  40. package/dist/esm/lib/subcomponent/RadioInput/styles.css +70 -66
  41. package/dist/esm/lib/subcomponent/RangeInput/styles.css +74 -70
  42. package/dist/esm/lib/subcomponent/RatingInput/styles.css +132 -128
  43. package/dist/esm/lib/subcomponent/SelectInput/styles.css +44 -40
  44. package/dist/esm/lib/subcomponent/SwitchInput/styles.css +90 -86
  45. package/dist/esm/lib/subcomponent/TextInput/styles.css +30 -26
  46. package/dist/esm/lib/subcomponent/TextareaInput/styles.css +14 -10
  47. package/dist/esm/lib/subcomponent/TimeInput/styles.css +19 -15
  48. package/dist/esm/lib/utils/countries/index.js +3 -3
  49. package/dist/esm/lib/utils/countries/index.js.map +1 -1
  50. package/dist/esm/lib/utils/formatter/applyPattern.js +38 -0
  51. package/dist/esm/lib/utils/formatter/applyPattern.js.map +1 -0
  52. package/dist/esm/lib/utils/formatter/createFormatterRegisterOptions.js +22 -0
  53. package/dist/esm/lib/utils/formatter/createFormatterRegisterOptions.js.map +1 -0
  54. package/dist/esm/lib/utils/formatter/createPatternFormatter.js +25 -0
  55. package/dist/esm/lib/utils/formatter/createPatternFormatter.js.map +1 -0
  56. package/dist/esm/lib/utils/formatter/index.js +8 -0
  57. package/dist/esm/lib/utils/formatter/index.js.map +1 -0
  58. package/dist/esm/lib/utils/formatter/stripToDigits.js +12 -0
  59. package/dist/esm/lib/utils/formatter/stripToDigits.js.map +1 -0
  60. package/dist/esm/lib/utils/formatter/types.js +2 -0
  61. package/dist/esm/lib/utils/formatter/types.js.map +1 -0
  62. package/dist/esm/lib/utils/hooks/index.js +1 -0
  63. package/dist/esm/lib/utils/hooks/index.js.map +1 -1
  64. package/dist/esm/lib/utils/hooks/types.js +2 -0
  65. package/dist/esm/lib/utils/hooks/types.js.map +1 -0
  66. package/dist/esm/lib/utils/hooks/useFormattedValue.js +195 -0
  67. package/dist/esm/lib/utils/hooks/useFormattedValue.js.map +1 -0
  68. package/dist/esm/lib/utils/index.js +6 -2
  69. package/dist/esm/lib/utils/index.js.map +1 -1
  70. package/dist/esm/lib/utils/mergeRefs.js +25 -0
  71. package/dist/esm/lib/utils/mergeRefs.js.map +1 -0
  72. package/dist/esm/lib/utils/middleware/addRESTValidation.js +1 -1
  73. package/dist/esm/lib/utils/middleware/addRESTValidation.js.map +1 -1
  74. package/dist/types/lib/component/ChoicesField/common/Option/Option.d.ts.map +1 -1
  75. package/dist/types/lib/component/PhoneField/PhoneField.d.ts +2 -1
  76. package/dist/types/lib/component/PhoneField/PhoneField.d.ts.map +1 -1
  77. package/dist/types/lib/index.d.ts +4 -0
  78. package/dist/types/lib/index.d.ts.map +1 -1
  79. package/dist/types/lib/subcomponent/ComboboxInput/SingleCombobox.d.ts.map +1 -1
  80. package/dist/types/lib/subcomponent/ComboboxInput/utils/index.d.ts +0 -1
  81. package/dist/types/lib/subcomponent/ComboboxInput/utils/index.d.ts.map +1 -1
  82. package/dist/types/lib/subcomponent/PhoneInput/PhoneInput.d.ts +19 -2
  83. package/dist/types/lib/subcomponent/PhoneInput/PhoneInput.d.ts.map +1 -1
  84. package/dist/types/lib/subcomponent/PhoneInput/types.d.ts +20 -7
  85. package/dist/types/lib/subcomponent/PhoneInput/types.d.ts.map +1 -1
  86. package/dist/types/lib/utils/countries/index.d.ts +0 -3
  87. package/dist/types/lib/utils/countries/index.d.ts.map +1 -1
  88. package/dist/types/lib/utils/formatter/applyPattern.d.ts +17 -0
  89. package/dist/types/lib/utils/formatter/applyPattern.d.ts.map +1 -0
  90. package/dist/types/lib/utils/formatter/createFormatterRegisterOptions.d.ts +20 -0
  91. package/dist/types/lib/utils/formatter/createFormatterRegisterOptions.d.ts.map +1 -0
  92. package/dist/types/lib/utils/formatter/createPatternFormatter.d.ts +19 -0
  93. package/dist/types/lib/utils/formatter/createPatternFormatter.d.ts.map +1 -0
  94. package/dist/types/lib/utils/formatter/index.d.ts +6 -0
  95. package/dist/types/lib/utils/formatter/index.d.ts.map +1 -0
  96. package/dist/types/lib/utils/formatter/stripToDigits.d.ts +10 -0
  97. package/dist/types/lib/utils/formatter/stripToDigits.d.ts.map +1 -0
  98. package/dist/types/lib/utils/formatter/types.d.ts +30 -0
  99. package/dist/types/lib/utils/formatter/types.d.ts.map +1 -0
  100. package/dist/types/lib/utils/hooks/index.d.ts +2 -0
  101. package/dist/types/lib/utils/hooks/index.d.ts.map +1 -1
  102. package/dist/types/lib/utils/hooks/types.d.ts +33 -0
  103. package/dist/types/lib/utils/hooks/types.d.ts.map +1 -0
  104. package/dist/types/lib/utils/hooks/useFormattedValue.d.ts +30 -0
  105. package/dist/types/lib/utils/hooks/useFormattedValue.d.ts.map +1 -0
  106. package/dist/types/lib/utils/index.d.ts +2 -0
  107. package/dist/types/lib/utils/index.d.ts.map +1 -1
  108. package/dist/types/lib/utils/mergeRefs.d.ts +14 -0
  109. package/dist/types/lib/utils/mergeRefs.d.ts.map +1 -0
  110. package/package.json +17 -16
  111. package/dist/esm/lib/subcomponent/ComboboxInput/utils/mergeRefs.js +0 -12
  112. package/dist/esm/lib/subcomponent/ComboboxInput/utils/mergeRefs.js.map +0 -1
  113. package/dist/esm/lib/utils/countries/applyPhoneMask.js +0 -35
  114. package/dist/esm/lib/utils/countries/applyPhoneMask.js.map +0 -1
  115. package/dist/esm/lib/utils/countries/phoneRegisterOptions.js +0 -18
  116. package/dist/esm/lib/utils/countries/phoneRegisterOptions.js.map +0 -1
  117. package/dist/esm/lib/utils/countries/removePhoneMask.js +0 -12
  118. package/dist/esm/lib/utils/countries/removePhoneMask.js.map +0 -1
  119. package/dist/types/lib/subcomponent/ComboboxInput/utils/mergeRefs.d.ts +0 -3
  120. package/dist/types/lib/subcomponent/ComboboxInput/utils/mergeRefs.d.ts.map +0 -1
  121. package/dist/types/lib/utils/countries/applyPhoneMask.d.ts +0 -14
  122. package/dist/types/lib/utils/countries/applyPhoneMask.d.ts.map +0 -1
  123. package/dist/types/lib/utils/countries/phoneRegisterOptions.d.ts +0 -14
  124. package/dist/types/lib/utils/countries/phoneRegisterOptions.d.ts.map +0 -1
  125. package/dist/types/lib/utils/countries/removePhoneMask.d.ts +0 -10
  126. package/dist/types/lib/utils/countries/removePhoneMask.d.ts.map +0 -1
@@ -1,105 +1,109 @@
1
- /* A switch is a checkbox (role="switch") styled as a sliding pill toggle.
2
- * The track is the <input> box; the knob is a `::before` pseudo-element that
3
- * slides from left (off) to right (on). Colours come from the switch token
4
- * channel; the geometry is in baseline multiples. */
5
- .ds.form-switch {
6
- /* Geometry, all derived from the track size and a 1px inset. Fixed element sizes
7
- (32×16px), NOT baseline multiples — the 4px-baseline spike halved the old
8
- `--space-baseline × 4 / × 2`. Stable dimension tokens decouple the switch size
9
- from the baseline grid unit. */
10
- --switch-track-width: var(--dimension-400); /* 32px */
11
- --switch-track-height: var(--dimension-200); /* 16px */
12
- --switch-knob-inset: 1px;
13
- --switch-knob-size: calc(
14
- var(--switch-track-height) -
15
- (var(--switch-knob-inset) * 2)
16
- );
1
+ /* Layer: ds.components.global (@canonical/styles README, "Cascade layers"). */
17
2
 
18
- appearance: none;
19
- box-sizing: border-box;
20
- position: relative;
3
+ @layer ds.components.global {
4
+ /* A switch is a checkbox (role="switch") styled as a sliding pill toggle.
5
+ * The track is the <input> box; the knob is a `::before` pseudo-element that
6
+ * slides from left (off) to right (on). Colours come from the switch token
7
+ * channel; the geometry is in baseline multiples. */
8
+ .ds.form-switch {
9
+ /* Geometry, all derived from the track size and a 1px inset. Fixed element sizes
10
+ (32×16px), NOT baseline multiples — the 4px-baseline spike halved the old
11
+ `--space-baseline × 4 / × 2`. Stable dimension tokens decouple the switch size
12
+ from the baseline grid unit. */
13
+ --switch-track-width: var(--dimension-400); /* 32px */
14
+ --switch-track-height: var(--dimension-200); /* 16px */
15
+ --switch-knob-inset: 1px;
16
+ --switch-knob-size: calc(
17
+ var(--switch-track-height) -
18
+ (var(--switch-knob-inset) * 2)
19
+ );
21
20
 
22
- /* Align to the field edge like the label, not the input's inner padding. */
23
- margin-inline: var(--form-label-padding-inline, 0);
21
+ appearance: none;
22
+ box-sizing: border-box;
23
+ position: relative;
24
24
 
25
- /* Track: a 2:1 pill. No border, so the width/height are the exact track box
26
- and the absolutely-positioned knob is measured against the same box (a
27
- border under `box-sizing: border-box` would shrink the padding box the knob
28
- is anchored to, throwing off the inset and slide). */
29
- width: var(--switch-track-width);
30
- height: var(--switch-track-height);
31
- border-radius: var(--dimension-radius-full);
32
- background: var(
33
- --surface-color-foreground-switch-unselected,
34
- var(--color-foreground-switch-unselected)
35
- );
36
- cursor: pointer;
37
- transition: background-color 150ms ease;
25
+ /* Align to the field edge like the label, not the input's inner padding. */
26
+ margin-inline: var(--form-label-padding-inline, 0);
38
27
 
39
- /* Knob: a circle inset from the track edges, sliding on the inline axis. */
40
- &::before {
41
- content: "";
42
- position: absolute;
43
- inset-block: var(--switch-knob-inset);
44
- inset-inline-start: var(--switch-knob-inset);
45
- width: var(--switch-knob-size);
46
- height: var(--switch-knob-size);
28
+ /* Track: a 2:1 pill. No border, so the width/height are the exact track box
29
+ and the absolutely-positioned knob is measured against the same box (a
30
+ border under `box-sizing: border-box` would shrink the padding box the knob
31
+ is anchored to, throwing off the inset and slide). */
32
+ width: var(--switch-track-width);
33
+ height: var(--switch-track-height);
47
34
  border-radius: var(--dimension-radius-full);
48
- /* Knob reads its surface-provided token (flat fallback) for OnSurface. */
49
- background: var(
50
- --surface-color-foreground-switch-knob,
51
- var(--color-foreground-switch-knob)
52
- );
53
- transition: translate 150ms ease;
54
- }
55
-
56
- &:checked {
57
- /* Selected track reads the surface-provided token (flat fallback). */
58
35
  background: var(
59
- --surface-color-foreground-switch-selected,
60
- var(--color-foreground-switch-selected)
36
+ --surface-color-foreground-switch-unselected,
37
+ var(--color-foreground-switch-unselected)
61
38
  );
39
+ cursor: pointer;
40
+ transition: background-color var(--motion-duration-fast) ease;
62
41
 
42
+ /* Knob: a circle inset from the track edges, sliding on the inline axis. */
63
43
  &::before {
64
- /* Slide to the far edge: the space left over after the knob and both
65
- insets are removed from the track width. */
66
- translate: calc(
67
- var(--switch-track-width) -
68
- var(--switch-knob-size) -
69
- (var(--switch-knob-inset) * 2)
70
- )
71
- 0;
44
+ content: "";
45
+ position: absolute;
46
+ inset-block: var(--switch-knob-inset);
47
+ inset-inline-start: var(--switch-knob-inset);
48
+ width: var(--switch-knob-size);
49
+ height: var(--switch-knob-size);
50
+ border-radius: var(--dimension-radius-full);
51
+ /* Knob reads its surface-provided token (flat fallback) for OnSurface. */
52
+ background: var(
53
+ --surface-color-foreground-switch-knob,
54
+ var(--color-foreground-switch-knob)
55
+ );
56
+ transition: translate var(--motion-duration-fast) ease;
72
57
  }
73
- }
74
58
 
75
- /* Hover shifts ONLY the track background, not the knob (per design review):
76
- * the track swaps to the hovered shade while the `::before` knob keeps its
77
- * colour. Shades come from the `--hover--…` channels (criticality-style OKLCH
78
- * delta shim), replacing the old whole-element `filter: brightness()` that
79
- * also dimmed the knob. */
80
- &:hover:not(:disabled):not(:checked) {
81
- background: var(--hover--color-foreground-switch-unselected);
82
- }
59
+ &:checked {
60
+ /* Selected track reads the surface-provided token (flat fallback). */
61
+ background: var(
62
+ --surface-color-foreground-switch-selected,
63
+ var(--color-foreground-switch-selected)
64
+ );
83
65
 
84
- &:checked:hover:not(:disabled) {
85
- background: var(--hover--color-foreground-switch-selected);
86
- }
66
+ &::before {
67
+ /* Slide to the far edge: the space left over after the knob and both
68
+ insets are removed from the track width. */
69
+ translate: calc(
70
+ var(--switch-track-width) -
71
+ var(--switch-knob-size) -
72
+ (var(--switch-knob-inset) * 2)
73
+ )
74
+ 0;
75
+ }
76
+ }
87
77
 
88
- &:focus-visible {
89
- outline: none;
90
- box-shadow: 0 0 0 1px var(--color-focusRing);
91
- }
78
+ /* Hover shifts ONLY the track background, not the knob (per design review):
79
+ * the track swaps to the hovered shade while the `::before` knob keeps its
80
+ * colour. Shades come from the `--hover--…` channels (criticality-style OKLCH
81
+ * delta shim), replacing the old whole-element `filter: brightness()` that
82
+ * also dimmed the knob. */
83
+ &:hover:not(:disabled):not(:checked) {
84
+ background: var(--hover--color-foreground-switch-unselected);
85
+ }
92
86
 
93
- &:disabled {
94
- cursor: not-allowed;
95
- background: var(--color-foreground-switch-unselected-disabled);
87
+ &:checked:hover:not(:disabled) {
88
+ background: var(--hover--color-foreground-switch-selected);
89
+ }
96
90
 
97
- &::before {
98
- background: var(--color-foreground-switch-knob-disabled);
91
+ &:focus-visible {
92
+ outline: none;
93
+ box-shadow: 0 0 0 1px var(--color-focus-ring);
99
94
  }
100
- }
101
95
 
102
- &:checked:disabled {
103
- background: var(--color-foreground-switch-selected-disabled);
96
+ &:disabled {
97
+ cursor: not-allowed;
98
+ background: var(--color-foreground-switch-unselected-disabled);
99
+
100
+ &::before {
101
+ background: var(--color-foreground-switch-knob-disabled);
102
+ }
103
+ }
104
+
105
+ &:checked:disabled {
106
+ background: var(--color-foreground-switch-selected-disabled);
107
+ }
104
108
  }
105
109
  }
@@ -1,30 +1,34 @@
1
- .ds.input.text {
2
- direction: inherit;
3
- display: flex;
4
- align-items: stretch;
5
- position: relative;
6
- padding: 0;
1
+ /* Layer: ds.components.global (@canonical/styles README, "Cascade layers"). */
7
2
 
8
- & > input {
9
- flex: 1;
10
- min-width: 0;
11
- border: none;
12
- background: transparent;
13
- color: inherit;
14
- font-family: inherit;
15
- outline: none;
16
- /* Baseline engine provides font-size, line-height, padding-top,
17
- padding-bottom via the .p class */
18
- padding-inline: var(--form-input-padding-inline);
19
- }
20
-
21
- & > .prefix,
22
- & > .suffix {
3
+ @layer ds.components.global {
4
+ .ds.input.text {
5
+ direction: inherit;
23
6
  display: flex;
24
- align-items: center;
25
- padding-inline: var(--form-field-inline-gap);
26
- color: var(--color-text-muted);
27
- white-space: nowrap;
28
- user-select: none;
7
+ align-items: stretch;
8
+ position: relative;
9
+ padding: 0;
10
+
11
+ & > input {
12
+ flex: 1;
13
+ min-width: 0;
14
+ border: none;
15
+ background: transparent;
16
+ color: inherit;
17
+ font-family: inherit;
18
+ outline: none;
19
+ /* Baseline engine provides font-size, line-height, padding-top,
20
+ padding-bottom via the .p class */
21
+ padding-inline: var(--form-input-padding-inline);
22
+ }
23
+
24
+ & > .prefix,
25
+ & > .suffix {
26
+ display: flex;
27
+ align-items: center;
28
+ padding-inline: var(--form-field-inline-gap);
29
+ color: var(--color-text-muted);
30
+ white-space: nowrap;
31
+ user-select: none;
32
+ }
29
33
  }
30
34
  }
@@ -1,12 +1,16 @@
1
- .ds.input.textarea {
2
- /* This element IS the text-bearing leaf, so it carries the inline padding
3
- * (`.ds.input.chrome` provides only the block padding). */
4
- padding-inline: var(--form-input-padding-inline);
1
+ /* Layer: ds.components.global (@canonical/styles README, "Cascade layers"). */
5
2
 
6
- /* Block placement is supplied by density.css (baseline-grid seating of the
7
- first line + grid-multiple line-height). The chrome contributes only its
8
- block padding as the box's own inset; the baseline nudge lives in density. */
9
- padding-block: var(--form-input-padding-block);
10
- min-height: calc(5lh + var(--form-input-padding-block) * 2);
11
- resize: vertical;
3
+ @layer ds.components.global {
4
+ .ds.input.textarea {
5
+ /* This element IS the text-bearing leaf, so it carries the inline padding
6
+ * (`.ds.input.chrome` provides only the block padding). */
7
+ padding-inline: var(--form-input-padding-inline);
8
+
9
+ /* Block placement is supplied by density.css (baseline-grid seating of the
10
+ first line + grid-multiple line-height). The chrome contributes only its
11
+ block padding as the box's own inset; the baseline nudge lives in density. */
12
+ padding-block: var(--form-input-padding-block);
13
+ min-height: calc(5lh + var(--form-input-padding-block) * 2);
14
+ resize: vertical;
15
+ }
12
16
  }
@@ -1,23 +1,27 @@
1
1
  /* Time — native input wrapper with shared chrome.
2
2
  * The .chrome class provides border, padding, focus, and state styles
3
3
  * from index.css's .ds.input.chrome rule. Component-specific overrides below.
4
+ *
5
+ * Layer: ds.components.global (@canonical/styles README, "Cascade layers").
4
6
  */
5
7
 
6
- .ds.input.time {
7
- /* This element IS the text-bearing leaf, so it carries the inline padding
8
- * (`.ds.input.chrome` provides only the block padding). */
9
- padding-inline: var(--form-input-padding-inline);
8
+ @layer ds.components.global {
9
+ .ds.input.time {
10
+ /* This element IS the text-bearing leaf, so it carries the inline padding
11
+ * (`.ds.input.chrome` provides only the block padding). */
12
+ padding-inline: var(--form-input-padding-inline);
10
13
 
11
- /* Suppress native clock picker inconsistencies across browsers */
12
- &::-webkit-inner-spin-button {
13
- display: none;
14
- }
14
+ /* Suppress native clock picker inconsistencies across browsers */
15
+ &::-webkit-inner-spin-button {
16
+ display: none;
17
+ }
15
18
 
16
- /* NOTE (design review — clock indicator → pragma icon): parked. There is no
17
- * clock/time glyph in @canonical/ds-assets to mask onto
18
- * `::-webkit-calendar-picker-indicator`, and that pseudo-element is
19
- * WebKit/Chromium-only (Firefox renders its own picker button that CSS cannot
20
- * target), so a custom icon can't be made consistent across browsers on a
21
- * native <input type="time">. Needs a new ds-assets glyph + accepting
22
- * Chrome/Safari-only styling, or a custom (non-native) control. */
19
+ /* NOTE (design review — clock indicator → pragma icon): parked. There is no
20
+ * clock/time glyph in @canonical/ds-assets to mask onto
21
+ * `::-webkit-calendar-picker-indicator`, and that pseudo-element is
22
+ * WebKit/Chromium-only (Firefox renders its own picker button that CSS cannot
23
+ * target), so a custom icon can't be made consistent across browsers on a
24
+ * native <input type="time">. Needs a new ds-assets glyph + accepting
25
+ * Chrome/Safari-only styling, or a custom (non-native) control. */
26
+ }
23
27
  }
@@ -1,6 +1,6 @@
1
- export { default as applyPhoneMask } from "./applyPhoneMask.js";
1
+ // The country dataset only. The display-mask helpers that used to live here are
2
+ // now the generic `utils/formatter` module — a phone pattern is one instance of
3
+ // the model/view split, not a phone-specific mechanism.
2
4
  export { default as countries } from "./countries.js";
3
5
  export { default as masks } from "./masks.js";
4
- export { default as phoneRegisterOptions } from "./phoneRegisterOptions.js";
5
- export { default as removePhoneMask } from "./removePhoneMask.js";
6
6
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/lib/utils/countries/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAChE,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEtD,OAAO,EAAE,OAAO,IAAI,KAAK,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,OAAO,IAAI,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAC5E,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,sBAAsB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/lib/utils/countries/index.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,gFAAgF;AAChF,wDAAwD;AAExD,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEtD,OAAO,EAAE,OAAO,IAAI,KAAK,EAAE,MAAM,YAAY,CAAC"}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Group a run of digits according to a display pattern (cosmetic only).
3
+ *
4
+ * The pattern uses `#` as a digit slot; any other character is a literal
5
+ * separator emitted between digits (e.g. `"(###) ###-####"`). Non-digits in
6
+ * `value` are stripped first, so the result is purely a function of the digits
7
+ * given. Extra digits beyond the pattern's slots are appended unformatted, so a
8
+ * longer-than-typical value is never truncated. With no pattern, the digits are
9
+ * returned as they are.
10
+ *
11
+ * This is display-only — callers keep the digits as the source of truth and
12
+ * recover them with {@link stripToDigits}.
13
+ *
14
+ * @note Pure.
15
+ */
16
+ export default function applyPattern(value, pattern) {
17
+ const digits = value.replace(/\D/g, "");
18
+ if (!pattern)
19
+ return digits;
20
+ let out = "";
21
+ let taken = 0;
22
+ for (const char of pattern) {
23
+ if (taken >= digits.length)
24
+ break;
25
+ if (char === "#") {
26
+ // `slice` rather than an index: it yields a string, not a value the type
27
+ // system claims is always present (see cs:code.array.safe_access).
28
+ out += digits.slice(taken, taken + 1);
29
+ taken += 1;
30
+ }
31
+ else {
32
+ out += char;
33
+ }
34
+ }
35
+ // Any digits beyond the pattern's slots are appended raw (never dropped).
36
+ return out + digits.slice(taken);
37
+ }
38
+ //# sourceMappingURL=applyPattern.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"applyPattern.js","sourceRoot":"","sources":["../../../../../src/lib/utils/formatter/applyPattern.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,OAAO,UAAU,YAAY,CAAC,KAAa,EAAE,OAAgB;IAClE,MAAM,MAAM,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IACxC,IAAI,CAAC,OAAO;QAAE,OAAO,MAAM,CAAC;IAE5B,IAAI,GAAG,GAAG,EAAE,CAAC;IACb,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,KAAK,MAAM,IAAI,IAAI,OAAO,EAAE,CAAC;QAC3B,IAAI,KAAK,IAAI,MAAM,CAAC,MAAM;YAAE,MAAM;QAClC,IAAI,IAAI,KAAK,GAAG,EAAE,CAAC;YACjB,yEAAyE;YACzE,mEAAmE;YACnE,GAAG,IAAI,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC;YACtC,KAAK,IAAI,CAAC,CAAC;QACb,CAAC;aAAM,CAAC;YACN,GAAG,IAAI,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IACD,0EAA0E;IAC1E,OAAO,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AACnC,CAAC"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Build react-hook-form `register()` options that normalise a formatted display
3
+ * value back to its model form, so the registered value is whatever the
4
+ * formatter's `parse` yields regardless of how the input is decorated on screen.
5
+ * Spread into `register(name, createFormatterRegisterOptions(formatter))`, or
6
+ * merge with your own rules.
7
+ *
8
+ * This covers the `register()` path only. react-hook-form does not apply
9
+ * `setValueAs` to a field bound with `useController`, so a controlled input must
10
+ * normalise in its own change handler instead — as PhoneInput does.
11
+ *
12
+ * @example
13
+ * <input {...register("phone", createFormatterRegisterOptions(formatter))} />
14
+ *
15
+ * @note Pure.
16
+ */
17
+ export default function createFormatterRegisterOptions(formatter) {
18
+ return {
19
+ setValueAs: (value) => formatter.parse(String(value ?? "")),
20
+ };
21
+ }
22
+ //# sourceMappingURL=createFormatterRegisterOptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createFormatterRegisterOptions.js","sourceRoot":"","sources":["../../../../../src/lib/utils/formatter/createFormatterRegisterOptions.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,OAAO,UAAU,8BAA8B,CACpD,SAAoB;IAEpB,OAAO;QACL,UAAU,EAAE,CAAC,KAAc,EAAE,EAAE,CAAC,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC;KACrE,CAAC;AACJ,CAAC"}
@@ -0,0 +1,25 @@
1
+ import applyPattern from "./applyPattern.js";
2
+ import stripToDigits from "./stripToDigits.js";
3
+ /**
4
+ * Build a {@link Formatter} for a fixed digit-grouping pattern — the common
5
+ * case, where the separators sit at the same offsets whatever the value is.
6
+ *
7
+ * The pattern uses `#` as a digit slot and treats any other character as a
8
+ * literal separator, so `"(###) ###-####"` groups ten digits as
9
+ * `"(555) 123-4567"`. With no pattern the formatter still strips the value to
10
+ * digits, which is how a field expresses "normalise but do not decorate".
11
+ *
12
+ * @example
13
+ * const formatter = createPatternFormatter("(###) ###-####");
14
+ * formatter.format("5551234567"); // "(555) 123-4567"
15
+ * formatter.parse("(555) 123-4567"); // "5551234567"
16
+ *
17
+ * @note Pure — the returned formatter's halves are pure too.
18
+ */
19
+ export default function createPatternFormatter(pattern) {
20
+ return {
21
+ format: (model) => applyPattern(model, pattern),
22
+ parse: stripToDigits,
23
+ };
24
+ }
25
+ //# sourceMappingURL=createPatternFormatter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createPatternFormatter.js","sourceRoot":"","sources":["../../../../../src/lib/utils/formatter/createPatternFormatter.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,mBAAmB,CAAC;AAC7C,OAAO,aAAa,MAAM,oBAAoB,CAAC;AAG/C;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,OAAO,UAAU,sBAAsB,CAAC,OAAgB;IAC7D,OAAO;QACL,MAAM,EAAE,CAAC,KAAa,EAAE,EAAE,CAAC,YAAY,CAAC,KAAK,EAAE,OAAO,CAAC;QACvD,KAAK,EAAE,aAAa;KACrB,CAAC;AACJ,CAAC"}
@@ -0,0 +1,8 @@
1
+ // Value formatting: the model/view split shared by any input whose displayed
2
+ // string is not the string it submits. `Formatter` is the contract; the helpers
3
+ // below cover the fixed-pattern case.
4
+ export { default as applyPattern } from "./applyPattern.js";
5
+ export { default as createFormatterRegisterOptions } from "./createFormatterRegisterOptions.js";
6
+ export { default as createPatternFormatter } from "./createPatternFormatter.js";
7
+ export { default as stripToDigits } from "./stripToDigits.js";
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/lib/utils/formatter/index.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,gFAAgF;AAChF,sCAAsC;AAEtC,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EAAE,OAAO,IAAI,8BAA8B,EAAE,MAAM,qCAAqC,CAAC;AAChG,OAAO,EAAE,OAAO,IAAI,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAChF,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,oBAAoB,CAAC"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Reduce a display string to the digits it contains, dropping every separator
3
+ * (spaces, dashes, parens, and anything else). This is the `parse` half of a
4
+ * digit-grouping {@link Formatter} — the inverse of
5
+ * {@link applyPattern}.
6
+ *
7
+ * @note Pure.
8
+ */
9
+ export default function stripToDigits(value) {
10
+ return value.replace(/\D/g, "");
11
+ }
12
+ //# sourceMappingURL=stripToDigits.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stripToDigits.js","sourceRoot":"","sources":["../../../../../src/lib/utils/formatter/stripToDigits.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,KAAa;IACjD,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;AAClC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../src/lib/utils/formatter/types.ts"],"names":[],"mappings":""}
@@ -1,4 +1,5 @@
1
1
  export { default as useFieldAriaProperties } from "./useFieldAriaProperties.js";
2
2
  export { default as useFieldError } from "./useFieldError.js";
3
+ export { default as useFormattedValue } from "./useFormattedValue.js";
3
4
  export { default as useOptionAriaProperties } from "./useOptionAriaProperties.js";
4
5
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/lib/utils/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAChF,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAE,OAAO,IAAI,uBAAuB,EAAE,MAAM,8BAA8B,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/lib/utils/hooks/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,OAAO,IAAI,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAChF,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAE,OAAO,IAAI,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AACtE,OAAO,EAAE,OAAO,IAAI,uBAAuB,EAAE,MAAM,8BAA8B,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../src/lib/utils/hooks/types.ts"],"names":[],"mappings":""}