Socket
Socket
Sign inDemoInstall

@karrotmarket/design-token

Package Overview
Dependencies
0
Maintainers
2
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @karrotmarket/design-token


Version published
Weekly downloads
230
increased by116.98%
Maintainers
2
Install size
40.0 kB
Created
Weekly downloads
Β 

Readme

Source

@karrotmarket/design-token

λ””μžμΈ 토큰이 λ¬΄μ—‡μΈκ°€μš”?

Design tokens are indivisible pieces of a design system such as colors, spacing, typography scale.

-- Design Token Working Group μ •μ˜

λ””μžμΈ 토큰은 μ—¬λŸ¬ λ””μžμΈ 도ꡬ, κ°œλ°œν™˜κ²½ 간에 λ””μžμΈ μ‹œμŠ€ν…œμ˜ μ΅œμ†Œ λ‹¨μœ„λ₯Ό κ³΅μœ ν•  수 μžˆλ„λ‘ ν‘œμ€€μ„ μ œκ³΅ν•˜λŠ” 것을 λͺ©ν‘œλ‘œ ν•©λ‹ˆλ‹€.

Goals & Non-goals

Goal

  • μƒν˜Έμš΄μš©μ„± 제곡
  • 라이브러리 배포만으둜 전체 μ• ν”Œλ¦¬μΌ€μ΄μ…˜μ— λ³€κ²½ 적용
  • λ””μžμΈ 도ꡬ와 효율적으둜 동기화

Non-goals

  • κ°œλ°œν•  λ•Œ νŽΈν•˜λ„λ‘ High-level API 제곡

Token Structures

λ””μžμΈ 토큰 계측ꡬ쑰

Raw valuesλŠ” μ–΄λ–€ λ””μŠ€ν”Œλ ˆμ΄ μž₯μΉ˜μ— 그릴 수 μžˆλŠ” μ‹€μ œ λ‹¨μœ„λ₯Ό μ˜λ―Έν•©λ‹ˆλ‹€. px, dp, rem, vw 와 같이 "크기"λ₯Ό λ‚˜νƒ€λ‚΄λŠ” λ‹¨μœ„, #fff, rgba(123, 123, 123, 1) 처럼 "색상을" λ‚˜νƒ€λ‚΄λŠ” λ‹¨μœ„, "Noto Sans KR" 같은 "폰트"λ₯Ό λ‚˜νƒ€λ‚΄λŠ” κ°’ 등이 λͺ¨λ‘ ν•΄λ‹Ήλ©λ‹ˆλ‹€.

사싀상 λ¬΄ν•œν•œ κ°’λ“€ 쀑에 μ‹€μ œλ‘œ μ‚¬μš©λ  값을 μ œν•œν•˜κ³  κ³ μœ ν•œ 이름을 λΆ€μ—¬ν•˜λŠ” κ²ƒμœΌλ‘œ λ””μžμΈμ˜ 일관성과 μž¬μ‚¬μš©μ„±μ„ 얻을 수 μžˆμ§€λ§Œ, λ°˜λŒ€λ‘œ λ””μžμΈμ˜ μœ μ—°μ„±κ³Ό μ°½μ˜μ„±μ„ 크게 μ œν•œν•  수 μžˆμŠ΅λ‹ˆλ‹€.

λ‹Ήκ·Όλ§ˆμΌ“μ˜ λ””μžμΈ 토큰은 μœ μ—°μ„±μ„ μœ„ν•΄ 크게 2λ‹¨κ³„λ‘œ κ³„μΈ΅ν™”ν•˜μ—¬ μ‚¬μš©ν•©λ‹ˆλ‹€.

Scale Token은 Raw value ν•˜λ‚˜μ— 이름을 λΆ€μ—¬ν•œ 것 μž…λ‹ˆλ‹€. Scale 의 이름을 톡해 전체 λ””μžμΈμ— μ‚¬μš©λ˜λŠ” 값을 μœ ν•œν•˜κ²Œ μœ μ§€ν•©λ‹ˆλ‹€. Scale은 슀슀둜 μ •μ˜ν•œ λ‹¨μœ„λ₯Ό 톡해 κ°’μ˜ 세뢀사항(좜λ ₯μž₯치)을 숨겨 이λ₯Ό 톡해 νŠΉμ • ν”Œλž«νΌμ— λΆˆκ°€μ§€λ‘ μ μΈ λ””μžμΈμ„ μœ μ§€ν•  수 있게 ν•©λ‹ˆλ‹€.

Semantic Token은 Scale Token의 μ‘°ν•©(Composition)으둜 λ””μžμΈ μ˜λ„λ₯Ό ν‘œν˜„ν•œ λ‹¨μœ„μ΄λ©°, μ‹€μ œ λ””μžμΈκ³Ό κ°œλ°œκ³Όμ •μ—μ„œ μ£Όμš” λΉŒλ”©λΈ”λŸ­μœΌλ‘œ μ‚¬μš©λ©λ‹ˆλ‹€. μ—¬λŸ¬κ°œμ˜ Scale 쑰합이 ν•˜λ‚˜μ˜ Semantic 을 ꡬ성할 μˆ˜λ„ 있고, μ—¬λŸ¬ Semantic 이 ν•˜λ‚˜μ˜ Scaleλ₯Ό μž¬μ •μ˜ν•΄μ„œ μ‚¬μš©λ  μˆ˜λ„ μžˆμŠ΅λ‹ˆλ‹€.

