carbon-react 111.13.0 → 111.13.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/esm/components/message/message.style.d.ts +1 -1
- package/esm/components/message/message.style.js +1 -1
- package/esm/components/pager/pager.style.js +5 -0
- package/esm/components/portal/index.d.ts +1 -0
- package/esm/components/portal/portal.d.ts +1 -1
- package/esm/components/toast/index.d.ts +2 -1
- package/esm/components/toast/toast.component.d.ts +30 -0
- package/esm/components/toast/toast.component.js +47 -63
- package/esm/components/toast/toast.config.d.ts +1 -0
- package/esm/components/toast/toast.style.d.ts +23 -0
- package/esm/components/toast/toast.style.js +12 -14
- package/lib/components/message/message.style.d.ts +1 -1
- package/lib/components/message/message.style.js +1 -1
- package/lib/components/pager/pager.style.js +6 -0
- package/lib/components/portal/index.d.ts +1 -0
- package/lib/components/portal/portal.d.ts +1 -1
- package/lib/components/toast/index.d.ts +2 -1
- package/lib/components/toast/toast.component.d.ts +30 -0
- package/lib/components/toast/toast.component.js +47 -64
- package/lib/components/toast/toast.config.d.ts +1 -0
- package/lib/components/toast/toast.style.d.ts +23 -0
- package/lib/components/toast/toast.style.js +12 -14
- package/package.json +1 -1
- package/esm/components/toast/toast.d.ts +0 -36
- package/lib/components/toast/toast.d.ts +0 -36
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { MarginProps } from "styled-system";
|
|
2
2
|
import { MessageVariant } from "./message.component";
|
|
3
3
|
declare type MessageStyleProps = {
|
|
4
|
-
variant
|
|
4
|
+
variant?: MessageVariant;
|
|
5
5
|
transparent?: boolean;
|
|
6
6
|
};
|
|
7
7
|
declare const MessageStyle: import("styled-components").StyledComponent<"div", any, MessageStyleProps & MarginProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>>, never>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import styled, { css } from "styled-components";
|
|
2
2
|
import StyledInput from "../../__internal__/input/input.style";
|
|
3
3
|
import StyledInputPresentation from "../../__internal__/input/input-presentation.style";
|
|
4
|
+
import StyledFormField from "../../__internal__/form-field/form-field.style";
|
|
4
5
|
import InputIconToggleStyle from "../../__internal__/input-icon-toggle/input-icon-toggle.style";
|
|
5
6
|
import StyledSelectText from "../select/__internal__/select-text/select-text.style";
|
|
6
7
|
import Link from "../link";
|
|
@@ -88,6 +89,10 @@ const StyledPagerNavInner = styled.div`
|
|
|
88
89
|
display: flex;
|
|
89
90
|
align-items: center;
|
|
90
91
|
padding: 0 12px;
|
|
92
|
+
|
|
93
|
+
&& ${StyledFormField} {
|
|
94
|
+
margin-bottom: 0;
|
|
95
|
+
}
|
|
91
96
|
`;
|
|
92
97
|
const StyledPagerLinkStyles = styled(Link)`
|
|
93
98
|
padding: 0 10px;
|
|
@@ -3,7 +3,7 @@ interface PortalContextProps {
|
|
|
3
3
|
renderInRoot?: boolean;
|
|
4
4
|
}
|
|
5
5
|
export declare const PortalContext: React.Context<PortalContextProps>;
|
|
6
|
-
interface PortalProps {
|
|
6
|
+
export interface PortalProps {
|
|
7
7
|
/** The content of the portal. */
|
|
8
8
|
children?: React.ReactNode;
|
|
9
9
|
/** Classname attached to portal container. */
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export { default } from "./toast";
|
|
1
|
+
export { default } from "./toast.component";
|
|
2
|
+
export type { ToastProps } from "./toast.component";
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
declare type ToastVariants = "error" | "info" | "success" | "warning" | "notice";
|
|
3
|
+
export interface ToastProps {
|
|
4
|
+
/** The rendered children of the component. */
|
|
5
|
+
children: React.ReactNode;
|
|
6
|
+
/** Customizes the appearance in the DLS theme */
|
|
7
|
+
variant?: ToastVariants;
|
|
8
|
+
/** Custom className */
|
|
9
|
+
className?: string;
|
|
10
|
+
/** Custom id */
|
|
11
|
+
id?: string;
|
|
12
|
+
/** Component name */
|
|
13
|
+
"data-component"?: string;
|
|
14
|
+
/** Determines if the Toast is open. */
|
|
15
|
+
open?: boolean;
|
|
16
|
+
/** Callback for when dismissed. */
|
|
17
|
+
onDismiss?: (ev?: KeyboardEvent | React.KeyboardEvent<HTMLButtonElement> | React.MouseEvent<HTMLButtonElement>) => void;
|
|
18
|
+
/** Time for Toast to remain on screen */
|
|
19
|
+
timeout?: string | number;
|
|
20
|
+
/** Centers the Toast on the screen */
|
|
21
|
+
isCenter?: boolean;
|
|
22
|
+
/** Target Portal ID where the Toast will render */
|
|
23
|
+
targetPortalId?: string;
|
|
24
|
+
/** Maximum toast width */
|
|
25
|
+
maxWidth?: string;
|
|
26
|
+
/** Disables auto focus functionality when the Toast has a close icon */
|
|
27
|
+
disableAutoFocus?: boolean;
|
|
28
|
+
}
|
|
29
|
+
export declare const Toast: React.ForwardRefExoticComponent<ToastProps & React.RefAttributes<HTMLDivElement>>;
|
|
30
|
+
export default Toast;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
function _extends() { _extends = Object.assign || 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); }
|
|
2
2
|
|
|
3
|
-
import React, { useCallback, useEffect,
|
|
4
|
-
import classNames from "classnames";
|
|
5
|
-
import { TransitionGroup, CSSTransition } from "react-transition-group";
|
|
3
|
+
import React, { useCallback, useEffect, useRef, useState } from "react";
|
|
6
4
|
import PropTypes from "prop-types";
|
|
5
|
+
import { TransitionGroup, CSSTransition } from "react-transition-group";
|
|
7
6
|
import Icon from "../icon";
|
|
8
7
|
import tagComponent from "../../__internal__/utils/helpers/tags/tags";
|
|
9
8
|
import { ToastStyle, TypeIcon, ToastContentStyle, ToastWrapper, StyledPortal } from "./toast.style";
|
|
@@ -21,22 +20,24 @@ const Toast = /*#__PURE__*/React.forwardRef(({
|
|
|
21
20
|
open = true,
|
|
22
21
|
targetPortalId,
|
|
23
22
|
timeout,
|
|
24
|
-
variant,
|
|
23
|
+
variant = "success",
|
|
25
24
|
disableAutoFocus,
|
|
26
25
|
...restProps
|
|
27
26
|
}, ref) => {
|
|
28
27
|
const isNotice = variant === "notice";
|
|
29
28
|
const locale = useLocale();
|
|
30
|
-
const toastRef = useRef();
|
|
31
|
-
const timer = useRef();
|
|
32
|
-
const toastContentNodeRef = useRef();
|
|
33
|
-
const closeIconRef = useRef();
|
|
34
|
-
const focusedElementBeforeOpening = useRef();
|
|
29
|
+
const toastRef = useRef(null);
|
|
30
|
+
const timer = useRef(null);
|
|
31
|
+
const toastContentNodeRef = useRef(null);
|
|
32
|
+
const closeIconRef = useRef(null);
|
|
33
|
+
const focusedElementBeforeOpening = useRef(null);
|
|
35
34
|
const [tabIndex, setTabIndex] = useState(0);
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
35
|
+
let refToPass = toastRef;
|
|
36
|
+
|
|
37
|
+
if (ref && typeof ref === "object" && "current" in ref) {
|
|
38
|
+
refToPass = ref;
|
|
39
|
+
}
|
|
40
|
+
|
|
40
41
|
const dismissToast = useCallback(ev => {
|
|
41
42
|
if (onDismiss && Events.isEscKey(ev)) {
|
|
42
43
|
ev.stopImmediatePropagation();
|
|
@@ -45,13 +46,14 @@ const Toast = /*#__PURE__*/React.forwardRef(({
|
|
|
45
46
|
}, [onDismiss]);
|
|
46
47
|
useModalManager(open, dismissToast, refToPass);
|
|
47
48
|
useEffect(() => {
|
|
48
|
-
|
|
49
|
+
/* istanbul ignore next */
|
|
50
|
+
if (timer.current) clearTimeout(timer.current);
|
|
49
51
|
|
|
50
52
|
if (!timeout || !open || !onDismiss) {
|
|
51
53
|
return;
|
|
52
54
|
}
|
|
53
55
|
|
|
54
|
-
timer.current = setTimeout(() => onDismiss(), timeout);
|
|
56
|
+
timer.current = setTimeout(() => onDismiss(), +timeout);
|
|
55
57
|
}, [onDismiss, open, timeout]);
|
|
56
58
|
useEffect(() => {
|
|
57
59
|
if (!disableAutoFocus) {
|
|
@@ -62,7 +64,7 @@ const Toast = /*#__PURE__*/React.forwardRef(({
|
|
|
62
64
|
(_toastContentNodeRef$ = toastContentNodeRef.current) === null || _toastContentNodeRef$ === void 0 ? void 0 : _toastContentNodeRef$.focus();
|
|
63
65
|
} else if (focusedElementBeforeOpening.current) {
|
|
64
66
|
focusedElementBeforeOpening.current.focus();
|
|
65
|
-
focusedElementBeforeOpening.current =
|
|
67
|
+
focusedElementBeforeOpening.current = null;
|
|
66
68
|
setTabIndex(0);
|
|
67
69
|
}
|
|
68
70
|
}
|
|
@@ -89,12 +91,12 @@ const Toast = /*#__PURE__*/React.forwardRef(({
|
|
|
89
91
|
|
|
90
92
|
function renderToastContent() {
|
|
91
93
|
if (!open) return null;
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
94
|
+
let toastVariant;
|
|
95
|
+
|
|
96
|
+
if (variant !== "notice") {
|
|
97
|
+
toastVariant = variant;
|
|
98
|
+
}
|
|
99
|
+
|
|
98
100
|
return /*#__PURE__*/React.createElement(CSSTransition, {
|
|
99
101
|
enter: true,
|
|
100
102
|
classNames: isNotice ? "toast-alternative" : "toast",
|
|
@@ -106,20 +108,23 @@ const Toast = /*#__PURE__*/React.forwardRef(({
|
|
|
106
108
|
nodeRef: toastContentNodeRef
|
|
107
109
|
}, /*#__PURE__*/React.createElement(ToastStyle, _extends({
|
|
108
110
|
isNotice: isNotice,
|
|
109
|
-
className:
|
|
110
|
-
}, tagComponent(restProps["data-component"] || "toast", restProps),
|
|
111
|
+
className: className
|
|
112
|
+
}, tagComponent(restProps["data-component"] || "toast", restProps), {
|
|
113
|
+
isCenter: isCenter,
|
|
114
|
+
variant: toastVariant,
|
|
115
|
+
id: id,
|
|
116
|
+
maxWidth: maxWidth,
|
|
111
117
|
ref: toastContentNodeRef
|
|
112
118
|
}, !disableAutoFocus && {
|
|
113
119
|
tabIndex,
|
|
114
120
|
onBlur: () => setTabIndex(undefined)
|
|
115
|
-
}),
|
|
116
|
-
variant:
|
|
121
|
+
}), variant !== "notice" && /*#__PURE__*/React.createElement(TypeIcon, {
|
|
122
|
+
variant: variant
|
|
117
123
|
}, /*#__PURE__*/React.createElement(Icon, {
|
|
118
|
-
type:
|
|
124
|
+
type: variant
|
|
119
125
|
})), /*#__PURE__*/React.createElement(ToastContentStyle, {
|
|
120
126
|
isNotice: isNotice,
|
|
121
|
-
|
|
122
|
-
isDismiss: onDismiss
|
|
127
|
+
isDismiss: !!onDismiss
|
|
123
128
|
}, children), renderCloseIcon()));
|
|
124
129
|
}
|
|
125
130
|
|
|
@@ -134,40 +139,19 @@ const Toast = /*#__PURE__*/React.forwardRef(({
|
|
|
134
139
|
}, /*#__PURE__*/React.createElement(TransitionGroup, null, renderToastContent())));
|
|
135
140
|
});
|
|
136
141
|
Toast.propTypes = {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
/** Custom className */
|
|
141
|
-
className: PropTypes.string,
|
|
142
|
-
|
|
143
|
-
/** Custom id */
|
|
144
|
-
id: PropTypes.string,
|
|
145
|
-
|
|
146
|
-
/** Component name */
|
|
142
|
+
"children": PropTypes.node,
|
|
143
|
+
"className": PropTypes.string,
|
|
147
144
|
"data-component": PropTypes.string,
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
open: PropTypes.bool,
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
/** Time for Toast to remain on screen */
|
|
159
|
-
timeout: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
160
|
-
|
|
161
|
-
/** Centers the Toast on the screen */
|
|
162
|
-
isCenter: PropTypes.bool,
|
|
163
|
-
|
|
164
|
-
/** Target Portal ID where the Toast will render */
|
|
165
|
-
targetPortalId: PropTypes.string,
|
|
166
|
-
|
|
167
|
-
/** Maximum toast width */
|
|
168
|
-
maxWidth: PropTypes.string,
|
|
169
|
-
|
|
170
|
-
/** Disables auto focus functionality when the Toast has a close icon */
|
|
171
|
-
disableAutoFocus: PropTypes.bool
|
|
145
|
+
"disableAutoFocus": PropTypes.bool,
|
|
146
|
+
"id": PropTypes.string,
|
|
147
|
+
"isCenter": PropTypes.bool,
|
|
148
|
+
"maxWidth": PropTypes.string,
|
|
149
|
+
"onDismiss": PropTypes.func,
|
|
150
|
+
"open": PropTypes.bool,
|
|
151
|
+
"targetPortalId": PropTypes.string,
|
|
152
|
+
"timeout": PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
153
|
+
"variant": PropTypes.oneOf(["error", "info", "notice", "success", "warning"])
|
|
172
154
|
};
|
|
155
|
+
export { Toast };
|
|
156
|
+
Toast.displayName = "Toast";
|
|
173
157
|
export default Toast;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const TOAST_COLORS: string[];
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import TypeIcon from "../message/type-icon/type-icon.style";
|
|
3
|
+
declare const StyledPortal: import("styled-components").StyledComponent<({ children, className, id, onReposition }: import("../portal/portal").PortalProps) => JSX.Element, any, {
|
|
4
|
+
isCenter?: boolean | undefined;
|
|
5
|
+
isNotice?: boolean | undefined;
|
|
6
|
+
}, never>;
|
|
7
|
+
declare const ToastStyle: import("styled-components").StyledComponent<"div", any, {
|
|
8
|
+
variant?: import("../message/message.component").MessageVariant | undefined;
|
|
9
|
+
transparent?: boolean | undefined;
|
|
10
|
+
} & import("styled-system").MarginProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> & {
|
|
11
|
+
maxWidth?: string | undefined;
|
|
12
|
+
isCenter?: boolean | undefined;
|
|
13
|
+
isNotice?: boolean | undefined;
|
|
14
|
+
}, never>;
|
|
15
|
+
declare const ToastContentStyle: import("styled-components").StyledComponent<"div", any, {
|
|
16
|
+
isNotice?: boolean | undefined;
|
|
17
|
+
isDismiss?: boolean | undefined;
|
|
18
|
+
}, never>;
|
|
19
|
+
declare const ToastWrapper: import("styled-components").StyledComponent<"div", any, {
|
|
20
|
+
isCenter?: boolean | undefined;
|
|
21
|
+
isNotice?: boolean | undefined;
|
|
22
|
+
}, never>;
|
|
23
|
+
export { ToastStyle, TypeIcon, ToastContentStyle, ToastWrapper, StyledPortal };
|
|
@@ -8,27 +8,25 @@ import baseTheme from "../../style/themes/base";
|
|
|
8
8
|
import StyledIcon from "../icon/icon.style";
|
|
9
9
|
const StyledPortal = styled(Portal)`
|
|
10
10
|
${({
|
|
11
|
-
theme
|
|
11
|
+
theme,
|
|
12
|
+
isCenter,
|
|
13
|
+
isNotice
|
|
12
14
|
}) => css`
|
|
13
15
|
position: fixed;
|
|
14
16
|
top: 0;
|
|
15
17
|
|
|
16
18
|
z-index: ${theme.zIndex.notification};
|
|
17
19
|
|
|
18
|
-
${
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
transform: translateX(-50%);
|
|
23
|
-
`}
|
|
20
|
+
${isCenter && css`
|
|
21
|
+
margin-left: 50%;
|
|
22
|
+
transform: translateX(-50%);
|
|
23
|
+
`}
|
|
24
24
|
|
|
25
|
-
${
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
width: 100%;
|
|
31
|
-
`}
|
|
25
|
+
${isNotice && css`
|
|
26
|
+
bottom: 0;
|
|
27
|
+
top: auto;
|
|
28
|
+
width: 100%;
|
|
29
|
+
`}
|
|
32
30
|
`}
|
|
33
31
|
`;
|
|
34
32
|
StyledPortal.defaultProps = {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { MarginProps } from "styled-system";
|
|
2
2
|
import { MessageVariant } from "./message.component";
|
|
3
3
|
declare type MessageStyleProps = {
|
|
4
|
-
variant
|
|
4
|
+
variant?: MessageVariant;
|
|
5
5
|
transparent?: boolean;
|
|
6
6
|
};
|
|
7
7
|
declare const MessageStyle: import("styled-components").StyledComponent<"div", any, MessageStyleProps & MarginProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>>, never>;
|
|
@@ -32,7 +32,7 @@ const MessageStyle = _styledComponents.default.div`
|
|
|
32
32
|
align-content: center;
|
|
33
33
|
border: 1px solid ${({
|
|
34
34
|
variant
|
|
35
|
-
}) => messageVariants[variant]};
|
|
35
|
+
}) => variant && messageVariants[variant]};
|
|
36
36
|
background-color: var(--colorsUtilityYang100);
|
|
37
37
|
min-height: 38px;
|
|
38
38
|
|
|
@@ -11,6 +11,8 @@ var _input = _interopRequireDefault(require("../../__internal__/input/input.styl
|
|
|
11
11
|
|
|
12
12
|
var _inputPresentation = _interopRequireDefault(require("../../__internal__/input/input-presentation.style"));
|
|
13
13
|
|
|
14
|
+
var _formField = _interopRequireDefault(require("../../__internal__/form-field/form-field.style"));
|
|
15
|
+
|
|
14
16
|
var _inputIconToggle = _interopRequireDefault(require("../../__internal__/input-icon-toggle/input-icon-toggle.style"));
|
|
15
17
|
|
|
16
18
|
var _selectText = _interopRequireDefault(require("../select/__internal__/select-text/select-text.style"));
|
|
@@ -112,6 +114,10 @@ const StyledPagerNavInner = _styledComponents.default.div`
|
|
|
112
114
|
display: flex;
|
|
113
115
|
align-items: center;
|
|
114
116
|
padding: 0 12px;
|
|
117
|
+
|
|
118
|
+
&& ${_formField.default} {
|
|
119
|
+
margin-bottom: 0;
|
|
120
|
+
}
|
|
115
121
|
`;
|
|
116
122
|
exports.StyledPagerNavInner = StyledPagerNavInner;
|
|
117
123
|
const StyledPagerLinkStyles = (0, _styledComponents.default)(_link.default)`
|
|
@@ -3,7 +3,7 @@ interface PortalContextProps {
|
|
|
3
3
|
renderInRoot?: boolean;
|
|
4
4
|
}
|
|
5
5
|
export declare const PortalContext: React.Context<PortalContextProps>;
|
|
6
|
-
interface PortalProps {
|
|
6
|
+
export interface PortalProps {
|
|
7
7
|
/** The content of the portal. */
|
|
8
8
|
children?: React.ReactNode;
|
|
9
9
|
/** Classname attached to portal container. */
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export { default } from "./toast";
|
|
1
|
+
export { default } from "./toast.component";
|
|
2
|
+
export type { ToastProps } from "./toast.component";
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
declare type ToastVariants = "error" | "info" | "success" | "warning" | "notice";
|
|
3
|
+
export interface ToastProps {
|
|
4
|
+
/** The rendered children of the component. */
|
|
5
|
+
children: React.ReactNode;
|
|
6
|
+
/** Customizes the appearance in the DLS theme */
|
|
7
|
+
variant?: ToastVariants;
|
|
8
|
+
/** Custom className */
|
|
9
|
+
className?: string;
|
|
10
|
+
/** Custom id */
|
|
11
|
+
id?: string;
|
|
12
|
+
/** Component name */
|
|
13
|
+
"data-component"?: string;
|
|
14
|
+
/** Determines if the Toast is open. */
|
|
15
|
+
open?: boolean;
|
|
16
|
+
/** Callback for when dismissed. */
|
|
17
|
+
onDismiss?: (ev?: KeyboardEvent | React.KeyboardEvent<HTMLButtonElement> | React.MouseEvent<HTMLButtonElement>) => void;
|
|
18
|
+
/** Time for Toast to remain on screen */
|
|
19
|
+
timeout?: string | number;
|
|
20
|
+
/** Centers the Toast on the screen */
|
|
21
|
+
isCenter?: boolean;
|
|
22
|
+
/** Target Portal ID where the Toast will render */
|
|
23
|
+
targetPortalId?: string;
|
|
24
|
+
/** Maximum toast width */
|
|
25
|
+
maxWidth?: string;
|
|
26
|
+
/** Disables auto focus functionality when the Toast has a close icon */
|
|
27
|
+
disableAutoFocus?: boolean;
|
|
28
|
+
}
|
|
29
|
+
export declare const Toast: React.ForwardRefExoticComponent<ToastProps & React.RefAttributes<HTMLDivElement>>;
|
|
30
|
+
export default Toast;
|
|
@@ -3,16 +3,14 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.default = void 0;
|
|
6
|
+
exports.default = exports.Toast = void 0;
|
|
7
7
|
|
|
8
8
|
var _react = _interopRequireWildcard(require("react"));
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
11
|
|
|
12
12
|
var _reactTransitionGroup = require("react-transition-group");
|
|
13
13
|
|
|
14
|
-
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
15
|
-
|
|
16
14
|
var _icon = _interopRequireDefault(require("../icon"));
|
|
17
15
|
|
|
18
16
|
var _tags = _interopRequireDefault(require("../../__internal__/utils/helpers/tags/tags"));
|
|
@@ -45,22 +43,24 @@ const Toast = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
45
43
|
open = true,
|
|
46
44
|
targetPortalId,
|
|
47
45
|
timeout,
|
|
48
|
-
variant,
|
|
46
|
+
variant = "success",
|
|
49
47
|
disableAutoFocus,
|
|
50
48
|
...restProps
|
|
51
49
|
}, ref) => {
|
|
52
50
|
const isNotice = variant === "notice";
|
|
53
51
|
const locale = (0, _useLocale.default)();
|
|
54
|
-
const toastRef = (0, _react.useRef)();
|
|
55
|
-
const timer = (0, _react.useRef)();
|
|
56
|
-
const toastContentNodeRef = (0, _react.useRef)();
|
|
57
|
-
const closeIconRef = (0, _react.useRef)();
|
|
58
|
-
const focusedElementBeforeOpening = (0, _react.useRef)();
|
|
52
|
+
const toastRef = (0, _react.useRef)(null);
|
|
53
|
+
const timer = (0, _react.useRef)(null);
|
|
54
|
+
const toastContentNodeRef = (0, _react.useRef)(null);
|
|
55
|
+
const closeIconRef = (0, _react.useRef)(null);
|
|
56
|
+
const focusedElementBeforeOpening = (0, _react.useRef)(null);
|
|
59
57
|
const [tabIndex, setTabIndex] = (0, _react.useState)(0);
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
58
|
+
let refToPass = toastRef;
|
|
59
|
+
|
|
60
|
+
if (ref && typeof ref === "object" && "current" in ref) {
|
|
61
|
+
refToPass = ref;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
64
|
const dismissToast = (0, _react.useCallback)(ev => {
|
|
65
65
|
if (onDismiss && _events.default.isEscKey(ev)) {
|
|
66
66
|
ev.stopImmediatePropagation();
|
|
@@ -69,13 +69,14 @@ const Toast = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
69
69
|
}, [onDismiss]);
|
|
70
70
|
(0, _useModalManager.default)(open, dismissToast, refToPass);
|
|
71
71
|
(0, _react.useEffect)(() => {
|
|
72
|
-
|
|
72
|
+
/* istanbul ignore next */
|
|
73
|
+
if (timer.current) clearTimeout(timer.current);
|
|
73
74
|
|
|
74
75
|
if (!timeout || !open || !onDismiss) {
|
|
75
76
|
return;
|
|
76
77
|
}
|
|
77
78
|
|
|
78
|
-
timer.current = setTimeout(() => onDismiss(), timeout);
|
|
79
|
+
timer.current = setTimeout(() => onDismiss(), +timeout);
|
|
79
80
|
}, [onDismiss, open, timeout]);
|
|
80
81
|
(0, _react.useEffect)(() => {
|
|
81
82
|
if (!disableAutoFocus) {
|
|
@@ -86,7 +87,7 @@ const Toast = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
86
87
|
(_toastContentNodeRef$ = toastContentNodeRef.current) === null || _toastContentNodeRef$ === void 0 ? void 0 : _toastContentNodeRef$.focus();
|
|
87
88
|
} else if (focusedElementBeforeOpening.current) {
|
|
88
89
|
focusedElementBeforeOpening.current.focus();
|
|
89
|
-
focusedElementBeforeOpening.current =
|
|
90
|
+
focusedElementBeforeOpening.current = null;
|
|
90
91
|
setTabIndex(0);
|
|
91
92
|
}
|
|
92
93
|
}
|
|
@@ -113,12 +114,12 @@ const Toast = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
113
114
|
|
|
114
115
|
function renderToastContent() {
|
|
115
116
|
if (!open) return null;
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
117
|
+
let toastVariant;
|
|
118
|
+
|
|
119
|
+
if (variant !== "notice") {
|
|
120
|
+
toastVariant = variant;
|
|
121
|
+
}
|
|
122
|
+
|
|
122
123
|
return /*#__PURE__*/_react.default.createElement(_reactTransitionGroup.CSSTransition, {
|
|
123
124
|
enter: true,
|
|
124
125
|
classNames: isNotice ? "toast-alternative" : "toast",
|
|
@@ -130,20 +131,23 @@ const Toast = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
130
131
|
nodeRef: toastContentNodeRef
|
|
131
132
|
}, /*#__PURE__*/_react.default.createElement(_toast.ToastStyle, _extends({
|
|
132
133
|
isNotice: isNotice,
|
|
133
|
-
className:
|
|
134
|
-
}, (0, _tags.default)(restProps["data-component"] || "toast", restProps),
|
|
134
|
+
className: className
|
|
135
|
+
}, (0, _tags.default)(restProps["data-component"] || "toast", restProps), {
|
|
136
|
+
isCenter: isCenter,
|
|
137
|
+
variant: toastVariant,
|
|
138
|
+
id: id,
|
|
139
|
+
maxWidth: maxWidth,
|
|
135
140
|
ref: toastContentNodeRef
|
|
136
141
|
}, !disableAutoFocus && {
|
|
137
142
|
tabIndex,
|
|
138
143
|
onBlur: () => setTabIndex(undefined)
|
|
139
|
-
}),
|
|
140
|
-
variant:
|
|
144
|
+
}), variant !== "notice" && /*#__PURE__*/_react.default.createElement(_toast.TypeIcon, {
|
|
145
|
+
variant: variant
|
|
141
146
|
}, /*#__PURE__*/_react.default.createElement(_icon.default, {
|
|
142
|
-
type:
|
|
147
|
+
type: variant
|
|
143
148
|
})), /*#__PURE__*/_react.default.createElement(_toast.ToastContentStyle, {
|
|
144
149
|
isNotice: isNotice,
|
|
145
|
-
|
|
146
|
-
isDismiss: onDismiss
|
|
150
|
+
isDismiss: !!onDismiss
|
|
147
151
|
}, children), renderCloseIcon()));
|
|
148
152
|
}
|
|
149
153
|
|
|
@@ -158,42 +162,21 @@ const Toast = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
158
162
|
}, /*#__PURE__*/_react.default.createElement(_reactTransitionGroup.TransitionGroup, null, renderToastContent())));
|
|
159
163
|
});
|
|
160
164
|
|
|
165
|
+
exports.Toast = Toast;
|
|
161
166
|
Toast.propTypes = {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
/** Custom className */
|
|
166
|
-
className: _propTypes.default.string,
|
|
167
|
-
|
|
168
|
-
/** Custom id */
|
|
169
|
-
id: _propTypes.default.string,
|
|
170
|
-
|
|
171
|
-
/** Component name */
|
|
167
|
+
"children": _propTypes.default.node,
|
|
168
|
+
"className": _propTypes.default.string,
|
|
172
169
|
"data-component": _propTypes.default.string,
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
open: _propTypes.default.bool,
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
/** Time for Toast to remain on screen */
|
|
184
|
-
timeout: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number]),
|
|
185
|
-
|
|
186
|
-
/** Centers the Toast on the screen */
|
|
187
|
-
isCenter: _propTypes.default.bool,
|
|
188
|
-
|
|
189
|
-
/** Target Portal ID where the Toast will render */
|
|
190
|
-
targetPortalId: _propTypes.default.string,
|
|
191
|
-
|
|
192
|
-
/** Maximum toast width */
|
|
193
|
-
maxWidth: _propTypes.default.string,
|
|
194
|
-
|
|
195
|
-
/** Disables auto focus functionality when the Toast has a close icon */
|
|
196
|
-
disableAutoFocus: _propTypes.default.bool
|
|
170
|
+
"disableAutoFocus": _propTypes.default.bool,
|
|
171
|
+
"id": _propTypes.default.string,
|
|
172
|
+
"isCenter": _propTypes.default.bool,
|
|
173
|
+
"maxWidth": _propTypes.default.string,
|
|
174
|
+
"onDismiss": _propTypes.default.func,
|
|
175
|
+
"open": _propTypes.default.bool,
|
|
176
|
+
"targetPortalId": _propTypes.default.string,
|
|
177
|
+
"timeout": _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]),
|
|
178
|
+
"variant": _propTypes.default.oneOf(["error", "info", "notice", "success", "warning"])
|
|
197
179
|
};
|
|
180
|
+
Toast.displayName = "Toast";
|
|
198
181
|
var _default = Toast;
|
|
199
182
|
exports.default = _default;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const TOAST_COLORS: string[];
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import TypeIcon from "../message/type-icon/type-icon.style";
|
|
3
|
+
declare const StyledPortal: import("styled-components").StyledComponent<({ children, className, id, onReposition }: import("../portal/portal").PortalProps) => JSX.Element, any, {
|
|
4
|
+
isCenter?: boolean | undefined;
|
|
5
|
+
isNotice?: boolean | undefined;
|
|
6
|
+
}, never>;
|
|
7
|
+
declare const ToastStyle: import("styled-components").StyledComponent<"div", any, {
|
|
8
|
+
variant?: import("../message/message.component").MessageVariant | undefined;
|
|
9
|
+
transparent?: boolean | undefined;
|
|
10
|
+
} & import("styled-system").MarginProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> & {
|
|
11
|
+
maxWidth?: string | undefined;
|
|
12
|
+
isCenter?: boolean | undefined;
|
|
13
|
+
isNotice?: boolean | undefined;
|
|
14
|
+
}, never>;
|
|
15
|
+
declare const ToastContentStyle: import("styled-components").StyledComponent<"div", any, {
|
|
16
|
+
isNotice?: boolean | undefined;
|
|
17
|
+
isDismiss?: boolean | undefined;
|
|
18
|
+
}, never>;
|
|
19
|
+
declare const ToastWrapper: import("styled-components").StyledComponent<"div", any, {
|
|
20
|
+
isCenter?: boolean | undefined;
|
|
21
|
+
isNotice?: boolean | undefined;
|
|
22
|
+
}, never>;
|
|
23
|
+
export { ToastStyle, TypeIcon, ToastContentStyle, ToastWrapper, StyledPortal };
|
|
@@ -35,27 +35,25 @@ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj;
|
|
|
35
35
|
|
|
36
36
|
const StyledPortal = (0, _styledComponents.default)(_portal.default)`
|
|
37
37
|
${({
|
|
38
|
-
theme
|
|
38
|
+
theme,
|
|
39
|
+
isCenter,
|
|
40
|
+
isNotice
|
|
39
41
|
}) => (0, _styledComponents.css)`
|
|
40
42
|
position: fixed;
|
|
41
43
|
top: 0;
|
|
42
44
|
|
|
43
45
|
z-index: ${theme.zIndex.notification};
|
|
44
46
|
|
|
45
|
-
${(
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
transform: translateX(-50%);
|
|
50
|
-
`}
|
|
47
|
+
${isCenter && (0, _styledComponents.css)`
|
|
48
|
+
margin-left: 50%;
|
|
49
|
+
transform: translateX(-50%);
|
|
50
|
+
`}
|
|
51
51
|
|
|
52
|
-
${(
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
width: 100%;
|
|
58
|
-
`}
|
|
52
|
+
${isNotice && (0, _styledComponents.css)`
|
|
53
|
+
bottom: 0;
|
|
54
|
+
top: auto;
|
|
55
|
+
width: 100%;
|
|
56
|
+
`}
|
|
59
57
|
`}
|
|
60
58
|
`;
|
|
61
59
|
exports.StyledPortal = StyledPortal;
|
package/package.json
CHANGED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
|
|
3
|
-
type ToastVariants = "error" | "info" | "success" | "warning" | "notice";
|
|
4
|
-
|
|
5
|
-
export interface ToastPropTypes {
|
|
6
|
-
/** The rendered children of the component. */
|
|
7
|
-
children: React.ReactNode;
|
|
8
|
-
/** Customizes the appearance in the DLS theme */
|
|
9
|
-
variant?: ToastVariants;
|
|
10
|
-
/** Custom className */
|
|
11
|
-
className?: string;
|
|
12
|
-
/** Custom id */
|
|
13
|
-
id?: string;
|
|
14
|
-
/** Component name */
|
|
15
|
-
"data-component"?: string;
|
|
16
|
-
/** Determines if the Toast is open. */
|
|
17
|
-
open?: boolean;
|
|
18
|
-
/** Callback for when dismissed. */
|
|
19
|
-
onDismiss?: () => void;
|
|
20
|
-
/** Time for Toast to remain on screen */
|
|
21
|
-
timeout?: string | number;
|
|
22
|
-
/** Centers the Toast on the screen */
|
|
23
|
-
isCenter?: boolean;
|
|
24
|
-
/** Target Portal ID where the Toast will render */
|
|
25
|
-
targetPortalId?: string;
|
|
26
|
-
/** Maximum toast width */
|
|
27
|
-
maxWidth?: string;
|
|
28
|
-
/** Disables auto focus functionality when the Toast has a close icon */
|
|
29
|
-
disableAutoFocus?: boolean;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
declare function Toast(
|
|
33
|
-
props: ToastPropTypes & React.RefAttributes<HTMLDivElement>
|
|
34
|
-
): JSX.Element;
|
|
35
|
-
|
|
36
|
-
export default Toast;
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
|
|
3
|
-
type ToastVariants = "error" | "info" | "success" | "warning" | "notice";
|
|
4
|
-
|
|
5
|
-
export interface ToastPropTypes {
|
|
6
|
-
/** The rendered children of the component. */
|
|
7
|
-
children: React.ReactNode;
|
|
8
|
-
/** Customizes the appearance in the DLS theme */
|
|
9
|
-
variant?: ToastVariants;
|
|
10
|
-
/** Custom className */
|
|
11
|
-
className?: string;
|
|
12
|
-
/** Custom id */
|
|
13
|
-
id?: string;
|
|
14
|
-
/** Component name */
|
|
15
|
-
"data-component"?: string;
|
|
16
|
-
/** Determines if the Toast is open. */
|
|
17
|
-
open?: boolean;
|
|
18
|
-
/** Callback for when dismissed. */
|
|
19
|
-
onDismiss?: () => void;
|
|
20
|
-
/** Time for Toast to remain on screen */
|
|
21
|
-
timeout?: string | number;
|
|
22
|
-
/** Centers the Toast on the screen */
|
|
23
|
-
isCenter?: boolean;
|
|
24
|
-
/** Target Portal ID where the Toast will render */
|
|
25
|
-
targetPortalId?: string;
|
|
26
|
-
/** Maximum toast width */
|
|
27
|
-
maxWidth?: string;
|
|
28
|
-
/** Disables auto focus functionality when the Toast has a close icon */
|
|
29
|
-
disableAutoFocus?: boolean;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
declare function Toast(
|
|
33
|
-
props: ToastPropTypes & React.RefAttributes<HTMLDivElement>
|
|
34
|
-
): JSX.Element;
|
|
35
|
-
|
|
36
|
-
export default Toast;
|