Skip to content
This repository was archived by the owner on Jun 20, 2022. It is now read-only.

Commit a76d417

Browse files
committed
feat(a11y): support "prefers-reduce-motion"
Also add "transitionEnabled" in theme Also add documentation about accessiblity. Closes #39
1 parent 1e84292 commit a76d417

File tree

9 files changed

+80
-15
lines changed

9 files changed

+80
-15
lines changed

docs/basics/Accessibility.mdx

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
name: Accessiblity
3+
menu: 1. Basics
4+
order: 6
5+
---
6+
7+
import { Playground } from 'docz'
8+
9+
# Accessiblity
10+
11+
Smooth UI takes accessibility seriously. We do our best to ensure that all components are the most accessible for everyone and on all devices.
12+
13+
## Reduce motion preference
14+
15+
All components implement [reduced motion media query](https://css-tricks.com/introduction-reduced-motion-media-query/), it means they respect settings of users.
16+
17+
`transition` mixin automatically adds the reduced motion media query.
18+
19+
```js
20+
import { mixin } from '@smooth-ui/core-sc'
21+
22+
const AccessibleButton = styled.button`
23+
background-color: red;
24+
${mixin('transition', 'background-color 200ms')};
25+
26+
&:hover {
27+
background-color: blue;
28+
}
29+
`
30+
31+
/*
32+
CSS injected in the page will be:
33+
34+
background-color: red;
35+
transition: background-color 200ms;
36+
@media screen and (prefers-reduced-motion: reduce) {
37+
transition: none;
38+
}
39+
40+
&:hover {
41+
background-color: blue;
42+
}
43+
*/
44+
```
45+
46+
## Turn off all transitions
47+
48+
You can also choose to turn off all transitions by setting `transitionEnabled` to `false` in theme. See [theming guide](http://localhost:3000/docs-basics-theming).

src/Button.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const Button = createComponent(() => ({
2626
line-height: ${th('lineHeightBase')};
2727
border-width: ${th('btnBorderWidth')};
2828
cursor: pointer;
29-
transition: ${th('transitionBase')};
29+
${th('transitionBase')};
3030
3131
/* When used as link */
3232
text-decoration: none;

src/Checkbox.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ const Checkbox = createComponent(() => ({
7979
border-style: solid;
8080
border-width: ${th('inputBorderWidth')};
8181
border-color: ${th('inputBorderColor')};
82-
transition: ${th('transitionBase')};
82+
${th('transitionBase')};
8383
8484
&.checked {
8585
background-color: ${th('primary')};
@@ -103,7 +103,7 @@ const Checkbox = createComponent(() => ({
103103
width: 80%;
104104
pointer-events: none;
105105
transform: scale(0);
106-
transition: ${th('transitionBase')};
106+
${th('transitionBase')};
107107
}
108108
109109
&.sui-checkbox-sm {

src/Input.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const Input = createComponent(() => ({
2929
font-size: ${th('fontSizeBase')};
3030
line-height: ${th('inputLineHeight')};
3131
color: ${th('inputTextColor')};
32-
transition: ${th('transitionBase')};
32+
${th('transitionBase')};
3333
background-color: ${th('inputBgColor')};
3434
3535
&[type='number'] {

src/Modal.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import PropTypes from 'prop-types'
44
import { createPortal } from 'react-dom'
55
import classNames from 'classnames'
66
import { css, withTheme } from './styled-engine'
7-
import { th } from './utils/system'
7+
import { th, mixin } from './utils/system'
88
import Transition from './Transition'
99
import createComponent from './utils/createComponent'
1010

@@ -93,7 +93,10 @@ const Modal = createComponent(() => ({
9393
visibility: hidden;
9494
overflow: hidden;
9595
outline: 0;
96-
transition: opacity ${th('modalTransitionDuration')}ms ease-in-out;
96+
${mixin(
97+
'transition',
98+
css`opacity ${th('modalTransitionDuration')}ms ease-in-out`,
99+
)};
97100
98101
&.sui-modal-opened {
99102
visibility: visible;

src/Radio.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ const ModalHeader = createComponent(() => ({
7474
border-width: ${th('inputBorderWidth')};
7575
border-style: solid;
7676
border-color: ${th('inputBorderColor')};
77-
transition: ${th('transitionBase')};
77+
${th('transitionBase')};
7878
7979
&.checked {
8080
border-color: ${th('primary')};
@@ -96,7 +96,7 @@ const ModalHeader = createComponent(() => ({
9696
.sui-radio-circle {
9797
width: 10px;
9898
height: 10px;
99-
transition: ${th('transitionBase')};
99+
${th('transitionBase')};
100100
border-radius: 50%;
101101
background-color: ${th('primary')};
102102
transform: scale(0);

src/Select.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ const Select = createComponent(() => ({
7575
padding: ${th('inputPaddingY')} ${th('inputPaddingX')};
7676
font-size: ${th('fontSizeBase')};
7777
line-height: ${th('lineHeightBase')};
78-
transition: ${th('transitionBase')};
78+
${th('transitionBase')};
7979
color: ${th('inputTextColor')};
8080
${props => props.arrow && !props.multiple && 'padding-right: 1.6rem;'};
8181

src/Switch.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ const Switch = createComponent(() => ({
6565
border-width: ${th('inputBorderWidth')};
6666
border-color: ${th('inputBorderColor')};
6767
border-style: solid;
68-
transition: ${th('transitionBase')};
68+
${th('transitionBase')};
6969
font-size: 9px;
7070
font-weight: 800;
7171
@@ -97,14 +97,14 @@ const Switch = createComponent(() => ({
9797
border-radius: 50%;
9898
width: 18px;
9999
height: 18px;
100-
transition: ${th('transitionBase')};
100+
${th('transitionBase')};
101101
}
102102
103103
.sui-switch-content {
104104
display: flex;
105105
align-items: center;
106106
height: 22px;
107-
transition: ${th('transitionBase')};
107+
${th('transitionBase')};
108108
transform: translateX(-25px);
109109
}
110110

src/theme.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,18 @@ export const zIndexModal = 1050
257257
export const zIndexModalBackdrop = 1071
258258

259259
// Transitions
260+
export const transitionEnabled = true
261+
export const transition = p => value =>
262+
p.theme.transitionEnabled
263+
? css`
264+
transition: ${value};
265+
266+
@media screen and (prefers-reduced-motion: reduce) {
267+
transition: none;
268+
}
269+
`
270+
: ''
271+
260272
const safeTransitionProperties = [
261273
'color',
262274
'border-style',
@@ -267,9 +279,11 @@ const safeTransitionProperties = [
267279
'box-shadow',
268280
'transform',
269281
]
270-
export const transitionBase = safeTransitionProperties
271-
.map(prop => `${prop} .2s ease-in-out`)
272-
.join(',')
282+
283+
export const transitionBase = mixin(
284+
'transition',
285+
safeTransitionProperties.map(prop => `${prop} .2s ease-in-out`).join(','),
286+
)
273287

274288
// Breakpoints
275289

0 commit comments

Comments
 (0)