Skip to content

Commit 2889d42

Browse files
1046: Add color utility classes (#1053)
* Add text colour utilities * Add background colour utilities * Add fill colour utilities * Import colour utilities partial * Add documentation
1 parent 92b3673 commit 2889d42

File tree

2 files changed

+74
-2
lines changed

2 files changed

+74
-2
lines changed

src/css/screen.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,8 @@
155155
"utilities/hide",
156156
"utilities/preserve-list-semantics",
157157
"utilities/spacing",
158-
"utilities/text-transform";
159-
158+
"utilities/text-transform",
159+
"utilities/colors";
160160

161161
// Components
162162
//

src/css/utilities/_colors.scss

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// Color Utilities
2+
//
3+
// A series of color utilities to control:
4+
// - text color
5+
// - background color
6+
// - fill color
7+
//
8+
// Supported colors are defined by the [brand colour variables](section-brand.html#kssref-brand-colors)
9+
//
10+
// Styleguide Utilities.Colors
11+
12+
$text-colors: (
13+
"black": $color-black,
14+
"gray-tint": $color-gray-tint,
15+
"gray-shade": $color-gray-shade,
16+
"white": $color-white,
17+
"green-tint": $color-green-tint,
18+
"green": $color-green,
19+
"green-shade": $color-green-shade,
20+
"blue-tint": $color-blue-tint,
21+
"blue": $color-blue,
22+
"blue-shade": $color-blue-shade,
23+
"pink-tint": $color-pink-tint,
24+
"pink": $color-pink,
25+
"pink-shade": $color-pink-shade,
26+
"sand": $color-sand,
27+
"red": $color-red,
28+
"yellow-tint": $color-yellow-tint,
29+
"yellow": $color-yellow,
30+
"yellow-shade": $color-yellow-shade
31+
);
32+
33+
@each $name, $var in $text-colors {
34+
// u-text-[color]
35+
//
36+
// Applies the specified color to the foreground.
37+
//
38+
// Markup:
39+
// <p class="u-text-green">The quick brown fox</p>
40+
//
41+
// Styleguide Utilities.Colors.u-text-[color]
42+
//
43+
.u-text-#{$name} {
44+
color: $var;
45+
}
46+
47+
// u-background-[color]
48+
//
49+
// Applies the specified color to the background.
50+
//
51+
// Markup:
52+
// <p class="u-background-green u-text-white">The quick brown fox</p>
53+
//
54+
// Styleguide Utilities.Colors.u-background-[color]
55+
//
56+
.u-background-#{$name} {
57+
background-color: $var;
58+
}
59+
60+
// u-fill-[color]
61+
//
62+
// Applies the specified color to the SVG fill property.
63+
//
64+
// Markup:
65+
// <svg class="u-fill-green" aria-hidden="true" focusable="false" width="51" height="51" xmlns="http://www.w3.org/2000/svg"><title>The A11Y Project</title><path d="M25.5 0C11.417 0 0 11.417 0 25.5S11.417 51 25.5 51 51 39.583 51 25.5 39.583 0 25.5 0zm-.385 5.064a3.3 3.3 0 0 1 3.307 3.291 3.304 3.304 0 0 1-3.307 3.306 3.3 3.3 0 0 1-3.29-3.306 3.29 3.29 0 0 1 3.29-3.291zm14.289 10.652l-9.809 1.24.005 9.817 4.755 15.867a1.85 1.85 0 0 1-1.344 2.252c-.989.25-2.003-.3-2.252-1.298l-4.87-14.443h-1.498l-4.48 14.742c-.374.964-1.448 1.404-2.407 1.03-.954-.37-1.533-1.454-1.158-2.418l4.115-15.572v-9.978l-9.04-1.228c-.928-.075-1.558-.89-1.483-1.818.07-.934.914-1.628 1.838-1.554l10.982.944h4.815l11.69-.963a1.68 1.68 0 0 1 1.749 1.623c.04.924-.68 1.718-1.608 1.758z"></path></svg>
66+
//
67+
// Styleguide Utilities.Colors.u-fill-[color]
68+
//
69+
.u-fill-#{$name} {
70+
fill: $var;
71+
}
72+
}

0 commit comments

Comments
 (0)