@zendeskgarden/react-notifications 9.0.0-next.2 → 9.0.0-next.21
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/README.md +6 -4
- package/dist/esm/elements/Close.js +40 -0
- package/dist/esm/elements/Notification.js +55 -0
- package/dist/esm/elements/Paragraph.js +28 -0
- package/dist/esm/elements/Title.js +35 -0
- package/dist/esm/elements/alert/Alert.js +56 -0
- package/dist/esm/elements/alert/Close.js +40 -0
- package/dist/esm/elements/alert/Paragraph.js +28 -0
- package/dist/esm/elements/alert/Title.js +35 -0
- package/dist/esm/elements/global-alert/GlobalAlert.js +78 -0
- package/dist/esm/elements/global-alert/GlobalAlertButton.js +47 -0
- package/dist/esm/elements/global-alert/GlobalAlertClose.js +43 -0
- package/dist/esm/elements/global-alert/GlobalAlertContent.js +30 -0
- package/dist/esm/elements/global-alert/GlobalAlertTitle.js +44 -0
- package/dist/esm/elements/toaster/Toast.js +62 -0
- package/dist/esm/elements/toaster/ToastContext.js +11 -0
- package/dist/esm/elements/toaster/ToastProvider.js +51 -0
- package/dist/esm/elements/toaster/ToastSlot.js +82 -0
- package/dist/esm/elements/toaster/reducer.js +66 -0
- package/dist/esm/elements/toaster/styled.js +71 -0
- package/dist/esm/elements/toaster/useToast.js +70 -0
- package/dist/esm/elements/well/Well.js +47 -0
- package/dist/esm/index.js +15 -0
- package/dist/esm/node_modules/@zendeskgarden/svg-icons/src/16/alert-error-stroke.svg.js +37 -0
- package/dist/esm/node_modules/@zendeskgarden/svg-icons/src/16/alert-warning-stroke.svg.js +32 -0
- package/dist/esm/node_modules/@zendeskgarden/svg-icons/src/16/check-circle-stroke.svg.js +33 -0
- package/dist/esm/node_modules/@zendeskgarden/svg-icons/src/16/info-stroke.svg.js +37 -0
- package/dist/esm/node_modules/@zendeskgarden/svg-icons/src/16/x-stroke.svg.js +26 -0
- package/dist/esm/styled/StyledAlert.js +51 -0
- package/dist/esm/styled/StyledBase.js +92 -0
- package/dist/esm/styled/StyledIcon.js +61 -0
- package/dist/esm/styled/StyledNotification.js +56 -0
- package/dist/esm/styled/StyledWell.js +47 -0
- package/dist/esm/styled/content/StyledClose.js +70 -0
- package/dist/esm/styled/content/StyledParagraph.js +22 -0
- package/dist/esm/styled/content/StyledTitle.js +25 -0
- package/dist/esm/styled/global-alert/StyledGlobalAlert.js +160 -0
- package/dist/esm/styled/global-alert/StyledGlobalAlertButton.js +118 -0
- package/dist/esm/styled/global-alert/StyledGlobalAlertClose.js +103 -0
- package/dist/esm/styled/global-alert/StyledGlobalAlertContent.js +22 -0
- package/dist/esm/styled/global-alert/StyledGlobalAlertIcon.js +65 -0
- package/dist/esm/styled/global-alert/StyledGlobalAlertTitle.js +49 -0
- package/dist/esm/types/index.js +9 -0
- package/dist/esm/utils/icons.js +25 -0
- package/dist/esm/utils/useGlobalAlertContext.js +14 -0
- package/dist/esm/utils/useNotificationsContext.js +14 -0
- package/dist/index.cjs.js +837 -435
- package/dist/typings/elements/Close.d.ts +13 -0
- package/dist/typings/elements/Notification.d.ts +9 -1
- package/dist/typings/elements/Paragraph.d.ts +13 -0
- package/dist/typings/elements/{Well.d.ts → Title.d.ts} +4 -2
- package/dist/typings/elements/alert/Alert.d.ts +20 -0
- package/dist/typings/elements/well/Paragraph.d.ts +11 -0
- package/dist/typings/elements/{Alert.d.ts → well/Title.d.ts} +2 -2
- package/dist/typings/elements/well/Well.d.ts +18 -0
- package/dist/typings/index.d.ts +7 -11
- package/dist/typings/styled/StyledAlert.d.ts +8 -3
- package/dist/typings/styled/StyledBase.d.ts +8 -6
- package/dist/typings/styled/StyledIcon.d.ts +11 -2
- package/dist/typings/styled/StyledNotification.d.ts +11 -3
- package/dist/typings/styled/StyledWell.d.ts +7 -2
- package/dist/typings/styled/content/StyledClose.d.ts +5 -3
- package/dist/typings/styled/content/StyledTitle.d.ts +1 -1
- package/dist/typings/styled/global-alert/StyledGlobalAlert.d.ts +1 -1
- package/dist/typings/styled/global-alert/StyledGlobalAlertButton.d.ts +4 -11
- package/dist/typings/styled/global-alert/StyledGlobalAlertClose.d.ts +2 -3
- package/dist/typings/styled/global-alert/StyledGlobalAlertIcon.d.ts +2 -2
- package/dist/typings/styled/global-alert/StyledGlobalAlertTitle.d.ts +2 -2
- package/dist/typings/utils/icons.d.ts +1 -1
- package/dist/typings/{elements/global-alert/utility.d.ts → utils/useGlobalAlertContext.d.ts} +1 -1
- package/dist/typings/utils/useNotificationsContext.d.ts +2 -3
- package/package.json +9 -9
- package/dist/index.esm.js +0 -1124
- /package/dist/typings/elements/{content → alert}/Close.d.ts +0 -0
- /package/dist/typings/elements/{content → alert}/Paragraph.d.ts +0 -0
- /package/dist/typings/elements/{content → alert}/Title.d.ts +0 -0
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Zendesk, Inc.
|
|
3
|
+
*
|
|
4
|
+
* Use of this source code is governed under the Apache License, Version 2.0
|
|
5
|
+
* found at http://www.apache.org/licenses/LICENSE-2.0.
|
|
6
|
+
*/
|
|
7
|
+
import { useState, useRef, useEffect, useCallback } from 'react';
|
|
8
|
+
import { useToast } from './useToast.js';
|
|
9
|
+
|
|
10
|
+
const Toast = _ref => {
|
|
11
|
+
let {
|
|
12
|
+
toast,
|
|
13
|
+
pauseTimers
|
|
14
|
+
} = _ref;
|
|
15
|
+
const {
|
|
16
|
+
removeToast
|
|
17
|
+
} = useToast();
|
|
18
|
+
const {
|
|
19
|
+
id
|
|
20
|
+
} = toast;
|
|
21
|
+
const {
|
|
22
|
+
autoDismiss
|
|
23
|
+
} = toast.options;
|
|
24
|
+
const [remainingTime, setRemainingTime] = useState(NaN);
|
|
25
|
+
const startTimeRef = useRef(Date.now());
|
|
26
|
+
const previousRemainingTimeRef = useRef(remainingTime);
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
if (typeof autoDismiss === 'number') {
|
|
29
|
+
setRemainingTime(autoDismiss);
|
|
30
|
+
} else {
|
|
31
|
+
setRemainingTime(NaN);
|
|
32
|
+
}
|
|
33
|
+
}, [autoDismiss]);
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
if (pauseTimers && !isNaN(remainingTime)) {
|
|
36
|
+
previousRemainingTimeRef.current = remainingTime - (Date.now() - startTimeRef.current);
|
|
37
|
+
setRemainingTime(NaN);
|
|
38
|
+
} else if (!pauseTimers && isNaN(remainingTime) && !isNaN(previousRemainingTimeRef.current)) {
|
|
39
|
+
setRemainingTime(previousRemainingTimeRef.current);
|
|
40
|
+
}
|
|
41
|
+
}, [pauseTimers, remainingTime]);
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
let timeout;
|
|
44
|
+
if (!isNaN(remainingTime)) {
|
|
45
|
+
startTimeRef.current = Date.now();
|
|
46
|
+
timeout = setTimeout(() => {
|
|
47
|
+
removeToast(id);
|
|
48
|
+
}, remainingTime);
|
|
49
|
+
}
|
|
50
|
+
return () => {
|
|
51
|
+
clearTimeout(timeout);
|
|
52
|
+
};
|
|
53
|
+
}, [id, pauseTimers, remainingTime, removeToast]);
|
|
54
|
+
const close = useCallback(() => {
|
|
55
|
+
removeToast(toast.id);
|
|
56
|
+
}, [removeToast, toast.id]);
|
|
57
|
+
return toast.content({
|
|
58
|
+
close
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export { Toast };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Zendesk, Inc.
|
|
3
|
+
*
|
|
4
|
+
* Use of this source code is governed under the Apache License, Version 2.0
|
|
5
|
+
* found at http://www.apache.org/licenses/LICENSE-2.0.
|
|
6
|
+
*/
|
|
7
|
+
import { createContext } from 'react';
|
|
8
|
+
|
|
9
|
+
const ToastContext = createContext(undefined);
|
|
10
|
+
|
|
11
|
+
export { ToastContext };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Zendesk, Inc.
|
|
3
|
+
*
|
|
4
|
+
* Use of this source code is governed under the Apache License, Version 2.0
|
|
5
|
+
* found at http://www.apache.org/licenses/LICENSE-2.0.
|
|
6
|
+
*/
|
|
7
|
+
import React__default, { useReducer, useMemo, useCallback } from 'react';
|
|
8
|
+
import PropTypes from 'prop-types';
|
|
9
|
+
import { toasterReducer, getInitialState } from './reducer.js';
|
|
10
|
+
import { ToastContext } from './ToastContext.js';
|
|
11
|
+
import { ToastSlot } from './ToastSlot.js';
|
|
12
|
+
|
|
13
|
+
const ToastProvider = _ref => {
|
|
14
|
+
let {
|
|
15
|
+
limit,
|
|
16
|
+
zIndex,
|
|
17
|
+
placementProps = {},
|
|
18
|
+
children
|
|
19
|
+
} = _ref;
|
|
20
|
+
const [state, dispatch] = useReducer(toasterReducer, getInitialState());
|
|
21
|
+
const contextValue = useMemo(() => ({
|
|
22
|
+
state,
|
|
23
|
+
dispatch
|
|
24
|
+
}), [state, dispatch]);
|
|
25
|
+
const toastsByPlacement = useCallback(placement => {
|
|
26
|
+
let matchingToasts = state.toasts.filter(toast => toast.options.placement === placement);
|
|
27
|
+
if (placement === 'bottom' || placement === 'bottom-start' || placement === 'bottom-end') {
|
|
28
|
+
matchingToasts = matchingToasts.reverse();
|
|
29
|
+
}
|
|
30
|
+
return React__default.createElement(ToastSlot, Object.assign({
|
|
31
|
+
placement: placement,
|
|
32
|
+
toasts: matchingToasts,
|
|
33
|
+
zIndex: zIndex,
|
|
34
|
+
limit: limit
|
|
35
|
+
}, placementProps[placement]));
|
|
36
|
+
}, [limit, state.toasts, zIndex, placementProps]);
|
|
37
|
+
return React__default.createElement(ToastContext.Provider, {
|
|
38
|
+
value: contextValue
|
|
39
|
+
}, toastsByPlacement('top-start'), toastsByPlacement('top'), toastsByPlacement('top-end'), children, toastsByPlacement('bottom-start'), toastsByPlacement('bottom'), toastsByPlacement('bottom-end'));
|
|
40
|
+
};
|
|
41
|
+
ToastProvider.displayName = 'ToastProvider';
|
|
42
|
+
ToastProvider.defaultProps = {
|
|
43
|
+
limit: 4
|
|
44
|
+
};
|
|
45
|
+
ToastProvider.propTypes = {
|
|
46
|
+
limit: PropTypes.number,
|
|
47
|
+
zIndex: PropTypes.number,
|
|
48
|
+
placementProps: PropTypes.object
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export { ToastProvider };
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Zendesk, Inc.
|
|
3
|
+
*
|
|
4
|
+
* Use of this source code is governed under the Apache License, Version 2.0
|
|
5
|
+
* found at http://www.apache.org/licenses/LICENSE-2.0.
|
|
6
|
+
*/
|
|
7
|
+
import React__default, { useState, useContext, useCallback, useEffect } from 'react';
|
|
8
|
+
import { ThemeContext } from 'styled-components';
|
|
9
|
+
import { TransitionGroup, CSSTransition } from 'react-transition-group';
|
|
10
|
+
import { useDocument } from '@zendeskgarden/react-theming';
|
|
11
|
+
import { Toast } from './Toast.js';
|
|
12
|
+
import { StyledTransitionContainer, TRANSITION_CLASS, StyledFadeInTransition } from './styled.js';
|
|
13
|
+
|
|
14
|
+
const ToastSlot = _ref => {
|
|
15
|
+
let {
|
|
16
|
+
toasts,
|
|
17
|
+
placement,
|
|
18
|
+
zIndex,
|
|
19
|
+
limit,
|
|
20
|
+
...props
|
|
21
|
+
} = _ref;
|
|
22
|
+
const [pauseTimers, setPauseTimers] = useState(false);
|
|
23
|
+
const theme = useContext(ThemeContext);
|
|
24
|
+
const environment = useDocument(theme);
|
|
25
|
+
const handleVisibilityChange = useCallback(e => {
|
|
26
|
+
if (e.target.visibilityState === 'visible') {
|
|
27
|
+
setPauseTimers(false);
|
|
28
|
+
} else {
|
|
29
|
+
setPauseTimers(true);
|
|
30
|
+
}
|
|
31
|
+
}, []);
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
if (environment) {
|
|
34
|
+
environment.addEventListener('visibilitychange', handleVisibilityChange);
|
|
35
|
+
}
|
|
36
|
+
return () => {
|
|
37
|
+
if (environment) {
|
|
38
|
+
environment.removeEventListener('visibilitychange', handleVisibilityChange);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
}, [environment, handleVisibilityChange]);
|
|
42
|
+
const handleMouseEnter = useCallback(() => {
|
|
43
|
+
setPauseTimers(true);
|
|
44
|
+
}, []);
|
|
45
|
+
const handleMouseLeave = useCallback(() => {
|
|
46
|
+
setPauseTimers(false);
|
|
47
|
+
}, []);
|
|
48
|
+
const isHidden = useCallback(index => {
|
|
49
|
+
if (placement === 'bottom' || placement === 'bottom-start' || placement === 'bottom-end') {
|
|
50
|
+
return index < toasts.length - limit;
|
|
51
|
+
}
|
|
52
|
+
return index >= limit;
|
|
53
|
+
}, [limit, placement, toasts.length]);
|
|
54
|
+
return React__default.createElement(StyledTransitionContainer, Object.assign({
|
|
55
|
+
key: placement,
|
|
56
|
+
toastPlacement: placement,
|
|
57
|
+
toastZIndex: zIndex,
|
|
58
|
+
onMouseEnter: handleMouseEnter,
|
|
59
|
+
onMouseLeave: handleMouseLeave
|
|
60
|
+
}, props), React__default.createElement(TransitionGroup, null, toasts.map((toast, index) => {
|
|
61
|
+
const transitionRef = React__default.createRef();
|
|
62
|
+
return React__default.createElement(CSSTransition, {
|
|
63
|
+
key: toast.id,
|
|
64
|
+
timeout: {
|
|
65
|
+
enter: 400,
|
|
66
|
+
exit: 550
|
|
67
|
+
},
|
|
68
|
+
unmountOnExit: true,
|
|
69
|
+
classNames: TRANSITION_CLASS,
|
|
70
|
+
nodeRef: transitionRef
|
|
71
|
+
}, React__default.createElement(StyledFadeInTransition, {
|
|
72
|
+
ref: transitionRef,
|
|
73
|
+
placement: placement,
|
|
74
|
+
isHidden: isHidden(index)
|
|
75
|
+
}, React__default.createElement(Toast, {
|
|
76
|
+
toast: toast,
|
|
77
|
+
pauseTimers: pauseTimers || isHidden(index)
|
|
78
|
+
})));
|
|
79
|
+
})));
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
export { ToastSlot };
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Zendesk, Inc.
|
|
3
|
+
*
|
|
4
|
+
* Use of this source code is governed under the Apache License, Version 2.0
|
|
5
|
+
* found at http://www.apache.org/licenses/LICENSE-2.0.
|
|
6
|
+
*/
|
|
7
|
+
const getInitialState = () => {
|
|
8
|
+
return {
|
|
9
|
+
toasts: []
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
const toasterReducer = (state, action) => {
|
|
13
|
+
switch (action.type) {
|
|
14
|
+
case 'ADD_TOAST':
|
|
15
|
+
{
|
|
16
|
+
return {
|
|
17
|
+
...state,
|
|
18
|
+
toasts: [...state.toasts, action.payload]
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
case 'REMOVE_TOAST':
|
|
22
|
+
{
|
|
23
|
+
const filteredToasts = state.toasts.filter(toast => toast.id !== action.payload);
|
|
24
|
+
return {
|
|
25
|
+
...state,
|
|
26
|
+
toasts: filteredToasts
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
case 'UPDATE_TOAST':
|
|
30
|
+
{
|
|
31
|
+
const updatedToasts = state.toasts.map(toast => {
|
|
32
|
+
if (toast.id !== action.payload.id) {
|
|
33
|
+
return toast;
|
|
34
|
+
}
|
|
35
|
+
const updatedToast = toast;
|
|
36
|
+
const {
|
|
37
|
+
content,
|
|
38
|
+
...newOptions
|
|
39
|
+
} = action.payload.options;
|
|
40
|
+
if (content) {
|
|
41
|
+
updatedToast.content = content;
|
|
42
|
+
}
|
|
43
|
+
updatedToast.options = {
|
|
44
|
+
...updatedToast.options,
|
|
45
|
+
...newOptions
|
|
46
|
+
};
|
|
47
|
+
return updatedToast;
|
|
48
|
+
});
|
|
49
|
+
return {
|
|
50
|
+
...state,
|
|
51
|
+
toasts: updatedToasts
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
case 'REMOVE_ALL_TOASTS':
|
|
55
|
+
{
|
|
56
|
+
return {
|
|
57
|
+
...state,
|
|
58
|
+
toasts: []
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
default:
|
|
62
|
+
throw new Error('Invalid toaster reducer action');
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export { getInitialState, toasterReducer };
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Zendesk, Inc.
|
|
3
|
+
*
|
|
4
|
+
* Use of this source code is governed under the Apache License, Version 2.0
|
|
5
|
+
* found at http://www.apache.org/licenses/LICENSE-2.0.
|
|
6
|
+
*/
|
|
7
|
+
import styled, { css } from 'styled-components';
|
|
8
|
+
import { hideVisually } from 'polished';
|
|
9
|
+
import { DEFAULT_THEME } from '@zendeskgarden/react-theming';
|
|
10
|
+
|
|
11
|
+
const TRANSITION_CLASS = 'garden-toast-transition';
|
|
12
|
+
const DEFAULT_DURATION = '400ms';
|
|
13
|
+
const StyledFadeInTransition = styled.div.withConfig({
|
|
14
|
+
displayName: "styled__StyledFadeInTransition",
|
|
15
|
+
componentId: "sc-nq0usb-0"
|
|
16
|
+
})(["transition:opacity ", " ease-in 300ms;opacity:", ";margin-bottom:", "px;", " &.", "-enter{transform:translateY( ", " );opacity:0;max-height:0;}&.", "-enter-active{transform:translateY(0);transition:opacity ", " ease-in,transform ", " cubic-bezier(0.15,0.85,0.35,1.2),max-height ", ";opacity:1;max-height:500px;}&.", "-exit{opacity:1;max-height:500px;}&.", "-exit-active{transition:opacity 550ms ease-out,max-height ", " linear 150ms;opacity:0;max-height:0;}"], DEFAULT_DURATION, p => p.isHidden ? '0 !important' : 1, p => p.theme.space.base * 2, p => p.isHidden && hideVisually(), TRANSITION_CLASS, props => {
|
|
17
|
+
if (props.placement === 'bottom-start' || props.placement === 'bottom' || props.placement === 'bottom-end') {
|
|
18
|
+
return '100px';
|
|
19
|
+
}
|
|
20
|
+
return '-100px';
|
|
21
|
+
}, TRANSITION_CLASS, DEFAULT_DURATION, DEFAULT_DURATION, DEFAULT_DURATION, TRANSITION_CLASS, TRANSITION_CLASS, DEFAULT_DURATION);
|
|
22
|
+
StyledFadeInTransition.defaultProps = {
|
|
23
|
+
theme: DEFAULT_THEME
|
|
24
|
+
};
|
|
25
|
+
const placementStyles = props => {
|
|
26
|
+
const verticalDistance = `${props.theme.space.base * 16}px`;
|
|
27
|
+
const horizontalDistance = `${props.theme.space.base * 3}px`;
|
|
28
|
+
const topLeftStyles = css(["top:", ";left:", ";"], verticalDistance, horizontalDistance);
|
|
29
|
+
const topStyles = css(["top:", ";left:50%;transform:translate(-50%,0);"], verticalDistance);
|
|
30
|
+
const topRightStyles = css(["top:", ";right:", ";"], verticalDistance, horizontalDistance);
|
|
31
|
+
const bottomLeftStyles = css(["bottom:", ";left:", ";"], verticalDistance, horizontalDistance);
|
|
32
|
+
const bottomStyles = css(["bottom:", ";left:50%;transform:translate(-50%,0);"], verticalDistance);
|
|
33
|
+
const bottomRightStyles = css(["right:", ";bottom:", ";"], horizontalDistance, verticalDistance);
|
|
34
|
+
switch (props.toastPlacement) {
|
|
35
|
+
case 'top-start':
|
|
36
|
+
if (props.theme.rtl) {
|
|
37
|
+
return topRightStyles;
|
|
38
|
+
}
|
|
39
|
+
return topLeftStyles;
|
|
40
|
+
case 'top':
|
|
41
|
+
return topStyles;
|
|
42
|
+
case 'top-end':
|
|
43
|
+
if (props.theme.rtl) {
|
|
44
|
+
return topLeftStyles;
|
|
45
|
+
}
|
|
46
|
+
return topRightStyles;
|
|
47
|
+
case 'bottom-start':
|
|
48
|
+
if (props.theme.rtl) {
|
|
49
|
+
return bottomRightStyles;
|
|
50
|
+
}
|
|
51
|
+
return bottomLeftStyles;
|
|
52
|
+
case 'bottom':
|
|
53
|
+
return bottomStyles;
|
|
54
|
+
case 'bottom-end':
|
|
55
|
+
if (props.theme.rtl) {
|
|
56
|
+
return bottomLeftStyles;
|
|
57
|
+
}
|
|
58
|
+
return bottomRightStyles;
|
|
59
|
+
default:
|
|
60
|
+
return '';
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
const StyledTransitionContainer = styled.div.withConfig({
|
|
64
|
+
displayName: "styled__StyledTransitionContainer",
|
|
65
|
+
componentId: "sc-nq0usb-1"
|
|
66
|
+
})(["position:fixed;z-index:", ";", ";"], props => props.toastZIndex, placementStyles);
|
|
67
|
+
StyledTransitionContainer.defaultProps = {
|
|
68
|
+
theme: DEFAULT_THEME
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export { StyledFadeInTransition, StyledTransitionContainer, TRANSITION_CLASS };
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Zendesk, Inc.
|
|
3
|
+
*
|
|
4
|
+
* Use of this source code is governed under the Apache License, Version 2.0
|
|
5
|
+
* found at http://www.apache.org/licenses/LICENSE-2.0.
|
|
6
|
+
*/
|
|
7
|
+
import { useContext, useCallback } from 'react';
|
|
8
|
+
import { uid } from 'react-uid';
|
|
9
|
+
import { ToastContext } from './ToastContext.js';
|
|
10
|
+
|
|
11
|
+
const DEFAULT_TOAST_OPTIONS = {
|
|
12
|
+
autoDismiss: 5000,
|
|
13
|
+
placement: 'top-end'
|
|
14
|
+
};
|
|
15
|
+
const useToast = () => {
|
|
16
|
+
const context = useContext(ToastContext);
|
|
17
|
+
if (context === undefined) {
|
|
18
|
+
throw new Error('useToast() must be used within a "ToastProvider"');
|
|
19
|
+
}
|
|
20
|
+
const {
|
|
21
|
+
dispatch,
|
|
22
|
+
state
|
|
23
|
+
} = context;
|
|
24
|
+
const addToast = useCallback(function (content) {
|
|
25
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
26
|
+
const mergedOptions = {
|
|
27
|
+
...DEFAULT_TOAST_OPTIONS,
|
|
28
|
+
...options
|
|
29
|
+
};
|
|
30
|
+
const newToast = {
|
|
31
|
+
id: mergedOptions.id || uid(content),
|
|
32
|
+
content,
|
|
33
|
+
options: mergedOptions
|
|
34
|
+
};
|
|
35
|
+
dispatch({
|
|
36
|
+
type: 'ADD_TOAST',
|
|
37
|
+
payload: newToast
|
|
38
|
+
});
|
|
39
|
+
return newToast.id;
|
|
40
|
+
}, [dispatch]);
|
|
41
|
+
const removeToast = useCallback(id => {
|
|
42
|
+
dispatch({
|
|
43
|
+
type: 'REMOVE_TOAST',
|
|
44
|
+
payload: id
|
|
45
|
+
});
|
|
46
|
+
}, [dispatch]);
|
|
47
|
+
const updateToast = useCallback((id, options) => {
|
|
48
|
+
dispatch({
|
|
49
|
+
type: 'UPDATE_TOAST',
|
|
50
|
+
payload: {
|
|
51
|
+
id,
|
|
52
|
+
options
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}, [dispatch]);
|
|
56
|
+
const removeAllToasts = useCallback(() => {
|
|
57
|
+
dispatch({
|
|
58
|
+
type: 'REMOVE_ALL_TOASTS'
|
|
59
|
+
});
|
|
60
|
+
}, [dispatch]);
|
|
61
|
+
return {
|
|
62
|
+
addToast,
|
|
63
|
+
removeToast,
|
|
64
|
+
updateToast,
|
|
65
|
+
removeAllToasts,
|
|
66
|
+
toasts: state.toasts
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export { useToast };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Zendesk, Inc.
|
|
3
|
+
*
|
|
4
|
+
* Use of this source code is governed under the Apache License, Version 2.0
|
|
5
|
+
* found at http://www.apache.org/licenses/LICENSE-2.0.
|
|
6
|
+
*/
|
|
7
|
+
import React__default from 'react';
|
|
8
|
+
import PropTypes from 'prop-types';
|
|
9
|
+
import '../../styled/content/StyledClose.js';
|
|
10
|
+
import '../../styled/content/StyledParagraph.js';
|
|
11
|
+
import '../../styled/content/StyledTitle.js';
|
|
12
|
+
import '../../styled/StyledAlert.js';
|
|
13
|
+
import '../../styled/StyledNotification.js';
|
|
14
|
+
import { StyledWell } from '../../styled/StyledWell.js';
|
|
15
|
+
import '../../styled/StyledIcon.js';
|
|
16
|
+
import '../../styled/StyledBase.js';
|
|
17
|
+
import '../../styled/global-alert/StyledGlobalAlert.js';
|
|
18
|
+
import '../../styled/global-alert/StyledGlobalAlertButton.js';
|
|
19
|
+
import '../../styled/global-alert/StyledGlobalAlertClose.js';
|
|
20
|
+
import '../../styled/global-alert/StyledGlobalAlertContent.js';
|
|
21
|
+
import '../../styled/global-alert/StyledGlobalAlertIcon.js';
|
|
22
|
+
import '../../styled/global-alert/StyledGlobalAlertTitle.js';
|
|
23
|
+
import { Title } from '../Title.js';
|
|
24
|
+
import { Paragraph } from '../Paragraph.js';
|
|
25
|
+
|
|
26
|
+
const WellComponent = React__default.forwardRef((_ref, ref) => {
|
|
27
|
+
let {
|
|
28
|
+
isFloating,
|
|
29
|
+
isRecessed,
|
|
30
|
+
...props
|
|
31
|
+
} = _ref;
|
|
32
|
+
return React__default.createElement(StyledWell, Object.assign({
|
|
33
|
+
ref: ref,
|
|
34
|
+
$isFloating: isFloating,
|
|
35
|
+
$isRecessed: isRecessed
|
|
36
|
+
}, props));
|
|
37
|
+
});
|
|
38
|
+
WellComponent.displayName = 'Well';
|
|
39
|
+
WellComponent.propTypes = {
|
|
40
|
+
isRecessed: PropTypes.bool,
|
|
41
|
+
isFloating: PropTypes.bool
|
|
42
|
+
};
|
|
43
|
+
const Well = WellComponent;
|
|
44
|
+
Well.Paragraph = Paragraph;
|
|
45
|
+
Well.Title = Title;
|
|
46
|
+
|
|
47
|
+
export { Well, WellComponent };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Zendesk, Inc.
|
|
3
|
+
*
|
|
4
|
+
* Use of this source code is governed under the Apache License, Version 2.0
|
|
5
|
+
* found at http://www.apache.org/licenses/LICENSE-2.0.
|
|
6
|
+
*/
|
|
7
|
+
export { Alert } from './elements/alert/Alert.js';
|
|
8
|
+
export { Notification } from './elements/Notification.js';
|
|
9
|
+
export { Well } from './elements/well/Well.js';
|
|
10
|
+
export { Close } from './elements/Close.js';
|
|
11
|
+
export { Paragraph } from './elements/Paragraph.js';
|
|
12
|
+
export { Title } from './elements/Title.js';
|
|
13
|
+
export { ToastProvider } from './elements/toaster/ToastProvider.js';
|
|
14
|
+
export { useToast } from './elements/toaster/useToast.js';
|
|
15
|
+
export { GlobalAlert } from './elements/global-alert/GlobalAlert.js';
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Zendesk, Inc.
|
|
3
|
+
*
|
|
4
|
+
* Use of this source code is governed under the Apache License, Version 2.0
|
|
5
|
+
* found at http://www.apache.org/licenses/LICENSE-2.0.
|
|
6
|
+
*/
|
|
7
|
+
import * as React from 'react';
|
|
8
|
+
|
|
9
|
+
var _g, _circle;
|
|
10
|
+
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
11
|
+
var SvgAlertErrorStroke = function SvgAlertErrorStroke(props) {
|
|
12
|
+
return /*#__PURE__*/React.createElement("svg", _extends({
|
|
13
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
14
|
+
width: 16,
|
|
15
|
+
height: 16,
|
|
16
|
+
focusable: "false",
|
|
17
|
+
viewBox: "0 0 16 16",
|
|
18
|
+
"aria-hidden": "true"
|
|
19
|
+
}, props), _g || (_g = /*#__PURE__*/React.createElement("g", {
|
|
20
|
+
fill: "none",
|
|
21
|
+
stroke: "currentColor"
|
|
22
|
+
}, /*#__PURE__*/React.createElement("circle", {
|
|
23
|
+
cx: 7.5,
|
|
24
|
+
cy: 8.5,
|
|
25
|
+
r: 7
|
|
26
|
+
}), /*#__PURE__*/React.createElement("path", {
|
|
27
|
+
strokeLinecap: "round",
|
|
28
|
+
d: "M7.5 4.5V9"
|
|
29
|
+
}))), _circle || (_circle = /*#__PURE__*/React.createElement("circle", {
|
|
30
|
+
cx: 7.5,
|
|
31
|
+
cy: 12,
|
|
32
|
+
r: 1,
|
|
33
|
+
fill: "currentColor"
|
|
34
|
+
})));
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export { SvgAlertErrorStroke as default };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Zendesk, Inc.
|
|
3
|
+
*
|
|
4
|
+
* Use of this source code is governed under the Apache License, Version 2.0
|
|
5
|
+
* found at http://www.apache.org/licenses/LICENSE-2.0.
|
|
6
|
+
*/
|
|
7
|
+
import * as React from 'react';
|
|
8
|
+
|
|
9
|
+
var _path, _circle;
|
|
10
|
+
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
11
|
+
var SvgAlertWarningStroke = function SvgAlertWarningStroke(props) {
|
|
12
|
+
return /*#__PURE__*/React.createElement("svg", _extends({
|
|
13
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
14
|
+
width: 16,
|
|
15
|
+
height: 16,
|
|
16
|
+
focusable: "false",
|
|
17
|
+
viewBox: "0 0 16 16",
|
|
18
|
+
"aria-hidden": "true"
|
|
19
|
+
}, props), _path || (_path = /*#__PURE__*/React.createElement("path", {
|
|
20
|
+
fill: "none",
|
|
21
|
+
stroke: "currentColor",
|
|
22
|
+
strokeLinecap: "round",
|
|
23
|
+
d: "M.88 13.77L7.06 1.86c.19-.36.7-.36.89 0l6.18 11.91c.17.33-.07.73-.44.73H1.32c-.37 0-.61-.4-.44-.73zM7.5 6v3.5"
|
|
24
|
+
})), _circle || (_circle = /*#__PURE__*/React.createElement("circle", {
|
|
25
|
+
cx: 7.5,
|
|
26
|
+
cy: 12,
|
|
27
|
+
r: 1,
|
|
28
|
+
fill: "currentColor"
|
|
29
|
+
})));
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export { SvgAlertWarningStroke as default };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Zendesk, Inc.
|
|
3
|
+
*
|
|
4
|
+
* Use of this source code is governed under the Apache License, Version 2.0
|
|
5
|
+
* found at http://www.apache.org/licenses/LICENSE-2.0.
|
|
6
|
+
*/
|
|
7
|
+
import * as React from 'react';
|
|
8
|
+
|
|
9
|
+
var _g;
|
|
10
|
+
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
11
|
+
var SvgCheckCircleStroke = function SvgCheckCircleStroke(props) {
|
|
12
|
+
return /*#__PURE__*/React.createElement("svg", _extends({
|
|
13
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
14
|
+
width: 16,
|
|
15
|
+
height: 16,
|
|
16
|
+
focusable: "false",
|
|
17
|
+
viewBox: "0 0 16 16",
|
|
18
|
+
"aria-hidden": "true"
|
|
19
|
+
}, props), _g || (_g = /*#__PURE__*/React.createElement("g", {
|
|
20
|
+
fill: "none",
|
|
21
|
+
stroke: "currentColor"
|
|
22
|
+
}, /*#__PURE__*/React.createElement("path", {
|
|
23
|
+
strokeLinecap: "round",
|
|
24
|
+
strokeLinejoin: "round",
|
|
25
|
+
d: "M4 9l2.5 2.5 5-5"
|
|
26
|
+
}), /*#__PURE__*/React.createElement("circle", {
|
|
27
|
+
cx: 7.5,
|
|
28
|
+
cy: 8.5,
|
|
29
|
+
r: 7
|
|
30
|
+
}))));
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export { SvgCheckCircleStroke as default };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Zendesk, Inc.
|
|
3
|
+
*
|
|
4
|
+
* Use of this source code is governed under the Apache License, Version 2.0
|
|
5
|
+
* found at http://www.apache.org/licenses/LICENSE-2.0.
|
|
6
|
+
*/
|
|
7
|
+
import * as React from 'react';
|
|
8
|
+
|
|
9
|
+
var _g, _circle;
|
|
10
|
+
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
11
|
+
var SvgInfoStroke = function SvgInfoStroke(props) {
|
|
12
|
+
return /*#__PURE__*/React.createElement("svg", _extends({
|
|
13
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
14
|
+
width: 16,
|
|
15
|
+
height: 16,
|
|
16
|
+
focusable: "false",
|
|
17
|
+
viewBox: "0 0 16 16",
|
|
18
|
+
"aria-hidden": "true"
|
|
19
|
+
}, props), _g || (_g = /*#__PURE__*/React.createElement("g", {
|
|
20
|
+
stroke: "currentColor"
|
|
21
|
+
}, /*#__PURE__*/React.createElement("circle", {
|
|
22
|
+
cx: 7.5,
|
|
23
|
+
cy: 8.5,
|
|
24
|
+
r: 7,
|
|
25
|
+
fill: "none"
|
|
26
|
+
}), /*#__PURE__*/React.createElement("path", {
|
|
27
|
+
strokeLinecap: "round",
|
|
28
|
+
d: "M7.5 12.5V8"
|
|
29
|
+
}))), _circle || (_circle = /*#__PURE__*/React.createElement("circle", {
|
|
30
|
+
cx: 7.5,
|
|
31
|
+
cy: 5,
|
|
32
|
+
r: 1,
|
|
33
|
+
fill: "currentColor"
|
|
34
|
+
})));
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export { SvgInfoStroke as default };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Zendesk, Inc.
|
|
3
|
+
*
|
|
4
|
+
* Use of this source code is governed under the Apache License, Version 2.0
|
|
5
|
+
* found at http://www.apache.org/licenses/LICENSE-2.0.
|
|
6
|
+
*/
|
|
7
|
+
import * as React from 'react';
|
|
8
|
+
|
|
9
|
+
var _path;
|
|
10
|
+
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
11
|
+
var SvgXStroke = function SvgXStroke(props) {
|
|
12
|
+
return /*#__PURE__*/React.createElement("svg", _extends({
|
|
13
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
14
|
+
width: 16,
|
|
15
|
+
height: 16,
|
|
16
|
+
focusable: "false",
|
|
17
|
+
viewBox: "0 0 16 16",
|
|
18
|
+
"aria-hidden": "true"
|
|
19
|
+
}, props), _path || (_path = /*#__PURE__*/React.createElement("path", {
|
|
20
|
+
stroke: "currentColor",
|
|
21
|
+
strokeLinecap: "round",
|
|
22
|
+
d: "M3 13L13 3m0 10L3 3"
|
|
23
|
+
})));
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export { SvgXStroke as default };
|