@weareconceptstudio/form 0.0.1 → 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.
@@ -1,3 +1,3 @@
1
1
  export default Checkbox;
2
2
  declare const Checkbox: React.ForwardRefExoticComponent<React.RefAttributes<any>>;
3
- import * as React from "react";
3
+ import React from 'react';
@@ -1,5 +1,5 @@
1
- import * as React from 'react';
2
- const Checkbox = React.forwardRef(({ type = 'checkbox', children, ...restProps }, forwardRef) => {
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,3 +1,3 @@
1
1
  export default ColorPicker;
2
2
  declare const ColorPicker: React.ForwardRefExoticComponent<React.RefAttributes<any>>;
3
- import * as React from "react";
3
+ import React from 'react';
@@ -1,5 +1,5 @@
1
- import * as React from 'react';
2
- const ColorPicker = React.forwardRef((props, forwardRef) => {
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,3 +1,3 @@
1
1
  export default DatePicker;
2
2
  declare const DatePicker: React.ForwardRefExoticComponent<React.RefAttributes<any>>;
3
- import * as React from "react";
3
+ import React from 'react';
@@ -1,9 +1,9 @@
1
- import * as React from 'react';
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 = React.forwardRef(({ type = 'date' }, forwardRef) => {
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') {
@@ -7,3 +7,6 @@ declare function ErrorMessage({ as, errors, name, message, render, ...rest }: {
7
7
  message: any;
8
8
  render: any;
9
9
  }): any;
10
+ declare namespace ErrorMessage {
11
+ let displayName: string;
12
+ }
@@ -1,4 +1,4 @@
1
- import * as React from 'react';
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 React.isValidElement(as)
14
- ? React.cloneElement(as, props)
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
- : React.createElement(as || React.Fragment, props);
20
+ : createElement(as || Fragment, props);
21
21
  };
22
+ if (process.env.NODE_ENV !== 'production') {
23
+ ErrorMessage.displayName = 'ErrorMessage';
24
+ }
22
25
  export default ErrorMessage;
@@ -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
- import * as React from "react";
18
+ declare namespace BaseForm {
19
+ let displayName: string;
20
+ }
21
+ import React from 'react';
@@ -1,4 +1,4 @@
1
- import * as React from 'react';
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;
@@ -6,6 +6,6 @@ declare function FormItem({ label, name, children, rules }: {
6
6
  rules?: {};
7
7
  }): React.JSX.Element;
8
8
  declare namespace FormItem {
9
- const displayName: string;
9
+ let displayName: string;
10
10
  }
11
- import React from "react";
11
+ import React from 'react';
@@ -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' }, React.cloneElement(children, {
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: 'span' }))));
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';
@@ -1,4 +1,4 @@
1
- import * as React from 'react';
1
+ import React from 'react';
2
2
  import { useFormContext } from 'react-hook-form';
