Skip to content

Commit

Permalink
feat: theme, useTheme export문 추가 (#30)
Browse files Browse the repository at this point in the history
* feat: theme export문 추가

* 0.1.1

* chore: tsconfig 설정 수정

* 0.1.2

* chore: tsconfig 설정 수정

* 0.1.3

* chore: styled.d.ts 파일 src로 이동

* 0.1.4

* feat: useTheme 훅 추가

* feat: useTheme export  추가

* 0.1.5

* feat: theme 타입 설정

* 0.1.6

---------

Co-authored-by: Leejin-Yang <ejin1996@gmail.com>
  • Loading branch information
xodms0309 and Leejin-Yang committed Jul 17, 2023
1 parent 57afd4c commit c8f6c91
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@fun-eat/design-system",
"description": "펀잇 디자인시스템 라이브러리",
"version": "0.1.0",
"version": "0.1.6",
"main": "dist/index.js",
"module": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
16 changes: 16 additions & 0 deletions src/hooks/useTheme.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { useContext } from 'react';
import { ThemeContext } from 'styled-components';

import type { Theme } from '../styles/theme';

const useTheme = () => {
const theme = useContext(ThemeContext);

if (!theme) {
throw new Error('theme을 사용하려면 App을 FunEatProvider로 감싸주세요.');
}

return theme as Theme;
};

export default useTheme;
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export { default as FunEatProvider } from './FunEatProvider';
export { default as theme } from './styles/theme';
export { default as useTheme } from './hooks/useTheme';

export { default as Badge } from './Badge';
export { default as BottomSheet } from './BottomSheet';
Expand Down
2 changes: 1 addition & 1 deletion src/styles/styled.d.ts → src/styled.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type {
FontWeights,
LineHeights,
TextColors,
} from './theme';
} from './styles/theme';

declare module 'styled-components' {
export interface DefaultTheme {
Expand Down
5 changes: 2 additions & 3 deletions src/styles/theme.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import type { DefaultTheme } from 'styled-components';

export type Colors = typeof colors;
export type TextColors = typeof textColors;
export type BorderColors = typeof borderColors;
Expand Down Expand Up @@ -84,7 +82,7 @@ const borderRadius = {
xl: '14px',
} as const;

const theme: DefaultTheme = {
const theme = {
colors,
textColors,
borderColors,
Expand All @@ -99,5 +97,6 @@ const theme: DefaultTheme = {
};

export type ColorKeys = keyof typeof colors;
export type Theme = typeof theme;

export default theme;
7 changes: 4 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
"skipLibCheck": true,
"jsx": "react-jsx",
"declaration": true,
"outDir": "./dist"
"outDir": "./dist",
"rootDir": "src"
},
"include": ["src"],
"exclude": ["node_modules", "dist"]
"include": ["**/*.tsx", "**/*.ts", "styled.d.ts"],
"exclude": ["node_modules", "dist", "**/*.stories.tsx"]
}

0 comments on commit c8f6c91

Please sign in to comment.