@thecb/components 9.3.1-beta.0 → 9.3.2-beta.1
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/dist/index.cjs.js +717 -536
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +169 -60
- package/dist/index.esm.js +715 -536
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/atoms/dropdown/Dropdown.js +70 -36
- package/src/components/atoms/dropdown/Dropdown.theme.js +8 -2
- package/src/components/atoms/form-select/FormSelect.js +16 -14
- package/src/components/molecules/index.d.ts +1 -0
- package/src/components/molecules/index.js +1 -0
- package/src/components/molecules/popover/Popover.js +1 -1
- package/src/components/molecules/radio-section/RadioSection.js +2 -3
- package/src/components/molecules/terms-and-conditions/TermsAndConditionsControlV2.js +1 -1
- package/src/components/molecules/toast-notification/ToastNotification.js +75 -0
- package/src/components/molecules/toast-notification/ToastNotification.stories.js +67 -0
- package/src/components/molecules/toast-notification/index.d.ts +18 -0
- package/src/components/molecules/toast-notification/index.js +3 -0
- package/src/constants/colors.d.ts +1 -0
- package/src/constants/colors.js +5 -1
- package/src/hooks/index.js +3 -0
- package/src/hooks/use-toast-notification/index.d.ts +23 -0
- package/src/hooks/use-toast-notification/index.js +38 -0
- package/src/index.d.ts +2 -1
- package/src/index.js +2 -1
- package/src/types/common/ToastVariants.ts +6 -0
- package/src/types/common/index.ts +1 -0
- package/src/util/index.js +10 -2
- package/dist/src/apps/checkout/pages/payment/sub-pages/payment-amount/PaymentAmount_old.js +0 -49322
- package/src/.DS_Store +0 -0
- package/src/components/.DS_Store +0 -0
- package/src/components/atoms/.DS_Store +0 -0
- package/src/components/atoms/icons/.DS_Store +0 -0
- /package/src/{util/useOutsideClick.js → hooks/use-outside-click/index.js} +0 -0
- /package/src/{util/useScrollTo.js → hooks/use-scroll-to/index.js} +0 -0
package/package.json
CHANGED
|
@@ -12,11 +12,11 @@ import styled from "styled-components";
|
|
|
12
12
|
import "core-js/proposals/relative-indexing-method";
|
|
13
13
|
|
|
14
14
|
import {
|
|
15
|
-
|
|
15
|
+
ERROR_COLOR,
|
|
16
16
|
GREY_CHATEAU,
|
|
17
|
-
STORM_GREY,
|
|
18
17
|
MINESHAFT_GREY,
|
|
19
|
-
|
|
18
|
+
STORM_GREY,
|
|
19
|
+
WHITE
|
|
20
20
|
} from "../../../constants/colors";
|
|
21
21
|
import { fallbackValues } from "./Dropdown.theme";
|
|
22
22
|
import { themeComponent } from "../../../util/themeUtils";
|
|
@@ -55,37 +55,65 @@ const DropdownContentWrapper = styled.div`
|
|
|
55
55
|
`;
|
|
56
56
|
|
|
57
57
|
const DropdownItemWrapper = styled.li`
|
|
58
|
-
background-color: ${({ selected, themeValues }) =>
|
|
59
|
-
selected ? themeValues.selectedColor : WHITE};
|
|
60
58
|
text-align: start;
|
|
61
|
-
border-width:
|
|
62
|
-
border-
|
|
59
|
+
border-width: 2px;
|
|
60
|
+
border-style: solid;
|
|
61
|
+
border-color: ${({ selected, themeValues }) =>
|
|
62
|
+
selected ? themeValues.selectedColor : WHITE};
|
|
63
63
|
box-shadow: none;
|
|
64
|
-
padding: 1rem;
|
|
65
64
|
box-sizing: border-box;
|
|
66
65
|
width: 100%;
|
|
67
66
|
list-style: none;
|
|
68
67
|
cursor: ${({ disabled }) => (disabled ? "default" : "pointer")};
|
|
69
68
|
|
|
70
69
|
&:hover {
|
|
71
|
-
|
|
70
|
+
border-color: ${({ disabled, selected, themeValues }) =>
|
|
72
71
|
selected
|
|
73
|
-
? themeValues.
|
|
72
|
+
? themeValues.focusColor
|
|
74
73
|
: disabled
|
|
75
74
|
? WHITE
|
|
76
75
|
: themeValues.hoverColor};
|
|
76
|
+
> * {
|
|
77
|
+
background: ${({ selected, disabled, themeValues }) =>
|
|
78
|
+
selected
|
|
79
|
+
? themeValues.focusColor
|
|
80
|
+
: disabled
|
|
81
|
+
? WHITE
|
|
82
|
+
: themeValues.hoverColor};
|
|
83
|
+
border-color: ${({ selected, disabled, themeValues }) =>
|
|
84
|
+
selected
|
|
85
|
+
? themeValues.focusColor
|
|
86
|
+
: disabled
|
|
87
|
+
? WHITE
|
|
88
|
+
: themeValues.hoverColor};
|
|
89
|
+
}
|
|
77
90
|
}
|
|
78
91
|
&:focus {
|
|
79
|
-
background-color: ${({ selected, disabled, themeValues }) =>
|
|
80
|
-
selected
|
|
81
|
-
? themeValues.selectedColor
|
|
82
|
-
: disabled
|
|
83
|
-
? WHITE
|
|
84
|
-
: themeValues.hoverColor};
|
|
85
92
|
outline: none;
|
|
93
|
+
border-color: ${({ themeValues }) => themeValues.selectedColor};
|
|
94
|
+
> * {
|
|
95
|
+
background: ${({ selected, disabled, themeValues }) =>
|
|
96
|
+
selected
|
|
97
|
+
? themeValues.focusColor
|
|
98
|
+
: disabled
|
|
99
|
+
? WHITE
|
|
100
|
+
: themeValues.hoverColor};
|
|
101
|
+
border-color: white;
|
|
102
|
+
outline: none;
|
|
103
|
+
}
|
|
86
104
|
}
|
|
87
105
|
`;
|
|
88
106
|
|
|
107
|
+
const DropdownItemBorder = styled.div`
|
|
108
|
+
background: ${({ selected, themeValues }) =>
|
|
109
|
+
selected ? themeValues.selectedColor : WHITE};
|
|
110
|
+
border-color: ${({ selected, themeValues }) =>
|
|
111
|
+
selected ? themeValues.selectedColor : WHITE};
|
|
112
|
+
border-width: 2px;
|
|
113
|
+
border-style: solid;
|
|
114
|
+
padding: 12px;
|
|
115
|
+
`;
|
|
116
|
+
|
|
89
117
|
const Dropdown = ({
|
|
90
118
|
placeholder,
|
|
91
119
|
options,
|
|
@@ -385,27 +413,33 @@ const Dropdown = ({
|
|
|
385
413
|
role="option"
|
|
386
414
|
onFocus={() => setFocusedRef(optionRefs.current[i])}
|
|
387
415
|
>
|
|
388
|
-
<
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
? WHITE
|
|
393
|
-
: disabledValues.includes(choice.value)
|
|
394
|
-
? STORM_GREY
|
|
395
|
-
: MINESHAFT_GREY
|
|
396
|
-
}
|
|
397
|
-
extraStyles={`padding-left: 16px;
|
|
398
|
-
cursor: ${
|
|
399
|
-
disabledValues.includes(choice.value)
|
|
400
|
-
? "default"
|
|
401
|
-
: "pointer"
|
|
402
|
-
};
|
|
403
|
-
white-space: nowrap;
|
|
404
|
-
overflow: hidden;
|
|
405
|
-
text-overflow: ellipsis;`}
|
|
416
|
+
<DropdownItemBorder
|
|
417
|
+
disabled={disabledValues.includes(choice.value)}
|
|
418
|
+
selected={choice.value === value}
|
|
419
|
+
themeValues={themeValues}
|
|
406
420
|
>
|
|
407
|
-
|
|
408
|
-
|
|
421
|
+
<Text
|
|
422
|
+
variant="p"
|
|
423
|
+
color={
|
|
424
|
+
choice.value === value
|
|
425
|
+
? WHITE
|
|
426
|
+
: disabledValues.includes(choice.value)
|
|
427
|
+
? STORM_GREY
|
|
428
|
+
: MINESHAFT_GREY
|
|
429
|
+
}
|
|
430
|
+
extraStyles={`padding-left: 16px;
|
|
431
|
+
cursor: ${
|
|
432
|
+
disabledValues.includes(choice.value)
|
|
433
|
+
? "default"
|
|
434
|
+
: "pointer"
|
|
435
|
+
};
|
|
436
|
+
white-space: nowrap;
|
|
437
|
+
overflow: hidden;
|
|
438
|
+
text-overflow: ellipsis;`}
|
|
439
|
+
>
|
|
440
|
+
{choice.text}
|
|
441
|
+
</Text>
|
|
442
|
+
</DropdownItemBorder>
|
|
409
443
|
</DropdownItemWrapper>
|
|
410
444
|
);
|
|
411
445
|
})}
|
|
@@ -1,9 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
HOVER_LIGHT_BLUE,
|
|
3
|
+
MATISSE_BLUE,
|
|
4
|
+
MATISSE_BLUE_DARK
|
|
5
|
+
} from "../../../constants/colors";
|
|
2
6
|
|
|
3
7
|
const selectedColor = `${MATISSE_BLUE}`;
|
|
4
8
|
const hoverColor = `${HOVER_LIGHT_BLUE}`;
|
|
9
|
+
const focusColor = `${MATISSE_BLUE_DARK}`;
|
|
5
10
|
|
|
6
11
|
export const fallbackValues = {
|
|
7
12
|
selectedColor,
|
|
8
|
-
hoverColor
|
|
13
|
+
hoverColor,
|
|
14
|
+
focusColor
|
|
9
15
|
};
|
|
@@ -96,26 +96,28 @@ const FormSelect = ({
|
|
|
96
96
|
smoothScroll={smoothScroll}
|
|
97
97
|
/>
|
|
98
98
|
<Stack direction="row" justify="space-between">
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
99
|
+
{(field.hasErrors && field.dirty) || (field.hasErrors && showErrors) ? (
|
|
100
|
+
<Text
|
|
101
|
+
color={ERROR_COLOR}
|
|
102
|
+
variant="pXS"
|
|
103
|
+
weight={themeValues.fontWeight}
|
|
104
|
+
extraStyles={`
|
|
104
105
|
word-break: break-word;
|
|
105
106
|
font-family: Public Sans;
|
|
106
107
|
&::first-letter {
|
|
107
108
|
text-transform: uppercase;
|
|
108
109
|
}
|
|
109
110
|
`}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
111
|
+
id={createIdFromString(labelTextWhenNoError, "error message")}
|
|
112
|
+
aria-live="polite"
|
|
113
|
+
aria-atomic={true}
|
|
114
|
+
data-qa={createIdFromString(labelTextWhenNoError, "error message")}
|
|
115
|
+
>
|
|
116
|
+
{errorMessages[field.errors[0]]}
|
|
117
|
+
</Text>
|
|
118
|
+
) : (
|
|
119
|
+
<Text extraStyles={`height: ${themeValues.lineHeight};`} />
|
|
120
|
+
)}
|
|
119
121
|
</Stack>
|
|
120
122
|
</SelectContainer>
|
|
121
123
|
);
|
|
@@ -37,5 +37,6 @@ export { default as TabSidebar } from "./tab-sidebar";
|
|
|
37
37
|
export { default as TermsAndConditions } from "./terms-and-conditions";
|
|
38
38
|
export { default as TermsAndConditionsModal } from "./terms-and-conditions-modal";
|
|
39
39
|
export { default as Timeout } from "./timeout";
|
|
40
|
+
export { default as ToastNotification } from "./toast-notification";
|
|
40
41
|
export { default as WelcomeModule } from "./welcome-module";
|
|
41
42
|
export { default as WorkflowTile } from "./workflow-tile";
|
|
@@ -4,7 +4,7 @@ import Text from "../../atoms/text";
|
|
|
4
4
|
import Paragraph from "../../atoms/paragraph";
|
|
5
5
|
import { Box } from "../../atoms/layouts";
|
|
6
6
|
import ButtonWithAction from "../../atoms/button-with-action";
|
|
7
|
-
import { useOutsideClick } from "../../../
|
|
7
|
+
import { useOutsideClick } from "../../../hooks";
|
|
8
8
|
import { noop } from "../../../util/general";
|
|
9
9
|
import { fallbackValues } from "./Popover.theme";
|
|
10
10
|
|
|
@@ -47,8 +47,7 @@ const RadioSection = ({
|
|
|
47
47
|
initiallyOpen = true,
|
|
48
48
|
openHeight = "auto",
|
|
49
49
|
containerStyles = "",
|
|
50
|
-
ariaDescribedBy
|
|
51
|
-
ariaLabel = "Please select an option."
|
|
50
|
+
ariaDescribedBy
|
|
52
51
|
}) => {
|
|
53
52
|
const handleKeyDown = (id, e) => {
|
|
54
53
|
if (e?.keyCode === 13 || e?.keyCode === 32) {
|
|
@@ -106,7 +105,7 @@ const RadioSection = ({
|
|
|
106
105
|
borderRadius="4px"
|
|
107
106
|
extraStyles={containerStyles}
|
|
108
107
|
>
|
|
109
|
-
<Stack childGap="0" role="radiogroup"
|
|
108
|
+
<Stack childGap="0" role="radiogroup">
|
|
110
109
|
{sections
|
|
111
110
|
.filter(section => !section.hidden)
|
|
112
111
|
.map(section => (
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
ERROR_COLOR
|
|
10
10
|
} from "../../../constants/colors";
|
|
11
11
|
import { generateShadows } from "../../../util/generateShadows";
|
|
12
|
-
import useScrollTo from "../../../
|
|
12
|
+
import { useScrollTo } from "../../../hooks";
|
|
13
13
|
|
|
14
14
|
const TermsAndConditionsControlV2 = ({
|
|
15
15
|
showCheckbox = true,
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Box, Cluster } from "../../atoms/layouts";
|
|
3
|
+
import { Paragraph } from "../../atoms";
|
|
4
|
+
import {
|
|
5
|
+
SuccessfulIconMedium,
|
|
6
|
+
ErroredIcon,
|
|
7
|
+
IconQuitLarge
|
|
8
|
+
} from "../../atoms/icons";
|
|
9
|
+
import {
|
|
10
|
+
ERROR_BACKGROUND_COLOR,
|
|
11
|
+
HINT_GREEN,
|
|
12
|
+
WHITE
|
|
13
|
+
} from "../../../constants/colors";
|
|
14
|
+
import { FONT_WEIGHT_SEMIBOLD } from "../../../constants/style_constants";
|
|
15
|
+
import { generateShadows } from "../../../util/generateShadows";
|
|
16
|
+
|
|
17
|
+
const VARIANTS = {
|
|
18
|
+
SUCCESS: "success",
|
|
19
|
+
ERROR: "error"
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const ToastNotification = ({
|
|
23
|
+
variant = VARIANTS.SUCCESS,
|
|
24
|
+
message = "",
|
|
25
|
+
toastOpen,
|
|
26
|
+
closeToastNotification,
|
|
27
|
+
extraStyles,
|
|
28
|
+
minWidth = "112px",
|
|
29
|
+
maxWidth = "350px",
|
|
30
|
+
height = "56px",
|
|
31
|
+
childGap = "1rem",
|
|
32
|
+
backgroundColor
|
|
33
|
+
}) => (
|
|
34
|
+
<Box
|
|
35
|
+
onClick={closeToastNotification}
|
|
36
|
+
background={
|
|
37
|
+
backgroundColor
|
|
38
|
+
? backgroundColor
|
|
39
|
+
: variant === VARIANTS.SUCCESS
|
|
40
|
+
? HINT_GREEN
|
|
41
|
+
: variant === VARIANTS.ERROR
|
|
42
|
+
? ERROR_BACKGROUND_COLOR
|
|
43
|
+
: WHITE
|
|
44
|
+
}
|
|
45
|
+
minWidth={minWidth}
|
|
46
|
+
minHeight={height && parseInt(height) < 100 ? height : "100px"}
|
|
47
|
+
height={height ? height : "auto"}
|
|
48
|
+
tabIndex={toastOpen ? "-1" : "0"}
|
|
49
|
+
padding="0rem 1rem"
|
|
50
|
+
borderRadius="4px"
|
|
51
|
+
boxShadow={generateShadows().standard.base}
|
|
52
|
+
extraStyles={`
|
|
53
|
+
display: ${toastOpen ? "block" : "none"};
|
|
54
|
+
position: fixed; bottom: 4rem; left: 4rem;
|
|
55
|
+
${extraStyles};
|
|
56
|
+
cursor: pointer;
|
|
57
|
+
`}
|
|
58
|
+
>
|
|
59
|
+
<Cluster align="center" childGap={childGap}>
|
|
60
|
+
{variant === VARIANTS.SUCCESS && <SuccessfulIconMedium />}
|
|
61
|
+
{variant === VARIANTS.ERROR && <ErroredIcon />}
|
|
62
|
+
<Box padding="1rem 0" maxWidth={maxWidth}>
|
|
63
|
+
<Paragraph
|
|
64
|
+
weight={FONT_WEIGHT_SEMIBOLD}
|
|
65
|
+
extraStyles={"word-break: break-word;"}
|
|
66
|
+
>
|
|
67
|
+
{message}
|
|
68
|
+
</Paragraph>
|
|
69
|
+
</Box>
|
|
70
|
+
<IconQuitLarge />
|
|
71
|
+
</Cluster>
|
|
72
|
+
</Box>
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
export default ToastNotification;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import React, { useEffect } from "react";
|
|
2
|
+
import ToastNotification from "./ToastNotification";
|
|
3
|
+
import page from "../../../../.storybook/page";
|
|
4
|
+
import { useToastNotification } from "../../../hooks";
|
|
5
|
+
import { ToastVariants } from "../../../types/common";
|
|
6
|
+
|
|
7
|
+
export const toastNotificationSuccess = () => {
|
|
8
|
+
const {
|
|
9
|
+
isToastOpen,
|
|
10
|
+
toastVariant,
|
|
11
|
+
toastMessage,
|
|
12
|
+
showToast,
|
|
13
|
+
hideToast
|
|
14
|
+
} = useToastNotification();
|
|
15
|
+
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
showToast({
|
|
18
|
+
message: "Success!",
|
|
19
|
+
variant: ToastVariants.SUCCESS
|
|
20
|
+
});
|
|
21
|
+
}, []);
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<ToastNotification
|
|
25
|
+
variant={toastVariant}
|
|
26
|
+
message={toastMessage}
|
|
27
|
+
toastOpen={isToastOpen}
|
|
28
|
+
closeToastNotification={() => hideToast()}
|
|
29
|
+
/>
|
|
30
|
+
);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
toastNotificationSuccess.storyName = "Success Toast";
|
|
34
|
+
|
|
35
|
+
export const toastNotificationError = () => {
|
|
36
|
+
const {
|
|
37
|
+
isToastOpen,
|
|
38
|
+
toastVariant,
|
|
39
|
+
toastMessage,
|
|
40
|
+
showToast,
|
|
41
|
+
hideToast
|
|
42
|
+
} = useToastNotification();
|
|
43
|
+
|
|
44
|
+
useEffect(() => {
|
|
45
|
+
showToast({
|
|
46
|
+
message: "An error occurred",
|
|
47
|
+
variant: ToastVariants.ERROR
|
|
48
|
+
});
|
|
49
|
+
}, []);
|
|
50
|
+
|
|
51
|
+
return (
|
|
52
|
+
<ToastNotification
|
|
53
|
+
variant={toastVariant}
|
|
54
|
+
message={toastMessage}
|
|
55
|
+
toastOpen={isToastOpen}
|
|
56
|
+
closeToastNotification={() => hideToast()}
|
|
57
|
+
/>
|
|
58
|
+
);
|
|
59
|
+
};
|
|
60
|
+
toastNotificationError.storyName = "Error Toast";
|
|
61
|
+
|
|
62
|
+
const story = page({
|
|
63
|
+
title: "Components|Molecules/ToastNotification",
|
|
64
|
+
Component: ToastNotification
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
export default story;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import Expand from "../../../util/expand";
|
|
3
|
+
|
|
4
|
+
export interface ToastNotificationProps {
|
|
5
|
+
variant?: string;
|
|
6
|
+
message: string;
|
|
7
|
+
toastOpen: boolean;
|
|
8
|
+
closeToastNotification: (event?: React.MouseEvent<HTMLElement>) => void;
|
|
9
|
+
extraStyles?: string;
|
|
10
|
+
minWidth?: string;
|
|
11
|
+
maxWidth?: string;
|
|
12
|
+
height?: string;
|
|
13
|
+
childGap?: string;
|
|
14
|
+
backgroundColor?: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const ToastNotification: React.FC<Expand<ToastNotificationProps> &
|
|
18
|
+
React.HTMLAttributes<HTMLElement>>;
|
package/src/constants/colors.js
CHANGED
|
@@ -56,6 +56,7 @@ const INFO_BLUE = "#E4F4FD";
|
|
|
56
56
|
const CORNFLOWER_BLUE = "#EBEFFB";
|
|
57
57
|
const HOVER_LIGHT_BLUE = "#EFFAFF";
|
|
58
58
|
const MATISSE_BLUE = "#15749D";
|
|
59
|
+
const MATISSE_BLUE_DARK = "#105C7D";
|
|
59
60
|
const ROYAL_BLUE = "#3181E3";
|
|
60
61
|
const ROYAL_BLUE_VIVID = "#3B5BDB";
|
|
61
62
|
const ASTRAL_BLUE = "#3176AA";
|
|
@@ -90,6 +91,7 @@ const BLUSH_RED = "#FFF0F5";
|
|
|
90
91
|
|
|
91
92
|
// Second level color constants
|
|
92
93
|
const ERROR_COLOR = RAZZMATAZZ_RED;
|
|
94
|
+
const ERROR_BACKGROUND_COLOR = "#FFF4F8";
|
|
93
95
|
|
|
94
96
|
// These colors are sequestered so that the alert component can reference them // by type of alert
|
|
95
97
|
const ALERT_COLORS = {
|
|
@@ -192,6 +194,7 @@ export {
|
|
|
192
194
|
BOSTON_BLUE,
|
|
193
195
|
HOVER_LIGHT_BLUE,
|
|
194
196
|
MATISSE_BLUE,
|
|
197
|
+
MATISSE_BLUE_DARK,
|
|
195
198
|
ROYAL_BLUE,
|
|
196
199
|
ROYAL_BLUE_VIVID,
|
|
197
200
|
ASTRAL_BLUE,
|
|
@@ -221,5 +224,6 @@ export {
|
|
|
221
224
|
RASPBERRY,
|
|
222
225
|
ALERT_COLORS,
|
|
223
226
|
PILL_COLORS,
|
|
224
|
-
ERROR_COLOR
|
|
227
|
+
ERROR_COLOR,
|
|
228
|
+
ERROR_BACKGROUND_COLOR
|
|
225
229
|
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ToastVariants } from "../../types/common";
|
|
2
|
+
|
|
3
|
+
export interface UseToastOptions {
|
|
4
|
+
timeout?: number;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export interface UseToastResult {
|
|
8
|
+
isToastOpen: boolean;
|
|
9
|
+
toastVariant: string | ToastVariants;
|
|
10
|
+
toastMessage: string;
|
|
11
|
+
showToast: ({
|
|
12
|
+
message,
|
|
13
|
+
variant
|
|
14
|
+
}: {
|
|
15
|
+
message: string;
|
|
16
|
+
variant: string | ToastVariants;
|
|
17
|
+
}) => void;
|
|
18
|
+
hideToast: () => void;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export default function useToastNotification(
|
|
22
|
+
options?: UseToastOptions
|
|
23
|
+
): UseToastResult;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
|
|
3
|
+
const initialToastState = {
|
|
4
|
+
isOpen: false,
|
|
5
|
+
variant: "",
|
|
6
|
+
message: ""
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
const useToastNotification = ({ timeout = 5000 } = {}) => {
|
|
10
|
+
const [toastState, setToastState] = useState(initialToastState);
|
|
11
|
+
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
if (toastState.isOpen) {
|
|
14
|
+
setTimeout(() => {
|
|
15
|
+
setToastState(initialToastState);
|
|
16
|
+
}, timeout);
|
|
17
|
+
}
|
|
18
|
+
}, [timeout, toastState.isOpen]);
|
|
19
|
+
|
|
20
|
+
const showToast = ({ message, variant }) =>
|
|
21
|
+
setToastState({
|
|
22
|
+
isOpen: true,
|
|
23
|
+
variant,
|
|
24
|
+
message
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const hideToast = () => setToastState(initialToastState);
|
|
28
|
+
|
|
29
|
+
return {
|
|
30
|
+
isToastOpen: toastState.isOpen,
|
|
31
|
+
toastVariant: toastState.variant,
|
|
32
|
+
toastMessage: toastState.message,
|
|
33
|
+
showToast,
|
|
34
|
+
hideToast
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export default useToastNotification;
|
package/src/index.d.ts
CHANGED
package/src/index.js
CHANGED
|
@@ -4,4 +4,5 @@ export { default as FieldActions } from "./FieldActions";
|
|
|
4
4
|
export { default as FormSelectOption } from "./FormSelectOption";
|
|
5
5
|
export { default as SearchableSelectOption } from "./SearchableSelectOption";
|
|
6
6
|
export { default as ErrorMessageDictionary } from "./ErrorMessageDictionary";
|
|
7
|
+
export { default as ToastVariants } from "./ToastVariants";
|
|
7
8
|
export * from "./FieldActions";
|
package/src/util/index.js
CHANGED
|
@@ -2,6 +2,14 @@ import * as formats from "./formats";
|
|
|
2
2
|
import * as general from "./general";
|
|
3
3
|
import * as theme from "./themeUtils";
|
|
4
4
|
import useFocusInvalidInput from "./focusFirstInvalidInputHook";
|
|
5
|
-
import useOutsideClick from "
|
|
5
|
+
import useOutsideClick from "../hooks/use-outside-click";
|
|
6
|
+
import useToastNotification from "../hooks/use-toast-notification";
|
|
6
7
|
|
|
7
|
-
export {
|
|
8
|
+
export {
|
|
9
|
+
formats,
|
|
10
|
+
general,
|
|
11
|
+
theme,
|
|
12
|
+
useFocusInvalidInput,
|
|
13
|
+
useOutsideClick,
|
|
14
|
+
useToastNotification
|
|
15
|
+
};
|