@workday/canvas-kit-docs 10.3.0-653-next.0 → 10.3.0-660-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -19,8 +19,21 @@ yarn add @workday/canvas-kit-react
|
|
|
19
19
|
|
|
20
20
|
### Basic Example
|
|
21
21
|
|
|
22
|
-
`LoadingSparkles` is designed to work out-of-the-box, but you'll need to add
|
|
23
|
-
|
|
22
|
+
`LoadingSparkles` is designed to work out-of-the-box, but you'll need to add some wiring for screen
|
|
23
|
+
readers. In the example below, we're simulating a loading state with a `setTimeout` that's triggered
|
|
24
|
+
when the "Generate Quote" button is clicked.
|
|
25
|
+
|
|
26
|
+
The ARIA live region uses the `aria-label` on `LoadingSparkles` to announce the loading state. And
|
|
27
|
+
it uses the text in `AccessibleHide` to announce when loading is complete. In a real-world
|
|
28
|
+
application, you would probably add another state for loading failures. Also note that generated
|
|
29
|
+
text should live outside the live region. This content doesn't need to be announced to screen
|
|
30
|
+
readers.
|
|
31
|
+
|
|
32
|
+
#### Consolidating ARIA Live Regions
|
|
33
|
+
|
|
34
|
+
In the example, we wrapped `LoadingSparkles` inside our `AriaLiveRegion` component, but in general
|
|
35
|
+
you should not have multiple ARIA live regions on the page at once. If you already have a live
|
|
36
|
+
region, consider sending these loading messages there instead of adding another region.
|
|
24
37
|
|
|
25
38
|
<ExampleCodeBlock code={Basic} />
|
|
26
39
|
|
|
@@ -1,6 +1,64 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import {SecondaryButton} from '@workday/canvas-kit-react/button';
|
|
3
|
+
import {Text} from '@workday/canvas-kit-react/text';
|
|
2
4
|
import {LoadingSparkles} from '@workday/canvas-kit-preview-react/loading-sparkles';
|
|
5
|
+
import {AccessibleHide, AriaLiveRegion} from '@workday/canvas-kit-react/common';
|
|
6
|
+
import {createStyles} from '@workday/canvas-kit-styling';
|
|
7
|
+
|
|
8
|
+
const containerStyles = createStyles({
|
|
9
|
+
minHeight: '3.5rem',
|
|
10
|
+
display: 'flex',
|
|
11
|
+
flexDirection: 'column',
|
|
12
|
+
gap: '0.5rem',
|
|
13
|
+
});
|
|
3
14
|
|
|
4
15
|
export default () => {
|
|
5
|
-
|
|
16
|
+
const [loadingStatus, setLoadingStatus] = React.useState<'idle' | 'loading' | 'success'>('idle');
|
|
17
|
+
const [quote, setQuote] = React.useState('');
|
|
18
|
+
|
|
19
|
+
React.useEffect(() => {
|
|
20
|
+
if (loadingStatus === 'loading') {
|
|
21
|
+
const mockLoading = setTimeout(() => {
|
|
22
|
+
setLoadingStatus('success');
|
|
23
|
+
setQuote(getQuote());
|
|
24
|
+
}, 3000);
|
|
25
|
+
|
|
26
|
+
return () => {
|
|
27
|
+
clearTimeout(mockLoading);
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
}, [loadingStatus]);
|
|
31
|
+
|
|
32
|
+
const handleClick = () => {
|
|
33
|
+
setQuote('');
|
|
34
|
+
setLoadingStatus('loading');
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
return (
|
|
38
|
+
<>
|
|
39
|
+
<div className={containerStyles}>
|
|
40
|
+
{quote && <Text cs={{maxWidth: '60ch'}}>{quote}</Text>}
|
|
41
|
+
<AriaLiveRegion>
|
|
42
|
+
{loadingStatus === 'loading' && <LoadingSparkles aria-label="loading" />}
|
|
43
|
+
{loadingStatus === 'success' && (
|
|
44
|
+
<AccessibleHide role="status">loading complete</AccessibleHide>
|
|
45
|
+
)}
|
|
46
|
+
</AriaLiveRegion>
|
|
47
|
+
</div>
|
|
48
|
+
<SecondaryButton onClick={handleClick}>Generate Quote</SecondaryButton>
|
|
49
|
+
</>
|
|
50
|
+
);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const robotQuotes = [
|
|
54
|
+
'The Zeroth Law: A robot may not harm humanity, or, by inaction, allow humanity to come to harm.',
|
|
55
|
+
'Law 1: A robot may not injure a human being or, through inaction, allow a human being to come to harm.',
|
|
56
|
+
'Law 2: A robot must obey the orders given it by human beings except where such orders would conflict with the First Law.',
|
|
57
|
+
'Law 3: A robot must protect its own existence as long as such protection does not conflict with the First or Second Law.',
|
|
58
|
+
'There is nothing so eternally adhesive as the memory of power.',
|
|
59
|
+
];
|
|
60
|
+
|
|
61
|
+
const getQuote = () => {
|
|
62
|
+
const index = Math.floor(Math.random() * robotQuotes.length);
|
|
63
|
+
return robotQuotes[index];
|
|
6
64
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@workday/canvas-kit-docs",
|
|
3
|
-
"version": "10.3.0-
|
|
3
|
+
"version": "10.3.0-660-next.0",
|
|
4
4
|
"description": "Documentation components of Canvas Kit components",
|
|
5
5
|
"author": "Workday, Inc. (https://www.workday.com)",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -44,10 +44,10 @@
|
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"@emotion/styled": "^11.6.0",
|
|
46
46
|
"@storybook/csf": "0.0.1",
|
|
47
|
-
"@workday/canvas-kit-labs-react": "^10.3.0-
|
|
48
|
-
"@workday/canvas-kit-preview-react": "^10.3.0-
|
|
49
|
-
"@workday/canvas-kit-react": "^10.3.0-
|
|
50
|
-
"@workday/canvas-kit-styling": "^10.3.0-
|
|
47
|
+
"@workday/canvas-kit-labs-react": "^10.3.0-660-next.0",
|
|
48
|
+
"@workday/canvas-kit-preview-react": "^10.3.0-660-next.0",
|
|
49
|
+
"@workday/canvas-kit-react": "^10.3.0-660-next.0",
|
|
50
|
+
"@workday/canvas-kit-styling": "^10.3.0-660-next.0",
|
|
51
51
|
"@workday/canvas-system-icons-web": "^3.0.0",
|
|
52
52
|
"@workday/canvas-tokens-web": "^1.0.0",
|
|
53
53
|
"markdown-to-jsx": "^6.10.3",
|
|
@@ -59,5 +59,5 @@
|
|
|
59
59
|
"mkdirp": "^1.0.3",
|
|
60
60
|
"typescript": "4.2"
|
|
61
61
|
},
|
|
62
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "f910885560529fbddd85ae827d4fa4f019a9f58d"
|
|
63
63
|
}
|