@simplybusiness/mobius 10.3.2 → 10.3.3

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 (166) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/cjs/components/AddressLookup/AddressLookup.js +888 -5314
  3. package/dist/cjs/components/AddressLookup/AddressLookup.js.map +4 -4
  4. package/dist/cjs/components/AddressLookup/index.js +952 -5381
  5. package/dist/cjs/components/AddressLookup/index.js.map +4 -4
  6. package/dist/cjs/components/Checkbox/Checkbox.js +245 -5625
  7. package/dist/cjs/components/Checkbox/Checkbox.js.map +4 -4
  8. package/dist/cjs/components/Checkbox/CheckboxGroup.js +371 -5614
  9. package/dist/cjs/components/Checkbox/CheckboxGroup.js.map +4 -4
  10. package/dist/cjs/components/Checkbox/index.js +377 -5619
  11. package/dist/cjs/components/Checkbox/index.js.map +4 -4
  12. package/dist/cjs/components/Combobox/Combobox.js +829 -5344
  13. package/dist/cjs/components/Combobox/Combobox.js.map +4 -4
  14. package/dist/cjs/components/Combobox/index.js +813 -5327
  15. package/dist/cjs/components/Combobox/index.js.map +4 -4
  16. package/dist/cjs/components/DateField/DateField.js +379 -5505
  17. package/dist/cjs/components/DateField/DateField.js.map +4 -4
  18. package/dist/cjs/components/DateField/index.js +383 -5508
  19. package/dist/cjs/components/DateField/index.js.map +4 -4
  20. package/dist/cjs/components/ErrorMessage/ErrorMessage.js +120 -5643
  21. package/dist/cjs/components/ErrorMessage/ErrorMessage.js.map +4 -4
  22. package/dist/cjs/components/ErrorMessage/index.js +121 -5642
  23. package/dist/cjs/components/ErrorMessage/index.js.map +4 -4
  24. package/dist/cjs/components/ExpandableText/ExpandableText.js +511 -5604
  25. package/dist/cjs/components/ExpandableText/ExpandableText.js.map +4 -4
  26. package/dist/cjs/components/ExpandableText/index.js +512 -5604
  27. package/dist/cjs/components/ExpandableText/index.js.map +4 -4
  28. package/dist/cjs/components/MaskedField/MaskedField.js +394 -5511
  29. package/dist/cjs/components/MaskedField/MaskedField.js.map +4 -4
  30. package/dist/cjs/components/MaskedField/index.js +293 -5118
  31. package/dist/cjs/components/MaskedField/index.js.map +4 -4
  32. package/dist/cjs/components/NumberField/NumberField.js +357 -5523
  33. package/dist/cjs/components/NumberField/NumberField.js.map +4 -4
  34. package/dist/cjs/components/NumberField/index.js +358 -5523
  35. package/dist/cjs/components/NumberField/index.js.map +4 -4
  36. package/dist/cjs/components/PasswordField/PasswordField.js +330 -5511
  37. package/dist/cjs/components/PasswordField/PasswordField.js.map +4 -4
  38. package/dist/cjs/components/PasswordField/ShowHideButton.js +32 -5655
  39. package/dist/cjs/components/PasswordField/ShowHideButton.js.map +4 -4
  40. package/dist/cjs/components/PasswordField/index.js +332 -5512
  41. package/dist/cjs/components/PasswordField/index.js.map +4 -4
  42. package/dist/cjs/components/Radio/Radio.js +242 -5632
  43. package/dist/cjs/components/Radio/Radio.js.map +4 -4
  44. package/dist/cjs/components/Radio/RadioGroup.js +274 -5619
  45. package/dist/cjs/components/Radio/RadioGroup.js.map +4 -4
  46. package/dist/cjs/components/Radio/index.js +404 -5628
  47. package/dist/cjs/components/Radio/index.js.map +4 -4
  48. package/dist/cjs/components/Select/Select.js +233 -5588
  49. package/dist/cjs/components/Select/Select.js.map +4 -4
  50. package/dist/cjs/components/Select/index.js +234 -5588
  51. package/dist/cjs/components/Select/index.js.map +4 -4
  52. package/dist/cjs/components/TextArea/TextArea.js +229 -5531
  53. package/dist/cjs/components/TextArea/TextArea.js.map +4 -4
  54. package/dist/cjs/components/TextArea/index.js +230 -5531
  55. package/dist/cjs/components/TextArea/index.js.map +4 -4
  56. package/dist/cjs/components/TextField/TextField.js +265 -5522
  57. package/dist/cjs/components/TextField/TextField.js.map +4 -4
  58. package/dist/cjs/components/TextField/index.js +266 -5522
  59. package/dist/cjs/components/TextField/index.js.map +4 -4
  60. package/dist/cjs/components/index.js +4273 -5291
  61. package/dist/cjs/components/index.js.map +4 -4
  62. package/dist/cjs/index.js +4304 -5334
  63. package/dist/cjs/index.js.map +4 -4
  64. package/dist/cjs/meta.json +5734 -51529
  65. package/dist/esm/chunk-3O5DIIGS.js +1 -0
  66. package/dist/esm/chunk-3O5DIIGS.js.map +7 -0
  67. package/dist/esm/chunk-3PRSHEVX.js +1 -0
  68. package/dist/esm/chunk-3PRSHEVX.js.map +7 -0
  69. package/dist/esm/chunk-4NBLO5WK.js +54 -0
  70. package/dist/esm/chunk-4NBLO5WK.js.map +7 -0
  71. package/dist/esm/chunk-4WVJNNBK.js +157 -0
  72. package/dist/esm/chunk-4WVJNNBK.js.map +7 -0
  73. package/dist/esm/chunk-5L4G4VLM.js +1 -0
  74. package/dist/esm/chunk-5L4G4VLM.js.map +7 -0
  75. package/dist/esm/chunk-5OFXPT4J.js +135 -0
  76. package/dist/esm/chunk-5OFXPT4J.js.map +7 -0
  77. package/dist/esm/chunk-6O77SOOB.js +1 -0
  78. package/dist/esm/chunk-6O77SOOB.js.map +7 -0
  79. package/dist/esm/chunk-AFU7BFCD.js +151 -0
  80. package/dist/esm/chunk-AFU7BFCD.js.map +7 -0
  81. package/dist/esm/chunk-BGR2OTTR.js +1 -0
  82. package/dist/esm/chunk-BGR2OTTR.js.map +7 -0
  83. package/dist/esm/chunk-BIGO5EVC.js +1 -0
  84. package/dist/esm/chunk-BIGO5EVC.js.map +7 -0
  85. package/dist/esm/chunk-CUOVI2HT.js +1 -0
  86. package/dist/esm/chunk-CUOVI2HT.js.map +7 -0
  87. package/dist/esm/chunk-F4RQKLF7.js +1 -0
  88. package/dist/esm/chunk-F4RQKLF7.js.map +7 -0
  89. package/dist/esm/chunk-FKTDL7KO.js +355 -0
  90. package/dist/esm/chunk-FKTDL7KO.js.map +7 -0
  91. package/dist/esm/chunk-KQZ3MNK5.js +100 -0
  92. package/dist/esm/chunk-KQZ3MNK5.js.map +7 -0
  93. package/dist/esm/chunk-M2NDSQR5.js +106 -0
  94. package/dist/esm/chunk-M2NDSQR5.js.map +7 -0
  95. package/dist/esm/chunk-N4WQ6522.js +125 -0
  96. package/dist/esm/chunk-N4WQ6522.js.map +7 -0
  97. package/dist/esm/{chunk-CNOF66SV.js → chunk-NGNVAFBJ.js} +4 -4
  98. package/dist/esm/chunk-NOQ27VLY.js +1 -0
  99. package/dist/esm/chunk-NOQ27VLY.js.map +7 -0
  100. package/dist/esm/chunk-ONDOONBM.js +101 -0
  101. package/dist/esm/chunk-ONDOONBM.js.map +7 -0
  102. package/dist/esm/chunk-P34DI6BE.js +1 -0
  103. package/dist/esm/chunk-P34DI6BE.js.map +7 -0
  104. package/dist/esm/chunk-P5VEI574.js +97 -0
  105. package/dist/esm/chunk-P5VEI574.js.map +7 -0
  106. package/dist/esm/chunk-QPIA6BGW.js +64 -0
  107. package/dist/esm/chunk-QPIA6BGW.js.map +7 -0
  108. package/dist/esm/chunk-SZEFLEDA.js +1 -0
  109. package/dist/esm/chunk-SZEFLEDA.js.map +7 -0
  110. package/dist/esm/chunk-TXB4BOHB.js +1 -0
  111. package/dist/esm/chunk-TXB4BOHB.js.map +7 -0
  112. package/dist/esm/chunk-UIIXVY6K.js +123 -0
  113. package/dist/esm/chunk-UIIXVY6K.js.map +7 -0
  114. package/dist/esm/chunk-UQVAEWY2.js +44 -0
  115. package/dist/esm/chunk-UQVAEWY2.js.map +7 -0
  116. package/dist/esm/chunk-WC3D5GNN.js +29 -0
  117. package/dist/esm/chunk-WC3D5GNN.js.map +7 -0
  118. package/dist/esm/chunk-WNRO77YH.js +1 -0
  119. package/dist/esm/chunk-WNRO77YH.js.map +7 -0
  120. package/dist/esm/chunk-X6EPYQKX.js +96 -0
  121. package/dist/esm/chunk-X6EPYQKX.js.map +7 -0
  122. package/dist/esm/chunk-ZN5TRIVZ.js +41 -0
  123. package/dist/esm/chunk-ZN5TRIVZ.js.map +7 -0
  124. package/dist/esm/components/AddressLookup/AddressLookup.js +9 -106
  125. package/dist/esm/components/AddressLookup/index.js +10 -103
  126. package/dist/esm/components/Checkbox/Checkbox.js +3 -116
  127. package/dist/esm/components/Checkbox/CheckboxGroup.js +4 -114
  128. package/dist/esm/components/Checkbox/index.js +7 -114
  129. package/dist/esm/components/Combobox/Combobox.js +6 -107
  130. package/dist/esm/components/Combobox/index.js +8 -107
  131. package/dist/esm/components/DateField/DateField.js +6 -113
  132. package/dist/esm/components/DateField/index.js +7 -113
  133. package/dist/esm/components/ErrorMessage/ErrorMessage.js +1 -146
  134. package/dist/esm/components/ErrorMessage/index.js +2 -146
  135. package/dist/esm/components/ExpandableText/ExpandableText.js +1 -108
  136. package/dist/esm/components/ExpandableText/index.js +2 -108
  137. package/dist/esm/components/MaskedField/MaskedField.js +5 -114
  138. package/dist/esm/components/MaskedField/MaskedField.js.map +1 -1
  139. package/dist/esm/components/MaskedField/index.js +6 -114
  140. package/dist/esm/components/NumberField/NumberField.js +6 -114
  141. package/dist/esm/components/NumberField/index.js +7 -114
  142. package/dist/esm/components/PasswordField/PasswordField.js +7 -114
  143. package/dist/esm/components/PasswordField/ShowHideButton.js +1 -149
  144. package/dist/esm/components/PasswordField/index.js +8 -114
  145. package/dist/esm/components/Radio/Radio.js +3 -144
  146. package/dist/esm/components/Radio/RadioGroup.js +3 -114
  147. package/dist/esm/components/Radio/index.js +7 -115
  148. package/dist/esm/components/Select/Select.js +3 -114
  149. package/dist/esm/components/Select/index.js +4 -114
  150. package/dist/esm/components/Slider/Slider.js +2 -2
  151. package/dist/esm/components/Slider/index.js +2 -2
  152. package/dist/esm/components/TextArea/TextArea.js +3 -112
  153. package/dist/esm/components/TextArea/index.js +4 -112
  154. package/dist/esm/components/TextField/TextField.js +4 -114
  155. package/dist/esm/components/TextField/index.js +5 -114
  156. package/dist/esm/components/index.js +81 -44
  157. package/dist/esm/index.js +81 -39
  158. package/dist/esm/meta.json +6950 -19169
  159. package/dist/tsconfig.build.tsbuildinfo +1 -1
  160. package/package.json +1 -1
  161. package/src/components/ErrorMessage/ErrorMessage.tsx +1 -1
  162. package/src/components/ExpandableText/ExpandableText.tsx +3 -1
  163. package/src/components/PasswordField/ShowHideButton.tsx +1 -1
  164. package/dist/esm/chunk-W2RQH4WS.js +0 -1606
  165. package/dist/esm/chunk-W2RQH4WS.js.map +0 -7
  166. /package/dist/esm/{chunk-CNOF66SV.js.map → chunk-NGNVAFBJ.js.map} +0 -0
