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

Commit

Permalink
feat(a11y): support "prefers-reduce-motion"
Browse files Browse the repository at this point in the history
Also add "transitionEnabled" in theme

Also add documentation about accessiblity.

Closes #39
  • Loading branch information
gregberge committed Sep 8, 2018
1 parent 1e84292 commit a76d417
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 15 deletions.
48 changes: 48 additions & 0 deletions docs/basics/Accessibility.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
name: Accessiblity
menu: 1. Basics
order: 6
---

import { Playground } from 'docz'

# Accessiblity

Smooth UI takes accessibility seriously. We do our best to ensure that all components are the most accessible for everyone and on all devices.

## Reduce motion preference

All components implement [reduced motion media query](https://css-tricks.com/introduction-reduced-motion-media-query/), it means they respect settings of users.

`transition` mixin automatically adds the reduced motion media query.

```js
import { mixin } from '@smooth-ui/core-sc'

const AccessibleButton = styled.button`
background-color: red;
${mixin('transition', 'background-color 200ms')};
&:hover {
background-color: blue;
}
`

/*
CSS injected in the page will be:
background-color: red;
transition: background-color 200ms;
@media screen and (prefers-reduced-motion: reduce) {
transition: none;
}
&:hover {
background-color: blue;
}
*/
```

## Turn off all transitions

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).
2 changes: 1 addition & 1 deletion src/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const Button = createComponent(() => ({
line-height: ${th('lineHeightBase')};
border-width: ${th('btnBorderWidth')};
cursor: pointer;
transition: ${th('transitionBase')};
${th('transitionBase')};
/* When used as link */
text-decoration: none;
Expand Down
4 changes: 2 additions & 2 deletions src/Checkbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ const Checkbox = createComponent(() => ({
border-style: solid;
border-width: ${th('inputBorderWidth')};
border-color: ${th('inputBorderColor')};
transition: ${th('transitionBase')};
${th('transitionBase')};
&.checked {
background-color: ${th('primary')};
Expand All @@ -103,7 +103,7 @@ const Checkbox = createComponent(() => ({
width: 80%;
pointer-events: none;
transform: scale(0);
transition: ${th('transitionBase')};
${th('transitionBase')};
}
&.sui-checkbox-sm {
Expand Down
2 changes: 1 addition & 1 deletion src/Input.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const Input = createComponent(() => ({
font-size: ${th('fontSizeBase')};
line-height: ${th('inputLineHeight')};
color: ${th('inputTextColor')};
transition: ${th('transitionBase')};
${th('transitionBase')};
background-color: ${th('inputBgColor')};
&[type='number'] {
Expand Down
7 changes: 5 additions & 2 deletions src/Modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import PropTypes from 'prop-types'
import { createPortal } from 'react-dom'
import classNames from 'classnames'
import { css, withTheme } from './styled-engine'
import { th } from './utils/system'
import { th, mixin } from './utils/system'
import Transition from './Transition'
import createComponent from './utils/createComponent'

Expand Down Expand Up @@ -93,7 +93,10 @@ const Modal = createComponent(() => ({
visibility: hidden;
overflow: hidden;
outline: 0;
transition: opacity ${th('modalTransitionDuration')}ms ease-in-out;
${mixin(
'transition',
css`opacity ${th('modalTransitionDuration')}ms ease-in-out`,
)};
&.sui-modal-opened {
visibility: visible;
Expand Down
4 changes: 2 additions & 2 deletions src/Radio.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const ModalHeader = createComponent(() => ({
border-width: ${th('inputBorderWidth')};
border-style: solid;
border-color: ${th('inputBorderColor')};
transition: ${th('transitionBase')};
${th('transitionBase')};
&.checked {
border-color: ${th('primary')};
Expand All @@ -96,7 +96,7 @@ const ModalHeader = createComponent(() => ({
.sui-radio-circle {
width: 10px;
height: 10px;
transition: ${th('transitionBase')};
${th('transitionBase')};
border-radius: 50%;
background-color: ${th('primary')};
transform: scale(0);
Expand Down
2 changes: 1 addition & 1 deletion src/Select.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const Select = createComponent(() => ({
padding: ${th('inputPaddingY')} ${th('inputPaddingX')};
font-size: ${th('fontSizeBase')};
line-height: ${th('lineHeightBase')};
transition: ${th('transitionBase')};
${th('transitionBase')};
color: ${th('inputTextColor')};
${props => props.arrow && !props.multiple && 'padding-right: 1.6rem;'};
Expand Down
6 changes: 3 additions & 3 deletions src/Switch.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const Switch = createComponent(() => ({
border-width: ${th('inputBorderWidth')};
border-color: ${th('inputBorderColor')};
border-style: solid;
transition: ${th('transitionBase')};
${th('transitionBase')};
font-size: 9px;
font-weight: 800;
Expand Down Expand Up @@ -97,14 +97,14 @@ const Switch = createComponent(() => ({
border-radius: 50%;
width: 18px;
height: 18px;
transition: ${th('transitionBase')};
${th('transitionBase')};
}
.sui-switch-content {
display: flex;
align-items: center;
height: 22px;
transition: ${th('transitionBase')};
${th('transitionBase')};
transform: translateX(-25px);
}
Expand Down
20 changes: 17 additions & 3 deletions src/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,18 @@ export const zIndexModal = 1050
export const zIndexModalBackdrop = 1071

// Transitions
export const transitionEnabled = true
export const transition = p => value =>
p.theme.transitionEnabled
? css`
transition: ${value};
@media screen and (prefers-reduced-motion: reduce) {
transition: none;
}
`
: ''

const safeTransitionProperties = [
'color',
'border-style',
Expand All @@ -267,9 +279,11 @@ const safeTransitionProperties = [
'box-shadow',
'transform',
]
export const transitionBase = safeTransitionProperties
.map(prop => `${prop} .2s ease-in-out`)
.join(',')

export const transitionBase = mixin(
'transition',
safeTransitionProperties.map(prop => `${prop} .2s ease-in-out`).join(','),
)

// Breakpoints

Expand Down

0 comments on commit a76d417

Please sign in to comment.