Skip to content

Commit 664b27f

Browse files
Add color background helpers to the Colors tokens PR (#2831)
1 parent cafea37 commit 664b27f

File tree

13 files changed

+216
-140
lines changed

13 files changed

+216
-140
lines changed

.bundlewatch.config.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
"files": [
33
{
44
"path": "./dist/css/ouds-web-bootstrap.css",
5-
"maxSize": "63.75 kB"
5+
"maxSize": "64.0 kB"
66
},
77
{
88
"path": "./dist/css/ouds-web-bootstrap.min.css",
9-
"maxSize": "60.75 kB"
9+
"maxSize": "61.0 kB"
1010
},
1111
{
1212
"path": "./dist/css/ouds-web-grid.css",
@@ -34,7 +34,7 @@
3434
},
3535
{
3636
"path": "./dist/css/ouds-web.css",
37-
"maxSize": "57.0 kB"
37+
"maxSize": "57.25 kB"
3838
},
3939
{
4040
"path": "./dist/css/ouds-web.min.css",

js/tests/visual/modal.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ <h1 class="modal-title h4" id="slowModalLabel">Lorem slowly</h1>
188188

189189
<br><br>
190190

191-
<div class="text-bg-dark p-short" id="tall" style="display: none;">
191+
<div class="text-bg-always-black p-short" id="tall" style="display: none;">
192192
Tall body content to force the page to have a scrollbar.
193193
</div>
194194

scss/helpers/_color-bg.scss

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,29 @@
1313
background-color: RGBA(var(--#{$prefix}#{$color}-rgb), var(--#{$prefix}bg-opacity, 1)) if($enable-important-utilities, !important, null);
1414
}
1515
}
16+
17+
// OUDS mod
18+
@each $color, $value in map-remove($ouds-backgrounds, "transparent") {
19+
$text-bg-color: var(--#{$prefix}color-content-default);
20+
@if index(("brand-primary"), #{$color}) {
21+
$text-bg-color: var(--#{$prefix}color-content-on-brand-primary);
22+
} @else if index(("emphasized"), #{$color}) {
23+
$text-bg-color: var(--#{$prefix}color-always-white);
24+
} @else if index(("always-black"), #{$color}) {
25+
$text-bg-color: var(--#{$prefix}color-always-on-black);
26+
} @else if index(("always-white"), #{$color}) {
27+
$text-bg-color: var(--#{$prefix}color-always-on-white);
28+
} @else if index(("status-neutral-emphasized", "status-negative-emphasized"), #{$color}) {
29+
$text-bg-color: var(--#{$prefix}color-content-on-status-emphasized-alt);
30+
} @else if index(("status-accent-emphasized", "status-positive-emphasized", "status-warning-emphasized", "status-info-emphasized"), #{$color}) {
31+
$text-bg-color: var(--#{$prefix}color-content-on-status-emphasized);
32+
} @else if index(("status-neutral-muted", "status-accent-muted", "status-positive-muted", "status-negative-muted", "status-warning-muted", "status-info-muted"), #{$color}) {
33+
$text-bg-color: var(--#{$prefix}color-content-on-status-muted);
34+
}
35+
36+
.text-bg-#{$color} {
37+
color: $text-bg-color if($enable-important-utilities, !important, null);
38+
background-color: $value if($enable-important-utilities, !important, null);
39+
}
40+
}
41+
// End mod

site/content/docs/0.0/helpers/color-background.md

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,55 @@ aliases:
88
toc: true
99
---
1010

11-
{{< callout-soon "helper" >}}
11+
## Overview
12+
13+
Color and background helpers combine the power of our [`.text-*` utilities]({{< docsref "/utilities/colors" >}}) and [`.bg-*` utilities]({{< docsref "/utilities/background" >}}) in one class. We determine a contrasting `color` for a particular `background-color`. However, it doesn't change mode at all.
14+
15+
{{< callout info >}}
16+
Please consider using our [color modes]({{< docsref "/customize/color-modes" >}}) directly as explained in our [background utilities]({{< docsref "/utilities/background" >}}) to set nested components in the right mode directly as well.
17+
{{< /callout >}}
18+
19+
{{< example >}}
20+
<p class="text-bg-primary p-tall fw-bold">.text-bg-primary</p>
21+
<p class="text-bg-secondary p-tall fw-bold">.text-bg-secondary</p>
22+
<p class="text-bg-tertiary p-tall fw-bold">.text-bg-tertiary</p>
23+
<p class="text-bg-emphasized p-tall fw-bold">.text-bg-emphasized</p>
24+
<p class="text-bg-brand-primary p-tall fw-bold">.text-bg-brand-primary</p>
25+
<p class="text-bg-status-neutral-emphasized p-tall fw-bold">.text-bg-status-neutral-emphasized</p>
26+
<p class="text-bg-status-neutral-muted p-tall fw-bold">.text-bg-status-neutral-muted</p>
27+
<p class="text-bg-status-accent-emphasized p-tall fw-bold">.text-bg-status-accent-emphasized</p>
28+
<p class="text-bg-status-accent-muted p-tall fw-bold">.text-bg-status-accent-muted</p>
29+
<p class="text-bg-status-positive-emphasized p-tall fw-bold">.text-bg-status-positive-emphasized</p>
30+
<p class="text-bg-status-positive-muted p-tall fw-bold">.text-bg-status-positive-muted</p>
31+
<p class="text-bg-status-negative-emphasized p-tall fw-bold">.text-bg-status-negative-emphasized</p>
32+
<p class="text-bg-status-negative-muted p-tall fw-bold">.text-bg-status-negative-muted</p>
33+
<p class="text-bg-status-warning-emphasized p-tall fw-bold">.text-bg-status-warning-emphasized</p>
34+
<p class="text-bg-status-warning-muted p-tall fw-bold">.text-bg-status-warning-muted</p>
35+
<p class="text-bg-status-info-emphasized p-tall fw-bold">.text-bg-status-info-emphasized</p>
36+
<p class="text-bg-status-info-muted p-tall fw-bold">.text-bg-status-info-muted</p>
37+
<p class="text-bg-always-black p-tall fw-bold">.text-bg-always-black</p>
38+
<p class="text-bg-always-white p-tall fw-bold">.text-bg-always-white</p>
39+
{{< /example >}}
40+
41+
{{< callout info >}}
42+
{{< partial "callouts/warning-color-assistive-technologies.md" >}}
43+
{{< /callout >}}
44+
45+
{{< bootstrap-compatibility >}}
46+
<!-- TODO LM: Check Bootstrap compatibility -->
47+
Color and background helpers combine the power of our [`.text-*` utilities]({{< docsref "/utilities/colors" >}}) and [`.bg-*` utilities]({{< docsref "/utilities/background" >}}) in one class. Using our Sass `color-contrast()` function, we automatically determine a contrasting `color` for a particular `background-color`.
48+
49+
{{< callout warning >}}
50+
**Heads up!** There's currently no support for a CSS-native `color-contrast` function, so we use our own via Sass. This means that customizing our theme colors via CSS variables may cause color contrast issues with these utilities.
51+
{{< /callout >}}
52+
53+
{{< example >}}
54+
{{< text-bg.inline >}}
55+
{{- range (index $.Site.Data "theme-colors") }}
56+
<div class="text-bg-{{ .name }} p-3">{{ .name | title }} with contrasting color</div>
57+
{{- end -}}
58+
{{< /text-bg.inline >}}
59+
{{< /example >}}
60+
{{< /bootstrap-compatibility >}}
61+
62+
<!-- ## With components -->

0 commit comments

Comments
 (0)