Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Switch 컴포넌트 구현 #22

Merged
merged 34 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
e17e716
feat: 토글 컴포넌트 구현
ghdtjgus76 May 21, 2024
7a176b4
docs: gitignore 업데이트
ghdtjgus76 May 21, 2024
982d1e2
design: 배경색 변경
ghdtjgus76 May 21, 2024
1af0733
docs: 토글 컴포넌트 스토리 작성
ghdtjgus76 May 21, 2024
41af488
docs: 토글 컴포넌트 스토리 코드 문서화 추가
ghdtjgus76 May 21, 2024
8fa5856
chore: 토글 컴포넌트 text 관련 props 추가
ghdtjgus76 May 21, 2024
e98f6ed
chore: 변경된 styled-system 반영
ghdtjgus76 May 21, 2024
bf0d27b
chore: jest config 수정
ghdtjgus76 May 22, 2024
46ad9a3
feat: testing-library/user-event 설치
ghdtjgus76 May 22, 2024
478ac13
chore: 토글 컴포넌트 data-disabled 속성 변경
ghdtjgus76 May 22, 2024
9e8433e
test: 토글 컴포넌트 테스트 작성
ghdtjgus76 May 22, 2024
e144236
chore: jest setup 관련 tsconfig 설정 변경
ghdtjgus76 May 22, 2024
7d72782
chore: 토글 컴포넌트에 use client 추가
ghdtjgus76 May 23, 2024
063dfd8
chore: package.json, rollup config 토글 컴포넌트 반영
ghdtjgus76 May 23, 2024
74be1bd
design: 토글 가로, 세로 너비 고정
ghdtjgus76 May 23, 2024
505bed3
chore: 토글 컴포넌트 text props 타입 변경
ghdtjgus76 May 23, 2024
16140c8
chore: 토글 컴포넌트에 onClick, onKeyDown 이벤트 핸들러 props 추가
ghdtjgus76 May 24, 2024
fe8c161
chore: 외부 상태 제어 관련 props 추가
ghdtjgus76 May 24, 2024
09aa783
fix: 토글 컴포넌트 forwardRef, generic 관련 타입 추론 안 되는 문제 해결
ghdtjgus76 May 24, 2024
a3e72b8
chore: 빌드 시 exports type 필드 경로 변경
ghdtjgus76 May 24, 2024
cb0c1e1
fix: 토글 컴포넌트 테스트 props 변경에 따른 수정
ghdtjgus76 May 24, 2024
a7121f2
feat: 크로마틱 배포 워크플로우에 스토리북 링크 코멘트 기능 추가
ghdtjgus76 May 24, 2024
053f4e7
test: 토글 컴포넌트 테스트 코드 수정
ghdtjgus76 May 24, 2024
15cb024
chore: 토글 컴포넌트 외부 상태 허용하도록 변경
ghdtjgus76 May 24, 2024
d399542
chore: 토글 컴포넌트 props 타입 변경
ghdtjgus76 May 24, 2024
745185f
chore: Toggle 컴포넌트 Switch 컴포넌트로 네이밍 변경
ghdtjgus76 May 25, 2024
595b37f
chore: 스위치 컴포넌트 코드 및 스토리 수정
ghdtjgus76 May 25, 2024
7641049
test: 토글 컴포넌트 변경 사항 테스트에 적용
ghdtjgus76 May 25, 2024
54c2e07
test: 토글 컴포넌트 변경된 props에 따른 테스트 변경
ghdtjgus76 May 25, 2024
44ec339
chore: 빌드 관련 설정 변경
ghdtjgus76 May 26, 2024
e9514af
chore: props 및 상태 네이밍 변경
ghdtjgus76 May 27, 2024
404d1f7
fix: rollup 빌드 시 use client 없애는 문제 해결
ghdtjgus76 May 27, 2024
0d3392c
fix: rollup use client 주석 없애는 이슈 해결
ghdtjgus76 May 27, 2024
9bd0cbe
Merge branch 'main' into feature/toggle-component
ghdtjgus76 May 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/workflows/deploy-chromatic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,10 @@ jobs:
workingDir: packages/wow-ui/src
projectToken: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}
token: ${{ secrets.TOKEN }}

- name: Create comment PR
uses: thollander/actions-comment-pull-request@v1
env:
GITHUB_TOKEN: ${{ secrets.TOKEN }}
with:
message: "🚀 storybook: ${{ steps.chromatic.outputs.storybookUrl }}"
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,7 @@ yarn-error.log*

## Panda
styled-system-studio
*storybook.log

*storybook.log

.eslintcache
4 changes: 2 additions & 2 deletions apps/wow-docs/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { css } from "@styled-system/css/css";
import { UpArrow } from "wowds-icons";
import Button from "wowds-ui/Button";
import Switch from "wowds-ui/Switch";

const Home = () => {
return (
Expand All @@ -15,7 +15,7 @@ const Home = () => {
<p>docs</p>
<UpArrow />
</main>
<Button>버튼</Button>
<Switch />
</>
);
};
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"@svgr/rollup": "^8.1.0",
"@testing-library/jest-dom": "^6.4.5",
"@testing-library/react": "^15.0.7",
"@testing-library/user-event": "^14.5.2",
"@types/jest": "^29.5.12",
"@types/react": "^18.2.61",
"@types/react-dom": "^18.2.19",
Expand Down Expand Up @@ -66,6 +67,7 @@
"rollup": "^4.17.2",
"rollup-jest": "^3.1.0",
"rollup-plugin-peer-deps-external": "^2.2.4",
"rollup-plugin-preserve-directives": "^0.4.0",
"shared-config": "workspace:^",
"theme": "workspace:*",
"ts-jest": "^29.1.2",
Expand Down
5 changes: 3 additions & 2 deletions packages/shared-config/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const config: Config = {
],
},

