Skip to content

Commit f9a9a85

Browse files
authored
Merge pull request #2 from taku10101/feature/form-component
Feature/form component
2 parents 6ea92c6 + b8d3a37 commit f9a9a85

File tree

59 files changed

+428
-8
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+428
-8
lines changed

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,18 @@
3939
},
4040
"dependencies": {
4141
"@axe-core/playwright": "^4.10.1",
42+
"@hookform/resolvers": "^5.0.1",
4243
"axios": "^1.8.4",
4344
"lucide-react": "^0.292.0",
4445
"postcss": "^8.4.31",
4546
"react-aria": "^3.38.1",
4647
"react-aria-components": "latest",
48+
"react-hook-form": "^7.55.0",
4749
"react-router-dom": "^7.5.0",
4850
"tailwind-merge": "^3.1.0",
49-
"tailwind-variants": "^0.3.1"
51+
"tailwind-variants": "^0.3.1",
52+
"zod": "^3.24.2"
5053
},
54+
"sideEffects": false,
5155
"packageManager": "[email protected]+sha512.cdf928fca20832cd59ec53826492b7dc25dc524d4370b6b4adbf65803d32efaa6c1c88147c0ae4e8d579a6c9eec715757b50d4fa35eea179d868eada4ed043af"
5256
}

pnpm-lock.yaml

Lines changed: 39 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/form/InputField.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { useFormContext } from "react-hook-form";
2+
import { Input } from "../ui/Field";
3+
4+
type Props = {
5+
name: string;
6+
};
7+
8+
function InputField(props: Props) {
9+
const methods = useFormContext();
10+
11+
return (
12+
<>
13+
<Input {...methods.register(props.name)} />
14+
{methods.formState.errors[props.name] && (
15+
<p>{methods.formState.errors[props.name]?.message as string}</p>
16+
)}
17+
</>
18+
);
19+
}
20+
export default InputField;

src/components/form/SampleForm.tsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { useForm, FormProvider } from "react-hook-form";
2+
import { zodResolver } from "@hookform/resolvers/zod";
3+
import InputField from "./InputField";
4+
import SelectField from "./SelectField";
5+
import { Button } from "../ui/Button/";
6+
import { z } from "zod";
7+
import { Form } from "../ui/Form";
8+
const sampleFormSchema = z.object({
9+
input: z.string().min(1),
10+
select: z.string().min(1),
11+
});
12+
13+
const SampleForm = () => {
14+
const methods = useForm({
15+
resolver: zodResolver(sampleFormSchema),
16+
});
17+
const { handleSubmit } = methods;
18+
return (
19+
<FormProvider {...methods}>
20+
<Form onSubmit={handleSubmit((data) => console.log(data))}>
21+
<InputField name='input' />
22+
<SelectField name='select' />
23+
<Button type='submit'>Submit</Button>
24+
</Form>
25+
</FormProvider>
26+
);
27+
}
28+
export default SampleForm;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { useFormContext } from "react-hook-form";
2+
import { Select } from "../ui/Select";
3+
const options = ["", "one", "two", "three"];
4+
type Props = {
5+
name: string;
6+
};
7+
function SelectField(props: Props) {
8+
const methods = useFormContext();
9+
return (
10+
<>
11+
<Select {...methods.register(props.name)}>
12+
{options.map((value) => (
13+
<option key={value} value={value}>
14+
{value}
15+
</option>
16+
))}
17+
</Select>
18+
19+
{methods.formState.errors[props.name] && (
20+
<p>{methods.formState.errors[props.name]?.message as string}</p>
21+
)}
22+
</>
23+
);
24+
}
25+
export default SelectField;

src/components/ui/AlertDialog/AlertDialog.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import { AlertCircleIcon, InfoIcon } from "lucide-react";
22
import { ReactNode } from "react";
33
import { Dialog } from "../Dialog/Dialog";
44
import { Button } from "../Button/Button";
5-
import { DialogProps ,Heading} from "react-aria-components";
5+
import { DialogProps, Heading } from "react-aria-components";
66
import { chain } from "react-aria";
77

88

9-
interface AlertDialogProps extends Omit<DialogProps, 'children'> {
9+
export interface AlertDialogProps extends Omit<DialogProps, 'children'> {
1010
title: string,
1111
children: ReactNode,
1212
variant?: 'info' | 'destructive',
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
export { AlertDialog } from './AlertDialog';
3+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
export {
3+
Autocomplete,
4+
AutocompleteItem,
5+
AutocompleteSection,
6+
} from "./Autocomplete";
7+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
export {
3+
Breadcrumbs,
4+
Breadcrumb,
5+
} from "./Breadcrumbs";
6+

src/components/ui/Button/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
export {
3+
Button,
4+
} from "./Button";
5+

0 commit comments

Comments
 (0)