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

[PUBLIC] Storybook 작업 #1100

Merged
merged 22 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 3 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
*.d.ts
**/*.storybook.ts
**/*.storybook.tsx
*.d.ts
63 changes: 63 additions & 0 deletions .refresh_icon_story.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/bin/bash

# This script is used to refresh the icon storybook

# Get storybook code


# Go to the src directory
cd src

# Remove the old storybook
rm -rf ./stories/icons && mkdir ./stories/icons

# Get icons list
icons=$(awk 'BEGIN{ORS="\n"} {print $5}' ./icons/index.ts)

for icon in $icons
do
echo "Creating story for $icon"
# Create a new story for the icon
echo "import type { Meta, StoryObj } from '@storybook/react'
import { $icon } from '@/icons'

const meta: Meta<typeof $icon> = {
component: $icon,
}
export default meta

type Story = StoryObj<typeof $icon>

export const Default: Story = {}" > "./stories/icons/$icon.stories.tsx"
done

# Get sub directories
sub_dirs=$(cd ./icons &&ls -dF */ | tr -d '/')

echo "Sub directories: $sub_dirs"

for sub_dir in $sub_dirs
do
# Make a new directory for the sub directory
mkdir ./stories/icons/$sub_dir

# Get icons list
icons=$(awk 'BEGIN{ORS="\n"} {print $5}' ./icons/$sub_dir/index.ts)

for icon in $icons
do
echo "Creating story for $icon"
# Create a new story for the icon
echo "import type { Meta, StoryObj } from '@storybook/react'
import { $icon } from '@/icons/$sub_dir'

const meta: Meta<typeof $icon> = {
component: $icon,
}
export default meta

type Story = StoryObj<typeof $icon>

export const Default: Story = {}" > "./stories/icons/$sub_dir/$icon.stories.tsx"
done
done
32 changes: 31 additions & 1 deletion .storybook/main.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import path from 'path'
import type { StorybookConfig } from '@storybook/nextjs'

const config: StorybookConfig = {
Expand All @@ -7,7 +8,8 @@ const config: StorybookConfig = {
'@storybook/addon-essentials',
'@storybook/addon-onboarding',
'@storybook/addon-interactions',
'@storybook/addon-mdx-gfm'
'@storybook/addon-themes',
'@storybook/themes',
],
framework: {
name: '@storybook/nextjs',
Expand All @@ -16,5 +18,33 @@ const config: StorybookConfig = {
docs: {
autodocs: 'tag',
},
typescript: {
reactDocgen: 'react-docgen-typescript',
reactDocgenTypescriptOptions: {
// Speeds up Storybook build time
compilerOptions: {
allowSyntheticDefaultImports: false,
esModuleInterop: false,
},
// Makes union prop types like variant and size appear as select controls
shouldExtractLiteralValuesFromEnum: true,
// Makes string and boolean types that can be undefined appear as inputs and switches
shouldRemoveUndefinedFromOptional: true,
// Filter out third-party props from node_modules except @mui packages
propFilter: (prop) =>
prop.parent
? !/node_modules\/(?!@mui)/.test(prop.parent.fileName)
: true,
},
},
webpackFinal: async (config) => {
if (config.resolve) {
config.resolve.alias = {
...config.resolve.alias,
'@': path.resolve(__dirname, '../src'),
}
}
return config
},
}
export default config
30 changes: 30 additions & 0 deletions .storybook/preview.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
import type { Preview } from '@storybook/react'

import { ThemeProvider, CssBaseline } from '@mui/material'
import { withThemeFromJSXProvider } from '@storybook/addon-themes'

/* TODO: update import for your custom Material UI themes */
import { lightTheme, darkTheme } from '../src/constant/ColorTheme'

export const parameters = {
actions: { argTypesRegex: '^on[A-Z].*' },
controls: {
expanded: true, // Adds the description and default columns
matchers: {
color: /(background|color)$/i,
date: /Date$/,
},
},
}

const preview: Preview = {
parameters: {
actions: { argTypesRegex: '^on[A-Z].*' },
Expand All @@ -10,6 +27,19 @@ const preview: Preview = {
},
},
},

decorators: [
withThemeFromJSXProvider({
GlobalStyles: CssBaseline,
Provider: ThemeProvider,
themes: {
// Provide your custom themes here
light: lightTheme,
dark: darkTheme,
},
defaultTheme: 'light',
}),
],
}

export default preview
Loading
Loading