@@ -1,1606 +0,0 @@
1
- import {
2
- Accordion
3
- } from "./chunk-7JT4DKQA.js";
4
- import {
5
- isLoqateErrorResponse
6
- } from "./chunk-66ARYOY7.js";
7
- import {
8
- Listbox
9
- } from "./chunk-PQSPISME.js";
10
- import {
11
- useComboboxHighlight
12
- } from "./chunk-XZUQV54A.js";
13
- import {
14
- convertToDateFormat,
15
- isValidDate
16
- } from "./chunk-CI5GCPUG.js";
17
- import {
18
- useComboboxOptions
19
- } from "./chunk-GU5OMKTM.js";
20
- import {
21
- getOptionLabel,
22
- getOptionValue,
23
- isOptionGroup
24
- } from "./chunk-2JLZNSLY.js";
25
- import {
26
- Stack
27
- } from "./chunk-XH3OJQMW.js";
28
- import {
29
- Label
30
- } from "./chunk-ZN7OWLZY.js";
31
- import {
32
- adornmentWithClassName
33
- } from "./chunk-IM3I5CZL.js";
34
- import {
35
- TextAreaInput
36
- } from "./chunk-BM4M36KU.js";
37
- import {
38
- Icon
39
- } from "./chunk-TKIP5Q5H.js";
40
- import {
41
- TextOrHTML
42
- } from "./chunk-DYTHXKMX.js";
43
- import {
44
- VisuallyHidden
45
- } from "./chunk-PRZRE6A5.js";
46
- import {
47
- useBreakpoint
48
- } from "./chunk-7FQ7SXK4.js";
49
- import {
50
- useTextField
51
- } from "./chunk-UYVF3QSW.js";
52
- import {
53
- useLabel
54
- } from "./chunk-YLEFK7S2.js";
55
- import {
56
- useValidationClasses
57
- } from "./chunk-DYOFXXZD.js";
58
- import {
59
- mergeRefs
60
- } from "./chunk-QGGILW3D.js";
61
- import {
62
- spaceDelimitedList
63
- } from "./chunk-DTWRSP5P.js";
64
-
65
- // src/components/ErrorMessage/ErrorMessage.tsx
66
- import { error } from "@simplybusiness/icons";
67
- import classNames13 from "classnames/dedupe";
68
-
69
- // src/components/AddressLookup/AddressLookup.tsx
70
- import { search } from "@simplybusiness/icons";
71
- import { useCallback, useState as useState2 } from "react";
72
-
73
- // src/components/Combobox/Combobox.tsx
74
- import { useOnUnmount } from "@simplybusiness/mobius-hooks";
75
- import classNames2 from "classnames/dedupe";
76
- import { useEffect, useId, useRef, useState } from "react";
77
-
78
- // src/components/TextField/TextField.tsx
79
- import classNames from "classnames/dedupe";
80
- import "@simplybusiness/mobius/src/components/TextField/TextField.css";
81
- import { jsx, jsxs } from "react/jsx-runtime";
82
- var TextField = ({ ref, ...props }) => {
83
- const {
84
- isDisabled,
85
- type = "text",
86
- isInvalid,
87
- className,
88
- label,
89
- errorMessage,
90
- children,
91
- isRequired,
92
- prefixInside,
93
- prefixOutside,
94
- suffixInside,
95
- suffixOutside,
96
- autoComplete,
97
- isReadOnly,
98
- ...otherProps
99
- } = props;
100
- const resolvedAutoComplete = autoComplete ?? (type === "email" ? "email" : type === "tel" ? "tel" : void 0);
101
- const { inputProps, labelProps, errorMessageProps } = useTextField({
102
- ...props,
103
- autoComplete: resolvedAutoComplete,
104
- "aria-errormessage": errorMessage
105
- });
106
- const hidden = type === "hidden";
107
- const validationClasses = useValidationClasses({ isInvalid });
108
- const textfieldClasses = {
109
- "--is-disabled": isDisabled,
110
- "--is-required": typeof isRequired === "boolean" && isRequired,
111
- "--is-optional": typeof isRequired === "boolean" && !isRequired,
112
- "--is-hidden": hidden,
113
- [className || ""]: true
114
- };
115
- const sharedClasses = classNames(validationClasses, textfieldClasses);
116
- const labelClasses = classNames(
117
- {
118
- "--is-disabled": isDisabled
119
- },
120
- validationClasses
121
- );
122
- const containerClasses = classNames(
123
- "mobius",
124
- "mobius-text-field",
125
- sharedClasses
126
- );
127
- const inputClasses = classNames(
128
- "mobius",
129
- "mobius-text-field__input",
130
- sharedClasses
131
- );
132
- const inputWrapperClasses = classNames(
133
- "mobius-text-field__input-wrapper",
134
- sharedClasses
135
- );
136
- return /* @__PURE__ */ jsxs(Stack, { gap: "xs", className: containerClasses, children: [
137
- label && !hidden && /* @__PURE__ */ jsx(Label, { ...labelProps, className: labelClasses, children: label }),
138
- /* @__PURE__ */ jsxs("div", { className: "mobius-text-field__inner-container", children: [
139
- adornmentWithClassName(
140
- prefixOutside,
141
- labelClasses,
142
- "mobius-text-field__prefix-outside"
143
- ),
144
- /* @__PURE__ */ jsxs("div", { className: inputWrapperClasses, children: [
145
- adornmentWithClassName(
146
- prefixInside,
147
- labelClasses,
148
- "mobius-text-field__prefix-inside"
149
- ),
150
- /* @__PURE__ */ jsx(
151
- "input",
152
- {
153
- ...otherProps,
154
- ...inputProps,
155
- ref,
156
- type,
157
- className: inputClasses
158
- }
159
- ),
160
- adornmentWithClassName(
161
- suffixInside,
162
- labelClasses,
163
- "mobius-text-field__suffix-inside"
164
- )
165
- ] }),
166
- adornmentWithClassName(
167
- suffixOutside,
168
- labelClasses,
169
- "mobius-text-field__suffix-outside"
170
- )
171
- ] }),
172
- children && /* @__PURE__ */ jsx("div", { className: "mobius-text-field__children", children }),
173
- /* @__PURE__ */ jsx(ErrorMessage, { ...errorMessageProps, errorMessage })
174
- ] });
175
- };
176
- TextField.displayName = "TextField";
177
-
178
- // src/components/Combobox/Combobox.tsx
179
- import "@simplybusiness/mobius/src/components/Combobox/Combobox.css";
180
- import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
181
- var ComboboxInner = ({
182
- ref,
183
- ...props
184
- }) => {
185
- const {
186
- id,
187
- defaultValue,
188
- value,
189
- options,
190
- asyncOptions,
191
- delay,
192
- minSearchLength,
193
- onSelected,
194
- className,
195
- placeholder,
196
- icon,
197
- onBlur,
198
- onFocus,
199
- onChange,
200
- // onSearched, // unused prop, consider removing
201
- optionComponent,
202
- optionTestIdPrefix,
203
- errorMessage,
204
- ...otherProps
205
- } = props;
206
- const skipNextDebounceRef = useRef(false);
207
- const fallbackRef = useRef(null);
208
- const [inputValue, setInputValue] = useState(defaultValue || "");
209
- const [isOpen, setIsOpen] = useState(false);
210
- const [isChanging, setIsChanging] = useState(false);
211
- const { filteredOptions, updateFilteredOptions, isLoading, error: error2 } = useComboboxOptions({
212
- options,
213
- asyncOptions,
214
- inputValue,
215
- delay,
216
- minSearchLength,
217
- skipNextDebounceRef
218
- });
219
- const [validationError, setValidationError] = useState(
220
- error2?.message || errorMessage
221
- );
222
- const {
223
- highlightedIndex,
224
- highlightedGroupIndex,
225
- highlightNextOption,
226
- highlightPreviousOption,
227
- highlightFirstOption,
228
- highlightLastOption,
229
- clearHighlight
230
- } = useComboboxHighlight(filteredOptions);
231
- const inputRef = ref || fallbackRef;
232
- const listboxId = useId();
233
- const statusId = useId();
234
- const blurTimeoutRef = useRef(null);
235
- const userInteractedRef = useRef(false);
236
- const justSelectedRef = useRef(false);
237
- const { down } = useBreakpoint();
238
- const isMobile = down("md");
239
- useEffect(() => {
240
- setValidationError(error2?.message || errorMessage);
241
- }, [error2, errorMessage]);
242
- const getEmptyValue = () => {
243
- const firstOption = filteredOptions ? isOptionGroup(filteredOptions) ? filteredOptions[0]?.options[0] : filteredOptions[0] : options ? isOptionGroup(options) ? options[0]?.options[0] : options[0] : void 0;
244
- if (typeof firstOption === "string") {
245
- return "";
246
- }
247
- return { label: "", value: "" };
248
- };
249
- const handleFocus = (e) => {
250
- onFocus?.(e);
251
- if (!filteredOptions || filteredOptions.length === 0) return;
252
- if (blurTimeoutRef.current) {
253
- clearTimeout(blurTimeoutRef.current);
254
- blurTimeoutRef.current = null;
255
- }
256
- const isNaturalFocus = userInteractedRef.current || e.relatedTarget !== null;
257
- if (userInteractedRef.current) {
258
- userInteractedRef.current = false;
259
- }
260
- if (justSelectedRef.current && !isNaturalFocus) {
261
- return;
262
- }
263
- if (isNaturalFocus) {
264
- setIsOpen(true);
265
- justSelectedRef.current = false;
266
- }
267
- };
268
- useEffect(() => {
269
- if (!inputRef || typeof inputRef === "function") return;
270
- const inputElement = inputRef.current;
271
- if (!inputElement) return;
272
- const handleMouseDown = () => {
273
- userInteractedRef.current = true;
274
- };
275
- inputElement.addEventListener("mousedown", handleMouseDown);
276
- return () => {
277
- inputElement.removeEventListener("mousedown", handleMouseDown);
278
- };
279
- }, [inputRef]);
280
- useOnUnmount(() => {
281
- if (blurTimeoutRef.current) {
282
- clearTimeout(blurTimeoutRef.current);
283
- }
284
- });
285
- const handleInputChange = (e) => {
286
- const newValue = e.target.value;
287
- setInputValue(newValue);
288
- setValidationError(void 0);
289
- justSelectedRef.current = false;
290
- setIsChanging(true);
291
- if (!asyncOptions) {
292
- setIsOpen(true);
293
- }
294
- clearHighlight();
295
- onChange?.(e);
296
- };
297
- const handleOptionSelect = (option) => {
298
- const val = getOptionValue(option);
299
- if (!val && val !== "") return;
300
- if (typeof option === "object" && "callback" in option && option.callback && typeof option.callback === "function") {
301
- justSelectedRef.current = true;
302
- setTimeout(() => {
303
- if (inputRef && typeof inputRef !== "function" && inputRef.current) {
304
- inputRef.current.focus();
305
- }
306
- }, 0);
307
- const callbackPromise = option.callback();
308
- updateFilteredOptions(callbackPromise);
309
- callbackPromise.then(() => {
310
- setIsOpen(true);
311
- setIsChanging(true);
312
- }).catch(() => {
313
- });
314
- return;
315
- }
316
- skipNextDebounceRef.current = true;
317
- justSelectedRef.current = true;
318
- setIsChanging(false);
319
- setValidationError(void 0);
320
- setIsOpen(false);
321
- setInputValue(val);
322
- onSelected?.(option);
323
- };
324
- const getFirstOption = () => {
325
- if (!filteredOptions) return void 0;
326
- if (isOptionGroup(filteredOptions)) {
327
- return filteredOptions[0]?.options[0];
328
- }
329
- return filteredOptions[0];
330
- };
331
- const getHighlightedOption = () => {
332
- if (!filteredOptions) return void 0;
333
- if (highlightedIndex === -1) return void 0;
334
- if (isOptionGroup(filteredOptions)) {
335
- const group = filteredOptions[highlightedGroupIndex];
336
- return group?.options[highlightedIndex];
337
- }
338
- return filteredOptions[highlightedIndex];
339
- };
340
- const getHighlightedOptionId = () => {
341
- const option = getHighlightedOption();
342
- if (!option) return void 0;
343
- if (isOptionGroup(filteredOptions)) {
344
- return `${listboxId}-option-${highlightedGroupIndex}-${highlightedIndex}`;
345
- }
346
- return `${listboxId}-option-${highlightedIndex}`;
347
- };
348
- const handleBlur = (e) => {
349
- if (!justSelectedRef.current) {
350
- const typedText = inputValue.trim();
351
- const typedTextLower = typedText.toLowerCase();
352
- const highlightedOption = getHighlightedOption();
353
- const label = getOptionLabel(highlightedOption);
354
- if (typedTextLower === label?.toLowerCase()) {
355
- setTimeout(() => {
356
- handleOptionSelect(highlightedOption);
357
- }, 0);
358
- } else if (typedText === "") {
359
- setTimeout(() => {
360
- handleOptionSelect(getEmptyValue());
361
- }, 0);
362
- } else {
363
- setValidationError(
364
- errorMessage || "Please select an option from the list"
365
- );
366
- setTimeout(() => {
367
- setInputValue("");
368
- }, 0);
369
- }
370
- }
371
- blurTimeoutRef.current = setTimeout(() => {
372
- onBlur?.(e);
373
- setIsOpen(false);
374
- setIsChanging(false);
375
- }, 150);
376
- };
377
- const handleKeyDown = (e) => {
378
- switch (e.key) {
379
- case "ArrowDown":
380
- e.preventDefault();
381
- justSelectedRef.current = false;
382
- setIsOpen(true);
383
- highlightNextOption();
384
- break;
385
- case "ArrowUp":
386
- e.preventDefault();
387
- justSelectedRef.current = false;
388
- setIsOpen(true);
389
- highlightPreviousOption();
390
- break;
391
- case "Home":
392
- e.preventDefault();
393
- justSelectedRef.current = false;
394
- setIsOpen(true);
395
- highlightFirstOption();
396
- break;
397
- case "End":
398
- e.preventDefault();
399
- justSelectedRef.current = false;
400
- setIsOpen(true);
401
- highlightLastOption();
402
- break;
403
- case "Enter":
404
- e.preventDefault();
405
- if (isOpen) {
406
- const selectedOption = getHighlightedOption() || getFirstOption();
407
- if (selectedOption) {
408
- handleOptionSelect(selectedOption);
409
- }
410
- }
411
- break;
412
- case "Escape":
413
- e.preventDefault();
414
- setInputValue("");
415
- setIsOpen(false);
416
- clearHighlight();
417
- break;
418
- default:
419
- }
420
- };
421
- useEffect(() => {
422
- if (value) {
423
- setInputValue(value);
424
- }
425
- }, [value]);
426
- useEffect(() => {
427
- if (asyncOptions && isChanging) {
428
- setIsOpen(!!filteredOptions && filteredOptions.length > 0);
429
- }
430
- }, [filteredOptions, asyncOptions, isChanging]);
431
- const classes = classNames2(
432
- "mobius mobius-combobox",
433
- {
434
- "mobius-combobox--is-expanded": isOpen,
435
- "mobius-combobox--is-loading": isLoading,
436
- "mobius-combobox--is-mobile": isMobile
437
- },
438
- className
439
- );
440
- const getStatusMessage = () => {
441
- if (isLoading) return "Loading options";
442
- if (!filteredOptions || filteredOptions.length === 0) {
443
- return isChanging ? "No options found" : "";
444
- }
445
- const count = isOptionGroup(filteredOptions) ? filteredOptions.reduce((sum, group) => sum + group.options.length, 0) : filteredOptions.length;
446
- return isOpen && isChanging ? `${count} option${count === 1 ? "" : "s"} available` : "";
447
- };
448
- return /* @__PURE__ */ jsxs2("div", { id, "data-testid": "mobius-combobox__wrapper", className: classes, children: [
449
- /* @__PURE__ */ jsx2(
450
- VisuallyHidden,
451
- {
452
- role: "status",
453
- "aria-live": "polite",
454
- id: statusId,
455
- elementType: "div",
456
- className: "mobius-combobox__status",
457
- children: getStatusMessage()
458
- }
459
- ),
460
- /* @__PURE__ */ jsx2(
461
- TextField,
462
- {
463
- ...otherProps,
464
- className: "mobius-combobox__input",
465
- role: "combobox",
466
- value: inputValue,
467
- placeholder,
468
- onFocus: handleFocus,
469
- onBlur: handleBlur,
470
- onKeyDown: handleKeyDown,
471
- onChange: handleInputChange,
472
- autoComplete: "off",
473
- "aria-describedby": isLoading ? statusId : void 0,
474
- "aria-autocomplete": "list",
475
- "aria-haspopup": "listbox",
476
- "aria-controls": isOpen ? listboxId : void 0,
477
- "aria-expanded": isOpen,
478
- "aria-activedescendant": highlightedIndex === -1 ? void 0 : getHighlightedOptionId(),
479
- prefixInside: icon,
480
- ref: inputRef,
481
- errorMessage: errorMessage || validationError || error2?.message
482
- }
483
- ),
484
- /* @__PURE__ */ jsx2(
485
- Listbox,
486
- {
487
- id: listboxId,
488
- isOpen,
489
- isLoading,
490
- options: filteredOptions,
491
- highlightedIndex,
492
- highlightedGroupIndex,
493
- onOptionSelect: handleOptionSelect,
494
- optionComponent,
495
- optionTestIdPrefix
496
- }
497
- )
498
- ] });
499
- };
500
- var Combobox = ComboboxInner;
501
-
502
- // src/components/AddressLookup/AddressLookup.tsx
503
- import { jsx as jsx3 } from "react/jsx-runtime";
504
- function optionsFromResponse({ Items }, addressLookupService) {
505
- if (!Items || !Array.isArray(Items)) {
506
- throw Error("No address found");
507
- }
508
- if (isLoqateErrorResponse(Items)) {
509
- throw Error(Items[0].Description);
510
- }
511
- return Items.map((item) => ({
512
- id: item.Id,
513
- label: `${item.Text}, ${item.Description}`,
514
- value: item.Text,
515
- // Add a callback to trigger secondary search
516
- // if the address type is not "Address"
517
- callback: item.Type === "Address" ? void 0 : async () => {
518
- const result = await addressLookupService.findById(item.Id);
519
- return optionsFromResponse(result, addressLookupService);
520
- }
521
- }));
522
- }
523
- var AddressLookup = ({
524
- ref,
525
- addressLookupService,
526
- onAddressSelected,
527
- onOptionsDisplayed,
528
- onError,
529
- errorMessage,
530
- ...otherProps
531
- }) => {
532
- const [error2, _setError] = useState2(null);
533
- const setError = useCallback(
534
- (newError) => {
535
- if (newError != null) onError?.(newError);
536
- _setError(newError);
537
- },
538
- [onError]
539
- );
540
- const asyncOptions = useCallback(
541
- async (searchTerm) => {
542
- try {
543
- const response = await addressLookupService.search(searchTerm);
544
- setError(null);
545
- const options = optionsFromResponse(response, addressLookupService);
546
- onOptionsDisplayed?.();
547
- return options;
548
- } catch (e) {
549
- setError(e);
550
- return [];
551
- }
552
- },
553
- [addressLookupService, setError, onOptionsDisplayed]
554
- );
555
- const handleSelected = (selected) => {
556
- setError(null);
557
- const isEmpty = typeof selected === "string" ? selected === "" : !selected.id && !selected.value;
558
- if (isEmpty) {
559
- return Promise.resolve();
560
- }
561
- if (typeof selected === "string" || !selected.id) {
562
- setError(new Error("Selected option missing id"));
563
- return Promise.resolve();
564
- }
565
- return addressLookupService.get(selected.id).then(onAddressSelected).catch(setError);
566
- };
567
- const realErrorMessage = error2 && "An error occurred" || errorMessage;
568
- return /* @__PURE__ */ jsx3(
569
- Combobox,
570
- {
571
- ...otherProps,
572
- ref,
573
- onSelected: handleSelected,
574
- asyncOptions,
575
- errorMessage: realErrorMessage,
576
- icon: /* @__PURE__ */ jsx3(Icon, { icon: search })
577
- }
578
- );
579
- };
580
- AddressLookup.displayName = "AddressLookup";
581
-
582
- // src/components/Checkbox/Checkbox.tsx
583
- import { useRef as useRef2, useId as useId2, useState as useState3, useEffect as useEffect2 } from "react";
584
- import classNames3 from "classnames/dedupe";
585
- import { squareTick, square } from "@simplybusiness/icons";
586
- import "@simplybusiness/mobius/src/components/Checkbox/Checkbox.css";
587
- import { jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
588
- var Checkbox = ({ ref, ...props }) => {
589
- const {
590
- id,
591
- label,
592
- isDisabled,
593
- isRequired,
594
- isInvalid,
595
- onChange,
596
- className,
597
- errorMessage,
598
- selected,
599
- defaultSelected = false,
600
- isReadOnly,
601
- isLastItem,
602
- name,
603
- value,
604
- ["aria-describedby"]: ariaDescribedBy,
605
- ...rest
606
- } = props;
607
- const [checked, setChecked] = useState3(defaultSelected);
608
- const fallbackRef = useRef2(null);
609
- const refObj = ref || fallbackRef;
610
- const inputId = useId2();
611
- const isControlled = typeof selected === "boolean";
612
- useEffect2(() => {
613
- if (isControlled) {
614
- setChecked(selected);
615
- }
616
- }, [selected, isControlled]);
617
- const validationClasses = useValidationClasses({ isInvalid });
618
- const sharedClasses = classNames3(
619
- {
620
- "--is-disabled": isDisabled,
621
- "--is-selected": checked,
622
- "--is-required": typeof isRequired === "boolean" && isRequired,
623
- "--is-optional": typeof isRequired === "boolean" && !isRequired
624
- },
625
- validationClasses
626
- );
627
- const wrapperClasses = classNames3(
628
- "mobius",
629
- "mobius-checkbox",
630
- sharedClasses,
631
- className
632
- );
633
- const labelClasses = classNames3("mobius-checkbox__label", sharedClasses);
634
- const inputClasses = classNames3("mobius-checkbox__input", sharedClasses);
635
- const iconClasses = classNames3("mobius-checkbox__icon", sharedClasses);
636
- const errorMessageId = useId2();
637
- const shouldErrorMessageShow = errorMessage ? errorMessageId : void 0;
638
- const describedBy = spaceDelimitedList([
639
- shouldErrorMessageShow,
640
- ariaDescribedBy
641
- ]);
642
- const labelId = useId2();
643
- const handleChange = (event) => {
644
- setChecked(!checked);
645
- if (onChange) {
646
- onChange(event, isLastItem);
647
- }
648
- };
649
- return /* @__PURE__ */ jsxs3(Stack, { gap: "xs", className: wrapperClasses, children: [
650
- /* @__PURE__ */ jsxs3("label", { className: labelClasses, children: [
651
- /* @__PURE__ */ jsx4(
652
- "input",
653
- {
654
- "aria-describedby": describedBy,
655
- "aria-errormessage": shouldErrorMessageShow,
656
- "aria-invalid": isInvalid,
657
- "aria-labelledby": labelId,
658
- readOnly: isReadOnly,
659
- disabled: isDisabled,
660
- ref: refObj,
661
- className: inputClasses,
662
- onChange: handleChange,
663
- type: "checkbox",
664
- checked,
665
- required: isRequired,
666
- id: id || inputId,
667
- name,
668
- value,
669
- ...rest
670
- }
671
- ),
672
- /* @__PURE__ */ jsx4(
673
- Icon,
674
- {
675
- icon: checked ? squareTick : square,
676
- size: "md",
677
- className: iconClasses
678
- }
679
- ),
680
- /* @__PURE__ */ jsx4("span", { id: labelId, className: "mobius-checkbox__visible-label", children: label })
681
- ] }),
682
- /* @__PURE__ */ jsx4(ErrorMessage, { id: errorMessageId, errorMessage })
683
- ] });
684
- };
685
- Checkbox.displayName = "Checkbox";
686
-
687
- // src/components/Checkbox/CheckboxGroup.tsx
688
- import classNames4 from "classnames/dedupe";
689
- import {
690
- Children,
691
- cloneElement,
692
- isValidElement,
693
- useEffect as useEffect3,
694
- useId as useId3,
695
- useRef as useRef3,
696
- useState as useState4
697
- } from "react";
698
- import "@simplybusiness/mobius/src/components/Checkbox/CheckboxGroup.css";
699
- import { jsx as jsx5, jsxs as jsxs4 } from "react/jsx-runtime";
700
- var CheckboxGroup = ({ ref, ...props }) => {
701
- const {
702
- label,
703
- isDisabled = false,
704
- isRequired,
705
- isInvalid,
706
- orientation = "vertical",
707
- onChange,
708
- className,
709
- errorMessage,
710
- children,
711
- defaultValue = [],
712
- isReadOnly,
713
- itemsPerRow,
714
- lastItemDisables = false,
715
- ...rest
716
- } = props;
717
- const [selected, setSelected] = useState4(defaultValue);
718
- const isInitializedRef = useRef3(false);
719
- const prevDefaultValueRef = useRef3(defaultValue);
720
- useEffect3(() => {
721
- const hasChanged = defaultValue.length !== prevDefaultValueRef.current.length || defaultValue.some(
722
- (val, index) => val !== prevDefaultValueRef.current[index]
723
- );
724
- if (hasChanged || !isInitializedRef.current) {
725
- setSelected(defaultValue);
726
- prevDefaultValueRef.current = defaultValue;
727
- isInitializedRef.current = true;
728
- }
729
- }, [defaultValue]);
730
- const checkboxGroupClasses = classNames4(
731
- "mobius",
732
- "mobius-checkbox-group",
733
- className,
734
- {
735
- "--is-horizontal": orientation === "horizontal",
736
- "--is-vertical": orientation === "vertical",
737
- "--is-required": typeof isRequired === "boolean" && isRequired,
738
- "--is-optional": typeof isRequired === "boolean" && !isRequired
739
- }
740
- );
741
- const validationClasses = useValidationClasses({ isInvalid });
742
- const labelClasses = classNames4(
743
- {
744
- "--is-disabled": isDisabled
745
- },
746
- validationClasses
747
- );
748
- const errorMessageId = useId3();
749
- const shouldErrorMessageShow = errorMessage ? errorMessageId : void 0;
750
- const describedBy = spaceDelimitedList([
751
- shouldErrorMessageShow,
752
- props["aria-describedby"]
753
- ]);
754
- const labelId = useId3();
755
- const handleChange = (event, isLastItem = false) => {
756
- const {
757
- target: { value, checked }
758
- } = event;
759
- let newValue = [...selected];
760
- if (!checked) {
761
- newValue = selected.filter((item) => item !== value);
762
- }
763
- if (checked) {
764
- newValue = [...selected, value];
765
- }
766
- if (checked && lastItemDisables && isLastItem) {
767
- newValue = [value];
768
- }
769
- setSelected(newValue);
770
- onChange?.(newValue);
771
- };
772
- const childrenArray = Children.toArray(children);
773
- const lastCheckbox = childrenArray.filter(
774
- (child) => isValidElement(child) && child.type === Checkbox
775
- ).pop();
776
- const lastCheckboxIsChecked = lastCheckbox && selected.includes(lastCheckbox.props.value);
777
- return /* @__PURE__ */ jsxs4(
778
- "div",
779
- {
780
- ...rest,
781
- "aria-labelledby": props["aria-labelledby"] || labelId,
782
- ref,
783
- className: checkboxGroupClasses,
784
- role: "group",
785
- style: {
786
- "--checkbox-items-per-row": itemsPerRow || Children.count(children)
787
- },
788
- children: [
789
- label && /* @__PURE__ */ jsx5(Label, { elementType: "span", id: labelId, className: labelClasses, children: label }),
790
- /* @__PURE__ */ jsx5("div", { className: "mobius-checkbox-group__wrapper", children: childrenArray.map((child) => {
791
- if (isValidElement(child)) {
792
- const isLastItem = child === lastCheckbox;
793
- const isChildDisabled = isDisabled || lastItemDisables && lastCheckboxIsChecked && !isLastItem;
794
- const childProps = child.props;
795
- return cloneElement(
796
- child,
797
- {
798
- isDisabled: isChildDisabled,
799
- isRequired,
800
- isReadOnly,
801
- isInvalid,
802
- isLastItem,
803
- selected: selected.includes(childProps.value),
804
- onChange: childProps.onChange || handleChange,
805
- "aria-describedby": describedBy
806
- }
807
- );
808
- }
809
- return child;
810
- }) }),
811
- errorMessage && /* @__PURE__ */ jsx5(ErrorMessage, { id: errorMessageId, errorMessage })
812
- ]
813
- }
814
- );
815
- };
816
- CheckboxGroup.displayName = "CheckboxGroup";
817
-
818
- // src/components/DateField/DateField.tsx
819
- import classNames5 from "classnames/dedupe";
820
- import { useEffect as useEffect4, useRef as useRef4, useState as useState5 } from "react";
821
- import { jsx as jsx6 } from "react/jsx-runtime";
822
- var MIN_MAX_ERROR = '"min" value should not be greater than "max" value.';
823
- var DateField = ({ ref, ...props }) => {
824
- const {
825
- min,
826
- max,
827
- format,
828
- className,
829
- errorMessage,
830
- defaultValue,
831
- value,
832
- ...otherProps
833
- } = props;
834
- const [error2, setError] = useState5(errorMessage);
835
- const [isInvalid, setIsInvalid] = useState5(void 0);
836
- const localRef = useRef4(null);
837
- const classes = classNames5("mobius-date-field", className);
838
- const formattedMin = min ? convertToDateFormat(min, format) : void 0;
839
- const formattedMax = max ? convertToDateFormat(max, format) : void 0;
840
- const formattedDefaultValue = defaultValue ? convertToDateFormat(defaultValue, format) : void 0;
841
- const formattedValue = value ? convertToDateFormat(value, format) : void 0;
842
- const setInvalidState = (error3) => {
843
- setError(error3);
844
- setIsInvalid(true);
845
- };
846
- const setValidState = () => {
847
- setError(props.errorMessage);
848
- setIsInvalid(false);
849
- };
850
- useEffect4(() => {
851
- if (!isValidDate(min, format)) {
852
- setInvalidState(`Invalid min date: ${min}`);
853
- return;
854
- }
855
- if (!isValidDate(max, format)) {
856
- setInvalidState(`Invalid max date: ${max}`);
857
- return;
858
- }
859
- if (min && max) {
860
- const minDate = new Date(min);
861
- const maxDate = new Date(max);
862
- if (minDate > maxDate) {
863
- setInvalidState(MIN_MAX_ERROR);
864
- } else {
865
- setValidState();
866
- }
867
- } else {
868
- setValidState();
869
- }
870
- }, [min, max, format]);
871
- const validate = () => {
872
- const isValidInput = localRef.current?.checkValidity();
873
- if (!isValidInput) {
874
- setInvalidState("Invalid date input");
875
- } else {
876
- setValidState();
877
- }
878
- };
879
- const handleBlur = (event) => {
880
- validate();
881
- otherProps.onBlur?.(event);
882
- };
883
- return /* @__PURE__ */ jsx6(
884
- TextField,
885
- {
886
- ref: mergeRefs([localRef, ref]),
887
- className: classes,
888
- type: "date",
889
- min: formattedMin,
890
- max: formattedMax,
891
- errorMessage: errorMessage ?? error2,
892
- isInvalid,
893
- defaultValue: formattedDefaultValue,
894
- value: formattedValue,
895
- onBlur: handleBlur,
896
- ...otherProps
897
- }
898
- );
899
- };
900
- DateField.displayName = "DateField";
901
-
902
- // src/components/NumberField/NumberField.tsx
903
- import classNames6 from "classnames/dedupe";
904
- import { useCallback as useCallback2, useEffect as useEffect5, useRef as useRef5 } from "react";
905
- import "@simplybusiness/mobius/src/components/NumberField/NumberField.css";
906
- import { jsx as jsx7 } from "react/jsx-runtime";
907
- var NumberField = ({ ref, ...props }) => {
908
- const {
909
- minValue,
910
- maxValue,
911
- step,
912
- defaultValue,
913
- hideSpinButtons,
914
- className,
915
- ...otherProps
916
- } = props;
917
- const {
918
- onFocus: customOnFocus,
919
- onBlur: customOnBlur,
920
- ...rest
921
- } = otherProps;
922
- const focusedInputRef = useRef5(null);
923
- const wheelHandler = useCallback2((ev) => ev.preventDefault(), []);
924
- useEffect5(() => {
925
- return () => {
926
- focusedInputRef.current?.removeEventListener("wheel", wheelHandler);
927
- focusedInputRef.current = null;
928
- };
929
- }, [wheelHandler]);
930
- const containerClasses = classNames6("mobius-number-field", className, {
931
- "--hide-spin-buttons": hideSpinButtons
932
- });
933
- const handleBeforeInput = (event) => {
934
- const { data } = event.nativeEvent;
935
- if (step && Number.isInteger(step) && data === ".") {
936
- event.preventDefault();
937
- }
938
- if (minValue && minValue >= 0 && data === "-") {
939
- event.preventDefault();
940
- }
941
- };
942
- const handleBlur = (event) => {
943
- const { value } = event.target;
944
- const numValue = parseFloat(value);
945
- if (step && step > 1 && !isNaN(numValue)) {
946
- const baseValue = minValue ?? 0;
947
- const steps = Math.round((numValue - baseValue) / step);
948
- const snappedValue = baseValue + steps * step;
949
- if (snappedValue !== numValue) {
950
- event.target.value = snappedValue.toString();
951
- const changeEvent = new Event("change", { bubbles: true });
952
- event.target.dispatchEvent(changeEvent);
953
- const syntheticChangeEvent = {
954
- ...event,
955
- target: event.target,
956
- currentTarget: event.currentTarget
957
- };
958
- otherProps.onChange?.(syntheticChangeEvent);
959
- }
960
- }
961
- customOnBlur?.(event);
962
- };
963
- const forwardedProps = {
964
- ...rest,
965
- onFocus: (e) => {
966
- const el = e.currentTarget;
967
- focusedInputRef.current?.removeEventListener("wheel", wheelHandler);
968
- focusedInputRef.current = el;
969
- el.addEventListener("wheel", wheelHandler, { passive: false });
970
- customOnFocus?.(e);
971
- },
972
- onBlur: (e) => handleBlur(e)
973
- };
974
- return /* @__PURE__ */ jsx7(
975
- TextField,
976
- {
977
- ...forwardedProps,
978
- className: containerClasses,
979
- onBeforeInput: handleBeforeInput,
980
- type: "number",
981
- min: minValue ?? void 0,
982
- max: maxValue ?? void 0,
983
- step,
984
- ref,
985
- defaultValue: defaultValue != null ? defaultValue?.toString() : defaultValue
986
- }
987
- );
988
- };
989
- NumberField.displayName = "NumberField";
990
-
991
- // src/components/PasswordField/PasswordField.tsx
992
- import classNames7 from "classnames/dedupe";
993
- import { useRef as useRef6, useState as useState6 } from "react";
994
-
995
- // src/components/PasswordField/ShowHideButton.tsx
996
- import { eye, eyeSlash } from "@simplybusiness/icons";
997
- import { jsx as jsx8 } from "react/jsx-runtime";
998
- var ShowHideButton = ({
999
- show = false,
1000
- onClick
1001
- }) => /* @__PURE__ */ jsx8(
1002
- "button",
1003
- {
1004
- className: "mobius-password-field__show-button",
1005
- type: "button",
1006
- onClick: (e) => {
1007
- e.preventDefault();
1008
- onClick();
1009
- },
1010
- "aria-label": `${show ? "Hide" : "Show"} password`,
1011
- "data-testid": "show-hide-button",
1012
- children: /* @__PURE__ */ jsx8(Icon, { icon: show ? eyeSlash : eye, "aria-hidden": "true" })
1013
- }
1014
- );
1015
-
1016
- // src/components/PasswordField/PasswordField.tsx
1017
- import "@simplybusiness/mobius/src/components/PasswordField/PasswordField.css";
1018
- import { jsx as jsx9 } from "react/jsx-runtime";
1019
- var PasswordField = ({
1020
- ref,
1021
- className,
1022
- autoComplete = "current-password",
1023
- ...props
1024
- }) => {
1025
- const [show, setShow] = useState6(false);
1026
- const type = show ? "text" : "password";
1027
- const classes = classNames7("mobius-password-field", className);
1028
- const localRef = useRef6(null);
1029
- const handleShowHideButtonClick = () => {
1030
- const selectionStart = localRef.current?.selectionStart;
1031
- const selectionEnd = localRef.current?.selectionEnd;
1032
- setShow((oldShow) => !oldShow);
1033
- requestAnimationFrame(() => {
1034
- localRef.current?.focus();
1035
- if (selectionStart != null && selectionEnd != null) {
1036
- localRef.current?.setSelectionRange(selectionStart, selectionEnd);
1037
- }
1038
- });
1039
- };
1040
- return /* @__PURE__ */ jsx9(
1041
- TextField,
1042
- {
1043
- ref: mergeRefs([localRef, ref]),
1044
- className: classes,
1045
- ...props,
1046
- autoComplete,
1047
- type,
1048
- suffixInside: /* @__PURE__ */ jsx9(ShowHideButton, { onClick: handleShowHideButtonClick, show })
1049
- }
1050
- );
1051
- };
1052
- PasswordField.displayName = "PasswordField";
1053
-
1054
- // src/components/Radio/Radio.tsx
1055
- import classNames8 from "classnames/dedupe";
1056
- import {
1057
- Children as Children2,
1058
- isValidElement as isValidElement2,
1059
- useLayoutEffect,
1060
- useMemo,
1061
- useRef as useRef7
1062
- } from "react";
1063
- import "@simplybusiness/mobius/src/components/Radio/Radio.css";
1064
- import { Fragment, jsx as jsx10, jsxs as jsxs5 } from "react/jsx-runtime";
1065
- var Radio = ({ ref, ...props }) => {
1066
- const {
1067
- children,
1068
- value,
1069
- label,
1070
- className,
1071
- isDisabled,
1072
- errorMessage,
1073
- onChange,
1074
- defaultChecked,
1075
- groupDisabled,
1076
- name,
1077
- selected,
1078
- setSelected,
1079
- isRequired,
1080
- onOverflow,
1081
- orientation,
1082
- ...otherProps
1083
- } = props;
1084
- const realDisabled = groupDisabled || isDisabled;
1085
- const isMultiline = label && children;
1086
- const isControlled = selected !== void 0;
1087
- const isChecked = isControlled ? selected === value : defaultChecked;
1088
- const contentRef = useRef7(null);
1089
- const prevOverflowRef = useRef7({
1090
- vertical: false,
1091
- horizontal: false
1092
- });
1093
- const hasIconFirst = useMemo(() => {
1094
- if (!children || Children2.count(children) === 0) return false;
1095
- const firstChild = Children2.toArray(children)[0];
1096
- if (!isValidElement2(firstChild)) return false;
1097
- const props2 = firstChild.props;
1098
- return "icon" in props2 && props2.icon !== void 0;
1099
- }, [children]);
1100
- useLayoutEffect(() => {
1101
- if (!contentRef.current || !onOverflow) return;
1102
- if (orientation === "vertical") {
1103
- return;
1104
- }
1105
- const element = contentRef.current;
1106
- const scrollOverflowVertical = element.scrollHeight > element.clientHeight;
1107
- const scrollOverflowHorizontal = element.scrollWidth > element.clientWidth;
1108
- const styles = window.getComputedStyle(element);
1109
- const lineHeight = parseFloat(styles.lineHeight);
1110
- const fontSize = parseFloat(styles.fontSize);
1111
- const singleLineHeight = isNaN(lineHeight) ? fontSize * 1.2 : lineHeight;
1112
- const WRAP_DETECTION_TOLERANCE = 1.1;
1113
- const hasWrapped = element.clientHeight > singleLineHeight * WRAP_DETECTION_TOLERANCE;
1114
- const vertical = scrollOverflowVertical || hasWrapped;
1115
- const horizontal = scrollOverflowHorizontal;
1116
- const newOverflowState = { vertical, horizontal };
1117
- const prevOverflow = prevOverflowRef.current;
1118
- if (newOverflowState.vertical !== prevOverflow.vertical || newOverflowState.horizontal !== prevOverflow.horizontal) {
1119
- prevOverflowRef.current = newOverflowState;
1120
- onOverflow(newOverflowState);
1121
- }
1122
- }, [label, children, onOverflow, orientation]);
1123
- const radioClasses = {
1124
- "--is-disabled": realDisabled,
1125
- "--is-selected": selected === value,
1126
- "--is-multiline": !!isMultiline,
1127
- "--is-required": isRequired
1128
- };
1129
- const containerClasses = classNames8(
1130
- "mobius-radio__label",
1131
- radioClasses,
1132
- className,
1133
- { "--has-icon-first": hasIconFirst }
1134
- );
1135
- const inputClasses = classNames8("mobius-radio__input", radioClasses);
1136
- const { "aria-describedby": _ariaDescribedBy, ...rest } = otherProps;
1137
- const handleChange = (event) => {
1138
- if (setSelected) {
1139
- setSelected(event.target.value);
1140
- }
1141
- if (onChange) {
1142
- const adaptedEvent = {
1143
- ...event.nativeEvent,
1144
- target: event.target
1145
- };
1146
- onChange(adaptedEvent);
1147
- }
1148
- };
1149
- return /* @__PURE__ */ jsxs5(Fragment, { children: [
1150
- /* @__PURE__ */ jsxs5(Label, { className: containerClasses, children: [
1151
- /* @__PURE__ */ jsx10(
1152
- "input",
1153
- {
1154
- "aria-describedby": otherProps["aria-describedby"],
1155
- disabled: realDisabled,
1156
- ref,
1157
- className: inputClasses,
1158
- value,
1159
- tabIndex: 0,
1160
- type: "radio",
1161
- onChange: handleChange,
1162
- ...isControlled ? { checked: isChecked } : { defaultChecked: isChecked },
1163
- name,
1164
- required: isRequired,
1165
- ...rest
1166
- }
1167
- ),
1168
- isMultiline ? /* @__PURE__ */ jsxs5("div", { ref: contentRef, className: "mobius-radio__content--multiline", children: [
1169
- /* @__PURE__ */ jsx10("div", { className: "mobius-radio__content-first-line", children: label }),
1170
- /* @__PURE__ */ jsx10("div", { className: "mobius-radio__extra-content", children })
1171
- ] }) : /* @__PURE__ */ jsx10("div", { ref: contentRef, className: "mobius-radio__content", children: label || children })
1172
- ] }),
1173
- errorMessage && /* @__PURE__ */ jsx10(ErrorMessage, { errorMessage })
1174
- ] });
1175
- };
1176
- Radio.displayName = "Radio";
1177
-
1178
- // src/components/Radio/RadioGroup.tsx
1179
- import classNames9 from "classnames/dedupe";
1180
- import {
1181
- Children as Children3,
1182
- cloneElement as cloneElement2,
1183
- isValidElement as isValidElement3,
1184
- useCallback as useCallback3,
1185
- useEffect as useEffect6,
1186
- useId as useId4,
1187
- useRef as useRef8,
1188
- useState as useState7
1189
- } from "react";
1190
- import { jsx as jsx11, jsxs as jsxs6 } from "react/jsx-runtime";
1191
- var getDefaultVal = (children, defaultValue) => {
1192
- if (Array.isArray(children) && defaultValue) {
1193
- const option = children?.find((item) => item.props.value === defaultValue);
1194
- if (!option) return "";
1195
- return option.props.value;
1196
- }
1197
- return "";
1198
- };
1199
- var RadioGroup = ({ ref, ...props }) => {
1200
- const {
1201
- label,
1202
- isDisabled = false,
1203
- isRequired,
1204
- isInvalid,
1205
- orientation = "vertical",
1206
- className,
1207
- errorMessage,
1208
- children,
1209
- defaultValue,
1210
- value,
1211
- isReadOnly,
1212
- name,
1213
- onChange,
1214
- autoStack = false,
1215
- ...rest
1216
- } = props;
1217
- const defaultSelected = getDefaultVal(children, value || defaultValue);
1218
- const [selected, setSelected] = useState7(defaultSelected);
1219
- const overflowsRef = useRef8({});
1220
- const [hasOverflow, setHasOverflow] = useState7(false);
1221
- useEffect6(() => {
1222
- if (value !== void 0) {
1223
- setSelected(value);
1224
- }
1225
- }, [value]);
1226
- const handleOverflow = useCallback3(
1227
- (radioValue, overflow) => {
1228
- overflowsRef.current = {
1229
- ...overflowsRef.current,
1230
- [radioValue]: overflow
1231
- };
1232
- const anyOverflow = Object.values(overflowsRef.current).some(
1233
- (o) => o.vertical || o.horizontal
1234
- );
1235
- if (anyOverflow !== hasOverflow) {
1236
- setHasOverflow(anyOverflow);
1237
- }
1238
- },
1239
- [hasOverflow]
1240
- );
1241
- const effectiveOrientation = autoStack && orientation === "horizontal" && hasOverflow ? "vertical" : orientation;
1242
- const validationClasses = useValidationClasses({ isInvalid });
1243
- const radioClasses = {
1244
- "--is-disabled": isDisabled,
1245
- "--is-required": typeof isRequired === "boolean" && isRequired,
1246
- "--is-optional": typeof isRequired === "boolean" && !isRequired,
1247
- [`--is-${effectiveOrientation}`]: true,
1248
- [className || ""]: true
1249
- };
1250
- const radioGroupClasses = classNames9(
1251
- "mobius",
1252
- "mobius-radio-group",
1253
- radioClasses,
1254
- validationClasses
1255
- );
1256
- const radioWrapperClasses = classNames9("mobius-radio__wrapper", {
1257
- [`--is-${effectiveOrientation}`]: true
1258
- });
1259
- const labelClasses = classNames9(radioClasses, validationClasses);
1260
- const errorMessageId = useId4();
1261
- const defaultNameAttrId = useId4();
1262
- const nameAttribute = name || defaultNameAttrId;
1263
- const shouldErrorMessageShow = errorMessage ? errorMessageId : void 0;
1264
- const describedBy = spaceDelimitedList([
1265
- shouldErrorMessageShow,
1266
- props["aria-describedby"]
1267
- ]);
1268
- const labelId = useId4();
1269
- return /* @__PURE__ */ jsx11(
1270
- "div",
1271
- {
1272
- ...rest,
1273
- "aria-describedby": describedBy,
1274
- "aria-disabled": isDisabled,
1275
- "aria-errormessage": shouldErrorMessageShow,
1276
- "aria-invalid": isInvalid,
1277
- "aria-label": props["aria-label"],
1278
- "aria-labelledby": props["aria-labelledby"] || labelId,
1279
- "aria-orientation": effectiveOrientation,
1280
- "aria-readonly": isReadOnly,
1281
- "aria-required": isRequired,
1282
- ref,
1283
- className: radioGroupClasses,
1284
- role: "radiogroup",
1285
- children: /* @__PURE__ */ jsxs6(Stack, { gap: "xs", children: [
1286
- label && /* @__PURE__ */ jsx11(Label, { htmlFor: name, id: labelId, className: labelClasses, children: label }),
1287
- /* @__PURE__ */ jsx11("div", { className: radioWrapperClasses, children: Children3.map(children, (child) => {
1288
- if (isValidElement3(child)) {
1289
- const childValue = child.props.value;
1290
- return cloneElement2(
1291
- child,
1292
- {
1293
- orientation: effectiveOrientation,
1294
- groupDisabled: isDisabled,
1295
- name: nameAttribute,
1296
- selected: selected || defaultSelected,
1297
- // in case state does not update
1298
- setSelected,
1299
- isRequired,
1300
- "aria-describedby": describedBy,
1301
- onChange,
1302
- onOverflow: childValue ? (overflow) => handleOverflow(childValue, overflow) : void 0
1303
- }
1304
- );
1305
- }
1306
- return child;
1307
- }) }),
1308
- /* @__PURE__ */ jsx11(ErrorMessage, { id: errorMessageId, errorMessage })
1309
- ] })
1310
- }
1311
- );
1312
- };
1313
- RadioGroup.displayName = "RadioGroup";
1314
-
1315
- // src/components/Select/Select.tsx
1316
- import { chevronDown } from "@simplybusiness/icons";
1317
- import classNames10 from "classnames/dedupe";
1318
- import { useId as useId5 } from "react";
1319
- import "@simplybusiness/mobius/src/components/Select/Select.css";
1320
- import { jsx as jsx12, jsxs as jsxs7 } from "react/jsx-runtime";
1321
- var Select = ({ ref, ...props }) => {
1322
- const {
1323
- label,
1324
- onChange,
1325
- isInvalid,
1326
- errorMessage,
1327
- isDisabled = false,
1328
- isRequired,
1329
- ...otherProps
1330
- } = props;
1331
- const { labelProps, fieldProps } = useLabel({
1332
- label,
1333
- ...otherProps
1334
- });
1335
- const validationClasses = useValidationClasses({ isInvalid });
1336
- const stateClasses = {
1337
- "--is-disabled": isDisabled,
1338
- "--is-required": typeof isRequired === "boolean" && isRequired,
1339
- "--is-optional": typeof isRequired === "boolean" && !isRequired
1340
- };
1341
- const sharedClasses = classNames10(validationClasses, stateClasses);
1342
- const wrapperClasses = classNames10(
1343
- "mobius-select__wrapper",
1344
- sharedClasses,
1345
- otherProps.className
1346
- );
1347
- const selectClasses = classNames10(
1348
- "mobius-select",
1349
- sharedClasses,
1350
- otherProps.className
1351
- );
1352
- const labelClasses = classNames10(
1353
- "mobius-label",
1354
- sharedClasses,
1355
- otherProps.className
1356
- );
1357
- const iconClasses = classNames10("mobius-select__icon", sharedClasses);
1358
- const errorMessageId = useId5();
1359
- const shouldErrorMessageShow = errorMessage ? errorMessageId : void 0;
1360
- const describedBy = spaceDelimitedList([
1361
- shouldErrorMessageShow,
1362
- props["aria-describedby"]
1363
- ]);
1364
- const handleChange = (e) => {
1365
- if (onChange) {
1366
- onChange(e);
1367
- }
1368
- };
1369
- return /* @__PURE__ */ jsxs7(Stack, { className: "mobius mobius-select__outer", gap: "xs", children: [
1370
- label && /* @__PURE__ */ jsx12(Label, { ...labelProps, className: labelClasses, children: label }),
1371
- /* @__PURE__ */ jsxs7("div", { className: wrapperClasses, children: [
1372
- /* @__PURE__ */ jsx12(
1373
- "select",
1374
- {
1375
- ...otherProps,
1376
- ...fieldProps,
1377
- ref,
1378
- multiple: false,
1379
- className: selectClasses,
1380
- disabled: isDisabled,
1381
- "aria-invalid": !!errorMessage,
1382
- "aria-describedby": describedBy,
1383
- "aria-required": isRequired,
1384
- required: isRequired,
1385
- onChange: handleChange
1386
- }
1387
- ),
1388
- /* @__PURE__ */ jsx12("span", { className: iconClasses, children: /* @__PURE__ */ jsx12(Icon, { icon: chevronDown }) })
1389
- ] }),
1390
- errorMessage && /* @__PURE__ */ jsx12(ErrorMessage, { id: errorMessageId, errorMessage })
1391
- ] });
1392
- };
1393
- Select.displayName = "Select";
1394
-
1395
- // src/components/TextArea/TextArea.tsx
1396
- import classNames11 from "classnames/dedupe";
1397
- import "@simplybusiness/mobius/src/components/TextArea/TextArea.css";
1398
- import { jsx as jsx13, jsxs as jsxs8 } from "react/jsx-runtime";
1399
- var TextArea = ({ ref, ...props }) => {
1400
- const {
1401
- isDisabled,
1402
- className,
1403
- errorMessage,
1404
- label,
1405
- isInvalid,
1406
- ...otherProps
1407
- } = props;
1408
- const { inputProps, labelProps, errorMessageProps } = useTextField(props);
1409
- const classes = classNames11("mobius", "mobius-text-area", className);
1410
- const validationClasses = useValidationClasses({ isInvalid });
1411
- const inputClasses = classNames11("mobius-text-area__input", validationClasses);
1412
- const labelClasses = classNames11(
1413
- {
1414
- "--is-disabled": isDisabled
1415
- },
1416
- validationClasses
1417
- );
1418
- return /* @__PURE__ */ jsxs8(Stack, { className: classes, gap: "xs", children: [
1419
- label && /* @__PURE__ */ jsx13(Label, { ...labelProps, className: labelClasses, children: props.label }),
1420
- /* @__PURE__ */ jsx13(
1421
- TextAreaInput,
1422
- {
1423
- ...otherProps,
1424
- ...inputProps,
1425
- ref,
1426
- className: inputClasses,
1427
- isDisabled,
1428
- "aria-invalid": errorMessage != null
1429
- }
1430
- ),
1431
- /* @__PURE__ */ jsx13(ErrorMessage, { ...errorMessageProps, errorMessage })
1432
- ] });
1433
- };
1434
- TextArea.displayName = "TextArea";
1435
-
1436
- // src/components/ExpandableText/ExpandableText.tsx
1437
- import classNames12 from "classnames/dedupe";
1438
- import { useEffect as useEffect7, useId as useId6, useRef as useRef9, useState as useState8 } from "react";
1439
- import "@simplybusiness/mobius/src/components/ExpandableText/ExpandableText.css";
1440
- import { jsx as jsx14, jsxs as jsxs9 } from "react/jsx-runtime";
1441
- var ExpandableText = ({ ref, ...props }) => {
1442
- const {
1443
- text,
1444
- maxLines = 3,
1445
- breakpoint,
1446
- showText = "Read more",
1447
- hideText = "Read less",
1448
- className,
1449
- textProps = {},
1450
- accordionProps = {},
1451
- onToggle,
1452
- ...otherProps
1453
- } = props;
1454
- const [isExpanded, setIsExpanded] = useState8(false);
1455
- const [isCollapsed, setIsCollapsed] = useState8(false);
1456
- const textRef = useRef9(null);
1457
- const { down } = useBreakpoint();
1458
- const baseId = useId6();
1459
- const expandButtonId = `expandable-text-expand-${baseId}`;
1460
- const shouldCollapse = breakpoint ? down(breakpoint) : true;
1461
- useEffect7(() => {
1462
- if (!shouldCollapse || !textRef.current) {
1463
- setIsCollapsed(false);
1464
- return;
1465
- }
1466
- const element = textRef.current;
1467
- const isOverflowing = element.scrollHeight > element.clientHeight;
1468
- setIsCollapsed(isOverflowing);
1469
- }, [text, shouldCollapse, maxLines]);
1470
- if (breakpoint && !shouldCollapse) {
1471
- return /* @__PURE__ */ jsx14("div", { ref, className, ...otherProps, children: /* @__PURE__ */ jsx14(TextOrHTML, { text, textWrapper: true, ...textProps }) });
1472
- }
1473
- const handleAccordionChange = (expanded) => {
1474
- setIsExpanded(expanded);
1475
- onToggle?.(expanded);
1476
- };
1477
- const classes = classNames12("mobius-expandable-text", className);
1478
- const textContainerClasses = classNames12("mobius-expandable-text__content", {
1479
- "mobius-expandable-text__content--collapsed": !isExpanded
1480
- });
1481
- const textContainerStyle = {
1482
- "--line-clamp": maxLines
1483
- };
1484
- return /* @__PURE__ */ jsxs9(
1485
- "div",
1486
- {
1487
- ref,
1488
- className: classes,
1489
- "data-testid": "expandable-text",
1490
- ...otherProps,
1491
- children: [
1492
- /* @__PURE__ */ jsx14(
1493
- "div",
1494
- {
1495
- ref: textRef,
1496
- className: textContainerClasses,
1497
- style: textContainerStyle,
1498
- "data-testid": "expandable-text-content",
1499
- "aria-describedby": isCollapsed ? expandButtonId : void 0,
1500
- children: /* @__PURE__ */ jsx14(TextOrHTML, { elementType: "span", textWrapper: true, text, ...textProps })
1501
- }
1502
- ),
1503
- isCollapsed && /* @__PURE__ */ jsx14(
1504
- Accordion,
1505
- {
1506
- showText,
1507
- hideText,
1508
- headerPosition: "bottom",
1509
- onChange: handleAccordionChange,
1510
- onClick: (e) => {
1511
- e?.stopPropagation();
1512
- },
1513
- id: expandButtonId,
1514
- ...accordionProps
1515
- }
1516
- )
1517
- ]
1518
- }
1519
- );
1520
- };
1521
- ExpandableText.displayName = "ExpandableText";
1522
-
1523
- // src/components/MaskedField/index.tsx
1524
- import loadable from "@loadable/component";
1525
- import { jsx as jsx15 } from "react/jsx-runtime";
1526
- var LoadableMaskedField = loadable(() => import("./components/MaskedField/MaskedField.js"), {
1527
- resolveComponent: (mod) => mod.MaskedField
1528
- });
1529
- function MaskedField(props) {
1530
- const {
1531
- mask: _mask,
1532
- useMaskedValue: _useMaskedValue,
1533
- "data-testid": _dataTestId,
1534
- ref: forwardedRef,
1535
- ...textFieldProps
1536
- } = props;
1537
- return /* @__PURE__ */ jsx15(
1538
- LoadableMaskedField,
1539
- {
1540
- ...props,
1541
- fallback: /* @__PURE__ */ jsx15(
1542
- TextField,
1543
- {
1544
- ...textFieldProps,
1545
- ref: forwardedRef,
1546
- type: "text",
1547
- isDisabled: true,
1548
- isReadOnly: true
1549
- }
1550
- )
1551
- }
1552
- );
1553
- }
1554
- MaskedField.displayName = "MaskedField";
1555
-
1556
- // src/components/ErrorMessage/ErrorMessage.tsx
1557
- import "@simplybusiness/mobius/src/components/ErrorMessage/ErrorMessage.css";
1558
- import { jsx as jsx16, jsxs as jsxs10 } from "react/jsx-runtime";
1559
- var ErrorMessage = ({
1560
- id,
1561
- errorMessage,
1562
- className
1563
- }) => {
1564
- const classes = classNames13("mobius", "mobius-error-message", className);
1565
- if (!errorMessage) return null;
1566
- return /* @__PURE__ */ jsxs10("div", { id, className: classes, "data-testid": "ErrorMessage", role: "alert", children: [
1567
- /* @__PURE__ */ jsx16(
1568
- Icon,
1569
- {
1570
- icon: error,
1571
- className: "mobius-error-message__icon",
1572
- "aria-hidden": "true"
1573
- }
1574
- ),
1575
- /* @__PURE__ */ jsx16(
1576
- TextOrHTML,
1577
- {
1578
- elementType: "span",
1579
- className: "mobius-error-message__text",
1580
- text: errorMessage
1581
- }
1582
- )
1583
- ] });
1584
- };
1585
- ErrorMessage.displayName = "ErrorMessage";
1586
-
1587
- export {
1588
- ErrorMessage,
1589
- TextField,
1590
- Combobox,
1591
- AddressLookup,
1592
- Checkbox,
1593
- CheckboxGroup,
1594
- MIN_MAX_ERROR,
1595
- DateField,
1596
- NumberField,
1597
- ShowHideButton,
1598
- PasswordField,
1599
- Radio,
1600
- RadioGroup,
1601
- Select,
1602
- TextArea,
1603
- ExpandableText,
1604
- MaskedField
1605
- };
1606
- //# sourceMappingURL=chunk-W2RQH4WS.js.map