Skip to content

Commit

Permalink
feat(packages/ui): Icon 컴포넌트
Browse files Browse the repository at this point in the history
  • Loading branch information
kongnayeon committed Jan 8, 2025
1 parent f862424 commit 33b4d38
Show file tree
Hide file tree
Showing 12 changed files with 559 additions and 21 deletions.
7 changes: 5 additions & 2 deletions apps/web/next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { createVanillaExtractPlugin } from '@vanilla-extract/next-plugin';
const withVanillaExtract = createVanillaExtractPlugin();

/** @type {import('next').NextConfig} */
const nextConfig = {};
// TODO 디자인 시스템 패키지 추가 필요
// https://vanilla-extract.style/documentation/integrations/next/
const nextConfig = {
transpilePackages: ['@repo/ui', '@repo/theme'],
};

export default withVanillaExtract(nextConfig);
3 changes: 3 additions & 0 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "web",
"version": "0.1.0",
"private": true,
"type": "module",
"scripts": {
"dev": "next dev",
"build": "next build",
Expand All @@ -19,6 +20,8 @@
"devDependencies": {
"@repo/eslint-config": "workspace:*",
"@repo/typescript-config": "workspace:*",
"@repo/theme": "workspace:*",
"@repo/ui": "workspace:*",
"@types/node": "^20.11.24",
"@types/react": "18.3.0",
"@types/react-dom": "18.3.1",
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { Metadata } from 'next';
import localFont from 'next/font/local';
import './globals.css';
import '@repo/theme/styles';
//import '@repo/ui/styles';
import '@repo/ui/styles';
import { ThemeProvider } from '@repo/theme';

const geistSans = localFont({
Expand Down
9 changes: 8 additions & 1 deletion apps/web/src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
import { Icon } from '@repo/ui';

export default function Home() {
return <div>웹 1팀 파이팅!</div>;
return (
<div>
웹 1팀 파이팅!
<Icon width={100} height={100} name="stack" fill="semantic.blue" />
</div>
);
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
},
"dependencies": {
"@vanilla-extract/css": "^1.17.0",
"@vanilla-extract/dynamic": "^2.1.2",
"@vanilla-extract/recipes": "^0.5.5"
}
}
3 changes: 3 additions & 0 deletions packages/theme/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"name": "@repo/theme",
"version": "0.0.0",
"private": true,
"main": "./dist/index.js",
"type": "module",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"exports": {
".": {
Expand Down
11 changes: 11 additions & 0 deletions packages/ui/src/components/Icon/Icon.css.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { style, createVar, globalStyle } from '@vanilla-extract/css';

export const strokeColor = createVar();
export const fillColor = createVar();

export const parent = style({});

globalStyle(`.${parent} path`, {
stroke: strokeColor,
fill: fillColor,
});
53 changes: 53 additions & 0 deletions packages/ui/src/components/Icon/Icon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { FC, SVGProps } from 'react';
import { icons } from './assets';
import { tokens } from '@repo/theme';
import * as styles from './Icon.css';
import { assignInlineVars } from '@vanilla-extract/dynamic';

type IconName = keyof typeof icons;

type Colors = typeof tokens.colors;

type ColorType =
| `primary.${keyof Colors['primary']}`
| `semantic.${keyof Colors['semantic']}`
| `grey.${keyof Colors['grey']}`;

interface IconProps extends SVGProps<SVGSVGElement> {
name: IconName;
fill?: ColorType;
stroke?: ColorType;
}

export const Icon: FC<IconProps> = ({
name,
stroke,
fill,
...rest
}: IconProps) => {
const SVG = icons[name] as FC<SVGProps<SVGSVGElement>>;

const getColor = (color?: ColorType): string => {
if (!color) return 'transparent';
const [category, key] = color.split('.') as [keyof Colors, string];
return tokens.colors[category][key as keyof Colors[typeof category]];
};

const resolvedFill = getColor(fill) || 'transparent';
const resolvedStroke = getColor(stroke) || 'transparent';

return (
<SVG
className={styles.parent}
style={JSON.parse(
JSON.stringify(
assignInlineVars({
[styles.strokeColor]: resolvedStroke,
[styles.fillColor]: resolvedFill,
})
)
)}
{...rest}
/>
);
};
2 changes: 1 addition & 1 deletion packages/ui/src/components/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
//export * from './TestComponent';
export * from './Icon/Icon';
1 change: 0 additions & 1 deletion packages/ui/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export * from './components';
export * from './icons';
2 changes: 1 addition & 1 deletion packages/ui/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
"outDir": "./dist",
"declaration": true
},
"include": ["src/**/*"],
"include": ["src/**/*", "global.d.ts"],
"exclude": ["node_modules", "dist"]
}
Loading

0 comments on commit 33b4d38

Please sign in to comment.