3
3
  export default function useFormInstance() {
4
4
  const methods = useFormContext();
@@ -1,5 +1,5 @@
1
1
  export default Form;
2
- declare const Form: ({ initialValues: defaultValues, values, children, onSubmit, layout, mode, reValidateMode, errors, resetOptions, criteriaMode, shouldFocusError, delayError, shouldUseNativeValidation, shouldUnregister, }: {
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
- }) => import("react").JSX.Element;
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 * as React from "react";
3
+ import React from 'react';
4
4
  declare const BaseInput: React.ForwardRefExoticComponent<React.RefAttributes<any>>;
@@ -1,6 +1,6 @@
1
- import * as React from 'react';
1
+ import React, { forwardRef, useRef, cloneElement } from 'react';
2
2
  import styled from 'styled-components';
3
- import clsx from 'classnames';
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 = React.forwardRef((props, forwardRef) => {
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 || 'span';
25
- const GroupWrapperComponent = components?.groupWrapper || 'span';
26
- const WrapperComponent = components?.wrapper || 'span';
27
- const GroupAddonComponent = components?.groupAddon || 'span';
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 = React.useRef(null);
30
- const groupRef = React.useRef(null);
31
- let element = React.cloneElement(inputElement, {
32
- // ...props,
33
- className: `base-input`
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: clsx(clearIconCls, {
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, null, React.cloneElement(element, {
71
- className: clsx(element.props?.className, className) || null,
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') {
@@ -1,3 +1,3 @@
1
1
  export default Input;
2
2
  declare const Input: React.ForwardRefExoticComponent<React.RefAttributes<any>>;
3
- import * as React from "react";
3
+ import React from 'react';
@@ -1,4 +1,4 @@
1
- import * as React from 'react';
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 = React.forwardRef((props, forwardRef) => {
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,3 +1,3 @@
1
1
  export default Number;
2
2
  declare const Number: React.ForwardRefExoticComponent<React.RefAttributes<any>>;
3
- import * as React from "react";
3
+ import React from 'react';
@@ -1,4 +1,4 @@
1
- import * as React from 'react';
1
+ import React, { forwardRef } from 'react';
2
2
  import Input from '../Input';
3
3
  const Number = React.forwardRef((props, forwardRef) => {
4
4
  return (React.createElement(Input, { ref: forwardRef, type: 'number', ...props }));
@@ -1,3 +1,3 @@
1
1
  export default Password;
2
2
  declare const Password: React.ForwardRefExoticComponent<React.RefAttributes<any>>;
3
- import * as React from "react";
3
+ import React from 'react';
@@ -1,4 +1,4 @@
1
- import * as React from 'react';
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 = React.forwardRef((props, ref) => {
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] = React.useState(() => visibilityControlled ? visibilityToggle.visible : false);
14
- React.useEffect(() => {
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 React.cloneElement(React.isValidElement(icon) ? icon : React.createElement("span", null, icon), iconProps);
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,3 +1,3 @@
1
1
  export default TextArea;
2
2
  declare const TextArea: React.ForwardRefExoticComponent<React.RefAttributes<any>>;
3
- import * as React from "react";
3
+ import React from 'react';
@@ -1,11 +1,11 @@
1
- import * as React from 'react';
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 = React.forwardRef((props, forwardRef) => {
8
+ const TextArea = forwardRef((props, forwardRef) => {
9
9
  return (React.createElement(BaseInput, { ...props },
10
10
  React.createElement(StyledTextArea, { ...forwardRef, rows: 5 })));
11
11
  });
@@ -1,2 +1,2 @@
1
1
  export default Input;
2
- import Input from "./Input";
2
+ import Input from './Input';
@@ -1,3 +1,3 @@
1
1
  export default Radio;
2
2
  declare const Radio: React.ForwardRefExoticComponent<React.RefAttributes<any>>;
3
- import * as React from "react";
3
+ import React from 'react';
@@ -1,8 +1,8 @@
1
- import * as React from 'react';
1
+ import React, { forwardRef, useContext } from 'react';
2
2
  import RadioGroupContext, { RadioOptionTypeContext } from './context';
3
3
  import Checkbox from "../checkbox";
4
- const Radio = React.forwardRef(({ children, ...restProps }, forwardRef) => {
5
- const groupContext = React.useContext(RadioGroupContext);
4
+ const Radio = forwardRef(({ children, ...restProps }, forwardRef) => {
5
+ const groupContext = useContext(RadioGroupContext);
6
6
  const radioProps = {
7
7
  ref: forwardRef,
8
8
  ...restProps
@@ -1,3 +1,3 @@
1
1
  export default RadioGroup;
2
2
  declare const RadioGroup: React.ForwardRefExoticComponent<React.RefAttributes<any>>;
3
- import * as React from "react";
3
+ import React from 'react';
@@ -1,7 +1,7 @@
1
- import * as React from 'react';
1
+ import React, { forwardRef } from 'react';
2
2
  import { RadioGroupContextProvider } from './context';
3
3
  import Radio from './BaseRadio';
4
- const RadioGroup = React.forwardRef((props, forwardRef) => {
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;
@@ -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 * as React from "react";
5
+ import React from 'react';
6
6
  declare const RadioGroupContext: React.Context<any>;
@@ -1,6 +1,6 @@
1
- import * as React from 'react';
2
- const RadioGroupContext = React.createContext(null);
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 = React.createContext(null);
5
+ export const RadioOptionTypeContext = createContext(null);
6
6
  export const RadioOptionTypeContextProvider = RadioOptionTypeContext.Provider;
@@ -1,3 +1,3 @@
1
1
  export default Select;
2
2
  declare const Select: React.ForwardRefExoticComponent<React.RefAttributes<any>>;
3
- import * as React from "react";
3
+ import React from 'react';
@@ -1,11 +1,11 @@
1
- import * as React from 'react';
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 = React.forwardRef((props, forwardRef) => {
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] = React.useState(formInstance.getValues()[name] || (multiple ? [] : ''));
8
- const handleChange = React.useCallback((newVal) => {
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);
@@ -1,3 +1,3 @@
1
1
  export default Upload;
2
2
  declare const Upload: React.ForwardRefExoticComponent<React.RefAttributes<any>>;
3
- import * as React from "react";
3
+ import React from 'react';
@@ -1,6 +1,9 @@
1
- import * as React from 'react';
2
- const Upload = React.forwardRef((props, forwardRef) => {
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@weareconceptstudio/form",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "description": "Concept Studio Form",
5
5
  "author": "Concept Studio",
6
6
  "license": "ISC",
@@ -19,7 +19,7 @@
19
19
  "watch": "tsc -m es6 --watch"
20
20
  },
21
21
  "dependencies": {
22
- "@weareconceptstudio/core": "0.0.0",
22
+ "@weareconceptstudio/core": "*",
23
23
  "classnames": "2.5.1",
24
24
  "react": "^18.3.1",
25
25
  "react-dom": "^18.3.1",