[SCSS] IBM Carbon Design System React ์ค์
https://carbondesignsystem.com/developing/react-tutorial/overview
Carbon Design System
Carbon is IBM’s open source design system for products and digital experiences. With the IBM Design Language as its foundation, the system consists of working code, design tools and resources, human interface guidelines, and a vibrant community of contri
carbondesignsystem.com
Carbon์ด๋?
Carbon์ IBM์ ๋์งํธ ์ ํ ๋ฐ ๊ฒฝํ์ ์ํ ์คํ์์ค ๋์์ธ ์์คํ ์ด๋ค.
์ด ์์คํ ์ ๋์งํธ ์ ํ ๋ฐ ๊ฒฝํ์ ๊ฐ๋ฐํ๋ ๋ฐ ๋์์ด ๋๋ ๋ค์ํ ์์๊ณผ ๋๊ตฌ๋ฅผ ์ ๊ณตํ๋ค.
์ด๋ฅผ ํตํด ๋์์ด๋์ ๊ฐ๋ฐ์๋ค์ ์ผ๊ด๋ ๋์์ธ ์์น์ ์ค์ํ๊ณ , ์ฌ์ฉ์ ๊ฒฝํ์ ํฅ์์ํค๋ฉฐ, ์ ํ์ ๋ณด๋ค ํจ์จ์ ์ผ๋ก ๊ฐ๋ฐํ ์ ์๋ค.
๋ํ Carbon์ IBM Design Language๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ํ์ฌ ๋์์ธ์ ์ผ๊ด์ฑ๊ณผ ํ์ง์ ์ ์งํฉ๋๋ค.
2๏ธโฃ Modular
Carbon์ ๋ชจ๋ํ๋์ด ์์ต๋๋ค.
Carbon์ ๋ชจ๋ํ๋ ์คํ์์ ์ต๋์ ์ ์ฐ์ฑ์ ๋ณด์ฅํ๋ค.
์นด๋ณธ์ ๊ตฌ์ฑ์์๋ ์ฌ์ฉ์์ ์๊ตฌ์ ๋ง๋ ์ด๋ค ์กฐํฉ์ผ๋ก๋ ์ํํ๊ฒ ์๋ํ๋๋ก ์ค๊ณ๋์๋ค.
3๏ธโฃ Consistent
Carbon์ ์ผ๊ด์ฑ์ ์ ์งํ๋ค.
ํฌ๊ด์ ์ธ IBM ๋์์ธ ์ธ์ด๋ฅผ ๊ธฐ๋ฐ์ผ๋ก, ์นด๋ณธ์ ๋ชจ๋ ์์์ ๊ตฌ์ฑ์์๋ ์ผ๊ด๋๊ณ ์์ง๋ ฅ ์๋ ์ฌ์ฉ์ ๊ฒฝํ์ ๋ณด์ฅํ๊ธฐ ์ํด ์ฒ์๋ถํฐ ํจ๊ป ์๋ํ๋๋ก ์ค๊ณ๋์๋ค.
React์ ์ ์ฉํด๋ณด๊ธฐ
https://carbondesignsystem.com/developing/react-tutorial/step-1#fork-clone-and-branch
Carbon Design System
Carbon is IBM’s open source design system for products and digital experiences. With the IBM Design Language as its foundation, the system consists of working code, design tools and resources, human interface guidelines, and a vibrant community of contri
carbondesignsystem.com
์ค์น
carbon ์ค์น
yarn add @carbon/react@1.33.0
# ํน์
npm install @carbon/react@1.33.0
sass ์ค์น
yarn add sass@1.63.6
# ํน์
npm install sass@1.63.6
Carbon์ ์คํ์ผ์ด Sass๋ก ์์ฑ๋์ด ์๊ธฐ ๋๋ฌธ์ Sass ๋น๋๋ฅผ ์คํํด์ผ ํ๋ค.
์ค์น๊ฐ ์๋ฃ๋์์ผ๋ ์ฌ์ฉํด๋ณด์.
์ฝ๋ ์์ฑ
scss ์ฝ๋
AppTest.scss
// ์ํ๋ ๋ฒํผ ์์ ๋ณ์ ์ ์
$myButtonColor: blue;
// Button ์ปดํฌ๋ํธ์ ์คํ์ผ ์ ์ฉ
.MyButton {
background-color: $myButtonColor;
color: white;
border: none;
padding: 10px 20px;
border-radius: 5px;
cursor: pointer;
}
// Button ์ปดํฌ๋ํธ์ ํธ๋ฒ ํจ๊ณผ ์ ์ฉ
.MyButton:hover {
background-color: darken($myButtonColor, 10%);
}
Javascript ์ฝ๋
App.js
import './App.css';
import './style/AppTest.scss';
import { Button } from '@carbon/react';
function App() {
return (
<div>
<Button className="MyButton">button</Button>
</div>
);
}
export default App;
์ ์ฝ๋๋ฅผ ์คํํ๋ฉด ์ด๋ ๊ฒ ๋ณด์ธ๋ค.
๋ถํธ์คํธ๋ฉ์ฒ๋ผ ์ฌ๋ฌ๊ฐ์ง ๋ฒํผ ๋ชจ์์ด ์์ ์ค ์์๋ค.
(EX. btn-primary ํ๋ฉด ๊ธฐ๋ณธ ๋ฒํผ ๋ชจ์์ด ์กํ๋ ๊ฒ)
ํ์ง๋ง carbon์๋ ๊ธฐ๋ณธ ๋์์ธ ๋ชจ์์ ์๋ ๊ฒ ๊ฐ๊ณ , ์ง์ ๋์์ธ ์ค์ ์ ํด์ผ ํ๋ ๊ฒ ๊ฐ๋ค.
์ ์ญ scss ์ค์ ํ๊ธฐ
๋ง์ด ์ฐ์ด๋ ์ฝ๋๋ฅผ ์ ์ญ scss ํ์ผ์ ๋ชจ์์ ์ฌ์ฉํ ์ ์๋ค.
ํ์ผ ์ด๋ฆ์ global.scss๋ผ๊ณ ํ๊ฒ ๋ค.
src/app/globals.scss
@use '@carbon/react';
์ฒซ ์ค์ ์์ ๊ฐ์ด ์ ์ด์ค๋ค.
์๋ฅผ ๋ค์ด
src/components/TutorialHeader
โโโ_tutorial-header.scss
โโโTutorialHeader.js
ํด๋ ๊ตฌ์กฐ๊ฐ ์ด๋ ๊ฒ ๋์ด ์๋ค๋ฉด,
src/app/globals.scss ํ์ผ ์์ชฝ์ ์ ๋ฌธ์ฅ์ ์จ์ค๋ค.
@use '@carbon/react';
@use '@/components/TutorialHeader/tutorial-header';
๊ทธ๋ฆฌ๊ณ js์์ tutorial-header.scss๋ง importํ๋ฉด ๋๊ณ ,
global.scss๋ import ํด์ค์ง ์์๋ ๋๋ค.
TutorialHeader.js
import React from 'react';
import '@carbon/icons/css/16/fill.css'; // Carbon ์์ด์ฝ ์คํ์ผ import
import '@/components/TutorialHeader/tutorial-header.scss'; // ํค๋ ์ปดํฌ๋ํธ ์คํ์ผ import
function TutorialHeader() {
return (
<div className="tutorial-header">
<h1>Welcome to the Tutorial</h1>
<p>This is a tutorial header component.</p>
</div>
);
}
export default TutorialHeader;
CSS ์ SCSS ์ฐจ์ด
CSS
'.css' ํ์ฅ์๋ฅผ ๊ฐ์ง ์ผ๋ฐ์ ์ธ CSS ํ์ผ
๊ธฐ๋ณธ์ ์ผ๋ก ์คํ์ผ์ ์ ์ํ๋ ๋ฐ ์ฌ์ฉ
๋ณ์, mixin, nesting, ์์ ๋ฑ์ ๊ณ ๊ธ ๊ธฐ๋ฅ์ ์ง์ํ์ง ์๋๋ค.
SCSS
'scss' ํ์ฅ์๋ฅผ ๊ฐ์ง SCSS(Sassy CSS)ํ์ผ์ด๋ค.
CSS์ ํ์ฅ์ผ๋ก CSS ๋ฌธ๋ฒ์ ํ์ฅํ์ฌ ๋ ํ๋ถํ ๊ธฐ๋ฅ์ ์ ๊ณตํ๋ค.
๋ณ์, mxin, nesting, ์์ ๋ฑ๊ณผ ๊ฐ์ CSS ์ ์ฒ๋ฆฌ๊ธฐ ๊ธฐ๋ฅ์ ์ฌ์ฉํ ์ ์๋ค.
CSS ์์ฑ์ด ๋ ํจ์จ์ ์ด๊ณ ์ ์ง๋ณด์ํ๊ธฐ ์ฌ์์ง๋ค.
→ '.scss' ํ์ผ์ด '.css' ํ์ผ๋ณด๋ค ๋ ๋ง์ ๊ธฐ๋ฅ์ ์ ๊ณตํ๋ฉฐ, ํ๋ก์ ํธ์ ์๊ตฌ์ ๋ฐ๋ผ ์ ํํ ์ ์๋ค.
SCSS์ ์ปดํ์ผ ๊ณผ์
SCSS ํ์ผ ์์ฑ → SCSS ํ์ผ์ CSS ํ์ผ๋ก ์ปดํ์ผ → CSS ํ์ผ ์ ์ฉ