@bonlineza/luxity-lib 2.39.4 → 2.39.6

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 (96) hide show
  1. package/Accordion.js +342 -352
  2. package/AddInterest.js +3109 -3068
  3. package/AddProductInterest.js +999 -7572
  4. package/BrandSelector.js +854 -861
  5. package/Checkbox.js +240 -250
  6. package/CheckboxButton.js +229 -236
  7. package/CommunicationPreferenceOptionsRenderer.js +560 -568
  8. package/CommunicationPreferenceSection.js +651 -659
  9. package/CommunicationPreferences.js +2394 -2402
  10. package/ConditionSelector.js +852 -859
  11. package/CountryCodeSelect.js +79 -6650
  12. package/CurrencyInputFormatter.js +86 -96
  13. package/CurrencySelect.js +219 -227
  14. package/DropdownSelector.js +212 -6821
  15. package/GALink.js +43 -51
  16. package/GenderSelector.js +355 -362
  17. package/GraphQLDropdownSelector.js +5308 -11832
  18. package/GraphQLMultiSelector.js +593 -601
  19. package/IconHeader.js +118 -126
  20. package/IconWrapper.js +17 -25
  21. package/InterestCatSelector.js +424 -389
  22. package/InterestItem.js +462 -469
  23. package/Interests.js +4719 -11243
  24. package/InterestsSubheading.js +33 -41
  25. package/InvertedTextButton.js +167 -175
  26. package/LuxityAppSideNav.js +181 -189
  27. package/LuxityDesktopHeader.js +1355 -1363
  28. package/LuxityFooter.js +2228 -2236
  29. package/LuxityGraphQLDropdownSelector.js +5395 -11919
  30. package/LuxityGraphQLMultiselector.js +778 -785
  31. package/LuxityMobileHeader.js +1786 -1794
  32. package/LuxityPageReady.js +199 -209
  33. package/LuxityProductInterestItem.js +359 -367
  34. package/LuxitySideNav.js +665 -673
  35. package/MaterialSelector.js +5430 -11954
  36. package/ModelSelector.js +5430 -11954
  37. package/NotificationDropDown.js +459 -7030
  38. package/Notify.js +20 -32
  39. package/OutlinePrimaryButton.js +134 -142
  40. package/PriceRangeSelector.js +1264 -1265
  41. package/PrimaryButton.js +129 -137
  42. package/RadioButtons.js +308 -318
  43. package/RangeSlider.js +1033 -1039
  44. package/RareStepFooter.js +257 -264
  45. package/RareStepHeader.js +801 -808
  46. package/ReactSelectWrapper.js +33 -6604
  47. package/SecondaryButton.js +144 -152
  48. package/ShoeSizeRangeSelector.js +1147 -1153
  49. package/ShoeSizeSelector.js +1146 -1154
  50. package/SimpleErrorBoundary.js +130 -138
  51. package/StyleSelector.js +854 -861
  52. package/TestComponent.js +15 -0
  53. package/TextButton.js +135 -143
  54. package/Tooltip.js +176 -184
  55. package/Tracking.js +15 -25
  56. package/WrapperButton.js +50 -58
  57. package/build/CountryCodeSelect/index.js +18 -0
  58. package/build/ReactSelectWrapper/index.js +34 -0
  59. package/build/bundle.css +1 -1
  60. package/build/bundle.js +10634 -17192
  61. package/build/constants.js +32 -43
  62. package/package.json +2 -2
  63. package/postcss.config.js +6 -0
  64. package/svg/Accessories.js +34 -42
  65. package/svg/Account.js +30 -38
  66. package/svg/Add.js +31 -39
  67. package/svg/ArrowRight.js +28 -36
  68. package/svg/Bags.js +40 -48
  69. package/svg/BurgerMenu.js +24 -32
  70. package/svg/Calendar.js +98 -106
  71. package/svg/CalendarCircled.js +100 -108
  72. package/svg/CheckCircled.js +32 -40
  73. package/svg/Close.js +29 -37
  74. package/svg/Clothing.js +36 -44
  75. package/svg/Dot.js +32 -40
  76. package/svg/Edit.js +27 -35
  77. package/svg/Eye.js +28 -36
  78. package/svg/FileAttach.js +28 -36
  79. package/svg/FileAttachCircled.js +30 -38
  80. package/svg/Jewellery.js +56 -0
  81. package/svg/LightBulb.js +58 -66
  82. package/svg/Logo.js +132 -140
  83. package/svg/LuxityMenu.js +28 -36
  84. package/svg/Minus.js +29 -37
  85. package/svg/MobileAvatar.js +28 -36
  86. package/svg/MyOrder.js +36 -44
  87. package/svg/MyPayment.js +36 -44
  88. package/svg/MyProfile.js +44 -52
  89. package/svg/MySale.js +31 -39
  90. package/svg/Notification.js +30 -38
  91. package/svg/PointerDown.js +28 -36
  92. package/svg/Search.js +27 -35
  93. package/svg/Shoes.js +37 -45
  94. package/svg/SvgWrapper.js +13 -21
  95. package/svg/Trash.js +32 -40
  96. package/svg/Watches.js +47 -55
