@workday/canvas-kit-react 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.
- package/collection/lib/useCursorListModel.tsx +1 -1
- package/collection/lib/useListItemRovingFocus.tsx +2 -5
- package/dist/commonjs/collection/lib/useCursorListModel.js +1 -1
- package/dist/commonjs/collection/lib/useListItemRovingFocus.d.ts.map +1 -1
- package/dist/commonjs/collection/lib/useListItemRovingFocus.js +2 -3
- package/dist/commonjs/popup/lib/PopupCloseIcon.d.ts.map +1 -1
- package/dist/commonjs/popup/lib/PopupCloseIcon.js +2 -7
- package/dist/commonjs/toast/index.d.ts +1 -0
- package/dist/commonjs/toast/index.d.ts.map +1 -1
- package/dist/commonjs/toast/index.js +1 -0
- package/dist/commonjs/toast/lib/Toast.d.ts +56 -22
- package/dist/commonjs/toast/lib/Toast.d.ts.map +1 -1
- package/dist/commonjs/toast/lib/Toast.js +95 -56
- package/dist/commonjs/toast/lib/ToastBody.d.ts +6 -0
- package/dist/commonjs/toast/lib/ToastBody.d.ts.map +1 -0
- package/dist/commonjs/toast/lib/ToastBody.js +38 -0
- package/dist/commonjs/toast/lib/ToastCloseIcon.d.ts +6 -0
- package/dist/commonjs/toast/lib/ToastCloseIcon.d.ts.map +1 -0
- package/dist/commonjs/toast/lib/ToastCloseIcon.js +26 -0
- package/dist/commonjs/toast/lib/ToastIcon.d.ts +5 -0
- package/dist/commonjs/toast/lib/ToastIcon.d.ts.map +1 -0
- package/dist/commonjs/toast/lib/ToastIcon.js +26 -0
- package/dist/commonjs/toast/lib/ToastLink.d.ts +5 -0
- package/dist/commonjs/toast/lib/ToastLink.d.ts.map +1 -0
- package/dist/commonjs/toast/lib/ToastLink.js +38 -0
- package/dist/commonjs/toast/lib/ToastMessage.d.ts +12 -0
- package/dist/commonjs/toast/lib/ToastMessage.d.ts.map +1 -0
- package/dist/commonjs/toast/lib/ToastMessage.js +38 -0
- package/dist/commonjs/toast/lib/hooks/useToastModel.d.ts +75 -0
- package/dist/commonjs/toast/lib/hooks/useToastModel.d.ts.map +1 -0
- package/dist/commonjs/toast/lib/hooks/useToastModel.js +37 -0
- package/dist/es6/collection/lib/useCursorListModel.js +1 -1
- package/dist/es6/collection/lib/useListItemRovingFocus.d.ts.map +1 -1
- package/dist/es6/collection/lib/useListItemRovingFocus.js +2 -3
- package/dist/es6/popup/lib/PopupCloseIcon.d.ts.map +1 -1
- package/dist/es6/popup/lib/PopupCloseIcon.js +3 -8
- package/dist/es6/toast/index.d.ts +1 -0
- package/dist/es6/toast/index.d.ts.map +1 -1
- package/dist/es6/toast/index.js +1 -0
- package/dist/es6/toast/lib/Toast.d.ts +56 -22
- package/dist/es6/toast/lib/Toast.d.ts.map +1 -1
- package/dist/es6/toast/lib/Toast.js +92 -37
- package/dist/es6/toast/lib/ToastBody.d.ts +6 -0
- package/dist/es6/toast/lib/ToastBody.d.ts.map +1 -0
- package/dist/es6/toast/lib/ToastBody.js +32 -0
- package/dist/es6/toast/lib/ToastCloseIcon.d.ts +6 -0
- package/dist/es6/toast/lib/ToastCloseIcon.d.ts.map +1 -0
- package/dist/es6/toast/lib/ToastCloseIcon.js +20 -0
- package/dist/es6/toast/lib/ToastIcon.d.ts +5 -0
- package/dist/es6/toast/lib/ToastIcon.d.ts.map +1 -0
- package/dist/es6/toast/lib/ToastIcon.js +20 -0
- package/dist/es6/toast/lib/ToastLink.d.ts +5 -0
- package/dist/es6/toast/lib/ToastLink.d.ts.map +1 -0
- package/dist/es6/toast/lib/ToastLink.js +32 -0
- package/dist/es6/toast/lib/ToastMessage.d.ts +12 -0
- package/dist/es6/toast/lib/ToastMessage.d.ts.map +1 -0
- package/dist/es6/toast/lib/ToastMessage.js +32 -0
- package/dist/es6/toast/lib/hooks/useToastModel.d.ts +75 -0
- package/dist/es6/toast/lib/hooks/useToastModel.d.ts.map +1 -0
- package/dist/es6/toast/lib/hooks/useToastModel.js +34 -0
- package/package.json +3 -3
- package/popup/lib/PopupCloseIcon.tsx +14 -15
- package/toast/LICENSE +1 -0
- package/toast/README.md +3 -5
- package/toast/index.ts +1 -0
- package/toast/lib/Toast.tsx +104 -109
- package/toast/lib/ToastBody.tsx +28 -0
- package/toast/lib/ToastCloseIcon.tsx +14 -0
- package/toast/lib/ToastIcon.tsx +23 -0
- package/toast/lib/ToastLink.tsx +17 -0
- package/toast/lib/ToastMessage.tsx +24 -0
- package/toast/lib/hooks/useToastModel.tsx +29 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
13
|
+
var t = {};
|
|
14
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
15
|
+
t[p] = s[p];
|
|
16
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
17
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
18
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
19
|
+
t[p[i]] = s[p[i]];
|
|
20
|
+
}
|
|
21
|
+
return t;
|
|
22
|
+
};
|
|
23
|
+
import React from 'react';
|
|
24
|
+
import { createSubcomponent } from '@workday/canvas-kit-react/common';
|
|
25
|
+
import { useToastModel } from './hooks/useToastModel';
|
|
26
|
+
import { Subtext } from '@workday/canvas-kit-react/text';
|
|
27
|
+
export var ToastMessage = createSubcomponent('p')({
|
|
28
|
+
modelHook: useToastModel,
|
|
29
|
+
})(function (_a, Element, model) {
|
|
30
|
+
var children = _a.children, elemProps = __rest(_a, ["children"]);
|
|
31
|
+
return (React.createElement(Subtext, __assign({ size: "large", wordBreak: "break-word", marginY: "zero", id: model.state.id, as: Element }, elemProps), children));
|
|
32
|
+
});
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
export declare type AriaRoleMode = 'dialog' | 'status' | 'alert';
|
|
2
|
+
export declare const useToastModel: (<TT_Special_Generic>(config?: (Partial<{
|
|
3
|
+
/**
|
|
4
|
+
* Sets the correct aria attributes for the Toast.
|
|
5
|
+
* Alert toasts are used to convey urgency and important information. The `role` is set to `alert`
|
|
6
|
+
* Status toasts are used to convey a message or a successful action. The `role` is set to `status`
|
|
7
|
+
* Dialog toasts are used when there's an action to be taken. The `role` is set to `dialog`.
|
|
8
|
+
* If you use this mode, you must add an aria-label to the main `Toast` component.
|
|
9
|
+
* The aria-label should provide additional information to the contents of the `Toast`.
|
|
10
|
+
* @default 'status'
|
|
11
|
+
*/
|
|
12
|
+
mode: AriaRoleMode;
|
|
13
|
+
/**
|
|
14
|
+
* When the Toast has a `mode="dialog"` this adds a unique id to `Toast.Message` so that the message gets read out for screen readers.
|
|
15
|
+
*/
|
|
16
|
+
id: string;
|
|
17
|
+
}> & {} & {}) | undefined) => {
|
|
18
|
+
state: {
|
|
19
|
+
id: string;
|
|
20
|
+
/**
|
|
21
|
+
* Sets the correct aria attributes for the Toast.
|
|
22
|
+
* Alert toasts are used to convey urgency and important information. The `role` is set to `alert`
|
|
23
|
+
* Status toasts are used to convey a message or a successful action. The `role` is set to `status`
|
|
24
|
+
* Dialog toasts are used when there's an action to be taken. The `role` is set to `dialog`.
|
|
25
|
+
* If you use this mode, you must add an aria-label to the main `Toast` component.
|
|
26
|
+
* The aria-label should provide additional information to the contents of the `Toast`.
|
|
27
|
+
* @default 'status'
|
|
28
|
+
*/
|
|
29
|
+
mode: AriaRoleMode;
|
|
30
|
+
};
|
|
31
|
+
events: {};
|
|
32
|
+
}) & import("@workday/canvas-kit-react/common").ModelExtras<{
|
|
33
|
+
/**
|
|
34
|
+
* Sets the correct aria attributes for the Toast.
|
|
35
|
+
* Alert toasts are used to convey urgency and important information. The `role` is set to `alert`
|
|
36
|
+
* Status toasts are used to convey a message or a successful action. The `role` is set to `status`
|
|
37
|
+
* Dialog toasts are used when there's an action to be taken. The `role` is set to `dialog`.
|
|
38
|
+
* If you use this mode, you must add an aria-label to the main `Toast` component.
|
|
39
|
+
* The aria-label should provide additional information to the contents of the `Toast`.
|
|
40
|
+
* @default 'status'
|
|
41
|
+
*/
|
|
42
|
+
mode: AriaRoleMode;
|
|
43
|
+
/**
|
|
44
|
+
* When the Toast has a `mode="dialog"` this adds a unique id to `Toast.Message` so that the message gets read out for screen readers.
|
|
45
|
+
*/
|
|
46
|
+
id: string;
|
|
47
|
+
}, {}, {
|
|
48
|
+
id: string;
|
|
49
|
+
/**
|
|
50
|
+
* Sets the correct aria attributes for the Toast.
|
|
51
|
+
* Alert toasts are used to convey urgency and important information. The `role` is set to `alert`
|
|
52
|
+
* Status toasts are used to convey a message or a successful action. The `role` is set to `status`
|
|
53
|
+
* Dialog toasts are used when there's an action to be taken. The `role` is set to `dialog`.
|
|
54
|
+
* If you use this mode, you must add an aria-label to the main `Toast` component.
|
|
55
|
+
* The aria-label should provide additional information to the contents of the `Toast`.
|
|
56
|
+
* @default 'status'
|
|
57
|
+
*/
|
|
58
|
+
mode: AriaRoleMode;
|
|
59
|
+
}, {}, {
|
|
60
|
+
state: {
|
|
61
|
+
id: string;
|
|
62
|
+
/**
|
|
63
|
+
* Sets the correct aria attributes for the Toast.
|
|
64
|
+
* Alert toasts are used to convey urgency and important information. The `role` is set to `alert`
|
|
65
|
+
* Status toasts are used to convey a message or a successful action. The `role` is set to `status`
|
|
66
|
+
* Dialog toasts are used when there's an action to be taken. The `role` is set to `dialog`.
|
|
67
|
+
* If you use this mode, you must add an aria-label to the main `Toast` component.
|
|
68
|
+
* The aria-label should provide additional information to the contents of the `Toast`.
|
|
69
|
+
* @default 'status'
|
|
70
|
+
*/
|
|
71
|
+
mode: AriaRoleMode;
|
|
72
|
+
};
|
|
73
|
+
events: {};
|
|
74
|
+
}>;
|
|
75
|
+
//# sourceMappingURL=useToastModel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useToastModel.d.ts","sourceRoot":"","sources":["../../../../../toast/lib/hooks/useToastModel.tsx"],"names":[],"mappings":"AACA,oBAAY,YAAY,GAAG,QAAQ,GAAG,QAAQ,GAAG,OAAO,CAAC;AAEzD,eAAO,MAAM,aAAa;IAEtB;;;;;;;;OAQG;;IAEH;;OAEG;;;;;QAZH;;;;;;;;WAQG;;;;;IARH;;;;;;;;OAQG;;IAEH;;OAEG;;;;IAZH;;;;;;;;OAQG;;;;;QARH;;;;;;;;WAQG;;;;EAeL,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
import { createModelHook, useUniqueId } from '@workday/canvas-kit-react/common';
|
|
13
|
+
export var useToastModel = createModelHook({
|
|
14
|
+
defaultConfig: {
|
|
15
|
+
/**
|
|
16
|
+
* Sets the correct aria attributes for the Toast.
|
|
17
|
+
* Alert toasts are used to convey urgency and important information. The `role` is set to `alert`
|
|
18
|
+
* Status toasts are used to convey a message or a successful action. The `role` is set to `status`
|
|
19
|
+
* Dialog toasts are used when there's an action to be taken. The `role` is set to `dialog`.
|
|
20
|
+
* If you use this mode, you must add an aria-label to the main `Toast` component.
|
|
21
|
+
* The aria-label should provide additional information to the contents of the `Toast`.
|
|
22
|
+
* @default 'status'
|
|
23
|
+
*/
|
|
24
|
+
mode: 'status',
|
|
25
|
+
/**
|
|
26
|
+
* When the Toast has a `mode="dialog"` this adds a unique id to `Toast.Message` so that the message gets read out for screen readers.
|
|
27
|
+
*/
|
|
28
|
+
id: '',
|
|
29
|
+
},
|
|
30
|
+
})(function (config) {
|
|
31
|
+
var id = useUniqueId(config.id);
|
|
32
|
+
var state = __assign(__assign({}, config), { id: id });
|
|
33
|
+
return { state: state, events: {} };
|
|
34
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@workday/canvas-kit-react",
|
|
3
|
-
"version": "9.0.0-alpha.
|
|
3
|
+
"version": "9.0.0-alpha.362-next.2+ea2fe722",
|
|
4
4
|
"description": "The parent module that contains all Workday Canvas Kit React components",
|
|
5
5
|
"author": "Workday, Inc. (https://www.workday.com)",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"@emotion/styled": "^11.6.0",
|
|
50
50
|
"@popperjs/core": "^2.5.4",
|
|
51
51
|
"@workday/canvas-colors-web": "^2.0.0",
|
|
52
|
-
"@workday/canvas-kit-popup-stack": "^9.0.0-alpha.
|
|
52
|
+
"@workday/canvas-kit-popup-stack": "^9.0.0-alpha.362-next.2+ea2fe722",
|
|
53
53
|
"@workday/canvas-system-icons-web": "^3.0.0",
|
|
54
54
|
"@workday/design-assets-types": "^0.2.8",
|
|
55
55
|
"chroma-js": "^2.1.0",
|
|
@@ -66,5 +66,5 @@
|
|
|
66
66
|
"@workday/canvas-accent-icons-web": "^3.0.0",
|
|
67
67
|
"@workday/canvas-applet-icons-web": "^2.0.0"
|
|
68
68
|
},
|
|
69
|
-
"gitHead": "
|
|
69
|
+
"gitHead": "ea2fe722d1176835120f765c4b9b88dcd5234fe5"
|
|
70
70
|
}
|
|
@@ -1,30 +1,29 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
|
|
3
3
|
import {xIcon} from '@workday/canvas-system-icons-web';
|
|
4
|
-
import {
|
|
5
|
-
styled,
|
|
6
|
-
createSubcomponent,
|
|
7
|
-
StyledType,
|
|
8
|
-
ExtractProps,
|
|
9
|
-
} from '@workday/canvas-kit-react/common';
|
|
4
|
+
import {createSubcomponent, ExtractProps} from '@workday/canvas-kit-react/common';
|
|
10
5
|
import {TertiaryButton} from '@workday/canvas-kit-react/button';
|
|
6
|
+
import {space} from '@workday/canvas-kit-react/tokens';
|
|
11
7
|
|
|
12
8
|
import {usePopupCloseButton, usePopupModel} from './hooks';
|
|
13
9
|
|
|
14
|
-
const closeIconSpacing = 4;
|
|
15
|
-
|
|
16
10
|
export interface PopupCloseIconProps extends ExtractProps<typeof TertiaryButton, never> {}
|
|
17
11
|
|
|
18
|
-
const StyledCloseIcon = styled(TertiaryButton)<StyledType & PopupCloseIconProps>({
|
|
19
|
-
position: 'absolute',
|
|
20
|
-
right: closeIconSpacing,
|
|
21
|
-
top: closeIconSpacing,
|
|
22
|
-
});
|
|
23
|
-
|
|
24
12
|
export const PopupCloseIcon = createSubcomponent('button')({
|
|
25
13
|
displayName: 'Popup.CloseIcon',
|
|
26
14
|
modelHook: usePopupModel,
|
|
27
15
|
elemPropsHook: usePopupCloseButton,
|
|
28
16
|
})<PopupCloseIconProps>(({children, ...elemProps}, Element) => {
|
|
29
|
-
return
|
|
17
|
+
return (
|
|
18
|
+
<TertiaryButton
|
|
19
|
+
as={Element}
|
|
20
|
+
size="medium"
|
|
21
|
+
icon={xIcon}
|
|
22
|
+
type="button"
|
|
23
|
+
position="absolute"
|
|
24
|
+
right={space.xxxs}
|
|
25
|
+
top={space.xxxs}
|
|
26
|
+
{...elemProps}
|
|
27
|
+
/>
|
|
28
|
+
);
|
|
30
29
|
});
|
package/toast/LICENSE
CHANGED
|
@@ -45,6 +45,7 @@ END OF TERMS AND CONDITIONS
|
|
|
45
45
|
|
|
46
46
|
©2020. Workday, Inc. All rights reserved. Workday and the Workday logo are registered trademarks of Workday, Inc. All other brand and product names are trademarks or registered trademarks of their respective holders.
|
|
47
47
|
|
|
48
|
+
|
|
48
49
|
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
|
|
49
50
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
50
51
|
|
package/toast/README.md
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
# Canvas Kit Toast
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
For more detailed information on this component, please refer to the
|
|
7
|
-
[storybook documentation](https://workday.github.io/canvas-kit/?path=/docs/components-popups-toast-react--with-popper#canvas-kit-toast)
|
|
3
|
+
View the
|
|
4
|
+
[documentation for Toast](https://workday.github.io/canvas-kit/?path=/docs/components-popups-toast-react--with-popper#canvas-kit-toast)
|
|
5
|
+
on Storybook.
|
package/toast/index.ts
CHANGED
package/toast/lib/Toast.tsx
CHANGED
|
@@ -1,118 +1,113 @@
|
|
|
1
|
-
import
|
|
1
|
+
import React from 'react';
|
|
2
2
|
|
|
3
|
+
import {createContainer, ExtractProps} from '@workday/canvas-kit-react/common';
|
|
4
|
+
import {Flex} from '@workday/canvas-kit-react/layout';
|
|
3
5
|
import {Popup} from '@workday/canvas-kit-react/popup';
|
|
4
|
-
import {space, colors, type, CanvasColor} from '@workday/canvas-kit-react/tokens';
|
|
5
|
-
import {SystemIcon} from '@workday/canvas-kit-react/icon';
|
|
6
|
-
import {checkIcon, exclamationCircleIcon} from '@workday/canvas-system-icons-web';
|
|
7
|
-
import {CanvasSystemIcon} from '@workday/design-assets-types';
|
|
8
|
-
import {createComponent, ExtractProps, styled, StyledType} from '@workday/canvas-kit-react/common';
|
|
9
|
-
import {Hyperlink} from '@workday/canvas-kit-react/button';
|
|
10
6
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* The color of the Toast icon.
|
|
19
|
-
* @default colors.greenApple400
|
|
20
|
-
*/
|
|
21
|
-
iconColor?: CanvasColor | string; // TODO: Fix
|
|
22
|
-
/**
|
|
23
|
-
* The text of the Toast message.
|
|
24
|
-
*/
|
|
25
|
-
children: string;
|
|
26
|
-
/**
|
|
27
|
-
* The function called when the Toast is closed.
|
|
28
|
-
*/
|
|
29
|
-
onClose?: () => void;
|
|
30
|
-
/**
|
|
31
|
-
* The function called when the Toast action is clicked.
|
|
32
|
-
*/
|
|
33
|
-
onActionClick?: () => void;
|
|
34
|
-
/**
|
|
35
|
-
* The text of the Toast action.
|
|
36
|
-
*/
|
|
37
|
-
actionText?: string;
|
|
38
|
-
}
|
|
39
|
-
const toastWidth = 360;
|
|
7
|
+
import {ToastCloseIcon} from './ToastCloseIcon';
|
|
8
|
+
import {ToastIcon} from './ToastIcon';
|
|
9
|
+
import {ToastMessage} from './ToastMessage';
|
|
10
|
+
import {ToastLink} from './ToastLink';
|
|
11
|
+
import {ToastBody} from './ToastBody';
|
|
12
|
+
import {useToastModel} from './hooks/useToastModel';
|
|
40
13
|
|
|
41
|
-
|
|
42
|
-
{
|
|
43
|
-
display: 'flex',
|
|
44
|
-
alignItems: 'center',
|
|
45
|
-
...type.levels.subtext.large,
|
|
46
|
-
},
|
|
47
|
-
({onClose}) => ({
|
|
48
|
-
marginRight: onClose ? space.m : undefined,
|
|
49
|
-
})
|
|
50
|
-
);
|
|
51
|
-
|
|
52
|
-
const ToastSystemIcon = styled(SystemIcon)({
|
|
53
|
-
marginRight: space.s,
|
|
54
|
-
alignSelf: 'start',
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
const {color, ...subTextLargeStyles} = type.levels.subtext.large;
|
|
14
|
+
export interface ToastProps extends Omit<ExtractProps<typeof Popup.Card, never>, 'model'> {}
|
|
58
15
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
16
|
+
/**
|
|
17
|
+
* The function helps set the correct aria attributes based on the mode
|
|
18
|
+
* @param mode Defines what aria attributes will be added to the main container
|
|
19
|
+
* @param id Used to tie the Toast to Toast.Message for screen readers
|
|
20
|
+
*/
|
|
21
|
+
const getAriaAttributes = (mode: string, id: string): React.HtmlHTMLAttributes<HTMLDivElement> => {
|
|
22
|
+
switch (mode) {
|
|
23
|
+
case 'dialog':
|
|
24
|
+
return {
|
|
25
|
+
'aria-describedby': id,
|
|
26
|
+
// This is added by Popup.Card, so overwriting to remove it
|
|
27
|
+
'aria-labelledby': undefined,
|
|
28
|
+
role: 'dialog',
|
|
29
|
+
};
|
|
30
|
+
case 'alert':
|
|
31
|
+
return {
|
|
32
|
+
role: 'alert',
|
|
33
|
+
'aria-live': 'assertive',
|
|
34
|
+
'aria-atomic': true,
|
|
35
|
+
};
|
|
36
|
+
case 'status':
|
|
37
|
+
return {
|
|
38
|
+
role: 'status',
|
|
39
|
+
'aria-live': 'polite',
|
|
40
|
+
'aria-atomic': true,
|
|
41
|
+
};
|
|
42
|
+
default: {
|
|
43
|
+
return {};
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
};
|
|
70
47
|
|
|
71
|
-
|
|
48
|
+
/**
|
|
49
|
+
* Toast is a compound component that has different modes based on its contents. The modes add the proper aria attributes for accessibility
|
|
50
|
+
*
|
|
51
|
+
* ```tsx
|
|
52
|
+
* import { Toast } from "@workday/canvas-kit-react/toast";
|
|
53
|
+
*
|
|
54
|
+
* const MyToast = (props: CardProps) => (
|
|
55
|
+
* <Toast mode="dialog" aria-label="notifcation">
|
|
56
|
+
* <Toast.Icon icon={checkIcon} color={colors.greenApple400} />
|
|
57
|
+
* <Toast.Body>
|
|
58
|
+
* <Toast.Message>Your workbook was successfully processed.</Toast.Message>
|
|
59
|
+
* <Toast.Link href="#hreflink">Custom Link</Toast.Link>
|
|
60
|
+
* </Toast.Body>
|
|
61
|
+
* <Toast.CloseIcon aria-label="Close" onClick={handleClose} />
|
|
62
|
+
* </Toast>
|
|
63
|
+
* );
|
|
64
|
+
*```
|
|
65
|
+
*/
|
|
66
|
+
export const Toast = createContainer('div')({
|
|
72
67
|
displayName: 'Toast',
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
<ToastContentContainer onClose={onClose}>
|
|
104
|
-
{icon && <ToastSystemIcon color={iconColor} colorHover={iconColor} icon={icon} />}
|
|
105
|
-
<Message>
|
|
106
|
-
{children}
|
|
107
|
-
{onActionClick && (
|
|
108
|
-
<StyledActionButton as="button" onClick={onActionClick}>
|
|
109
|
-
{actionText}
|
|
110
|
-
</StyledActionButton>
|
|
111
|
-
)}
|
|
112
|
-
</Message>
|
|
113
|
-
</ToastContentContainer>
|
|
114
|
-
</Popup.Body>
|
|
115
|
-
</Popup.Card>
|
|
116
|
-
);
|
|
68
|
+
modelHook: useToastModel,
|
|
69
|
+
subComponents: {
|
|
70
|
+
/**
|
|
71
|
+
* `Toast.Body` should container `Toast.Message` and `Toast.Link`. This ensures proper styling and spacing between elements.
|
|
72
|
+
*
|
|
73
|
+
* ```tsx
|
|
74
|
+
* <Toast.Body>
|
|
75
|
+
* <Toast.Message>Your workbook was successfully processed.</Toast.Message>
|
|
76
|
+
* <Toast.Link href="#hreflink">Custom Link</Toast.Link>
|
|
77
|
+
* </Toast.Body>
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
Body: ToastBody,
|
|
81
|
+
/**
|
|
82
|
+
* `Toast.CloseIcon` renders a {@link PopupCloseIcon}. You can pass an `onClick` when used with `Popper` to dismiss the `Toast`.
|
|
83
|
+
*/
|
|
84
|
+
CloseIcon: ToastCloseIcon,
|
|
85
|
+
/**
|
|
86
|
+
* `ToastIcon` renders a `SystemIcon` where you have access to all styling properties from `SystemIcon`.
|
|
87
|
+
*/
|
|
88
|
+
Icon: ToastIcon,
|
|
89
|
+
/**
|
|
90
|
+
* `Toast.Message` renders our `Subtext` component where you can style however way you'd like with style properties.
|
|
91
|
+
* This component also has an `id` so that when the `Toast` has a prop of `mode="dialog"` the message is read out by screen readers by adding an `aria-describedby` on the main `Toast` component.
|
|
92
|
+
*/
|
|
93
|
+
Message: ToastMessage,
|
|
94
|
+
/**
|
|
95
|
+
* `Toast.Link` renders our `Hyperlink` component. If you need to link to more information, use this component.
|
|
96
|
+
*/
|
|
97
|
+
Link: ToastLink,
|
|
117
98
|
},
|
|
99
|
+
})<ToastProps>(({children, ...elemProps}, _, model) => {
|
|
100
|
+
return (
|
|
101
|
+
<Popup.Card
|
|
102
|
+
as={Flex}
|
|
103
|
+
width={360}
|
|
104
|
+
padding="0"
|
|
105
|
+
{...getAriaAttributes(model.state.mode, model.state.id)}
|
|
106
|
+
flexDirection="row"
|
|
107
|
+
gap="xxxs"
|
|
108
|
+
{...elemProps}
|
|
109
|
+
>
|
|
110
|
+
{children}
|
|
111
|
+
</Popup.Card>
|
|
112
|
+
);
|
|
118
113
|
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import {createComponent, ExtractProps} from '@workday/canvas-kit-react/common';
|
|
4
|
+
import {Popup} from '@workday/canvas-kit-react/popup';
|
|
5
|
+
import {Flex} from '@workday/canvas-kit-react/layout';
|
|
6
|
+
|
|
7
|
+
export interface ToastBodyProps extends ExtractProps<typeof Popup.Body> {}
|
|
8
|
+
|
|
9
|
+
export const ToastBody = createComponent('div')({
|
|
10
|
+
displayName: 'Toast.Body',
|
|
11
|
+
Component: ({children, ...elemProps}: ToastBodyProps, ref, Element) => {
|
|
12
|
+
return (
|
|
13
|
+
<Flex
|
|
14
|
+
alignItems="flex-start"
|
|
15
|
+
flexDirection="column"
|
|
16
|
+
justifyContent="center"
|
|
17
|
+
paddingY="s"
|
|
18
|
+
ref={ref}
|
|
19
|
+
as={Element}
|
|
20
|
+
flexGrow={1}
|
|
21
|
+
gap="xxxs"
|
|
22
|
+
{...elemProps}
|
|
23
|
+
>
|
|
24
|
+
{children}
|
|
25
|
+
</Flex>
|
|
26
|
+
);
|
|
27
|
+
},
|
|
28
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {createComponent, ExtractProps} from '@workday/canvas-kit-react/common';
|
|
3
|
+
import {Popup} from '@workday/canvas-kit-react/popup';
|
|
4
|
+
|
|
5
|
+
export interface ToastCloseIconProps extends ExtractProps<typeof Popup.CloseIcon, never> {}
|
|
6
|
+
|
|
7
|
+
export const ToastCloseIcon = createComponent('button')({
|
|
8
|
+
displayName: 'Toast.CloseIcon',
|
|
9
|
+
Component: (elemProps: ToastCloseIconProps, ref, Element) => {
|
|
10
|
+
return (
|
|
11
|
+
<Popup.CloseIcon as={Element} ref={ref} size="small" position="relative" {...elemProps} />
|
|
12
|
+
);
|
|
13
|
+
},
|
|
14
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import {createComponent} from '@workday/canvas-kit-react/common';
|
|
4
|
+
import {SystemIcon, SystemIconProps} from '@workday/canvas-kit-react/icon';
|
|
5
|
+
|
|
6
|
+
export interface ToastIconProps extends Omit<SystemIconProps, 'colorHover'> {}
|
|
7
|
+
|
|
8
|
+
export const ToastIcon = createComponent('div')({
|
|
9
|
+
displayName: 'Toast.Icon',
|
|
10
|
+
Component: (elemProps: ToastIconProps, ref, Element) => {
|
|
11
|
+
return (
|
|
12
|
+
<SystemIcon
|
|
13
|
+
colorHover={elemProps.color}
|
|
14
|
+
marginY="s"
|
|
15
|
+
marginX="xs"
|
|
16
|
+
alignSelf="start"
|
|
17
|
+
ref={ref}
|
|
18
|
+
as={Element}
|
|
19
|
+
{...elemProps}
|
|
20
|
+
/>
|
|
21
|
+
);
|
|
22
|
+
},
|
|
23
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import {createComponent} from '@workday/canvas-kit-react/common';
|
|
4
|
+
import {Hyperlink, HyperlinkProps} from '@workday/canvas-kit-react/button';
|
|
5
|
+
|
|
6
|
+
export interface ToastLinkProps extends HyperlinkProps {}
|
|
7
|
+
|
|
8
|
+
export const ToastLink = createComponent('a')({
|
|
9
|
+
displayName: 'Toast.Link',
|
|
10
|
+
Component: ({children, href, ...elemProps}: ToastLinkProps, ref, Element) => {
|
|
11
|
+
return (
|
|
12
|
+
<Hyperlink ref={ref} href={href} as={Element} {...elemProps}>
|
|
13
|
+
{children}
|
|
14
|
+
</Hyperlink>
|
|
15
|
+
);
|
|
16
|
+
},
|
|
17
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import {createSubcomponent, ExtractProps} from '@workday/canvas-kit-react/common';
|
|
4
|
+
import {useToastModel} from './hooks/useToastModel';
|
|
5
|
+
import {Subtext} from '@workday/canvas-kit-react/text';
|
|
6
|
+
|
|
7
|
+
export interface ToastMessageProps extends Omit<ExtractProps<typeof Subtext>, 'size'> {}
|
|
8
|
+
|
|
9
|
+
export const ToastMessage = createSubcomponent('p')({
|
|
10
|
+
modelHook: useToastModel,
|
|
11
|
+
})<ToastMessageProps>(({children, ...elemProps}, Element, model) => {
|
|
12
|
+
return (
|
|
13
|
+
<Subtext
|
|
14
|
+
size="large"
|
|
15
|
+
wordBreak="break-word"
|
|
16
|
+
marginY="zero"
|
|
17
|
+
id={model.state.id}
|
|
18
|
+
as={Element}
|
|
19
|
+
{...elemProps}
|
|
20
|
+
>
|
|
21
|
+
{children}
|
|
22
|
+
</Subtext>
|
|
23
|
+
);
|
|
24
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import {createModelHook, useUniqueId} from '@workday/canvas-kit-react/common';
|
|
2
|
+
export type AriaRoleMode = 'dialog' | 'status' | 'alert';
|
|
3
|
+
|
|
4
|
+
export const useToastModel = createModelHook({
|
|
5
|
+
defaultConfig: {
|
|
6
|
+
/**
|
|
7
|
+
* Sets the correct aria attributes for the Toast.
|
|
8
|
+
* Alert toasts are used to convey urgency and important information. The `role` is set to `alert`
|
|
9
|
+
* Status toasts are used to convey a message or a successful action. The `role` is set to `status`
|
|
10
|
+
* Dialog toasts are used when there's an action to be taken. The `role` is set to `dialog`.
|
|
11
|
+
* If you use this mode, you must add an aria-label to the main `Toast` component.
|
|
12
|
+
* The aria-label should provide additional information to the contents of the `Toast`.
|
|
13
|
+
* @default 'status'
|
|
14
|
+
*/
|
|
15
|
+
mode: 'status' as AriaRoleMode,
|
|
16
|
+
/**
|
|
17
|
+
* When the Toast has a `mode="dialog"` this adds a unique id to `Toast.Message` so that the message gets read out for screen readers.
|
|
18
|
+
*/
|
|
19
|
+
id: '',
|
|
20
|
+
},
|
|
21
|
+
})(config => {
|
|
22
|
+
const id = useUniqueId(config.id);
|
|
23
|
+
const state = {
|
|
24
|
+
...config,
|
|
25
|
+
id,
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
return {state, events: {}};
|
|
29
|
+
});
|