@weareconceptstudio/form 0.0.3 → 0.0.4
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/FormConfig.d.ts +5 -0
- package/dist/FormConfig.js +19 -0
- package/dist/checkbox/BaseCheckbox.d.ts +3 -0
- package/dist/checkbox/BaseCheckbox.js +51 -0
- package/dist/checkbox/index.js +15 -4
- package/dist/color-picker/index.d.ts +4 -1
- package/dist/color-picker/index.js +4 -4
- package/dist/date-picker/index.d.ts +6 -1
- package/dist/date-picker/index.js +4 -4
- package/dist/error-message/index.js +2 -2
- package/dist/form/BaseForm.d.ts +22 -20
- package/dist/form/BaseForm.js +38 -55
- package/dist/form/Builder/index.d.ts +9 -0
- package/dist/form/Builder/index.js +46 -0
- package/dist/form/Builder/style.d.ts +2 -0
- package/dist/form/Builder/style.js +3 -0
- package/dist/form/Item/index.d.ts +12 -10
- package/dist/form/Item/index.js +25 -18
- package/dist/form/hooks/rules.d.ts +3 -0
- package/dist/form/hooks/rules.js +44 -0
- package/dist/form/hooks/useEvent.d.ts +1 -0
- package/dist/form/hooks/useEvent.js +12 -0
- package/dist/form/hooks/useFormInstance.js +3 -0
- package/dist/form/hooks/useInput.d.ts +12 -0
- package/dist/form/hooks/useInput.js +46 -0
- package/dist/form/index.d.ts +6 -17
- package/dist/form/index.js +3 -2
- package/dist/index.d.ts +3 -0
- package/dist/index.js +4 -0
- package/dist/input/BaseInput/index.d.ts +4 -2
- package/dist/input/BaseInput/index.js +13 -31
- package/dist/input/Input.d.ts +4 -1
- package/dist/input/Input.js +15 -16
- package/dist/input/Number/index.d.ts +4 -1
- package/dist/input/Number/index.js +27 -4
- package/dist/input/Password/icons.d.ts +1 -1
- package/dist/input/Password/icons.js +6 -6
- package/dist/input/Password/index.d.ts +4 -1
- package/dist/input/Password/index.js +5 -5
- package/dist/input/TextArea/index.d.ts +4 -1
- package/dist/input/TextArea/index.js +8 -9
- package/dist/input/index.d.ts +10 -1
- package/dist/input/index.js +6 -4
- package/dist/phone-number/index.d.ts +7 -0
- package/dist/phone-number/index.js +13 -0
- package/dist/radio/BaseRadio.js +18 -5
- package/dist/radio/Group.js +19 -2
- package/dist/radio/index.js +2 -2
- package/dist/select/icons.d.ts +3 -0
- package/dist/select/icons.js +6 -0
- package/dist/select/index.d.ts +4 -1
- package/dist/select/index.js +57 -20
- package/dist/styles/formStyle.d.ts +2 -0
- package/dist/styles/formStyle.js +585 -0
- package/dist/styles/theme.d.ts +2 -0
- package/dist/styles/theme.js +113 -0
- package/dist/styles/variables.d.ts +2 -0
- package/dist/styles/variables.js +246 -0
- package/dist/translations/en.d.ts +52 -0
- package/dist/translations/en.js +52 -0
- package/dist/translations/index.d.ts +54 -0
- package/dist/translations/index.js +2 -0
- package/dist/upload/UploadButton/index.d.ts +3 -0
- package/dist/upload/UploadButton/index.js +41 -0
- package/dist/upload/UploadButton/style.d.ts +2 -0
- package/dist/upload/UploadButton/style.js +24 -0
- package/dist/upload/UploadList/ListItem/index.d.ts +5 -0
- package/dist/upload/UploadList/ListItem/index.js +11 -0
- package/dist/upload/UploadList/index.d.ts +3 -0
- package/dist/upload/UploadList/index.js +11 -0
- package/dist/upload/UploadList/style.d.ts +2 -0
- package/dist/upload/UploadList/style.js +13 -0
- package/dist/upload/index.d.ts +4 -1
- package/dist/upload/index.js +15 -5
- package/dist/upload/utils.d.ts +9 -0
- package/dist/upload/utils.js +64 -0
- package/package.json +31 -34
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
export * from "./FormConfig";
|
|
1
2
|
export { default as Form } from "./form";
|
|
3
|
+
export { default as FormBuilder } from "./form/Builder";
|
|
2
4
|
export { default as ErrorMessage } from "./error-message";
|
|
3
5
|
export { default as Input } from "./input";
|
|
4
6
|
export { default as Checkbox } from "./checkbox";
|
|
@@ -7,3 +9,4 @@ export { default as DatePicker } from "./date-picker";
|
|
|
7
9
|
export { default as Radio } from "./radio";
|
|
8
10
|
export { default as Select } from "./select";
|
|
9
11
|
export { default as Upload } from "./upload";
|
|
12
|
+
export { default as PhoneNumber } from "./phone-number";
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
export * from './FormConfig';
|
|
1
3
|
export { default as Form } from './form';
|
|
4
|
+
export { default as FormBuilder } from './form/Builder';
|
|
2
5
|
export { default as ErrorMessage } from './error-message';
|
|
3
6
|
export { default as Input } from './input';
|
|
4
7
|
export { default as Checkbox } from './checkbox';
|
|
@@ -7,3 +10,4 @@ export { default as DatePicker } from './date-picker';
|
|
|
7
10
|
export { default as Radio } from './radio';
|
|
8
11
|
export { default as Select } from './select';
|
|
9
12
|
export { default as Upload } from './upload';
|
|
13
|
+
export { default as PhoneNumber } from './phone-number';
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
export const InputContainer: import("styled-components").IStyledComponent<"web", import("styled-components/dist/types").FastOmit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>>;
|
|
2
1
|
export default BaseInput;
|
|
2
|
+
declare function BaseInput(props: any): React.JSX.Element;
|
|
3
|
+
declare namespace BaseInput {
|
|
4
|
+
let displayName: string;
|
|
5
|
+
}
|
|
3
6
|
import React from 'react';
|
|
4
|
-
declare const BaseInput: React.ForwardRefExoticComponent<React.RefAttributes<any>>;
|
|
@@ -1,23 +1,7 @@
|
|
|
1
|
-
import React, {
|
|
2
|
-
import styled from 'styled-components';
|
|
1
|
+
import React, { useRef, cloneElement } from 'react';
|
|
3
2
|
import classNames from 'classnames';
|
|
4
3
|
import { hasPrefixSuffix, hasAddon } from './utils';
|
|
5
|
-
|
|
6
|
-
.affix-wrapper {
|
|
7
|
-
position:relative;
|
|
8
|
-
display:inline-flex;
|
|
9
|
-
|
|
10
|
-
.clear-icon {
|
|
11
|
-
font-size: 12px;
|
|
12
|
-
cursor: pointer;
|
|
13
|
-
|
|
14
|
-
&-hidden {
|
|
15
|
-
display: none;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
`;
|
|
20
|
-
const BaseInput = forwardRef((props, forwardRef) => {
|
|
4
|
+
const BaseInput = (props) => {
|
|
21
5
|
const { inputElement: inputEl, addonBefore, addonAfter, prefix, suffix, allowClear, disabled, readOnly, components, value, className, children } = props;
|
|
22
6
|
const inputElement = children ?? inputEl;
|
|
23
7
|
// ======================== Components ======================== //
|
|
@@ -31,7 +15,7 @@ const BaseInput = forwardRef((props, forwardRef) => {
|
|
|
31
15
|
let element = cloneElement(inputElement, {
|
|
32
16
|
className: classNames({
|
|
33
17
|
'base-input': true,
|
|
34
|
-
[`${inputElement.props.className}`]: inputElement.props.className
|
|
18
|
+
[`${inputElement.props.className}`]: inputElement.props.className,
|
|
35
19
|
}),
|
|
36
20
|
});
|
|
37
21
|
// ======================== Prefix && Suffix ======================== //
|
|
@@ -40,15 +24,13 @@ const BaseInput = forwardRef((props, forwardRef) => {
|
|
|
40
24
|
if (allowClear) {
|
|
41
25
|
const needClear = !disabled && !readOnly && !!value;
|
|
42
26
|
const clearIconCls = 'clear-icon';
|
|
43
|
-
const iconNode = typeof allowClear === 'object' && allowClear?.clearIcon
|
|
44
|
-
? allowClear.clearIcon
|
|
45
|
-
: '✖';
|
|
27
|
+
const iconNode = typeof allowClear === 'object' && allowClear?.clearIcon ? allowClear.clearIcon : '✖';
|
|
46
28
|
clearIcon = (React.createElement("span", {
|
|
47
29
|
// onClick={(event) => {
|
|
48
30
|
// handleReset?.(event);
|
|
49
31
|
// onClear?.();
|
|
50
32
|
// }}
|
|
51
|
-
onMouseDown: (e) => e.preventDefault(), role:
|
|
33
|
+
onMouseDown: (e) => e.preventDefault(), role: 'button', tabIndex: -1, className: classNames(clearIconCls, {
|
|
52
34
|
[`${clearIconCls}-hidden`]: !needClear,
|
|
53
35
|
[`${clearIconCls}-has-suffix`]: !!suffix,
|
|
54
36
|
}) }, iconNode));
|
|
@@ -57,7 +39,7 @@ const BaseInput = forwardRef((props, forwardRef) => {
|
|
|
57
39
|
clearIcon,
|
|
58
40
|
suffix));
|
|
59
41
|
element = (React.createElement(AffixWrapperComponent, { ref: containerRef, className: 'affix-wrapper' },
|
|
60
|
-
prefix &&
|
|
42
|
+
prefix && React.createElement("span", null, prefix),
|
|
61
43
|
element,
|
|
62
44
|
suffixNode));
|
|
63
45
|
}
|
|
@@ -65,19 +47,19 @@ const BaseInput = forwardRef((props, forwardRef) => {
|
|
|
65
47
|
if (hasAddon(props)) {
|
|
66
48
|
element = (React.createElement(GroupWrapperComponent, { className: 'group-wrapper', ref: groupRef },
|
|
67
49
|
React.createElement(WrapperComponent, null,
|
|
68
|
-
addonBefore &&
|
|
50
|
+
addonBefore && React.createElement(GroupAddonComponent, null, addonBefore),
|
|
69
51
|
element,
|
|
70
|
-
addonAfter &&
|
|
52
|
+
addonAfter && React.createElement(GroupAddonComponent, null, addonAfter))));
|
|
71
53
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
54
|
+
const classString = classNames('base-input-container', {
|
|
55
|
+
[`${className}-container`]: className,
|
|
56
|
+
});
|
|
57
|
+
return (React.createElement("div", { className: classString }, cloneElement(element, {
|
|
76
58
|
className: classNames({
|
|
77
59
|
[element.props.className]: element.props.className,
|
|
78
60
|
}),
|
|
79
61
|
})));
|
|
80
|
-
}
|
|
62
|
+
};
|
|
81
63
|
if (process.env.NODE_ENV !== 'production') {
|
|
82
64
|
BaseInput.displayName = 'BaseInput';
|
|
83
65
|
}
|
package/dist/input/Input.d.ts
CHANGED
package/dist/input/Input.js
CHANGED
|
@@ -1,20 +1,19 @@
|
|
|
1
|
-
import React
|
|
2
|
-
import styled from 'styled-components';
|
|
1
|
+
import React from 'react';
|
|
3
2
|
import BaseInput from './BaseInput';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
return (React.createElement(BaseInput, { ...props, value: value, disabled: disabled },
|
|
16
|
-
React.createElement(
|
|
17
|
-
}
|
|
3
|
+
import { useInput } from '../form/hooks/useInput';
|
|
4
|
+
import { useTranslation } from '@weareconceptstudio/core';
|
|
5
|
+
const Input = (props) => {
|
|
6
|
+
const { name, autoComplete = 'new-password', onChange, onFocus, onBlur, onKeyDown, onKeyUp, disabled, className, type = 'text', placeholder } = props;
|
|
7
|
+
const { translate } = useTranslation();
|
|
8
|
+
const { field } = useInput({
|
|
9
|
+
type,
|
|
10
|
+
name,
|
|
11
|
+
onChange,
|
|
12
|
+
onBlur,
|
|
13
|
+
});
|
|
14
|
+
return (React.createElement(BaseInput, { ...props, value: field.value, disabled: disabled },
|
|
15
|
+
React.createElement("input", { type: type, onFocus: onFocus, onKeyUp: onKeyUp, disabled: disabled, className: className, onKeyDown: onKeyDown, placeholder: translate(placeholder), autoComplete: autoComplete, ...field })));
|
|
16
|
+
};
|
|
18
17
|
if (process.env.NODE_ENV !== 'production') {
|
|
19
18
|
Input.displayName = 'Input';
|
|
20
19
|
}
|
|
@@ -1,8 +1,31 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, { useEffect } from 'react';
|
|
2
2
|
import Input from '../Input';
|
|
3
|
-
const Number =
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
const Number = (props) => {
|
|
4
|
+
//! Disable number input scroll
|
|
5
|
+
useEffect(() => {
|
|
6
|
+
const handleMouseWheel = (e) => {
|
|
7
|
+
e.target.blur();
|
|
8
|
+
};
|
|
9
|
+
const handleKeyDown = (e) => {
|
|
10
|
+
const key = e.charCode || e.keyCode;
|
|
11
|
+
if (key === 38 || key === 40) {
|
|
12
|
+
e.preventDefault();
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
const numberInputs = document.querySelectorAll('input[type="number"]');
|
|
16
|
+
numberInputs.forEach((input) => {
|
|
17
|
+
input.addEventListener('mousewheel', handleMouseWheel);
|
|
18
|
+
input.addEventListener('keydown', handleKeyDown);
|
|
19
|
+
});
|
|
20
|
+
return () => {
|
|
21
|
+
numberInputs.forEach((input) => {
|
|
22
|
+
input.removeEventListener('mousewheel', handleMouseWheel);
|
|
23
|
+
input.removeEventListener('keydown', handleKeyDown);
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
}, []);
|
|
27
|
+
return (React.createElement(Input, { type: 'number', ...props }));
|
|
28
|
+
};
|
|
6
29
|
if (process.env.NODE_ENV !== 'production') {
|
|
7
30
|
Number.displayName = 'InputNumber';
|
|
8
31
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import React from
|
|
2
|
-
export const eyeIcon = React.createElement("svg", { version:
|
|
3
|
-
React.createElement("path", { d:
|
|
4
|
-
React.createElement("path", { d:
|
|
5
|
-
export const openEye = React.createElement("svg", { version:
|
|
6
|
-
React.createElement("path", { d:
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export const eyeIcon = (React.createElement("svg", { version: '1.1', viewBox: '0 0 32 32', xmlns: 'http://www.w3.org/2000/svg' },
|
|
3
|
+
React.createElement("path", { d: 'M15.817 26.533c-8.133 0-14.267-8.8-14.533-9.2s-0.267-1.067 0-1.6c0.267-0.4 6.667-9.067 14.667-9.067 8.133 0 14.267 8.667 14.533 9.067s0.267 1.067 0 1.6c-0.267 0.4-6.667 9.2-14.667 9.2zM4.083 16.533c1.6 2 6.4 7.333 11.733 7.333 5.467 0 10.267-5.333 11.867-7.333-1.6-2-6.4-7.2-11.733-7.2-5.467 0-10.267 5.2-11.867 7.2z' }),
|
|
4
|
+
React.createElement("path", { d: 'M15.952 22.266c-3.2 0-5.733-2.533-5.733-5.733s2.533-5.733 5.733-5.733c3.2 0 5.733 2.533 5.733 5.733s-2.533 5.733-5.733 5.733zM15.952 13.466c-1.733 0-3.067 1.333-3.067 3.067s1.333 3.067 3.067 3.067c1.733 0 3.067-1.333 3.067-3.067s-1.333-3.067-3.067-3.067z' })));
|
|
5
|
+
export const openEye = (React.createElement("svg", { version: '1.1', viewBox: '0 0 32 32', xmlns: 'http://www.w3.org/2000/svg' },
|
|
6
|
+
React.createElement("path", { d: 'M29.983 8.366c-0.533-0.4-1.333-0.4-1.867 0.133 0 0.133-5.867 7.067-12.4 7.067s-12.267-7.067-12.267-7.067c-0.4-0.533-1.333-0.667-1.867-0.267-0.533 0.667-0.667 1.467-0.267 2 0.133 0.133 1.733 2.267 4.4 4.267l-2.933 3.067c-0.533 0.533-0.533 1.333 0 1.867 0.267 0.267 0.533 0.4 0.933 0.4s0.667-0.133 0.933-0.4l3.2-3.333c1.867 1.067 4 2 6.4 2.267l-0.4 4.133c-0.133 0.667 0.4 1.333 1.2 1.467h0.133c0.667 0 1.2-0.533 1.333-1.2l0.4-4.533c2.533-0.267 4.8-1.2 6.8-2.4l2.933 3.067c0.267 0.267 0.667 0.4 0.933 0.4s0.667-0.133 0.933-0.4c0.533-0.533 0.533-1.333 0-1.867l-2.667-2.8c2.533-2 4.133-4 4.267-4.133 0.533-0.4 0.4-1.2-0.133-1.733z' })));
|
|
@@ -2,15 +2,15 @@ import React, { useState, useEffect, forwardRef, isValidElement, cloneElement }
|
|
|
2
2
|
import { omit } from '@weareconceptstudio/core';
|
|
3
3
|
import { eyeIcon, openEye } from './icons';
|
|
4
4
|
import Input from '../Input';
|
|
5
|
-
const defaultIconRender = (visible) => visible ? openEye : eyeIcon;
|
|
5
|
+
const defaultIconRender = (visible) => (visible ? openEye : eyeIcon);
|
|
6
6
|
const actionMap = {
|
|
7
7
|
click: 'onClick',
|
|
8
8
|
hover: 'onMouseOver',
|
|
9
9
|
};
|
|
10
|
-
const Password =
|
|
10
|
+
const Password = (props) => {
|
|
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] = useState(() => visibilityControlled ? visibilityToggle.visible : false);
|
|
13
|
+
const [visible, setVisible] = useState(() => (visibilityControlled ? visibilityToggle.visible : false));
|
|
14
14
|
useEffect(() => {
|
|
15
15
|
if (visibilityControlled) {
|
|
16
16
|
setVisible(visibilityToggle.visible);
|
|
@@ -51,8 +51,8 @@ const Password = forwardRef((props, ref) => {
|
|
|
51
51
|
type: visible ? 'text' : 'password',
|
|
52
52
|
suffix: suffixIcon,
|
|
53
53
|
};
|
|
54
|
-
return
|
|
55
|
-
}
|
|
54
|
+
return React.createElement(Input, { ...omittedProps });
|
|
55
|
+
};
|
|
56
56
|
if (process.env.NODE_ENV !== 'production') {
|
|
57
57
|
Password.displayName = 'InputPassword';
|
|
58
58
|
}
|
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import React
|
|
2
|
-
import styled from 'styled-components';
|
|
1
|
+
import React from 'react';
|
|
3
2
|
import BaseInput from '../BaseInput';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
import { useInput } from '../../form/hooks/useInput';
|
|
4
|
+
const TextArea = (props) => {
|
|
5
|
+
const { field } = useInput({
|
|
6
|
+
name: props.name,
|
|
7
|
+
});
|
|
9
8
|
return (React.createElement(BaseInput, { ...props },
|
|
10
|
-
React.createElement(
|
|
11
|
-
}
|
|
9
|
+
React.createElement("textarea", { ...field, rows: 5 })));
|
|
10
|
+
};
|
|
12
11
|
if (process.env.NODE_ENV !== 'production') {
|
|
13
12
|
TextArea.displayName = 'TextArea';
|
|
14
13
|
}
|
package/dist/input/index.d.ts
CHANGED
|
@@ -1,2 +1,11 @@
|
|
|
1
|
-
export default Input;
|
|
2
1
|
import Input from './Input';
|
|
2
|
+
import TextArea from './TextArea';
|
|
3
|
+
import Password from './Password';
|
|
4
|
+
import Number from './Number';
|
|
5
|
+
type InputComponent = typeof Input & {
|
|
6
|
+
TextArea: typeof TextArea;
|
|
7
|
+
Password: typeof Password;
|
|
8
|
+
Number: typeof Number;
|
|
9
|
+
};
|
|
10
|
+
declare const EnhancedInput: InputComponent;
|
|
11
|
+
export default EnhancedInput;
|
package/dist/input/index.js
CHANGED
|
@@ -2,7 +2,9 @@ import Input from './Input';
|
|
|
2
2
|
import TextArea from './TextArea';
|
|
3
3
|
import Password from './Password';
|
|
4
4
|
import Number from './Number';
|
|
5
|
-
Input
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
// Assign the sub-components to the Input component
|
|
6
|
+
const EnhancedInput = Input;
|
|
7
|
+
EnhancedInput.TextArea = TextArea;
|
|
8
|
+
EnhancedInput.Password = Password;
|
|
9
|
+
EnhancedInput.Number = Number;
|
|
10
|
+
export default EnhancedInput;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import classNames from 'classnames';
|
|
3
|
+
import Input from 'react-phone-number-input/react-hook-form-input';
|
|
4
|
+
import useFormInstance from '../form/hooks/useFormInstance';
|
|
5
|
+
const PhoneNumber = ({ name, className, autoComplete = 'new-password' }) => {
|
|
6
|
+
const { control } = useFormInstance();
|
|
7
|
+
//! ClassName
|
|
8
|
+
const classString = classNames('phone-number-input', {
|
|
9
|
+
[className]: className,
|
|
10
|
+
});
|
|
11
|
+
return (React.createElement(Input, { name: name, country: 'AM', international: true, maxLength: 14, control: control, withCountryCallingCode: true, className: classString, autoComplete: autoComplete }));
|
|
12
|
+
};
|
|
13
|
+
export default PhoneNumber;
|
package/dist/radio/BaseRadio.js
CHANGED
|
@@ -1,16 +1,29 @@
|
|
|
1
1
|
import React, { forwardRef, useContext } from 'react';
|
|
2
|
-
import RadioGroupContext
|
|
3
|
-
import
|
|
4
|
-
|
|
2
|
+
import RadioGroupContext from './context';
|
|
3
|
+
import classNames from 'classnames';
|
|
4
|
+
import BaseCheckbox from '../checkbox/BaseCheckbox';
|
|
5
|
+
const Radio = forwardRef(({ prefixCls = 'radio', children, ...props }, forwardRef) => {
|
|
5
6
|
const groupContext = useContext(RadioGroupContext);
|
|
7
|
+
const onChange = (e) => {
|
|
8
|
+
props.onChange?.(e);
|
|
9
|
+
groupContext?.onChange?.(e);
|
|
10
|
+
};
|
|
6
11
|
const radioProps = {
|
|
7
12
|
ref: forwardRef,
|
|
8
|
-
...
|
|
13
|
+
...props,
|
|
9
14
|
};
|
|
10
15
|
if (groupContext) {
|
|
11
16
|
radioProps.ref = groupContext.forwardRef;
|
|
17
|
+
radioProps.checked = props.value === groupContext.value;
|
|
18
|
+
radioProps.onChange = onChange;
|
|
12
19
|
}
|
|
13
|
-
|
|
20
|
+
const wrapperClassString = classNames(`${prefixCls}-wrapper`, {
|
|
21
|
+
[`${prefixCls}-wrapper-checked`]: radioProps.checked,
|
|
22
|
+
[`${prefixCls}-wrapper-disabled`]: radioProps.disabled,
|
|
23
|
+
});
|
|
24
|
+
return (React.createElement("label", { className: wrapperClassString },
|
|
25
|
+
React.createElement(BaseCheckbox, { type: 'radio', prefixCls: prefixCls, ...radioProps }),
|
|
26
|
+
children !== undefined && React.createElement("span", { className: `${prefixCls}-content` }, children)));
|
|
14
27
|
});
|
|
15
28
|
if (process.env.NODE_ENV !== 'production') {
|
|
16
29
|
Radio.displayName = 'Radio';
|
package/dist/radio/Group.js
CHANGED
|
@@ -1,20 +1,37 @@
|
|
|
1
1
|
import React, { forwardRef } from 'react';
|
|
2
|
+
import { useMergedState } from '@weareconceptstudio/core';
|
|
2
3
|
import { RadioGroupContextProvider } from './context';
|
|
3
4
|
import Radio from './BaseRadio';
|
|
4
5
|
const RadioGroup = forwardRef((props, forwardRef) => {
|
|
6
|
+
const [value, setValue] = useMergedState(props.defaultValue, {
|
|
7
|
+
value: props.value,
|
|
8
|
+
});
|
|
9
|
+
const onRadioChange = (ev) => {
|
|
10
|
+
const lastValue = value;
|
|
11
|
+
const val = ev.target.value;
|
|
12
|
+
if (!('value' in props)) {
|
|
13
|
+
setValue(val);
|
|
14
|
+
}
|
|
15
|
+
const { onChange } = props;
|
|
16
|
+
if (onChange && val !== lastValue) {
|
|
17
|
+
onChange(ev);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
5
20
|
const { children, options } = props;
|
|
6
21
|
let childrenToRender = children;
|
|
7
22
|
if (options && options.length > 0) {
|
|
8
|
-
childrenToRender = options.map(option => {
|
|
23
|
+
childrenToRender = options.map((option) => {
|
|
9
24
|
if (typeof option === 'string' || typeof option === 'number') {
|
|
10
25
|
return (React.createElement(Radio, { key: option.toString(), value: option }, option));
|
|
11
26
|
}
|
|
12
27
|
return (React.createElement(Radio, { key: `radio-group-value-options-${option.value}`, value: option.value }, option.label));
|
|
13
28
|
});
|
|
14
29
|
}
|
|
15
|
-
return (React.createElement("div",
|
|
30
|
+
return (React.createElement("div", { className: 'radio-group' },
|
|
16
31
|
React.createElement(RadioGroupContextProvider, { value: {
|
|
32
|
+
onChange: onRadioChange,
|
|
17
33
|
forwardRef: forwardRef,
|
|
34
|
+
value,
|
|
18
35
|
} }, childrenToRender)));
|
|
19
36
|
});
|
|
20
37
|
if (process.env.NODE_ENV !== 'production') {
|
package/dist/radio/index.js
CHANGED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export const bottom_arrow = (React.createElement("svg", { version: '1.1', viewBox: '0 0 32 32', xmlns: 'http://www.w3.org/2000/svg' },
|
|
3
|
+
React.createElement("path", { d: 'M15.644 25.954c-0.533 0-1.067-0.178-1.422-0.711l-12.978-15.822c-0.711-0.711-0.533-1.778 0.178-2.489s1.956-0.533 2.489 0.178l11.733 14.222 12.267-14.222c0.711-0.711 1.778-0.889 2.489-0.178s0.889 1.778 0.178 2.489l-13.689 15.822c-0.178 0.356-0.711 0.711-1.244 0.711z' })));
|
|
4
|
+
export const empty = (React.createElement("svg", { version: '1.1', viewBox: '0 0 32 32', xmlns: 'http://www.w3.org/2000/svg' },
|
|
5
|
+
React.createElement("path", { d: 'M29.567 5.773v-1.153c0-0.008 0-0.017 0-0.027 0-1.603-1.298-2.903-2.9-2.907h-21.334c-1.587 0.019-2.867 1.31-2.867 2.9 0 0.012 0 0.024 0 0.035l-0-0.002v1.153c-1.414 0.303-2.459 1.538-2.467 3.019v18.414c0 0 0 0 0 0 0 1.713 1.387 3.103 3.1 3.107h25.794c1.716 0 3.107-1.391 3.107-3.107v0-18.413c-0.004-1.473-1.034-2.704-2.413-3.016l-0.021-0.004zM30.667 8.793v5.767h-1.1v-7.393c0.65 0.266 1.1 0.894 1.1 1.627v0zM5.333 3.020h21.333c0.855 0.019 1.54 0.716 1.54 1.573 0 0.010-0 0.019-0 0.028l0-0.001v9.94h-3.82c-0.998 0.001-1.848 0.64-2.162 1.531l-0.005 0.016-0.587 1.687c-0.127 0.388-0.484 0.663-0.906 0.667h-9.46c-0.422-0.003-0.78-0.279-0.905-0.66l-0.002-0.007-0.587-1.687c-0.322-0.908-1.173-1.547-2.173-1.547-0 0-0 0-0 0h-3.833v-9.94c-0-0.008-0-0.017-0-0.027 0-0.867 0.701-1.57 1.567-1.573h0zM2.467 7.167v7.393h-1.133v-5.767c0-0.733 0.45-1.361 1.088-1.622l0.012-0.004zM28.893 28.98h-25.793c-0.977-0.004-1.767-0.796-1.767-1.773 0 0 0 0 0 0v0-11.333h6.267c0.425 0 0.785 0.277 0.911 0.66l0.002 0.007 0.587 1.68c0.319 0.907 1.168 1.546 2.167 1.547h9.46c0.998-0.001 1.848-0.64 2.162-1.531l0.005-0.016 0.587-1.68c0.127-0.388 0.484-0.663 0.906-0.667h6.28v11.333c0 0.979-0.794 1.773-1.773 1.773v0z' }),
|
|
6
|
+
React.createElement("path", { d: 'M13.020 11.387c0.12 0.12 0.286 0.193 0.469 0.193 0.001 0 0.003 0 0.004 0h-0c0.182-0.001 0.347-0.074 0.467-0.193l-0 0 2.040-2.053 2.033 2c0.12 0.12 0.286 0.193 0.469 0.193 0.001 0 0.003 0 0.004 0h-0c0.182-0.001 0.347-0.074 0.467-0.193l-0 0c0.12-0.12 0.194-0.287 0.194-0.47s-0.074-0.35-0.194-0.47l0 0-2.033-2.040 2.033-2c0.143-0.123 0.233-0.304 0.233-0.506 0-0.368-0.298-0.667-0.667-0.667-0.202 0-0.383 0.090-0.506 0.232l-0.001 0.001-2.033 2.053-2.040-2c-0.123-0.143-0.304-0.233-0.506-0.233-0.368 0-0.667 0.298-0.667 0.667 0 0.202 0.090 0.383 0.232 0.506l0.001 0.001 2 2-2 2.040c-0.12 0.12-0.194 0.287-0.194 0.47s0.074 0.35 0.194 0.47l-0-0z' })));
|
package/dist/select/index.d.ts
CHANGED
package/dist/select/index.js
CHANGED
|
@@ -1,25 +1,62 @@
|
|
|
1
|
-
import React, {
|
|
2
|
-
import ReactSelect from 'react-select';
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import ReactSelect, { components } from 'react-select';
|
|
3
|
+
import classNames from 'classnames';
|
|
4
|
+
import { bottom_arrow, empty } from './icons';
|
|
5
|
+
import { useInput } from '../form/hooks/useInput';
|
|
3
6
|
import useFormInstance from '../form/hooks/useFormInstance';
|
|
4
|
-
|
|
5
|
-
|
|
7
|
+
import { useTranslation } from '@weareconceptstudio/core';
|
|
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;
|
|
10
|
+
const { translate } = useTranslation();
|
|
6
11
|
const formInstance = useFormInstance();
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
12
|
+
let selectProps = {};
|
|
13
|
+
if (formInstance == null) {
|
|
14
|
+
const [val, setVal] = useState(value);
|
|
15
|
+
selectProps = {
|
|
16
|
+
onChange: (e) => {
|
|
17
|
+
onChange && onChange(e.value);
|
|
18
|
+
setVal(e.value);
|
|
19
|
+
},
|
|
20
|
+
value: val,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
const { field } = useInput({
|
|
25
|
+
type: 'select',
|
|
26
|
+
multiple,
|
|
27
|
+
name,
|
|
28
|
+
onChange,
|
|
29
|
+
});
|
|
30
|
+
selectProps = field;
|
|
31
|
+
}
|
|
32
|
+
//! ClassName
|
|
33
|
+
const classString = classNames('react-select-container', {
|
|
34
|
+
[className]: className,
|
|
35
|
+
});
|
|
36
|
+
//! Custom Placeholder
|
|
37
|
+
const Placeholder = (props) => {
|
|
38
|
+
return React.createElement(components.Placeholder, { ...props }, translate(placeholder));
|
|
39
|
+
};
|
|
40
|
+
//! Custom DropdownIndicator
|
|
41
|
+
const DropdownIndicator = (props) => {
|
|
42
|
+
return React.createElement(components.DropdownIndicator, { ...props }, select_arrow || bottom_arrow);
|
|
43
|
+
};
|
|
44
|
+
//! Custom Components
|
|
45
|
+
const customComponents = {
|
|
46
|
+
Placeholder,
|
|
47
|
+
DropdownIndicator,
|
|
48
|
+
};
|
|
49
|
+
//! Custom No Options Message
|
|
50
|
+
const customNoOptionsMessage = () => {
|
|
51
|
+
return (React.createElement("div", { className: 'no-options-block' },
|
|
52
|
+
select_empty || empty,
|
|
53
|
+
React.createElement("p", { className: `no-options` }, 'No Data')));
|
|
54
|
+
};
|
|
55
|
+
return (React.createElement(ReactSelect
|
|
56
|
+
// unstyled
|
|
57
|
+
// menuIsOpen={true}
|
|
58
|
+
, { ...selectProps, options: options, isMulti: multiple, isLoading: loading, isDisabled: disabled, className: classString, isClearable: allowClear, isSearchable: allowSearch, components: customComponents, classNamePrefix: 'react-select', noOptionsMessage: customNoOptionsMessage, value: options.filter((opt) => (multiple ? selectProps.value.includes(opt.value) : opt.value === selectProps.value)) }));
|
|
59
|
+
};
|
|
23
60
|
if (process.env.NODE_ENV !== 'production') {
|
|
24
61
|
Select.displayName = 'Select';
|
|
25
62
|
}
|