[Styled Components] ์ธํ
*์ค์น : yarn add styled-components, yarn add styled-reset(์ด๊ธฐ์ค์ )
์ธํ
- styles ํด๋ ๋ด๋ถ์ GlobalStyle.js, GlobalFonts.js, theme.js(๋ฐ์ํ) ํ์ผ ์์ฑ
- GlobalStyle
import { createGlobalStyle } from 'styled-components';
const GlobalStyle = createGlobalStyle`
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, menu, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
main, menu, nav, output, ruby, section, summary,
time, mark, audio, video {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure,
footer, header, hgroup, main, menu, nav, section {
display: block;
}
/* HTML5 hidden-attribute fix for newer browsers */
*[hidden] {
display: none;
}
body {
line-height: 1;
}
menu, ol, ul {
list-style: none;
}
blockquote, q {
quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
content: '';
content: none;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
* {
box-sizing: border-box;
}
body {
font-weight: 300;
font-family: 'Source Sans Pro', sans-serif;
line-height: 1.2;
}
a {
text-decoration:none;
color:inherit;
}`;
export default GlobalStyle;
- GlobalFonts.js
import { createGlobalStyle } from 'styled-components';
import ํฐํธ๋ช
from 'ํฐํธ ํ์ผ';
export default createGlobalStyle`
@font-face {
font-family: 'ํฐํธ๋ช
';
src: local('ํฐํธ๋ช
'),
url(${ํฐํธ๋ช
}) format('woff');
font-weight: 300;
font-style: normal;
}
`;
- theme.js
const size = {
mobile: '600px',
tablet: '900px',
laptop: '1200px',
desktop: '1800px',
};
const theme = {
mainColor: '#0a4297',
mobile: `(max-width: ${size.mobile})`,
tablet: `(max-width: ${size.tablet})`,
laptop: `(max-width: ${size.laptop})`,
desktop: `(min-width: ${size.desktop})`,
};
export default theme;
- index.js ํ์ผ์ ์ ์ฉ์ํค๊ธฐ (themeProvider๋ ๋จ์ผ์์๋ง ์์ด์ผํจ, style์ ๊ฐ์ฅ ์์ ์ ์ฉ
import React from 'react';
import ReactDOM from 'react-dom/client';
import GlobalStyle from './styles/GlobalStyles';
import GlobalFonts from './styles/fonts';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
<React.StrictMode>
<GlobalStyle />
<GlobalFonts />
<App />
</React.StrictMode>
);
reportWebVitals();
React + TypeScript + Styled-Components ์ด๊ธฐ ์ธํ ํ๊ธฐ
์ค์นํ๋ฉด ์ด์ ๊ฐ์ ํ๋ฉด ์ํ๋ฅผ ๋ณผ ์ ์๋ค.์์ด๋ ๋๋ ํ์ผ ๋ฆฌ์คํธsetupTests.tslogo.svgserviceWorker.tsApp.test.tsx"baseUrl": "src" ์คํ์ผ ๋ฆฌ์ ํจํค์ง ์ค์นํ๊ธฐ ๋ฐ styles ํด๋ ๋ง๋ค๊ธฐstyles ํด๋ ๋ด๋ถ์ G
velog.io
ํฐํธ : https://velog.io/@mokyoungg/Styled-Components-import-font
[Styled-Components] import font
๋ด์ฉ์ ๋ชจ๋ ์ถ์ฒ๋ ์ด๊ณณ์ ๋๋ค. https://dev.to/alaskaa/how-to-import-a-web-font-into-your-react-app-with-styled-components-4-1dni ๊ฐ์ธ ํ๋ก์ ํธ๋ฅผ ์งํํ๋ ์ค google font์๋ ์๋ font๋ฅผ ์จ์ผํ๋ ์ผ์ด ์๊ฒผ๋ค. styled-com
velog.io