Skip to content

Commit

Permalink
Merge pull request #18 from sendOwlOrganization/feature/LAB-39/linaria
Browse files Browse the repository at this point in the history
🔧  리나리아, 스토리북 설정
  • Loading branch information
leesangb authored May 10, 2023
2 parents 9632d27 + ec7931c commit 8e2c869
Show file tree
Hide file tree
Showing 17 changed files with 5,040 additions and 6,583 deletions.
25 changes: 0 additions & 25 deletions .storybook/main.js

This file was deleted.

85 changes: 85 additions & 0 deletions .storybook/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import type { StorybookConfig } from "@storybook/nextjs";
import MiniCssExtractPlugin, { Configuration } from "mini-css-extract-plugin";

const withLinaria = (config: Configuration) => {
// Replace TSX loader
// @ts-ignore
const tsxRule = config.module.rules.findIndex((rule) => rule.test.toString().includes("tsx"));
// @ts-ignore
config.module.rules[tsxRule] = {
// @ts-ignore
test: config.module.rules[tsxRule].test,
exclude: /node_modules/,
use: [
{
loader: "babel-loader",
options: {
presets: ["@babel/preset-env", "@babel/preset-typescript", ["@babel/preset-react", { runtime: "automatic" }]]
}
},
{
loader: "@linaria/webpack-loader",
options: {
sourceMap: true,
babelOptions: {
presets: [
"@babel/preset-env",
"@babel/preset-typescript",
["@babel/preset-react", { runtime: "automatic" }],
"@linaria/babel-preset"
]
}
}
}
]
};

// @ts-ignore
config.plugins.push(
new MiniCssExtractPlugin({
filename: "styles.css"
})
);
// Replace CSS loader
// @ts-ignore
const cssKey = config.module.rules.findIndex((rule) => rule.test.toString() === "/\\.css$/");
// @ts-ignore
config.module.rules[cssKey] = {
test: /\.css$/,
use: [
{
loader: MiniCssExtractPlugin.loader
},
{
loader: "css-loader",
options: { sourceMap: true }
}
]
};

return config;
};

const config: StorybookConfig = {
stories: ["../src/**/*.stories.@(js|jsx|ts|tsx)"],
staticDirs: ["../public"],
addons: [
"@storybook/addon-links",
"@storybook/addon-essentials",
"@storybook/addon-interactions",
"storybook-dark-mode",
"@storybook/addon-a11y"
],
framework: {
name: "@storybook/nextjs",
options: {}
},
webpackFinal: async (config) => {
return withLinaria(config);
},
docs: {
autodocs: true
}
};

export default config;
9 changes: 0 additions & 9 deletions .storybook/preview.js

This file was deleted.

32 changes: 32 additions & 0 deletions .storybook/preview.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import "@/mds/style.linaria.global";
import { Preview } from "@storybook/react";
import { useEffect } from "react";
import { useDarkMode } from "storybook-dark-mode";

const preview: Preview = {
parameters: {
actions: { argTypesRegex: "^on[A-Z].*" },
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/
}
}
},
decorators: [
(Story) => {
const isDark = useDarkMode();

useEffect(() => {
const html = document.querySelector("html");
if (!html) return;
html.classList.toggle("light", !isDark);
html.classList.toggle("dark", isDark);
}, [isDark]);

return <Story />;
}
]
};

export default preview;
15 changes: 15 additions & 0 deletions app/ThemeSwitcher.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"use client";

// FIXME: temporary solution
export const ThemeSwitcher = () => {
const toggleTheme = () => {
const html = document.querySelector("html");
if (!html) return;

const isDark = html.classList.contains("light");
html.classList.toggle("light", !isDark);
html.classList.toggle("dark", isDark);
};

return <button onClick={() => toggleTheme()}>theme</button>;
};
107 changes: 0 additions & 107 deletions app/globals.css

This file was deleted.

