Crate ReNew Updates
Code Changes:
New Variables
- $button-border-width: 2px;
- $button-oneoff-letter-spacing: 1px;
- $link: #222;
Updated Variables
- $button-font-weight: 600;
- $button-radius: 0;
- $button-radius-focus-ring: 0;
- $button-text-transform: uppercase;
- $button-primary-letter-spacing: 1px;
- $button-secondary-letter-spacing: 1px;
- $button-tertiary-letter-spacing: 0;
- $button-xl-line-height: 44px;
- $button-lg-line-height: 36px;
- $button-md-line-height: 32px;
- $button-sm-line-height: 28px;
- $button-xs-line-height: 22px;
- $button-xl-font-size: 12px;
- $button-lg-font-size: 12px;
- $button-md-font-size: 12px;
- $button-primary-ring-color-disabled-focus: #ccc;
- $button-secondary-ring-color-disabled-focus: #ccc;
- $button-tertiary-ring-color-disabled-focus: #fff;
- // Tertiary Button - Default
- $button-tertiary-border: #f0efed;
- $button-tertiary-background: #f0efed;
- $button-tertiary-color: #222;
- $button-tertiary-letter-spacing: 0;
- // Tertiary Buttons - Hover
- $button-tertiary-border-hover: #f0efed;
- $button-tertiary-background-hover: #f0efed;
- $button-tertiary-color-hover: #222;
- // Tertiary Buttons - Focus
- $button-tertiary-border-focus: #666;
- $button-tertiary-background-focus: #f0efed;
- $button-tertiary-color-focus: #222;
- $button-tertiary-ring-color-focus: #666;
- $button-tertiary-box-shadow-focus: none;
- // Tertiary Buttons - Disabled
- $button-tertiary-border-disabled: #ccc;
- $button-tertiary-background-disabled: #fff;
- $button-tertiary-color-disabled: #ccc;
- $button-tertiary-ring-color-disabled-focus: #ccc;
New Classes
.button-place-order {
@include mixin-button-oneoff(
/* One-Off Buttons - Default */
$button-oneoff-border: #008000,
$button-oneoff-background: #008000,
$button-oneoff-color: #fff,
/* One-Off Buttons - Hover */
$button-oneoff-border-hover: #006400,
$button-oneoff-background-hover: #006400,
$button-oneoff-color-hover: #fff,
/* One-Off Buttons - Focus */
$button-oneoff-border-focus: #008000,
$button-oneoff-background-focus: #008000,
$button-oneoff-color-focus: #fff,
$button-oneoff-ring-color-focus: #fff,
$button-oneoff-box-shadow-focus: none,
/* One-Off Buttons - Disabled */
$button-oneoff-border-disabled: #b0bca7,
$button-oneoff-background-disabled: #b0bca7,
$button-oneoff-color-disabled: #fff
$button-oneoff-ring-color-disabled-focus: #fff
);
}
Updated Mixins
// Tertiary Button
@mixin mixin-button-tertiary {
border-color: $button-tertiary-border;
background: $button-tertiary-background;
color: $button-tertiary-color;
letter-spacing: $button-tertiary-letter-spacing;
text-transform: none;
&.hover,
&:hover {
border-color: $button-tertiary-border-hover;
background: $button-tertiary-background-hover;
color: $button-tertiary-color-hover;
}
&.focus,
&:focus {
@include mixin-button-focus-ring($button-tertiary-ring-color-focus);
border-color: $button-tertiary-border-focus;
background: $button-tertiary-background-focus;
color: $button-tertiary-color-focus;
box-shadow: $button-tertiary-box-shadow-focus;
}
&.disabled,
&[disabled],
&[aria-disabled="true"] {
border-color: $button-tertiary-border-disabled;
background: $button-tertiary-background-disabled;
color: $button-tertiary-color-disabled;
cursor: default;
&.hover,
&:hover {
border-color: $button-tertiary-border-disabled;
background: $button-tertiary-background-disabled;
color: $button-tertiary-color-disabled;
}
&.focus,
&:focus {
@include mixin-button-focus-ring($button-tertiary-ring-color-disabled-focus);
border-color: $button-tertiary-border-disabled;
background: $button-tertiary-background-disabled;
color: $button-tertiary-color-disabled;
box-shadow: none;
}
}
}
// One-Off Button
@mixin mixin-button-oneoff(
// One-Off Buttons - Default
$button-oneoff-border: #333,
$button-oneoff-background: #333,
$button-oneoff-color: #fff,
// One-Off Buttons - Hover
$button-oneoff-border-hover: #111,
$button-oneoff-background-hover: #111,
$button-oneoff-color-hover: #fff,
// One-Off Buttons - Focus
$button-oneoff-border-focus: #111,
$button-oneoff-background-focus: #111,
$button-oneoff-color-focus: #fff,
$button-oneoff-ring-color-focus: #111,
$button-oneoff-box-shadow-focus: none,
// One-Off Buttons - Disabled
$button-oneoff-border-disabled: #ccc,
$button-oneoff-background-disabled: #ccc,
$button-oneoff-color-disabled: #fff,
$button-oneoff-ring-color-disabled-focus: #ccc
) {
border-color: $button-oneoff-border;
background: $button-oneoff-background;
color: $button-oneoff-color;
letter-spacing: $button-oneoff-letter-spacing;
&:hover {
border-color: $button-oneoff-border-hover;
background: $button-oneoff-background-hover;
color: $button-oneoff-color-hover;
}
&:focus {
@include mixin-button-focus-ring($button-oneoff-ring-color-focus);
border-color: $button-oneoff-border-focus;
background: $button-oneoff-background-focus;
color: $button-oneoff-color-focus;
box-shadow: $button-oneoff-box-shadow-focus;
}
&.disabled,
&[disabled],
&[aria-disabled="true"] {
border-color: $button-oneoff-border-disabled;
background: $button-oneoff-background-disabled;
color: $button-oneoff-color-disabled;
cursor: default;
&:hover {
border-color: $button-oneoff-border-disabled;
background: $button-oneoff-background-disabled;
color: $button-oneoff-color-disabled;
}
&:focus {
@include mixin-button-focus-ring($button-oneoff-ring-color-disabled-focus);
border-color: $button-oneoff-border-disabled;
background: $button-oneoff-background-disabled;
color: $button-oneoff-color-disabled;
box-shadow: $button-oneoff-box-shadow-focus;
}
}
}
@mixin mixin-button-transparent {
display: inline;
background: none;
border: 0;
padding: 0;
color: $link;
text-align: left;
text-decoration: underline;
&:hover {
text-decoration: underline;
}
&:focus {
outline: $focus-outline-style $focus-outline-width;
outline-offset: $focus-outline-offset;
text-decoration: underline;
&::before {
display: none;
}
}
}
@mixin body-copy-link {
color: $link;
text-decoration: underline;
&:hover {
text-decoration: underline;
}
&:focus {
outline: $focus-outline-style $focus-outline-width;
outline-offset: $focus-outline-offset;
text-decoration: underline;
}
}
Buttons
Usage Notes
All items that appear to be buttons should use either a true <button>
element or an <a href="">
element.
This styling does not support the use of <input type="button" />
, <input type="submit" />
, or <input type="reset" />
.
Do not create overrides to default styling using the standard button classes. If you must override the default button styling, create and add a custom class and attach your styling to it. The recommended naming convention for custom button related classes is to start with .button-
and add a short descriptive word or two. For example: .button-place-order
Button or Link?
Short Version:
- Does it navigate to a new page? It's a link.
- Does it trigger an action on the page? It's a button.
Detailed Version:
- Does it navigates to a new page? Then it is a normal link, even if it looks like a button. Use a link. Do not use
role="button"
.- <a class="button" href="galaxy-far-far-away.html">Text</a>
- <a class="button" href="galaxy-far-far-away.html">Text</a>
- Does it submit a form?
- <button type="submit" class="button">Text</button>
- <button type="submit" class="button">Text</button>
- Does it reset a form?
- <button type="reset" class="button">Text</button>
- <button type="reset" class="button">Text</button>
- Does it open or close a popup or perform some other action on the same page?
- <button type="button" class="button">Text</button>
- <button type="button" class="button">Text</button>
- Does it have an on/off state that needs to be toggled (e.g. favorites heart)?
- Non-Pressed State:
<button type="button" class="button" aria-pressed="false">Text</button>
- Pressed State:
<button type="button" class="button" aria-pressed="true">Text</button>
- Non-Pressed State:
-
If a
<button>
would normally be used but you must use an<a>
element instead for some reason:- It must include
role="button"
and it must be able to gain focus via mouse or keyboard:
(Anhref=""
ortabindex="0"
is required for the<a>
to be in the tab order.)- <a class="button" role="button" href="javascript:;">Add to Cart</a>
or - <a class="button" role="button" tabindex="0">Add to Cart</a>
- <a class="button" role="button" href="javascript:;">Add to Cart</a>
- Toggle and state rules may still apply.
- See also required Event Triggers.
- It must include
Event Triggers
-
"Buttons" that are links to a different page must work when:
- Clicked with a mouse
- When focused via keyboard or script, with the enter key
- When tapped on a touch screen
-
This is the default behavior for link elements.
<a href="">Text</a>
-
Buttons that are anything else must work when:
- Clicked with a mouse
- When focused via keyboard or script, with the enter key
- When focused via keyboard or script, with the space key
(If you have used<a>
, you will be required to add support for this via script.)-
(To Do: A generic javascript snippet is being added to handle this automactically.
Don't also implement your own version, we want just one simple one to handle them.
Please tell Michelle the location of your button so we can be sure it gets tested when we add the script.)
-
(To Do: A generic javascript snippet is being added to handle this automactically.
- When tapped on a touch screen
-
This is the default behavior for button elements. Be sure to specify the type as
submit
is the default value. Most of ours should betype="button"
.
(e.g. opening modal dialogs, revealing panels on the page)<button type="button">Text</button>
Disabled Buttons
When a button is disabled, it requires additional attributes. This will ensure that screen reader software announces the button state correctly as well as automactically apply the disabled styling. Disabled elements generally should not be focusable so apply tabindex="-1"
. The disabled attribute is preferred on buttons as aria only changes how the button is announced to screen reader software, it doesn't apply any functionality changes. JavaScript would have to be used to also actually disable the button while you get that for free with the disabled attribute.
<button disabled>Button Text</button>
<a role="button" href="javascript:();" aria-disabled="true" tabindex="-1">Button Text</a>
When the button is re-enabled, be sure to reset these by:
<button>
- Removing the disabled attribute. Removing the tabindex attribute completely or setting it to zero.
or<a role="button" href="javascript:();" aria-disabled="false" tabindex="0">
- Setting their values toaria-disabled="false"
tabindex="0">