@workday/canvas-kit-docs 9.0.0-alpha.359-next.4 → 9.0.0-alpha.362-next.2

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.
@@ -6903,66 +6903,6 @@ module.exports = {specifications: [
6903
6903
  {
6904
6904
  "type": "file",
6905
6905
  "name": "Toast.spec.ts",
6906
- "children": [
6907
- {
6908
- "type": "describe",
6909
- "name": "Toast",
6910
- "children": [
6911
- {
6912
- "type": "describe",
6913
- "name": "given the 'Error' story is rendered",
6914
- "children": [
6915
- {
6916
- "type": "it",
6917
- "name": "should not have any axe errors"
6918
- }
6919
- ]
6920
- },
6921
- {
6922
- "type": "describe",
6923
- "name": "given the 'Success' story is rendered",
6924
- "children": [
6925
- {
6926
- "type": "it",
6927
- "name": "should not have any axe errors"
6928
- }
6929
- ]
6930
- },
6931
- {
6932
- "type": "describe",
6933
- "name": "given the toast with no close icon or action button",
6934
- "children": [
6935
- {
6936
- "type": "it",
6937
- "name": "should have a role of status"
6938
- },
6939
- {
6940
- "type": "it",
6941
- "name": "should have aria live set to polite"
6942
- },
6943
- {
6944
- "type": "it",
6945
- "name": "should have aria atomic set to true"
6946
- }
6947
- ]
6948
- },
6949
- {
6950
- "type": "describe",
6951
- "name": "given the toast with a close button and action button",
6952
- "children": [
6953
- {
6954
- "type": "it",
6955
- "name": "should have a role of dialog"
6956
- }
6957
- ]
6958
- }
6959
- ]
6960
- }
6961
- ]
6962
- },
6963
- {
6964
- "type": "file",
6965
- "name": "ToastLabs.spec.ts",
6966
6906
  "children": [
6967
6907
  {
6968
6908
  "type": "describe",
@@ -11,6 +11,7 @@ any questions.
11
11
  - [Stack](#stack-hstack-vstack)
12
12
  - [Component Updates](#component-updates)
13
13
  - [Buttons](#buttons)
14
+ - [Toast](#toast)
14
15
  - [Utility Updates](#utility-updates)
15
16
  - [focusRing](#focusring)
16
17
 
@@ -127,6 +128,37 @@ This change affects all of our `buttons` including:
127
128
  If you still wish for a specific `button` within a `form` to submit, just add the attribute
128
129
  `type="submit"`.
129
130
 
131
+ ### Toast
132
+
133
+ We've promoted `Toast` from Labs (`@workday/canvas-kit-labs-react`) to the Main
134
+ (`@workday/canvas-kit-react`) package.
135
+
136
+ - This component is a
137
+ [compound component](/getting-started/for-developers/resources/compound-components/).
138
+ - It has a `mode` prop that allows for proper accessibility attributes to be defined.
139
+ - Its sub components allow for more flexibility and access to lower level elements.
140
+
141
+ ```tsx
142
+ // v8
143
+ <Toast actionText="View more details" onClose={handleClose}>Your workbook was successfully processed.</Toast>
144
+
145
+ // v9
146
+ <Toast mode="dialog">
147
+ <Toast.Icon icon={checkIcon} color={colors.greenApple400} />
148
+ <Toast.Body>
149
+ <Toast.Message>Your workbook was successfully processed.</Toast.Message>
150
+ <Toast.Link href="#hreflink">Custom Link</Toast.Link>
151
+ </Toast.Body>
152
+ <Toast.CloseIcon aria-label="Close" onClick={handleClose} />
153
+ </Toast>
154
+ ```
155
+
156
+ 🤖 The codemod will convert the `Toast` into a compound component with it's sub components having
157
+ the correct props.
158
+
159
+ > **Note**: If your Toast is a warning of some kind, you'll have to manually set the `mode` to
160
+ > `alert`.
161
+
130
162
  ## Utility Updates
131
163
 
132
164
  ### focusRing
@@ -32,9 +32,9 @@ export default () => {
32
32
  * @param id The id of the item that will be removed
33
33
  */
34
34
  const removeItem = <T extends unknown>(id: string, model: ReturnType<typeof useTabsModel>) => {
35
- const index = model.state.items.findIndex(item => model.getId(item) === model.state.cursorId);
35
+ const index = model.state.items.findIndex(item => item.id === model.state.cursorId);
36
36
  const nextIndex = index === model.state.items.length - 1 ? index - 1 : index + 1;
37
- const nextId = model.getId(model.state.items[nextIndex]);
37
+ const nextId = model.state.items[nextIndex].id;
38
38
  if (model.state.selectedIds[0] === id) {
39
39
  // We're removing the currently selected item. Select next item
40
40
  model.events.select({id: nextId});
@@ -1,13 +1,12 @@
1
1
  import React from 'react';
2
2
 
3
- import {Toast} from '@workday/canvas-kit-labs-react/toast';
3
+ import {Toast} from '@workday/canvas-kit-react/toast';
4
4
  import {checkIcon} from '@workday/canvas-system-icons-web';
5
- import {colors} from '@workday/canvas-kit-react/tokens';
6
5
 
7
6
  export default () => {
8
7
  return (
9
8
  <Toast>
10
- <Toast.Icon icon={checkIcon} color={colors.greenApple400} />
9
+ <Toast.Icon icon={checkIcon} color="greenApple400" />
11
10
  <Toast.Body>
12
11
  <Toast.Message>Your workbook was successfully processed.</Toast.Message>
13
12
  </Toast.Body>
@@ -1,14 +1,22 @@
1
- import * as React from 'react';
1
+ import React from 'react';
2
+
2
3
  import {Toast} from '@workday/canvas-kit-react/toast';
4
+ import {checkIcon} from '@workday/canvas-system-icons-web';
5
+ import {colors} from '@workday/canvas-kit-react/tokens';
3
6
  import {CanvasProvider, ContentDirection} from '@workday/canvas-kit-react/common';
4
7
 
5
8
  export default () => {
6
- const handleClose = () => {
7
- console.log('close button clicked');
8
- };
9
+ const handleClose = () => console.log('close button clicked');
10
+
9
11
  return (
10
12
  <CanvasProvider theme={{canvas: {direction: ContentDirection.RTL}}}>
11
- <Toast onClose={handleClose}>Your workbook was successfully processed.</Toast>
13
+ <Toast mode="dialog">
14
+ <Toast.Icon icon={checkIcon} color="greenApple400" />
15
+ <Toast.Body>
16
+ <Toast.Message>Your workbook was successfully processed.</Toast.Message>
17
+ </Toast.Body>
18
+ <Toast.CloseIcon aria-label="Close" onClick={handleClose} />
19
+ </Toast>
12
20
  </CanvasProvider>
13
21
  );
14
22
  };
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
 
3
- import {Toast} from '@workday/canvas-kit-labs-react/toast';
3
+ import {Toast} from '@workday/canvas-kit-react/toast';
4
4
  import {exclamationCircleIcon} from '@workday/canvas-system-icons-web';
5
5
  import {colors} from '@workday/canvas-kit-react/tokens';
6
6
 
@@ -1,12 +1,11 @@
1
1
  import React from 'react';
2
2
 
3
- import {Toast} from '@workday/canvas-kit-labs-react/toast';
3
+ import {Toast} from '@workday/canvas-kit-react/toast';
4
4
  import {checkIcon} from '@workday/canvas-system-icons-web';
5
- import {colors} from '@workday/canvas-kit-react/tokens';
6
5
 
7
6
  export default () => (
8
- <Toast mode="dialog">
9
- <Toast.Icon icon={checkIcon} color={colors.greenApple400} />
7
+ <Toast mode="dialog" aria-label="notification">
8
+ <Toast.Icon icon={checkIcon} color="greenApple400" />
10
9
  <Toast.Body>
11
10
  <Toast.Message>Your workbook was successfully processed.</Toast.Message>
12
11
  <Toast.Link href="#hreflink">Custom Link</Toast.Link>
@@ -1,16 +1,20 @@
1
- import * as React from 'react';
1
+ import React from 'react';
2
+
2
3
  import {Toast} from '@workday/canvas-kit-react/toast';
4
+ import {checkIcon} from '@workday/canvas-system-icons-web';
5
+ import {colors} from '@workday/canvas-kit-react/tokens';
3
6
 
4
7
  export default () => {
5
- const handleActionClick = () => {
6
- console.log('action button clicked');
7
- };
8
- const handleClose = () => {
9
- console.log('close button clicked');
10
- };
8
+ const handleClose = () => console.log('close button clicked');
9
+
11
10
  return (
12
- <Toast actionText="View more details" onActionClick={handleActionClick} onClose={handleClose}>
13
- Your workbook was successfully processed.
11
+ <Toast mode="dialog" aria-label="notification">
12
+ <Toast.Icon icon={checkIcon} color="greenApple400" />
13
+ <Toast.Body>
14
+ <Toast.Message>Your workbook was successfully</Toast.Message>
15
+ <Toast.Link href="#hyperlink">Custom Link</Toast.Link>
16
+ </Toast.Body>
17
+ <Toast.CloseIcon aria-label="Close" onClick={handleClose} />
14
18
  </Toast>
15
19
  );
16
20
  };
@@ -1,9 +1,19 @@
1
- import * as React from 'react';
1
+ import React from 'react';
2
+
2
3
  import {Toast} from '@workday/canvas-kit-react/toast';
4
+ import {checkIcon} from '@workday/canvas-system-icons-web';
5
+ import {colors} from '@workday/canvas-kit-react/tokens';
3
6
 
4
7
  export default () => {
5
- const handleClose = () => {
6
- console.log('close button clicked');
7
- };
8
- return <Toast onClose={handleClose}>Your workbook was successfully processed.</Toast>;
8
+ const handleClose = () => console.log('close button clicked');
9
+
10
+ return (
11
+ <Toast>
12
+ <Toast.Icon icon={checkIcon} color="greenApple400" />
13
+ <Toast.Body>
14
+ <Toast.Message>Your workbook was successfully processed.</Toast.Message>
15
+ </Toast.Body>
16
+ <Toast.CloseIcon aria-label="Close" onClick={handleClose} />
17
+ </Toast>
18
+ );
9
19
  };
@@ -1,7 +1,10 @@
1
- import * as React from 'react';
2
- import {SecondaryButton} from '@workday/canvas-kit-react/button';
3
- import {Popper} from '@workday/canvas-kit-react/popup';
1
+ import React from 'react';
2
+
4
3
  import {Toast} from '@workday/canvas-kit-react/toast';
4
+ import {checkIcon} from '@workday/canvas-system-icons-web';
5
+ import {colors} from '@workday/canvas-kit-react/tokens';
6
+ import {Popper} from '@workday/canvas-kit-react/popup';
7
+ import {SecondaryButton} from '@workday/canvas-kit-react/button';
5
8
 
6
9
  export default () => {
7
10
  const [open, setOpen] = React.useState(false);
@@ -19,7 +22,13 @@ export default () => {
19
22
  <div ref={containerRef}>
20
23
  <SecondaryButton onClick={handleOpen}>Show Toast</SecondaryButton>
21
24
  <Popper placement="bottom-end" open={open} anchorElement={containerRef}>
22
- <Toast onClose={handleClose}>Your workbook was successfully processed.</Toast>
25
+ <Toast mode="dialog" aria-label="notification">
26
+ <Toast.Icon icon={checkIcon} color="greenApple400" />
27
+ <Toast.Body>
28
+ <Toast.Message>Your workbook was successfully processed.</Toast.Message>
29
+ </Toast.Body>
30
+ <Toast.CloseIcon aria-label="Close" onClick={handleClose} />
31
+ </Toast>
23
32
  </Popper>
24
33
  </div>
25
34
  );
@@ -1,10 +1,10 @@
1
1
  import {SymbolDoc} from '@workday/canvas-kit-docs';
2
2
 
3
3
  import {Toast} from '@workday/canvas-kit-react/toast';
4
- import Success from './examples/Success';
5
- import Error from './examples/Error';
4
+ import Basic from './examples/Basic';
5
+ import ToastAlert from './examples/ToastAlert';
6
6
  import WithCloseButton from './examples/WithCloseButton';
7
- import WithActionLink from './examples/WithActionLink';
7
+ import ToastDialog from './examples/ToastDialog';
8
8
  import WithActionLinkAndCloseIcon from './examples/WithActionLinkAndCloseIcon';
9
9
  import WithPopper from './examples/WithPopper';
10
10
  import RTL from './examples/RTL';
@@ -12,10 +12,8 @@ import RTL from './examples/RTL';
12
12
 
13
13
  # Canvas Kit Toast
14
14
 
15
- `Toast` is a Canvas-styled React toast component. It allows for a brief message to be be shown about
16
- a process or action occurring in the app.
17
-
18
- [> Workday Design Reference](https://design.workday.com/components/popups/toasts)
15
+ `Toast` is a [compound component](/getting-started/for-developers/resources/compound-components/)
16
+ that contains updates or messages about the status of an application's process.
19
17
 
20
18
  ## Installation
21
19
 
@@ -25,39 +23,89 @@ yarn add @workday/canvas-kit-react
25
23
 
26
24
  ## Usage
27
25
 
28
- ### Basic Usage
26
+ ### Basic Example
27
+
28
+ `Toast` includes a container `Toast` component and the following subcomponents: `Toast.Body`,
29
+ `Toast.CloseIcon`, `Toast.Icon`, `Toast.Message`, and `Toast.Link`.
30
+
31
+ `Toast` supports different modes through the `mode` prop: `status`, `alert`, and `dialog`. Each mode
32
+ conveys a different purpose of the message and assigns the necessary ARIA attributes to support that
33
+ purpose and provide an accessible experience.
34
+
35
+ By default, `mode` is set to `status`, which indicates the message contains advisory information
36
+ such as a successful action.
29
37
 
30
- Below are examples we expect will work for most use cases. Note that all examples include icons as
31
- they are an important signifier to communicate meaning. For this reason, Toast notifications should
32
- always include an icon.
38
+ <ExampleCodeBlock code={Basic} />
33
39
 
34
- #### Complete Example with Popper
40
+ A `status` `Toast` will wrap the message within a `polite` ARIA live region with a `role` of
41
+ `status`.
35
42
 
36
- We use Popper to position Toast. Here's an example of how to use them together.
43
+ Here's a more complete example with a button which triggers a dismissable `Toast`. The `Toast` is
44
+ positioned using `Popper`.
37
45
 
38
46
  <ExampleCodeBlock code={WithPopper} />
39
47
 
40
- #### Success
48
+ ### Alert
41
49
 
42
- <ExampleCodeBlock code={Success} />
50
+ Set the `mode` prop to `alert` to convey urgent and important information such as an error.
43
51
 
44
- #### Error
52
+ <ExampleCodeBlock code={ToastAlert} />
45
53
 
46
- <ExampleCodeBlock code={Error} />
54
+ An `alert` `Toast` will wrap the message within an `assertive` ARIA live region with a `role` of
55
+ `alert`.
47
56
 
48
- #### WithCloseButton
57
+ ### Dialog
49
58
 
50
- <ExampleCodeBlock code={WithCloseButton} />
59
+ Set the `mode` prop to `dialog` to convey the presence of a follow-up action. If you use this
60
+ `mode`, you need to add an `aria-label`. This `aria-label` should be like additional information for the
61
+ `Toast`. The `Toast` will also add an `aria-describedby` that links the `Toast` to `Toast.Message`
62
+ so that it is read out to screen readers. The `aria-label` should be different that the contents of
63
+ the `Toast` so there is no duplication being read out by screen readers.
64
+
65
+ <ExampleCodeBlock code={ToastDialog} />
66
+
67
+ The `Toast` will be given a role of `dialog`. You need to provide an `aria-label` to add
68
+ additional information regarding the contents.
51
69
 
52
- #### With an Action Link
70
+ Screen readers will read it out in the following order: `"Notifcation: Your workbook was
71
+ successfully processed."
53
72
 
54
- <ExampleCodeBlock code={WithActionLink} />
73
+ > **Note**: You must use the `Toast.Message` subcomponent when the `mode` is `dialog` so that `id`
74
+ > is tied to the message for accessibility. You can also pass in a `model` with `useToastModel` to
75
+ > provide a specific `id` for the `Toast.Message`:
55
76
 
56
- #### With an Action Link and CloseIcon
77
+ ```tsx
78
+ export const CustomIDToast = () => {
79
+ const model = useToastModel({
80
+ id: '12df5',
81
+ mode: 'dialog',
82
+ });
83
+ return (
84
+ <Toast model={model}>
85
+ <Toast.Icon icon={checkIcon} color={colors.greenApple400} />
86
+ <Toast.Body>
87
+ <Toast.Message>Your workbook was successfully processed.</Toast.Message>
88
+ <Toast.Link href="#href">View More Details</Toast.Link>
89
+ </Toast.Body>
90
+ </Toast>
91
+ );
92
+ };
93
+ ```
94
+
95
+ ### Close Icon Button
96
+
97
+ Include the `Toast.CloseIcon` subcomponent to display a close button within the Toast.
98
+
99
+ <ExampleCodeBlock code={WithCloseButton} />
100
+
101
+ `Toast.CloseIcon` may be included within a `dialog` `Toast` to create a `Toast` with both an action
102
+ link and a close button.
57
103
 
58
104
  <ExampleCodeBlock code={WithActionLinkAndCloseIcon} />
59
105
 
60
- #### With RTL
106
+ ### Right-to-Left (RTL)
107
+
108
+ `Toast` supports right-to-left languages when specified in the `CanvasProvider` `theme`.
61
109
 
62
110
  <ExampleCodeBlock code={RTL} />
63
111
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@workday/canvas-kit-docs",
3
- "version": "9.0.0-alpha.359-next.4+6d2e2650",
3
+ "version": "9.0.0-alpha.362-next.2+ea2fe722",
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,9 +44,9 @@
44
44
  "dependencies": {
45
45
  "@emotion/styled": "^11.6.0",
46
46
  "@storybook/csf": "0.0.1",
47
- "@workday/canvas-kit-labs-react": "^9.0.0-alpha.359-next.4+6d2e2650",
48
- "@workday/canvas-kit-preview-react": "^9.0.0-alpha.359-next.4+6d2e2650",
49
- "@workday/canvas-kit-react": "^9.0.0-alpha.359-next.4+6d2e2650",
47
+ "@workday/canvas-kit-labs-react": "^9.0.0-alpha.362-next.2+ea2fe722",
48
+ "@workday/canvas-kit-preview-react": "^9.0.0-alpha.362-next.2+ea2fe722",
49
+ "@workday/canvas-kit-react": "^9.0.0-alpha.362-next.2+ea2fe722",
50
50
  "@workday/canvas-system-icons-web": "^3.0.0",
51
51
  "markdown-to-jsx": "^6.10.3",
52
52
  "ts-node": "^10.9.1"
@@ -57,5 +57,5 @@
57
57
  "mkdirp": "^1.0.3",
58
58
  "typescript": "4.2"
59
59
  },
60
- "gitHead": "6d2e2650a991da4f2e1b0f60bba9643fe8f483b1"
60
+ "gitHead": "ea2fe722d1176835120f765c4b9b88dcd5234fe5"
61
61
  }
@@ -1,22 +0,0 @@
1
- import React from 'react';
2
-
3
- import {Toast} from '@workday/canvas-kit-labs-react/toast';
4
- import {checkIcon} from '@workday/canvas-system-icons-web';
5
- import {colors} from '@workday/canvas-kit-react/tokens';
6
- import {CanvasProvider, ContentDirection} from '@workday/canvas-kit-react/common';
7
-
8
- export default () => {
9
- const handleClose = () => console.log('close button clicked');
10
-
11
- return (
12
- <CanvasProvider theme={{canvas: {direction: ContentDirection.RTL}}}>
13
- <Toast mode="dialog">
14
- <Toast.Icon icon={checkIcon} color={colors.greenApple400} />
15
- <Toast.Body>
16
- <Toast.Message>Your workbook was successfully processed.</Toast.Message>
17
- </Toast.Body>
18
- <Toast.CloseIcon aria-label="Close" onClick={handleClose} />
19
- </Toast>
20
- </CanvasProvider>
21
- );
22
- };
@@ -1,20 +0,0 @@
1
- import React from 'react';
2
-
3
- import {Toast} from '@workday/canvas-kit-labs-react/toast';
4
- import {checkIcon} from '@workday/canvas-system-icons-web';
5
- import {colors} from '@workday/canvas-kit-react/tokens';
6
-
7
- export default () => {
8
- const handleClose = () => console.log('close button clicked');
9
-
10
- return (
11
- <Toast mode="dialog">
12
- <Toast.Icon icon={checkIcon} color={colors.greenApple400} />
13
- <Toast.Body>
14
- <Toast.Message>Your workbook was successfully processed.</Toast.Message>
15
- <Toast.Link href="#hyperlink">Custom Link</Toast.Link>
16
- </Toast.Body>
17
- <Toast.CloseIcon aria-label="Close" onClick={handleClose} />
18
- </Toast>
19
- );
20
- };
@@ -1,19 +0,0 @@
1
- import React from 'react';
2
-
3
- import {Toast} from '@workday/canvas-kit-labs-react/toast';
4
- import {checkIcon} from '@workday/canvas-system-icons-web';
5
- import {colors} from '@workday/canvas-kit-react/tokens';
6
-
7
- export default () => {
8
- const handleClose = () => console.log('close button clicked');
9
-
10
- return (
11
- <Toast>
12
- <Toast.Icon icon={checkIcon} color={colors.greenApple400} />
13
- <Toast.Body>
14
- <Toast.Message>Your workbook was successfully processed.</Toast.Message>
15
- </Toast.Body>
16
- <Toast.CloseIcon aria-label="Close" onClick={handleClose} />
17
- </Toast>
18
- );
19
- };
@@ -1,35 +0,0 @@
1
- import React from 'react';
2
-
3
- import {Toast} from '@workday/canvas-kit-labs-react/toast';
4
- import {checkIcon} from '@workday/canvas-system-icons-web';
5
- import {colors} from '@workday/canvas-kit-react/tokens';
6
- import {Popper} from '@workday/canvas-kit-react/popup';
7
- import {SecondaryButton} from '@workday/canvas-kit-react/button';
8
-
9
- export default () => {
10
- const [open, setOpen] = React.useState(false);
11
- const containerRef = React.useRef(null);
12
-
13
- const handleClose = () => {
14
- setOpen(false);
15
- };
16
-
17
- const handleOpen = () => {
18
- setOpen(true);
19
- };
20
-
21
- return (
22
- <div ref={containerRef}>
23
- <SecondaryButton onClick={handleOpen}>Show Toast</SecondaryButton>
24
- <Popper placement="bottom-end" open={open} anchorElement={containerRef}>
25
- <Toast mode="dialog">
26
- <Toast.Icon icon={checkIcon} color={colors.greenApple400} />
27
- <Toast.Body>
28
- <Toast.Message>Your workbook was successfully processed.</Toast.Message>
29
- </Toast.Body>
30
- <Toast.CloseIcon aria-label="Close" onClick={handleClose} />
31
- </Toast>
32
- </Popper>
33
- </div>
34
- );
35
- };
@@ -1,107 +0,0 @@
1
- import {SymbolDoc} from '@workday/canvas-kit-docs';
2
-
3
- import {Toast} from '@workday/canvas-kit-labs-react/toast';
4
- import Basic from './examples/Basic';
5
- import ToastAlert from './examples/ToastAlert';
6
- import WithCloseButton from './examples/WithCloseButton';
7
- import ToastDialog from './examples/ToastDialog';
8
- import WithActionLinkAndCloseIcon from './examples/WithActionLinkAndCloseIcon';
9
- import WithPopper from './examples/WithPopper';
10
- import RTL from './examples/RTL';
11
-
12
-
13
- # Canvas Kit Toast
14
-
15
- `Toast` is a [compound component](/getting-started/for-developers/resources/compound-components/)
16
- that contains updates or messages about the status of an application's process.
17
-
18
- ## Installation
19
-
20
- ```sh
21
- yarn add @workday/canvas-kit-labs-react
22
- ```
23
-
24
- ## Usage
25
-
26
- ### Basic Example
27
-
28
- `Toast` includes a container `Toast` component and the following subcomponents: `Toast.Body`,
29
- `Toast.CloseIcon`, `Toast.Icon`, `Toast.Message`, and `Toast.Link`.
30
-
31
- `Toast` supports different modes through the `mode` prop: `status`, `alert`, and `dialog`. Each mode
32
- conveys a different purpose of the message and assigns the necessary ARIA attributes to support that
33
- purpose and provide an accessible experience.
34
-
35
- By default, `mode` is set to `status`, which indicates the message contains advisory information
36
- such as a successful action.
37
-
38
- <ExampleCodeBlock code={Basic} />
39
-
40
- A `status` `Toast` will wrap the message within a `polite` ARIA live region with a `role` of
41
- `status`.
42
-
43
- Here's a more complete example with a button which triggers a dismissable `Toast`. The `Toast` is
44
- positioned using `Popper`.
45
-
46
- <ExampleCodeBlock code={WithPopper} />
47
-
48
- ### Alert
49
-
50
- Set the `mode` prop to `alert` to convey urgent and important information such as an error.
51
-
52
- <ExampleCodeBlock code={ToastAlert} />
53
-
54
- An `alert` `Toast` will wrap the message within an `assertive` ARIA live region with a `role` of
55
- `alert`.
56
-
57
- ### Dialog
58
-
59
- Set the `mode` prop to `dialog` to convey the presence of a follow-up action.
60
-
61
- <ExampleCodeBlock code={ToastDialog} />
62
-
63
- The `Toast` will be given a role of `dialog` along with an `aria-label` to indicate that it's a
64
- notification.
65
-
66
- > **Note**: You must use the `Toast.Message` subcomponent when the `mode` is `dialog` so that `id`
67
- > is tied to the message for accessibility. You can also pass in a `model` with `useToastModel` to
68
- > provide a specific `id` for the `Toast.Message`:
69
-
70
- ```tsx
71
- export const CustomIDToast = () => {
72
- const model = useToastModel({
73
- id: '12df5',
74
- mode: 'dialog',
75
- });
76
- return (
77
- <Toast model={model}>
78
- <Toast.Icon icon={checkIcon} color={colors.greenApple400} />
79
- <Toast.Body>
80
- <Toast.Message>Your workbook was successfully processed.</Toast.Message>
81
- <Toast.Link href="#href">View More Details</Toast.Link>
82
- </Toast.Body>
83
- </Toast>
84
- );
85
- };
86
- ```
87
-
88
- ### Close Icon Button
89
-
90
- Include the `Toast.CloseIcon` subcomponent to display a close button within the Toast.
91
-
92
- <ExampleCodeBlock code={WithCloseButton} />
93
-
94
- `Toast.CloseIcon` may be included within a `dialog` `Toast` to create a `Toast` with both an action
95
- link and a close button.
96
-
97
- <ExampleCodeBlock code={WithActionLinkAndCloseIcon} />
98
-
99
- ### Right-to-Left (RTL)
100
-
101
- `Toast` supports right-to-left languages when specified in the `CanvasProvider` `theme`.
102
-
103
- <ExampleCodeBlock code={RTL} />
104
-
105
- ## Component API
106
-
107
- <SymbolDoc name="Toast" fileName="/labs-react/" />