@weareconceptstudio/form 0.0.7 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/form/BaseForm.d.ts +1 -4
- package/dist/form/BaseForm.js +8 -4
- package/dist/select/index.js +29 -2
- package/dist/styles/formStyle.js +17 -0
- package/package.json +1 -1
package/dist/form/BaseForm.d.ts
CHANGED
|
@@ -16,8 +16,5 @@ interface BaseFormProps<T extends FieldValues> {
|
|
|
16
16
|
shouldUnregister?: boolean;
|
|
17
17
|
className?: string;
|
|
18
18
|
}
|
|
19
|
-
declare const BaseForm:
|
|
20
|
-
<T extends FieldValues>({ initialValues: defaultValues, values, children, onSubmit, mode, reValidateMode, errors, resetOptions, criteriaMode, shouldFocusError, delayError, shouldUseNativeValidation, shouldUnregister, className, }: BaseFormProps<T>): React.JSX.Element;
|
|
21
|
-
displayName: string;
|
|
22
|
-
};
|
|
19
|
+
declare const BaseForm: React.ForwardRefExoticComponent<BaseFormProps<FieldValues> & React.RefAttributes<any>>;
|
|
23
20
|
export default BaseForm;
|
package/dist/form/BaseForm.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import React, { useCallback } from 'react';
|
|
1
|
+
import React, { useCallback, forwardRef, useImperativeHandle } from 'react';
|
|
2
2
|
import { FormProvider, useForm } from 'react-hook-form';
|
|
3
3
|
import { Text } from '@weareconceptstudio/core';
|
|
4
4
|
import classNames from 'classnames';
|
|
5
|
-
const BaseForm = ({ initialValues: defaultValues, values, children, onSubmit, mode = 'onChange', reValidateMode = 'onChange', errors, resetOptions, criteriaMode = 'firstError', shouldFocusError, delayError = 0, shouldUseNativeValidation, shouldUnregister, className,
|
|
5
|
+
const BaseForm = forwardRef(({ initialValues: defaultValues, values, children, onSubmit, mode = 'onChange', reValidateMode = 'onChange', errors, resetOptions, criteriaMode = 'firstError', shouldFocusError, delayError = 0, shouldUseNativeValidation, shouldUnregister, className }, ref) => {
|
|
6
6
|
const methods = useForm({
|
|
7
7
|
mode,
|
|
8
8
|
errors,
|
|
@@ -38,14 +38,18 @@ const BaseForm = ({ initialValues: defaultValues, values, children, onSubmit, mo
|
|
|
38
38
|
}
|
|
39
39
|
});
|
|
40
40
|
}, [methods, onSubmit]);
|
|
41
|
+
useImperativeHandle(ref, () => ({
|
|
42
|
+
...methods,
|
|
43
|
+
submit: () => methods.handleSubmit(handleSubmit)(),
|
|
44
|
+
}));
|
|
41
45
|
return (React.createElement(FormProvider, { ...methods },
|
|
42
|
-
methods.formState.errors.root?.serverError && (React.createElement("div", { className:
|
|
46
|
+
methods.formState.errors.root?.serverError && (React.createElement("div", { className: 'global-error-wrap' },
|
|
43
47
|
React.createElement(Text, { className: 'backend-error', text: methods.formState.errors.root?.serverError.message }),
|
|
44
48
|
React.createElement(Text, { className: 'frontend-error', text: 'globalError' }))),
|
|
45
49
|
React.createElement("form", { onSubmit: methods.handleSubmit(handleSubmit), className: classNames({
|
|
46
50
|
[className]: !!className,
|
|
47
51
|
}) }, children)));
|
|
48
|
-
};
|
|
52
|
+
});
|
|
49
53
|
if (process.env.NODE_ENV !== 'production') {
|
|
50
54
|
BaseForm.displayName = 'BaseForm';
|
|
51
55
|
}
|
package/dist/select/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useState } from 'react';
|
|
1
|
+
import React, { useState, useMemo } from 'react';
|
|
2
2
|
import ReactSelect, { components } from 'react-select';
|
|
3
3
|
import classNames from 'classnames';
|
|
4
4
|
import { bottom_arrow, empty } from './icons';
|
|
@@ -6,7 +6,7 @@ import { useInput } from '../form/hooks/useInput';
|
|
|
6
6
|
import useFormInstance from '../form/hooks/useFormInstance';
|
|
7
7
|
import { useTranslation } from '@weareconceptstudio/core';
|
|
8
8
|
const Select = (props) => {
|
|
9
|
-
const { name, placeholder, value, onChange, multiple = false, allowClear = false, allowSearch = true, disabled = false, loading = false, options = [], className, select_arrow = false, select_empty = false } = props;
|
|
9
|
+
const { name, placeholder, value, onChange, multiple = false, allowClear = false, allowSearch = true, disabled = false, loading = false, options: list = [], className, select_arrow = false, select_empty = false, optionKey, optionValue, optGroup } = props;
|
|
10
10
|
const { translate } = useTranslation();
|
|
11
11
|
const formInstance = useFormInstance();
|
|
12
12
|
let selectProps = {};
|
|
@@ -52,6 +52,33 @@ const Select = (props) => {
|
|
|
52
52
|
select_empty || empty,
|
|
53
53
|
React.createElement("p", { className: `no-options` }, 'No Data')));
|
|
54
54
|
};
|
|
55
|
+
const options = useMemo(() => {
|
|
56
|
+
const newOptions = [];
|
|
57
|
+
const labelKey = optionKey ?? 'name';
|
|
58
|
+
const valueKey = optionValue ?? 'id';
|
|
59
|
+
if (optGroup) {
|
|
60
|
+
Object.keys(list).map((obj) => {
|
|
61
|
+
newOptions.push({
|
|
62
|
+
label: obj,
|
|
63
|
+
options: list[obj].map((option) => {
|
|
64
|
+
return {
|
|
65
|
+
label: option[labelKey],
|
|
66
|
+
value: option[valueKey],
|
|
67
|
+
};
|
|
68
|
+
}),
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
list?.map((option) => {
|
|
74
|
+
newOptions.push({
|
|
75
|
+
label: option[labelKey],
|
|
76
|
+
value: option[valueKey],
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
return newOptions;
|
|
81
|
+
}, [list, optionKey, optionValue, optGroup]);
|
|
55
82
|
return (React.createElement(ReactSelect
|
|
56
83
|
// unstyled
|
|
57
84
|
// menuIsOpen={true}
|
package/dist/styles/formStyle.js
CHANGED
|
@@ -7,6 +7,8 @@ const FormStyle = createGlobalStyle `${css `
|
|
|
7
7
|
--form_errorSize: var(--sp2x);
|
|
8
8
|
--form_passwordIconSize: var(--sp4x);
|
|
9
9
|
|
|
10
|
+
--form_errorDistance: var(--sp1x);
|
|
11
|
+
|
|
10
12
|
//! Select fix height size
|
|
11
13
|
--form_emptyPadTB: var(--sp5x);
|
|
12
14
|
--form_emptyIconSize: var(--sp7x);
|
|
@@ -383,6 +385,7 @@ const FormStyle = createGlobalStyle `${css `
|
|
|
383
385
|
font-family: var(--form_Font);
|
|
384
386
|
font-weight: 400;
|
|
385
387
|
color: var(--form_errorMessageColor);
|
|
388
|
+
transform: translateY(var(--form_errorDistance));
|
|
386
389
|
}
|
|
387
390
|
|
|
388
391
|
/* //! Disabled Styles */
|
|
@@ -444,6 +447,8 @@ const FormStyle = createGlobalStyle `${css `
|
|
|
444
447
|
--form_errorSize: var(--sp2x);
|
|
445
448
|
--form_passwordIconSize: var(--sp3x);
|
|
446
449
|
|
|
450
|
+
--form_errorDistance: var(--sp1x);
|
|
451
|
+
|
|
447
452
|
//! Select fix height size
|
|
448
453
|
--form_emptyPadTB: var(--sp5x);
|
|
449
454
|
--form_emptyIconSize: var(--sp6x);
|
|
@@ -465,6 +470,8 @@ const FormStyle = createGlobalStyle `${css `
|
|
|
465
470
|
--form_errorSize: var(--sp2x);
|
|
466
471
|
--form_passwordIconSize: var(--sp3x);
|
|
467
472
|
|
|
473
|
+
--form_errorDistance: var(--sp0-5x);
|
|
474
|
+
|
|
468
475
|
//! Select fix height size
|
|
469
476
|
--form_emptyPadTB: var(--sp6x);
|
|
470
477
|
--form_emptyIconSize: var(--sp6x);
|
|
@@ -486,6 +493,8 @@ const FormStyle = createGlobalStyle `${css `
|
|
|
486
493
|
--form_errorSize: var(--sp2x);
|
|
487
494
|
--form_passwordIconSize: var(--sp3x);
|
|
488
495
|
|
|
496
|
+
--form_errorDistance: var(--sp0-5x);
|
|
497
|
+
|
|
489
498
|
//! Select fix height size
|
|
490
499
|
--form_emptyPadTB: var(--sp5x);
|
|
491
500
|
--form_emptyIconSize: var(--sp6x);
|
|
@@ -507,6 +516,8 @@ const FormStyle = createGlobalStyle `${css `
|
|
|
507
516
|
--form_errorSize: var(--sp1-5x);
|
|
508
517
|
--form_passwordIconSize: var(--sp2-5x);
|
|
509
518
|
|
|
519
|
+
--form_errorDistance: var(--sp0-5x);
|
|
520
|
+
|
|
510
521
|
//! Select fix height size
|
|
511
522
|
--form_emptyPadTB: var(--sp4x);
|
|
512
523
|
--form_emptyIconSize: var(--sp6x);
|
|
@@ -528,6 +539,8 @@ const FormStyle = createGlobalStyle `${css `
|
|
|
528
539
|
--form_errorSize: var(--sp1-5x);
|
|
529
540
|
--form_passwordIconSize: var(--sp2-5x);
|
|
530
541
|
|
|
542
|
+
--form_errorDistance: var(--sp0-5x);
|
|
543
|
+
|
|
531
544
|
//! Select fix height size
|
|
532
545
|
--form_emptyPadTB: var(--sp4x);
|
|
533
546
|
--form_emptyIconSize: var(--sp5x);
|
|
@@ -549,6 +562,8 @@ const FormStyle = createGlobalStyle `${css `
|
|
|
549
562
|
--form_errorSize: var(--sp1-5x);
|
|
550
563
|
--form_passwordIconSize: var(--sp2-5x);
|
|
551
564
|
|
|
565
|
+
--form_errorDistance: var(--sp0-5x);
|
|
566
|
+
|
|
552
567
|
//! Select fix height size
|
|
553
568
|
--form_emptyPadTB: var(--sp4x);
|
|
554
569
|
--form_emptyIconSize: var(--sp5x);
|
|
@@ -570,6 +585,8 @@ const FormStyle = createGlobalStyle `${css `
|
|
|
570
585
|
--form_errorSize: var(--sp1-5x);
|
|
571
586
|
--form_passwordIconSize: var(--sp2-5x);
|
|
572
587
|
|
|
588
|
+
--form_errorDistance: var(--sp0-5x);
|
|
589
|
+
|
|
573
590
|
//! Select fix height size
|
|
574
591
|
--form_emptyPadTB: var(--sp4x);
|
|
575
592
|
--form_emptyIconSize: var(--sp5x);
|