๐Ÿ“Frontend/๐Ÿ“•CSS

[Styled Components] ์„ธํŒ…

Hoon2 2022. 8. 7. 19:27
728x90

*์„ค์น˜ : 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();

 

์ฐธ๊ณ  : https://velog.io/@taylorkwon92/React-TypeScript-Styled-Components-%EC%B4%88%EA%B8%B0-%EC%84%B8%ED%8C%85%ED%95%98%EA%B8%B0

 

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

 

728x90