@weareconceptstudio/form 0.0.0 → 0.0.1

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 * as React from "react";
@@ -1,7 +1,7 @@
1
1
  import * as React from 'react';
2
- const Checkbox = React.forwardRef(({ type = 'checkbox', children }, forwardRef) => {
2
+ const Checkbox = React.forwardRef(({ type = 'checkbox', children, ...restProps }, forwardRef) => {
3
3
  return (React.createElement("label", null,
4
- React.createElement("input", { type: type, ...forwardRef }),
4
+ React.createElement("input", { type: type, ...forwardRef, ...restProps }),
5
5
  children !== undefined && React.createElement("span", null, children)));
6
6
  });
7
7
  if (process.env.NODE_ENV !== 'production') {
@@ -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 * as React from "react";
@@ -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 * as React from "react";
@@ -1,5 +1,5 @@
1
1
  export default BaseForm;
2
- declare function BaseForm({ initialValues: defaultValues, values, children, onSubmit, layout, mode, reValidateMode, errors, resetOptions, criteriaMode, shouldFocusError, delayError, shouldUseNativeValidation, shouldUnregister, globalPrefixCls, theme, }: {
2
+ declare function BaseForm({ 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,7 +14,5 @@ declare function BaseForm({ initialValues: defaultValues, values, children, onSu
14
14
  delayError: any;
15
15
  shouldUseNativeValidation: any;
16
16
  shouldUnregister: any;
17
- globalPrefixCls: any;
18
- theme: any;
19
17
  }): React.JSX.Element;
20
- import * as React from 'react';
18
+ import * as React from "react";
@@ -1,7 +1,6 @@
1
1
  import * as React from 'react';
2
2
  import { FormProvider, useForm } from "react-hook-form";
3
3
  import styled from 'styled-components';
4
- import ConfigProvider from '../config-provider';
5
4
  // initialValues: object || async () => fetch('/api-endpoint')
6
5
  // values: object
7
6
  // children: React elements
@@ -47,7 +46,7 @@ const StyledForm = styled.form `
47
46
  margin-bottom: 24px;
48
47
  }
49
48
  `;
50
- const BaseForm = ({ initialValues: defaultValues, values, children, onSubmit, layout = 'vertical', mode = 'onChange', reValidateMode, errors, resetOptions, criteriaMode, shouldFocusError, delayError, shouldUseNativeValidation, shouldUnregister, globalPrefixCls, theme, }) => {
49
+ const BaseForm = ({ initialValues: defaultValues, values, children, onSubmit, layout = 'vertical', mode = 'onChange', reValidateMode, errors, resetOptions, criteriaMode, shouldFocusError, delayError, shouldUseNativeValidation, shouldUnregister, }) => {
51
50
  const methods = useForm({
52
51
  defaultValues,
53
52
  values,
@@ -61,8 +60,7 @@ const BaseForm = ({ initialValues: defaultValues, values, children, onSubmit, la
61
60
  shouldUseNativeValidation,
62
61
  shouldUnregister,
63
62
  });
64
- return (React.createElement(ConfigProvider, { globalPrefixCls: globalPrefixCls, theme: theme },
65
- React.createElement(FormProvider, { ...methods },
66
- React.createElement(StyledForm, { onSubmit: methods.handleSubmit(onSubmit), className: layout }, children))));
63
+ return (React.createElement(FormProvider, { ...methods },
64
+ React.createElement(StyledForm, { onSubmit: methods.handleSubmit(onSubmit), className: layout }, children)));
67
65
  };
68
66
  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
- let displayName: string;
9
+ const displayName: string;
10
10
  }
11
- import React from 'react';
11
+ import React from "react";
@@ -4,7 +4,7 @@ import { useFormContext } from "react-hook-form";
4
4
  //* Components
5
5
  import ErrorMessage from '../../error-message';
6
6
  const FormItem = ({ label, name, children, rules = {} }) => {
7
- const { register, getValues, setValue } = useFormContext();
7
+ const { register, getValues } = useFormContext();
8
8
  const innerRef = register(name, rules);
9
9
  return (React.createElement("div", { className: "form-item" },
10
10
  React.createElement("div", { className: "form-item-row" },
@@ -12,8 +12,6 @@ const FormItem = ({ label, name, children, rules = {} }) => {
12
12
  React.createElement("label", { htmlFor: name }, label)),
13
13
  React.createElement("div", { className: 'form-item-control' }, React.cloneElement(children, {
14
14
  ref: innerRef,
15
- getValues,
16
- setValue,
17
15
  name,
18
16
  value: getValues()[name]
19
17
  })),
@@ -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, globalPrefixCls, theme, }: {
2
+ declare const 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,6 +14,4 @@ declare const Form: ({ initialValues: defaultValues, values, children, onSubmit,
14
14
  delayError: any;
15
15
  shouldUseNativeValidation: any;
16
16
  shouldUnregister: any;
17
- globalPrefixCls: any;
18
- theme: any;
19
17
  }) => import("react").JSX.Element;
@@ -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 * as React from "react";
4
4
  declare const BaseInput: React.ForwardRefExoticComponent<React.RefAttributes<any>>;
@@ -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 * as React from "react";
@@ -11,8 +11,8 @@ const StyledInput = styled.input `
11
11
  outline: none;
12
12
  `;
13
13
  const Input = React.forwardRef((props, forwardRef) => {
14
- const { autoComplete, onChange, onFocus, onBlur, onPressEnter, onKeyDown, onKeyUp, disabled, className, type = 'text', value, } = props;
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
- React.createElement(StyledInput, { type: type, autoComplete: autoComplete, onChange: onChange, onFocus: onFocus, onBlur: onBlur, onPressEnter: onPressEnter, onKeyDown: onKeyDown, onKeyUp: onKeyUp, disabled: disabled, className: className, ...forwardRef })));
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
18
  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 * as React from "react";
@@ -1,6 +1,6 @@
1
1
  import React from "react";
2
- export const eyeIcon = React.createElement("svg", { viewBox: "64 64 896 896", focusable: "false", "data-icon": "eye-invisible", width: "1em", height: "1em", fill: "currentColor", "aria-hidden": "true" },
3
- React.createElement("path", { d: "M942.2 486.2Q889.47 375.11 816.7 305l-50.88 50.88C807.31 395.53 843.45 447.4 874.7 512 791.5 684.2 673.4 766 512 766q-72.67 0-133.87-22.38L323 798.75Q408 838 512 838q288.3 0 430.2-300.3a60.29 60.29 0 000-51.5zm-63.57-320.64L836 122.88a8 8 0 00-11.32 0L715.31 232.2Q624.86 186 512 186q-288.3 0-430.2 300.3a60.3 60.3 0 000 51.5q56.69 119.4 136.5 191.41L112.48 835a8 8 0 000 11.31L155.17 889a8 8 0 0011.31 0l712.15-712.12a8 8 0 000-11.32zM149.3 512C232.6 339.8 350.7 258 512 258c54.54 0 104.13 9.36 149.12 28.39l-70.3 70.3a176 176 0 00-238.13 238.13l-83.42 83.42C223.1 637.49 183.3 582.28 149.3 512zm246.7 0a112.11 112.11 0 01146.2-106.69L401.31 546.2A112 112 0 01396 512z" }),
4
- React.createElement("path", { d: "M508 624c-3.46 0-6.87-.16-10.25-.47l-52.82 52.82a176.09 176.09 0 00227.42-227.42l-52.82 52.82c.31 3.38.47 6.79.47 10.25a111.94 111.94 0 01-112 112z" }));
5
- export const openEye = React.createElement("svg", { viewBox: "64 64 896 896", focusable: "false", "data-icon": "eye", width: "1em", height: "1em", fill: "currentColor", "aria-hidden": "true" },
6
- React.createElement("path", { d: "M942.2 486.2C847.4 286.5 704.1 186 512 186c-192.2 0-335.4 100.5-430.2 300.3a60.3 60.3 0 000 51.5C176.6 737.5 319.9 838 512 838c192.2 0 335.4-100.5 430.2-300.3 7.7-16.2 7.7-35 0-51.5zM512 766c-161.3 0-279.4-81.8-362.7-254C232.6 339.8 350.7 258 512 258c161.3 0 279.4 81.8 362.7 254C791.5 684.2 673.4 766 512 766zm-4-430c-97.2 0-176 78.8-176 176s78.8 176 176 176 176-78.8 176-176-78.8-176-176-176zm0 288c-61.9 0-112-50.1-112-112s50.1-112 112-112 112 50.1 112 112-50.1 112-112 112z" }));
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,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 * as React from "react";
@@ -1,5 +1,5 @@
1
1
  import * as React from 'react';
2
- import { omit } from '@weareconceptstudio/utils';
2
+ import { omit } from '@weareconceptstudio/core';
3
3
  import { eyeIcon, openEye } from './icons';
4
4
  import Input from '../Input';
5
5
  const defaultIconRender = (visible) => visible ? openEye : eyeIcon;
@@ -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 * as React from "react";
@@ -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 * as React from "react";
@@ -5,13 +5,12 @@ const Radio = React.forwardRef(({ children, ...restProps }, forwardRef) => {
5
5
  const groupContext = React.useContext(RadioGroupContext);
6
6
  const radioProps = {
7
7
  ref: forwardRef,
8
+ ...restProps
8
9
  };
9
10
  if (groupContext) {
10
11
  radioProps.ref = groupContext.forwardRef;
11
12
  }
12
- return (React.createElement("label", null,
13
- React.createElement(Checkbox, { type: 'radio', ...radioProps }),
14
- children !== undefined ? React.createElement("span", null, children) : null));
13
+ return (React.createElement(Checkbox, { type: 'radio', ...radioProps }, children));
15
14
  });
16
15
  if (process.env.NODE_ENV !== 'production') {
17
16
  Radio.displayName = 'Radio';
@@ -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 * as React from "react";
@@ -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 * as React from "react";
6
6
  declare const RadioGroupContext: React.Context<any>;
@@ -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 * as React from "react";
@@ -1,8 +1,10 @@
1
1
  import * as React from 'react';
2
2
  import ReactSelect from 'react-select';
3
+ import useFormInstance from '../form/hooks/useFormInstance';
3
4
  const Select = React.forwardRef((props, forwardRef) => {
4
- const { name, getValues, setValue, multiple = false, allowClear = false, allowSearch = true, disabled = false, loading = false, options = [], } = props;
5
- const [val, setVal] = React.useState(getValues()[name] || (multiple ? [] : ''));
5
+ const { name, multiple = false, allowClear = false, allowSearch = true, disabled = false, loading = false, options = [], } = props;
6
+ const formInstance = useFormInstance();
7
+ const [val, setVal] = React.useState(formInstance.getValues()[name] || (multiple ? [] : ''));
6
8
  const handleChange = React.useCallback((newVal) => {
7
9
  let vals;
8
10
  if (multiple) {
@@ -11,7 +13,7 @@ const Select = React.forwardRef((props, forwardRef) => {
11
13
  else {
12
14
  vals = newVal.value;
13
15
  }
14
- setValue(name, vals);
16
+ formInstance.setValue(name, vals);
15
17
  setVal(vals);
16
18
  }, [name, multiple]);
17
19
  return (React.createElement("div", null,
@@ -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 * as React from "react";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@weareconceptstudio/form",
3
- "version": "0.0.0",
3
+ "version": "0.0.1",
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/utils": "*",
22
+ "@weareconceptstudio/core": "0.0.0",
23
23
  "classnames": "2.5.1",
24
24
  "react": "^18.3.1",
25
25
  "react-dom": "^18.3.1",
@@ -1,2 +0,0 @@
1
- export declare function getStyle(globalPrefixCls: string, theme: any): string;
2
- export declare function registerTheme(globalPrefixCls: any, theme: any): void;
@@ -1,25 +0,0 @@
1
- import { warning, canUseDom, updateCSS } from '@weareconceptstudio/utils';
2
- export function getStyle(globalPrefixCls = 'cs-form', theme) {
3
- const variables = {};
4
- const fillColor = (colorVal, type) => {
5
- variables[`${type}-color`] = colorVal;
6
- };
7
- if (theme.primaryColor) {
8
- fillColor(theme.primaryColor, 'primary');
9
- }
10
- const cssList = Object.keys(variables).map((key) => `--${globalPrefixCls}-${key}: ${variables[key]};`);
11
- return `
12
- :root {
13
- ${cssList.join('\n')}
14
- }
15
- `.trim();
16
- }
17
- export function registerTheme(globalPrefixCls, theme) {
18
- const style = getStyle(globalPrefixCls, theme);
19
- if (canUseDom()) {
20
- updateCSS(style, 'dynamic-theme');
21
- }
22
- else {
23
- warning(false, 'SSR do not support dynamic theme with css variables.');
24
- }
25
- }
@@ -1,12 +0,0 @@
1
- import * as React from 'react';
2
- export declare const ConfigContext: React.Context<{}>;
3
- interface ConfigProviderProps {
4
- globalPrefixCls?: string;
5
- theme?: object;
6
- children: React.ReactNode;
7
- }
8
- declare const ConfigProvider: {
9
- (props: ConfigProviderProps): React.JSX.Element;
10
- displayName: string;
11
- };
12
- export default ConfigProvider;
@@ -1,20 +0,0 @@
1
- import * as React from 'react';
2
- import { registerTheme } from './cssVariables';
3
- export const ConfigContext = React.createContext({});
4
- const ProviderChildren = (props) => {
5
- const { globalPrefixCls = 'cs-form', theme, children } = props;
6
- if (theme) {
7
- registerTheme(globalPrefixCls, theme);
8
- }
9
- return (React.createElement(ConfigContext.Provider, { value: {
10
- globalPrefixCls,
11
- theme
12
- } }, children));
13
- };
14
- const ConfigProvider = (props) => {
15
- return React.createElement(ProviderChildren, { ...props });
16
- };
17
- if (process.env.NODE_ENV !== 'production') {
18
- ConfigProvider.displayName = 'ConfigProvider';
19
- }
20
- export default ConfigProvider;