Skip to content

Instantly share code, notes, and snippets.

@yamoo9
Created September 5, 2022 07:37
Show Gist options
  • Save yamoo9/56f93d94a5f043bed4d7ff46302be20e to your computer and use it in GitHub Desktop.
Save yamoo9/56f93d94a5f043bed4d7ff46302be20e to your computer and use it in GitHub Desktop.
font 믹스인 예시
@use "sass:meta" as *;
@use "sass:list";
@use "sass:string";
@function get-value($props, $key) {
$index: list.index($props, $key);
@if $index != null {
$value: list.nth($props, $index + 1);
@return if(type-of($value) != string, $value, string.unquote($value));
} @else {
@return null;
}
}
@mixin set-key-value($props, $prop, $types) {
@each $key in $types {
#{$prop}: get-value($props, $key);
}
}
@mixin font($props) {
@if type-of($props) != list {
@error "$props #{$props} 타입은 list만 허용합니다.";
}
@include set-key-value($props, font-weight, w fw weight);
@include set-key-value($props, font-style, s fs style);
@include set-key-value($props, font-size, z fz size);
@include set-key-value($props, line-height, l lh height);
@include set-key-value($props, font-family, f ff family);
@include set-key-value($props, color, c color);
}
@use 'mixins' as *;
.demo1 {
@include font(w 200);
}
.demo2 {
@include font(fz 10px c red);
}
.demo3 {
@include font(
lh 1.5
s normal
ff 'Pretendard, "Spoqa Hans Sans Neo", sans-serif'
)
}
.demo1 {
font-weight: 200;
}
.demo2 {
font-size: 10px;
color: red;
}
.demo3 {
font-style: normal;
line-height: 1.5;
font-family: Pretendard, "Spoqa Hans Sans Neo", sans-serif;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment