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

[#370] Storybook & Headless UI 추가 #371

Merged
merged 8 commits into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
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
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"next/core-web-vitals"
"next/core-web-vitals",
"plugin:storybook/recommended"
],
"rules": {
"@typescript-eslint/no-unused-vars": [
Expand Down
36 changes: 36 additions & 0 deletions .github/workflows/chromatic.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Storybook Deployment

on:
pull_request:
branches:
- main

jobs:
chromatic-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0

- uses: actions/setup-node@v3
with:
node-version: 18
cache: 'yarn'

- name: Install Dependency
run: yarn install --immutable

- name: Publish Chromatic
id: chromatic
uses: chromaui/action@v1
with:
projectToken: ${{ secrets.CHROMATIC_TOKEN }}

- name: Comment Storybook URL at PR
uses: thollander/actions-comment-pull-request@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
message: '🚀 Storybook: ${{ steps.chromatic.outputs.storybookUrl }}'
28 changes: 28 additions & 0 deletions .storybook/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import type { StorybookConfig } from '@storybook/nextjs';
const config: StorybookConfig = {
stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|ts|tsx)'],
addons: [
'@storybook/addon-links',
'@storybook/addon-essentials',
'@storybook/addon-interactions',
{
name: '@storybook/addon-styling',
options: {
postCss: true,
},
},
],
framework: {
name: '@storybook/nextjs',
options: {},
},
docs: {
autodocs: 'tag',
},
refs: {
'@chakra-ui/react': {
disable: true,
},
},
};
export default config;
19 changes: 19 additions & 0 deletions .storybook/preview.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type { Preview } from '@storybook/react';
import '@/styles/global.css';

const preview: Preview = {
parameters: {
actions: { argTypesRegex: '^on[A-Z].*' },
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/,
},
},
nextjs: {
appDirectory: true,
},
},
};

export default preview;
28 changes: 25 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@
"build": "next build",
"start": "next start -H local.dev.dadok.site",
"lint": "next lint",
"prepare": "husky install"
"prepare": "husky install",
"storybook": "storybook dev -p 6006",
"build-storybook": "storybook build"
},
"dependencies": {
"@chakra-ui/icons": "^2.0.17",
"@chakra-ui/react": "^2.4.9",
"@emotion/react": "^11.10.5",
"@emotion/styled": "^11.10.5",
"@headlessui/react": "^1.7.15",
"@tanstack/react-query": "^4.24.4",
"@tanstack/react-query-devtools": "^4.24.12",
"@types/node": "18.13.0",
Expand All @@ -31,19 +34,38 @@
"recoil": "^0.7.7"
},
"devDependencies": {
"@babel/core": "^7.22.8",
"@storybook/addon-essentials": "^7.0.26",
"@storybook/addon-interactions": "^7.0.26",
"@storybook/addon-links": "^7.0.26",
"@storybook/addon-styling": "^1.3.2",
"@storybook/blocks": "^7.0.26",
"@storybook/nextjs": "^7.0.26",
"@storybook/react": "^7.0.26",
"@storybook/testing-library": "^0.0.14-next.2",
"@svgr/webpack": "^6.5.1",
"@typescript-eslint/eslint-plugin": "^5.52.0",
"@typescript-eslint/parser": "^5.61.0",
"autoprefixer": "^10.4.14",
"chromatic": "^6.19.9",
"eslint": "^8.34.0",
"eslint-config-next": "^13.1.6",
"eslint-plugin-storybook": "^0.6.12",
"husky": "^8.0.3",
"lint-staged": "^13.1.1",
"postcss": "^8.4.25",
"prettier": "^2.8.4",
"typescript": "^4.9.5"
"storybook": "^7.0.26",
"tailwindcss": "^3.3.2",
"typescript": "^4.9.5",
"webpack": "^5.88.1"
},
"lint-staged": {
"src/**/*.{ts,tsx}": [
"eslint --fix --max-warnings 0",
"prettier --write"
]
}
},
"readme": "ERROR: No README data found!",
"_id": "[email protected]"
}
6 changes: 6 additions & 0 deletions postcss.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
}
1 change: 1 addition & 0 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import ContextProvider from '@/components/ContextProvider';
import { ReactNode } from 'react';
import '@/styles/global.css';

