@weareconceptstudio/form 0.0.3 → 0.0.5

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 (77) hide show
  1. package/dist/FormConfig.d.ts +5 -0
  2. package/dist/FormConfig.js +19 -0
  3. package/dist/checkbox/BaseCheckbox.d.ts +3 -0
  4. package/dist/checkbox/BaseCheckbox.js +51 -0
  5. package/dist/checkbox/index.js +15 -4
  6. package/dist/color-picker/index.d.ts +4 -1
  7. package/dist/color-picker/index.js +4 -4
  8. package/dist/date-picker/index.d.ts +6 -1
  9. package/dist/date-picker/index.js +4 -4
  10. package/dist/error-message/index.js +2 -2
  11. package/dist/form/BaseForm.d.ts +22 -20
  12. package/dist/form/BaseForm.js +38 -55
  13. package/dist/form/Builder/index.d.ts +9 -0
  14. package/dist/form/Builder/index.js +46 -0
  15. package/dist/form/Builder/style.d.ts +2 -0
  16. package/dist/form/Builder/style.js +3 -0
  17. package/dist/form/Item/index.d.ts +12 -10
  18. package/dist/form/Item/index.js +25 -18
  19. package/dist/form/hooks/rules.d.ts +3 -0
  20. package/dist/form/hooks/rules.js +44 -0
  21. package/dist/form/hooks/useEvent.d.ts +1 -0
  22. package/dist/form/hooks/useEvent.js +12 -0
  23. package/dist/form/hooks/useFormInstance.js +3 -0
  24. package/dist/form/hooks/useInput.d.ts +12 -0
  25. package/dist/form/hooks/useInput.js +46 -0
  26. package/dist/form/index.d.ts +6 -17
  27. package/dist/form/index.js +3 -2
  28. package/dist/index.d.ts +3 -0
  29. package/dist/index.js +4 -0
  30. package/dist/input/BaseInput/index.d.ts +4 -2
  31. package/dist/input/BaseInput/index.js +13 -31
  32. package/dist/input/Input.d.ts +4 -1
  33. package/dist/input/Input.js +15 -16
  34. package/dist/input/Number/index.d.ts +4 -1
  35. package/dist/input/Number/index.js +27 -4
  36. package/dist/input/Password/icons.d.ts +1 -1
  37. package/dist/input/Password/icons.js +6 -6
  38. package/dist/input/Password/index.d.ts +4 -1
  39. package/dist/input/Password/index.js +5 -5
  40. package/dist/input/TextArea/index.d.ts +4 -1
  41. package/dist/input/TextArea/index.js +8 -9
  42. package/dist/input/index.d.ts +10 -1
  43. package/dist/input/index.js +6 -4
  44. package/dist/phone-number/index.d.ts +7 -0
  45. package/dist/phone-number/index.js +13 -0
  46. package/dist/radio/BaseRadio.js +18 -5
  47. package/dist/radio/Group.js +19 -2
  48. package/dist/radio/index.js +2 -2
  49. package/dist/select/icons.d.ts +3 -0
  50. package/dist/select/icons.js +6 -0
  51. package/dist/select/index.d.ts +4 -1
  52. package/dist/select/index.js +57 -20
  53. package/dist/styles/formStyle.d.ts +2 -0
  54. package/dist/styles/formStyle.js +585 -0
  55. package/dist/styles/theme.d.ts +2 -0
  56. package/dist/styles/theme.js +113 -0
  57. package/dist/styles/variables.d.ts +2 -0
  58. package/dist/styles/variables.js +246 -0
  59. package/dist/translations/en.d.ts +52 -0
  60. package/dist/translations/en.js +52 -0
  61. package/dist/translations/index.d.ts +54 -0
  62. package/dist/translations/index.js +2 -0
  63. package/dist/upload/UploadButton/index.d.ts +3 -0
  64. package/dist/upload/UploadButton/index.js +41 -0
  65. package/dist/upload/UploadButton/style.d.ts +2 -0
  66. package/dist/upload/UploadButton/style.js +24 -0
  67. package/dist/upload/UploadList/ListItem/index.d.ts +5 -0
  68. package/dist/upload/UploadList/ListItem/index.js +11 -0
  69. package/dist/upload/UploadList/index.d.ts +3 -0
  70. package/dist/upload/UploadList/index.js +11 -0
  71. package/dist/upload/UploadList/style.d.ts +2 -0
  72. package/dist/upload/UploadList/style.js +13 -0
  73. package/dist/upload/index.d.ts +4 -1
  74. package/dist/upload/index.js +15 -5
  75. package/dist/upload/utils.d.ts +9 -0
  76. package/dist/upload/utils.js +64 -0
  77. 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, { forwardRef, useRef, cloneElement } from '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
