-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(form): actions (submit & base button) in form (#5)
- Loading branch information
1 parent
4ec8c29
commit d724f15
Showing
15 changed files
with
218 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
packages/components/form/src/components/actions/base/actionBase.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { LoadingButton } from '@mui/lab'; | ||
import { FC } from 'react'; | ||
import { ActionBaseProps } from './actionBase.types'; | ||
|
||
const ActionBase: FC<ActionBaseProps> = ({ children, ...actionBaseProps }) => { | ||
return <LoadingButton {...actionBaseProps}>{children}</LoadingButton>; | ||
}; | ||
|
||
export default ActionBase; |
6 changes: 6 additions & 0 deletions
6
packages/components/form/src/components/actions/base/actionBase.types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { LoadingButtonProps } from '@mui/lab'; | ||
import { ReactNode } from 'react'; | ||
|
||
export type ActionBaseProps = LoadingButtonProps & { | ||
children: ReactNode; | ||
}; |
25 changes: 25 additions & 0 deletions
25
packages/components/form/src/components/actions/submit/submit.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { Button } from '@mui/material'; | ||
import { FC } from 'react'; | ||
import { ActionSubmitFieldProps } from './submit.types'; | ||
import useForms from '../../../hooks/useForms/useForms'; | ||
import { FieldValues } from 'react-hook-form'; | ||
|
||
const ActionSubmit: FC<ActionSubmitFieldProps> = ({ | ||
formId, | ||
children, | ||
...submitFieldProps | ||
}) => { | ||
const forms = useForms((state) => state.forms); | ||
const { handleSubmit } = forms[formId]; | ||
const onSubmit = (values: FieldValues) => { | ||
console.log(values); | ||
}; | ||
|
||
return ( | ||
<Button {...submitFieldProps} onClick={handleSubmit(onSubmit)}> | ||
{children} | ||
</Button> | ||
); | ||
}; | ||
|
||
export default ActionSubmit; |
4 changes: 4 additions & 0 deletions
4
packages/components/form/src/components/actions/submit/submit.types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { FormId } from '../../../types/public.types'; | ||
import { ActionBaseProps } from '../base/actionBase.types'; | ||
|
||
export type ActionSubmitFieldProps = ActionBaseProps & FormId; |
6 changes: 3 additions & 3 deletions
6
packages/components/form/src/components/builder/builder.types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import { FIELD_TYPE, FieldProps } from '../../types/public.types'; | ||
import { FormTypes, FieldProps } from '../../types/public.types'; | ||
|
||
export interface BuilderProps { | ||
fieldType: FIELD_TYPE; | ||
fieldType: FormTypes; | ||
fieldProps: FieldProps; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ts/form/src/components/text/text.types.ts → .../src/components/fields/text/text.types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { TextFieldProps } from "@mui/material"; | ||
import { FormId, Id } from "../../types/public.types"; | ||
import { FormId, Id } from "../../../types/public.types"; | ||
|
||
export type TextProps = TextFieldProps & Id & FormId; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,12 @@ | ||
import { TextProps } from "../components/text/text.types"; | ||
import { ActionSubmitFieldProps } from "../components/actions/submit/submit.types"; | ||
import { TextProps } from "../components/fields/text/text.types"; | ||
|
||
export type FormId = { formId: string }; | ||
|
||
export type Id = { | ||
id: string; | ||
}; | ||
|
||
export enum FIELD_TYPE { | ||
TEXT = 'text', | ||
} | ||
export type FormTypes = 'field-text' | "action-submit"; | ||
|
||
export type FieldProps = TextProps; | ||
export type FieldProps = TextProps | ActionSubmitFieldProps; |
Oops, something went wrong.