@@ -1,692 +1,684 @@
1
- (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('react'), require('styled-components')) :
3
- typeof define === 'function' && define.amd ? define(['react', 'styled-components'], factory) :
4
- (global = global || self, global.CommunicationPreferenceSection = factory(global.React, global.styled));
5
- }(this, (function (React, styled) { 'use strict';
6
-
7
- var React__default = 'default' in React ? React['default'] : React;
8
- var styled__default = 'default' in styled ? styled['default'] : styled;
9
-
10
- function _extends() {
11
- _extends = Object.assign ? Object.assign.bind() : function (target) {
12
- for (var i = 1; i < arguments.length; i++) {
13
- var source = arguments[i];
14
-
15
- for (var key in source) {
16
- if (Object.prototype.hasOwnProperty.call(source, key)) {
17
- target[key] = source[key];
18
- }
19
- }
20
- }
21
-
22
- return target;
23
- };
24
- return _extends.apply(this, arguments);
25
- }
26
-
27
- function _objectWithoutPropertiesLoose(source, excluded) {
28
- if (source == null) return {};
29
- var target = {};
30
- var sourceKeys = Object.keys(source);
31
- var key, i;
32
-
33
- for (i = 0; i < sourceKeys.length; i++) {
34
- key = sourceKeys[i];
35
- if (excluded.indexOf(key) >= 0) continue;
36
- target[key] = source[key];
37
- }
38
-
39
- return target;
40
- }
1
+ import React, { forwardRef, useEffect } from 'react';
2
+ import styled, { ThemeProvider } from 'styled-components';
41
3
 
42
- function _objectWithoutProperties(source, excluded) {
43
- if (source == null) return {};
4
+ function _extends() {
5
+ _extends = Object.assign ? Object.assign.bind() : function (target) {
6
+ for (var i = 1; i < arguments.length; i++) {
7
+ var source = arguments[i];
44
8
 
45
- var target = _objectWithoutPropertiesLoose(source, excluded);
46
-
47
- var key, i;
48
-
49
- if (Object.getOwnPropertySymbols) {
50
- var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
51
-
52
- for (i = 0; i < sourceSymbolKeys.length; i++) {
53
- key = sourceSymbolKeys[i];
54
- if (excluded.indexOf(key) >= 0) continue;
55
- if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
56
- target[key] = source[key];
9
+ for (var key in source) {
10
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
11
+ target[key] = source[key];
12
+ }
57
13
  }
58
14
  }
59
15
 
60
16
  return target;
61
- }
62
-
63
- function _taggedTemplateLiteral(strings, raw) {
64
- if (!raw) {
65
- raw = strings.slice(0);
66
- }
67
-
68
- return Object.freeze(Object.defineProperties(strings, {
69
- raw: {
70
- value: Object.freeze(raw)
71
- }
72
- }));
73
- }
74
-
75
- var theme = {
76
- breakpoints: ['40em', '52em', '64em'],
77
- space: ['0px', '4px', '8px', '16px', '32px', '64px', '128px', '256px', '512px'],
78
- fontSizes: ['12px', '14px', '16px', '20px', '24px', '32px', '48px', '64px', '72px'],
79
- marginPaddings: ['0.5rem', '1rem', '1.5rem', '2rem', '2.5rem', '3rem', '3.5rem', '4rem', '4.5rem', '5rem', '5.5rem', '6rem'],
80
- letterSpacings: ['-0.5px', '0px', '+0.5px'],
81
- radii: ['0px', '2px', '4px', '8px'],
82
- borderRadius: '6px',
83
- colors: {
84
- primary: '#000',
85
- base: '#4e4949',
86
- baseLt: '#817c7c',
87
- borderColor: '#d8d8d8',
88
- ntrlMin: '#fff',
89
- ntrlMinTen: '#e6e6e6',
90
- gray: '#efefef',
91
- darkerGray: '#454141'
92
- },
93
- rareStepColors: {
94
- primary: '#202b58',
95
- secondary: '#ef5c2d',
96
- ntrlMin: '#ffffff',
97
- ntrl40: '#f4f4f4',
98
- ntrl50: '#808080',
99
- ntrl60: '#e8e8e8',
100
- ntrl70: '#252525',
101
- ntrlMax: '#000000'
102
- },
103
- rareStepFontWeights: {
104
- normal: 400,
105
- medium: 500,
106
- semiBold: 600,
107
- bold: 700
108
- },
109
- rareStepFontSize: {
110
- h1: '36px',
111
- h2: '30px',
112
- h3: '24px',
113
- h4: '20px',
114
- h5: '16px',
115
- h6: '14px',
116
- footerTitle: '16px'
117
- },
118
- rareStepPageSizes: {
119
- mobile: '500px',
120
- tablet: '768px',
121
- desktop: '992px',
122
- screenl: '1280px',
123
- screenxl: '1680px',
124
- screenxxl: '1920px',
125
- container: '1600px'
126
- }
127
- };
128
-
129
- var themed = (function (Component) {
130
- return /*#__PURE__*/React.forwardRef(function (props, ref) {
131
- return /*#__PURE__*/React__default.createElement(styled.ThemeProvider, {
132
- theme: theme
133
- }, /*#__PURE__*/React__default.createElement(Component, _extends({}, props, {
134
- ref: ref
135
- })));
136
- });
137
- });
138
-
139
- var isCheckBoxInput = (element) => element.type === 'checkbox';
140
-
141
- var isDateObject = (value) => value instanceof Date;
142
-
143
- var isNullOrUndefined = (value) => value == null;
144
-
145
- const isObjectType = (value) => typeof value === 'object';
146
- var isObject = (value) => !isNullOrUndefined(value) &&
147
- !Array.isArray(value) &&
148
- isObjectType(value) &&
149
- !isDateObject(value);
150
-
151
- var getEventValue = (event) => isObject(event) && event.target
152
- ? isCheckBoxInput(event.target)
153
- ? event.target.checked
154
- : event.target.value
155
- : event;
156
-
157
- var getNodeParentName = (name) => name.substring(0, name.search(/\.\d+(\.|$)/)) || name;
158
-
159
- var isNameInFieldArray = (names, name) => names.has(getNodeParentName(name));
160
-
161
- var isPlainObject = (tempObject) => {
162
- const prototypeCopy = tempObject.constructor && tempObject.constructor.prototype;
163
- return (isObject(prototypeCopy) && prototypeCopy.hasOwnProperty('isPrototypeOf'));
164
17
  };
165
-
166
- var isWeb = typeof window !== 'undefined' &&
167
- typeof window.HTMLElement !== 'undefined' &&
168
- typeof document !== 'undefined';
169
-
170
- function cloneObject(data) {
171
- let copy;
172
- const isArray = Array.isArray(data);
173
- if (data instanceof Date) {
174
- copy = new Date(data);
175
- }
176
- else if (data instanceof Set) {
177
- copy = new Set(data);
178
- }
179
- else if (!(isWeb && (data instanceof Blob || data instanceof FileList)) &&
180
- (isArray || isObject(data))) {
181
- copy = isArray ? [] : {};
182
- if (!isArray && !isPlainObject(data)) {
183
- copy = data;
184
- }
185
- else {
186
- for (const key in data) {
187
- if (data.hasOwnProperty(key)) {
188
- copy[key] = cloneObject(data[key]);
189
- }
190
- }
191
- }
192
- }
193
- else {
194
- return data;
195
- }
196
- return copy;
18
+ return _extends.apply(this, arguments);
19
+ }
20
+
21
+ function _objectWithoutPropertiesLoose(source, excluded) {
22
+ if (source == null) return {};
23
+ var target = {};
24
+ var sourceKeys = Object.keys(source);
25
+ var key, i;
26
+
27
+ for (i = 0; i < sourceKeys.length; i++) {
28
+ key = sourceKeys[i];
29
+ if (excluded.indexOf(key) >= 0) continue;
30
+ target[key] = source[key];
197
31
  }
198
32
 
199
- var compact = (value) => Array.isArray(value) ? value.filter(Boolean) : [];
200
-
201
- var isUndefined = (val) => val === undefined;
202
-
203
- var get = (obj, path, defaultValue) => {
204
- if (!path || !isObject(obj)) {
205
- return defaultValue;
206
- }
207
- const result = compact(path.split(/[,[\].]+?/)).reduce((result, key) => isNullOrUndefined(result) ? result : result[key], obj);
208
- return isUndefined(result) || result === obj
209
- ? isUndefined(obj[path])
210
- ? defaultValue
211
- : obj[path]
212
- : result;
213
- };
214
-
215
- const EVENTS = {
216
- BLUR: 'blur',
217
- FOCUS_OUT: 'focusout',
218
- CHANGE: 'change',
219
- };
220
- const VALIDATION_MODE = {
221
- onBlur: 'onBlur',
222
- onChange: 'onChange',
223
- onSubmit: 'onSubmit',
224
- onTouched: 'onTouched',
225
- all: 'all',
226
- };
33
+ return target;
34
+ }
227
35
 
228
- const HookFormContext = React__default.createContext(null);
229
- /**
230
- * This custom hook allows you to access the form context. useFormContext is intended to be used in deeply nested structures, where it would become inconvenient to pass the context as a prop. To be used with {@link FormProvider}.
231
- *
232
- * @remarks
233
- * [API](https://react-hook-form.com/docs/useformcontext) • [Demo](https://codesandbox.io/s/react-hook-form-v7-form-context-ytudi)
234
- *
235
- * @returns return all useForm methods
236
- *
237
- * @example
238
- * ```tsx
239
- * function App() {
240
- * const methods = useForm();
241
- * const onSubmit = data => console.log(data);
242
- *
243
- * return (
244
- * <FormProvider {...methods} >
245
- * <form onSubmit={methods.handleSubmit(onSubmit)}>
246
- * <NestedInput />
247
- * <input type="submit" />
248
- * </form>
249
- * </FormProvider>
250
- * );
251
- * }
252
- *
253
- * function NestedInput() {
254
- * const { register } = useFormContext(); // retrieve all hook methods
255
- * return <input {...register("test")} />;
256
- * }
257
- * ```
258
- */
259
- const useFormContext = () => React__default.useContext(HookFormContext);
260
-
261
- var getProxyFormState = (formState, control, localProxyFormState, isRoot = true) => {
262
- const result = {
263
- defaultValues: control._defaultValues,
264
- };
265
- for (const key in formState) {
266
- Object.defineProperty(result, key, {
267
- get: () => {
268
- const _key = key;
269
- if (control._proxyFormState[_key] !== VALIDATION_MODE.all) {
270
- control._proxyFormState[_key] = !isRoot || VALIDATION_MODE.all;
271
- }
272
- localProxyFormState && (localProxyFormState[_key] = true);
273
- return formState[_key];
274
- },
275
- });
276
- }
277
- return result;
278
- };
36
+ function _objectWithoutProperties(source, excluded) {
37
+ if (source == null) return {};
279
38
 
280
- var isEmptyObject = (value) => isObject(value) && !Object.keys(value).length;
39
+ var target = _objectWithoutPropertiesLoose(source, excluded);
281
40
 
282
- var shouldRenderFormState = (formStateData, _proxyFormState, updateFormState, isRoot) => {
283
- updateFormState(formStateData);
284
- const { name, ...formState } = formStateData;
285
- return (isEmptyObject(formState) ||
286
- Object.keys(formState).length >= Object.keys(_proxyFormState).length ||
287
- Object.keys(formState).find((key) => _proxyFormState[key] ===
288
- (!isRoot || VALIDATION_MODE.all)));
289
- };
41
+ var key, i;
290
42
 
291
- var convertToArrayPayload = (value) => (Array.isArray(value) ? value : [value]);
292
-
293
- var shouldSubscribeByName = (name, signalName, exact) => exact && signalName
294
- ? name === signalName ||
295
- (Array.isArray(name) &&
296
- name.some((currentName) => currentName && exact && currentName === signalName))
297
- : !name ||
298
- !signalName ||
299
- name === signalName ||
300
- convertToArrayPayload(name).some((currentName) => currentName &&
301
- (currentName.startsWith(signalName) ||
302
- signalName.startsWith(currentName)));
303
-
304
- function useSubscribe(props) {
305
- const _props = React__default.useRef(props);
306
- _props.current = props;
307
- React__default.useEffect(() => {
308
- const subscription = !props.disabled &&
309
- _props.current.subject &&
310
- _props.current.subject.subscribe({
311
- next: _props.current.next,
312
- });
313
- return () => {
314
- subscription && subscription.unsubscribe();
315
- };
316
- }, [props.disabled]);
317
- }
43
+ if (Object.getOwnPropertySymbols) {
44
+ var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
318
45
 
319
- /**
320
- * This custom hook allows you to subscribe to each form state, and isolate the re-render at the custom hook level. It has its scope in terms of form state subscription, so it would not affect other useFormState and useForm. Using this hook can reduce the re-render impact on large and complex form application.
321
- *
322
- * @remarks
323
- * [API](https://react-hook-form.com/docs/useformstate) • [Demo](https://codesandbox.io/s/useformstate-75xly)
324
- *
325
- * @param props - include options on specify fields to subscribe. {@link UseFormStateReturn}
326
- *
327
- * @example
328
- * ```tsx
329
- * function App() {
330
- * const { register, handleSubmit, control } = useForm({
331
- * defaultValues: {
332
- * firstName: "firstName"
333
- * }});
334
- * const { dirtyFields } = useFormState({
335
- * control
336
- * });
337
- * const onSubmit = (data) => console.log(data);
338
- *
339
- * return (
340
- * <form onSubmit={handleSubmit(onSubmit)}>
341
- * <input {...register("firstName")} placeholder="First Name" />
342
- * {dirtyFields.firstName && <p>Field is dirty.</p>}
343
- * <input type="submit" />
344
- * </form>
345
- * );
346
- * }
347
- * ```
348
- */
349
- function useFormState(props) {
350
- const methods = useFormContext();
351
- const { control = methods.control, disabled, name, exact } = props || {};
352
- const [formState, updateFormState] = React__default.useState(control._formState);
353
- const _mounted = React__default.useRef(true);
354
- const _localProxyFormState = React__default.useRef({
355
- isDirty: false,
356
- isLoading: false,
357
- dirtyFields: false,
358
- touchedFields: false,
359
- isValidating: false,
360
- isValid: false,
361
- errors: false,
362
- });
363
- const _name = React__default.useRef(name);
364
- _name.current = name;
365
- useSubscribe({
366
- disabled,
367
- next: (value) => _mounted.current &&
368
- shouldSubscribeByName(_name.current, value.name, exact) &&
369
- shouldRenderFormState(value, _localProxyFormState.current, control._updateFormState) &&
370
- updateFormState({
371
- ...control._formState,
372
- ...value,
373
- }),
374
- subject: control._subjects.state,
375
- });
376
- React__default.useEffect(() => {
377
- _mounted.current = true;
378
- _localProxyFormState.current.isValid && control._updateValid(true);
379
- return () => {
380
- _mounted.current = false;
381
- };
382
- }, [control]);
383
- return getProxyFormState(formState, control, _localProxyFormState.current, false);
46
+ for (i = 0; i < sourceSymbolKeys.length; i++) {
47
+ key = sourceSymbolKeys[i];
48
+ if (excluded.indexOf(key) >= 0) continue;
49
+ if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
50
+ target[key] = source[key];
51
+ }
384
52
  }
385
53
 
386
- var isString = (value) => typeof value === 'string';
387
-
388
- var generateWatchOutput = (names, _names, formValues, isGlobal, defaultValue) => {
389
- if (isString(names)) {
390
- isGlobal && _names.watch.add(names);
391
- return get(formValues, names, defaultValue);
392
- }
393
- if (Array.isArray(names)) {
394
- return names.map((fieldName) => (isGlobal && _names.watch.add(fieldName), get(formValues, fieldName)));
395
- }
396
- isGlobal && (_names.watchAll = true);
397
- return formValues;
398
- };
54
+ return target;
55
+ }
399
56
 
400
- /**
401
- * Custom hook to subscribe to field change and isolate re-rendering at the component level.
402
- *
403
- * @remarks
404
- *
405
- * [API](https://react-hook-form.com/docs/usewatch) • [Demo](https://codesandbox.io/s/react-hook-form-v7-ts-usewatch-h9i5e)
406
- *
407
- * @example
408
- * ```tsx
409
- * const { watch } = useForm();
410
- * const values = useWatch({
411
- * name: "fieldName"
412
- * control,
413
- * })
414
- * ```
415
- */
416
- function useWatch(props) {
417
- const methods = useFormContext();
418
- const { control = methods.control, name, defaultValue, disabled, exact, } = props || {};
419
- const _name = React__default.useRef(name);
420
- _name.current = name;
421
- useSubscribe({
422
- disabled,
423
- subject: control._subjects.values,
424
- next: (formState) => {
425
- if (shouldSubscribeByName(_name.current, formState.name, exact)) {
426
- updateValue(cloneObject(generateWatchOutput(_name.current, control._names, formState.values || control._formValues, false, defaultValue)));
427
- }
428
- },
429
- });
430
- const [value, updateValue] = React__default.useState(control._getWatch(name, defaultValue));
431
- React__default.useEffect(() => control._removeUnmounted());
432
- return value;
57
+ function _taggedTemplateLiteral(strings, raw) {
58
+ if (!raw) {
59
+ raw = strings.slice(0);
433
60
  }
434
61
 
435
- var isKey = (value) => /^\w*$/.test(value);
436
-
437
- var stringToPath = (input) => compact(input.replace(/["|']|\]/g, '').split(/\.|\[/));
438
-
439
- function set(object, path, value) {
440
- let index = -1;
441
- const tempPath = isKey(path) ? [path] : stringToPath(path);
442
- const length = tempPath.length;
443
- const lastIndex = length - 1;
444
- while (++index < length) {
445
- const key = tempPath[index];
446
- let newValue = value;
447
- if (index !== lastIndex) {
448
- const objValue = object[key];
449
- newValue =
450
- isObject(objValue) || Array.isArray(objValue)
451
- ? objValue
452
- : !isNaN(+tempPath[index + 1])
453
- ? []
454
- : {};
455
- }
456
- object[key] = newValue;
457
- object = object[key];
458
- }
459
- return object;
460
- }
461
-
462
- /**
463
- * Custom hook to work with controlled component, this function provide you with both form and field level state. Re-render is isolated at the hook level.
464
- *
465
- * @remarks
466
- * [API](https://react-hook-form.com/docs/usecontroller) • [Demo](https://codesandbox.io/s/usecontroller-0o8px)
467
- *
468
- * @param props - the path name to the form field value, and validation rules.
469
- *
470
- * @returns field properties, field and form state. {@link UseControllerReturn}
471
- *
472
- * @example
473
- * ```tsx
474
- * function Input(props) {
475
- * const { field, fieldState, formState } = useController(props);
476
- * return (
477
- * <div>
478
- * <input {...field} placeholder={props.name} />
479
- * <p>{fieldState.isTouched && "Touched"}</p>
480
- * <p>{formState.isSubmitted ? "submitted" : ""}</p>
481
- * </div>
482
- * );
483
- * }
484
- * ```
485
- */
486
- function useController(props) {
487
- const methods = useFormContext();
488
- const { name, disabled, control = methods.control, shouldUnregister } = props;
489
- const isArrayField = isNameInFieldArray(control._names.array, name);
490
- const value = useWatch({
491
- control,
492
- name,
493
- defaultValue: get(control._formValues, name, get(control._defaultValues, name, props.defaultValue)),
494
- exact: true,
495
- });
496
- const formState = useFormState({
497
- control,
498
- name,
499
- });
500
- const _registerProps = React__default.useRef(control.register(name, {
501
- ...props.rules,
502
- value,
503
- }));
504
- _registerProps.current = control.register(name, props.rules);
505
- React__default.useEffect(() => {
506
- const _shouldUnregisterField = control._options.shouldUnregister || shouldUnregister;
507
- const updateMounted = (name, value) => {
508
- const field = get(control._fields, name);
509
- if (field) {
510
- field._f.mount = value;
511
- }
512
- };
513
- updateMounted(name, true);
514
- if (_shouldUnregisterField) {
515
- const value = cloneObject(get(control._options.defaultValues, name));
516
- set(control._defaultValues, name, value);
517
- if (isUndefined(get(control._formValues, name))) {
518
- set(control._formValues, name, value);
519
- }
520
- }
521
- return () => {
522
- (isArrayField
523
- ? _shouldUnregisterField && !control._state.action
524
- : _shouldUnregisterField)
525
- ? control.unregister(name)
526
- : updateMounted(name, false);
527
- };
528
- }, [name, control, isArrayField, shouldUnregister]);
529
- React__default.useEffect(() => {
530
- control._updateDisabledField({
531
- disabled,
532
- fields: control._fields,
533
- name,
534
- });
535
- }, [disabled, name, control]);
536
- return {
537
- field: {
538
- name,
539
- value,
540
- disabled,
541
- onChange: React__default.useCallback((event) => _registerProps.current.onChange({
542
- target: {
543
- value: getEventValue(event),
544
- name: name,
545
- },
546
- type: EVENTS.CHANGE,
547
- }), [name]),
548
- onBlur: React__default.useCallback(() => _registerProps.current.onBlur({
549
- target: {
550
- value: get(control._formValues, name),
551
- name: name,
552
- },
553
- type: EVENTS.BLUR,
554
- }), [name, control]),
555
- ref: (elm) => {
556
- const field = get(control._fields, name);
557
- if (field && elm) {
558
- field._f.ref = {
559
- focus: () => elm.focus(),
560
- select: () => elm.select(),
561
- setCustomValidity: (message) => elm.setCustomValidity(message),
562
- reportValidity: () => elm.reportValidity(),
563
- };
564
- }
565
- },
566
- },
567
- formState,
568
- fieldState: Object.defineProperties({}, {
569
- invalid: {
570
- enumerable: true,
571
- get: () => !!get(formState.errors, name),
572
- },
573
- isDirty: {
574
- enumerable: true,
575
- get: () => !!get(formState.dirtyFields, name),
576
- },
577
- isTouched: {
578
- enumerable: true,
579
- get: () => !!get(formState.touchedFields, name),
580
- },
581
- error: {
582
- enumerable: true,
583
- get: () => get(formState.errors, name),
584
- },
585
- }),
586
- };
62
+ return Object.freeze(Object.defineProperties(strings, {
63
+ raw: {
64
+ value: Object.freeze(raw)
65
+ }
66
+ }));
67
+ }
68
+
69
+ var theme = {
70
+ breakpoints: ['40em', '52em', '64em'],
71
+ space: ['0px', '4px', '8px', '16px', '32px', '64px', '128px', '256px', '512px'],
72
+ fontSizes: ['12px', '14px', '16px', '20px', '24px', '32px', '48px', '64px', '72px'],
73
+ marginPaddings: ['0.5rem', '1rem', '1.5rem', '2rem', '2.5rem', '3rem', '3.5rem', '4rem', '4.5rem', '5rem', '5.5rem', '6rem'],
74
+ letterSpacings: ['-0.5px', '0px', '+0.5px'],
75
+ radii: ['0px', '2px', '4px', '8px'],
76
+ borderRadius: '6px',
77
+ colors: {
78
+ primary: '#000',
79
+ base: '#4e4949',
80
+ baseLt: '#817c7c',
81
+ borderColor: '#d8d8d8',
82
+ ntrlMin: '#fff',
83
+ ntrlMinTen: '#e6e6e6',
84
+ gray: '#efefef',
85
+ darkerGray: '#454141'
86
+ },
87
+ rareStepColors: {
88
+ primary: '#202b58',
89
+ secondary: '#ef5c2d',
90
+ ntrlMin: '#ffffff',
91
+ ntrl40: '#f4f4f4',
92
+ ntrl50: '#808080',
93
+ ntrl60: '#e8e8e8',
94
+ ntrl70: '#252525',
95
+ ntrlMax: '#000000'
96
+ },
97
+ rareStepFontWeights: {
98
+ normal: 400,
99
+ medium: 500,
100
+ semiBold: 600,
101
+ bold: 700
102
+ },
103
+ rareStepFontSize: {
104
+ h1: '36px',
105
+ h2: '30px',
106
+ h3: '24px',
107
+ h4: '20px',
108
+ h5: '16px',
109
+ h6: '14px',
110
+ footerTitle: '16px'
111
+ },
112
+ rareStepPageSizes: {
113
+ mobile: '500px',
114
+ tablet: '768px',
115
+ desktop: '992px',
116
+ screenl: '1280px',
117
+ screenxl: '1680px',
118
+ screenxxl: '1920px',
119
+ container: '1600px'
587
120
  }
588
-
589
- var _templateObject;
590
- var RadioButtonLabel = styled__default.label(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n display: flex;\n margin-bottom: ", ";\n margin-right: ", ";\n"])), function (props) {
591
- return props.theme.marginPaddings[0];
592
- }, function (props) {
593
- return props.theme.marginPaddings[0];
121
+ };
122
+
123
+ var themed = (function (Component) {
124
+ return /*#__PURE__*/forwardRef(function (props, ref) {
125
+ return /*#__PURE__*/React.createElement(ThemeProvider, {
126
+ theme: theme
127
+ }, /*#__PURE__*/React.createElement(Component, _extends({}, props, {
128
+ ref: ref
129
+ })));
594
130
  });
131
+ });
595
132
 
596
- var _templateObject$1;
597
- var RadioButtonText = styled__default.div(_templateObject$1 || (_templateObject$1 = _taggedTemplateLiteral(["\n display: flex;\n align-items: center;\n"])));
133
+ var isCheckBoxInput = (element) => element.type === 'checkbox';
598
134
 
599
- var _templateObject$2;
600
- var RadioButtonCircle = styled__default.div(_templateObject$2 || (_templateObject$2 = _taggedTemplateLiteral(["\n height: 20px;\n width: 20px;\n border-radius: 50%;\n margin-right: 5px;\n border: 1px solid ", ";\n display: flex;\n"])), function (props) {
601
- return props.theme.colors.base;
602
- });
135
+ var isDateObject = (value) => value instanceof Date;
603
136
 
604
- var _templateObject$3;
605
- var RadioButtonCircleInner = styled__default.div(_templateObject$3 || (_templateObject$3 = _taggedTemplateLiteral(["\n height: 8px;\n width: 8px;\n border-radius: 50%;\n margin: auto;\n"])));
137
+ var isNullOrUndefined = (value) => value == null;
606
138
 
607
- var _templateObject$4;
608
- var RadioButtonInput = styled__default.input(_templateObject$4 || (_templateObject$4 = _taggedTemplateLiteral(["\n display: none;\n :checked ~ ", " {\n ", " {\n background-color: ", ";\n }\n }\n"])), RadioButtonCircle, RadioButtonCircleInner, function (props) {
609
- return props.theme.colors.base;
610
- });
139
+ const isObjectType = (value) => typeof value === 'object';
140
+ var isObject = (value) => !isNullOrUndefined(value) &&
141
+ !Array.isArray(value) &&
142
+ isObjectType(value) &&
143
+ !isDateObject(value);
611
144
 
612
- var _excluded = ["ref"];
145
+ var getEventValue = (event) => isObject(event) && event.target
146
+ ? isCheckBoxInput(event.target)
147
+ ? event.target.checked
148
+ : event.target.value
149
+ : event;
613
150
 
614
- var _templateObject$5, _templateObject2;
615
- var OptionsRow = styled__default.div(_templateObject$5 || (_templateObject$5 = _taggedTemplateLiteral(["\n display: flex;\n flex-wrap: nowrap;\n flex-direction: row;\n"])));
616
- var Options = styled__default.div(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n display: flex;\n flex-wrap: nowrap;\n flex-direction: row;\n flex-basis: 60%;\n"])));
151
+ var getNodeParentName = (name) => name.substring(0, name.search(/\.\d+(\.|$)/)) || name;
617
152
 
618
- var CommunicationPreferenceOptionsRenderer = function CommunicationPreferenceOptionsRenderer(_ref) {
619
- var control = _ref.control,
620
- name = _ref.name,
621
- isDisabled = _ref.isDisabled,
622
- options = _ref.options,
623
- defaultValue = _ref.defaultValue,
624
- setValue = _ref.setValue;
153
+ var isNameInFieldArray = (names, name) => names.has(getNodeParentName(name));
625
154
 
626
- var _useController = useController({
627
- name: name,
628
- control: control,
629
- defaultValue: defaultValue
630
- }),
631
- _useController$field = _useController.field,
632
- ref = _useController$field.ref,
633
- inputProps = _objectWithoutProperties(_useController$field, _excluded),
634
- _useController$fieldS = _useController.fieldState,
635
- invalid = _useController$fieldS.invalid,
636
- error = _useController$fieldS.error;
637
-
638
- React.useEffect(function () {
639
- if (defaultValue) {
640
- setValue(name, defaultValue);
641
- }
642
- }, [defaultValue, name, setValue]);
643
- return /*#__PURE__*/React__default.createElement(OptionsRow, null, /*#__PURE__*/React__default.createElement(Options, null, options.map(function (option) {
644
- return /*#__PURE__*/React__default.createElement(RadioButtonLabel, {
645
- key: option.value,
646
- htmlFor: option.value
647
- }, /*#__PURE__*/React__default.createElement(RadioButtonInput, _extends({
648
- id: option.value,
649
- ref: ref,
650
- type: "radio",
651
- name: name,
652
- defaultChecked: inputProps.value === option.value.toString()
653
- }, inputProps, {
654
- disabled: isDisabled,
655
- value: option.value
656
- })), /*#__PURE__*/React__default.createElement(RadioButtonCircle, null, /*#__PURE__*/React__default.createElement(RadioButtonCircleInner, null)), /*#__PURE__*/React__default.createElement(RadioButtonText, null, option.label));
657
- })), invalid && /*#__PURE__*/React__default.createElement("span", {
658
- className: "form__error"
659
- }, error === null || error === void 0 ? void 0 : error.message));
660
- };
155
+ var isPlainObject = (tempObject) => {
156
+ const prototypeCopy = tempObject.constructor && tempObject.constructor.prototype;
157
+ return (isObject(prototypeCopy) && prototypeCopy.hasOwnProperty('isPrototypeOf'));
158
+ };
661
159
 
662
- var _templateObject$6, _templateObject2$1;
663
- var SectionContainer = styled__default.div(_templateObject$6 || (_templateObject$6 = _taggedTemplateLiteral(["\n border-top: flex 1px solid ", ";\n border-top-width: calc(100% - 50px);\n padding: 5px 10px;\n"])), function (props) {
664
- return props.theme.colors.primary;
665
- });
666
- var SectionHeading = styled__default.div(_templateObject2$1 || (_templateObject2$1 = _taggedTemplateLiteral(["\n padding: 5px 10px;\n"])));
667
-
668
- var CommunicationPreferenceSection = function CommunicationPreferenceSection(_ref) {
669
- var section_heading = _ref.section_heading,
670
- description = _ref.description,
671
- control = _ref.control,
672
- name = _ref.name,
673
- isDisabled = _ref.isDisabled,
674
- options = _ref.options,
675
- defaultValue = _ref.defaultValue,
676
- setValue = _ref.setValue;
677
- return /*#__PURE__*/React__default.createElement(SectionContainer, null, /*#__PURE__*/React__default.createElement(SectionHeading, null, section_heading), /*#__PURE__*/React__default.createElement(CommunicationPreferenceOptionsRenderer, {
678
- description: description,
679
- control: control,
680
- name: name,
681
- isDisabled: isDisabled,
682
- options: options,
683
- defaultValue: defaultValue,
684
- setValue: setValue
685
- }));
686
- };
160
+ var isWeb = typeof window !== 'undefined' &&
161
+ typeof window.HTMLElement !== 'undefined' &&
162
+ typeof document !== 'undefined';
687
163
 
688
- var index = themed(CommunicationPreferenceSection);
164
+ function cloneObject(data) {
165
+ let copy;
166
+ const isArray = Array.isArray(data);
167
+ if (data instanceof Date) {
168
+ copy = new Date(data);
169
+ }
170
+ else if (data instanceof Set) {
171
+ copy = new Set(data);
172
+ }
173
+ else if (!(isWeb && (data instanceof Blob || data instanceof FileList)) &&
174
+ (isArray || isObject(data))) {
175
+ copy = isArray ? [] : {};
176
+ if (!isArray && !isPlainObject(data)) {
177
+ copy = data;
178
+ }
179
+ else {
180
+ for (const key in data) {
181
+ if (data.hasOwnProperty(key)) {
182
+ copy[key] = cloneObject(data[key]);
183
+ }
184
+ }
185
+ }
186
+ }
187
+ else {
188
+ return data;
189
+ }
190
+ return copy;
191
+ }
689
192
 
690
- return index;
193
+ var compact = (value) => Array.isArray(value) ? value.filter(Boolean) : [];
691
194
 
692
- })));
195
+ var isUndefined = (val) => val === undefined;
196
+
197
+ var get = (obj, path, defaultValue) => {
198
+ if (!path || !isObject(obj)) {
199
+ return defaultValue;
200
+ }
201
+ const result = compact(path.split(/[,[\].]+?/)).reduce((result, key) => isNullOrUndefined(result) ? result : result[key], obj);
202
+ return isUndefined(result) || result === obj
203
+ ? isUndefined(obj[path])
204
+ ? defaultValue
205
+ : obj[path]
206
+ : result;
207
+ };
208
+
209
+ const EVENTS = {
210
+ BLUR: 'blur',
211
+ FOCUS_OUT: 'focusout',
212
+ CHANGE: 'change',
213
+ };
214
+ const VALIDATION_MODE = {
215
+ onBlur: 'onBlur',
216
+ onChange: 'onChange',
217
+ onSubmit: 'onSubmit',
218
+ onTouched: 'onTouched',
219
+ all: 'all',
220
+ };
221
+
222
+ const HookFormContext = React.createContext(null);
223
+ /**
224
+ * This custom hook allows you to access the form context. useFormContext is intended to be used in deeply nested structures, where it would become inconvenient to pass the context as a prop. To be used with {@link FormProvider}.
225
+ *
226
+ * @remarks
227
+ * [API](https://react-hook-form.com/docs/useformcontext) • [Demo](https://codesandbox.io/s/react-hook-form-v7-form-context-ytudi)
228
+ *
229
+ * @returns return all useForm methods
230
+ *
231
+ * @example
232
+ * ```tsx
233
+ * function App() {
234
+ * const methods = useForm();
235
+ * const onSubmit = data => console.log(data);
236
+ *
237
+ * return (
238
+ * <FormProvider {...methods} >
239
+ * <form onSubmit={methods.handleSubmit(onSubmit)}>
240
+ * <NestedInput />
241
+ * <input type="submit" />
242
+ * </form>
243
+ * </FormProvider>
244
+ * );
245
+ * }
246
+ *
247
+ * function NestedInput() {
248
+ * const { register } = useFormContext(); // retrieve all hook methods
249
+ * return <input {...register("test")} />;
250
+ * }
251
+ * ```
252
+ */
253
+ const useFormContext = () => React.useContext(HookFormContext);
254
+
255
+ var getProxyFormState = (formState, control, localProxyFormState, isRoot = true) => {
256
+ const result = {
257
+ defaultValues: control._defaultValues,
258
+ };
259
+ for (const key in formState) {
260
+ Object.defineProperty(result, key, {
261
+ get: () => {
262
+ const _key = key;
263
+ if (control._proxyFormState[_key] !== VALIDATION_MODE.all) {
264
+ control._proxyFormState[_key] = !isRoot || VALIDATION_MODE.all;
265
+ }
266
+ localProxyFormState && (localProxyFormState[_key] = true);
267
+ return formState[_key];
268
+ },
269
+ });
270
+ }
271
+ return result;
272
+ };
273
+
274
+ var isEmptyObject = (value) => isObject(value) && !Object.keys(value).length;
275
+
276
+ var shouldRenderFormState = (formStateData, _proxyFormState, updateFormState, isRoot) => {
277
+ updateFormState(formStateData);
278
+ const { name, ...formState } = formStateData;
279
+ return (isEmptyObject(formState) ||
280
+ Object.keys(formState).length >= Object.keys(_proxyFormState).length ||
281
+ Object.keys(formState).find((key) => _proxyFormState[key] ===
282
+ (!isRoot || VALIDATION_MODE.all)));
283
+ };
284
+
285
+ var convertToArrayPayload = (value) => (Array.isArray(value) ? value : [value]);
286
+
287
+ var shouldSubscribeByName = (name, signalName, exact) => exact && signalName
288
+ ? name === signalName ||
289
+ (Array.isArray(name) &&
290
+ name.some((currentName) => currentName && exact && currentName === signalName))
291
+ : !name ||
292
+ !signalName ||
293
+ name === signalName ||
294
+ convertToArrayPayload(name).some((currentName) => currentName &&
295
+ (currentName.startsWith(signalName) ||
296
+ signalName.startsWith(currentName)));
297
+
298
+ function useSubscribe(props) {
299
+ const _props = React.useRef(props);
300
+ _props.current = props;
301
+ React.useEffect(() => {
302
+ const subscription = !props.disabled &&
303
+ _props.current.subject &&
304
+ _props.current.subject.subscribe({
305
+ next: _props.current.next,
306
+ });
307
+ return () => {
308
+ subscription && subscription.unsubscribe();
309
+ };
310
+ }, [props.disabled]);
311
+ }
312
+
313
+ /**
314
+ * This custom hook allows you to subscribe to each form state, and isolate the re-render at the custom hook level. It has its scope in terms of form state subscription, so it would not affect other useFormState and useForm. Using this hook can reduce the re-render impact on large and complex form application.
315
+ *
316
+ * @remarks
317
+ * [API](https://react-hook-form.com/docs/useformstate) • [Demo](https://codesandbox.io/s/useformstate-75xly)
318
+ *
319
+ * @param props - include options on specify fields to subscribe. {@link UseFormStateReturn}
320
+ *
321
+ * @example
322
+ * ```tsx
323
+ * function App() {
324
+ * const { register, handleSubmit, control } = useForm({
325
+ * defaultValues: {
326
+ * firstName: "firstName"
327
+ * }});
328
+ * const { dirtyFields } = useFormState({
329
+ * control
330
+ * });
331
+ * const onSubmit = (data) => console.log(data);
332
+ *
333
+ * return (
334
+ * <form onSubmit={handleSubmit(onSubmit)}>
335
+ * <input {...register("firstName")} placeholder="First Name" />
336
+ * {dirtyFields.firstName && <p>Field is dirty.</p>}
337
+ * <input type="submit" />
338
+ * </form>
339
+ * );
340
+ * }
341
+ * ```
342
+ */
343
+ function useFormState(props) {
344
+ const methods = useFormContext();
345
+ const { control = methods.control, disabled, name, exact } = props || {};
346
+ const [formState, updateFormState] = React.useState(control._formState);
347
+ const _mounted = React.useRef(true);
348
+ const _localProxyFormState = React.useRef({
349
+ isDirty: false,
350
+ isLoading: false,
351
+ dirtyFields: false,
352
+ touchedFields: false,
353
+ isValidating: false,
354
+ isValid: false,
355
+ errors: false,
356
+ });
357
+ const _name = React.useRef(name);
358
+ _name.current = name;
359
+ useSubscribe({
360
+ disabled,
361
+ next: (value) => _mounted.current &&
362
+ shouldSubscribeByName(_name.current, value.name, exact) &&
363
+ shouldRenderFormState(value, _localProxyFormState.current, control._updateFormState) &&
364
+ updateFormState({
365
+ ...control._formState,
366
+ ...value,
367
+ }),
368
+ subject: control._subjects.state,
369
+ });
370
+ React.useEffect(() => {
371
+ _mounted.current = true;
372
+ _localProxyFormState.current.isValid && control._updateValid(true);
373
+ return () => {
374
+ _mounted.current = false;
375
+ };
376
+ }, [control]);
377
+ return getProxyFormState(formState, control, _localProxyFormState.current, false);
378
+ }
379
+
380
+ var isString = (value) => typeof value === 'string';
381
+
382
+ var generateWatchOutput = (names, _names, formValues, isGlobal, defaultValue) => {
383
+ if (isString(names)) {
384
+ isGlobal && _names.watch.add(names);
385
+ return get(formValues, names, defaultValue);
386
+ }
387
+ if (Array.isArray(names)) {
388
+ return names.map((fieldName) => (isGlobal && _names.watch.add(fieldName), get(formValues, fieldName)));
389
+ }
390
+ isGlobal && (_names.watchAll = true);
391
+ return formValues;
392
+ };
393
+
394
+ /**
395
+ * Custom hook to subscribe to field change and isolate re-rendering at the component level.
396
+ *
397
+ * @remarks
398
+ *
399
+ * [API](https://react-hook-form.com/docs/usewatch) • [Demo](https://codesandbox.io/s/react-hook-form-v7-ts-usewatch-h9i5e)
400
+ *
401
+ * @example
402
+ * ```tsx
403
+ * const { watch } = useForm();
404
+ * const values = useWatch({
405
+ * name: "fieldName"
406
+ * control,
407
+ * })
408
+ * ```
409
+ */
410
+ function useWatch(props) {
411
+ const methods = useFormContext();
412
+ const { control = methods.control, name, defaultValue, disabled, exact, } = props || {};
413
+ const _name = React.useRef(name);
414
+ _name.current = name;
415
+ useSubscribe({
416
+ disabled,
417
+ subject: control._subjects.values,
418
+ next: (formState) => {
419
+ if (shouldSubscribeByName(_name.current, formState.name, exact)) {
420
+ updateValue(cloneObject(generateWatchOutput(_name.current, control._names, formState.values || control._formValues, false, defaultValue)));
421
+ }
422
+ },
423
+ });
424
+ const [value, updateValue] = React.useState(control._getWatch(name, defaultValue));
425
+ React.useEffect(() => control._removeUnmounted());
426
+ return value;
427
+ }
428
+
429
+ var isKey = (value) => /^\w*$/.test(value);
430
+
431
+ var stringToPath = (input) => compact(input.replace(/["|']|\]/g, '').split(/\.|\[/));
432
+
433
+ function set(object, path, value) {
434
+ let index = -1;
435
+ const tempPath = isKey(path) ? [path] : stringToPath(path);
436
+ const length = tempPath.length;
437
+ const lastIndex = length - 1;
438
+ while (++index < length) {
439
+ const key = tempPath[index];
440
+ let newValue = value;
441
+ if (index !== lastIndex) {
442
+ const objValue = object[key];
443
+ newValue =
444
+ isObject(objValue) || Array.isArray(objValue)
445
+ ? objValue
446
+ : !isNaN(+tempPath[index + 1])
447
+ ? []
448
+ : {};
449
+ }
450
+ object[key] = newValue;
451
+ object = object[key];
452
+ }
453
+ return object;
454
+ }
455
+
456
+ /**
457
+ * Custom hook to work with controlled component, this function provide you with both form and field level state. Re-render is isolated at the hook level.
458
+ *
459
+ * @remarks
460
+ * [API](https://react-hook-form.com/docs/usecontroller) • [Demo](https://codesandbox.io/s/usecontroller-0o8px)
461
+ *
462
+ * @param props - the path name to the form field value, and validation rules.
463
+ *
464
+ * @returns field properties, field and form state. {@link UseControllerReturn}
465
+ *
466
+ * @example
467
+ * ```tsx
468
+ * function Input(props) {
469
+ * const { field, fieldState, formState } = useController(props);
470
+ * return (
471
+ * <div>
472
+ * <input {...field} placeholder={props.name} />
473
+ * <p>{fieldState.isTouched && "Touched"}</p>
474
+ * <p>{formState.isSubmitted ? "submitted" : ""}</p>
475
+ * </div>
476
+ * );
477
+ * }
478
+ * ```
479
+ */
480
+ function useController(props) {
481
+ const methods = useFormContext();
482
+ const { name, disabled, control = methods.control, shouldUnregister } = props;
483
+ const isArrayField = isNameInFieldArray(control._names.array, name);
484
+ const value = useWatch({
485
+ control,
486
+ name,
487
+ defaultValue: get(control._formValues, name, get(control._defaultValues, name, props.defaultValue)),
488
+ exact: true,
489
+ });
490
+ const formState = useFormState({
491
+ control,
492
+ name,
493
+ });
494
+ const _registerProps = React.useRef(control.register(name, {
495
+ ...props.rules,
496
+ value,
497
+ }));
498
+ _registerProps.current = control.register(name, props.rules);
499
+ React.useEffect(() => {
500
+ const _shouldUnregisterField = control._options.shouldUnregister || shouldUnregister;
501
+ const updateMounted = (name, value) => {
502
+ const field = get(control._fields, name);
503
+ if (field) {
504
+ field._f.mount = value;
505
+ }
506
+ };
507
+ updateMounted(name, true);
508
+ if (_shouldUnregisterField) {
509
+ const value = cloneObject(get(control._options.defaultValues, name));
510
+ set(control._defaultValues, name, value);
511
+ if (isUndefined(get(control._formValues, name))) {
512
+ set(control._formValues, name, value);
513
+ }
514
+ }
515
+ return () => {
516
+ (isArrayField
517
+ ? _shouldUnregisterField && !control._state.action
518
+ : _shouldUnregisterField)
519
+ ? control.unregister(name)
520
+ : updateMounted(name, false);
521
+ };
522
+ }, [name, control, isArrayField, shouldUnregister]);
523
+ React.useEffect(() => {
524
+ control._updateDisabledField({
525
+ disabled,
526
+ fields: control._fields,
527
+ name,
528
+ });
529
+ }, [disabled, name, control]);
530
+ return {
531
+ field: {
532
+ name,
533
+ value,
534
+ disabled,
535
+ onChange: React.useCallback((event) => _registerProps.current.onChange({
536
+ target: {
537
+ value: getEventValue(event),
538
+ name: name,
539
+ },
540
+ type: EVENTS.CHANGE,
541
+ }), [name]),
542
+ onBlur: React.useCallback(() => _registerProps.current.onBlur({
543
+ target: {
544
+ value: get(control._formValues, name),
545
+ name: name,
546
+ },
547
+ type: EVENTS.BLUR,
548
+ }), [name, control]),
549
+ ref: (elm) => {
550
+ const field = get(control._fields, name);
551
+ if (field && elm) {
552
+ field._f.ref = {
553
+ focus: () => elm.focus(),
554
+ select: () => elm.select(),
555
+ setCustomValidity: (message) => elm.setCustomValidity(message),
556
+ reportValidity: () => elm.reportValidity(),
557
+ };
558
+ }
559
+ },
560
+ },
561
+ formState,
562
+ fieldState: Object.defineProperties({}, {
563
+ invalid: {
564
+ enumerable: true,
565
+ get: () => !!get(formState.errors, name),
566
+ },
567
+ isDirty: {
568
+ enumerable: true,
569
+ get: () => !!get(formState.dirtyFields, name),
570
+ },
571
+ isTouched: {
572
+ enumerable: true,
573
+ get: () => !!get(formState.touchedFields, name),
574
+ },
575
+ error: {
576
+ enumerable: true,
577
+ get: () => get(formState.errors, name),
578
+ },
579
+ }),
580
+ };
581
+ }
582
+
583
+ var _templateObject;
584
+ var RadioButtonLabel = styled.label(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n display: flex;\n margin-bottom: ", ";\n margin-right: ", ";\n"])), function (props) {
585
+ return props.theme.marginPaddings[0];
586
+ }, function (props) {
587
+ return props.theme.marginPaddings[0];
588
+ });
589
+
590
+ var _templateObject$1;
591
+ var RadioButtonText = styled.div(_templateObject$1 || (_templateObject$1 = _taggedTemplateLiteral(["\n display: flex;\n align-items: center;\n"])));
592
+
593
+ var _templateObject$2;
594
+ var RadioButtonCircle = styled.div(_templateObject$2 || (_templateObject$2 = _taggedTemplateLiteral(["\n height: 20px;\n width: 20px;\n border-radius: 50%;\n margin-right: 5px;\n border: 1px solid ", ";\n display: flex;\n"])), function (props) {
595
+ return props.theme.colors.base;
596
+ });
597
+
598
+ var _templateObject$3;
599
+ var RadioButtonCircleInner = styled.div(_templateObject$3 || (_templateObject$3 = _taggedTemplateLiteral(["\n height: 8px;\n width: 8px;\n border-radius: 50%;\n margin: auto;\n"])));
600
+
601
+ var _templateObject$4;
602
+ var RadioButtonInput = styled.input(_templateObject$4 || (_templateObject$4 = _taggedTemplateLiteral(["\n display: none;\n :checked ~ ", " {\n ", " {\n background-color: ", ";\n }\n }\n"])), RadioButtonCircle, RadioButtonCircleInner, function (props) {
603
+ return props.theme.colors.base;
604
+ });
605
+
606
+ var _excluded = ["ref"];
607
+
608
+ var _templateObject$5, _templateObject2;
609
+ var OptionsRow = styled.div(_templateObject$5 || (_templateObject$5 = _taggedTemplateLiteral(["\n display: flex;\n flex-wrap: nowrap;\n flex-direction: row;\n"])));
610
+ var Options = styled.div(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n display: flex;\n flex-wrap: nowrap;\n flex-direction: row;\n flex-basis: 60%;\n"])));
611
+
612
+ var CommunicationPreferenceOptionsRenderer = function CommunicationPreferenceOptionsRenderer(_ref) {
613
+ var control = _ref.control,
614
+ name = _ref.name,
615
+ isDisabled = _ref.isDisabled,
616
+ options = _ref.options,
617
+ defaultValue = _ref.defaultValue,
618
+ setValue = _ref.setValue;
619
+
620
+ var _useController = useController({
621
+ name: name,
622
+ control: control,
623
+ defaultValue: defaultValue
624
+ }),
625
+ _useController$field = _useController.field,
626
+ ref = _useController$field.ref,
627
+ inputProps = _objectWithoutProperties(_useController$field, _excluded),
628
+ _useController$fieldS = _useController.fieldState,
629
+ invalid = _useController$fieldS.invalid,
630
+ error = _useController$fieldS.error;
631
+
632
+ useEffect(function () {
633
+ if (defaultValue) {
634
+ setValue(name, defaultValue);
635
+ }
636
+ }, [defaultValue, name, setValue]);
637
+ return /*#__PURE__*/React.createElement(OptionsRow, null, /*#__PURE__*/React.createElement(Options, null, options.map(function (option) {
638
+ return /*#__PURE__*/React.createElement(RadioButtonLabel, {
639
+ key: option.value,
640
+ htmlFor: option.value
641
+ }, /*#__PURE__*/React.createElement(RadioButtonInput, _extends({
642
+ id: option.value,
643
+ ref: ref,
644
+ type: "radio",
645
+ name: name,
646
+ defaultChecked: inputProps.value === option.value.toString()
647
+ }, inputProps, {
648
+ disabled: isDisabled,
649
+ value: option.value
650
+ })), /*#__PURE__*/React.createElement(RadioButtonCircle, null, /*#__PURE__*/React.createElement(RadioButtonCircleInner, null)), /*#__PURE__*/React.createElement(RadioButtonText, null, option.label));
651
+ })), invalid && /*#__PURE__*/React.createElement("span", {
652
+ className: "form__error"
653
+ }, error === null || error === void 0 ? void 0 : error.message));
654
+ };
655
+
656
+ var _templateObject$6, _templateObject2$1;
657
+ var SectionContainer = styled.div(_templateObject$6 || (_templateObject$6 = _taggedTemplateLiteral(["\n border-top: flex 1px solid ", ";\n border-top-width: calc(100% - 50px);\n padding: 5px 10px;\n"])), function (props) {
658
+ return props.theme.colors.primary;
659
+ });
660
+ var SectionHeading = styled.div(_templateObject2$1 || (_templateObject2$1 = _taggedTemplateLiteral(["\n padding: 5px 10px;\n"])));
661
+
662
+ var CommunicationPreferenceSection = function CommunicationPreferenceSection(_ref) {
663
+ var section_heading = _ref.section_heading,
664
+ description = _ref.description,
665
+ control = _ref.control,
666
+ name = _ref.name,
667
+ isDisabled = _ref.isDisabled,
668
+ options = _ref.options,
669
+ defaultValue = _ref.defaultValue,
670
+ setValue = _ref.setValue;
671
+ return /*#__PURE__*/React.createElement(SectionContainer, null, /*#__PURE__*/React.createElement(SectionHeading, null, section_heading), /*#__PURE__*/React.createElement(CommunicationPreferenceOptionsRenderer, {
672
+ description: description,
673
+ control: control,
674
+ name: name,
675
+ isDisabled: isDisabled,
676
+ options: options,
677
+ defaultValue: defaultValue,
678
+ setValue: setValue
679
+ }));
680
+ };
681
+
682
+ var index = themed(CommunicationPreferenceSection);
683
+
684
+ export default index;