Skip to content

Commit

Permalink
feat: CSS Variable로 반응형 구현 (#39)
Browse files Browse the repository at this point in the history
* feat: 데스크탑 및 모바일 뷰 CSS Variable 추가

* chore: 파일 끝 빈 줄 추가

* fix: 컴포넌트 상대 경로 수정

* chore: 컴포넌트 주석 처리

---------

Co-authored-by: solar3070 <>
  • Loading branch information
solar3070 authored Jan 21, 2024
1 parent 25cc5f3 commit 071f581
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 15 deletions.
4 changes: 4 additions & 0 deletions packages/ui/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/node_modules/
/dist
.DS_Store
/*.css
4 changes: 4 additions & 0 deletions packages/ui/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/src/
/scripts/
.gitignore
tsconfig.json
6 changes: 3 additions & 3 deletions packages/ui/Toast/parts/style.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { keyframes, style } from "@vanilla-extract/css";
import theme from "../../theme.css";

const toastAnimation = keyframes({
"0%, 100%": { transform: "translate(-50%, calc(-100% - 36px))" },
"0%, 100%": { transform: "translate(-50%, calc(-100% - var(--mds-toast-top, 36px)))" },
"10%, 90%": { transform: "translate(-50%, 0)" },
});

Expand All @@ -14,12 +14,12 @@ export const root = style({
gap: "8px",

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

width: "380px",
width: "var(--mds-toast-width, 380px)",
padding: "14px 16px",
borderRadius: "18px",
backgroundColor: theme.colors.gray10,
Expand Down
4 changes: 2 additions & 2 deletions packages/ui/cssVariables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ export const desktopVariables = `:root {
--mds-dialog-title-font-weight:600;
--mds-dialog-title-font-line-height:30px;
--mds-dialog-title-font-letter-spacing:-2%;
--mds-dialog-title-margin-bottom:12;
--mds-dialog-description-font-family: SUIT;
--mds-dialog-description-font-size:16px;
--mds-dialog-description-font-style:normal;
--mds-dialog-description-font-weight:400;
--mds-dialog-description-font-line-height:26px;
--mds-dialog-description-font-letter-spacing:-1.5%;
}`;

export const mobileVariables = `:root {
Expand Down
8 changes: 8 additions & 0 deletions packages/ui/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export * from "./cssVariables";

// component exports
// export { default as Button } from "./Button";
// export { ToastProvider, useToast } from "./Toast";
// export type { ToastOptionType } from "./Toast";
// export { default as Test } from "./Test";
// export { default as Dialog } from "./Dialog";
6 changes: 0 additions & 6 deletions packages/ui/index.tsx

This file was deleted.

8 changes: 6 additions & 2 deletions packages/ui/package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
{
"name": "ui",
"version": "0.0.0",
"main": "./index.tsx",
"types": "./index.tsx",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"license": "MIT",
"scripts": {
"build": "tsup index.ts cssVariables.ts --format cjs,esm --dts && yarn build-css-modules",
"build-css-modules": "node ./scripts/build-css-modules.js",
"lint": "eslint .",
"generate:component": "turbo gen react-component"
},
Expand All @@ -17,6 +20,7 @@
"eslint-config-custom": "*",
"react": "^18.2.0",
"tsconfig": "*",
"tsup": "^8.0.1",
"typescript": "^4.5.2"
},
"dependencies": {
Expand Down
26 changes: 26 additions & 0 deletions packages/ui/scripts/build-css-modules.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const fs = require("fs");
const path = require("path");
const allVariables = require("../dist/cssVariables");
const outputDir = require("../tsconfig.json").compilerOptions.outDir;

Object.keys(allVariables).forEach((key) => {
const variableValues = Object.entries(allVariables).find(
([name]) => name === key
)[1];

fs.writeFileSync(
path.join(outputDir, toFileName(key) + ".css"),
`${variableValues}`
);
});

function toCssCasing(str) {
return str
.replace(/([a-z])/, "$1")
.replace(/([A-Z])/g, "-$1")
.toLowerCase();
}

function toFileName(str) {
return toCssCasing(str);
}
6 changes: 4 additions & 2 deletions packages/ui/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
{
"compilerOptions": {
"jsx": "react"
"jsx": "react-jsx",
"outDir": ".",
"allowSyntheticDefaultImports": true
},
"extends": "tsconfig/react-library.json",
"include": ["."],
"include": ["index.ts", "cssVariables.ts"],
"exclude": ["dist", "build", "node_modules"]
}
20 changes: 20 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10276,6 +10276,26 @@ tsup@^7.2.0:
sucrase "^3.20.3"
tree-kill "^1.2.2"

tsup@^8.0.1:
version "8.0.1"
resolved "https://registry.npmjs.org/tsup/-/tsup-8.0.1.tgz#04a0170f7bbe77e81da3b53006b0a40282291833"
integrity sha512-hvW7gUSG96j53ZTSlT4j/KL0q1Q2l6TqGBFc6/mu/L46IoNWqLLUzLRLP1R8Q7xrJTmkDxxDoojV5uCVs1sVOg==
dependencies:
bundle-require "^4.0.0"
cac "^6.7.12"
chokidar "^3.5.1"
debug "^4.3.1"
esbuild "^0.19.2"
execa "^5.0.0"
globby "^11.0.3"
joycon "^3.0.1"
postcss-load-config "^4.0.1"
resolve-from "^5.0.0"
rollup "^4.0.2"
source-map "0.8.0-beta.0"
sucrase "^3.20.3"
tree-kill "^1.2.2"

tsutils@^3.21.0:
version "3.21.0"
resolved "https://registry.yarnpkg.com/tsutils/-/tsutils-3.21.0.tgz#b48717d394cea6c1e096983eed58e9d61715b623"
Expand Down

0 comments on commit 071f581

Please sign in to comment.