carbon-react 120.3.1 → 120.4.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.
- package/esm/components/message/message.component.d.ts +1 -1
- package/esm/components/message/message.component.js +1 -1
- package/esm/components/message/message.style.js +3 -2
- package/esm/components/message/type-icon/type-icon.component.js +6 -1
- package/esm/components/message/type-icon/type-icon.style.js +4 -2
- package/esm/components/toast/toast.component.d.ts +4 -1
- package/esm/components/toast/toast.component.js +27 -5
- package/esm/components/toast/toast.config.js +1 -1
- package/esm/components/toast/toast.style.d.ts +4 -0
- package/esm/components/toast/toast.style.js +36 -3
- package/lib/components/message/message.component.d.ts +1 -1
- package/lib/components/message/message.component.js +1 -1
- package/lib/components/message/message.style.js +3 -2
- package/lib/components/message/type-icon/type-icon.component.js +6 -1
- package/lib/components/message/type-icon/type-icon.style.js +4 -2
- package/lib/components/toast/toast.component.d.ts +4 -1
- package/lib/components/toast/toast.component.js +27 -5
- package/lib/components/toast/toast.config.js +1 -1
- package/lib/components/toast/toast.style.d.ts +4 -0
- package/lib/components/toast/toast.style.js +36 -3
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { MarginProps } from "styled-system";
|
|
3
|
-
export declare type MessageVariant = "error" | "info" | "success" | "warning";
|
|
3
|
+
export declare type MessageVariant = "error" | "info" | "success" | "warning" | "neutral";
|
|
4
4
|
export interface MessageProps extends MarginProps {
|
|
5
5
|
/** set content to component */
|
|
6
6
|
children?: React.ReactNode;
|
|
@@ -217,7 +217,7 @@ Message.propTypes = {
|
|
|
217
217
|
"showCloseIcon": PropTypes.bool,
|
|
218
218
|
"title": PropTypes.node,
|
|
219
219
|
"transparent": PropTypes.bool,
|
|
220
|
-
"variant": PropTypes.oneOf(["error", "info", "success", "warning"])
|
|
220
|
+
"variant": PropTypes.oneOf(["error", "info", "neutral", "success", "warning"])
|
|
221
221
|
};
|
|
222
222
|
export { Message };
|
|
223
223
|
Message.displayName = "Message";
|
|
@@ -4,9 +4,10 @@ import BaseTheme from "../../style/themes/base";
|
|
|
4
4
|
import StyledIconButton from "../icon-button/icon-button.style";
|
|
5
5
|
const messageVariants = {
|
|
6
6
|
error: "var(--colorsSemanticNegative500)",
|
|
7
|
-
info: "var(--
|
|
7
|
+
info: "var(--colorsSemanticInfo500)",
|
|
8
8
|
success: "var(--colorsSemanticPositive500)",
|
|
9
|
-
warning: "var(--colorsSemanticCaution500)"
|
|
9
|
+
warning: "var(--colorsSemanticCaution500)",
|
|
10
|
+
neutral: "var(--colorsSemanticNeutral500)"
|
|
10
11
|
};
|
|
11
12
|
const MessageStyle = styled.div`
|
|
12
13
|
position: relative;
|
|
@@ -6,11 +6,16 @@ const TypeIcon = ({
|
|
|
6
6
|
variant = "info",
|
|
7
7
|
transparent = false
|
|
8
8
|
}) => {
|
|
9
|
+
function iconToRender() {
|
|
10
|
+
if (variant === "neutral") return "info";
|
|
11
|
+
if (variant === "success") return "tick_circle";
|
|
12
|
+
return variant;
|
|
13
|
+
}
|
|
9
14
|
return /*#__PURE__*/React.createElement(TypeIconStyle, {
|
|
10
15
|
variant: variant,
|
|
11
16
|
transparent: transparent
|
|
12
17
|
}, /*#__PURE__*/React.createElement(Icon, {
|
|
13
|
-
type:
|
|
18
|
+
type: iconToRender()
|
|
14
19
|
}));
|
|
15
20
|
};
|
|
16
21
|
export default TypeIcon;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import styled, { css } from "styled-components";
|
|
2
2
|
const messageVariants = {
|
|
3
3
|
error: "var(--colorsSemanticNegative500)",
|
|
4
|
-
info: "var(--
|
|
4
|
+
info: "var(--colorsSemanticInfo500)",
|
|
5
5
|
success: "var(--colorsSemanticPositive500)",
|
|
6
|
-
warning: "var(--colorsSemanticCaution500)"
|
|
6
|
+
warning: "var(--colorsSemanticCaution500)",
|
|
7
|
+
neutral: "var(--colorsSemanticNeutral500)",
|
|
8
|
+
notification: "var(--colorsSemanticInfo500)"
|
|
7
9
|
};
|
|
8
10
|
const TypeIconStyle = styled.div`
|
|
9
11
|
align-items: center;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
declare type ToastVariants = "error" | "info" | "success" | "warning" | "notice";
|
|
2
|
+
declare type ToastVariants = "error" | "info" | "success" | "warning" | "notice" | "neutral" | "notification";
|
|
3
|
+
declare type AlignOptions = "left" | "center" | "right";
|
|
3
4
|
export interface ToastProps {
|
|
5
|
+
/** Sets the alignment of the component. */
|
|
6
|
+
align?: AlignOptions;
|
|
4
7
|
/** The rendered children of the component. */
|
|
5
8
|
children: React.ReactNode;
|
|
6
9
|
/** Customizes the appearance in the DLS theme */
|
|
@@ -9,7 +9,10 @@ import IconButton from "../icon-button";
|
|
|
9
9
|
import Events from "../../__internal__/utils/helpers/events";
|
|
10
10
|
import useLocale from "../../hooks/__internal__/useLocale";
|
|
11
11
|
import useModalManager from "../../hooks/__internal__/useModalManager";
|
|
12
|
+
import Logger from "../../__internal__/utils/logger";
|
|
13
|
+
let isDeprecationWarningTriggered = false;
|
|
12
14
|
const Toast = /*#__PURE__*/React.forwardRef(({
|
|
15
|
+
align,
|
|
13
16
|
children,
|
|
14
17
|
className,
|
|
15
18
|
id,
|
|
@@ -24,6 +27,7 @@ const Toast = /*#__PURE__*/React.forwardRef(({
|
|
|
24
27
|
...restProps
|
|
25
28
|
}, ref) => {
|
|
26
29
|
const isNotice = variant === "notice";
|
|
30
|
+
const isNotification = variant === "notification";
|
|
27
31
|
const locale = useLocale();
|
|
28
32
|
const toastRef = useRef(null);
|
|
29
33
|
const timer = useRef(null);
|
|
@@ -35,6 +39,10 @@ const Toast = /*#__PURE__*/React.forwardRef(({
|
|
|
35
39
|
if (ref && typeof ref === "object" && "current" in ref) {
|
|
36
40
|
refToPass = ref;
|
|
37
41
|
}
|
|
42
|
+
if (isCenter !== undefined && !isDeprecationWarningTriggered) {
|
|
43
|
+
isDeprecationWarningTriggered = true;
|
|
44
|
+
Logger.deprecate(`isCenter prop in ${Toast.displayName} is being deprecated in favour of the align prop.`);
|
|
45
|
+
}
|
|
38
46
|
const dismissToast = useCallback(ev => {
|
|
39
47
|
if (onDismiss && Events.isEscKey(ev)) {
|
|
40
48
|
ev.stopImmediatePropagation();
|
|
@@ -87,10 +95,19 @@ const Toast = /*#__PURE__*/React.forwardRef(({
|
|
|
87
95
|
type: "close"
|
|
88
96
|
}));
|
|
89
97
|
}
|
|
98
|
+
const iconToRender = {
|
|
99
|
+
notification: "alert",
|
|
100
|
+
neutral: "info",
|
|
101
|
+
success: "tick_circle",
|
|
102
|
+
error: "error",
|
|
103
|
+
info: "info",
|
|
104
|
+
warning: "warning"
|
|
105
|
+
};
|
|
106
|
+
const toastIcon = iconToRender[variant] || "none";
|
|
90
107
|
function renderToastContent() {
|
|
91
108
|
if (!open) return null;
|
|
92
109
|
let toastVariant;
|
|
93
|
-
if (
|
|
110
|
+
if (!isNotice && !isNotification) {
|
|
94
111
|
toastVariant = variant;
|
|
95
112
|
}
|
|
96
113
|
return /*#__PURE__*/React.createElement(CSSTransition, {
|
|
@@ -103,7 +120,9 @@ const Toast = /*#__PURE__*/React.forwardRef(({
|
|
|
103
120
|
},
|
|
104
121
|
nodeRef: toastContentNodeRef
|
|
105
122
|
}, /*#__PURE__*/React.createElement(ToastStyle, _extends({
|
|
123
|
+
align: align,
|
|
106
124
|
isNotice: isNotice,
|
|
125
|
+
isNotification: isNotification,
|
|
107
126
|
className: className
|
|
108
127
|
}, tagComponent(restProps["data-component"] || "toast", restProps), {
|
|
109
128
|
isCenter: isCenter,
|
|
@@ -114,10 +133,10 @@ const Toast = /*#__PURE__*/React.forwardRef(({
|
|
|
114
133
|
}, !disableAutoFocus && {
|
|
115
134
|
tabIndex,
|
|
116
135
|
onBlur: () => setTabIndex(undefined)
|
|
117
|
-
}),
|
|
118
|
-
variant: variant
|
|
136
|
+
}), !isNotice && /*#__PURE__*/React.createElement(TypeIcon, {
|
|
137
|
+
variant: isNotification ? "info" : variant
|
|
119
138
|
}, /*#__PURE__*/React.createElement(Icon, {
|
|
120
|
-
type:
|
|
139
|
+
type: toastIcon
|
|
121
140
|
})), /*#__PURE__*/React.createElement(ToastContentStyle, {
|
|
122
141
|
isNotice: isNotice,
|
|
123
142
|
isDismiss: !!onDismiss
|
|
@@ -125,15 +144,18 @@ const Toast = /*#__PURE__*/React.forwardRef(({
|
|
|
125
144
|
}
|
|
126
145
|
return /*#__PURE__*/React.createElement(StyledPortal, {
|
|
127
146
|
id: targetPortalId,
|
|
147
|
+
align: align,
|
|
128
148
|
isCenter: isCenter,
|
|
129
149
|
isNotice: isNotice
|
|
130
150
|
}, /*#__PURE__*/React.createElement(ToastWrapper, {
|
|
151
|
+
align: align,
|
|
131
152
|
isCenter: isCenter,
|
|
132
153
|
ref: refToPass,
|
|
133
154
|
isNotice: isNotice
|
|
134
155
|
}, /*#__PURE__*/React.createElement(TransitionGroup, null, renderToastContent())));
|
|
135
156
|
});
|
|
136
157
|
Toast.propTypes = {
|
|
158
|
+
"align": PropTypes.oneOf(["center", "left", "right"]),
|
|
137
159
|
"children": PropTypes.node,
|
|
138
160
|
"className": PropTypes.string,
|
|
139
161
|
"data-component": PropTypes.string,
|
|
@@ -145,7 +167,7 @@ Toast.propTypes = {
|
|
|
145
167
|
"open": PropTypes.bool,
|
|
146
168
|
"targetPortalId": PropTypes.string,
|
|
147
169
|
"timeout": PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
148
|
-
"variant": PropTypes.oneOf(["error", "info", "notice", "success", "warning"])
|
|
170
|
+
"variant": PropTypes.oneOf(["error", "info", "neutral", "notice", "notification", "success", "warning"])
|
|
149
171
|
};
|
|
150
172
|
export { Toast };
|
|
151
173
|
Toast.displayName = "Toast";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// eslint-disable-next-line import/prefer-default-export
|
|
2
|
-
export const TOAST_COLORS = ["error", "info", "success", "warning"];
|
|
2
|
+
export const TOAST_COLORS = ["error", "info", "success", "warning", "neutral", "notification"];
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import TypeIcon from "../message/type-icon/type-icon.style";
|
|
3
3
|
declare const StyledPortal: import("styled-components").StyledComponent<({ children, className, id, onReposition }: import("../portal/portal").PortalProps) => import("react").JSX.Element, any, {
|
|
4
|
+
align?: "left" | "right" | "center" | undefined;
|
|
4
5
|
isCenter?: boolean | undefined;
|
|
5
6
|
isNotice?: boolean | undefined;
|
|
6
7
|
}, never>;
|
|
@@ -8,15 +9,18 @@ declare const ToastStyle: import("styled-components").StyledComponent<"div", any
|
|
|
8
9
|
variant?: import("../message/message.component").MessageVariant | undefined;
|
|
9
10
|
transparent?: boolean | undefined;
|
|
10
11
|
} & import("styled-system").MarginProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> & {
|
|
12
|
+
align?: "left" | "right" | "center" | undefined;
|
|
11
13
|
maxWidth?: string | undefined;
|
|
12
14
|
isCenter?: boolean | undefined;
|
|
13
15
|
isNotice?: boolean | undefined;
|
|
16
|
+
isNotification?: boolean | undefined;
|
|
14
17
|
}, never>;
|
|
15
18
|
declare const ToastContentStyle: import("styled-components").StyledComponent<"div", any, Pick<import("../message/message-content/message-content.component").MessageContentProps, "showCloseIcon"> & {
|
|
16
19
|
isNotice?: boolean | undefined;
|
|
17
20
|
isDismiss?: boolean | undefined;
|
|
18
21
|
}, never>;
|
|
19
22
|
declare const ToastWrapper: import("styled-components").StyledComponent<"div", any, {
|
|
23
|
+
align?: "left" | "right" | "center" | undefined;
|
|
20
24
|
isCenter?: boolean | undefined;
|
|
21
25
|
isNotice?: boolean | undefined;
|
|
22
26
|
}, never>;
|
|
@@ -10,7 +10,8 @@ const StyledPortal = styled(Portal)`
|
|
|
10
10
|
${({
|
|
11
11
|
theme,
|
|
12
12
|
isCenter,
|
|
13
|
-
isNotice
|
|
13
|
+
isNotice,
|
|
14
|
+
align
|
|
14
15
|
}) => css`
|
|
15
16
|
position: fixed;
|
|
16
17
|
top: 0;
|
|
@@ -22,6 +23,22 @@ const StyledPortal = styled(Portal)`
|
|
|
22
23
|
transform: translateX(-50%);
|
|
23
24
|
`}
|
|
24
25
|
|
|
26
|
+
${align === "left" && css`
|
|
27
|
+
left: 12%;
|
|
28
|
+
transform: translateX(-50%);
|
|
29
|
+
`}
|
|
30
|
+
|
|
31
|
+
${align === "center" && css`
|
|
32
|
+
margin-left: 50%;
|
|
33
|
+
transform: translateX(-50%);
|
|
34
|
+
`}
|
|
35
|
+
|
|
36
|
+
${align === "right" && css`
|
|
37
|
+
display: flex;
|
|
38
|
+
right: 0;
|
|
39
|
+
transform: translateX(-50%);
|
|
40
|
+
`}
|
|
41
|
+
|
|
25
42
|
${isNotice && css`
|
|
26
43
|
bottom: 0;
|
|
27
44
|
top: auto;
|
|
@@ -37,7 +54,9 @@ const alternativeAnimationName = ".toast-alternative";
|
|
|
37
54
|
const ToastStyle = styled(MessageStyle)`
|
|
38
55
|
${({
|
|
39
56
|
maxWidth,
|
|
40
|
-
isCenter
|
|
57
|
+
isCenter,
|
|
58
|
+
align,
|
|
59
|
+
isNotification
|
|
41
60
|
}) => css`
|
|
42
61
|
box-shadow: 0 10px 30px 0 rgba(0, 20, 29, 0.1),
|
|
43
62
|
0 30px 60px 0 rgba(0, 20, 29, 0.1);
|
|
@@ -45,7 +64,11 @@ const ToastStyle = styled(MessageStyle)`
|
|
|
45
64
|
margin-top: 30px;
|
|
46
65
|
max-width: ${!maxWidth ? "300px" : maxWidth};
|
|
47
66
|
position: relative;
|
|
48
|
-
margin-right: ${isCenter ? "auto" : "30px"};
|
|
67
|
+
margin-right: ${isCenter || align === "right" ? "auto" : "30px"};
|
|
68
|
+
|
|
69
|
+
${isNotification && css`
|
|
70
|
+
border: 1px solid var(--colorsSemanticInfo500);
|
|
71
|
+
`}
|
|
49
72
|
`}
|
|
50
73
|
|
|
51
74
|
:focus {
|
|
@@ -139,6 +162,16 @@ const ToastContentStyle = styled(MessageContentStyle)`
|
|
|
139
162
|
`}
|
|
140
163
|
`;
|
|
141
164
|
const ToastWrapper = styled.div`
|
|
165
|
+
${({
|
|
166
|
+
align
|
|
167
|
+
}) => align && css`
|
|
168
|
+
position: relative;
|
|
169
|
+
width: auto;
|
|
170
|
+
height: auto;
|
|
171
|
+
justify-content: ${align};
|
|
172
|
+
display: flex;
|
|
173
|
+
`}
|
|
174
|
+
|
|
142
175
|
${({
|
|
143
176
|
isCenter
|
|
144
177
|
}) => isCenter && css`
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { MarginProps } from "styled-system";
|
|
3
|
-
export declare type MessageVariant = "error" | "info" | "success" | "warning";
|
|
3
|
+
export declare type MessageVariant = "error" | "info" | "success" | "warning" | "neutral";
|
|
4
4
|
export interface MessageProps extends MarginProps {
|
|
5
5
|
/** set content to component */
|
|
6
6
|
children?: React.ReactNode;
|
|
@@ -227,7 +227,7 @@ Message.propTypes = {
|
|
|
227
227
|
"showCloseIcon": _propTypes.default.bool,
|
|
228
228
|
"title": _propTypes.default.node,
|
|
229
229
|
"transparent": _propTypes.default.bool,
|
|
230
|
-
"variant": _propTypes.default.oneOf(["error", "info", "success", "warning"])
|
|
230
|
+
"variant": _propTypes.default.oneOf(["error", "info", "neutral", "success", "warning"])
|
|
231
231
|
};
|
|
232
232
|
Message.displayName = "Message";
|
|
233
233
|
var _default = Message;
|
|
@@ -13,9 +13,10 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
|
|
|
13
13
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
14
14
|
const messageVariants = {
|
|
15
15
|
error: "var(--colorsSemanticNegative500)",
|
|
16
|
-
info: "var(--
|
|
16
|
+
info: "var(--colorsSemanticInfo500)",
|
|
17
17
|
success: "var(--colorsSemanticPositive500)",
|
|
18
|
-
warning: "var(--colorsSemanticCaution500)"
|
|
18
|
+
warning: "var(--colorsSemanticCaution500)",
|
|
19
|
+
neutral: "var(--colorsSemanticNeutral500)"
|
|
19
20
|
};
|
|
20
21
|
const MessageStyle = _styledComponents.default.div`
|
|
21
22
|
position: relative;
|
|
@@ -13,11 +13,16 @@ const TypeIcon = ({
|
|
|
13
13
|
variant = "info",
|
|
14
14
|
transparent = false
|
|
15
15
|
}) => {
|
|
16
|
+
function iconToRender() {
|
|
17
|
+
if (variant === "neutral") return "info";
|
|
18
|
+
if (variant === "success") return "tick_circle";
|
|
19
|
+
return variant;
|
|
20
|
+
}
|
|
16
21
|
return /*#__PURE__*/_react.default.createElement(_typeIcon.default, {
|
|
17
22
|
variant: variant,
|
|
18
23
|
transparent: transparent
|
|
19
24
|
}, /*#__PURE__*/_react.default.createElement(_icon.default, {
|
|
20
|
-
type:
|
|
25
|
+
type: iconToRender()
|
|
21
26
|
}));
|
|
22
27
|
};
|
|
23
28
|
var _default = TypeIcon;
|
|
@@ -9,9 +9,11 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
|
|
|
9
9
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
10
10
|
const messageVariants = {
|
|
11
11
|
error: "var(--colorsSemanticNegative500)",
|
|
12
|
-
info: "var(--
|
|
12
|
+
info: "var(--colorsSemanticInfo500)",
|
|
13
13
|
success: "var(--colorsSemanticPositive500)",
|
|
14
|
-
warning: "var(--colorsSemanticCaution500)"
|
|
14
|
+
warning: "var(--colorsSemanticCaution500)",
|
|
15
|
+
neutral: "var(--colorsSemanticNeutral500)",
|
|
16
|
+
notification: "var(--colorsSemanticInfo500)"
|
|
15
17
|
};
|
|
16
18
|
const TypeIconStyle = _styledComponents.default.div`
|
|
17
19
|
align-items: center;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
declare type ToastVariants = "error" | "info" | "success" | "warning" | "notice";
|
|
2
|
+
declare type ToastVariants = "error" | "info" | "success" | "warning" | "notice" | "neutral" | "notification";
|
|
3
|
+
declare type AlignOptions = "left" | "center" | "right";
|
|
3
4
|
export interface ToastProps {
|
|
5
|
+
/** Sets the alignment of the component. */
|
|
6
|
+
align?: AlignOptions;
|
|
4
7
|
/** The rendered children of the component. */
|
|
5
8
|
children: React.ReactNode;
|
|
6
9
|
/** Customizes the appearance in the DLS theme */
|
|
@@ -14,11 +14,14 @@ var _iconButton = _interopRequireDefault(require("../icon-button"));
|
|
|
14
14
|
var _events = _interopRequireDefault(require("../../__internal__/utils/helpers/events"));
|
|
15
15
|
var _useLocale = _interopRequireDefault(require("../../hooks/__internal__/useLocale"));
|
|
16
16
|
var _useModalManager = _interopRequireDefault(require("../../hooks/__internal__/useModalManager"));
|
|
17
|
+
var _logger = _interopRequireDefault(require("../../__internal__/utils/logger"));
|
|
17
18
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
18
19
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
19
20
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
20
21
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
22
|
+
let isDeprecationWarningTriggered = false;
|
|
21
23
|
const Toast = /*#__PURE__*/_react.default.forwardRef(({
|
|
24
|
+
align,
|
|
22
25
|
children,
|
|
23
26
|
className,
|
|
24
27
|
id,
|
|
@@ -33,6 +36,7 @@ const Toast = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
33
36
|
...restProps
|
|
34
37
|
}, ref) => {
|
|
35
38
|
const isNotice = variant === "notice";
|
|
39
|
+
const isNotification = variant === "notification";
|
|
36
40
|
const locale = (0, _useLocale.default)();
|
|
37
41
|
const toastRef = (0, _react.useRef)(null);
|
|
38
42
|
const timer = (0, _react.useRef)(null);
|
|
@@ -44,6 +48,10 @@ const Toast = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
44
48
|
if (ref && typeof ref === "object" && "current" in ref) {
|
|
45
49
|
refToPass = ref;
|
|
46
50
|
}
|
|
51
|
+
if (isCenter !== undefined && !isDeprecationWarningTriggered) {
|
|
52
|
+
isDeprecationWarningTriggered = true;
|
|
53
|
+
_logger.default.deprecate(`isCenter prop in ${Toast.displayName} is being deprecated in favour of the align prop.`);
|
|
54
|
+
}
|
|
47
55
|
const dismissToast = (0, _react.useCallback)(ev => {
|
|
48
56
|
if (onDismiss && _events.default.isEscKey(ev)) {
|
|
49
57
|
ev.stopImmediatePropagation();
|
|
@@ -96,10 +104,19 @@ const Toast = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
96
104
|
type: "close"
|
|
97
105
|
}));
|
|
98
106
|
}
|
|
107
|
+
const iconToRender = {
|
|
108
|
+
notification: "alert",
|
|
109
|
+
neutral: "info",
|
|
110
|
+
success: "tick_circle",
|
|
111
|
+
error: "error",
|
|
112
|
+
info: "info",
|
|
113
|
+
warning: "warning"
|
|
114
|
+
};
|
|
115
|
+
const toastIcon = iconToRender[variant] || "none";
|
|
99
116
|
function renderToastContent() {
|
|
100
117
|
if (!open) return null;
|
|
101
118
|
let toastVariant;
|
|
102
|
-
if (
|
|
119
|
+
if (!isNotice && !isNotification) {
|
|
103
120
|
toastVariant = variant;
|
|
104
121
|
}
|
|
105
122
|
return /*#__PURE__*/_react.default.createElement(_reactTransitionGroup.CSSTransition, {
|
|
@@ -112,7 +129,9 @@ const Toast = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
112
129
|
},
|
|
113
130
|
nodeRef: toastContentNodeRef
|
|
114
131
|
}, /*#__PURE__*/_react.default.createElement(_toast.ToastStyle, _extends({
|
|
132
|
+
align: align,
|
|
115
133
|
isNotice: isNotice,
|
|
134
|
+
isNotification: isNotification,
|
|
116
135
|
className: className
|
|
117
136
|
}, (0, _tags.default)(restProps["data-component"] || "toast", restProps), {
|
|
118
137
|
isCenter: isCenter,
|
|
@@ -123,10 +142,10 @@ const Toast = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
123
142
|
}, !disableAutoFocus && {
|
|
124
143
|
tabIndex,
|
|
125
144
|
onBlur: () => setTabIndex(undefined)
|
|
126
|
-
}),
|
|
127
|
-
variant: variant
|
|
145
|
+
}), !isNotice && /*#__PURE__*/_react.default.createElement(_toast.TypeIcon, {
|
|
146
|
+
variant: isNotification ? "info" : variant
|
|
128
147
|
}, /*#__PURE__*/_react.default.createElement(_icon.default, {
|
|
129
|
-
type:
|
|
148
|
+
type: toastIcon
|
|
130
149
|
})), /*#__PURE__*/_react.default.createElement(_toast.ToastContentStyle, {
|
|
131
150
|
isNotice: isNotice,
|
|
132
151
|
isDismiss: !!onDismiss
|
|
@@ -134,9 +153,11 @@ const Toast = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
134
153
|
}
|
|
135
154
|
return /*#__PURE__*/_react.default.createElement(_toast.StyledPortal, {
|
|
136
155
|
id: targetPortalId,
|
|
156
|
+
align: align,
|
|
137
157
|
isCenter: isCenter,
|
|
138
158
|
isNotice: isNotice
|
|
139
159
|
}, /*#__PURE__*/_react.default.createElement(_toast.ToastWrapper, {
|
|
160
|
+
align: align,
|
|
140
161
|
isCenter: isCenter,
|
|
141
162
|
ref: refToPass,
|
|
142
163
|
isNotice: isNotice
|
|
@@ -144,6 +165,7 @@ const Toast = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
144
165
|
});
|
|
145
166
|
exports.Toast = Toast;
|
|
146
167
|
Toast.propTypes = {
|
|
168
|
+
"align": _propTypes.default.oneOf(["center", "left", "right"]),
|
|
147
169
|
"children": _propTypes.default.node,
|
|
148
170
|
"className": _propTypes.default.string,
|
|
149
171
|
"data-component": _propTypes.default.string,
|
|
@@ -155,7 +177,7 @@ Toast.propTypes = {
|
|
|
155
177
|
"open": _propTypes.default.bool,
|
|
156
178
|
"targetPortalId": _propTypes.default.string,
|
|
157
179
|
"timeout": _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]),
|
|
158
|
-
"variant": _propTypes.default.oneOf(["error", "info", "notice", "success", "warning"])
|
|
180
|
+
"variant": _propTypes.default.oneOf(["error", "info", "neutral", "notice", "notification", "success", "warning"])
|
|
159
181
|
};
|
|
160
182
|
Toast.displayName = "Toast";
|
|
161
183
|
var _default = Toast;
|
|
@@ -5,5 +5,5 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.TOAST_COLORS = void 0;
|
|
7
7
|
// eslint-disable-next-line import/prefer-default-export
|
|
8
|
-
const TOAST_COLORS = ["error", "info", "success", "warning"];
|
|
8
|
+
const TOAST_COLORS = ["error", "info", "success", "warning", "neutral", "notification"];
|
|
9
9
|
exports.TOAST_COLORS = TOAST_COLORS;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import TypeIcon from "../message/type-icon/type-icon.style";
|
|
3
3
|
declare const StyledPortal: import("styled-components").StyledComponent<({ children, className, id, onReposition }: import("../portal/portal").PortalProps) => import("react").JSX.Element, any, {
|
|
4
|
+
align?: "left" | "right" | "center" | undefined;
|
|
4
5
|
isCenter?: boolean | undefined;
|
|
5
6
|
isNotice?: boolean | undefined;
|
|
6
7
|
}, never>;
|
|
@@ -8,15 +9,18 @@ declare const ToastStyle: import("styled-components").StyledComponent<"div", any
|
|
|
8
9
|
variant?: import("../message/message.component").MessageVariant | undefined;
|
|
9
10
|
transparent?: boolean | undefined;
|
|
10
11
|
} & import("styled-system").MarginProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> & {
|
|
12
|
+
align?: "left" | "right" | "center" | undefined;
|
|
11
13
|
maxWidth?: string | undefined;
|
|
12
14
|
isCenter?: boolean | undefined;
|
|
13
15
|
isNotice?: boolean | undefined;
|
|
16
|
+
isNotification?: boolean | undefined;
|
|
14
17
|
}, never>;
|
|
15
18
|
declare const ToastContentStyle: import("styled-components").StyledComponent<"div", any, Pick<import("../message/message-content/message-content.component").MessageContentProps, "showCloseIcon"> & {
|
|
16
19
|
isNotice?: boolean | undefined;
|
|
17
20
|
isDismiss?: boolean | undefined;
|
|
18
21
|
}, never>;
|
|
19
22
|
declare const ToastWrapper: import("styled-components").StyledComponent<"div", any, {
|
|
23
|
+
align?: "left" | "right" | "center" | undefined;
|
|
20
24
|
isCenter?: boolean | undefined;
|
|
21
25
|
isNotice?: boolean | undefined;
|
|
22
26
|
}, never>;
|
|
@@ -25,7 +25,8 @@ const StyledPortal = (0, _styledComponents.default)(_portal.default)`
|
|
|
25
25
|
${({
|
|
26
26
|
theme,
|
|
27
27
|
isCenter,
|
|
28
|
-
isNotice
|
|
28
|
+
isNotice,
|
|
29
|
+
align
|
|
29
30
|
}) => (0, _styledComponents.css)`
|
|
30
31
|
position: fixed;
|
|
31
32
|
top: 0;
|
|
@@ -37,6 +38,22 @@ const StyledPortal = (0, _styledComponents.default)(_portal.default)`
|
|
|
37
38
|
transform: translateX(-50%);
|
|
38
39
|
`}
|
|
39
40
|
|
|
41
|
+
${align === "left" && (0, _styledComponents.css)`
|
|
42
|
+
left: 12%;
|
|
43
|
+
transform: translateX(-50%);
|
|
44
|
+
`}
|
|
45
|
+
|
|
46
|
+
${align === "center" && (0, _styledComponents.css)`
|
|
47
|
+
margin-left: 50%;
|
|
48
|
+
transform: translateX(-50%);
|
|
49
|
+
`}
|
|
50
|
+
|
|
51
|
+
${align === "right" && (0, _styledComponents.css)`
|
|
52
|
+
display: flex;
|
|
53
|
+
right: 0;
|
|
54
|
+
transform: translateX(-50%);
|
|
55
|
+
`}
|
|
56
|
+
|
|
40
57
|
${isNotice && (0, _styledComponents.css)`
|
|
41
58
|
bottom: 0;
|
|
42
59
|
top: auto;
|
|
@@ -53,7 +70,9 @@ const alternativeAnimationName = ".toast-alternative";
|
|
|
53
70
|
const ToastStyle = (0, _styledComponents.default)(_message.default)`
|
|
54
71
|
${({
|
|
55
72
|
maxWidth,
|
|
56
|
-
isCenter
|
|
73
|
+
isCenter,
|
|
74
|
+
align,
|
|
75
|
+
isNotification
|
|
57
76
|
}) => (0, _styledComponents.css)`
|
|
58
77
|
box-shadow: 0 10px 30px 0 rgba(0, 20, 29, 0.1),
|
|
59
78
|
0 30px 60px 0 rgba(0, 20, 29, 0.1);
|
|
@@ -61,7 +80,11 @@ const ToastStyle = (0, _styledComponents.default)(_message.default)`
|
|
|
61
80
|
margin-top: 30px;
|
|
62
81
|
max-width: ${!maxWidth ? "300px" : maxWidth};
|
|
63
82
|
position: relative;
|
|
64
|
-
margin-right: ${isCenter ? "auto" : "30px"};
|
|
83
|
+
margin-right: ${isCenter || align === "right" ? "auto" : "30px"};
|
|
84
|
+
|
|
85
|
+
${isNotification && (0, _styledComponents.css)`
|
|
86
|
+
border: 1px solid var(--colorsSemanticInfo500);
|
|
87
|
+
`}
|
|
65
88
|
`}
|
|
66
89
|
|
|
67
90
|
:focus {
|
|
@@ -157,6 +180,16 @@ const ToastContentStyle = (0, _styledComponents.default)(_messageContent.default
|
|
|
157
180
|
`;
|
|
158
181
|
exports.ToastContentStyle = ToastContentStyle;
|
|
159
182
|
const ToastWrapper = _styledComponents.default.div`
|
|
183
|
+
${({
|
|
184
|
+
align
|
|
185
|
+
}) => align && (0, _styledComponents.css)`
|
|
186
|
+
position: relative;
|
|
187
|
+
width: auto;
|
|
188
|
+
height: auto;
|
|
189
|
+
justify-content: ${align};
|
|
190
|
+
display: flex;
|
|
191
|
+
`}
|
|
192
|
+
|
|
160
193
|
${({
|
|
161
194
|
isCenter
|
|
162
195
|
}) => isCenter && (0, _styledComponents.css)`
|