Sass는 CSS pre-processor(전처리기)로써 복잡한 작업을 쉽게 할 수 있게 해주고, 코드의 재활용성을 높여줄 뿐만 아니라, 코드의 가독성을 높여주어 유지보수를 쉽게 해줍니다.
Sass Guidelines — Korean translation
분별 있고, 유지∙확장 가능한 Sass 작성을 위한 주관적인 스타일가이드.
sass-guidelin.es
sass설치
$ yarn add node-sass
색상관련 git
Open Color
Color scheme for UI design
yeun.github.io
@mixin name {}
여러 중복되는 코드를 방지하기 위해 써주는 문법 중 하나.
@mixin button-color($color) {
background-color: $color;
&:hover{
background-color: lighten($color, 10%); // 색상을 10% 밝게
}
&:active {
background-color: darken($color, 10%); // 색상을 10% 어둡게
}
}
&.blue {
@include button-color($blue)
}
조건부 스타일링을 할 때 className을 직접 조합해주는 것보다 편하게 작성해주는 모듈
설치방법
$ yarn add classnames
classNames("Button", "red"); 👉🏻 <className="Button red">
classNames("Button", {red:true}); 👉🏻 <className="Button red (false일 경우 Button만 나옴)">
classNames({Button:true}, {red:true}) 👉🏻 <className="Button red (Button만 true일 경우 Button만 나옴)">
import classNames from "classnames";
<button className={classNames("Button", size, color)}>{children}</button>
CSS Module
- 리액트 프로젝트에서 컴포넌트를 스타일링 할 때 CSS 클래스가 중첩되는 것을 방지
- CRA(Create React App)프로젝트에서 CSS Module을 사용할 때에는 CSS 파일의 확장자를 .module.css로 만들면 됩니다.
- 파일경로, 파일이름, 클래스이름, 해쉬값등 사용
PostCSS - a tool for transforming CSS with JavaScript
Enforce consistent conventions and avoid errors in your stylesheets with stylelint, a modern CSS linter. It supports the latest CSS syntax, as well as CSS-like syntaxes, such as SCSS.
postcss.org
styled-components
- JS안에 CSS를 작성하는 것
- styled-components 라이브러리를 사용(emotion, styled-jsx ...)
- Tagged Template Literal 문법을 사용
https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Template_literals
Template literals - JavaScript | MDN
템플릿 리터럴은 내장된 표현식을 허용하는 문자열 리터럴입니다. 여러 줄로 이뤄진 문자열과 문자 보간기능을 사용할 수 있습니다. 이전 버전의 ES2015사양 명세에서는 "template strings" (템플릿 문
developer.mozilla.org
'Front-End > React' 카테고리의 다른 글
[React] react-async 라이브러리 (0) | 2021.06.01 |
---|---|
[React] class형 컴포넌트 (0) | 2021.05.21 |
[React] Immer를 사용한 불변성 지키기 (0) | 2021.05.20 |
[React]배열 렌더링하기 (0) | 2021.05.13 |
[React] ref: Dom에 이름 달기 (useRef) (0) | 2021.05.13 |
댓글