๐Ÿค ์€์ง€log ๐Ÿค

[REACT] SCSS ๋ณธ๋ฌธ

๐Ÿ’™ React

[REACT] SCSS

Eun_zii 2022. 10. 6. 14:44

SCSS

sass๋Š” css์™€ ๋น„์Šทํ•˜๊ฒŒ App.scss ํŒŒ์ผ์„ ๋งŒ๋“ค์–ด scss ๋ฌธ๋ฒ•์— ๋งž๊ฒŒ ์ฝ”๋“œ ๋„ฃ๋Š”๊ฒƒ ์ด๋‹ค.

Sass๋Š” ๋‘๊ฐ€์ง€ ํ™•์žฅ์ž(.scss/.sass)๋ฅผ ์ง€์›ํ•˜๊ณ  ๐Ÿ“Œ npm install ์ž‘์—…์ด ํ•„์š”ํ•จ. ( node- sass ) ๐Ÿ“Œ

import styled, { css } from 'styled-components'

const Box = styled.div`
  background: ${(props) => props.color || 'blue'};
  padding: 1rem;
  display: flex;
`
//Box ์ปดํฌ๋„ŒํŠธ์— .color ๋ผ๋Š” props๊ฐ€ ์—†์œผ๋ฉด blue๊ฐ€ ๋œ๋‹ค-> ์ง€๊ธˆ์€ ์žˆ์œผ๋‹ˆ black

const Button = styled.button`
  background: white;
  color: black;
  border-radius: 4px;
  padding: 0.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  font-size: 1rem;
  font-weight: 600;

  &:hover {
    background: rgba(255, 255, 255, 0.9);
  }
  
${(props) =>
    props.inverted &&
    /* inverted๊ฐ’์ด true๋ฉด ๋ฐ‘ ์†์„ฑ๋“ค์ด ์ ์šฉ๋œ๋‹ค */
    css`
      background: none;
      border: 2px solid white;
      color: white;
      &:hover {
        background: white;
        color: black;
      }
    `}
  &+button {
    margin-left: 1rem;
  }
`

const StyledComponent = () => (
  <Box color="black">
    <Button>์•ˆ๋…•ํ•˜์„ธ์š”</Button>
    <Button inverted={true}>ํ…Œ๋‘๋ฆฌ๋งŒ</Button>
  </Box>
)

export default StyledComponent

 

 
728x90

'๐Ÿ’™ React' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

[REACT] ๋ฐ˜๋ณต ( Iteration )  (0) 2022.10.07
[REACT] HOOK  (0) 2022.10.07
[REACT] SPA ์™€ async  (0) 2022.10.06
[REACT] useEffect๊ฐ€ 2๋ฒˆ์‹คํ–‰๋ ๋•Œ  (0) 2022.10.06
[REACT] To-do List ๋งŒ๋“ค๊ธฐ  (0) 2022.10.06