Skip to content

Commit

Permalink
test(stylelint): add a11y rules to stylelint (#10780)
Browse files Browse the repository at this point in the history
* test(stylelint): add a11y rules to stylelint

* chore(stylelint): fix lint violations

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
Co-authored-by: Josh Black <[email protected]>
Co-authored-by: Taylor Jones <[email protected]>
  • Loading branch information
4 people authored Feb 28, 2022
1 parent 53413ac commit 2c28ad3
Show file tree
Hide file tree
Showing 25 changed files with 155 additions and 0 deletions.
Binary file not shown.
1 change: 1 addition & 0 deletions config/stylelint-config-carbon/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module.exports = {
require.resolve('./rules/possible-errors'),
require.resolve('./rules/limit-language-features'),
require.resolve('./rules/stylistic-issues'),
require.resolve('./plugins/a11y'),
require.resolve('./plugins/prettier'),
require.resolve('./plugins/scss'),
],
Expand Down
1 change: 1 addition & 0 deletions config/stylelint-config-carbon/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"stylelint": "^14.3.0"
},
"dependencies": {
"stylelint-a11y": "^1.2.3",
"stylelint-config-idiomatic-order": "^8.1.0",
"stylelint-config-prettier": "^9.0.3",
"stylelint-config-standard": "^24.0.0",
Expand Down
15 changes: 15 additions & 0 deletions config/stylelint-config-carbon/plugins/a11y.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* Copyright IBM Corp. 2018, 2018
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/

'use strict';

module.exports = {
plugins: ['stylelint-a11y'],
rules: {
'a11y/media-prefers-reduced-motion': true,
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@
content: '';
opacity: 0;
transition: opacity $duration--fast-01 motion(standard, productive);

@media screen and (prefers-reduced-motion: reduce) {
transition: none;
}
}
}

Expand Down
8 changes: 8 additions & 0 deletions packages/components/src/components/loading/_mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
animation-duration: 10ms;
animation-name: init-stroke;
animation-timing-function: $carbon--standard-easing;

@media screen and (prefers-reduced-motion: reduce) {
animation: none;
}
}
}

Expand All @@ -42,5 +46,9 @@
animation-fill-mode: forwards;
animation-name: stroke-end;
animation-timing-function: $carbon--ease-out;

@media screen and (prefers-reduced-motion: reduce) {
animation: none;
}
}
}
4 changes: 4 additions & 0 deletions packages/components/src/components/modal/_modal.scss
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@
transition: opacity $duration--moderate-02 motion(entrance, expressive),
visibility 0ms linear;
visibility: inherit;

@media screen and (prefers-reduced-motion: reduce) {
transition: none;
}
}

// V11: Question for design: do we have an updated tokens for fields that exist on `layer`?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@
content: '';
transition: background-color $duration--fast-02
motion(entrance, productive);

@media screen and (prefers-reduced-motion: reduce) {
transition: none;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
content: '';
opacity: 0;
transition: width $duration--fast-02 motion(standard, productive);

@media screen and (prefers-reduced-motion: reduce) {
transition: none;
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions packages/components/src/components/search/_search.scss
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@
content: '';
transition: background-color $duration--fast-02
motion(standard, productive);

@media screen and (prefers-reduced-motion: reduce) {
transition: none;
}
}

&:hover {
Expand Down
4 changes: 4 additions & 0 deletions packages/components/src/components/tile/_tile.scss
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@
transform-origin: center;
transition: $duration--fast-02 motion(standard, productive);

@media screen and (prefers-reduced-motion: reduce) {
transition: none;
}

// Windows, Firefox HCM Fix
@media screen and (-ms-high-contrast: active),
screen and (prefers-contrast) {
Expand Down
20 changes: 20 additions & 0 deletions packages/components/src/components/toggle/_toggle.scss
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@
border-radius: 50%;
content: '';
transition: transform $duration--fast-01 motion(exit, productive);

@media screen and (prefers-reduced-motion: reduce) {
transition: none;
}
}
}

Expand Down Expand Up @@ -197,6 +201,10 @@
transition: box-shadow $duration--fast-01 motion(exit, productive),
background-color $duration--fast-01 motion(exit, productive);
will-change: box-shadow;

@media screen and (prefers-reduced-motion: reduce) {
transition: none;
}
}

// Toggle circle
Expand Down Expand Up @@ -311,6 +319,10 @@
&::after {
cursor: not-allowed;
transition: $duration--fast-01 motion(exit, productive);

@media screen and (prefers-reduced-motion: reduce) {
transition: none;
}
}
}

Expand Down Expand Up @@ -430,6 +442,10 @@
transition: box-shadow $duration--fast-01 motion(exit, productive),
background-color $duration--fast-01 motion(exit, productive);
will-change: box-shadow;

@media screen and (prefers-reduced-motion: reduce) {
transition: none;
}
}

