|
43 | 43 | } |
44 | 44 |
|
45 | 45 | // build individual color blocks |
| 46 | +/* stylelint-disable max-nesting-depth */ |
46 | 47 | @each $name, $color in $sage-colors { |
47 | | - // Skip if $color is not a map (handles aliases like primary, sage, orange, charcoal) |
48 | | - @if type-of($color) == map { |
49 | | - @each $value, $map in $color { |
50 | | - // Skip if $map is null or not a map (safety check) |
51 | | - @if $map != null and type-of($map) == map { |
52 | | - // Use sage-color-hex() for SCSS operations (lightness() requires actual color values) |
53 | | - $hex: sage-color-hex($name, $value); |
54 | | - |
55 | | - // Determine class name for $value == 50 |
56 | | - $classname: ".color-#{"" + $name}-#{$value}"; |
57 | | - |
58 | | - /* stylelint-disable max-nesting-depth, block-closing-brace-newline-after */ |
59 | | - // This should be numeric, not string |
60 | | - @if ($value == 50) { |
61 | | - $classname: ".color-#{"" + $name}-0#{$value}"; |
62 | | - } |
63 | | - |
64 | | - #{$classname} { |
65 | | - padding: sage-spacing(sm) sage-spacing(); |
66 | | - font-size: sage-font-size(body); |
67 | | - background: $hex; |
68 | | - |
69 | | - // Use lightness-based logic for dynamic contrast (prioritized for better readability) |
70 | | - // If background is dark (lightness < 65%), use light text; otherwise use dark text |
71 | | - @if (lightness($hex) < 65) { |
72 | | - // Dark background → use light text color |
73 | | - @if ($name == white) { |
74 | | - color: sage-color(black); |
75 | | - } @else if ($name == grey or $name == black or $name == charcoal) { |
76 | | - color: sage-color(white); |
77 | | - } @else { |
78 | | - // For colored backgrounds, use the lightest shade (100) or white |
79 | | - color: sage-color($name, 100); |
80 | | - } |
81 | | - } @else { |
82 | | - // Light background → use dark text color |
83 | | - @if ($name == white) { |
84 | | - color: sage-color(grey, 950); |
85 | | - } @else if ($name == black or $name == charcoal) { |
86 | | - color: sage-color(white); |
87 | | - } @else if ($name == grey) { |
88 | | - color: sage-color(grey, 950); |
89 | | - } @else { |
90 | | - // For colored backgrounds, use a darker shade (400+) for contrast |
91 | | - color: sage-color($name, 400); |
92 | | - } |
93 | | - } |
94 | | - |
95 | | - &::after { |
96 | | - content: "#{$hex}"; |
97 | | - padding-inline-start: sage-spacing(xs); |
98 | | - font-weight: sage-font-weight(semibold); |
99 | | - text-transform: uppercase; |
100 | | - } |
101 | | - } |
102 | | - /* stylelint-enable max-nesting-depth, block-closing-brace-newline-after */ |
| 48 | + @each $value, $map in $color { |
| 49 | + // Use sage-color-hex() for actual hex values (needed for color documentation display) |
| 50 | + // This ensures colors are displayed correctly regardless of dark/light mode |
| 51 | + $hex: sage-color-hex($name, $value); |
| 52 | + |
| 53 | + // Determine class name for $value == 50 |
| 54 | + $classname: ".color-#{"" + $name}-#{$value}"; |
| 55 | + |
| 56 | + // This should be numeric, not string |
| 57 | + @if ($value == 50) { |
| 58 | + $classname: ".color-#{"" + $name}-0#{$value}"; |
| 59 | + } |
| 60 | + |
| 61 | + #{$classname} { |
| 62 | + padding: sage-spacing(sm) sage-spacing(); |
| 63 | + font-size: sage-font-size(body); |
| 64 | + background: $hex; |
| 65 | + |
| 66 | + // Simple lightness-based contrast: white text on dark, black text on light |
| 67 | + @if (lightness($hex) < 55%) { |
| 68 | + color: sage-color-hex(white); |
| 69 | + } |
| 70 | + @else { |
| 71 | + color: sage-color-hex(grey, 950); |
| 72 | + } |
| 73 | + |
| 74 | + &::after { |
| 75 | + content: "#{$hex}"; |
| 76 | + padding-inline-start: sage-spacing(xs); |
| 77 | + font-weight: sage-font-weight(semibold); |
| 78 | + text-transform: uppercase; |
103 | 79 | } |
104 | 80 | } |
105 | 81 | } |
106 | 82 | } |
| 83 | +/* stylelint-enable max-nesting-depth */ |
107 | 84 |
|
108 | 85 | [class*="color-"]:only-child { |
109 | 86 | border-radius: sage-border(radius); |
110 | 87 | } |
111 | 88 |
|
112 | 89 | .color-white-100 { |
113 | 90 | border-radius: sage-border(radius); |
114 | | - border: 1px solid sage-color(grey, 800); |
115 | | - box-shadow: inset 0 0 0.0625rem sage-color(grey, 800); |
| 91 | + border: 1px solid sage-color-hex(grey, 300); |
| 92 | + box-shadow: inset 0 0 0.0625rem sage-color-hex(grey, 300); |
116 | 93 | } |
117 | 94 |
|
118 | 95 | .color-black-100 { |
119 | | - color: sage-color(white); |
| 96 | + color: sage-color-hex(white); |
120 | 97 | } |
0 commit comments