From 239a4cf9998f89472be190f0273b8242be9c8acb Mon Sep 17 00:00:00 2001 From: erfan moghadasi <97363934+erfanmoghadasi@users.noreply.github.com> Date: Mon, 8 Jul 2024 16:23:30 +0330 Subject: [PATCH 1/2] Feat(form) select 46 (#48) * feat(form): initial select component * feat(form): select input prop types * fix(form): set controller field props * fix(form): select input label align * fix: some issue on dependesies and inputLableProps and options select component * fix: Options in select and sutocomplete * fix: formID --------- Co-authored-by: mrbadri --- apps/docs/src/app/app.tsx | 271 ++++++++++-------- .../fields/autoComplete/autoComplete.tsx | 5 +- .../autoComplete/autoComplete.types.tsx | 11 +- .../fields/autoComplete/useAutoComplete.tsx | 23 +- .../fields/checkbox/checkbox.types.ts | 2 +- .../components/fields/checkbox/useCheckbox.ts | 4 +- .../src/components/fields/select/select.tsx | 35 +++ .../components/fields/select/select.types.ts | 26 ++ .../src/components/fields/select/useSelect.ts | 113 ++++++++ .../src/components/fields/text/text.types.ts | 2 +- .../src/components/fields/text/useText.ts | 4 +- .../modules/form/src/types/public.types.ts | 21 +- .../form/src/utils/selector/formSelector.tsx | 22 +- 13 files changed, 378 insertions(+), 161 deletions(-) create mode 100644 packages/core/src/modules/form/src/components/fields/select/select.tsx create mode 100644 packages/core/src/modules/form/src/components/fields/select/select.types.ts create mode 100644 packages/core/src/modules/form/src/components/fields/select/useSelect.ts diff --git a/apps/docs/src/app/app.tsx b/apps/docs/src/app/app.tsx index ef530a9..c2b704b 100644 --- a/apps/docs/src/app/app.tsx +++ b/apps/docs/src/app/app.tsx @@ -9,123 +9,123 @@ import Tabs, { TabData } from '@mui-builder/tab'; export function App() { const children: BuilderProps[] = [ // Fields - { - id: 'form-field-1', - groupType: 'form', - type: 'field-text', - props: { - id: 'Field-One', - formId: '20', - label: 'Field One (Form Id: 20)', - dependesies: ['FieldTwo'], - script: ` - if(formMethod.getValues()?.FieldTwo === "erfan"){ - setProps('FieldTwo' , {label:'i can'}); - return {}; - }`, - api: { - configs: { - url: `return ("https://jsonplaceholder.typicode.com/todo8888s/" + formMethod.getValues()?.FieldTwo);`, - method: 'post', - data: { - test: '1', - }, - }, - queries: { - enable: ` - if(formMethod.getValues()?.FieldTwo === 'api'){ - return true; - } - return false; - `, - }, - }, - defaultValue: 'default value field one', - }, - }, - { - id: 'form-field-2', - groupType: 'form', - type: 'field-text', - props: { - id: 'FieldTwo', - formId: '20', - label: 'Field Two (Form Id: 20)', - }, - }, + // { + // id: 'form-field-1', + // groupType: 'form', + // type: 'field-text', + // props: { + // id: 'Field-One', + // formId: '20', + // label: 'Field One (Form Id: 20)', + // dependencies: ['FieldTwo'], + // script: ` + // if(formMethod.getValues()?.FieldTwo === "erfan"){ + // setProps('FieldTwo' , {label:'i can'}); + // return {}; + // }`, + // api: { + // configs: { + // url: `return ("https://jsonplaceholder.typicode.com/todo8888s/" + formMethod.getValues()?.FieldTwo);`, + // method: 'post', + // data: { + // test: '1', + // }, + // }, + // queries: { + // enable: ` + // if(formMethod.getValues()?.FieldTwo === 'api'){ + // return true; + // } + // return false; + // `, + // }, + // }, + // defaultValue: 'default value field one', + // }, + // }, + // { + // id: 'form-field-2', + // groupType: 'form', + // type: 'field-text', + // props: { + // id: 'FieldTwo', + // formId: '20', + // label: 'Field Two (Form Id: 20)', + // }, + // }, - { - id: 'form-field-273', - groupType: 'grid', - type: 'container', - props: { - rowSpacing: 2, - columnSpacing: 2, - children: [ - { - id: 'form-field-4kldjd', - groupType: 'grid', - type: 'item', - props: { - children: { - id: 'form-field-4', - groupType: 'form', - type: 'field-text', - props: { - id: 'Field4', - formId: '20', - label: 'Field 4 (Form Id: 20)', - }, - }, - }, - }, + // { + // id: 'form-field-273', + // groupType: 'grid', + // type: 'container', + // props: { + // rowSpacing: 2, + // columnSpacing: 2, + // children: [ + // { + // id: 'form-field-4kldjd', + // groupType: 'grid', + // type: 'item', + // props: { + // children: { + // id: 'form-field-4', + // groupType: 'form', + // type: 'field-text', + // props: { + // id: 'Field4', + // formId: '20', + // label: 'Field 4 (Form Id: 20)', + // }, + // }, + // }, + // }, - { - id: 'form-field-5', - groupType: 'grid', - type: 'item', - props: { - children: { - id: 'form-field-4', - groupType: 'form', - type: 'field-text', - props: { - id: 'Field4', - formId: '20', - label: 'Field 5 (Form Id: 20)', - }, - }, - }, - }, - ], - }, - }, + // { + // id: 'form-field-5', + // groupType: 'grid', + // type: 'item', + // props: { + // children: { + // id: 'form-field-4', + // groupType: 'form', + // type: 'field-text', + // props: { + // id: 'Field4', + // formId: '20', + // label: 'Field 5 (Form Id: 20)', + // }, + // }, + // }, + // }, + // ], + // }, + // }, - { - id: 'form-field-3', - groupType: 'form', - type: 'field-text', - props: { - id: 'Field-Three', - formId: '21', - label: 'Field Three (Form Id: 21)', - // helperText: 'Helper Text', - rule: { - // required: { - // message: 'this is required', - // value: true, - // }, - // validate: (value, formValues) => { - // if(value === 'val') - // return 'rule validate'; - // }, - validate: ` - if(value === 'val') - return 'rule validate'; - `, - }, - }, - }, + // { + // id: 'form-field-3', + // groupType: 'form', + // type: 'field-text', + // props: { + // id: 'Field-Three', + // formId: '21', + // label: 'Field Three (Form Id: 21)', + // // helperText: 'Helper Text', + // rule: { + // // required: { + // // message: 'this is required', + // // value: true, + // // }, + // // validate: (value, formValues) => { + // // if(value === 'val') + // // return 'rule validate'; + // // }, + // validate: ` + // if(value === 'val') + // return 'rule validate'; + // `, + // }, + // }, + // }, // Actions { @@ -171,7 +171,7 @@ export function App() { type: 'auto-complete', props: { id: 'auto-complete-1', - formId: '18', + formId: '21', options: [ { name: 'folan lab', id: 'fo val' }, { name: 'folan lab22', id: 'fo val22' }, @@ -190,7 +190,7 @@ export function App() { type: 'checkbox', props: { id: 'checkbox-1', - formId: '18', + formId: '21', label: 'label 1', checkboxProps: {}, children: [ @@ -219,6 +219,43 @@ export function App() { ], }, }, + { + id: 'select-form-1', + groupType: 'form', + type: 'select', + props: { + formId: '20', + children: 'child', + id: 'select-1', + sx: { width: '200px' }, + fullWidth: true, + // multiple: true, + defaultValue: '', + inputLabelProps: { + children: 'select label', + }, + options: [ + { name: 'first', id: '1' }, + { name: 'second', id: '2' }, + ], + }, + }, + // id: 'select-form-1', + // groupType: 'form', + // type: 'select', + // props:{ + // formId: '18', + // variant: 'contained', + // options:[{ + // title: 'menu 1', + // value: 'm1' + // }], + // formControlProps:{ + // title: 'select input', + // variant: 'standard' + // }, + // } + // } ]; const [tabs, setTabs] = useState([ @@ -229,7 +266,7 @@ export function App() {
---- - + {/* */} ---
  • diff --git a/packages/core/src/modules/form/src/components/fields/autoComplete/autoComplete.tsx b/packages/core/src/modules/form/src/components/fields/autoComplete/autoComplete.tsx index 8377c21..b5b445d 100644 --- a/packages/core/src/modules/form/src/components/fields/autoComplete/autoComplete.tsx +++ b/packages/core/src/modules/form/src/components/fields/autoComplete/autoComplete.tsx @@ -4,11 +4,12 @@ import { Autocomplete, TextField } from '@mui/material'; import ShowIf from '@mui-builder/utils/showIf/showIf'; -import { AutoCompleteOptions, AutoCompleteProps } from './autoComplete.types'; +import { Option } from '../../../types/public.types'; +import { AutoCompleteProps } from './autoComplete.types'; import useAutoComplete from './useAutoComplete'; -const AutoComplete: FC> = (props) => { +const AutoComplete: FC> = (props) => { const { show, getFieldProps, getInnerTextFieldProps } = useAutoComplete(props); diff --git a/packages/core/src/modules/form/src/components/fields/autoComplete/autoComplete.types.tsx b/packages/core/src/modules/form/src/components/fields/autoComplete/autoComplete.types.tsx index 33cdf18..7640d5f 100644 --- a/packages/core/src/modules/form/src/components/fields/autoComplete/autoComplete.types.tsx +++ b/packages/core/src/modules/form/src/components/fields/autoComplete/autoComplete.types.tsx @@ -8,14 +8,9 @@ import { import { Api } from '@mui-builder/types/api.types'; import { Script } from '@mui-builder/types/script.types'; -import { Dependesies, FormId, Id } from '../../../types/public.types'; +import { Dependesies, FormId, Id, Option } from '../../../types/public.types'; import { Rule } from '../../../types/validation.types'; -export type AutoCompleteOptions = { - name: number | string; - id: number | string; -}; - export type AutoCompleteProps< Value, Multiple extends boolean | undefined = false, @@ -29,12 +24,12 @@ export type AutoCompleteProps< id: Id; formId: FormId; script?: Script; - dependesies?: Dependesies; + dependencies?: Dependesies; propsController?: Record; api?: Api; rule?: Rule; show?: boolean; - options: AutoCompleteOptions[]; + options: Option[]; renderInput?: (params: AutocompleteRenderInputParams) => React.ReactNode; innerTextFieldProps?: Partial; }; diff --git a/packages/core/src/modules/form/src/components/fields/autoComplete/useAutoComplete.tsx b/packages/core/src/modules/form/src/components/fields/autoComplete/useAutoComplete.tsx index 4fdddab..cbaa3d6 100644 --- a/packages/core/src/modules/form/src/components/fields/autoComplete/useAutoComplete.tsx +++ b/packages/core/src/modules/form/src/components/fields/autoComplete/useAutoComplete.tsx @@ -1,4 +1,3 @@ -import { useMemo } from 'react'; import { useController, useWatch } from 'react-hook-form'; import useQueryBuilder from '@mui-builder/utils/useQueryBuilder/useQueryBuilder'; @@ -6,19 +5,20 @@ import UseScript from '@mui-builder/utils/useScript/useScript'; import axios from 'axios'; -import { AutoCompleteOptions, AutoCompleteProps } from './autoComplete.types'; +import { Option } from '../../../types/public.types'; +import { AutoCompleteProps } from './autoComplete.types'; import useForms from '../../../hooks/useForms/useForms'; import usePropsController from '../../../hooks/usePropsController/usePropsController'; import useRule from '../../../hooks/useRule/useRule'; -const useAutoComplete = (props: AutoCompleteProps) => { +const useAutoComplete = (props: AutoCompleteProps