diff --git a/.gitignore b/.gitignore index afd6235..e8e4b18 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,8 @@ # production /build +/dist +tsconfig.tsbuildinfo # misc .DS_Store diff --git a/README.md b/README.md index bdddee6..e96b40a 100644 --- a/README.md +++ b/README.md @@ -19,9 +19,21 @@ Live demo - [open](https://react-formik-abstraction.vercel.app/) ## Naming Convention -We will use a **PascalCase**. Pascal case is a programming variable naming convention where the first letter of each compound word in a variable is capitalized. +We will use a **kebab-case**. Kebab case is a programming variable naming convention where all letters are lowercase and words are separated by hyphens. -Here are some examples of kebab case: `ComponentName.tsx` and `OtherComponent.tsx`. +Here are some examples of kebab case: `component-name.tsx` and `other-component.tsx`. + +## Component Structure Convention + +When creating a component, we will follow the convention of splitting it into separate files for the controller, model, view, index, and stories. This helps in maintaining a clean and organized codebase. + +Here is the structure: + +- `component-name.controller.ts` - Contains the logic and state management for the component. +- `component-name.model.ts` - Defines the data structures and types used by the component. +- `component-name.view.tsx` - Contains the JSX and styling for the component. +- `component-name.stories.tsx` - Contains the Storybook stories for the component. +- `index.ts` - Exports the component and any related hooks or utilities. ## Directory Structure diff --git a/index.html b/index.html index b819faa..5642615 100644 --- a/index.html +++ b/index.html @@ -1,8 +1,7 @@ - +
-Monthly
-Yearly
>( + props: P, +) => { + const { label, name, className, ...otherProps } = props; + const id = name; + + return { + formFieldProps: { id, name, label, className }, + childProps: { ...otherProps, id, name }, + }; +}; diff --git a/src/components/Form/components/form-field/form-field.model.ts b/src/components/Form/components/form-field/form-field.model.ts new file mode 100644 index 0000000..0d5b3d3 --- /dev/null +++ b/src/components/Form/components/form-field/form-field.model.ts @@ -0,0 +1,8 @@ +import { PropsWithChildren } from 'react'; + +export type FormFieldProps = { + className?: string; + id: string; + label?: string; + name: string; +} & PropsWithChildren; diff --git a/src/components/Form/FormField.tsx b/src/components/Form/components/form-field/form-field.tsx similarity index 50% rename from src/components/Form/FormField.tsx rename to src/components/Form/components/form-field/form-field.tsx index 2c70b30..f1d8979 100644 --- a/src/components/Form/FormField.tsx +++ b/src/components/Form/components/form-field/form-field.tsx @@ -1,27 +1,9 @@ -import { PropsWithChildren } from 'react'; import { clsxm } from '@lib/clsxm'; import { useFormikContext } from 'formik'; -type FormFieldType = { - className?: string; - id: string; - label?: string; - name: string; -} & PropsWithChildren; +import type { FormFieldProps } from './form-field.model'; -export const useFormField =
>( - props: P, -) => { - const { label, name, className, ...otherProps } = props; - const id = name; - - return { - formFieldProps: { id, name, label, className }, - childProps: { ...otherProps, id, name }, - }; -}; - -export const FormField = ({ children, name, id, label, className }: FormFieldType) => { +const FormField = ({ children, name, id, label, className }: FormFieldProps) => { const form = useFormikContext(); const { error } = form.getFieldMeta(name); @@ -39,3 +21,5 @@ export const FormField = ({ children, name, id, label, className }: FormFieldTyp