- export const InputContainer = styled.div `
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: "button", tabIndex: -1, className: classNames(clearIconCls, {
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 && (React.createElement("span", null, 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 && (React.createElement(GroupAddonComponent, null, addonBefore)),
50
+ addonBefore && React.createElement(GroupAddonComponent, null, addonBefore),
69
51
  element,
70
- addonAfter && (React.createElement(GroupAddonComponent, null, addonAfter)))));
52
+ addonAfter && React.createElement(GroupAddonComponent, null, addonAfter))));
71
53
  }
72
- return (React.createElement(InputContainer, { className: classNames({
73
- 'base-input-container': true,
74
- [`${className}-container`]: className
75
- }) }, cloneElement(element, {
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
  }
@@ -1,3 +1,6 @@
1
1
  export default Input;
2
- declare const Input: React.ForwardRefExoticComponent<React.RefAttributes<any>>;
2
+ declare function Input(props: any): React.JSX.Element;
3
+ declare namespace Input {
4
+ let displayName: string;
5
+ }
3
6
  import React from 'react';
@@ -1,20 +1,19 @@
1
- import React, { forwardRef } from 'react';
2
- import styled from 'styled-components';
1
+ import React from 'react';
3
2
  import BaseInput from './BaseInput';
4
- const StyledInput = styled.input `
5
- box-sizing: border-box;
6
- margin: 0;
7
- list-style: none;
8
- display: inline-block;
9
- font-size: 14px;
10
- padding: 4px 11px;
11
- outline: none;
12
- `;
13
- const Input = forwardRef((props, forwardRef) => {
14
- const { autoComplete, onChange, onFocus, onBlur, onPressEnter, onKeyDown, onKeyUp, disabled, className, type = 'text', placeholder, value, } = props;
15
- return (React.createElement(BaseInput, { ...props, value: value, disabled: disabled },
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
- });
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,3 +1,6 @@
1
1
  export default Number;
2
- declare const Number: React.ForwardRefExoticComponent<React.RefAttributes<any>>;
2
+ declare function Number(props: any): React.JSX.Element;
3
+ declare namespace Number {
4
+ let displayName: string;
5
+ }
3
6
  import React from 'react';
@@ -1,8 +1,31 @@
1
- import React, { forwardRef } from 'react';
1
+ import React, { useEffect } from 'react';
2
2
  import Input from '../Input';
3
- const Number = React.forwardRef((props, forwardRef) => {
4
- return (React.createElement(Input, { ref: forwardRef, type: 'number', ...props }));
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,3 +1,3 @@
1
1
  export const eyeIcon: React.JSX.Element;
2
2
  export const openEye: React.JSX.Element;
3
- import React from "react";
3
+ import React from 'react';
@@ -1,6 +1,6 @@
1
- import React from "react";
2
- export const eyeIcon = React.createElement("svg", { version: "1.1", xmlns: "http://www.w3.org/2000/svg", width: "32", height: "32", viewBox: "0 0 32 32" },
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", xmlns: "http://www.w3.org/2000/svg", width: "32", height: "32", viewBox: "0 0 32 32" },
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" }));
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' })));
@@ -1,3 +1,6 @@
1
1
  export default Password;
2
- declare const Password: React.ForwardRefExoticComponent<React.RefAttributes<any>>;
2
+ declare function Password(props: any): React.JSX.Element;
3
+ declare namespace Password {
4
+ let displayName: string;
5
+ }
3
6
  import React from 'react';
@@ -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 = forwardRef((props, ref) => {
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 (React.createElement(Input, { ref: ref, ...omittedProps }));
55
- });
54
+ return React.createElement(Input, { ...omittedProps });
55
+ };
56
56
  if (process.env.NODE_ENV !== 'production') {
57
57
  Password.displayName = 'InputPassword';
58
58
  }
@@ -1,3 +1,6 @@
1
1
  export default TextArea;
2
- declare const TextArea: React.ForwardRefExoticComponent<React.RefAttributes<any>>;
2
+ declare function TextArea(props: any): React.JSX.Element;
3
+ declare namespace TextArea {
4
+ let displayName: string;
5
+ }
3
6
  import React from 'react';
@@ -1,14 +1,13 @@
1
- import React, { forwardRef } from 'react';
2
- import styled from 'styled-components';
1
+ import React from 'react';
3
2
  import BaseInput from '../BaseInput';
4
- const StyledTextArea = styled.textarea `
5
- font-size: 14px;
6
- padding: 4px 11px;
7
- `;
8
- const TextArea = forwardRef((props, forwardRef) => {
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(StyledTextArea, { ...forwardRef, rows: 5 })));
11
- });
9
+ React.createElement("textarea", { ...field, rows: 5 })));
10
+ };
12
11
  if (process.env.NODE_ENV !== 'production') {
13
12
  TextArea.displayName = 'TextArea';
14
13
  }
@@ -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;
@@ -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.TextArea = TextArea;
6
- Input.Password = Password;
7
- Input.Number = Number;
8
- export default Input;
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,7 @@
1
+ export default PhoneNumber;
2
+ declare function PhoneNumber({ name, className, autoComplete }: {
3
+ name: any;
4
+ className: any;
5
+ autoComplete?: string;
6
+ }): React.JSX.Element;
7
+ import React from 'react';
@@ -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;
@@ -1,16 +1,29 @@
1
1
  import React, { forwardRef, useContext } from 'react';
2
- import RadioGroupContext, { RadioOptionTypeContext } from './context';
3
- import Checkbox from "../checkbox";
4
- const Radio = forwardRef(({ children, ...restProps }, forwardRef) => {
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
- ...restProps
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
- return (React.createElement(Checkbox, { type: 'radio', ...radioProps }, children));
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';
@@ -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", null,
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') {
@@ -1,5 +1,5 @@
1
- import BaseRadio from "./BaseRadio";
2
- import RadioGroup from "./Group";
1
+ import BaseRadio from './BaseRadio';
2
+ import RadioGroup from './Group';
3
3
  const Radio = BaseRadio;
4
4
  Radio.Group = RadioGroup;
5
5
  export default Radio;
@@ -0,0 +1,3 @@
1
+ export const bottom_arrow: React.JSX.Element;
2
+ export const empty: React.JSX.Element;
3
+ import React from 'react';
@@ -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' })));
@@ -1,3 +1,6 @@
1
1
  export default Select;
2
- declare const Select: React.ForwardRefExoticComponent<React.RefAttributes<any>>;
2
+ declare function Select(props: any): React.JSX.Element;
3
+ declare namespace Select {
4
+ let displayName: string;
5
+ }
3
6
  import React from 'react';
@@ -1,25 +1,62 @@
1
- import React, { forwardRef, useState, useCallback } from '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
- const Select = forwardRef((props, forwardRef) => {
5
- const { name, multiple = false, allowClear = false, allowSearch = true, disabled = false, loading = false, options = [], } = props;
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
- const [val, setVal] = useState(formInstance.getValues()[name] || (multiple ? [] : ''));
8
- const handleChange = useCallback((newVal) => {
9
- let vals;
10
- if (multiple) {
11
- vals = newVal.map(item => item.value);
12
- }
13
- else {
14
- vals = newVal.value;
15
- }
16
- formInstance.setValue(name, vals);
17
- setVal(vals);
18
- }, [name, multiple]);
19
- return (React.createElement("div", null,
20
- React.createElement("input", { type: 'hidden', ...forwardRef }),
21
- React.createElement(ReactSelect, { options: options, onChange: handleChange, value: options.filter((opt) => multiple ? val.includes(opt.value) : opt.value === val), isMulti: multiple, isClearable: allowClear, isSearchable: allowSearch, isDisabled: disabled, isLoading: loading })));
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
  }
@@ -0,0 +1,2 @@
1
+ export default FormStyle;
2
+ declare const FormStyle: import("react").NamedExoticComponent<import("styled-components").ExecutionProps & object>;