Skip to content

Commit

Permalink
feat: rollup 설정 (#50)
Browse files Browse the repository at this point in the history
* chore: 자잘한 코드 수정

* feat: set rollup config

* fix: storybook autodocs 설명이 안보이는 문제 해결

패키지 루트 대신 컴포넌트를  직접 참조하도록 변경

* chore: Test 컴포넌트 내보내기

* fix: rollup 패키지들 버전 다운그레이드

* feat: "use client" 지시어 유지되도록 설정

* chore: ve 설정 제거

* chore: toast docs 수정

* chore: 큰따옴표 수정

* style: toast style 수정

---------

Co-authored-by: solar3070 <>
  • Loading branch information
solar3070 authored Feb 23, 2024
1 parent 162d606 commit adf7d2f
Show file tree
Hide file tree
Showing 16 changed files with 535 additions and 86 deletions.
2 changes: 1 addition & 1 deletion apps/docs/src/stories/Button.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Meta, StoryObj } from '@storybook/react';
import { Button } from 'ui';
import Button from 'ui/Button';

interface ButtonOwnProps {
size?: 'sm' | 'md' | 'lg';
Expand Down
11 changes: 7 additions & 4 deletions apps/docs/src/stories/Dialog.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { Meta, StoryFn, StoryObj } from '@storybook/react';

import { useContext } from 'react';
import { Dialog } from 'ui';
import DialogProvider, { DialogContext } from 'ui/Dialog/DialogProvider';
import { DialogOptionType } from 'ui/Dialog/types';
import useDialog from '../../../../packages/ui/Dialog/useDialog';
import {
Dialog,
DialogProvider,
DialogContext,
type DialogOptionType,
useDialog,
} from 'ui/Dialog';

export default {
title: 'Components/Dialog',
Expand Down
77 changes: 56 additions & 21 deletions apps/docs/src/stories/Toast.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Meta, StoryObj, StoryFn } from "@storybook/react";
import { useToast, ToastProvider, type ToastOptionType } from "ui";
import { IconArchive } from "../../../../packages/icons/src";
import { IconCopy } from "../../../../packages/icons/src";
import ToastComponent from "ui/Toast/Toast";

const meta: Meta = {
Expand All @@ -12,10 +12,11 @@ const meta: Meta = {
control: "radio",
options: ["success", "alert", "error", "custom"],
description: "토스트의 아이콘을 지정합니다.",
mapping: { custom: <IconArchive /> },
mapping: { custom: <IconCopy /> },
table: {
defaultValue: { summary: "success" },
type: { summary: "success | alert | error | ReactElement" },
type: {
summary: "success | alert | error | ReactElement",
},
},
},
content: { description: "토스트의 내용을 작성합니다." },
Expand All @@ -41,7 +42,7 @@ export default meta;
export const Component: StoryObj = {
args: {
icon: "success",
content: "Default Toast",
content: "프로젝트가 등록되었어요.",
action: { name: "보러가기", onClick: () => {} },
style: {
root: { position: "static", animation: "none", transform: "none" },
Expand All @@ -54,64 +55,98 @@ const ToastSample = ({ option }: { option: ToastOptionType }) => {
return <button onClick={() => open(option)}>Open Toast</button>;
};

export const DefaultSuccess: StoryObj = {
name: "Default - Success",
export const Default: StoryObj = {
name: "Default",

Check warning on line 59 in apps/docs/src/stories/Toast.stories.tsx

View workflow job for this annotation

GitHub Actions / Release

Named exports should not use the name annotation if it is redundant to the name that would be generated by the export name
argTypes: { icon: { control: { disable: true } } },
render: () => {
const option: ToastOptionType = {
content: "저는 토스트예요.",
};
return <ToastSample option={option} />;
},
};

export const SuccessIcon: StoryObj = {
name: "Icon - Success ",
argTypes: { icon: { control: { disable: true } } },
render: () => {
const option: ToastOptionType = {
icon: "success",
content: "기본 토스트입니다.",
content: "프로젝트가 등록되었어요.",
};
return <ToastSample option={option} />;
},
};

export const TextOverAlert: StoryObj = {
name: "Text Over - Alert",
export const AlertIcon: StoryObj = {
name: "Icon - Alert",
argTypes: { icon: { control: { disable: true } } },
render: () => {
const option: ToastOptionType = {
icon: "alert",
content:
"토스트 내용은 두 줄을 초과할 수 없습니다. 토스트 내용은 두 줄을 초과할 수 없습니다. 토스트 내용은 두 줄을 초과할 수 없습니다. ",
content: "이메일을 입력해주세요.",
};
return <ToastSample option={option} />;
},
};

export const ActionButtonError: StoryObj = {
name: "Action Button - Error",
export const ErrorIcon: StoryObj = {
name: "Icon - Error",
argTypes: { icon: { control: { disable: true } } },
render: () => {
const option: ToastOptionType = {
icon: "error",
content: "액션 버튼이 있는 토스트입니다.",
action: { name: "보러가기", onClick: () => {} },
content: "프로젝트 수정에 실패했어요.",
};
return <ToastSample option={option} />;
},
};

export const ActionButtonCustomIcon: StoryObj = {
name: "Action Button - Custom Icon",
export const CustomIcon: StoryObj = {
name: "Icon - Custom",
argTypes: { icon: { control: { disable: true } } },
render: () => {
const option: ToastOptionType = {
icon: <IconArchive />,
content: "커스텀 아이콘을 사용한 토스트입니다.",
icon: <IconCopy />,
content: "링크를 복사했어요.",
};
return <ToastSample option={option} />;
},
};

export const ActionButton: StoryObj = {
name: "Action Button",

Check warning on line 118 in apps/docs/src/stories/Toast.stories.tsx

View workflow job for this annotation

GitHub Actions / Release

Named exports should not use the name annotation if it is redundant to the name that would be generated by the export name
argTypes: { icon: { control: { disable: true } } },
render: () => {
const option: ToastOptionType = {
icon: "success",
content: "프로젝트가 등록되었어요.",
action: { name: "보러가기", onClick: () => {} },
};
return <ToastSample option={option} />;
},
};

export const TextOver: StoryObj = {
name: "Text Over",

Check warning on line 131 in apps/docs/src/stories/Toast.stories.tsx

View workflow job for this annotation

GitHub Actions / Release

Named exports should not use the name annotation if it is redundant to the name that would be generated by the export name
argTypes: { icon: { control: { disable: true } } },
render: () => {
const option: ToastOptionType = {
icon: "alert",
content:
"토스트 내용은 두 줄을 초과할 수 없습니다. 토스트 내용은 두 줄을 초과할 수 없습니다. 토스트 내용은 두 줄을 초과할 수 없습니다. ",
};
return <ToastSample option={option} />;
},
};

export const CloseToast: StoryObj = {
name: "CloseToast",
argTypes: { icon: { control: { disable: true } } },
render: () => {
const { open, close } = useToast();

Check failure on line 147 in apps/docs/src/stories/Toast.stories.tsx

View workflow job for this annotation

GitHub Actions / Release

React Hook "useToast" is called in function "render" that is neither a React function component nor a custom React Hook function. React component names must start with an uppercase letter. React Hook names must start with the word "use"
const option: ToastOptionType = {
icon: "alert",
icon: "success",
content: "토스트를 원하는 타이밍에 닫을 수 있습니다.",
};
return (
Expand Down
10 changes: 1 addition & 9 deletions apps/web/next.config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
const {
createVanillaExtractPlugin
} = require('@vanilla-extract/next-plugin');
const withVanillaExtract = createVanillaExtractPlugin();

/** @type {import('next').NextConfig} */
const nextConfig = {
module.exports = {
reactStrictMode: true,
transpilePackages: ["ui"],
};

module.exports = withVanillaExtract(nextConfig);
2 changes: 1 addition & 1 deletion packages/ui/CheckBox/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { InputHTMLAttributes, forwardRef } from 'react';
import { IconCheck } from '../../icons/src';
import IconCheck from '../../icons/src/Icon/Interaction/ic-check';
import {
check,
checkBox,
Expand Down
2 changes: 2 additions & 0 deletions packages/ui/Dialog/Dialog.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"use client";

import { FC } from 'react';

import * as Dialogs from '@radix-ui/react-dialog';
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/Dialog/DialogProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'use client';
"use client";

import { createContext, useEffect, useState } from 'react';
import { DialogComponent } from './DialogComponent';
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/Toast/Toast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as Toast from "./parts";
import { ToastOptionType } from "./types";

function ToastComponent(props: ToastOptionType, ref: React.Ref<HTMLDivElement>) {
const { icon = "success", content, action, style } = props;
const { icon, content, action, style } = props;

return (
<Toast.Root ref={ref} style={style?.root} icon={icon}>
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/Toast/ToastProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const ToastContext = createContext({
function ToastProvider({ children }: Children) {
const [toastOption, setToastOption] = useState<ToastOptionType | null>(null);
const timerRef = useRef<NodeJS.Timeout>();
const toastRef = useRef<HTMLDivElement>();
const toastRef = useRef<HTMLDivElement>(null);

const openToast = (option: ToastOptionType) => {
if (toastOption) return;
Expand Down
4 changes: 2 additions & 2 deletions packages/ui/Toast/parts/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const convertToIcon = {
};

interface RootProps {
icon: DefaultIconType | React.ReactElement;
icon?: DefaultIconType | React.ReactElement;
style?: React.CSSProperties;
}

Expand All @@ -26,7 +26,7 @@ function Root(props: StrictPropsWithChildren<RootProps>, ref: React.Ref<HTMLDivE
{DefaultIcon ? (
<DefaultIcon />
) : (
<div className={styles.icon}>{icon}</div>
icon && <div className={styles.icon}>{icon}</div>
)}
{children}
</div>
Expand Down
5 changes: 3 additions & 2 deletions packages/ui/Toast/parts/style.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ export const root = style({

position: "fixed",
top: "var(--mds-toast-top, 36px)",
left: "50%",
left: "calc(50% - 16px)",
transform: "translateX(-50%)",
transition: "transform .2s linear",

width: "var(--mds-toast-width, 380px)",
margin: "0 16px",
padding: "14px 16px",
borderRadius: "18px",
backgroundColor: theme.colors.gray10,
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/cssVariables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const desktopVariables = `:root {
}`;

export const mobileVariables = `:root {
--mds-toast-width: 343px;
--mds-toast-width: min(calc(100% - 32px), 343px);
--mds-toast-top: 16px;
--mds-dialog-container-padding:20px;
Expand Down
2 changes: 2 additions & 0 deletions packages/ui/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ export type { DialogOptionType } from "./Dialog";
export { ToastProvider, useToast } from "./Toast";
export type { ToastOptionType } from "./Toast";

// test component
export { default as Test } from "./Test";
13 changes: 10 additions & 3 deletions packages/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,32 @@
"name": "ui",
"version": "0.0.0",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"module": "./dist/esm/index.js",
"types": "./dist/index.d.ts",
"license": "MIT",
"scripts": {
"build": "tsup index.ts cssVariables.ts --format cjs,esm --dts && yarn build-css-modules",
"build": "yarn clean && rollup -c && yarn build-css-modules",
"clean": "rm -rf dist desktop-variables.css mobile-variables.css",
"build-css-modules": "node ./scripts/build-css-modules.js",
"lint": "eslint .",
"generate:component": "turbo gen react-component"
},
"devDependencies": {
"@rollup/plugin-json": "^4.1.0",
"@turbo/gen": "^1.10.12",
"@types/node": "^20.5.2",
"@types/react": "^18.2.0",
"@types/react-dom": "^18.2.0",
"@vanilla-extract/css": "^1.14.0",
"@vanilla-extract/rollup-plugin": "^1.0.1",
"eslint-config-custom": "*",
"react": "^18.2.0",
"rollup": "^2.70.1",
"rollup-plugin-dts": "^4.2.0",
"rollup-plugin-esbuild": "^4.8.2",
"rollup-plugin-node-externals": "^4.0.0",
"rollup-plugin-preserve-directives": "^0.4.0",
"tsconfig": "*",
"tsup": "^8.0.1",
"typescript": "^4.5.2"
},
"dependencies": {
Expand Down
89 changes: 89 additions & 0 deletions packages/ui/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import json from "@rollup/plugin-json";
import { vanillaExtractPlugin } from "@vanilla-extract/rollup-plugin";
import path from "path";
import dts from "rollup-plugin-dts";
import esbuild from "rollup-plugin-esbuild";
import nodeExternals from "rollup-plugin-node-externals";
import ts from "typescript";
import preserveDirectives from "rollup-plugin-preserve-directives";

const loadCompilerOptions = (tsconfig) => {
if (!tsconfig) return {};
const configFile = ts.readConfigFile(tsconfig, ts.sys.readFile);
const { options } = ts.parseJsonConfigFileContent(
configFile.config,
ts.sys,
"./"
);
return options;
};

const compilerOptions = loadCompilerOptions("tsconfig.json");

const plugins = [
vanillaExtractPlugin(),
nodeExternals(),
esbuild(),
json(),
preserveDirectives(),
];

const dirSrc = [
["dist", "cjs"],
["dist/esm", "esm"],
];

export default [
...dirSrc.map(([dir, format]) => {
return {
input: ["index.ts", "cssVariables.ts"],
plugins,
output: {
dir,
format,
preserveModules: true,
preserveModulesRoot: ".",
entryFileNames({ name }) {
return `${name.replace(/\.css$/, ".css.vanilla")}.js`;
},
assetFileNames({ name }) {
return name;
},
exports: "named",
},
onwarn(warning, warn) {
const errorCode = ["MODULE_LEVEL_DIRECTIVE", "SOURCEMAP_ERROR"];
if (!errorCode.includes(warning.code)) {
warn(warning);
}
},
};
}),
// Declaration files
{
input: ["index.ts", "cssVariables.ts"],
plugins: [
...plugins,
dts({
compilerOptions: {
...compilerOptions,
baseUrl: path.resolve(compilerOptions.baseUrl || "."),
declaration: true,
noEmit: false,
emitDeclarationOnly: true,
noEmitOnError: true,
target: ts.ScriptTarget.ESNext,
},
}),
],
output: [
{
dir: "dist",
format: "esm",
preserveModules: true,
preserveModulesRoot: ".",
},
],
},
];

Loading

0 comments on commit adf7d2f

Please sign in to comment.