-
Notifications
You must be signed in to change notification settings - Fork 1
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
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
dca5217
chore: storybook, chromatic 패키지 추가
minjongbaek 90acf4f
feat: 스토리북 프리뷰 확인용 workflow 작성
minjongbaek 9444bcb
chore: @babel/core 등 몇몇 종속성 패키지 추가
minjongbaek 7149793
chore: Headless UI 추가
minjongbaek d9abcfe
chore: Tailwind CSS 추가
minjongbaek 1255030
setting: tailwind 설정
minjongbaek 68ba6d7
Update tailwind.config.js
minjongbaek 613b165
feat: PR에 새로운 커밋 발생하면 새로 코멘트를 생성하지 않고 수정
minjongbaek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,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 }}' |
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,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; |
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 @@ | ||
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; |
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 |
---|---|---|
|
@@ -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", | ||
|
@@ -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]" | ||
} |
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,6 @@ | ||
module.exports = { | ||
plugins: { | ||
tailwindcss: {}, | ||
autoprefixer: {}, | ||
}, | ||
} |
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
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,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', | ||
}, | ||
}; |
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,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> | ||
); | ||
}; |
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,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: {}, | ||
}; |
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,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`} | ||
/> | ||
</button> | ||
)} | ||
</Switch> | ||
); | ||
}; | ||
|
||
export default MySwitch; |
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,3 @@ | ||
@tailwind base; | ||
@tailwind components; | ||
@tailwind utilities; |
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,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: [], | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이 부분 저희 변수로 따로 작성하기로 한 건 아니었..나?..요?.. 갑자기 생각나서 여쭤봅니다!
삼항조건으로 하지 말자고 한 부분이 .. 이런 부분이 아니었을까요? 😅 혹시나 해서 여쭤봅니다.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
확인용으로 Headless UI 예제 코드를 그대로 가져왔어요! 실제 컴포넌트를 작성한다면 이야기한대로 변수를 따로 만드는게 좋을 것 같아요.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
아하! 확인했습니다~ 감사합니다!