@bonlineza/luxity-lib 2.41.0 → 2.41.1

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.
@@ -1,600 +0,0 @@
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.CommunicationPreferenceOptionsRenderer = factory(global.React, global.styled));
5
- }(this, (function (React, styled) { 'use strict';
6
-
7
- var React__default = 'default' in React ? React['default'] : React;
8
- styled = styled && Object.prototype.hasOwnProperty.call(styled, 'default') ? 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
- }
41
-
42
- function _objectWithoutProperties(source, excluded) {
43
- if (source == null) return {};
44
-
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];
57
- }
58
- }
59
-
60
- 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 isCheckBoxInput = (element) => element.type === 'checkbox';
76
-
77
- var isDateObject = (value) => value instanceof Date;
78
-
79
- var isNullOrUndefined = (value) => value == null;
80
-
81
- const isObjectType = (value) => typeof value === 'object';
82
- var isObject = (value) => !isNullOrUndefined(value) &&
83
- !Array.isArray(value) &&
84
- isObjectType(value) &&
85
- !isDateObject(value);
86
-
87
- var getEventValue = (event) => isObject(event) && event.target
88
- ? isCheckBoxInput(event.target)
89
- ? event.target.checked
90
- : event.target.value
91
- : event;
92
-
93
- var getNodeParentName = (name) => name.substring(0, name.search(/\.\d+(\.|$)/)) || name;
94
-
95
- var isNameInFieldArray = (names, name) => names.has(getNodeParentName(name));
96
-
97
- var isPlainObject = (tempObject) => {
98
- const prototypeCopy = tempObject.constructor && tempObject.constructor.prototype;
99
- return (isObject(prototypeCopy) && prototypeCopy.hasOwnProperty('isPrototypeOf'));
100
- };
101
-
102
- var isWeb = typeof window !== 'undefined' &&
103
- typeof window.HTMLElement !== 'undefined' &&
104
- typeof document !== 'undefined';
105
-
106
- function cloneObject(data) {
107
- let copy;
108
- const isArray = Array.isArray(data);
109
- if (data instanceof Date) {
110
- copy = new Date(data);
111
- }
112
- else if (data instanceof Set) {
113
- copy = new Set(data);
114
- }
115
- else if (!(isWeb && (data instanceof Blob || data instanceof FileList)) &&
116
- (isArray || isObject(data))) {
117
- copy = isArray ? [] : {};
118
- if (!isArray && !isPlainObject(data)) {
119
- copy = data;
120
- }
121
- else {
122
- for (const key in data) {
123
- if (data.hasOwnProperty(key)) {
124
- copy[key] = cloneObject(data[key]);
125
- }
126
- }
127
- }
128
- }
129
- else {
130
- return data;
131
- }
132
- return copy;
133
- }
134
-
135
- var compact = (value) => Array.isArray(value) ? value.filter(Boolean) : [];
136
-
137
- var isUndefined = (val) => val === undefined;
138
-
139
- var get = (obj, path, defaultValue) => {
140
- if (!path || !isObject(obj)) {
141
- return defaultValue;
142
- }
143
- const result = compact(path.split(/[,[\].]+?/)).reduce((result, key) => isNullOrUndefined(result) ? result : result[key], obj);
144
- return isUndefined(result) || result === obj
145
- ? isUndefined(obj[path])
146
- ? defaultValue
147
- : obj[path]
148
- : result;
149
- };
150
-
151
- const EVENTS = {
152
- BLUR: 'blur',
153
- FOCUS_OUT: 'focusout',
154
- CHANGE: 'change',
155
- };
156
- const VALIDATION_MODE = {
157
- onBlur: 'onBlur',
158
- onChange: 'onChange',
159
- onSubmit: 'onSubmit',
160
- onTouched: 'onTouched',
161
- all: 'all',
162
- };
163
-
164
- const HookFormContext = React__default.createContext(null);
165
- /**
166
- * 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}.
167
- *
168
- * @remarks
169
- * [API](https://react-hook-form.com/docs/useformcontext) • [Demo](https://codesandbox.io/s/react-hook-form-v7-form-context-ytudi)
170
- *
171
- * @returns return all useForm methods
172
- *
173
- * @example
174
- * ```tsx
175
- * function App() {
176
- * const methods = useForm();
177
- * const onSubmit = data => console.log(data);
178
- *
179
- * return (
180
- * <FormProvider {...methods} >
181
- * <form onSubmit={methods.handleSubmit(onSubmit)}>
182
- * <NestedInput />
183
- * <input type="submit" />
184
- * </form>
185
- * </FormProvider>
186
- * );
187
- * }
188
- *
189
- * function NestedInput() {
190
- * const { register } = useFormContext(); // retrieve all hook methods
191
- * return <input {...register("test")} />;
192
- * }
193
- * ```
194
- */
195
- const useFormContext = () => React__default.useContext(HookFormContext);
196
-
197
- var getProxyFormState = (formState, control, localProxyFormState, isRoot = true) => {
198
- const result = {
199
- defaultValues: control._defaultValues,
200
- };
201
- for (const key in formState) {
202
- Object.defineProperty(result, key, {
203
- get: () => {
204
- const _key = key;
205
- if (control._proxyFormState[_key] !== VALIDATION_MODE.all) {
206
- control._proxyFormState[_key] = !isRoot || VALIDATION_MODE.all;
207
- }
208
- localProxyFormState && (localProxyFormState[_key] = true);
209
- return formState[_key];
210
- },
211
- });
212
- }
213
- return result;
214
- };
215
-
216
- var isEmptyObject = (value) => isObject(value) && !Object.keys(value).length;
217
-
218
- var shouldRenderFormState = (formStateData, _proxyFormState, updateFormState, isRoot) => {
219
- updateFormState(formStateData);
220
- const { name, ...formState } = formStateData;
221
- return (isEmptyObject(formState) ||
222
- Object.keys(formState).length >= Object.keys(_proxyFormState).length ||
223
- Object.keys(formState).find((key) => _proxyFormState[key] ===
224
- (!isRoot || VALIDATION_MODE.all)));
225
- };
226
-
227
- var convertToArrayPayload = (value) => (Array.isArray(value) ? value : [value]);
228
-
229
- var shouldSubscribeByName = (name, signalName, exact) => exact && signalName
230
- ? name === signalName ||
231
- (Array.isArray(name) &&
232
- name.some((currentName) => currentName && exact && currentName === signalName))
233
- : !name ||
234
- !signalName ||
235
- name === signalName ||
236
- convertToArrayPayload(name).some((currentName) => currentName &&
237
- (currentName.startsWith(signalName) ||
238
- signalName.startsWith(currentName)));
239
-
240
- function useSubscribe(props) {
241
- const _props = React__default.useRef(props);
242
- _props.current = props;
243
- React__default.useEffect(() => {
244
- const subscription = !props.disabled &&
245
- _props.current.subject &&
246
- _props.current.subject.subscribe({
247
- next: _props.current.next,
248
- });
249
- return () => {
250
- subscription && subscription.unsubscribe();
251
- };
252
- }, [props.disabled]);
253
- }
254
-
255
- /**
256
- * 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.
257
- *
258
- * @remarks
259
- * [API](https://react-hook-form.com/docs/useformstate) • [Demo](https://codesandbox.io/s/useformstate-75xly)
260
- *
261
- * @param props - include options on specify fields to subscribe. {@link UseFormStateReturn}
262
- *
263
- * @example
264
- * ```tsx
265
- * function App() {
266
- * const { register, handleSubmit, control } = useForm({
267
- * defaultValues: {
268
- * firstName: "firstName"
269
- * }});
270
- * const { dirtyFields } = useFormState({
271
- * control
272
- * });
273
- * const onSubmit = (data) => console.log(data);
274
- *
275
- * return (
276
- * <form onSubmit={handleSubmit(onSubmit)}>
277
- * <input {...register("firstName")} placeholder="First Name" />
278
- * {dirtyFields.firstName && <p>Field is dirty.</p>}
279
- * <input type="submit" />
280
- * </form>
281
- * );
282
- * }
283
- * ```
284
- */
285
- function useFormState(props) {
286
- const methods = useFormContext();
287
- const { control = methods.control, disabled, name, exact } = props || {};
288
- const [formState, updateFormState] = React__default.useState(control._formState);
289
- const _mounted = React__default.useRef(true);
290
- const _localProxyFormState = React__default.useRef({
291
- isDirty: false,
292
- isLoading: false,
293
- dirtyFields: false,
294
- touchedFields: false,
295
- isValidating: false,
296
- isValid: false,
297
- errors: false,
298
- });
299
- const _name = React__default.useRef(name);
300
- _name.current = name;
301
- useSubscribe({
302
- disabled,
303
- next: (value) => _mounted.current &&
304
- shouldSubscribeByName(_name.current, value.name, exact) &&
305
- shouldRenderFormState(value, _localProxyFormState.current, control._updateFormState) &&
306
- updateFormState({
307
- ...control._formState,
308
- ...value,
309
- }),
310
- subject: control._subjects.state,
311
- });
312
- React__default.useEffect(() => {
313
- _mounted.current = true;
314
- _localProxyFormState.current.isValid && control._updateValid(true);
315
- return () => {
316
- _mounted.current = false;
317
- };
318
- }, [control]);
319
- return getProxyFormState(formState, control, _localProxyFormState.current, false);
320
- }
321
-
322
- var isString = (value) => typeof value === 'string';
323
-
324
- var generateWatchOutput = (names, _names, formValues, isGlobal, defaultValue) => {
325
- if (isString(names)) {
326
- isGlobal && _names.watch.add(names);
327
- return get(formValues, names, defaultValue);
328
- }
329
- if (Array.isArray(names)) {
330
- return names.map((fieldName) => (isGlobal && _names.watch.add(fieldName), get(formValues, fieldName)));
331
- }
332
- isGlobal && (_names.watchAll = true);
333
- return formValues;
334
- };
335
-
336
- /**
337
- * Custom hook to subscribe to field change and isolate re-rendering at the component level.
338
- *
339
- * @remarks
340
- *
341
- * [API](https://react-hook-form.com/docs/usewatch) • [Demo](https://codesandbox.io/s/react-hook-form-v7-ts-usewatch-h9i5e)
342
- *
343
- * @example
344
- * ```tsx
345
- * const { watch } = useForm();
346
- * const values = useWatch({
347
- * name: "fieldName"
348
- * control,
349
- * })
350
- * ```
351
- */
352
- function useWatch(props) {
353
- const methods = useFormContext();
354
- const { control = methods.control, name, defaultValue, disabled, exact, } = props || {};
355
- const _name = React__default.useRef(name);
356
- _name.current = name;
357
- useSubscribe({
358
- disabled,
359
- subject: control._subjects.values,
360
- next: (formState) => {
361
- if (shouldSubscribeByName(_name.current, formState.name, exact)) {
362
- updateValue(cloneObject(generateWatchOutput(_name.current, control._names, formState.values || control._formValues, false, defaultValue)));
363
- }
364
- },
365
- });
366
- const [value, updateValue] = React__default.useState(control._getWatch(name, defaultValue));
367
- React__default.useEffect(() => control._removeUnmounted());
368
- return value;
369
- }
370
-
371
- var isKey = (value) => /^\w*$/.test(value);
372
-
373
- var stringToPath = (input) => compact(input.replace(/["|']|\]/g, '').split(/\.|\[/));
374
-
375
- function set(object, path, value) {
376
- let index = -1;
377
- const tempPath = isKey(path) ? [path] : stringToPath(path);
378
- const length = tempPath.length;
379
- const lastIndex = length - 1;
380
- while (++index < length) {
381
- const key = tempPath[index];
382
- let newValue = value;
383
- if (index !== lastIndex) {
384
- const objValue = object[key];
385
- newValue =
386
- isObject(objValue) || Array.isArray(objValue)
387
- ? objValue
388
- : !isNaN(+tempPath[index + 1])
389
- ? []
390
- : {};
391
- }
392
- object[key] = newValue;
393
- object = object[key];
394
- }
395
- return object;
396
- }
397
-
398
- /**
399
- * 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.
400
- *
401
- * @remarks
402
- * [API](https://react-hook-form.com/docs/usecontroller) • [Demo](https://codesandbox.io/s/usecontroller-0o8px)
403
- *
404
- * @param props - the path name to the form field value, and validation rules.
405
- *
406
- * @returns field properties, field and form state. {@link UseControllerReturn}
407
- *
408
- * @example
409
- * ```tsx
410
- * function Input(props) {
411
- * const { field, fieldState, formState } = useController(props);
412
- * return (
413
- * <div>
414
- * <input {...field} placeholder={props.name} />
415
- * <p>{fieldState.isTouched && "Touched"}</p>
416
- * <p>{formState.isSubmitted ? "submitted" : ""}</p>
417
- * </div>
418
- * );
419
- * }
420
- * ```
421
- */
422
- function useController(props) {
423
- const methods = useFormContext();
424
- const { name, disabled, control = methods.control, shouldUnregister } = props;
425
- const isArrayField = isNameInFieldArray(control._names.array, name);
426
- const value = useWatch({
427
- control,
428
- name,
429
- defaultValue: get(control._formValues, name, get(control._defaultValues, name, props.defaultValue)),
430
- exact: true,
431
- });
432
- const formState = useFormState({
433
- control,
434
- name,
435
- });
436
- const _registerProps = React__default.useRef(control.register(name, {
437
- ...props.rules,
438
- value,
439
- }));
440
- _registerProps.current = control.register(name, props.rules);
441
- React__default.useEffect(() => {
442
- const _shouldUnregisterField = control._options.shouldUnregister || shouldUnregister;
443
- const updateMounted = (name, value) => {
444
- const field = get(control._fields, name);
445
- if (field) {
446
- field._f.mount = value;
447
- }
448
- };
449
- updateMounted(name, true);
450
- if (_shouldUnregisterField) {
451
- const value = cloneObject(get(control._options.defaultValues, name));
452
- set(control._defaultValues, name, value);
453
- if (isUndefined(get(control._formValues, name))) {
454
- set(control._formValues, name, value);
455
- }
456
- }
457
- return () => {
458
- (isArrayField
459
- ? _shouldUnregisterField && !control._state.action
460
- : _shouldUnregisterField)
461
- ? control.unregister(name)
462
- : updateMounted(name, false);
463
- };
464
- }, [name, control, isArrayField, shouldUnregister]);
465
- React__default.useEffect(() => {
466
- control._updateDisabledField({
467
- disabled,
468
- fields: control._fields,
469
- name,
470
- });
471
- }, [disabled, name, control]);
472
- return {
473
- field: {
474
- name,
475
- value,
476
- disabled,
477
- onChange: React__default.useCallback((event) => _registerProps.current.onChange({
478
- target: {
479
- value: getEventValue(event),
480
- name: name,
481
- },
482
- type: EVENTS.CHANGE,
483
- }), [name]),
484
- onBlur: React__default.useCallback(() => _registerProps.current.onBlur({
485
- target: {
486
- value: get(control._formValues, name),
487
- name: name,
488
- },
489
- type: EVENTS.BLUR,
490
- }), [name, control]),
491
- ref: (elm) => {
492
- const field = get(control._fields, name);
493
- if (field && elm) {
494
- field._f.ref = {
495
- focus: () => elm.focus(),
496
- select: () => elm.select(),
497
- setCustomValidity: (message) => elm.setCustomValidity(message),
498
- reportValidity: () => elm.reportValidity(),
499
- };
500
- }
501
- },
502
- },
503
- formState,
504
- fieldState: Object.defineProperties({}, {
505
- invalid: {
506
- enumerable: true,
507
- get: () => !!get(formState.errors, name),
508
- },
509
- isDirty: {
510
- enumerable: true,
511
- get: () => !!get(formState.dirtyFields, name),
512
- },
513
- isTouched: {
514
- enumerable: true,
515
- get: () => !!get(formState.touchedFields, name),
516
- },
517
- error: {
518
- enumerable: true,
519
- get: () => get(formState.errors, name),
520
- },
521
- }),
522
- };
523
- }
524
-
525
- var _templateObject;
526
- var RadioButtonLabel = styled.label(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n display: flex;\n margin-bottom: ", ";\n margin-right: ", ";\n"])), function (props) {
527
- return props.theme.marginPaddings[0];
528
- }, function (props) {
529
- return props.theme.marginPaddings[0];
530
- });
531
-
532
- var _templateObject$1;
533
- var RadioButtonText = styled.div(_templateObject$1 || (_templateObject$1 = _taggedTemplateLiteral(["\n display: flex;\n align-items: center;\n"])));
534
-
535
- var _templateObject$2;
536
- 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) {
537
- return props.theme.colors.base;
538
- });
539
-
540
- var _templateObject$3;
541
- var RadioButtonCircleInner = styled.div(_templateObject$3 || (_templateObject$3 = _taggedTemplateLiteral(["\n height: 8px;\n width: 8px;\n border-radius: 50%;\n margin: auto;\n"])));
542
-
543
- var _templateObject$4;
544
- 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) {
545
- return props.theme.colors.base;
546
- });
547
-
548
- var _excluded = ["ref"];
549
-
550
- var _templateObject$5, _templateObject2;
551
- var OptionsRow = styled.div(_templateObject$5 || (_templateObject$5 = _taggedTemplateLiteral(["\n display: flex;\n flex-wrap: nowrap;\n flex-direction: row;\n"])));
552
- var Options = styled.div(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n display: flex;\n flex-wrap: nowrap;\n flex-direction: row;\n flex-basis: 60%;\n"])));
553
-
554
- var CommunicationPreferenceOptionsRenderer = function CommunicationPreferenceOptionsRenderer(_ref) {
555
- var control = _ref.control,
556
- name = _ref.name,
557
- isDisabled = _ref.isDisabled,
558
- options = _ref.options,
559
- defaultValue = _ref.defaultValue,
560
- setValue = _ref.setValue;
561
-
562
- var _useController = useController({
563
- name: name,
564
- control: control,
565
- defaultValue: defaultValue
566
- }),
567
- _useController$field = _useController.field,
568
- ref = _useController$field.ref,
569
- inputProps = _objectWithoutProperties(_useController$field, _excluded),
570
- _useController$fieldS = _useController.fieldState,
571
- invalid = _useController$fieldS.invalid,
572
- error = _useController$fieldS.error;
573
-
574
- React.useEffect(function () {
575
- if (defaultValue) {
576
- setValue(name, defaultValue);
577
- }
578
- }, [defaultValue, name, setValue]);
579
- return /*#__PURE__*/React__default.createElement(OptionsRow, null, /*#__PURE__*/React__default.createElement(Options, null, options.map(function (option) {
580
- return /*#__PURE__*/React__default.createElement(RadioButtonLabel, {
581
- key: option.value,
582
- htmlFor: option.value
583
- }, /*#__PURE__*/React__default.createElement(RadioButtonInput, _extends({
584
- id: option.value,
585
- ref: ref,
586
- type: "radio",
587
- name: name,
588
- defaultChecked: inputProps.value === option.value.toString()
589
- }, inputProps, {
590
- disabled: isDisabled,
591
- value: option.value
592
- })), /*#__PURE__*/React__default.createElement(RadioButtonCircle, null, /*#__PURE__*/React__default.createElement(RadioButtonCircleInner, null)), /*#__PURE__*/React__default.createElement(RadioButtonText, null, option.label));
593
- })), invalid && /*#__PURE__*/React__default.createElement("span", {
594
- className: "form__error"
595
- }, error === null || error === void 0 ? void 0 : error.message));
596
- };
597
-
598
- return CommunicationPreferenceOptionsRenderer;
599
-
600
- })));