mui-design-system 0.0.15 → 0.0.16

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 (29) hide show
  1. package/dist/components/custom-mobile-date-picker/CustomMobileDatePicker.js +2 -5
  2. package/dist/components/input-list/Form.d.ts +21 -0
  3. package/dist/components/input-list/Form.js +18 -0
  4. package/dist/components/input-list/UseFormInput.d.ts +2 -2
  5. package/dist/components/input-list/checkbox-list/CheckboxList.d.ts +19 -0
  6. package/dist/components/input-list/checkbox-list/CheckboxList.js +30 -0
  7. package/dist/components/input-list/components/UFAutoComplete.js +15 -26
  8. package/dist/components/input-list/components/UFCheckbox.d.ts +7 -7
  9. package/dist/components/input-list/components/UFCheckbox.js +14 -17
  10. package/dist/components/input-list/components/UFCurrency.d.ts +3 -3
  11. package/dist/components/input-list/components/UFCurrency.js +43 -46
  12. package/dist/components/input-list/components/UFDatePicker.js +7 -4
  13. package/dist/components/input-list/components/UFMultiCheckbox.d.ts +3 -3
  14. package/dist/components/input-list/components/UFMultiCheckbox.js +13 -9
  15. package/dist/components/input-list/components/UFMultiSelect.d.ts +3 -3
  16. package/dist/components/input-list/components/UFMultiSelect.js +41 -28
  17. package/dist/components/input-list/components/UFRadio.d.ts +5 -5
  18. package/dist/components/input-list/components/UFRadio.js +15 -12
  19. package/dist/components/input-list/components/UFSelect.d.ts +5 -5
  20. package/dist/components/input-list/components/UFSelect.js +17 -25
  21. package/dist/components/input-list/components/UFSwitch.js +2 -2
  22. package/dist/components/input-list/components/UFTextArea.js +5 -2
  23. package/dist/components/input-list/components/UFTextField.d.ts +5 -3
  24. package/dist/components/input-list/components/UFTextField.js +17 -40
  25. package/dist/components/input-list/components/UFUploader.d.ts +3 -3
  26. package/dist/components/input-list/components/UFUploader.js +18 -16
  27. package/dist/context/FormContext.d.ts +16 -0
  28. package/dist/context/FormContext.js +8 -0
  29. package/package.json +1 -1
@@ -35,7 +35,7 @@ const createDateObject = (date, lang) => {
35
35
  }),
36
36
  });
37
37
  };