const RootLayout = ({ children }: { children: ReactNode }) => {
return (
Expand Down
42 changes: 42 additions & 0 deletions src/stories/Button.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import type { Meta, StoryObj } from '@storybook/react';

import { Button } from './Button';

// More on how to set up stories at: https://storybook.js.org/docs/react/writing-stories/introduction
const meta: Meta<typeof Button> = {
title: 'Example/Button',
component: Button,
tags: ['autodocs'],
argTypes: {},
};

export default meta;
type Story = StoryObj<typeof Button>;

// More on writing stories with args: https://storybook.js.org/docs/react/writing-stories/args
export const Primary: Story = {
args: {
primary: true,
label: 'Button',
},
};

export const Secondary: Story = {
args: {
label: 'Button',
},
};

export const Large: Story = {
args: {
size: 'large',
label: 'Button',
},
};

export const Small: Story = {
args: {
size: 'small',
label: 'Button',
},
};
56 changes: 56 additions & 0 deletions src/stories/Button.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// ./src/stories/Button.js

import React, { ComponentPropsWithoutRef, useMemo } from 'react';

const getSizeClasses = (size: string) => {
switch (size) {
case 'small': {
return 'px-4 py-2.5';
}
case 'large': {
return 'px-6 py-3';
}
default: {
return 'px-5 py-2.5';
}
}
};

const getModeClasses = (isPrimary: boolean) =>
isPrimary
? 'text-white bg-pink-600 border-pink-600 dark:bg-pink-700 dark:border-pink-700'
: 'text-slate-700 bg-transparent border-slate-700 dark:text-white dark:border-white';

const BASE_BUTTON_CLASSES =
'cursor-pointer rounded-full border-2 font-bold leading-none inline-block';

/**
* Primary UI component for user interaction
*/
export const Button = ({
primary = false,
size = 'medium',
label,
...props
}: {
primary: boolean;
size: string;
label: string;
} & ComponentPropsWithoutRef<'button'>) => {
const computedClasses = useMemo(() => {
const modeClass = getModeClasses(primary);
const sizeClass = getSizeClasses(size);

return [modeClass, sizeClass].join(' ');
}, [primary, size]);

return (
<button
type="button"
className={`${BASE_BUTTON_CLASSES} ${computedClasses}`}
{...props}
>
{label}
</button>
);
};
16 changes: 16 additions & 0 deletions src/stories/Switch.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Meta, StoryObj } from '@storybook/react';
import MySwitch from './Switch';

const meta: Meta<typeof MySwitch> = {
title: 'Example/MySwitch',
component: MySwitch,
tags: ['autodocs'],
};

export default meta;

type Story = StoryObj<typeof MySwitch>;

export const Primary: Story = {
args: {},
};
25 changes: 25 additions & 0 deletions src/stories/Switch.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Switch } from '@headlessui/react';
import { Fragment } from 'react';

const MySwitch = () => {
return (
<Switch name="terms-of-service" defaultChecked={true} as={Fragment}>
{({ checked }) => (
<button
className={`${
checked ? 'bg-blue-600' : 'bg-gray-200'
} relative inline-flex h-6 w-11 items-center rounded-full`}
>
<span className="sr-only">Enable notifications</span>
<span
className={`${
checked ? 'translate-x-6' : 'translate-x-1'
} inline-block h-4 w-4 transform rounded-full bg-white transition`}
Comment on lines +9 to +17
Copy link
Member

@WooDaeHyun WooDaeHyun Jul 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 부분 저희 변수로 따로 작성하기로 한 건 아니었..나?..요?.. 갑자기 생각나서 여쭤봅니다!
삼항조건으로 하지 말자고 한 부분이 .. 이런 부분이 아니었을까요? 😅 혹시나 해서 여쭤봅니다.

Copy link
Member Author

@minjongbaek minjongbaek Jul 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

확인용으로 Headless UI 예제 코드를 그대로 가져왔어요! 실제 컴포넌트를 작성한다면 이야기한대로 변수를 따로 만드는게 좋을 것 같아요.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아하! 확인했습니다~ 감사합니다!

/>
</button>
)}
</Switch>
);
};

export default MySwitch;
3 changes: 3 additions & 0 deletions src/styles/global.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@tailwind base;
@tailwind components;
@tailwind utilities;
13 changes: 13 additions & 0 deletions tailwind.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/** @type {import('tailwindcss').Config} */
module.exports = {
content: [
'./src/pages/**/*.{ts,tsx}',
'./src/components/**/*.{ts,tsx}',
'./src/app/**/*.{ts,tsx}',
'./src/stories/**/*.{ts,tsx}',
],
minjongbaek marked this conversation as resolved.
Show resolved Hide resolved
theme: {
extend: {},
},
plugins: [],
};
Loading