일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- CSS
- AI
- es6
- JS
- ES5+
- developerlife
- object
- git
- gitCLI
- This
- learn next.js
- react
- array
- DOM
- 선택자
- next.js
- html5
- github
- 함수
- 우아한테코톡
- ES6+
- Python
- API
- 변수
- JavaScript
- 햇소
- 최적화
- hooks
- dev
- hatso
Archives
- Today
- Total
codinghatso
styled-components를 활용하여 일관된 디자인 시스템을 구축하기 본문
Theme 정의하는 방법
테마 객체를 만들어 일관성 있는 디자인 시스템을 구축하는 방법입니다.
유지보수가 용이하며, 생산력을 높여줄 수 있는 방법입니다.
// theme.js
export const theme = {
colors: {
primary: '#3498db',
secondary: '#2ecc71',
text: '#333',
background: '#ecf0f1',
},
spacing: {
small: '8px',
medium: '16px',
large: '24px',
},
};
// App.js
import React from 'react';
import { ThemeProvider } from 'styled-components';
import { theme } from './theme';
import MyStyledComponent from './MyStyledComponent';
const App = () => {
return (
<ThemeProvider theme={theme}>
<MyStyledComponent />
{/* 다른 컴포넌트들 */}
</ThemeProvider>
);
};
export default App;
사용 예시
// MyStyledComponent.js
import styled from 'styled-components';
const MyStyledComponent = styled.div`
background-color: ${props => props.theme.colors.background};
color: ${props => props.theme.colors.text};
margin: ${props => props.theme.spacing.medium};
`;
export default MyStyledComponent;
처음 css를 접했을 때는 엉망으로 사용했었는데 공부를 계속하다 보니 속성 값을 변수처럼 가져다가 사용하는 방법을 알게 되었고, 개발과정이 체계화되어간다는 느낌을 받아 스스로 뿌듯함을 느꼈던 경험이 있습니다.
'WEB > React' 카테고리의 다른 글
Transient props란 무엇인가? (0) | 2024.01.17 |
---|---|
React에서 폰트 테마(Theme) 적용하기 (0) | 2024.01.12 |
useReducer - React Hooks (0) | 2023.11.30 |
useMemo -React Hooks (0) | 2023.11.09 |
useContext - React Hooks (0) | 2023.11.03 |
Comments