setupFilesAfterEnv: ["./jest.config.ts"],
setupFilesAfterEnv: ["../shared-config/jest.setup.ts"],
verbose: true,
collectCoverage: true,
restoreMocks: true,
Expand All @@ -29,7 +29,8 @@ const config: Config = {
"<rootDir>/node-modules/",
],
moduleNameMapper: {
"^@styled-system(.*)$": "<rootDir>/styled-system$1",
"^@/(.*)$": "<rootDir>/src/$1",
"^@styled-system(.*)$": "<rootDir>/styled-system/$1",
},
};

Expand Down
10 changes: 10 additions & 0 deletions packages/wow-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@
"types": "./dist/Button/index.d.ts",
"require": "./dist/Button.cjs",
"import": "./dist/Button.js"
},
"./Toggle": {
"types": "./dist/components/Toggle/index.d.ts",
"require": "./dist/Toggle.cjs",
"import": "./dist/Toggle.js"
},
"./Switch": {
"types": "./dist/Switch/index.d.ts",
"require": "./dist/Switch.cjs",
"import": "./dist/Switch.js"
}
},
"keywords": [],
Expand Down
1 change: 1 addition & 0 deletions packages/wow-ui/panda.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export default defineConfig({
watch: true,
outExtension: "js",
polyfill: true,
jsxFramework: "react",
include: ["./src/**/*.{js,jsx,ts,tsx}"],
exclude: [],
hooks: {
Expand Down
14 changes: 13 additions & 1 deletion packages/wow-ui/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import url from "@rollup/plugin-url";
import peerDepsExternal from "rollup-plugin-peer-deps-external";
import typescript from "@rollup/plugin-typescript";
import { fileURLToPath } from "url";
import preserveDirectives from "rollup-plugin-preserve-directives";

const extensions = [".tsx", ".ts", ".js", ".jsx"];

Expand All @@ -18,12 +19,17 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url));
process.env.BABEL_ENV = "production";

export default {
input: { Box: "./src/components/Box", Button: "./src/components/Button" },
input: {
Box: "./src/components/Box",
Button: "./src/components/Button",
Switch: "./src/components/Switch",
},
output: [
{
format: "esm",
dir: "dist",
entryFileNames: "[name].js",
preserveModules: true,
},
{
format: "cjs",
Expand Down Expand Up @@ -65,5 +71,11 @@ export default {
svgr(),
terser(),
json(),
preserveDirectives.default(),
],
onwarn: (warning) => {
if (warning.code !== "MODULE_LEVEL_DIRECTIVE") {
return;
}
},
};
128 changes: 128 additions & 0 deletions packages/wow-ui/src/components/Switch/Switch.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
import type { Meta, StoryObj } from "@storybook/react";
import { useState } from "react";

import Switch from "@/components/Switch";

const meta = {
title: "UI/Switch",
component: Switch,
tags: ["autodocs"],
parameters: {
componentSubtitle: "스위치 컴포넌트",
},
argTypes: {
defaultChecked: {
description:
"defaultChecked는 스위치가 처음에 활성화되어 있는지 여부를 나타냅니다.",
table: {
type: { summary: "boolean" },
defaultValue: { summary: "false" },
},
control: {
type: "boolean",
},
},
isDisabled: {
description:
"isDisabled는 스위치가 비활성화되어 있는지 여부를 나타냅니다.",
table: {
type: { summary: "boolean" },
defaultValue: { summary: "false" },
},
control: {
type: "boolean",
},
},
isChecked: {
description: "isChecked는 외부에서 제어할 활성 상태를 나타냅니다.",
table: {
type: { summary: "boolean" },
defaultValue: { summary: "false" },
},
control: {
type: "boolean",
},
},
text: {
description: "스위치 오른쪽에 들어갈 텍스트입니다.",
table: {
type: { summary: "string" },
defaultValue: { summary: null },
},
control: {
type: "text",
},
},
onChange: {
description: "외부 활성 상태가 변경될 때 호출될 콜백 함수를 나타냅니다.",
table: {
type: { summary: "() => void" },
defaultValue: { summary: null },
control: {
type: "function",
},
},
},
onClick: {
description: "스위치 클릭 시 동작할 이벤트입니다.",
table: {
type: { summary: "() => void" },
defaultValue: { summary: null },
control: {
type: "function",
},
},
},
onKeyDown: {
description:
"스위치가 포커스됐을 때 엔터 키 또는 스페이스 바를 눌렀을 때 동작할 이벤트입니다.",
table: {
type: { summary: "() => void" },
defaultValue: { summary: null },
control: {
type: "function",
},
},
},
},
} satisfies Meta<typeof Switch>;

export default meta;

type Story = StoryObj<typeof meta>;

export const Primary: Story = {
args: {},
};

export const DefaultChecked: Story = {
args: {
defaultChecked: true,
},
};

export const Disabled: Story = {
args: {
isDisabled: true,
},
};

export const WithText: Story = {
args: {
text: "Text",
},
};

const ControlledSwitch = () => {
const [isChecked, setIsChecked] = useState(false);

const handleChange = () => {
setIsChecked((prev) => !prev);
};

return <Switch isChecked={isChecked} onChange={handleChange} />;
};

export const ControlledState: Story = {
render: () => <ControlledSwitch />,
};
Loading
Loading