색상
Devup UI는 직접 지정한 값과 테마 토큰을 통해 유연하게 색상을 관리할 수 있도록 지원합니다.
색상 값 직접 지정
모든 컴포넌트에 색상 값을 직접 전달할 수 있습니다.
1// Hex colors 2const example1 = <Box bg="#FF0000" /> 3const example2 = <Box bg="#F00" /> 4 5// RGB/RGBA 6const example3 = <Box bg="rgb(255, 0, 0)" /> 7const example4 = <Box bg="rgba(255, 0, 0, 0.5)" /> 8 9// HSL 10const example5 = <Box bg="hsl(0, 100%, 50%)" /> 11 12// Named colors 13const example6 = <Box bg="red" /> 14const example7 = <Box bg="tomato" />1// Hex colors 2const example1 = <Box bg="#FF0000" /> 3const example2 = <Box bg="#F00" /> 4 5// RGB/RGBA 6const example3 = <Box bg="rgb(255, 0, 0)" /> 7const example4 = <Box bg="rgba(255, 0, 0, 0.5)" /> 8 9// HSL 10const example5 = <Box bg="hsl(0, 100%, 50%)" /> 11 12// Named colors 13const example6 = <Box bg="red" /> 14const example7 = <Box bg="tomato" />
Devup UI는 빌드 시점에 색상 값을 자동으로 최적화합니다.
#FF0000,#F00,rgb(255, 0, 0)은 모두#F00이 되어 하나의 클래스를 공유하고,rgba(255, 0, 0, 0.5)는#FF000080이 됩니다.
1.a { 2 background: #f00; 3} 4.b { 5 background: #ff000080; 6} 7.c { 8 background: hsl(0, 100%, 50%); 9} 10.d { 11 background: red; 12} 13.e { 14 background: tomato; 15}1.a { 2 background: #f00; 3} 4.b { 5 background: #ff000080; 6} 7.c { 8 background: hsl(0, 100%, 50%); 9} 10.d { 11 background: red; 12} 13.e { 14 background: tomato; 15}
테마 색상
규모가 큰 프로젝트에서는 일관성과 테마 지원을 위해 devup.json에 색상을 정의하세요.
1{ 2 "theme": { 3 "colors": { 4 "default": { 5 "primary": "#0070f3", 6 "secondary": "#7928ca", 7 "success": "#0070f3", 8 "warning": "#f5a623", 9 "error": "#e00", 10 "text": "#000", 11 "textSecondary": "#666", 12 "background": "#fff", 13 "border": "#eaeaea" 14 }, 15 "dark": { 16 "primary": "#3291ff", 17 "secondary": "#8a63d2", 18 "success": "#3291ff", 19 "warning": "#f7b955", 20 "error": "#f33", 21 "text": "#fff", 22 "textSecondary": "#888", 23 "background": "#000", 24 "border": "#333" 25 } 26 } 27 } 28}1{ 2 "theme": { 3 "colors": { 4 "default": { 5 "primary": "#0070f3", 6 "secondary": "#7928ca", 7 "success": "#0070f3", 8 "warning": "#f5a623", 9 "error": "#e00", 10 "text": "#000", 11 "textSecondary": "#666", 12 "background": "#fff", 13 "border": "#eaeaea" 14 }, 15 "dark": { 16 "primary": "#3291ff", 17 "secondary": "#8a63d2", 18 "success": "#3291ff", 19 "warning": "#f7b955", 20 "error": "#f33", 21 "text": "#fff", 22 "textSecondary": "#888", 23 "background": "#000", 24 "border": "#333" 25 } 26 } 27 } 28}
테마 색상은 $ 접두사를 붙여 사용합니다.
1const boxExample1 = <Box bg="$primary" /> 2const textExample = <Text color="$text" /> 3const boxExample2 = <Box borderColor="$border" />1const boxExample1 = <Box bg="$primary" /> 2const textExample = <Text color="$text" /> 3const boxExample2 = <Box borderColor="$border" />
각 토큰은 CSS 변수를 읽으므로 테마를 전환해도 새 클래스가 필요하지 않습니다.
1.a { 2 background: var(--primary); 3} 4.b { 5 color: var(--text); 6} 7.c { 8 border-color: var(--border); 9}1.a { 2 background: var(--primary); 3} 4.b { 5 color: var(--text); 6} 7.c { 8 border-color: var(--border); 9}
여러 테마 변형
default와 dark 외에도 여러 테마 변형을 정의할 수 있습니다.
1{ 2 "theme": { 3 "colors": { 4 "default": { 5 "primary": "#0070f3" 6 }, 7 "dark": { 8 "primary": "#3291ff" 9 }, 10 "blue": { 11 "primary": "#0052cc" 12 }, 13 "green": { 14 "primary": "#00875a" 15 } 16 } 17 } 18}1{ 2 "theme": { 3 "colors": { 4 "default": { 5 "primary": "#0070f3" 6 }, 7 "dark": { 8 "primary": "#3291ff" 9 }, 10 "blue": { 11 "primary": "#0052cc" 12 }, 13 "green": { 14 "primary": "#00875a" 15 } 16 } 17 } 18}
기본 테마는 default입니다(없으면 light, 그것도 없으면 첫 번째 변형). 다른 테마는 테마 API로 활성화할 수 있습니다. 변형에는 바꾸려는 색상만 나열하면 됩니다. 나머지 색상은 기본 테마의 값을 그대로 유지하며, 한 변형에만 정의된 색상은 해당 변형에서만 정의됩니다.
각 변형은 페이지의 네이티브 색 구성표(폼 컨트롤, 스크롤바, 기본 텍스트 색상)도 설정합니다. dark는 어둡게, 그 밖의 모든 변형은 밝게 렌더링되며, 다른 변형의 색 구성표는 colorScheme에 지정합니다.
1{ 2 "theme": { 3 "colors": { 4 "default": { "primary": "#0070f3" }, 5 "midnight": { "primary": "#3291ff" } 6 }, 7 "colorScheme": { "midnight": "dark" } 8 } 9}1{ 2 "theme": { 3 "colors": { 4 "default": { "primary": "#0070f3" }, 5 "midnight": { "primary": "#3291ff" } 6 }, 7 "colorScheme": { "midnight": "dark" } 8 } 9}
토큰 이름은 문자, 숫자 또는 _로 시작하고, 이어서 문자, 숫자, -, _, .를 사용할 수 있습니다(primary, text-primary, gray.100). 점은 CSS 변수에서 대시로 바뀌므로 gray.100은 var(--gray-100)이 됩니다. 허용되지 않는 문자가 포함된 이름이나, 한 변형 안에서 같은 변수가 되는 두 토큰(a-b와 a.b)이 있으면 브라우저가 무시할 CSS를 출력하는 대신 빌드에서 이를 보고합니다. 색상, length, shadow 토큰은 CSS 변수의 네임스페이스 하나를 공유하므로, 색상 card와 그림자 card(둘 다 --card)도 빌드 오류가 됩니다. 둘 중 하나의 이름을 바꾸세요.
의미 기반 색상 이름
색상을 겉모습이 아니라 용도에 따라 구성하세요.
1{ 2 "theme": { 3 "colors": { 4 "default": { 5 "primary": "#0070f3", 6 "primaryHover": "#0060df", 7 "primaryActive": "#0050c0", 8 9 "text": "#000", 10 "textMuted": "#666", 11 "textInverse": "#fff", 12 13 "background": "#fff", 14 "backgroundSubtle": "#fafafa", 15 "backgroundMuted": "#f5f5f5", 16 17 "border": "#eaeaea", 18 "borderFocus": "#0070f3", 19 20 "success": "#0070f3", 21 "warning": "#f5a623", 22 "error": "#e00", 23 "info": "#0070f3" 24 } 25 } 26 } 27}1{ 2 "theme": { 3 "colors": { 4 "default": { 5 "primary": "#0070f3", 6 "primaryHover": "#0060df", 7 "primaryActive": "#0050c0", 8 9 "text": "#000", 10 "textMuted": "#666", 11 "textInverse": "#fff", 12 13 "background": "#fff", 14 "backgroundSubtle": "#fafafa", 15 "backgroundMuted": "#f5f5f5", 16 17 "border": "#eaeaea", 18 "borderFocus": "#0070f3", 19 20 "success": "#0070f3", 21 "warning": "#f5a623", 22 "error": "#e00", 23 "info": "#0070f3" 24 } 25 } 26 } 27}
투명도가 있는 색상 사용
투명한 변형이 필요하면 RGBA를 사용하거나 별도의 토큰을 정의하세요.
1{ 2 "theme": { 3 "colors": { 4 "default": { 5 "primary": "#0070f3", 6 "primaryAlpha10": "rgba(0, 112, 243, 0.1)", 7 "primaryAlpha20": "rgba(0, 112, 243, 0.2)", 8 "overlay": "rgba(0, 0, 0, 0.5)" 9 } 10 } 11 } 12}1{ 2 "theme": { 3 "colors": { 4 "default": { 5 "primary": "#0070f3", 6 "primaryAlpha10": "rgba(0, 112, 243, 0.1)", 7 "primaryAlpha20": "rgba(0, 112, 243, 0.2)", 8 "overlay": "rgba(0, 0, 0, 0.5)" 9 } 10 } 11 } 12}
타입 안전성
테마 색상은 완전히 타입 안전합니다. TypeScript가 사용 가능한 색상 토큰을 자동 완성합니다.
1// 자동 완성 목록: $primary, $secondary, $text 등 2<Box bg="$" />1// 자동 완성 목록: $primary, $secondary, $text 등 2<Box bg="$" />
잘못된 색상 토큰은 TypeScript 오류로 표시되므로 코드베이스 전체에서 일관성을 유지할 수 있습니다.