38
- const MobileDatePicker = ({ form, name, defaultValue, label, sx, rules, readonly, disabled, placeholder, error, itemProps, props, helperText, variant = 'outlined', withoutHelperText, inputLabelMode, }) => {
38
+ const MobileDatePicker = ({ form, name, defaultValue, label, rules, readonly, disabled, placeholder, error, itemProps, props, helperText, variant = 'outlined', withoutHelperText, inputLabelMode, }) => {
39
39
  const lang = document.documentElement.lang;
40
40
  const [open, setOpen] = useState(false);
41
41
  const defaultValueDate = defaultValue
@@ -80,10 +80,7 @@ const MobileDatePicker = ({ form, name, defaultValue, label, sx, rules, readonly
80
80
  form
81
81
  .register(name, { ...rules })
82
82
  .onBlur({ target: { current: selectedDate.toDate() } });
83
- }, value: selectedDate?.format('YYYY/MM/DD'), defaultValue: selectedDate?.format('YYYY/MM/DD'), variant: variant, fullWidth: true, id: field?.name, error: !!error, onClick: !(disabled || readonly) && handleTextFieldClick, onTouchEnd: !(disabled || readonly) && handleTextFieldClick, placeholder: placeholder, sx: [
84
- ...(Array.isArray(sx) ? sx : [sx]),
85
- { userSelect: disabled || readonly ? 'none' : 'all' },
86
- ], helperText: getHelperText(), "aria-readonly": readonly, disabled: disabled, inputProps: { readOnly: readonly }, InputProps: {
83
+ }, value: selectedDate?.format('YYYY/MM/DD'), defaultValue: selectedDate?.format('YYYY/MM/DD'), variant: variant, fullWidth: true, id: field?.name, error: !!error, onClick: !(disabled || readonly) && handleTextFieldClick, onTouchEnd: !(disabled || readonly) && handleTextFieldClick, placeholder: placeholder, helperText: getHelperText(), "aria-readonly": readonly, disabled: disabled, inputProps: { readOnly: readonly }, InputProps: {
87
84
  endAdornment: (_jsx(InputAdornment, { position: 'end', sx: {
88
85
  '& .MuiInputAdornment-positionStart': {
89
86
  marginTop: '0 important',
@@ -0,0 +1,21 @@
1
+ import { FC } from "react";
2
+ import { UseFormReturn } from "react-hook-form";
3
+ import { GridProps } from "@mui/material/Grid";
4
+ import { TypographyProps } from "@mui/material/Typography";
5
+ import { TFormSchema, TInputLabelMode } from "./type";
6
+ import { TextFieldProps } from "@mui/material/TextField";
7
+ interface FormProps {
8
+ schema: TFormSchema;
9
+ form: UseFormReturn<any, any, any>;
10
+ gridContainerProps?: GridProps;
11
+ gridItemProps?: GridProps;
12
+ itemProps?: any;
13
+ labelsProps?: Partial<TypographyProps<"label", {}>> | undefined;
14
+ hideRequiredStar?: boolean;
15
+ inputLabelMode?: TInputLabelMode;
16
+ inputVariants?: TextFieldProps["variant"];
17
+ withoutHelperText?: boolean;
18
+ disabled?: boolean;
19
+ }
20
+ declare const Form: FC<FormProps>;
21
+ export default Form;
@@ -0,0 +1,18 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { isValidElement } from "react";
3
+ //------------------------------------------------------------------------
4
+ //@Mui
5
+ import Box from "@mui/material/Box";
6
+ import Grid from "@mui/material/Grid";
7
+ import Stack from "@mui/material/Stack";
8
+ import Typography from "@mui/material/Typography";
9
+ import UseFormInput from "./UseFormInput";
10
+ import { deepMerge, result } from "../../methods/general";
11
+ const Form = ({ schema, form, gridItemProps, gridContainerProps, labelsProps, itemProps, hideRequiredStar = false, inputLabelMode = "static", inputVariants = "outlined", withoutHelperText, disabled, }) => {
12
+ return (_jsx(Grid, { container: true, columnSpacing: 4, rowSpacing: 0, rowGap: 2, alignItems: "flex-start", ...gridContainerProps, children: schema?.map((inputProp) => (_jsxs(Grid, { item: true, xs: 4, width: "100%", height: "auto", position: "relative", ...deepMerge(gridItemProps, inputProp.gridItemProp), children: [inputLabelMode === "static" && inputProp.type !== "checkbox" && (_jsx(Box, { display: "flex", children: _jsx(Typography, { flexGrow: 1, width: 0, component: "label", display: "inline-block", mb: 2, htmlFor: inputProp.name, color: result(form?.formState?.errors, `${inputProp.name}`)
13
+ ? "error"
14
+ : "text.16", noWrap: true, title: !isValidElement(inputProp?.label)
15
+ ? inputProp?.label?.toString() || ""
16
+ : "", ...deepMerge(labelsProps, inputProp.labelProps), children: _jsxs(Stack, { direction: "row", children: [inputProp.label, inputProp.rules?.required && !hideRequiredStar && (_jsx(Typography, { component: "span", color: "error", fontSize: 12, children: "*" }))] }) }) })), _jsx(UseFormInput, { form: form, itemProps: itemProps, error: result(form?.formState?.errors, `${inputProp.name}`), inputLabelMode: inputLabelMode, inputVariants: inputVariants, withoutHelperText: withoutHelperText, disabled: disabled, ...inputProp })] }, inputProp.name))) }));
17
+ };
18
+ export default Form;
@@ -1,8 +1,8 @@
1
1
  import { FC } from 'react';
2
2
  import { UseFormReturn } from 'react-hook-form';
3
- import { IUseFormInput } from './type';
3
+ import { TSchema } from './type';
4
4
  import { TextFieldProps } from '@mui/material/TextField';
5
- type IUseFormInputProps = IUseFormInput & {
5
+ type IUseFormInputProps = TSchema & {
6
6
  form: UseFormReturn<any>;
7
7
  error?: any;
8
8
  inputVariants?: TextFieldProps['variant'];
@@ -0,0 +1,19 @@
1
+ import { FC } from 'react';
2
+ import { CheckboxProps, StackProps } from '@mui/material';
3
+ import { FormControlLabelProps } from '@mui/material/FormControlLabel';
4
+ import { IFormOption } from '../type';
5
+ export interface ICheckboxValue {
6
+ label: string;
7
+ value: string | number;
8
+ }
9
+ export interface CheckboxListProps {
10
+ options: IFormOption[];
11
+ value?: ICheckboxValue[];
12
+ onChange: (values: ICheckboxValue[]) => void;
13
+ multiple?: boolean;
14
+ stackProps?: StackProps;
15
+ checkboxProps?: CheckboxProps;
16
+ formControlLabelProps?: Omit<FormControlLabelProps, 'label' | 'control'>;
17
+ }
18
+ declare const CheckboxList: FC<CheckboxListProps>;
19
+ export default CheckboxList;
@@ -0,0 +1,30 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { FormControlLabel, Stack, } from '@mui/material';
3
+ import Checkbox from '@mui/material/Checkbox';
4
+ const CheckboxList = ({ options = [], value = [], onChange, multiple, checkboxProps, stackProps, formControlLabelProps, }) => {
5
+ // console.log('values', values)
6
+ const handleChange = (event, changedValue) => {
7
+ const newValues = [...value];
8
+ if (multiple) {
9
+ if (event.target.checked) {
10
+ newValues.push(changedValue);
11
+ onChange(newValues);
12
+ }
13
+ else {
14
+ const index = newValues.findIndex((v) => v.value === changedValue.value);
15
+ newValues.splice(index, 1);
16
+ onChange(newValues);
17
+ }
18
+ }
19
+ else {
20
+ if (event.target.checked) {
21
+ onChange([changedValue]);
22
+ }
23
+ else {
24
+ onChange([]);
25
+ }
26
+ }
27
+ };
28
+ return (_jsx(Stack, { ...stackProps, children: options.map((option) => (_jsx(FormControlLabel, { control: _jsx(Checkbox, { ...checkboxProps, checked: value?.findIndex((v) => v.value === option.value) > -1, onChange: (e) => handleChange(e, option) }), label: option.label, slotProps: { typography: option?.labelProp }, ...formControlLabelProps }, option.value))) }));
29
+ };
30
+ export default CheckboxList;
@@ -1,20 +1,10 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import { useRef, useMemo } from 'react';
3
2
  import { Controller } from 'react-hook-form';
4
- import { CustomAutoComplete } from '../../index';
5
- const UFAutoComplete = ({ form, label, error, placeholder, sx, rules, disabled, name, options, defaultValue, readonly, props, helperText, isLoading = false, onSearch, inputLabelMode, variant, itemProps, onReachEnd, }) => {
6
- //Cache result options for search and integration across the pages
7
- const cachedOptionsRef = useRef([]);
8
- const cachedOptions = useMemo(() => {
9
- options?.forEach((option) => {
10
- if (!cachedOptionsRef.current.find((opt) => opt.value === option?.value)
11
- ?.value) {
12
- cachedOptionsRef.current.push(option);
13
- }
14
- });
15
- return cachedOptionsRef.current;
16
- }, [options?.length]);
17
- //________________________________________________________________
3
+ import CustomAutoComplete from "../../custom-auto-complete/CustomAutoComplete";
4
+ import { deepMerge } from "../../../methods/general";
5
+ import { useFormContext } from "../../../context/FormContext";
6
+ const UFAutoComplete = ({ form, label, error, placeholder, rules, disabled, name, options, defaultValue, readonly, props, helperText, isLoading = false, inputLabelMode, variant, itemProps, onReachEnd }) => {
7
+ const { theme } = useFormContext();
18
8
  // Convert defaultValue if it's an array of strings
19
9
  const convertDefaultValue = (defaultValue, options) => {
20
10
  // Check if options are undefined or null, return an empty array or default value
@@ -23,30 +13,29 @@ const UFAutoComplete = ({ form, label, error, placeholder, sx, rules, disabled,
23
13
  }
24
14
  // Convert value to corresponding object with label and value
25
15
  if (Array.isArray(defaultValue)) {
26
- return defaultValue
27
- .map((val) => {
28
- const matchedOption = options.find((option) => option.value === val);
16
+ return defaultValue.map(val => {
17
+ const matchedOption = options.find(option => option.value === val);
29
18
  return matchedOption ? matchedOption : null;
30
- })
31
- .filter(Boolean);
19
+ }).filter(Boolean);
32
20
  }
33
21
  else {
34
- const matchedOption = options.find((option) => option.value === defaultValue);
22
+ const matchedOption = options.find(option => option.value === defaultValue);
35
23
  return matchedOption ? matchedOption : null;
36
24
  }
37
25
  };
38
- //________________________________________________________________
39
- return (_jsx(Controller, { control: form?.control, name: name, rules: { ...rules }, defaultValue: convertDefaultValue(defaultValue, cachedOptions) || [], render: ({ field }) => (_jsx(CustomAutoComplete, { ...field, label: label, hideLabel: true, placeholder: typeof label === 'string' ? label : placeholder, inputLabelMode: inputLabelMode, helperText: error?.message ?? helperText, options: cachedOptions || [], selectedOptions: field.value, value: convertDefaultValue(field?.value, cachedOptions), sx: sx, validation: { isInvalid: !!error, message: error?.message }, disabled: disabled, id: name, readOnly: readonly, variant: variant, isLoading: isLoading, onReachEnd: onReachEnd, onSearch: onSearch, onChange: (e, newValue) => {
26
+ return (_jsx(Controller, { control: form?.control, name: name, rules: { ...rules }, defaultValue: convertDefaultValue(defaultValue, options), render: ({ field }) => (_jsx(CustomAutoComplete, { ...field, label: label, hideLabel: true, placeholder: typeof label === "string" ? label : placeholder, inputLabelMode: inputLabelMode, helperText: error?.message ?? helperText, options: options || [], selectedOptions: field.value, value: convertDefaultValue(field?.value, options), sx: { width: '100%' }, inputMaxHeight: '120px', limitTags: 2, validation: { isInvalid: !!error, message: error?.message }, disabled: disabled, id: name, readOnly: readonly, variant: variant, isLoading: isLoading, isOptionEqualToValue: (option, value) => {
27
+ return option?.value === value?.value;
28
+ }, onReachEnd: onReachEnd, onChange: (_, newValue) => {
40
29
  const isMultiple = Array.isArray(newValue);
41
30
  if (isMultiple) {
42
31
  // Handle multiple selection
43
- const valuesArray = newValue.map((item) => item.value);
32
+ const valuesArray = newValue.map(item => item.value);
44
33
  field.onChange(valuesArray);
45
34
  }
46
35
  else {
47
36
  // Handle single selection
48
- field.onChange(newValue ? newValue.value : '');
37
+ field.onChange(newValue ? newValue.value : "");
49
38
  }
50
- }, ...props, ...itemProps })) }));
39
+ }, ...deepMerge(theme?.autoComplete?.autoCompleteProps, itemProps, props) })) }));
51
40
  };
52
41
  export default UFAutoComplete;
@@ -1,11 +1,11 @@
1
- import { FC } from 'react';
2
- import { ICheckboxForm } from '../type';
3
- import { CheckboxProps } from '@mui/material';
4
- import { UseFormReturn } from 'react-hook-form';
5
- import { SwitchBaseProps } from '@mui/material/internal/SwitchBase';
6
- import { TypographyProps } from '@mui/material/Typography';
1
+ import { FC } from "react";
2
+ import { ICheckboxForm } from "../type";
3
+ import { CheckboxProps } from "@mui/material";
4
+ import { UseFormReturn } from "react-hook-form";
5
+ import { SwitchBaseProps } from "@mui/material/internal/SwitchBase";
6
+ import { TypographyProps } from "@mui/material/Typography";
7
7
  export interface ICustomCheckboxProps {
8
- inputProps: SwitchBaseProps['inputProps'];
8
+ inputProps: SwitchBaseProps["inputProps"];
9
9
  slotProps: {
10
10
  typography?: TypographyProps;
11
11
  };
@@ -1,24 +1,21 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import Checkbox from '@mui/material/Checkbox';
3
- import FormControl from '@mui/material/FormControl';
4
- import { Controller } from 'react-hook-form';
5
- import FormControlLabel from '@mui/material/FormControlLabel';
6
- import Typography from '@mui/material/Typography';
7
- const UFCheckbox = ({ form, name, label, rules, disabled, sx, error, helperText, withoutHelperText, props, ...otherProps }) => {
8
- return (_jsx(Controller, { control: form?.control, name: name, rules: { ...rules }, render: ({ field: { onChange, name, value = false } }) => (_jsxs(FormControl, { sx: { display: 'flex', ...(disabled && { filter: 'contrast(0.3)' }) }, children: [_jsx(FormControlLabel, { sx: [
9
- ...(Array.isArray(sx) ? sx : [sx]),
10
- { pointerEvents: otherProps.readonly ? 'none' : 'all' },
11
- ], slotProps: {
2
+ import Checkbox from "@mui/material/Checkbox";
3
+ import FormControl from "@mui/material/FormControl";
4
+ import { Controller } from "react-hook-form";
5
+ import FormControlLabel from "@mui/material/FormControlLabel";
6
+ import Typography from "@mui/material/Typography";
7
+ import { useFormContext } from "../../../context/FormContext";
8
+ import { deepMerge } from "../../../methods/general";
9
+ const UFCheckbox = ({ form, name, label, rules, error, helperText, withoutHelperText, props, disabled, itemProps, formControlLabelProps, }) => {
10
+ const { theme } = useFormContext();
11
+ return (_jsx(Controller, { control: form?.control, name: name, rules: { ...rules }, render: ({ field: { onChange, name, value = false } }) => (_jsxs(FormControl, { sx: { display: "flex", ...(disabled && { filter: "contrast(0.3)" }) }, children: [_jsx(FormControlLabel, { slotProps: {
12
12
  typography: {
13
- variant: 'caption3',
14
13
  ...props?.slotProps?.typography,
15
14
  },
16
- }, control: _jsx(Checkbox, { color: 'primary', checked: value, ...(!otherProps.readonly && {
17
- onChange: onChange,
18
- }), disabled: disabled, name: name, inputProps: props?.inputProps, ...props?.checkBoxProps }), label: label }), !withoutHelperText && (_jsx(Typography, { variant: 'caption3', sx: {
15
+ }, control: _jsx(Checkbox, { color: "primary", checked: value, onChange: onChange, disabled: disabled, name: name, ...deepMerge(theme?.checkbox?.checkboxProps, itemProps, props) }), label: label, ...deepMerge(theme?.checkbox?.formControlLabelProps, formControlLabelProps) }), !withoutHelperText && (_jsx(Typography, { sx: {
19
16
  height: 23,
20
- width: 'max-content',
21
- color: error ? 'error.4' : 'text.primary',
22
- }, children: error?.message ?? helperText ?? ' ' }))] })) }));
17
+ width: "max-content",
18
+ color: error ? "error.4" : "text.primary",
19
+ }, children: error?.message ?? helperText ?? " " }))] })) }));
23
20
  };
24
21
  export default UFCheckbox;
@@ -1,6 +1,6 @@
1
- import { FC } from 'react';
2
- import { UseFormReturn } from 'react-hook-form';
3
- import { ICurrencyForm } from '../type';
1
+ import { FC } from "react";
2
+ import { UseFormReturn } from "react-hook-form";
3
+ import { ICurrencyForm } from "../type";
4
4
  type Props = ICurrencyForm & {
5
5
  form: UseFormReturn<any>;
6
6
  error: any;
@@ -1,50 +1,47 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import { Controller } from 'react-hook-form';
3
- import CustomNumericInput from '../../custom-input/CustomNumericInput';
4
- import { useTheme } from '@mui/material';
5
- import Typography from '@mui/material/Typography';
6
- const UfCurrency = ({ form, name, defaultValue, sx, rules, readonly, disabled, placeholder, error, itemProps, props, helperText, withoutHelperText, variant,
7
- // currencyIcon = <SvgDollarCircle primarycolor={"inherit"} />,
8
- currencyIcon = _jsx(Typography, { children: "\u062A\u0648\u0645\u0627\u0646" }), inputLabelMode, label, }) => {
2
+ import { Controller } from "react-hook-form";
3
+ import CustomNumericInput from "../../custom-input/CustomNumericInput";
4
+ import { useTheme } from "@mui/material";
5
+ import Typography from "@mui/material/Typography";
6
+ import { useFormContext } from "../../../context/FormContext";
7
+ import { deepMerge } from "../../../methods/general";
8
+ const UfCurrency = ({ form, name, defaultValue, rules, readonly, disabled, placeholder, error, itemProps, props, helperText, withoutHelperText, variant, currencyIcon = _jsx(Typography, { children: "\u062A\u0648\u0645\u0627\u0646" }), inputLabelMode, label, }) => {
9
+ const { theme } = useFormContext();
9
10
  const { direction } = useTheme();
10
- return (_jsx(Controller, { control: form?.control, name: name, rules: { ...rules }, defaultValue: defaultValue, render: ({ field: { onChange, name, value, onBlur } }) => {
11
- return (_jsx(CustomNumericInput, { value: value, onChange: (value) => {
12
- onChange({
13
- target: { value: value },
14
- });
15
- }, onBlur: onBlur, fullWidth: true, id: name, error: !!error, placeholder: placeholder, disabled: disabled, variant: variant, ...(inputLabelMode === 'static' && { hiddenLabel: true }), ...(inputLabelMode === 'relative' && { label: label }), sx: {
16
- ...sx,
17
- '.MuiInputBase-root': {
18
- px: (theme) => theme.spacing(2),
19
- },
20
- ...(direction === 'rtl'
21
- ? {
22
- '.MuiFilledInput-input': {
23
- py: '16px !important',
24
- textAlign: 'right !important',
25
- pr: '3px !important',
26
- },
27
- }
28
- : {
29
- '.MuiFilledInput-input': {
30
- pl: '3px !important',
31
- },
32
- }),
33
- backgroundColor: readonly ? 'background.paper' : 'unset',
34
- borderRadius: '8px',
35
- pointerEvents: readonly ? 'none' : 'unset',
36
- '& .MuiOutlinedInput-input': {
37
- backgroundColor: readonly ? 'background.paper' : 'unset',
38
- color: readonly ? 'text.secondary' : 'unset',
39
- },
40
- }, helperText: withoutHelperText
41
- ? undefined
42
- : error?.message ?? helperText ?? ' ', "aria-readonly": readonly, inputProps: { readOnly: readonly }, ...itemProps, ...props, InputProps: {
43
- sx: { gap: 2 },
44
- endAdornment: props?.currencyIcon ?? currencyIcon,
45
- ...itemProps?.InputProps,
46
- ...props?.InputProps,
47
- } }));
48
- } }));
11
+ const currencyMergedProps = deepMerge(theme?.currency?.currencyProps, itemProps, props);
12
+ return (_jsx(Controller, { control: form?.control, name: name, rules: { ...rules }, defaultValue: defaultValue, render: ({ field: { onChange, name, value, onBlur } }) => (_jsx(CustomNumericInput, { value: value, onChange: (value) => {
13
+ onChange({
14
+ target: { value: value },
15
+ });
16
+ }, onBlur: onBlur, fullWidth: true, id: name, error: !!error, placeholder: placeholder, disabled: disabled, variant: variant, ...(inputLabelMode === "static" && { hiddenLabel: true }), ...(inputLabelMode === "relative" && { label: label }), helperText: withoutHelperText ? undefined : error?.message ?? helperText ?? " ", "aria-readonly": readonly, inputProps: { readOnly: readonly }, ...currencyMergedProps, sx: {
17
+ ".MuiInputBase-root": {
18
+ px: (theme) => theme.spacing(2),
19
+ },
20
+ ...(direction === "rtl"
21
+ ? {
22
+ ".MuiFilledInput-input": {
23
+ py: "16px !important",
24
+ textAlign: "right !important",
25
+ pr: "3px !important",
26
+ },
27
+ }
28
+ : {
29
+ ".MuiFilledInput-input": {
30
+ pl: "3px !important",
31
+ },
32
+ }),
33
+ backgroundColor: readonly ? "background.paper" : "unset",
34
+ borderRadius: "8px",
35
+ pointerEvents: readonly ? "none" : "unset",
36
+ "& .MuiOutlinedInput-input": {
37
+ backgroundColor: readonly ? "background.paper" : "unset",
38
+ color: readonly ? "text.secondary" : "unset",
39
+ },
40
+ ...currencyMergedProps.sx
41
+ }, InputProps: {
42
+ sx: { gap: 2 },
43
+ endAdornment: props?.currencyIcon ?? currencyIcon,
44
+ ...currencyMergedProps.InputProps
45
+ } })) }));
49
46
  };
50
47
  export default UfCurrency;
@@ -1,14 +1,17 @@
1
1
  import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  import { Controller } from 'react-hook-form';
3
- import { CustomDatePicker } from '../../index';
4
- const UFDatePicker = ({ form, rules, disabled, defaultValue, name, label, error, readonly, helperText, withoutHelperText, variant, inputLabelMode = 'static', props, sx, itemProps, }) => {
3
+ import CustomDatePicker from "../../custom-date-picker/CustomDatePicker";
4
+ import { useFormContext } from "../../../context/FormContext";
5
+ import { deepMerge } from "../../../methods/general";
6
+ const UFDatePicker = ({ form, rules, disabled, defaultValue, name, label, error, withoutHelperText, variant, inputLabelMode = 'static', props, itemProps, readonly }) => {
7
+ const { theme } = useFormContext();
5
8
  return (
6
9
  //ToDo date picker issue on grid should be resolved
7
10
  _jsx(Controller, { control: form?.control, name: name, rules: { ...rules }, defaultValue: defaultValue, render: ({ field: { onChange, name, value } }) => (_jsx(_Fragment, { children: _jsx(CustomDatePicker, { readOnly: readonly, textFieldProps: {
8
11
  id: name,
9
12
  variant: variant,
10
13
  ...itemProps,
11
- sx: { width: '100%', ...sx },
12
- }, error: error, disabled: disabled, value: value, onChange: onChange, inputLabelMode: inputLabelMode, withoutHelperText: withoutHelperText, label: label, ...props }) })) }));
14
+ sx: { width: '100%' },
15
+ }, error: error, disabled: disabled, value: value, onChange: onChange, inputLabelMode: inputLabelMode, withoutHelperText: withoutHelperText, label: label, ...deepMerge(theme?.datePicker?.datePickerProps, props) }) })) }));
13
16
  };
14
17
  export default UFDatePicker;
@@ -1,6 +1,6 @@
1
- import { FC } from 'react';
2
- import { UseFormReturn } from 'react-hook-form';
3
- import { IMultiCheckboxForm } from '../type';
1
+ import { FC } from "react";
2
+ import { UseFormReturn } from "react-hook-form";
3
+ import { IMultiCheckboxForm } from "../type";
4
4
  type UFMultiCheckboxProps = IMultiCheckboxForm & {
5
5
  form: UseFormReturn<any>;
6
6
  error: any;
@@ -1,13 +1,17 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import FormControl from '@mui/material/FormControl';
3
- import Typography from '@mui/material/Typography';
4
- import { Controller } from 'react-hook-form';
5
- import CheckboxList from '../../checkbox-list/CheckboxList';
6
- const UFMultiCheckbox = ({ form, error, rules, disabled, withoutHelperText, helperText, name, options, multiple, props, itemProps, readonly, }) => {
7
- return (_jsx(Controller, { control: form?.control, name: name, rules: { ...rules }, render: ({ field }) => (_jsxs(FormControl, { sx: { display: 'flex', ...(disabled && { filter: 'contrast(0.3)' }) }, children: [_jsx(CheckboxList, { readonly: readonly, multiple: multiple, options: options, ...itemProps, ...props, ...field }), !withoutHelperText && (_jsx(Typography, { variant: 'caption3', sx: {
2
+ import FormControl from "@mui/material/FormControl";
3
+ import Typography from "@mui/material/Typography";
4
+ import { Controller } from "react-hook-form";
5
+ import CheckboxList from "../checkbox-list/CheckboxList";
6
+ import { useFormContext } from "../../../context/FormContext";
7
+ import { deepMerge } from "../../../methods/general";
8
+ const UFMultiCheckbox = ({ form, error, rules, disabled, withoutHelperText, helperText, name, options, multiple, props, itemProps, }) => {
9
+ const { theme } = useFormContext();
10
+ const multiCheckboxMergedProps = deepMerge(theme?.multiCheckbox?.multiCheckboxProps, itemProps, props);
11
+ return (_jsx(Controller, { control: form?.control, name: name, rules: { ...rules }, render: ({ field }) => (_jsxs(FormControl, { sx: { display: "flex", ...(disabled && { filter: "contrast(0.3)" }) }, children: [_jsx(CheckboxList, { multiple: multiple, options: options, ...field, ...multiCheckboxMergedProps }), !withoutHelperText && (_jsx(Typography, { sx: {
8
12
  height: 23,
9
- width: 'max-content',
10
- color: error ? 'error.4' : 'text.primary',
11
- }, children: error?.message ?? helperText ?? ' ' }))] })) }));
13
+ width: "max-content",
14
+ color: error ? "error.4" : "text.primary",
15
+ }, children: error?.message ?? helperText ?? " " }))] })) }));
12
16
  };
13
17
  export default UFMultiCheckbox;
@@ -1,6 +1,6 @@
1
- import { FC } from 'react';
2
- import { UseFormReturn } from 'react-hook-form';
3
- import { IMultiSelectForm } from '../type';
1
+ import { FC } from "react";
2
+ import { UseFormReturn } from "react-hook-form";
3
+ import { IMultiSelectForm } from "../type";
4
4
  type Props = IMultiSelectForm & {
5
5
  form: UseFormReturn<any>;
6
6
  error: any;
@@ -1,43 +1,56 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { useState } from "react";
2
3
  //@3rd Party
3
- import { Controller } from 'react-hook-form';
4
+ import { Controller } from "react-hook-form";
4
5
  //----------------------------------------------------------------------------------
5
6
  //@Mui
6
- import Stack from '@mui/material/Stack';
7
- import MenuItem from '@mui/material/MenuItem';
8
- import InputLabel from '@mui/material/InputLabel';
9
- import ListItemText from '@mui/material/ListItemText';
10
- import FormControl from '@mui/material/FormControl';
11
- import Typography from '@mui/material/Typography';
12
- import TextField from '@mui/material/TextField';
13
- const UFMultiSelect = ({ form, error, placeholder, sx, rules, disabled, name, options, defaultValue = [], readonly, props, itemProps, helperText, variant = 'outlined', withoutHelperText, inputLabelMode, label, }) => {
7
+ import Stack from "@mui/material/Stack";
8
+ import MenuItem from "@mui/material/MenuItem";
9
+ import InputLabel from "@mui/material/InputLabel";
10
+ import ListItemText from "@mui/material/ListItemText";
11
+ import FormControl from "@mui/material/FormControl";
12
+ import Typography from "@mui/material/Typography";
13
+ import TextField from "@mui/material/TextField";
14
+ import { useFormContext } from "../../../context/FormContext";
15
+ import { deepMerge } from "../../../methods/general";
16
+ const UFMultiSelect = ({ form, error, placeholder, rules, disabled, name, options, defaultValue, readonly, props, itemProps, helperText, variant = "outlined", withoutHelperText, inputLabelMode, label, }) => {
17
+ const { theme } = useFormContext();
18
+ const [optionValues, setOptionValues] = useState([]);
14
19
  const selectedItems = (value) => options?.find((option) => option?.value === value)?.label;
15
- return (_jsx(Controller, { control: form?.control, name: name, rules: { ...rules }, render: ({ field }) => (_jsx(_Fragment, { children: _jsxs(FormControl, { fullWidth: true, children: [placeholder && (_jsx(InputLabel, { id: 'simple-select-label', sx: {
16
- '&.MuiInputLabel-root[data-shrink=true]': { opacity: '0%' },
17
- '&.MuiInputLabel-root[data-shrink=false]': {
18
- opacity: '100%',
20
+ return (_jsx(Controller, { control: form?.control, name: name, rules: { ...rules }, defaultValue: defaultValue, render: ({ field }) => (_jsx(_Fragment, { children: _jsxs(FormControl, { fullWidth: true, children: [placeholder && (_jsx(InputLabel, { id: "simple-select-label", sx: {
21
+ "&.MuiInputLabel-root[data-shrink=true]": { opacity: "0%" },
22
+ "&.MuiInputLabel-root[data-shrink=false]": {
23
+ opacity: "100%",
19
24
  },
20
- }, children: placeholder })), _jsx(TextField, { select: true, ...(inputLabelMode === 'static' && { hiddenLabel: true }), ...(inputLabelMode === 'relative' && { label: label }), ...field, fullWidth: true, id: name, disabled: disabled, variant: variant, error: !!error, SelectProps: {
25
+ }, children: placeholder })), _jsx(TextField, { select: true, ...(inputLabelMode === "static" && { hiddenLabel: true }), ...(inputLabelMode === "relative" && { label: label }), ...field, fullWidth: true, value: optionValues, id: name, disabled: disabled, defaultValue: defaultValue, variant: variant, error: !!error, SelectProps: {
21
26
  multiple: true,
22
- defaultValue: [defaultValue].flat(),
23
- renderValue: (selected) => (_jsx(Stack, { gap: 1, height: '100%', alignItems: 'center', direction: 'row', flexWrap: 'wrap', children: _jsx(Typography, { variant: 'caption3', children: selected
27
+ value: optionValues,
28
+ renderValue: (selected) => (_jsx(Stack, { gap: 1, height: "100%", alignItems: "center", direction: "row", flexWrap: "wrap", sx: {
29
+ ...(optionValues.includes(selected) && {
30
+ backgroundColor: "background.main",
31
+ }),
32
+ }, children: _jsx(Typography, { children: selected
24
33
  .map((value) => selectedItems(value))
25
- .join(' , ') }) })),
34
+ .join(",") }) })),
26
35
  }, inputProps: { readOnly: readonly }, helperText: withoutHelperText
27
36
  ? undefined
28
- : error?.message ?? helperText ?? ' ', sx: {
29
- '.MuiInputBase-root': {
37
+ : error?.message ?? helperText ?? " ", sx: {
38
+ ".MuiInputBase-root": {
30
39
  paddingRight: (theme) => theme.spacing(2),
31
40
  },
32
- ...sx,
33
- pointerEvents: readonly ? 'none' : 'unset',
34
- backgroundColor: readonly ? 'background.paper' : 'unset',
35
- '& .MuiOutlinedInput-input.MuiSelect-select': {
36
- backgroundColor: readonly ? 'background.paper' : 'unset',
37
- color: readonly ? 'text.5' : 'unset',
38
- },
39
- }, ...props, ...itemProps, children: options?.map(({ label, value }) => {
40
- return (_jsx(MenuItem, { value: value, id: label, sx: { transition: 'all 0.2s' }, children: _jsx(ListItemText, { primary: label, color: 'red', sx: { flex: 'none', mx: '4px' }, disableTypography: true }) }, value));
41
+ // ...sx,
42
+ // pointerEvents: readonly ? "none" : "unset",
43
+ // backgroundColor: readonly ? "background.paper" : "unset",
44
+ // "& .MuiOutlinedInput-input.MuiSelect-select": {
45
+ // backgroundColor: readonly ? "background.paper" : "unset",
46
+ // color: readonly ? "text.5" : "unset",
47
+ // },
48
+ }, ...deepMerge(theme?.multiSelect?.multiSelectProps, itemProps, props), children: options?.map(({ label, value }) => {
49
+ return (_jsx(MenuItem, { value: value, id: label, sx: { transition: "all 0.2s" }, onClick: () => {
50
+ !optionValues.includes(value)
51
+ ? setOptionValues([value, ...optionValues])
52
+ : setOptionValues(optionValues.filter((optionValue) => optionValue !== value));
53
+ }, children: _jsx(ListItemText, { primary: label, color: "red", sx: { flex: "none", mx: "4px" }, disableTypography: true }) }, value));
41
54
  }) })] }) })) }));
42
55
  };
43
56
  export default UFMultiSelect;
@@ -1,9 +1,9 @@
1
- import { FC } from 'react';
2
- import { IRadioForm } from '../type';
3
- import { UseFormReturn } from 'react-hook-form';
4
- type Props = IRadioForm & {
1
+ import { FC } from "react";
2
+ import { IRadioForm } from "../type";
3
+ import { UseFormReturn } from "react-hook-form";
4
+ type TRadioProps = IRadioForm & {
5
5
  form: UseFormReturn<any>;
6
6
  error: any;
7
7
  };
8
- declare const UFRadio: FC<Props>;
8
+ declare const UFRadio: FC<TRadioProps>;
9
9
  export default UFRadio;
@@ -1,16 +1,19 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { Controller } from 'react-hook-form';
3
- import FormControlLabel from '@mui/material/FormControlLabel';
4
- import FormControl from '@mui/material/FormControl';
5
- import Typography from '@mui/material/Typography';
6
- import RadioGroup from '@mui/material/RadioGroup';
7
- import Radio from '@mui/material/Radio';
8
- const UFRadio = ({ form, name, rules, disabled, sx, defaultValue, options, error, helperText, withoutHelperText, props, label, labelProps, inputLabelMode, }) => {
9
- return (_jsx(Controller, { control: form?.control, name: name, rules: { ...rules }, defaultValue: defaultValue, render: ({ field: { onChange, name, value } }) => (_jsxs(FormControl, { sx: { display: 'block' }, children: [inputLabelMode === 'relative' && (_jsx(Typography, { ...labelProps, children: label })), _jsx(RadioGroup, { row: true, "aria-labelledby": 'demo-row-radio-buttons-group-label', name: 'row-radio-buttons-group', onChange: onChange, value: value, sx: { gap: 5 }, children: options?.map((option) => (_jsx(FormControlLabel, { disabled: disabled, value: option.value, sx: sx, control: _jsx(Radio, { ...props, checked: value === option.value }), label: _jsx(Typography, { fontWeight: 400, fontSize: 12, ...option.labelProp, children: option.label }) }, option.value))) }), !withoutHelperText && (_jsx(Typography, { variant: 'caption3', sx: {
10
- display: 'block',
2
+ import { Controller } from "react-hook-form";
3
+ import FormControlLabel from "@mui/material/FormControlLabel";
4
+ import FormControl from "@mui/material/FormControl";
5
+ import Typography from "@mui/material/Typography";
6
+ import RadioGroup from "@mui/material/RadioGroup";
7
+ import Radio from "@mui/material/Radio";
8
+ import { useFormContext } from "../../../context/FormContext";
9
+ import { deepMerge } from "../../../methods/general";
10
+ const UFRadio = ({ form, name, rules, disabled, defaultValue, options, error, helperText, withoutHelperText, label, labelProps, inputLabelMode, formControlLabelProps, radioProps, itemProps, radioGroupProps }) => {
11
+ const { theme } = useFormContext();
12
+ return (_jsx(Controller, { control: form?.control, name: name, rules: { ...rules }, defaultValue: defaultValue, render: ({ field: { onChange, value } }) => (_jsxs(FormControl, { sx: { display: "block" }, children: [inputLabelMode === "relative" && (_jsx(Typography, { ...labelProps, children: label })), _jsx(RadioGroup, { row: true, "aria-labelledby": "demo-row-radio-buttons-group-label", name: "row-radio-buttons-group", onChange: onChange, value: value, sx: { gap: 5 }, ...deepMerge(theme?.radio?.radioGroupProps, radioGroupProps), children: options?.map((option) => (_jsx(FormControlLabel, { disabled: disabled, value: option.value, control: _jsx(Radio, { ...deepMerge(theme?.radio?.radioProps, itemProps, radioProps), checked: value === option.value }), label: _jsx(Typography, { fontWeight: 400, fontSize: 12, ...option.labelProp, children: option.label }), ...deepMerge(theme?.radio?.formControlLabelProps, formControlLabelProps) }, option.value))) }), !withoutHelperText && (_jsx(Typography, { sx: {
13
+ display: "block",
11
14
  height: 23,
12
- width: 'max-content',
13
- color: error ? 'error.4' : 'text.primary',
14
- }, children: error?.message ?? helperText ?? ' ' }))] })) }));
15
+ width: "max-content",
16
+ color: error ? "error.4" : "text.primary",
17
+ }, children: error?.message ?? helperText ?? " " }))] })) }));
15
18
  };
16
19
  export default UFRadio;
@@ -1,9 +1,9 @@
1
- import { FC } from 'react';
2
- import { UseFormReturn } from 'react-hook-form';
3
- import { ISelectForm } from '../type';
4
- type Props = ISelectForm & {
1
+ import { FC } from "react";
2
+ import { UseFormReturn } from "react-hook-form";
3
+ import { ISelectForm } from "../type";
4
+ type TSelectProps = ISelectForm & {
5
5
  form: UseFormReturn<any>;
6
6
  error: any;
7
7
  };
8
- declare const UFSelect: FC<Props>;
8
+ declare const UFSelect: FC<TSelectProps>;
9
9
  export default UFSelect;
@@ -1,27 +1,19 @@
1
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
- import { useState } from 'react';
3
- import FormControl from '@mui/material/FormControl';
4
- import { InputLabel, TextField } from '@mui/material';
5
- import MenuItem from '@mui/material/MenuItem';
6
- import { Controller } from 'react-hook-form';
7
- const UFSelect = ({ form, error, sx, rules, disabled, name, options, defaultValue = '', readonly, props, itemProps, helperText, variant = 'outlined', withoutHelperText, inputLabelMode, label, placeholder, }) => {
8
- const [open, setOpen] = useState(false);
9
- return (_jsx(Controller, { control: form?.control, name: name, rules: { ...rules }, defaultValue: defaultValue, render: ({ field }) => (_jsx(_Fragment, { children: _jsxs(FormControl, { fullWidth: true, variant: variant, children: [inputLabelMode === 'static' && !!placeholder && !field.value && (_jsx(InputLabel, { id: 'simple-select-label', error: !!error, sx: {
10
- top: itemProps?.size === 'small' || props?.size === 'small'
11
- ? '-6px'
12
- : 0,
13
- color: '#d3d1d1',
14
- fontSize: 14,
15
- fontWeight: 400,
16
- }, children: placeholder })), _jsx(TextField, { SelectProps: {
17
- open,
18
- }, select: true, ...field, error: !!error, value: field.value, id: name, fullWidth: true, ...(inputLabelMode === 'static' && { hiddenLabel: true }), ...(inputLabelMode === 'relative' && { label: label }), disabled: disabled, defaultValue: defaultValue, variant: variant, placeholder: 'saasdlasd', helperText: withoutHelperText
19
- ? undefined
20
- : error?.message ?? helperText ?? ' ', onClick: () => setOpen((prev) => !prev), InputProps: { readOnly: readonly }, sx: {
21
- '.MuiInputBase-root': {
22
- paddingRight: (theme) => theme.spacing(2),
23
- },
24
- ...sx,
25
- }, ...itemProps, ...props, children: options?.map((option) => (_jsx(MenuItem, { value: option.value, id: option.value, children: option.label }, option.value))) })] }) })) }));
1
+ import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import FormControl from "@mui/material/FormControl";
3
+ import { TextField } from "@mui/material";
4
+ import MenuItem from "@mui/material/MenuItem";
5
+ import { Controller } from "react-hook-form";
6
+ import { useFormContext } from "../../../context/FormContext";
7
+ import { deepMerge } from "../../../methods/general";
8
+ const UFSelect = ({ form, error, rules, disabled, name, options, defaultValue = "", readonly, props, itemProps, helperText, variant = "outlined", withoutHelperText, inputLabelMode, label, }) => {
9
+ const { theme } = useFormContext() || {};
10
+ return (_jsx(Controller, { control: form?.control, name: name, rules: { ...rules }, defaultValue: defaultValue, render: ({ field }) => (_jsx(_Fragment, { children: _jsx(FormControl, { fullWidth: true, variant: variant, children: _jsx(TextField, { select: true, ...field, error: !!error, value: field.value, id: name, fullWidth: true, ...inputLabelMode === "static" && { hiddenLabel: true }, ...inputLabelMode === "relative" && { label: label }, disabled: disabled, defaultValue: defaultValue, variant: variant, helperText: withoutHelperText
11
+ ? undefined
12
+ : error?.message ?? helperText ?? " ", InputProps: { readOnly: readonly
13
+ }, sx: {
14
+ ".MuiInputBase-root": {
15
+ paddingRight: (theme) => theme.spacing(2),
16
+ },
17
+ }, ...deepMerge(theme?.select?.selectProps, itemProps, props), children: options?.map((option) => (_jsx(MenuItem, { value: option.value, id: option.value, children: option.label }, option.value))) }) }) })) }));
26
18
  };
27
19
  export default UFSelect;
@@ -4,11 +4,11 @@ import { Controller } from 'react-hook-form';
4
4
  import FormControl from '@mui/material/FormControl';
5
5
  import FormControlLabel from '@mui/material/FormControlLabel';
6
6
  import Typography from '@mui/material/Typography';
7
- const UFSwitch = ({ form, name, label, rules, disabled, sx, error, defaultValue, helperText, withoutHelperText, props, }) => {
7
+ const UFSwitch = ({ form, name, label, rules, disabled, error, defaultValue, helperText, withoutHelperText, props, }) => {
8
8
  return (_jsx(Controller, { control: form?.control, name: name, rules: { ...rules }, defaultValue: defaultValue, render: ({ field: { onChange, name, value = false } }) => (_jsxs(FormControl, { sx: {
9
9
  display: 'flex',
10
10
  ...(disabled && { filter: 'contrast(0.3)' }),
11
- }, children: [_jsx(FormControlLabel, { sx: { gap: 2, ...sx }, slotProps: {
11
+ }, children: [_jsx(FormControlLabel, { slotProps: {
12
12
  typography: {
13
13
  variant: 'caption3',
14
14
  ...props?.slotProps?.typography,
@@ -1,9 +1,12 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { Controller } from 'react-hook-form';
3
3
  import TextField from '@mui/material/TextField';
4
- const UFTextArea = ({ form, name, type, defaultValue, sx, rules, readonly, disabled, placeholder, error, props, helperText, variant = 'outlined', withoutHelperText, inputLabelMode, label, }) => {
4
+ import { useFormContext } from "../../../context/FormContext";
5
+ import { deepMerge } from "../../../methods/general";
6
+ const UFTextArea = ({ form, name, type, defaultValue, rules, readonly, disabled, placeholder, error, props, helperText, variant = 'outlined', withoutHelperText, inputLabelMode, label, }) => {
7
+ const { theme } = useFormContext() || {};
5
8
  return (_jsx(Controller, { control: form?.control, name: name, rules: { ...rules }, defaultValue: defaultValue || '', render: ({ field: { name, value } }) => (_jsx(TextField, { ...form?.register(name, {
6
9
  ...rules,
7
- }), type: type, value: value, ...(inputLabelMode === 'static' && { hiddenLabel: true }), ...(inputLabelMode === 'relative' && { label: label }), fullWidth: true, multiline: true, rows: 3, id: name, error: !!error, placeholder: placeholder, helperText: withoutHelperText ? undefined : error?.message ?? helperText ?? ' ', sx: sx, "aria-readonly": readonly, disabled: disabled, variant: variant, inputProps: { readOnly: readonly }, ...props })) }));
10
+ }), type: type, value: value, ...(inputLabelMode === 'static' && { hiddenLabel: true }), ...(inputLabelMode === 'relative' && { label: label }), fullWidth: true, multiline: true, rows: 3, id: name, error: !!error, placeholder: placeholder, helperText: withoutHelperText ? undefined : error?.message ?? helperText ?? ' ', "aria-readonly": readonly, disabled: disabled, variant: variant, inputProps: { readOnly: readonly }, ...deepMerge(theme?.textArea?.textAreaProps, props) })) }));
8
11
  };
9
12
  export default UFTextArea;
@@ -1,9 +1,11 @@
1
- import { FC } from 'react';
2
- import { UseFormReturn } from 'react-hook-form';
3
- import { ITextFieldForm } from '../type';
1
+ import { FC } from "react";
2
+ import { UseFormReturn } from "react-hook-form";
3
+ import { ITextFieldForm } from "../type";
4
4
  type Props = ITextFieldForm & {
5
5
  form: UseFormReturn<any>;
6
6
  error: any;
7
7
  };
8
+ export declare const p2e: (s: string) => boolean;
9
+ export declare const checkIfNumber: (value: string) => boolean;
8
10
  declare const UFTextField: FC<Props>;
9
11
  export default UFTextField;
@@ -1,52 +1,29 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import { useState } from 'react';
3
- import { Controller } from 'react-hook-form';
4
- import TextField from '@mui/material/TextField';
5
- import SvgEye from '../../../icons/Eye';
6
- import SvgEyeSlash from '../../../icons/EyeSlash';
7
- import IconButton from '@mui/material/IconButton';
8
- const UFTextField = ({ form, name, type, defaultValue, label, sx, rules, readonly, disabled, placeholder, error, itemProps, props, helperText, variant = 'outlined', withoutHelperText, inputLabelMode, }) => {
2
+ import { Controller } from "react-hook-form";
3
+ import TextField from "@mui/material/TextField";
4
+ import { useFormContext } from '../../../context/FormContext';
5
+ import { deepMerge } from '../../../methods/general';
6
+ export const p2e = (s) => /^[0-9 | \u06F0-\u06F9\s][.\d | \u06F0-\u06F9\s]*(,\d+)?$/g.test(s);
7
+ export const checkIfNumber = (value) => {
8
+ const charLength = value.length;
9
+ return !charLength || p2e(value);
10
+ };
11
+ const UFTextField = ({ form, name, type = 'text', defaultValue, label, rules, readonly, disabled, placeholder, error, itemProps, props, helperText, variant = "outlined", withoutHelperText, inputLabelMode, }) => {
12
+ const { theme } = useFormContext();
13
+ const themeProp = theme?.[type];
14
+ const textFieldMergedProps = deepMerge(themeProp, itemProps, props);
9
15
  const handleKeyDown = (e, onChange) => {
10
16
  const value = e?.target?.value;
11
- const checkFirstLetter = value === '';
12
- const numberTypeValidation = type === 'number' && !checkFirstLetter && !/^-?\d*\.?\d*$/.test(value);
13
- const emailTypeValidation = type === 'email' && !checkFirstLetter && !/^[a-zA-Z0-9.@-]*$/.test(value);
14
- if (numberTypeValidation || emailTypeValidation) {
17
+ if (type === "number" &&
18
+ !checkIfNumber(value)) {
15
19
  e.preventDefault();
16
20
  }
17
21
  else {
18
22
  onChange(value);
19
23
  }
20
24
  };
21
- const [inputType, setInputType] = useState(type);
22
- const toggleInputMode = () => {
23
- if (inputType === 'password') {
24
- setInputType('text');
25
- }
26
- else {
27
- setInputType('password');
28
- }
29
- };
30
- return (_jsx(Controller, { control: form?.control, name: name, rules: { ...rules }, defaultValue: defaultValue || '', render: ({ field }) => (_jsx(TextField, { ...form?.register(name, {
25
+ return (_jsx(Controller, { control: form?.control, name: name, rules: { ...rules }, defaultValue: defaultValue || "", render: ({ field }) => (_jsx(TextField, { ...form?.register(name, {
31
26
  ...rules,
32
- }), ...(inputLabelMode === 'static' && { hiddenLabel: true }), ...(inputLabelMode === 'relative' && { label: label }), value: field.value, variant: variant, type: inputType === 'number' ? 'text' : inputType, fullWidth: true, id: name, error: !!error, placeholder: placeholder, onChange: (e) => handleKeyDown(e, field.onChange), sx: [...(Array.isArray(sx) ? sx : [sx]), {}], helperText: withoutHelperText ? undefined : error?.message ?? helperText ?? ' ', ...(type === 'email' && {
33
- InputProps: {
34
- sx: {
35
- input: {
36
- direction: (theme) => theme.direction === 'rtl'
37
- ? 'rtl !important'
38
- : 'ltr !important',
39
- // textAlign: (theme) =>
40
- // theme.direction === 'rtl'
41
- // ? 'right !important'
42
- // : 'left !important',
43
- },
44
- },
45
- },
46
- }), ...(type === 'password' && {
47
- InputProps: {
48
- endAdornment: (_jsx(IconButton, { onClick: toggleInputMode, sx: { mr: -2 }, children: inputType === 'password' ? (_jsx(SvgEye, { primarycolor: 'inherit' })) : (_jsx(SvgEyeSlash, { primarycolor: 'inherit' })) })),
49
- },
50
- }), "aria-readonly": readonly, disabled: disabled, inputProps: { readOnly: readonly }, ...itemProps, ...props })) }));
27
+ }), ...(inputLabelMode === "static" && { hiddenLabel: true }), ...(inputLabelMode === "relative" && { label: label }), value: field.value, variant: variant, type: type === "number" ? "text" : type, fullWidth: true, id: name, error: !!error, placeholder: placeholder, onChange: (e) => handleKeyDown(e, field.onChange), helperText: withoutHelperText ? undefined : error?.message ?? helperText ?? " ", "aria-readonly": readonly, disabled: disabled, inputProps: { readOnly: readonly }, ...textFieldMergedProps })) }));
51
28
  };
52
29
  export default UFTextField;
@@ -1,6 +1,6 @@
1
- import { FC } from 'react';
2
- import { IUploaderForm } from '../type';
3
- import { UseFormReturn } from 'react-hook-form';
1
+ import { FC } from "react";
2
+ import { IUploaderForm } from "../type";
3
+ import { UseFormReturn } from "react-hook-form";
4
4
  type UFUploaderProps = IUploaderForm & {
5
5
  form: UseFormReturn<any>;
6
6
  error: any;
@@ -1,16 +1,20 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { Controller } from 'react-hook-form';
3
- import FormControl from '@mui/material/FormControl';
4
- import Typography from '@mui/material/Typography';
5
- import Box from '@mui/material/Box';
6
- import CustomUploader from '../../custom-uploader/CustomUploader';
7
- const UFUploader = ({ form, error, itemProps, props, rules, disabled, multiple, name, withoutHelperText, helperText, onDelete, wrapperProps, }) => {
8
- const handleChange = (addedFiles, addedPreview) => {
2
+ import { Controller } from "react-hook-form";
3
+ import FormControl from "@mui/material/FormControl";
4
+ import Typography from "@mui/material/Typography";
5
+ import CustomUploader from "../../custom-uploader/CustomUploader";
6
+ import Box from "@mui/material/Box";
7
+ import { useFormContext } from '../../../context/FormContext';
8
+ import { deepMerge } from '../../../methods/general';
9
+ const UFUploader = ({ form, error, itemProps, props, rules, disabled, multiple, name, withoutHelperText, helperText, onDelete, }) => {
10
+ const { theme } = useFormContext();
11
+ const uploaderMergedProps = deepMerge(theme?.uploader?.uploaderProps, itemProps, props);
12
+ const handleChange = (addedFiles) => {
9
13
  const files = form.getValues(name)?.files || [];
10
14
  const previews = form.getValues(name)?.preview || [];
11
15
  for (let i = 0; i < addedFiles.length; i++) {
12
16
  const file = addedFiles[i];
13
- if (!files || files?.findIndex((f) => f.name === file.name) < 0) {
17
+ if (!files || files?.findIndex(f => f.name === file.name) < 0) {
14
18
  files?.push(file);
15
19
  previews.push(URL.createObjectURL(file));
16
20
  }
@@ -21,19 +25,17 @@ const UFUploader = ({ form, error, itemProps, props, rules, disabled, multiple,
21
25
  });
22
26
  };
23
27
  const handleDelete = (index) => {
28
+ console.log('index', index);
24
29
  const files = form.getValues(name)?.files;
25
30
  const preview = form.getValues(name)?.preview;
26
31
  const newFiles = files?.filter((_, i) => i !== index);
27
32
  const newPreview = preview?.filter((_, i) => i !== index);
28
- form.setValue(name, !!newPreview?.length
29
- ? { files: newFiles, preview: newPreview }
30
- : null);
33
+ form.setValue(name, { files: newFiles, preview: newPreview });
31
34
  };
32
- return (_jsx(Controller, { control: form?.control, name: name, rules: { ...rules }, render: ({ field: { name, value, onBlur } }) => (_jsxs(FormControl, { sx: { display: 'flex', ...(disabled && { filter: 'contrast(0.3)' }) }, children: [_jsxs(Box, { display: 'flex', gap: 2, ...wrapperProps, children: [_jsx(CustomUploader, { multiple: multiple, link: !multiple ? value?.preview?.[0] : undefined, ...props, ...itemProps, inputProps: { name, disabled, onBlur }, onChange: handleChange, onDeleteDocument: onDelete ? () => onDelete(0) : () => handleDelete(0) }), multiple &&
33
- value?.preview?.map((preview, i) => (_jsx(CustomUploader, { multiple: multiple, ...props, ...itemProps, link: preview, inputProps: { name, disabled, onBlur }, onChange: handleChange, onDeleteDocument: onDelete ? () => onDelete(i) : () => handleDelete(i) })))] }), !withoutHelperText && (_jsx(Typography, { sx: {
35
+ return (_jsx(Controller, { control: form?.control, name: name, rules: { ...rules }, render: ({ field: { name, value, onBlur } }) => (_jsxs(FormControl, { sx: { display: "flex", ...(disabled && { filter: "contrast(0.3)" }) }, children: [_jsxs(Box, { display: "flex", gap: 2, children: [(multiple || !value?.files?.length) && (_jsx(CustomUploader, { multiple: multiple, ...uploaderMergedProps, inputProps: { name, disabled, onBlur }, onChange: handleChange })), value?.preview?.map((preview, i) => (_jsx(CustomUploader, { multiple: multiple, ...uploaderMergedProps, link: preview, inputProps: { name, disabled, onBlur }, onChange: handleChange, onDeleteDocument: onDelete ? () => onDelete(i) : () => handleDelete(i) })))] }), !withoutHelperText && (_jsx(Typography, { sx: {
34
36
  height: 23,
35
- width: 'max-content',
36
- color: error ? 'error.4' : 'text.primary',
37
- }, children: error?.message ?? helperText ?? ' ' }))] })) }));
37
+ width: "max-content",
38
+ color: error ? "error.4" : "text.primary",
39
+ }, children: error?.message ?? helperText ?? " " }))] })) }));
38
40
  };
39
41
  export default UFUploader;
@@ -0,0 +1,16 @@
1
+ import { FC, ReactNode } from "react";
2
+ import { TFormTheme } from "../components/input-list/type";
3
+ export interface ICustomInputs {
4
+ }
5
+ interface InputContextType {
6
+ customInputs?: ICustomInputs[];
7
+ theme?: TFormTheme;
8
+ }
9
+ export interface IFormProvider {
10
+ children: ReactNode;
11
+ customInputs?: ICustomInputs[];
12
+ theme?: TFormTheme;
13
+ }
14
+ declare const FormProvider: FC<IFormProvider>;
15
+ export declare const useFormContext: () => InputContextType;
16
+ export default FormProvider;
@@ -0,0 +1,8 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { createContext, useContext } from "react";
3
+ const FormContext = createContext(undefined);
4
+ const FormProvider = ({ children, customInputs, theme, }) => {
5
+ return (_jsx(FormContext.Provider, { value: { customInputs, theme }, children: children }));
6
+ };
7
+ export const useFormContext = () => useContext(FormContext) || {};
8
+ export default FormProvider;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mui-design-system",
3
- "version": "0.0.15",
3
+ "version": "0.0.16",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",