@euid/scss-mixins
  • Sass 믹스인 라이브러리
  • Getting Started
    • 시작하기
    • 환경 구성
    • 변경 이력
    • VS Code 확장
  • Utilities
    • 단위 (Unit)
      • rem()
      • em()
      • unitless-px()
      • remove-unit()
      • get-number-or-string()
    • 컬러 (Color)
      • get-color()
      • get-color-name()
      • has-color()
      • alt-color()
      • a11y-color()
      • light-or-dark()
      • color-contrast()
      • most-legible-color()
    • 문자 (String)
      • str-replace()
      • str-split()
      • str-to-num()
      • str-repeat()
      • str-extract-count-keyword()
    • 리스트 (List)
      • first()
      • last()
      • copy-list()
      • merge-list()
      • get-value-after-key()
      • get-match-value-of-keys()
    • 검사 (Validation)
      • is-valid-types()
      • is-valid-keywords()
      • is-include-items()
    • 이징 (Easing)
      • ease()
      • ease-add()
      • ease-merge()
  • Mixins
    • 폰트 (Font)
      • font()
      • font-face()
      • font-size-padding()
    • 텍스트 (Text)
      • text()
      • text-ellipsis()
    • 간격 (Spacing)
      • margin()
      • m()
      • mx()
      • my()
      • padding()
      • p()
      • px()
      • py()
      • space()
      • s()
      • sx()
      • sy()
    • 디스플레이 (Display)
      • show()
      • hide()
      • order()
    • 포지션 (Position)
      • position()
      • relative()
      • absolute()
      • fixed()
      • sticky()
      • static()
    • 플렉스박스 (Flexbox)
      • Flex 컨테이너(Container)
        • flex-container()
        • flex-container-append()
      • Flex 아이템(Item)
        • flex-item()
        • flex()
    • CSS 그리드 (Grid)
      • Grid 컨테이너(Container)
        • grid-container()
        • grid-container-append()
          • grid-rows()
          • grid-cols()
          • grid-auto()
            • auto-rows()
            • auto-cols()
            • auto-flow()
          • grid-areas()
          • gap()
      • Grid 아이템(Item)
        • grid-item()
        • grid-area()
        • grid-row()
          • row-start()
          • row-end()
          • row-span()
        • grid-col()
          • col-start()
          • col-end()
          • col-span()
    • 박스 정렬 (Box Alignment)
      • box-alignment()
      • place()
        • content()
        • items()
        • self()
      • justify-content()
      • align-content()
      • justify-items()
      • align-items()
      • justify-self()
      • align-self()
    • 반응형 웹 (Rsponsive Web)
      • media()
      • rwd-img()
      • rwd-video()
      • rwd-iframe-wrapper()
    • 이니셜라이즈 (Initialize)
      • initialize()
      • normalize()
      • reset-box()
      • reset-box-sizing()
      • reset-img()
      • reset-link()
      • reset-list()
      • reset-dl()
      • reset-abbr()
      • reset-button()
    • 인터페이스 (Interface)
      • appearance()
      • selection()
      • scrollbar()
    • 접근성 (Accessibility)
      • a11y-hidden()
      • focus-visible()
    • 상속 (Inheritance)
      • inherit-box-sizing()
      • inherit-pseudo-elements()
    • 폼 (Form)
      • button()
      • input()
      • radio()
      • search()
      • checkbox()
      • placeholder()
      • textarea()
      • select()
      • select-multiple()
Powered by GitBook
On this page
  • 용도
  • 사용법
  • 로직
  • 참고

Was this helpful?

  1. Utilities
  2. 컬러 (Color)

get-color()

색 구성표(Color Scheme)에 등록된 컬러 값 반환 유틸리티 함수

Previous컬러 (Color)Nextget-color-name()

Last updated 4 years ago

Was this helpful?

용도

색 구성표에 등록된 수 많은 컬러 값(예: #28120e)을 암기하는 것은 매우 어렵습니다. 하지만 컬러 이름(bean)은 상대적으로 기억하기 용이합니다. 컬러 이름을 전달해 매칭되는 컬러 값을 추출할 수 있어 일관된 컬러 시스템을 구축, 활용하는데 유용하게 사용 할 수 있습니다.

사용 예

  • 배경, 전경, 테두리, 그림자 등 색을 일관적으로 관리해야 하는 경우

  • 컬러 이름을 통해 연결된 값을 사용해야 할 경우 (gray → #787878)

에 사용자가 임의로 컬러 이름에 매칭되는 값을 등록할 수 있습니다.

사용법

get-color() 함수에 등록된 컬러 이름을 전달합니다. (이름과 매칭되는 컬러 값 반환)

get-color($name:string) → color

.usage {
  background: get-color(black); // #010101 반환
  color: get-color(white);      // #fefefe 반환
}

매개변수(parameter)

유형(type)

필수(required)

기본 값(default)

$name

string

✔︎

null

로직

get-color() 유틸리티는 다음의 로직에 의해 작성되었습니다.

@function get-color($name: null) {
  @if has-color($name) {
    @return map-get($colors, $name);
  } @else {
    @error '설정 가능한 컬러 값은 #{map-keys($colors)} 중 하나입니다.';
  }
}
  1. 등록된 컬러 이름과 동일한 경우, 컬러 값을 반환

  2. 등록된 컬러 이름과 일치하지 않을 경우, 오류 출력

참고

유틸리티 함수 로직에 사용된 Sass 빌트인 모듈은 다음과 같습니다.

믹스인에 사용된 자체 제작 모듈은 다음과 같습니다.

Sass의 Map 자료형(Data Type)은 JavaScript의 Object와 유사합니다.

전달 받은 컬러 이름($name)이 에 등록된 값이 유효한 지 검사

map-get()
map-keys()
has-color()
Sass: sass:map
환경 구성 변수 $colors
$colors 구성 변수
Logo