-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: group component compose pattern
- Loading branch information
Showing
48 changed files
with
652 additions
and
638 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
"use client"; | ||
|
||
import { Stack } from "@seed-design/react"; | ||
import { CheckSelectBox, CheckSelectBoxGroup } from "seed-design/ui/select-box"; | ||
|
||
export default function CheckSelectBoxPreview() { | ||
return ( | ||
<CheckSelectBoxGroup> | ||
<Stack gap="s3"> | ||
<CheckSelectBox label="Apple" defaultChecked /> | ||
<CheckSelectBox | ||
label="Melon" | ||
description="Elit cupidatat dolore fugiat enim veniam culpa." | ||
/> | ||
<CheckSelectBox label="Mango" /> | ||
</Stack> | ||
</CheckSelectBoxGroup> | ||
); | ||
} |
79 changes: 79 additions & 0 deletions
79
docs/components/example/check-select-box-react-hook-form.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,79 @@ | ||
"use client"; | ||
|
||
import { Column, Columns, Stack } from "@seed-design/react"; | ||
import { useCallback, type FormEvent } from "react"; | ||
import { useController, useForm } from "react-hook-form"; | ||
import { ActionButton } from "seed-design/ui/action-button"; | ||
import { CheckSelectBox, CheckSelectBoxGroup } from "seed-design/ui/select-box"; | ||
|
||
const POSSIBLE_FRUIT_VALUES = ["apple", "melon", "mango"] as const; | ||
|
||
type FormValues = Record<(typeof POSSIBLE_FRUIT_VALUES)[number], boolean>; | ||
|
||
export default function CheckSelectBoxReactHookForm() { | ||
const { handleSubmit, reset, setValue, control } = useForm<FormValues>({ | ||
defaultValues: { | ||
apple: false, | ||
melon: true, | ||
mango: false, | ||
}, | ||
}); | ||
|
||
const onValid = useCallback((data: FormValues) => { | ||
window.alert(JSON.stringify(data, null, 2)); | ||
}, []); | ||
|
||
const onReset = useCallback( | ||
(event: FormEvent) => { | ||
event.preventDefault(); | ||
reset(); | ||
}, | ||
[reset], | ||
); | ||
|
||
return ( | ||
<form onSubmit={handleSubmit(onValid)} onReset={onReset}> | ||
<Stack gap="s3" width="384px"> | ||
<CheckSelectBoxGroup> | ||
<Stack gap="s3"> | ||
{POSSIBLE_FRUIT_VALUES.map((name) => { | ||
const { | ||
field: { value, ...restProps }, | ||
fieldState: { invalid }, | ||
} = useController({ name, control }); | ||
|
||
return ( | ||
<CheckSelectBox | ||
key={name} | ||
label={name} | ||
checked={value} | ||
inputProps={restProps} | ||
invalid={invalid} | ||
/> | ||
); | ||
})} | ||
</Stack> | ||
</CheckSelectBoxGroup> | ||
<Columns gap="s2"> | ||
<Column> | ||
<ActionButton type="submit">제출</ActionButton> | ||
</Column> | ||
<Column width="content"> | ||
<ActionButton | ||
type="button" | ||
variant="neutralWeak" | ||
onClick={() => setValue("mango", true)} | ||
> | ||
mango 선택 | ||
</ActionButton> | ||
</Column> | ||
<Column width="content"> | ||
<ActionButton type="reset" variant="neutralWeak"> | ||
초기화 | ||
</ActionButton> | ||
</Column> | ||
</Columns> | ||
</Stack> | ||
</form> | ||
); | ||
} |
Large diffs are not rendered by default.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
"use client"; | ||
|
||
import { Stack } from "@seed-design/react"; | ||
import { RadioSelectBoxItem, RadioSelectBoxRoot } from "seed-design/ui/select-box"; | ||
|
||
export default function RadioSelectBoxPreview() { | ||
return ( | ||
<RadioSelectBoxRoot defaultValue="apple" aria-label="Fruit"> | ||
<Stack gap="s3"> | ||
<RadioSelectBoxItem value="apple" label="Apple" /> | ||
<RadioSelectBoxItem | ||
value="melon" | ||
label="Melon" | ||
description="Elit cupidatat dolore fugiat enim veniam culpa." | ||
/> | ||
<RadioSelectBoxItem value="mango" label="Mango" /> | ||
</Stack> | ||
</RadioSelectBoxRoot> | ||
); | ||
} |
67 changes: 67 additions & 0 deletions
67
docs/components/example/radio-select-box-react-hook-form.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,67 @@ | ||
"use client"; | ||
|
||
import { Column, Columns, Stack } from "@seed-design/react"; | ||
import { useCallback, type FormEvent } from "react"; | ||
import { useController, useForm } from "react-hook-form"; | ||
import { ActionButton } from "seed-design/ui/action-button"; | ||
import { RadioSelectBoxItem, RadioSelectBoxRoot } from "seed-design/ui/select-box"; | ||
|
||
const POSSIBLE_FRUIT_VALUES = ["apple", "melon", "mango"] as const; | ||
|
||
interface FormValues { | ||
fruit: (typeof POSSIBLE_FRUIT_VALUES)[number]; | ||
} | ||
|
||
export default function RadioSelectBoxReactHookForm() { | ||
const { handleSubmit, reset, setValue, control } = useForm<FormValues>({ | ||
defaultValues: { | ||
fruit: "melon", | ||
}, | ||
}); | ||
const { field } = useController({ name: "fruit", control }); | ||
|
||
const onValid = useCallback((data: FormValues) => { | ||
window.alert(JSON.stringify(data, null, 2)); | ||
}, []); | ||
|
||
const onReset = useCallback( | ||
(event: FormEvent) => { | ||
event.preventDefault(); | ||
reset(); | ||
}, | ||
[reset], | ||
); | ||
|
||
return ( | ||
<form onSubmit={handleSubmit(onValid)} onReset={onReset}> | ||
<Stack gap="s3" width="384px"> | ||
<RadioSelectBoxRoot aria-label="Fruit" {...field}> | ||
<Stack gap="s3"> | ||
{POSSIBLE_FRUIT_VALUES.map((value) => ( | ||
<RadioSelectBoxItem key={value} value={value} label={value} /> | ||
))} | ||
</Stack> | ||
</RadioSelectBoxRoot> | ||
<Columns gap="s2"> | ||
<Column> | ||
<ActionButton type="submit">제출</ActionButton> | ||
</Column> | ||
<Column width="content"> | ||
<ActionButton | ||
type="button" | ||
variant="neutralWeak" | ||
onClick={() => setValue("fruit", "mango")} | ||
> | ||
mango 선택 | ||
</ActionButton> | ||
</Column> | ||
<Column width="content"> | ||
<ActionButton type="reset" variant="neutralWeak"> | ||
초기화 | ||
</ActionButton> | ||
</Column> | ||
</Columns> | ||
</Stack> | ||
</form> | ||
); | ||
} |
This file was deleted.
Oops, something went wrong.
66 changes: 0 additions & 66 deletions
66
docs/components/example/select-box-check-react-hook-form.tsx
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
60 changes: 0 additions & 60 deletions
60
docs/components/example/select-box-radio-react-hook-form.tsx
This file was deleted.
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
24 changes: 24 additions & 0 deletions
24
docs/content/docs/react/components/select-box/check-select-box.mdx
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,24 @@ | ||
--- | ||
title: Check Select Box | ||
--- | ||
|
||
<ComponentExample name="check-select-box-preview" /> | ||
|
||
## 설치 | ||
|
||
<Installation name="select-box" /> | ||
|
||
## Props | ||
|
||
### `CheckSelectBox` | ||
|
||
<ReactTypeTable | ||
path="./registry/ui/select-box.tsx" | ||
name="CheckSelectBoxProps" | ||
/> | ||
|
||
## 예제 | ||
|
||
### React Hook Form | ||
|
||
<ComponentExample name="check-select-box-react-hook-form" /> |
Oops, something went wrong.