6 changes: 4 additions & 2 deletions app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import "@/mds/style.linaria.global";
import { ReactNode } from "react";
import "./globals.css";
import Providers from "./providers";
import { ThemeSwitcher } from "./ThemeSwitcher";

export const metadata = {
title: "Create Next App"
Expand All @@ -9,8 +10,9 @@ export const metadata = {
// pages/_app.tsx와 pages/_document.tsx 파일 대체
const RootLayout = ({ children }: { children: ReactNode }) => {
return (
<html lang="ko">
<html lang="ko" className={"light"}>
<body>
<ThemeSwitcher />
<Providers>{children}</Providers>
</body>
</html>
Expand Down
5 changes: 4 additions & 1 deletion next.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// eslint-disable-next-line @typescript-eslint/no-var-requires
const withLinaria = require("next-with-linaria");

/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
Expand All @@ -7,4 +10,4 @@ const nextConfig = {
}
};

module.exports = nextConfig;
module.exports = withLinaria(nextConfig);
36 changes: 21 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"test:storybook": "test-storybook",
"e2e": "playwright test",
"report": "playwright show-report",
"storybook": "start-storybook -p 6006",
"build-storybook": "build-storybook",
"storybook": "storybook dev -p 6006",
"build-storybook": "storybook build",
"chromatic": "chromatic --exit-zero-on-changes",
"gen": "rm -r src/api/generated && orval",
"tt:global": "npx token-transformer tokens.json ./src/tokens/global.json global",
Expand All @@ -34,8 +34,11 @@
]
},
"dependencies": {
"@linaria/core": "^4.2.9",
"@linaria/react": "^4.3.7",
"axios": "^1.3.4",
"next": "13.2.3",
"next-with-linaria": "^0.5.0",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-query": "^3.39.3",
Expand All @@ -45,19 +48,20 @@
"devDependencies": {
"@babel/core": "^7.21.3",
"@faker-js/faker": "^7.6.0",
"@linaria/babel-preset": "^4.4.4",
"@linaria/webpack-loader": "^4.1.16",
"@playwright/test": "^1.32.1",
"@storybook/addon-a11y": "^6.5.16",
"@storybook/addon-actions": "^6.5.16",
"@storybook/addon-docs": "^6.5.16",
"@storybook/addon-essentials": "^6.5.16",
"@storybook/addon-interactions": "^6.5.16",
"@storybook/addon-links": "^6.5.16",
"@storybook/builder-webpack5": "^6.5.16",
"@storybook/jest": "^0.0.10",
"@storybook/manager-webpack5": "^6.5.16",
"@storybook/react": "^6.5.16",
"@storybook/test-runner": "^0.9.4",
"@storybook/testing-library": "^0.0.13",
"@storybook/addon-a11y": "^7.0.8",
"@storybook/addon-actions": "^7.0.8",
"@storybook/addon-docs": "^7.0.8",
"@storybook/addon-essentials": "^7.0.8",
"@storybook/addon-interactions": "^7.0.8",
"@storybook/addon-links": "^7.0.8",
"@storybook/jest": "^0.1.0",
"@storybook/nextjs": "^7.0.8",
"@storybook/react": "^7.0.8",
"@storybook/test-runner": "^0.10.0",
"@storybook/testing-library": "^0.1.0",
"@testing-library/jest-dom": "5.16.5",
"@testing-library/react": "14.0.0",
"@types/axios": "^0.14.0",
Expand Down Expand Up @@ -87,10 +91,12 @@
"jest": "29.5.0",
"jest-environment-jsdom": "29.5.0",
"lint-staged": "^13.1.2",
"mini-css-extract-plugin": "^2.7.5",
"msw": "^1.1.0",
"orval": "^6.12.1",
"prettier": "^2.8.4",
"storybook-dark-mode": "^2.1.1",
"storybook": "^7.0.8",
"storybook-dark-mode": "^3.0.0",
"ts-jest": "29.0.5",
"typescript": "^4.9.5"
}
Expand Down
Loading

0 comments on commit 8e2c869

Please sign in to comment.