Skip to content

Commit

Permalink
[Feature] MultiGroup 컴포넌트 개발 (#56)
Browse files Browse the repository at this point in the history
* Squashed commit of refactor/switch-component

* chore: package.json 수정

* chore: Story 템플릿 수정

* feat: MultiGroup 컴포넌트 구현

* chore: Checkbox 스토리 및 테스트 코드 수정

* chore: Switch 컴포넌트 스토리 및 테스트 수정

* feat: MultiGroup 컴포넌트 빌드 설정 적용

* feat: docs에 MultiGroup 컴포넌트 적용

* comment: jsdoc 추가

* docs: 스토리 코드 문서화 추가

* test: 테스트 코드 작성

* chore: 자잘한 수정사항 반영

* chore: useCheckedState 훅에서 disabled 상태 고려할 수 있도록 로직 개선

* chore: group context 상태 구조 분해 할당으로 가져오도록 수정

* chore: MultiGroup 잘못된 variant 수정

* chore: 상태값 네이밍 변경

* chore: 개별 스위치, 체크박스에는 value default 값 지정

* comment: gap, position 관련 주석 추가

* fix: 머지 에러 해결
  • Loading branch information
ghdtjgus76 authored Jun 23, 2024
1 parent 08934fa commit 3530dbc
Show file tree
Hide file tree
Showing 15 changed files with 878 additions and 40 deletions.
18 changes: 15 additions & 3 deletions apps/wow-docs/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,32 @@
import Checkbox from "wowds-ui/Checkbox";
import Chip from "wowds-ui/Chip";
import MultiGroup from "wowds-ui/MultiGroup";
import RadioButton from "wowds-ui/RadioButton";
import RadioGroup from "wowds-ui/RadioGroup";
import Switch from "wowds-ui/Switch";

const Home = () => {
return (
<>
<Checkbox />
<Checkbox value="checkbox" />
<Chip label="Chip" />
<Switch />

<Switch value="switch" />
<RadioGroup defaultValue="1학년" name="학년">
<RadioButton label="1학년" value="1학년" />
<RadioButton label="2학년" value="2학년" />
</RadioGroup>
<MultiGroup variant="checkbox">
<Checkbox children="checkbox1" value="checkbox1" />
<Checkbox children="checkbox2" value="checkbox2" />
<Checkbox children="checkbox3" value="checkbox3" />
<Checkbox children="checkbox4" value="checkbox4" />
</MultiGroup>
<MultiGroup variant="switch">
<Switch label="switch1" value="switch1" />
<Switch label="switch2" value="switch2" />
<Switch label="switch3" value="switch3" />
<Switch label="switch4" value="switch4" />
</MultiGroup>
</>
);
};
Expand Down
2 changes: 1 addition & 1 deletion packages/codegen/templates/Story.tsx.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const meta = {
},
argTypes: {
props1: {
description: "props1은 default 값이 있는 필수적인 속성입니다."",
description: "props1은 default 값이 있는 필수적인 속성입니다.",
table: {
// type, 필수가 아닐 경우 required 삭제
type: { summary: "string", required: true },
Expand Down
5 changes: 5 additions & 0 deletions packages/wow-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@
"require": "./dist/RadioGroup.cjs",
"import": "./dist/RadioGroup.js"
},
"./MultiGroup": {
"types": "./dist/components/MultiGroup/index.d.ts",
"require": "./dist/MultiGroup.cjs",
"import": "./dist/MultiGroup.js"
},
"./Chip": {
"types": "./dist/components/Chip/index.d.ts",
"require": "./dist/Chip.cjs",
Expand Down
1 change: 1 addition & 0 deletions packages/wow-ui/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export default {
Switch: "./src/components/Switch",
RadioButton: "./src/components/RadioGroup/RadioButton",
RadioGroup: "./src/components/RadioGroup/RadioGroup",
MultiGroup: "./src/components/MultiGroup",
Chip: "./src/components/Chip",
Checkbox: "./src/components/Checkbox",
Button: "./src/components/Button",
Expand Down
12 changes: 11 additions & 1 deletion packages/wow-ui/src/components/Checkbox/Checkbox.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,18 +148,21 @@ type Story = StoryObj<typeof meta>;
export const Default: Story = {
args: {
defaultChecked: false,
value: "checkbox",
},
};

export const Checked: Story = {
args: {
defaultChecked: true,
value: "checkbox",
},
};

export const Disabled: Story = {
args: {
disabled: true,
value: "checkbox",
},
};

Expand All @@ -168,6 +171,7 @@ export const Vertical: Story = {
checked: true,
children: "string",
position: "vertical",
value: "checkbox",
},
};

Expand All @@ -176,6 +180,7 @@ export const Horizontal: Story = {
checked: true,
children: "string",
position: "horizontal",
value: "checkbox",
},
};

Expand All @@ -186,9 +191,14 @@ const ControlledCheckBox = () => {
setIsChecked((prev) => !prev);
};

return <Checkbox checked={isChecked} onChange={handleChange} />;
return (
<Checkbox checked={isChecked} value="checkbox" onChange={handleChange} />
);
};

export const ControlledState: Story = {
render: () => <ControlledCheckBox />,
args: {
value: "checkbox",
},
};
6 changes: 5 additions & 1 deletion packages/wow-ui/src/components/Checkbox/Checkbox.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import Checkbox from "./index";

describe("Checkbox component", () => {
const renderCheckbox = (props: Partial<CheckboxProps> = {}): RenderResult => {
return render(<Checkbox {...props}>Text</Checkbox>);
return render(
<Checkbox value="checkbox" {...props}>
Text
</Checkbox>
);
};

test("toggles checked state when clicked", async () => {
Expand Down
12 changes: 9 additions & 3 deletions packages/wow-ui/src/components/Checkbox/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { useCheckedState } from "@/hooks";
* @param {boolean} [defaultChecked=false] 체크박스가 처음에 활성화되어 있는지 여부.
* @param {boolean} [disabled=false] 체크박스가 비활성화되어 있는지 여부.
* @param {boolean} [checked] 외부에서 제어할 활성 상태.
* @param {string} value 체크박스 값.
* @param {() => void} [onChange] 외부 활성 상태가 변경될 때 호출되는 함수.
* @param {() => void} [onClick] 체크박스 클릭 시 호출되는 함수.
* @param {() => void} [onKeyDown] 체크박스에 포커스 됐을 때 엔터 키 또는 스페이스 바를 눌렀을 때 호출되는 함수.
Expand All @@ -35,6 +36,7 @@ export interface CheckboxProps extends PropsWithChildren {
defaultChecked?: boolean;
disabled?: boolean;
checked?: boolean;
value?: string;
onChange?: () => void;
onClick?: () => void;
onKeyDown?: () => void;
Expand All @@ -50,8 +52,9 @@ const Checkbox = forwardRef<HTMLInputElement, CheckboxProps>(
(
{
defaultChecked = false,
disabled = false,
disabled: disabledProp = false,
checked: checkedProp,
value = "checkbox",
onClick,
onChange,
children,
Expand All @@ -68,6 +71,7 @@ const Checkbox = forwardRef<HTMLInputElement, CheckboxProps>(
const {
checked,
pressed,
disabled,
handleClick,
handleKeyDown,
handleKeyUp,
Expand All @@ -76,7 +80,8 @@ const Checkbox = forwardRef<HTMLInputElement, CheckboxProps>(
} = useCheckedState({
defaultChecked,
checked: checkedProp,
disabled,
disabled: disabledProp,
value,
onChange,
onClick,
onKeyDown,
Expand Down Expand Up @@ -112,7 +117,8 @@ const Checkbox = forwardRef<HTMLInputElement, CheckboxProps>(
type: disabled ? "disabled" : checked ? "checked" : "default",
})}
{...inputProps}
onClick={handleClick}
value={value}
onClick={() => handleClick(value)}
/>
{checked && (
<styled.span
Expand Down
Loading

0 comments on commit 3530dbc

Please sign in to comment.