Skip to content

Commit 10666ad

Browse files
authored
Rename theme text tokens to fg, update utilities (#42295)
With this refactor, our .fg-* and .bg-* and .border-* utilities can be modified by custom CSS, like in our blue theme example. This also standardizes some nomenclature by using fg instead of text in the token names for theme values, better matching bg. Classes already use this, as do root fg tokens, so this is just a consistency update.
1 parent a1544ae commit 10666ad

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+236
-246
lines changed

scss/_accordion.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ $accordion-tokens: defaults(
106106
border-color: var(--theme-border, var(--accordion-border-color));
107107

108108
> .accordion-header {
109-
color: var(--theme-text, var(--accordion-active-color));
109+
color: var(--theme-fg, var(--accordion-active-color));
110110
background-color: var(--theme-bg-subtle, var(--accordion-active-bg));
111111
box-shadow: inset 0 calc(-1 * var(--accordion-border-width)) 0 var(--theme-border, var(--accordion-border-color));
112112

scss/_alert.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ $alert-tokens: defaults(
1313
--alert-bg: var(--theme-bg-subtle, var(--bg-1)),
1414
--alert-padding-x: #{$spacer},
1515
--alert-padding-y: #{$spacer},
16-
--alert-color: var(--theme-text, inherit),
16+
--alert-color: var(--theme-fg, inherit),
1717
--alert-border-color: var(--theme-border, var(--border-color)),
1818
--alert-border: var(--border-width) solid var(--alert-border-color),
1919
--alert-border-radius: var(--border-radius),

scss/_avatar.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ $avatar-sizes: defaults(
7575
}
7676

7777
.avatar-subtle {
78-
color: var(--theme-text, var(--avatar-color));
78+
color: var(--theme-fg, var(--avatar-color));
7979
background-color: var(--theme-bg-subtle, var(--avatar-bg));
8080
}
8181

scss/_card.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,13 @@ $card-tokens: defaults(
140140
border-color: var(--theme-border, var(--card-border-color));
141141

142142
.card-header {
143-
color: var(--theme-text-emphasis, currentcolor);
143+
color: var(--theme-fg-emphasis, currentcolor);
144144
background-color: var(--theme-bg-subtle, var(--card-cap-bg));
145145
border-color: var(--theme-border, var(--card-border-color));
146146
}
147147

148148
.card-footer {
149-
color: var(--theme-text-emphasis, currentcolor);
149+
color: var(--theme-fg-emphasis, currentcolor);
150150
background-color: var(--theme-bg-subtle, var(--card-cap-bg));
151151
border-color: var(--theme-border, var(--card-border-color));
152152
}

scss/_chip.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ $chip-tokens: defaults(
1919
--chip-dismiss-size: 1rem,
2020
--chip-dismiss-opacity: .65,
2121
--chip-dismiss-hover-opacity: 1,
22-
--chip-color: var(--theme-text, var(--fg-body)),
22+
--chip-color: var(--theme-fg, var(--fg-body)),
2323
--chip-bg: var(--theme-bg-subtle, var(--bg-2)),
2424
--chip-border-color: transparent,
2525
--chip-selected-color: var(--theme-contrast, var(--primary-contrast)),

scss/_list-group.scss

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ $list-group-tokens: defaults(
6565
position: relative;
6666
display: block;
6767
padding: var(--list-group-item-padding-y) var(--list-group-item-padding-x);
68-
color: var(--theme-text, var(--list-group-color));
68+
color: var(--theme-fg, var(--list-group-color));
6969
// stylelint-disable-next-line scss/at-function-named-arguments
7070
text-decoration: if(sass($link-decoration == none): null);
7171
background-color: var(--theme-bg-subtle, var(--list-group-bg));
@@ -112,7 +112,7 @@ $list-group-tokens: defaults(
112112

113113
.list-group-item-action {
114114
width: 100%; // For `<button>`s (anchors become 100% by default though)
115-
color: var(--theme-text, var(--list-group-action-color));
115+
color: var(--theme-fg, var(--list-group-action-color));
116116
text-align: inherit; // For `<button>`s (anchors inherit)
117117
text-decoration: none;
118118

@@ -121,13 +121,13 @@ $list-group-tokens: defaults(
121121
&:hover,
122122
&:focus {
123123
z-index: 1; // Place hover/focus items above their siblings for proper border styling
124-
color: var(--theme-text-emphasis, var(--list-group-action-hover-color));
124+
color: var(--theme-fg-emphasis, var(--list-group-action-hover-color));
125125
text-decoration: none;
126126
background-color: var(--theme-bg-muted, var(--list-group-action-hover-bg));
127127
}
128128

129129
&:active {
130-
color: var(--theme-text-emphasis, var(--list-group-action-active-color));
130+
color: var(--theme-fg-emphasis, var(--list-group-action-active-color));
131131
background-color: var(--theme-bg-muted, var(--list-group-action-active-bg));
132132
}
133133
}

scss/_menu.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ $menu-tokens: defaults(
152152
width: 100%;
153153
padding: var(--menu-item-padding-y) var(--menu-item-padding-x);
154154
font-weight: var(--menu-item-font-weight, var(--font-weight-normal));
155-
color: var(--theme-text, var(--menu-item-color));
155+
color: var(--theme-fg, var(--menu-item-color));
156156
text-align: inherit;
157157
text-decoration: none;
158158
white-space: nowrap;
@@ -164,7 +164,7 @@ $menu-tokens: defaults(
164164

165165
&:hover,
166166
&:focus {
167-
color: var(--theme-text-emphasis, var(--menu-item-hover-color));
167+
color: var(--theme-fg-emphasis, var(--menu-item-hover-color));
168168
background-color: var(--theme-bg-subtle, var(--menu-item-hover-bg));
169169
// @include gradient-bg(var(--theme-bg-subtle, var(--menu-item-hover-bg)));
170170
}

scss/_root.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ $root-tokens: defaults(
4141

4242
--hr-border-color: var(--border-color),
4343

44-
--link-color: light-dark(var(--primary-base), var(--primary-text)),
44+
--link-color: light-dark(var(--primary-base), var(--primary-fg)),
4545
--link-decoration: #{$link-decoration},
4646
--link-hover-color: color-mix(in oklch, var(--link-color) 90%, #000),
4747

scss/_theme.scss

Lines changed: 49 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,39 @@
1212
@return $result;
1313
}
1414

15+
// Themes map sub-keys
16+
//
17+
// Return var() references to root tokens instead of raw values.
18+
// Ex: theme-color-refs("bg") => (primary: var(--primary-bg), accent: var(--accent-bg), ...)
19+
@function theme-color-refs($key) {
20+
$result: ();
21+
22+
@each $color-name, $color-map in $theme-colors {
23+
@if map.has-key($color-map, $key) {
24+
$result: map.merge($result, ($color-name: var(--#{$color-name}-#{$key})));
25+
}
26+
}
27+
28+
@return $result;
29+
}
30+
31+
// Theme token to root tokens
32+
//
33+
// Returns the global :root token reference for a given a given token map, prefix, and key.
34+
// Ex: theme-token-refs($theme-bgs, "bg") => (body: var(--bg-body), 1: var(--bg-1), ...)
35+
// Skips `inherit` since it's a CSS-wide keyword that can't be stored in a custom property.
36+
@function theme-token-refs($map, $prefix) {
37+
$result: ();
38+
39+
@each $key, $value in $map {
40+
@if $value != inherit {
41+
$result: map.merge($result, ($key: var(--#{$prefix}-#{$key})));
42+
}
43+
}
44+
45+
@return $result;
46+
}
47+
1548
// Generate opacity values using color-mix()
1649
@function theme-opacity-values($color-var, $opacities: $util-opacity) {
1750
$result: ();
@@ -45,8 +78,8 @@
4578
$theme-colors: (
4679
"primary": (
4780
"base": var(--blue-500),
48-
"text": light-dark(var(--blue-600), var(--blue-400)),
49-
"text-emphasis": light-dark(var(--blue-800), var(--blue-200)),
81+
"fg": light-dark(var(--blue-600), var(--blue-400)),
82+
"fg-emphasis": light-dark(var(--blue-800), var(--blue-200)),
5083
"bg": var(--blue-500),
5184
"bg-subtle": light-dark(var(--blue-100), var(--blue-900)),
5285
"bg-muted": light-dark(var(--blue-200), var(--blue-800)),
@@ -56,8 +89,8 @@ $theme-colors: (
5689
),
5790
"accent": (
5891
"base": var(--indigo-500),
59-
"text": light-dark(var(--indigo-600), color-mix(in oklch, var(--indigo-400), var(--indigo-300))),
60-
"text-emphasis": light-dark(var(--indigo-800), var(--indigo-300)),
92+
"fg": light-dark(var(--indigo-600), color-mix(in oklch, var(--indigo-400), var(--indigo-300))),
93+
"fg-emphasis": light-dark(var(--indigo-800), var(--indigo-300)),
6194
"bg": var(--indigo-500),
6295
"bg-subtle": light-dark(var(--indigo-100), var(--indigo-900)),
6396
"bg-muted": light-dark(var(--indigo-200), var(--indigo-800)),
@@ -67,8 +100,8 @@ $theme-colors: (
67100
),
68101
"success": (
69102
"base": var(--green-500),
70-
"text": light-dark(var(--green-600), var(--green-400)),
71-
"text-emphasis": light-dark(var(--green-800), var(--green-300)),
103+
"fg": light-dark(var(--green-600), var(--green-400)),
104+
"fg-emphasis": light-dark(var(--green-800), var(--green-300)),
72105
"bg": var(--green-500),
73106
"bg-subtle": light-dark(var(--green-100), var(--green-900)),
74107
"bg-muted": light-dark(var(--green-200), var(--green-800)),
@@ -78,8 +111,8 @@ $theme-colors: (
78111
),
79112
"danger": (
80113
"base": var(--red-500),
81-
"text": light-dark(var(--red-600), var(--red-400)),
82-
"text-emphasis": light-dark(var(--red-800), var(--red-300)),
114+
"fg": light-dark(var(--red-600), var(--red-400)),
115+
"fg-emphasis": light-dark(var(--red-800), var(--red-300)),
83116
"bg": var(--red-500),
84117
"bg-subtle": light-dark(var(--red-100), var(--red-900)),
85118
"bg-muted": light-dark(var(--red-200), var(--red-800)),
@@ -89,8 +122,8 @@ $theme-colors: (
89122
),
90123
"warning": (
91124
"base": var(--yellow-500),
92-
"text": light-dark(var(--yellow-700), var(--yellow-400)),
93-
"text-emphasis": light-dark(var(--yellow-800), var(--yellow-300)),
125+
"fg": light-dark(var(--yellow-700), var(--yellow-400)),
126+
"fg-emphasis": light-dark(var(--yellow-800), var(--yellow-300)),
94127
"bg": var(--yellow-500),
95128
"bg-subtle": light-dark(var(--yellow-100), var(--yellow-900)),
96129
"bg-muted": light-dark(var(--yellow-200), var(--yellow-800)),
@@ -100,8 +133,8 @@ $theme-colors: (
100133
),
101134
"info": (
102135
"base": var(--cyan-500),
103-
"text": light-dark(var(--cyan-600), var(--cyan-400)),
104-
"text-emphasis": light-dark(var(--cyan-800), var(--cyan-300)),
136+
"fg": light-dark(var(--cyan-600), var(--cyan-400)),
137+
"fg-emphasis": light-dark(var(--cyan-800), var(--cyan-300)),
105138
"bg": var(--cyan-500),
106139
"bg-subtle": light-dark(var(--cyan-100), var(--cyan-900)),
107140
"bg-muted": light-dark(var(--cyan-200), var(--cyan-800)),
@@ -111,8 +144,8 @@ $theme-colors: (
111144
),
112145
"inverse": (
113146
"base": var(--gray-900),
114-
"text": light-dark(var(--gray-900), var(--gray-200)),
115-
"text-emphasis": light-dark(var(--gray-975), var(--white)),
147+
"fg": light-dark(var(--gray-900), var(--gray-200)),
148+
"fg-emphasis": light-dark(var(--gray-975), var(--white)),
116149
"bg": light-dark(var(--gray-900), var(--gray-025)),
117150
"bg-subtle": light-dark(var(--gray-100), var(--gray-900)),
118151
"bg-muted": light-dark(var(--gray-200), var(--gray-300)),
@@ -122,8 +155,8 @@ $theme-colors: (
122155
),
123156
"secondary": (
124157
"base": var(--gray-200),
125-
"text": light-dark(var(--gray-600), var(--gray-400)),
126-
"text-emphasis": light-dark(var(--gray-800), var(--gray-200)),
158+
"fg": light-dark(var(--gray-600), var(--gray-400)),
159+
"fg-emphasis": light-dark(var(--gray-800), var(--gray-200)),
127160
"bg": light-dark(var(--gray-100), var(--gray-600)),
128161
"bg-subtle": light-dark(var(--gray-050), var(--gray-800)),
129162
"bg-muted": light-dark(var(--gray-100), var(--gray-700)),

scss/_toasts.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ $toast-tokens: defaults(
7676
display: flex;
7777
align-items: center;
7878
padding: var(--toast-padding-y) var(--toast-padding-x);
79-
color: var(--theme-text-emphasis, var(--toast-header-color));
79+
color: var(--theme-fg-emphasis, var(--toast-header-color));
8080
background-color: var(--theme-bg-subtle, var(--toast-header-bg));
8181
// background-clip: padding-box;
8282
border-block-end: var(--toast-border-width, var(--border-width)) solid var(--theme-border, var(--toast-header-border-color, var(--border-color-translucent)));

0 commit comments

Comments
 (0)