This repository was archived by the owner on Jun 20, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 9 files changed +80
-15
lines changed Expand file tree Collapse file tree 9 files changed +80
-15
lines changed Original file line number Diff line number Diff line change
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 ) .
Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ const Button = createComponent(() => ({
26
26
line-height : ${ th ( 'lineHeightBase' ) } ;
27
27
border-width : ${ th ( 'btnBorderWidth' ) } ;
28
28
cursor : pointer;
29
- transition : ${ th ( 'transitionBase' ) } ;
29
+ ${ th ( 'transitionBase' ) } ;
30
30
31
31
/* When used as link */
32
32
text- decor ation: none;
Original file line number Diff line number Diff line change @@ -79,7 +79,7 @@ const Checkbox = createComponent(() => ({
79
79
border-style : solid;
80
80
border-width : ${ th ( 'inputBorderWidth' ) } ;
81
81
border-color: ${ th ( 'inputBorderColor' ) } ;
82
- transition : ${ th ( 'transitionBase' ) } ;
82
+ ${ th ( 'transitionBase' ) } ;
83
83
84
84
& .checked {
85
85
background-color : ${ th ( 'primary' ) } ;
@@ -103,7 +103,7 @@ const Checkbox = createComponent(() => ({
103
103
width : 80% ;
104
104
pointer-events : none;
105
105
transform : scale (0 );
106
- transition : ${ th ( 'transitionBase' ) } ;
106
+ ${ th ( 'transitionBase' ) } ;
107
107
}
108
108
109
109
& .sui-checkbox-sm {
Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ const Input = createComponent(() => ({
29
29
font-size : ${ th ( 'fontSizeBase' ) } ;
30
30
line-height : ${ th ( 'inputLineHeight' ) } ;
31
31
color: ${ th ( 'inputTextColor' ) } ;
32
- transition : ${ th ( 'transitionBase' ) } ;
32
+ ${ th ( 'transitionBase' ) } ;
33
33
background- color : ${ th ( 'inputBgColor' ) } ;
34
34
35
35
& [type = 'number' ] {
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ import PropTypes from 'prop-types'
4
4
import { createPortal } from 'react-dom'
5
5
import classNames from 'classnames'
6
6
import { css , withTheme } from './styled-engine'
7
- import { th } from './utils/system'
7
+ import { th , mixin } from './utils/system'
8
8
import Transition from './Transition'
9
9
import createComponent from './utils/createComponent'
10
10
@@ -93,7 +93,10 @@ const Modal = createComponent(() => ({
93
93
visibility : hidden;
94
94
overflow : hidden;
95
95
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
+ ) } ;
97
100
98
101
& .sui-modal-opened {
99
102
visibility : visible;
Original file line number Diff line number Diff line change @@ -74,7 +74,7 @@ const ModalHeader = createComponent(() => ({
74
74
border-width : ${ th ( 'inputBorderWidth' ) } ;
75
75
border-style : solid;
76
76
border-color: ${ th ( 'inputBorderColor' ) } ;
77
- transition : ${ th ( 'transitionBase' ) } ;
77
+ ${ th ( 'transitionBase' ) } ;
78
78
79
79
& .checked {
80
80
border-color : ${ th ( 'primary' ) } ;
@@ -96,7 +96,7 @@ const ModalHeader = createComponent(() => ({
96
96
.sui-radio-circle {
97
97
width : 10px ;
98
98
height : 10px ;
99
- transition : ${ th ( 'transitionBase' ) } ;
99
+ ${ th ( 'transitionBase' ) } ;
100
100
bor der- radius: 50%;
101
101
background- color : ${ th ( 'primary' ) } ;
102
102
transfor m: scale(0);
Original file line number Diff line number Diff line change @@ -75,7 +75,7 @@ const Select = createComponent(() => ({
75
75
padding : ${ th ( 'inputPaddingY' ) } ${ th ( 'inputPaddingX' ) } ;
76
76
font-size : ${ th ( 'fontSizeBase' ) } ;
77
77
line-height: ${ th ( 'lineHeightBase' ) } ;
78
- transition : ${ th ( 'transitionBase' ) } ;
78
+ ${ th ( 'transitionBase' ) } ;
79
79
color : ${ th ( 'inputTextColor' ) } ;
80
80
${ props => props . arrow && ! props . multiple && 'padding-right: 1.6rem;' } ;
81
81
Original file line number Diff line number Diff line change @@ -65,7 +65,7 @@ const Switch = createComponent(() => ({
65
65
border-width : ${ th ( 'inputBorderWidth' ) } ;
66
66
border-color : ${ th ( 'inputBorderColor' ) } ;
67
67
border-style : solid;
68
- transition : ${ th ( 'transitionBase' ) } ;
68
+ ${ th ( 'transitionBase' ) } ;
69
69
font- size: 9px;
70
70
font- weight: 800;
71
71
@@ -97,14 +97,14 @@ const Switch = createComponent(() => ({
97
97
border-radius : 50% ;
98
98
width : 18px ;
99
99
height : 18px ;
100
- transition : ${ th ( 'transitionBase' ) } ;
100
+ ${ th ( 'transitionBase' ) } ;
101
101
}
102
102
103
103
.sui-switch-content {
104
104
display : flex;
105
105
align-items : center;
106
106
height : 22px ;
107
- transition : ${ th ( 'transitionBase' ) } ;
107
+ ${ th ( 'transitionBase' ) } ;
108
108
transfor m: translateX(-25px);
109
109
}
110
110
Original file line number Diff line number Diff line change @@ -257,6 +257,18 @@ export const zIndexModal = 1050
257
257
export const zIndexModalBackdrop = 1071
258
258
259
259
// 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
+
260
272
const safeTransitionProperties = [
261
273
'color' ,
262
274
'border-style' ,
@@ -267,9 +279,11 @@ const safeTransitionProperties = [
267
279
'box-shadow' ,
268
280
'transform' ,
269
281
]
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
+ )
273
287
274
288
// Breakpoints
275
289
You can’t perform that action at this time.
0 commit comments