@weareconceptstudio/form 0.0.2 → 0.0.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.
- package/dist/checkbox/index.d.ts +1 -1
- package/dist/checkbox/index.js +2 -2
- package/dist/color-picker/index.d.ts +1 -1
- package/dist/color-picker/index.js +2 -2
- package/dist/date-picker/index.d.ts +1 -1
- package/dist/date-picker/index.js +2 -2
- package/dist/error-message/index.d.ts +3 -0
- package/dist/error-message/index.js +7 -4
- package/dist/form/BaseForm.d.ts +4 -1
- package/dist/form/BaseForm.js +4 -1
- package/dist/form/Item/index.d.ts +2 -2
- package/dist/form/Item/index.js +3 -3
- package/dist/form/hooks/useFormInstance.js +1 -1
- package/dist/form/index.d.ts +3 -2
- package/dist/input/BaseInput/index.d.ts +1 -1
- package/dist/input/BaseInput/index.js +23 -16
- package/dist/input/Input.d.ts +1 -1
- package/dist/input/Input.js +5 -2
- package/dist/input/Number/index.d.ts +1 -1
- package/dist/input/Number/index.js +1 -1
- package/dist/input/Password/index.d.ts +1 -1
- package/dist/input/Password/index.js +5 -5
- package/dist/input/TextArea/index.d.ts +1 -1
- package/dist/input/TextArea/index.js +2 -2
- package/dist/input/index.d.ts +1 -1
- package/dist/radio/BaseRadio.d.ts +1 -1
- package/dist/radio/BaseRadio.js +3 -3
- package/dist/radio/Group.d.ts +1 -1
- package/dist/radio/Group.js +5 -2
- package/dist/radio/context.d.ts +1 -1
- package/dist/radio/context.js +3 -3
- package/dist/select/index.d.ts +1 -1
- package/dist/select/index.js +4 -4
- package/dist/upload/index.d.ts +1 -1
- package/dist/upload/index.js +5 -2
- package/package.json +1 -1
package/dist/checkbox/index.d.ts
CHANGED
package/dist/checkbox/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
const Checkbox =
|
|
1
|
+
import React, { forwardRef } from 'react';
|
|
2
|
+
const Checkbox = forwardRef(({ type = 'checkbox', children, ...restProps }, forwardRef) => {
|
|
3
3
|
return (React.createElement("label", null,
|
|
4
4
|
React.createElement("input", { type: type, ...forwardRef, ...restProps }),
|
|
5
5
|
children !== undefined && React.createElement("span", null, children)));
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
const ColorPicker =
|
|
1
|
+
import React, { forwardRef } from 'react';
|
|
2
|
+
const ColorPicker = forwardRef((props, forwardRef) => {
|
|
3
3
|
return (React.createElement("input", { type: 'color', ...forwardRef }));
|
|
4
4
|
});
|
|
5
5
|
if (process.env.NODE_ENV !== 'production') {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import
|
|
1
|
+
import React, { forwardRef } from 'react';
|
|
2
2
|
/*
|
|
3
3
|
types - default=date,datetime-local,month,time,week
|
|
4
4
|
*
|
|
5
5
|
*/
|
|
6
|
-
const DatePicker =
|
|
6
|
+
const DatePicker = forwardRef(({ type = 'date' }, forwardRef) => {
|
|
7
7
|
return (React.createElement("input", { type: type, ...forwardRef }));
|
|
8
8
|
});
|
|
9
9
|
if (process.env.NODE_ENV !== 'production') {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import React, { Fragment, isValidElement, cloneElement, createElement } from 'react';
|
|
2
2
|
import { useFormContext, get } from 'react-hook-form';
|
|
3
3
|
const ErrorMessage = ({ as, errors, name, message, render, ...rest }) => {
|
|
4
4
|
const methods = useFormContext();
|
|
@@ -10,13 +10,16 @@ const ErrorMessage = ({ as, errors, name, message, render, ...rest }) => {
|
|
|
10
10
|
const props = Object.assign({}, rest, {
|
|
11
11
|
children: messageFromRegister || message,
|
|
12
12
|
});
|
|
13
|
-
return
|
|
14
|
-
?
|
|
13
|
+
return isValidElement(as)
|
|
14
|
+
? cloneElement(as, props)
|
|
15
15
|
: render
|
|
16
16
|
? (render({
|
|
17
17
|
message: messageFromRegister || message,
|
|
18
18
|
messages: types,
|
|
19
19
|
}))
|
|
20
|
-
:
|
|
20
|
+
: createElement(as || Fragment, props);
|
|
21
21
|
};
|
|
22
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
23
|
+
ErrorMessage.displayName = 'ErrorMessage';
|
|
24
|
+
}
|
|
22
25
|
export default ErrorMessage;
|
package/dist/form/BaseForm.d.ts
CHANGED
|
@@ -15,4 +15,7 @@ declare function BaseForm({ initialValues: defaultValues, values, children, onSu
|
|
|
15
15
|
shouldUseNativeValidation: any;
|
|
16
16
|
shouldUnregister: any;
|
|
17
17
|
}): React.JSX.Element;
|
|
18
|
-
|
|
18
|
+
declare namespace BaseForm {
|
|
19
|
+
let displayName: string;
|
|
20
|
+
}
|
|
21
|
+
import React from 'react';
|
package/dist/form/BaseForm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import React from 'react';
|
|
2
2
|
import { FormProvider, useForm } from "react-hook-form";
|
|
3
3
|
import styled from 'styled-components';
|
|
4
4
|
// initialValues: object || async () => fetch('/api-endpoint')
|
|
@@ -63,4 +63,7 @@ const BaseForm = ({ initialValues: defaultValues, values, children, onSubmit, la
|
|
|
63
63
|
return (React.createElement(FormProvider, { ...methods },
|
|
64
64
|
React.createElement(StyledForm, { onSubmit: methods.handleSubmit(onSubmit), className: layout }, children)));
|
|
65
65
|
};
|
|
66
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
67
|
+
BaseForm.displayName = 'BaseForm';
|
|
68
|
+
}
|
|
66
69
|
export default BaseForm;
|
package/dist/form/Item/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { cloneElement, isValidElement } from 'react';
|
|
2
2
|
//* HOC's
|
|
3
3
|
import { useFormContext } from "react-hook-form";
|
|
4
4
|
//* Components
|
|
@@ -10,12 +10,12 @@ const FormItem = ({ label, name, children, rules = {} }) => {
|
|
|
10
10
|
React.createElement("div", { className: "form-item-row" },
|
|
11
11
|
React.createElement("div", { className: "form-item-label" },
|
|
12
12
|
React.createElement("label", { htmlFor: name }, label)),
|
|
13
|
-
React.createElement("div", { className: 'form-item-control' },
|
|
13
|
+
React.createElement("div", { className: 'form-item-control' }, isValidElement(children) && cloneElement(children, {
|
|
14
14
|
ref: innerRef,
|
|
15
15
|
name,
|
|
16
16
|
value: getValues()[name]
|
|
17
17
|
})),
|
|
18
|
-
React.createElement(ErrorMessage, { name: name, as: '
|
|
18
|
+
React.createElement(ErrorMessage, { name: name, as: React.createElement("div", { className: 'error-message' }) }))));
|
|
19
19
|
};
|
|
20
20
|
if (process.env.NODE_ENV !== 'production') {
|
|
21
21
|
FormItem.displayName = 'FormItem';
|
package/dist/form/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export default Form;
|
|
2
|
-
declare
|
|
2
|
+
declare function Form({ initialValues: defaultValues, values, children, onSubmit, layout, mode, reValidateMode, errors, resetOptions, criteriaMode, shouldFocusError, delayError, shouldUseNativeValidation, shouldUnregister, }: {
|
|
3
3
|
initialValues: any;
|
|
4
4
|
values: any;
|
|
5
5
|
children: any;
|
|
@@ -14,4 +14,5 @@ declare const Form: ({ initialValues: defaultValues, values, children, onSubmit,
|
|
|
14
14
|
delayError: any;
|
|
15
15
|
shouldUseNativeValidation: any;
|
|
16
16
|
shouldUnregister: any;
|
|
17
|
-
})
|
|
17
|
+
}): import("react").JSX.Element;
|
|
18
|
+
declare namespace Form { }
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export const InputContainer: import("styled-components").IStyledComponent<"web", import("styled-components/dist/types").FastOmit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>>;
|
|
2
2
|
export default BaseInput;
|
|
3
|
-
import
|
|
3
|
+
import React from 'react';
|
|
4
4
|
declare const BaseInput: React.ForwardRefExoticComponent<React.RefAttributes<any>>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import React, { forwardRef, useRef, cloneElement } from 'react';
|
|
2
2
|
import styled from 'styled-components';
|
|
3
|
-
import
|
|
3
|
+
import classNames from 'classnames';
|
|
4
4
|
import { hasPrefixSuffix, hasAddon } from './utils';
|
|
5
5
|
export const InputContainer = styled.div `
|
|
6
6
|
.affix-wrapper {
|
|
@@ -17,20 +17,22 @@ export const InputContainer = styled.div `
|
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
`;
|
|
20
|
-
const BaseInput =
|
|
20
|
+
const BaseInput = forwardRef((props, forwardRef) => {
|
|
21
21
|
const { inputElement: inputEl, addonBefore, addonAfter, prefix, suffix, allowClear, disabled, readOnly, components, value, className, children } = props;
|
|
22
22
|
const inputElement = children ?? inputEl;
|
|
23
23
|
// ======================== Components ======================== //
|
|
24
|
-
const AffixWrapperComponent = components?.affixWrapper || '
|
|
25
|
-
const GroupWrapperComponent = components?.groupWrapper || '
|
|
26
|
-
const WrapperComponent = components?.wrapper || '
|
|
27
|
-
const GroupAddonComponent = components?.groupAddon || '
|
|
24
|
+
const AffixWrapperComponent = components?.affixWrapper || 'div';
|
|
25
|
+
const GroupWrapperComponent = components?.groupWrapper || 'div';
|
|
26
|
+
const WrapperComponent = components?.wrapper || 'div';
|
|
27
|
+
const GroupAddonComponent = components?.groupAddon || 'div';
|
|
28
28
|
// ======================== Refs ======================== //
|
|
29
|
-
const containerRef =
|
|
30
|
-
const groupRef =
|
|
31
|
-
let element =
|
|
32
|
-
|
|
33
|
-
|
|
29
|
+
const containerRef = useRef(null);
|
|
30
|
+
const groupRef = useRef(null);
|
|
31
|
+
let element = cloneElement(inputElement, {
|
|
32
|
+
className: classNames({
|
|
33
|
+
'base-input': true,
|
|
34
|
+
[`${inputElement.props.className}`]: inputElement.props.className
|
|
35
|
+
}),
|
|
34
36
|
});
|
|
35
37
|
// ======================== Prefix && Suffix ======================== //
|
|
36
38
|
if (hasPrefixSuffix(props)) {
|
|
@@ -46,7 +48,7 @@ const BaseInput = React.forwardRef((props, forwardRef) => {
|
|
|
46
48
|
// handleReset?.(event);
|
|
47
49
|
// onClear?.();
|
|
48
50
|
// }}
|
|
49
|
-
onMouseDown: (e) => e.preventDefault(), role: "button", tabIndex: -1, className:
|
|
51
|
+
onMouseDown: (e) => e.preventDefault(), role: "button", tabIndex: -1, className: classNames(clearIconCls, {
|
|
50
52
|
[`${clearIconCls}-hidden`]: !needClear,
|
|
51
53
|
[`${clearIconCls}-has-suffix`]: !!suffix,
|
|
52
54
|
}) }, iconNode));
|
|
@@ -61,14 +63,19 @@ const BaseInput = React.forwardRef((props, forwardRef) => {
|
|
|
61
63
|
}
|
|
62
64
|
// ======================== Addon (Before && After) ======================== //
|
|
63
65
|
if (hasAddon(props)) {
|
|
64
|
-
element = (React.createElement(GroupWrapperComponent, { ref: groupRef },
|
|
66
|
+
element = (React.createElement(GroupWrapperComponent, { className: 'group-wrapper', ref: groupRef },
|
|
65
67
|
React.createElement(WrapperComponent, null,
|
|
66
68
|
addonBefore && (React.createElement(GroupAddonComponent, null, addonBefore)),
|
|
67
69
|
element,
|
|
68
70
|
addonAfter && (React.createElement(GroupAddonComponent, null, addonAfter)))));
|
|
69
71
|
}
|
|
70
|
-
return (React.createElement(InputContainer,
|
|
71
|
-
|
|
72
|
+
return (React.createElement(InputContainer, { className: classNames({
|
|
73
|
+
'base-input-container': true,
|
|
74
|
+
[`${className}-container`]: className
|
|
75
|
+
}) }, cloneElement(element, {
|
|
76
|
+
className: classNames({
|
|
77
|
+
[element.props.className]: element.props.className,
|
|
78
|
+
}),
|
|
72
79
|
})));
|
|
73
80
|
});
|
|
74
81
|
if (process.env.NODE_ENV !== 'production') {
|
package/dist/input/Input.d.ts
CHANGED
package/dist/input/Input.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import React, { forwardRef } from 'react';
|
|
2
2
|
import styled from 'styled-components';
|
|
3
3
|
import BaseInput from './BaseInput';
|
|
4
4
|
const StyledInput = styled.input `
|
|
@@ -10,9 +10,12 @@ const StyledInput = styled.input `
|
|
|
10
10
|
padding: 4px 11px;
|
|
11
11
|
outline: none;
|
|
12
12
|
`;
|
|
13
|
-
const Input =
|
|
13
|
+
const Input = forwardRef((props, forwardRef) => {
|
|
14
14
|
const { autoComplete, onChange, onFocus, onBlur, onPressEnter, onKeyDown, onKeyUp, disabled, className, type = 'text', placeholder, value, } = props;
|
|
15
15
|
return (React.createElement(BaseInput, { ...props, value: value, disabled: disabled },
|
|
16
16
|
React.createElement(StyledInput, { type: type, autoComplete: autoComplete, onChange: onChange, onFocus: onFocus, onBlur: onBlur, onPressEnter: onPressEnter, onKeyDown: onKeyDown, onKeyUp: onKeyUp, disabled: disabled, className: className, placeholder: placeholder, ...forwardRef })));
|
|
17
17
|
});
|
|
18
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
19
|
+
Input.displayName = 'Input';
|
|
20
|
+
}
|
|
18
21
|
export default Input;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import React, { useState, useEffect, forwardRef, isValidElement, cloneElement } from 'react';
|
|
2
2
|
import { omit } from '@weareconceptstudio/core';
|
|
3
3
|
import { eyeIcon, openEye } from './icons';
|
|
4
4
|
import Input from '../Input';
|
|
@@ -7,11 +7,11 @@ const actionMap = {
|
|
|
7
7
|
click: 'onClick',
|
|
8
8
|
hover: 'onMouseOver',
|
|
9
9
|
};
|
|
10
|
-
const Password =
|
|
10
|
+
const Password = forwardRef((props, ref) => {
|
|
11
11
|
const { disabled, action = 'click', visibilityToggle = true, iconRender = defaultIconRender } = props;
|
|
12
12
|
const visibilityControlled = typeof visibilityToggle === 'object' && visibilityToggle.visible !== undefined;
|
|
13
|
-
const [visible, setVisible] =
|
|
14
|
-
|
|
13
|
+
const [visible, setVisible] = useState(() => visibilityControlled ? visibilityToggle.visible : false);
|
|
14
|
+
useEffect(() => {
|
|
15
15
|
if (visibilityControlled) {
|
|
16
16
|
setVisible(visibilityToggle.visible);
|
|
17
17
|
}
|
|
@@ -42,7 +42,7 @@ const Password = React.forwardRef((props, ref) => {
|
|
|
42
42
|
e.preventDefault();
|
|
43
43
|
},
|
|
44
44
|
};
|
|
45
|
-
return
|
|
45
|
+
return cloneElement(isValidElement(icon) ? icon : React.createElement("span", null, icon), iconProps);
|
|
46
46
|
};
|
|
47
47
|
const suffixIcon = visibilityToggle && getIcon();
|
|
48
48
|
const { className, ...restProps } = props;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import React, { forwardRef } from 'react';
|
|
2
2
|
import styled from 'styled-components';
|
|
3
3
|
import BaseInput from '../BaseInput';
|
|
4
4
|
const StyledTextArea = styled.textarea `
|
|
5
5
|
font-size: 14px;
|
|
6
6
|
padding: 4px 11px;
|
|
7
7
|
`;
|
|
8
|
-
const TextArea =
|
|
8
|
+
const TextArea = forwardRef((props, forwardRef) => {
|
|
9
9
|
return (React.createElement(BaseInput, { ...props },
|
|
10
10
|
React.createElement(StyledTextArea, { ...forwardRef, rows: 5 })));
|
|
11
11
|
});
|
package/dist/input/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export default Input;
|
|
2
|
-
import Input from
|
|
2
|
+
import Input from './Input';
|
package/dist/radio/BaseRadio.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import React, { forwardRef, useContext } from 'react';
|
|
2
2
|
import RadioGroupContext, { RadioOptionTypeContext } from './context';
|
|
3
3
|
import Checkbox from "../checkbox";
|
|
4
|
-
const Radio =
|
|
5
|
-
const groupContext =
|
|
4
|
+
const Radio = forwardRef(({ children, ...restProps }, forwardRef) => {
|
|
5
|
+
const groupContext = useContext(RadioGroupContext);
|
|
6
6
|
const radioProps = {
|
|
7
7
|
ref: forwardRef,
|
|
8
8
|
...restProps
|
package/dist/radio/Group.d.ts
CHANGED
package/dist/radio/Group.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import React, { forwardRef } from 'react';
|
|
2
2
|
import { RadioGroupContextProvider } from './context';
|
|
3
3
|
import Radio from './BaseRadio';
|
|
4
|
-
const RadioGroup =
|
|
4
|
+
const RadioGroup = forwardRef((props, forwardRef) => {
|
|
5
5
|
const { children, options } = props;
|
|
6
6
|
let childrenToRender = children;
|
|
7
7
|
if (options && options.length > 0) {
|
|
@@ -17,4 +17,7 @@ const RadioGroup = React.forwardRef((props, forwardRef) => {
|
|
|
17
17
|
forwardRef: forwardRef,
|
|
18
18
|
} }, childrenToRender)));
|
|
19
19
|
});
|
|
20
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
21
|
+
RadioGroup.displayName = 'RadioGroup';
|
|
22
|
+
}
|
|
20
23
|
export default RadioGroup;
|
package/dist/radio/context.d.ts
CHANGED
|
@@ -2,5 +2,5 @@ export const RadioGroupContextProvider: React.Provider<any>;
|
|
|
2
2
|
export default RadioGroupContext;
|
|
3
3
|
export const RadioOptionTypeContext: React.Context<any>;
|
|
4
4
|
export const RadioOptionTypeContextProvider: React.Provider<any>;
|
|
5
|
-
import
|
|
5
|
+
import React from 'react';
|
|
6
6
|
declare const RadioGroupContext: React.Context<any>;
|
package/dist/radio/context.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
const RadioGroupContext =
|
|
1
|
+
import React, { createContext } from 'react';
|
|
2
|
+
const RadioGroupContext = createContext(null);
|
|
3
3
|
export const RadioGroupContextProvider = RadioGroupContext.Provider;
|
|
4
4
|
export default RadioGroupContext;
|
|
5
|
-
export const RadioOptionTypeContext =
|
|
5
|
+
export const RadioOptionTypeContext = createContext(null);
|
|
6
6
|
export const RadioOptionTypeContextProvider = RadioOptionTypeContext.Provider;
|
package/dist/select/index.d.ts
CHANGED
package/dist/select/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import React, { forwardRef, useState, useCallback } from 'react';
|
|
2
2
|
import ReactSelect from 'react-select';
|
|
3
3
|
import useFormInstance from '../form/hooks/useFormInstance';
|
|
4
|
-
const Select =
|
|
4
|
+
const Select = forwardRef((props, forwardRef) => {
|
|
5
5
|
const { name, multiple = false, allowClear = false, allowSearch = true, disabled = false, loading = false, options = [], } = props;
|
|
6
6
|
const formInstance = useFormInstance();
|
|
7
|
-
const [val, setVal] =
|
|
8
|
-
const handleChange =
|
|
7
|
+
const [val, setVal] = useState(formInstance.getValues()[name] || (multiple ? [] : ''));
|
|
8
|
+
const handleChange = useCallback((newVal) => {
|
|
9
9
|
let vals;
|
|
10
10
|
if (multiple) {
|
|
11
11
|
vals = newVal.map(item => item.value);
|
package/dist/upload/index.d.ts
CHANGED
package/dist/upload/index.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
const Upload =
|
|
1
|
+
import React, { forwardRef } from 'react';
|
|
2
|
+
const Upload = forwardRef((props, forwardRef) => {
|
|
3
3
|
return (React.createElement("div", null,
|
|
4
4
|
React.createElement("input", { type: 'file', ...forwardRef })));
|
|
5
5
|
});
|
|
6
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
7
|
+
Upload.displayName = 'Upload';
|
|
8
|
+
}
|
|
6
9
|
export default Upload;
|