// Toggle circle
Expand Down Expand Up @@ -529,6 +545,10 @@
&::after {
cursor: not-allowed;
transition: $duration--fast-01 motion(exit, productive);

@media screen and (prefers-reduced-motion: reduce) {
transition: none;
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions packages/components/src/components/tooltip/_tooltip.scss
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
opacity: 0;
pointer-events: none;
transition: opacity $duration--fast-01 motion(standard, productive);

@media screen and (prefers-reduced-motion: reduce) {
transition: none;
}
}

&::before {
Expand Down
4 changes: 4 additions & 0 deletions packages/components/src/globals/scss/_tooltip.scss
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@
&::before,
&::after {
transition: opacity $duration--fast-01 motion(standard, productive);

@media screen and (prefers-reduced-motion: reduce) {
transition: none;
}
}

&.#{$prefix}--tooltip--a11y::before,
Expand Down
4 changes: 4 additions & 0 deletions packages/styles/scss/components/breadcrumb/_breadcrumb.scss
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@
content: '';
opacity: 0;
transition: opacity $duration-fast-01 motion(standard, productive);

@media screen and (prefers-reduced-motion: reduce) {
transition: none;
}
}
}

Expand Down
8 changes: 8 additions & 0 deletions packages/styles/scss/components/date-picker/_flatpickr.scss
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@

.flatpickr-calendar.animate.open {
animation: fp-fade-in-down $duration-fast-02 motion(entrance, productive);

@media screen and (prefers-reduced-motion: reduce) {
animation: none;
}
}

.flatpickr-calendar.inline {
Expand Down Expand Up @@ -230,6 +234,10 @@
// Windows HCM fix
@include high-contrast-mode('icon-fill');

@media screen and (prefers-reduced-motion: reduce) {
transition: none;
}

&:hover {
background-color: $background-hover;
}
Expand Down
8 changes: 8 additions & 0 deletions packages/styles/scss/components/loading/_animation.scss
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
animation-duration: 10ms;
animation-name: init-stroke;
animation-timing-function: motion.$standard-easing;

@media screen and (prefers-reduced-motion: reduce) {
animation: none;
}
}
}

Expand All @@ -35,5 +39,9 @@
animation-fill-mode: forwards;
animation-name: stroke-end;
animation-timing-function: motion.$ease-out;

@media screen and (prefers-reduced-motion: reduce) {
animation: none;
}
}
}
4 changes: 4 additions & 0 deletions packages/styles/scss/components/modal/_modal.scss
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@
transition: opacity $duration-moderate-02 motion(entrance, expressive),
visibility 0ms linear;
visibility: inherit;

@media screen and (prefers-reduced-motion: reduce) {
transition: none;
}
}

// V11: Question for design: do we have an updated tokens for fields that exist on `layer`?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@
content: '';
transition: background-color $duration-fast-02
motion(entrance, productive);

@media screen and (prefers-reduced-motion: reduce) {
transition: none;
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions packages/styles/scss/components/pagination-nav/_mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
content: '';
opacity: 0;
transition: width $duration-fast-02 motion(standard, productive);

@media screen and (prefers-reduced-motion: reduce) {
transition: none;
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions packages/styles/scss/components/search/_search.scss
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@
content: '';
transition: background-color $duration-fast-02
motion(standard, productive);

@media screen and (prefers-reduced-motion: reduce) {
transition: none;
}
}

&:hover {
Expand Down
4 changes: 4 additions & 0 deletions packages/styles/scss/components/tile/_tile.scss
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@
transform-origin: center;
transition: $duration-fast-02 motion(standard, productive);

@media screen and (prefers-reduced-motion: reduce) {
transition: none;
}

// Windows, Firefox HCM Fix
@media screen and (-ms-high-contrast: active),
screen and (prefers-contrast) {
Expand Down
24 changes: 24 additions & 0 deletions packages/styles/scss/components/toggle/_toggle.scss
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@
border-radius: 50%;
content: '';
transition: transform $duration-fast-01 motion(exit, productive);

@media screen and (prefers-reduced-motion: reduce) {
transition: none;
}
}
}

Expand Down Expand Up @@ -199,6 +203,10 @@
transition: box-shadow $duration-fast-01 motion(exit, productive),
background-color $duration-fast-01 motion(exit, productive);
will-change: box-shadow;

@media screen and (prefers-reduced-motion: reduce) {
transition: none;
}
}

// Toggle circle
Expand All @@ -215,6 +223,10 @@
content: '';
cursor: pointer;
transition: transform $duration-fast-01 motion(exit, productive);

@media screen and (prefers-reduced-motion: reduce) {
transition: none;
}
}
}

Expand Down Expand Up @@ -313,6 +325,10 @@
&::after {
cursor: not-allowed;
transition: $duration-fast-01 motion(exit, productive);

@media screen and (prefers-reduced-motion: reduce) {
transition: none;
}
}
}

Expand Down Expand Up @@ -432,6 +448,10 @@
transition: box-shadow $duration-fast-01 motion(exit, productive),
background-color $duration-fast-01 motion(exit, productive);
will-change: box-shadow;

@media screen and (prefers-reduced-motion: reduce) {
transition: none;
}
}

// Toggle circle
Expand Down Expand Up @@ -531,6 +551,10 @@
&::after {
cursor: not-allowed;
transition: $duration-fast-01 motion(exit, productive);

@media screen and (prefers-reduced-motion: reduce) {
transition: none;
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions packages/styles/scss/utilities/_tooltip.scss
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@
&::before,
&::after {
transition: opacity $duration-fast-01 motion(standard, productive);

@media screen and (prefers-reduced-motion: reduce) {
transition: none;
}
}

&.#{$prefix}--tooltip--a11y::before,
Expand Down
Loading

0 comments on commit 2c28ad3

Please sign in to comment.