You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Lastly, lets add a quotation icon for some visual flare! Visit the <ahref="https://designsystem.digital.gov/components/icon/">Icon component</a> page, search for <strong>quote</strong>, and click the search result to copy the icons markup. Paste this markup directly after the opening <strong>my-testimonial</strong> div.
52
+
Lastly, let's add a quotation icon for some visual flare! Visit the <ahref="https://designsystem.digital.gov/components/icon/">Icon component</a> page, search for <strong>quote</strong>, and click the search result to copy the icons markup. Paste this markup directly after the opening <strong>my-testimonial</strong> div.
Just like using the <strong>color()</strong> function to use USWDS color tokens, we can use <strong>units()</strong>to allow native CSS properties to make use of USWDS spacing tokens. To get our base styles for our new component, add the following styles to the new stylesheet.
101
+
Just like using the <strong>color()</strong> function to use USWDS color tokens, we can use <strong>units()</strong>and other token functions to use USWDS tokens in native CSS properties. To get our base styles for our new component, add the following styles to the new stylesheet:
USWDS uses variables to maintain consistent styles across different definitions. Let's create a variable for our icon stroke and fill at the top of our stylesheet.
<h3class="step">Using USWDS theme tokens with mixins</h3>
177
180
<pclass="step-description">
178
-
USWDS also offers an extensive library of utility mixins which you can use to simplify style setting. Let's use some of the typeset mixins to customize our font weight and size. It's standard convention to include your mixins at the top of each style definition.
181
+
Using a combination of utility mixins and USWDS theme settings can help add uniformity across your project. In this example, we'll add the border settings and padding settings from earlier to help our new component sit nicely with the original card. The <strong>u-margin-x()</strong> mixin lets you set left and right margin at the same time.
<h3class="step">Color, background, and contrast</h3>
198
+
<pclass="step-description">
199
+
Finally, let's change the color of our testimonial component. The traditional way to set background and color is to use two separate rules. If we want to use our primary colors in this component, we can use the following two rules:
If you save and reload, you might not be sure if the colors you've added have proper color contrast. Upon closer inspection, these colors <strong>fail</strong> AA color contrast requirements! USWDS uses a color grading system. Using this system, a grade difference of 50+ ensures AA across any two color values. (You can learn more about this on our <ahref="https://designsystem.digital.gov/design-tokens/color/overview/#magic-number-2">Using Color</a> page.)
215
+
</p>
216
+
<pclass="step-description">
217
+
However, when you use theme tokens in your rules, like <strong>"primary-dark"</strong>, it's not as obvious what numerical grade you're using and it can lead to contrast errors.
218
+
</p>
219
+
<pclass="step-description">
220
+
When we build components internally, we use a more advanced tool to automatically check color contrast. If we replace our text and background color definitions with the combined <strong>set-text-and-bg()</strong> mixin, we can not only set the background color and the text color in the same mixin, but USWDS will check the contrast and provide a compile warning if there isn't AA contrast.
<h3class="step">Using uswds theme tokens with mixins</h3>
197
235
<pclass="step-description">
198
-
Finally, lets use a combination of utility mixins and uswds theme settings to display how you can add uniformity across your project! In this example, we'll add the border settings from step one to help our new component sit nicely with the original card.
236
+
This time, when you save and compile you'll see a warning in the terminal. Let's update our code to use <strong>primary-lighter</strong> as our text color.
This time, we don't get a warning, and our component looks even better. Not bad!
251
+
</p>
210
252
<pclass="step-description">
211
253
And voila! You've used theme settings, custom styles, USWDS tokens, and utility mixins to theme, customize, and extend USWDS into creating our very own component! Great work!
0 commit comments