μ‹œμŠ€ν…œμ— μ‘΄μž¬ν•˜λŠ” Scale κ³Ό Semantic μ •μ˜κ°€ 전체 λ””μžμΈμ˜ Theme을 κ²°μ •ν•˜κ³ , λ·°ν¬νŠΈλ‚˜ ν”Œλž«νΌ λ“± μ™ΈλΆ€ ν™˜κ²½μ— 맞게 Scale에 μ μ ˆν•œ 값을 μ£Όμž…ν•˜λŠ” κ²ƒμœΌλ‘œ μŠ€ν‚€λ§ˆ 변경없이 μœ μ—°ν•˜κ²Œ Theme을 μž¬μ •μ˜ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

μ‚¬μš©λ²•

yarn add @karrotmarket/design-token

JavaScript (TypeScript)

import { colors } from '@karrotmarket/design-token';

// raw token
colors.light.scheme

// semantic token
colors.light.semanticScheme

CSS (css-loader)

import '@karrotmarket/design-token/colors/light.css';
import '@karrotmarket/design-token/colors/dark.css';

Conditional Exports κΈ°λŠ₯이 μ§€μ›λ˜μ§€ μ•ŠλŠ” ν™˜κ²½μ΄λΌλ©΄ λ‹€μŒκ³Ό 같이 μ‚¬μš©ν•˜μ„Έμš”.

import '@karrotmarket/design-token/lib/colors/light.css';
import '@karrotmarket/design-token/lib/colors/dark.css';

λ‹€μŒκ³Ό 같이 CSS Variables 값이 μΆ”κ°€λ©λ‹ˆλ‹€.

.light-theme {
  --color-white: #FFF;
  --color-gray100: #F2F3F6;
  --color-gray200: #EAEBEE;
  --color-gray300: #DCDEE3;
  --color-gray400: #D1D3D8;
  --color-gray500: #ADB1BA;
  --color-gray600: #868B94;
  --color-gray700: #4D5159;
  --color-gray900: #212124;
  --color-carrot50: #FFF5F0;
  --color-carrot100: #FFE2D2;
  --color-carrot200: #FFD2B9;
  --color-carrot300: #FFBC97;
  --color-carrot400: #FF9E66;
  --color-carrot500: #FF7E36;
  --color-carrot600: #FA6616;
  --color-yellow50: #FFF7E6;
  --color-yellow500: #FFC552;
  --color-yellow800: #CE6400;
  --color-green50: #E8FAF6;
  --color-green500: #00B493;
  --color-green800: #008C72;
  --color-red50: #FFF3F2;
  --color-red800: #E81300;
  --color-blue50: #EBF7FA;
  --color-blue800: #0A86B7;
  --color-background: var(--color-white);
  --color-background-low: var(--color-gray100);
}

.dark-theme {
  --color-white: #212124;
  --color-gray100: #2B2E33;
  --color-gray200: #34373D;
  --color-gray300: #43474F;
  --color-gray400: #50545C;
  --color-gray500: #6D717A;
  --color-gray600: #868B94;
  --color-gray700: #ADB1BA;
  --color-gray900: #EAEBEE;
  --color-carrot50: #EDE4E0;
  --color-carrot100: #EDD3C4;
  --color-carrot200: #EDC4AD;
  --color-carrot300: #EDB08E;
  --color-carrot400: #EE9561;
  --color-carrot500: #ED7735;
  --color-carrot600: #E96017;
  --color-yellow50: #EDE6D6;
  --color-yellow500: #EDB84E;
  --color-yellow800: #C05F03;
  --color-green50: #D8E9E5;
  --color-green500: #03A88A;
  --color-green800: #03836C;
  --color-red50: #EDE2E2;
  --color-red800: #D81403;
  --color-blue50: #DBE6E9;
  --color-blue800: #0C7EAB;
  --color-background: var(--color-white);
  --color-background-low: #17171A;
}

CSS μ—μ„œ color: var(--color-carrot400) 처럼 μ“Έ 수 μžˆμŠ΅λ‹ˆλ‹€.

Theme μ μš©ν•˜κΈ°

<div class="light-theme">
  Light ν…Œλ§ˆκ°€ μ μš©λ©λ‹ˆλ‹€

  <div class="dark-theme">
    Dark ν…Œλ§ˆκ°€ μ μš©λ©λ‹ˆλ‹€
  </div>
</div>

Application ν™˜κ²½μ—μ„œλŠ” JavaScript λ₯Ό 톡해 Theme 을 μ œμ–΄ν•˜λŠ” 것을 ꢌμž₯ν•©λ‹ˆλ‹€.

μ˜ˆμ‹œ:

if (window.matchMedia('(prefers-color-scheme: dark)')) {
  document.body.classList.remove('light-theme');
  document.body.classList.add('dark-theme');
} else {
  document.body.classList.remove('dark-theme');
  document.body.classList.add('light-theme');
}

μ‹œμŠ€ν…œ μ„€μ •λ§Œ μ‚¬μš©ν•˜λŠ” μ›Ή ν”„λ‘œμ νŠΈμ—μ„œλŠ” 미리 κ΅¬μ„±λœ μŠ€νƒ€μΌμ‹œνŠΈλ₯Ό import ν•΄μ„œ μ“Έ 수 μžˆμŠ΅λ‹ˆλ‹€.

import '@karrotmarket/design-token/colors/system.css';

FAQs

Last updated on 10 Mar 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚑️ by Socket Inc