@redsift/popovers 8.0.0 → 8.0.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.
Files changed (185) hide show
  1. package/coverage/clover.xml +738 -0
  2. package/coverage/coverage-final.json +53 -0
  3. package/coverage/lcov-report/Tooltip.tsx.html +235 -0
  4. package/coverage/lcov-report/TooltipContent.tsx.html +235 -0
  5. package/coverage/lcov-report/TooltipTrigger.tsx.html +241 -0
  6. package/coverage/lcov-report/base.css +224 -0
  7. package/coverage/lcov-report/block-navigation.js +87 -0
  8. package/coverage/lcov-report/context.ts.html +97 -0
  9. package/coverage/lcov-report/dialog/Dialog.tsx.html +271 -0
  10. package/coverage/lcov-report/dialog/context.ts.html +97 -0
  11. package/coverage/lcov-report/dialog/index.html +191 -0
  12. package/coverage/lcov-report/dialog/index.ts.html +100 -0
  13. package/coverage/lcov-report/dialog/types.ts.html +253 -0
  14. package/coverage/lcov-report/dialog/useDialog.tsx.html +346 -0
  15. package/coverage/lcov-report/dialog/useDialogContext.tsx.html +121 -0
  16. package/coverage/lcov-report/dialog-content/DialogContent.tsx.html +487 -0
  17. package/coverage/lcov-report/dialog-content/index.html +146 -0
  18. package/coverage/lcov-report/dialog-content/index.ts.html +91 -0
  19. package/coverage/lcov-report/dialog-content/intl/index.html +116 -0
  20. package/coverage/lcov-report/dialog-content/intl/index.ts.html +106 -0
  21. package/coverage/lcov-report/dialog-content/styles.ts.html +301 -0
  22. package/coverage/lcov-report/dialog-content-actions/DialogContentActions.tsx.html +205 -0
  23. package/coverage/lcov-report/dialog-content-actions/index.html +146 -0
  24. package/coverage/lcov-report/dialog-content-actions/index.ts.html +91 -0
  25. package/coverage/lcov-report/dialog-content-actions/styles.ts.html +139 -0
  26. package/coverage/lcov-report/dialog-content-body/DialogContentBody.tsx.html +232 -0
  27. package/coverage/lcov-report/dialog-content-body/index.html +146 -0
  28. package/coverage/lcov-report/dialog-content-body/index.ts.html +91 -0
  29. package/coverage/lcov-report/dialog-content-body/styles.ts.html +259 -0
  30. package/coverage/lcov-report/dialog-content-header/DialogContentHeader.tsx.html +328 -0
  31. package/coverage/lcov-report/dialog-content-header/index.html +146 -0
  32. package/coverage/lcov-report/dialog-content-header/index.ts.html +91 -0
  33. package/coverage/lcov-report/dialog-content-header/styles.ts.html +193 -0
  34. package/coverage/lcov-report/dialog-trigger/DialogTrigger.tsx.html +214 -0
  35. package/coverage/lcov-report/dialog-trigger/index.html +131 -0
  36. package/coverage/lcov-report/dialog-trigger/index.ts.html +91 -0
  37. package/coverage/lcov-report/favicon.png +0 -0
  38. package/coverage/lcov-report/index.html +341 -0
  39. package/coverage/lcov-report/index.ts.html +97 -0
  40. package/coverage/lcov-report/popover/Popover.tsx.html +244 -0
  41. package/coverage/lcov-report/popover/context.ts.html +97 -0
  42. package/coverage/lcov-report/popover/index.html +191 -0
  43. package/coverage/lcov-report/popover/index.ts.html +100 -0
  44. package/coverage/lcov-report/popover/types.ts.html +244 -0
  45. package/coverage/lcov-report/popover/usePopover.tsx.html +295 -0
  46. package/coverage/lcov-report/popover/usePopoverContext.tsx.html +121 -0
  47. package/coverage/lcov-report/popover-content/PopoverContent.tsx.html +268 -0
  48. package/coverage/lcov-report/popover-content/index.html +146 -0
  49. package/coverage/lcov-report/popover-content/index.ts.html +91 -0
  50. package/coverage/lcov-report/popover-content/styles.ts.html +166 -0
  51. package/coverage/lcov-report/popover-trigger/PopoverTrigger.tsx.html +214 -0
  52. package/coverage/lcov-report/popover-trigger/index.html +131 -0
  53. package/coverage/lcov-report/popover-trigger/index.ts.html +91 -0
  54. package/coverage/lcov-report/prettify.css +1 -0
  55. package/coverage/lcov-report/prettify.js +2 -0
  56. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  57. package/coverage/lcov-report/sorter.js +196 -0
  58. package/coverage/lcov-report/styles.ts.html +391 -0
  59. package/coverage/lcov-report/toast/Toast.tsx.html +451 -0
  60. package/coverage/lcov-report/toast/index.html +161 -0
  61. package/coverage/lcov-report/toast/index.ts.html +91 -0
  62. package/coverage/lcov-report/toast/intl/index.html +116 -0
  63. package/coverage/lcov-report/toast/intl/index.ts.html +106 -0
  64. package/coverage/lcov-report/toast/styles.ts.html +214 -0
  65. package/coverage/lcov-report/toast/types.ts.html +217 -0
  66. package/coverage/lcov-report/toast-container/ToastContainer.tsx.html +217 -0
  67. package/coverage/lcov-report/toast-container/index.html +161 -0
  68. package/coverage/lcov-report/toast-container/index.ts.html +94 -0
  69. package/coverage/lcov-report/toast-container/styles.ts.html +2323 -0
  70. package/coverage/lcov-report/toast-container/useToast.tsx.html +469 -0
  71. package/coverage/lcov-report/toast-provider/ToastProvider.tsx.html +256 -0
  72. package/coverage/lcov-report/toast-provider/context.ts.html +106 -0
  73. package/coverage/lcov-report/toast-provider/index.html +161 -0
  74. package/coverage/lcov-report/toast-provider/index.ts.html +97 -0
  75. package/coverage/lcov-report/toast-provider/useToast.tsx.html +109 -0
  76. package/coverage/lcov-report/tooltip/Tooltip.tsx.html +250 -0
  77. package/coverage/lcov-report/tooltip/context.ts.html +97 -0
  78. package/coverage/lcov-report/tooltip/index.html +191 -0
  79. package/coverage/lcov-report/tooltip/index.ts.html +100 -0
  80. package/coverage/lcov-report/tooltip/types.ts.html +250 -0
  81. package/coverage/lcov-report/tooltip/useTooltip.tsx.html +352 -0
  82. package/coverage/lcov-report/tooltip/useTooltipContext.tsx.html +121 -0
  83. package/coverage/lcov-report/tooltip-content/TooltipContent.tsx.html +313 -0
  84. package/coverage/lcov-report/tooltip-content/index.html +146 -0
  85. package/coverage/lcov-report/tooltip-content/index.ts.html +91 -0
  86. package/coverage/lcov-report/tooltip-content/styles.ts.html +337 -0
  87. package/coverage/lcov-report/tooltip-trigger/TooltipTrigger.tsx.html +211 -0
  88. package/coverage/lcov-report/tooltip-trigger/index.html +131 -0
  89. package/coverage/lcov-report/tooltip-trigger/index.ts.html +91 -0
  90. package/coverage/lcov-report/types.ts.html +226 -0
  91. package/coverage/lcov-report/useTooltip.tsx.html +277 -0
  92. package/coverage/lcov-report/useTooltipContext.tsx.html +121 -0
  93. package/coverage/lcov-report/useTooltipOpen.tsx.html +559 -0
  94. package/coverage/lcov.info +1330 -0
  95. package/dist/package.json +96 -0
  96. package/index.ts +1 -0
  97. package/jest.config.js +3 -0
  98. package/package.json +2 -3
  99. package/rollup.config.js +13 -0
  100. package/src/components/dialog/Dialog.stories.tsx +201 -0
  101. package/src/components/dialog/Dialog.test.tsx +116 -0
  102. package/src/components/dialog/Dialog.tsx +62 -0
  103. package/src/components/dialog/context.ts +4 -0
  104. package/src/components/dialog/index.ts +5 -0
  105. package/src/components/dialog/types.ts +56 -0
  106. package/src/components/dialog/useDialog.tsx +87 -0
  107. package/src/components/dialog/useDialogContext.tsx +12 -0
  108. package/src/components/dialog-content/DialogContent.stories.tsx +337 -0
  109. package/src/components/dialog-content/DialogContent.tsx +134 -0
  110. package/src/components/dialog-content/index.ts +2 -0
  111. package/src/components/dialog-content/intl/en-US.json +3 -0
  112. package/src/components/dialog-content/intl/fr-FR.json +3 -0
  113. package/src/components/dialog-content/intl/index.ts +7 -0
  114. package/src/components/dialog-content/styles.ts +72 -0
  115. package/src/components/dialog-content/types.ts +11 -0
  116. package/src/components/dialog-content-actions/DialogContentActions.test.tsx +68 -0
  117. package/src/components/dialog-content-actions/DialogContentActions.tsx +40 -0
  118. package/src/components/dialog-content-actions/index.ts +2 -0
  119. package/src/components/dialog-content-actions/styles.ts +18 -0
  120. package/src/components/dialog-content-actions/types.ts +11 -0
  121. package/src/components/dialog-content-body/DialogContentBody.test.tsx +63 -0
  122. package/src/components/dialog-content-body/DialogContentBody.tsx +49 -0
  123. package/src/components/dialog-content-body/index.ts +2 -0
  124. package/src/components/dialog-content-body/styles.ts +58 -0
  125. package/src/components/dialog-content-body/types.ts +14 -0
  126. package/src/components/dialog-content-header/DialogContentHeader.test.tsx +63 -0
  127. package/src/components/dialog-content-header/DialogContentHeader.tsx +81 -0
  128. package/src/components/dialog-content-header/index.ts +2 -0
  129. package/src/components/dialog-content-header/styles.ts +36 -0
  130. package/src/components/dialog-content-header/types.ts +23 -0
  131. package/src/components/dialog-trigger/DialogTrigger.tsx +43 -0
  132. package/src/components/dialog-trigger/index.ts +2 -0
  133. package/src/components/dialog-trigger/types.ts +9 -0
  134. package/src/components/popover/Popover.stories.tsx +158 -0
  135. package/src/components/popover/Popover.test.tsx +102 -0
  136. package/src/components/popover/Popover.tsx +53 -0
  137. package/src/components/popover/context.ts +4 -0
  138. package/src/components/popover/index.ts +5 -0
  139. package/src/components/popover/types.ts +53 -0
  140. package/src/components/popover/usePopover.tsx +70 -0
  141. package/src/components/popover/usePopoverContext.tsx +12 -0
  142. package/src/components/popover-content/PopoverContent.tsx +61 -0
  143. package/src/components/popover-content/index.ts +2 -0
  144. package/src/components/popover-content/styles.ts +27 -0
  145. package/src/components/popover-content/types.ts +11 -0
  146. package/src/components/popover-trigger/PopoverTrigger.tsx +43 -0
  147. package/src/components/popover-trigger/index.ts +2 -0
  148. package/src/components/popover-trigger/types.ts +9 -0
  149. package/src/components/toast/Toast.stories.tsx +75 -0
  150. package/src/components/toast/Toast.test.tsx +63 -0
  151. package/src/components/toast/Toast.tsx +122 -0
  152. package/src/components/toast/index.ts +2 -0
  153. package/src/components/toast/intl/en-US.json +3 -0
  154. package/src/components/toast/intl/fr-FR.json +3 -0
  155. package/src/components/toast/intl/index.ts +7 -0
  156. package/src/components/toast/styles.ts +43 -0
  157. package/src/components/toast/types.ts +44 -0
  158. package/src/components/toast-container/ToastContainer.stories.tsx +349 -0
  159. package/src/components/toast-container/ToastContainer.tsx +44 -0
  160. package/src/components/toast-container/index.ts +3 -0
  161. package/src/components/toast-container/styles.ts +746 -0
  162. package/src/components/toast-container/types.ts +110 -0
  163. package/src/components/toast-container/useToast.test.tsx +111 -0
  164. package/src/components/toast-container/useToast.tsx +128 -0
  165. package/src/components/tooltip/Tooltip.stories.tsx +200 -0
  166. package/src/components/tooltip/Tooltip.test.tsx +119 -0
  167. package/src/components/tooltip/Tooltip.tsx +55 -0
  168. package/src/components/tooltip/context.ts +4 -0
  169. package/src/components/tooltip/index.ts +5 -0
  170. package/src/components/tooltip/types.ts +55 -0
  171. package/src/components/tooltip/useTooltip.tsx +89 -0
  172. package/src/components/tooltip/useTooltipContext.tsx +12 -0
  173. package/src/components/tooltip-content/TooltipContent.tsx +76 -0
  174. package/src/components/tooltip-content/index.ts +2 -0
  175. package/src/components/tooltip-content/styles.ts +84 -0
  176. package/src/components/tooltip-content/types.ts +14 -0
  177. package/src/components/tooltip-trigger/TooltipTrigger.tsx +42 -0
  178. package/src/components/tooltip-trigger/index.ts +2 -0
  179. package/src/components/tooltip-trigger/types.ts +9 -0
  180. package/src/index.ts +14 -0
  181. package/tsconfig.json +3 -0
  182. /package/{CONTRIBUTING.md → dist/CONTRIBUTING.md} +0 -0
  183. /package/{index.d.ts → dist/index.d.ts} +0 -0
  184. /package/{index.js → dist/index.js} +0 -0
  185. /package/{index.js.map → dist/index.js.map} +0 -0
@@ -0,0 +1,122 @@
1
+ import React, { forwardRef, RefObject } from 'react';
2
+ import classNames from 'classnames';
3
+
4
+ import { useLocalizedStringFormatter } from 'react-aria';
5
+ import intlMessages from './intl';
6
+
7
+ import {
8
+ mdiAlert,
9
+ mdiAlertCircle,
10
+ mdiCheckCircle,
11
+ mdiClose,
12
+ mdiInformation,
13
+ } from '@redsift/icons';
14
+ import {
15
+ ColorPalette,
16
+ Comp,
17
+ Icon,
18
+ Heading,
19
+ Flexbox,
20
+ Spinner,
21
+ isComponent,
22
+ ButtonColor,
23
+ IconButton,
24
+ } from '@redsift/design-system';
25
+ import { StyledToast } from './styles';
26
+ import { ToastProps, ToastVariant } from './types';
27
+
28
+ const COMPONENT_NAME = 'Toast';
29
+ const CLASSNAME = 'redsift-toast';
30
+ const DEFAULT_PROPS: Partial<ToastProps> = {
31
+ variant: 'info',
32
+ closeButton: true,
33
+ };
34
+
35
+ const getVariant = (variant: ToastVariant) => {
36
+ switch (variant) {
37
+ case ToastVariant.info:
38
+ default:
39
+ return <Icon icon={mdiInformation} color={ColorPalette.info} />;
40
+ case ToastVariant.error:
41
+ return <Icon icon={mdiAlertCircle} color={ColorPalette.error} />;
42
+ case ToastVariant.success:
43
+ return <Icon icon={mdiCheckCircle} color={ColorPalette.success} />;
44
+ case ToastVariant.warning:
45
+ return <Icon icon={mdiAlert} color={ColorPalette.warning} />;
46
+ case ToastVariant.loading:
47
+ return <Spinner size="small" />;
48
+ }
49
+ };
50
+
51
+ /**
52
+ * The Toast component.
53
+ */
54
+ export const Toast: Comp<
55
+ ToastProps & { closeToast?: () => void },
56
+ HTMLDivElement
57
+ > = forwardRef((props, ref) => {
58
+ const {
59
+ children,
60
+ className,
61
+ closeToast,
62
+ closeButton,
63
+ title,
64
+ variant,
65
+ ...forwardedProps
66
+ } = props;
67
+
68
+ const stringFormatter = useLocalizedStringFormatter(intlMessages);
69
+
70
+ const icon = getVariant(variant!);
71
+
72
+ return (
73
+ <StyledToast
74
+ {...forwardedProps}
75
+ className={classNames(Toast.className, className)}
76
+ ref={ref as RefObject<HTMLDivElement>}
77
+ $hasTitle={Boolean(title)}
78
+ $variant={variant}
79
+ >
80
+ <Flexbox
81
+ className={`${Toast.className}__header`}
82
+ justifyContent="space-between"
83
+ >
84
+ <Flexbox justifyContent="space-between" flexDirection="column" gap="0">
85
+ <Flexbox
86
+ className={`${Toast.className}-header__title`}
87
+ gap="14px"
88
+ alignItems="flex-start"
89
+ >
90
+ {icon}
91
+ {title ? <Heading as="h5">{title}</Heading> : null}
92
+ </Flexbox>
93
+
94
+ {children ? (
95
+ <div className={`${Toast.className}__content`}>{children}</div>
96
+ ) : null}
97
+ </Flexbox>
98
+
99
+ {closeButton === true ? (
100
+ <IconButton
101
+ aria-label={stringFormatter.format('close')}
102
+ className={`${Toast.className}-header__icon-button`}
103
+ icon={mdiClose}
104
+ onClick={closeToast}
105
+ />
106
+ ) : isComponent('Button')(closeButton) ||
107
+ isComponent('IconButton')(closeButton) ? (
108
+ React.cloneElement(closeButton, {
109
+ color: variant === 'loading' ? 'default' : (variant as ButtonColor),
110
+ onClick: () => {
111
+ closeButton.props.onClick?.();
112
+ closeToast?.();
113
+ },
114
+ })
115
+ ) : null}
116
+ </Flexbox>
117
+ </StyledToast>
118
+ );
119
+ });
120
+ Toast.className = CLASSNAME;
121
+ Toast.defaultProps = DEFAULT_PROPS;
122
+ Toast.displayName = COMPONENT_NAME;
@@ -0,0 +1,2 @@
1
+ export * from './types';
2
+ export * from './Toast';
@@ -0,0 +1,3 @@
1
+ {
2
+ "close": "Close"
3
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "close": "Fermer"
3
+ }
@@ -0,0 +1,7 @@
1
+ import enUS from './en-US.json';
2
+ import frFR from './fr-FR.json';
3
+
4
+ export default {
5
+ 'en-US': enUS,
6
+ 'fr-FR': frFR,
7
+ };
@@ -0,0 +1,43 @@
1
+ import styled, { css } from 'styled-components';
2
+ import { baseStyling } from '@redsift/design-system';
3
+ import { StyledToastProps } from './types';
4
+
5
+ /**
6
+ * Component style.
7
+ */
8
+ export const StyledToast = styled.div<StyledToastProps>`
9
+ ${baseStyling}
10
+
11
+ padding: 16px;
12
+ box-shadow: 0px 2px 4px -1px rgb(0 0 0 / 20%), 0px 4px 5px rgb(0 0 0 / 14%),
13
+ 0px 1px 10px rgb(0 0 0 / 12%);
14
+
15
+ ${({ $hasTitle, $variant }) => css`
16
+ background-color: ${$variant === 'loading'
17
+ ? 'var(--redsift-color-neutral-white)'
18
+ : `var(--redsift-color-${$variant}-hover)`};
19
+
20
+ .redsift-toast__header {
21
+ h5 {
22
+ line-height: 26px;
23
+ }
24
+ }
25
+
26
+ .redsift-toast-header__icon-button {
27
+ padding: 0px;
28
+ .redsift-icon {
29
+ color: var(--redsift-color-neutral-black);
30
+ }
31
+
32
+ &:hover,
33
+ &:focus-visible {
34
+ background-color: var(--redsift-color-${$variant}-active);
35
+ }
36
+ }
37
+
38
+ .redsift-toast__content {
39
+ margin-top: ${$hasTitle ? '8px' : '-24px'};
40
+ margin-left: 38px;
41
+ }
42
+ `}
43
+ `;
@@ -0,0 +1,44 @@
1
+ import { ComponentProps, ReactNode } from 'react';
2
+ import { ValueOf, SizingProps, SpacingProps } from '@redsift/design-system';
3
+
4
+ /**
5
+ * Component variant.
6
+ */
7
+ export const ToastVariant = {
8
+ success: 'success',
9
+ error: 'error',
10
+ warning: 'warning',
11
+ info: 'info',
12
+ loading: 'loading',
13
+ } as const;
14
+ export type ToastVariant = ValueOf<typeof ToastVariant>;
15
+
16
+ export const ToastPlacement = {
17
+ 'top-right': 'top-right',
18
+ 'top-center': 'top-center',
19
+ 'top-left': 'top-left',
20
+ 'bottom-right': 'bottom-right',
21
+ 'bottom-center': 'bottom-center',
22
+ 'bottom-left': 'bottom-left',
23
+ } as const;
24
+ export type ToastPlacement = ValueOf<typeof ToastPlacement>;
25
+
26
+ /**
27
+ * Component props.
28
+ */
29
+ export interface ToastProps
30
+ extends Omit<ComponentProps<'div'>, 'id' | 'style'>,
31
+ SpacingProps,
32
+ SizingProps {
33
+ /** Whether the component has a close button or not. */
34
+ closeButton?: boolean | ReactNode;
35
+ /** Title. */
36
+ title?: string;
37
+ /** Variant */
38
+ variant?: ToastVariant;
39
+ }
40
+
41
+ export type StyledToastProps = Omit<ToastProps, 'variant' | 'id'> & {
42
+ $hasTitle: boolean;
43
+ $variant: ToastProps['variant'];
44
+ };
@@ -0,0 +1,349 @@
1
+ import React from 'react';
2
+
3
+ import { ToastContainer, useToast } from '.';
4
+ import { Button, Flexbox } from '@redsift/design-system';
5
+
6
+ export default {
7
+ title: 'Popovers/Toast/ToastContainer',
8
+ component: ToastContainer,
9
+ };
10
+
11
+ export const Simple = () => {
12
+ const { notify } = useToast();
13
+
14
+ return (
15
+ <>
16
+ <Flexbox>
17
+ <Button
18
+ onClick={() =>
19
+ notify({
20
+ content: 'This is a success',
21
+ variant: 'success',
22
+ })
23
+ }
24
+ >
25
+ Success
26
+ </Button>
27
+ <Button
28
+ onClick={() =>
29
+ notify({
30
+ title: 'This is a warning',
31
+ content: 'Cupcake ipsum dolor sit amet.',
32
+ variant: 'warning',
33
+ })
34
+ }
35
+ >
36
+ Warning
37
+ </Button>
38
+ <Button
39
+ onClick={() =>
40
+ notify({
41
+ title: 'This is an error',
42
+ content:
43
+ 'Cupcake ipsum dolor sit amet. Cookie chocolate cake muffin chocolate bar powder cake chupa chups. Gummies chocolate cake cupcake chupa chups sesame snaps soufflé soufflé gingerbread blueie. Caramels chocolate bar soufflé sesame snaps tiramisu. Cookie muffin pie cake cupcake sweet.',
44
+ variant: 'error',
45
+ })
46
+ }
47
+ >
48
+ Error
49
+ </Button>
50
+ <Button
51
+ onClick={() =>
52
+ notify({
53
+ title: 'This is an info',
54
+ content:
55
+ 'Cupcake ipsum dolor sit amet. Cookie chocolate cake muffin chocolate bar powder cake chupa chups.',
56
+ variant: 'info',
57
+ })
58
+ }
59
+ >
60
+ Info
61
+ </Button>
62
+ </Flexbox>
63
+ <ToastContainer />
64
+ </>
65
+ );
66
+ };
67
+
68
+ export const AllVariants = () => {
69
+ const { notify, success, warning, error, info, loading } = useToast();
70
+
71
+ return (
72
+ <>
73
+ <Flexbox
74
+ flexDirection="row"
75
+ flexWrap="wrap"
76
+ justifyContent="center"
77
+ alignItems="flex-start"
78
+ marginTop="96px"
79
+ >
80
+ <Button
81
+ variant="secondary"
82
+ onClick={() =>
83
+ notify({
84
+ content: 'Default',
85
+ })
86
+ }
87
+ >
88
+ Default
89
+ </Button>
90
+ <Button
91
+ variant="secondary"
92
+ onClick={() =>
93
+ success({
94
+ content: 'Success',
95
+ })
96
+ }
97
+ >
98
+ Success
99
+ </Button>
100
+ <Button
101
+ variant="secondary"
102
+ onClick={() =>
103
+ warning({
104
+ content: 'Warning',
105
+ })
106
+ }
107
+ >
108
+ Warning
109
+ </Button>
110
+ <Button
111
+ variant="secondary"
112
+ onClick={() =>
113
+ error({
114
+ content: 'Error',
115
+ })
116
+ }
117
+ >
118
+ Error
119
+ </Button>
120
+ <Button
121
+ variant="secondary"
122
+ onClick={() =>
123
+ info({
124
+ content: 'Info',
125
+ })
126
+ }
127
+ >
128
+ Info
129
+ </Button>
130
+ <Button
131
+ variant="secondary"
132
+ onClick={() =>
133
+ loading({
134
+ content: 'Loading',
135
+ })
136
+ }
137
+ >
138
+ Loading
139
+ </Button>
140
+ </Flexbox>
141
+ <ToastContainer />
142
+ </>
143
+ );
144
+ };
145
+
146
+ export const AllPlacements = () => {
147
+ const { notify } = useToast();
148
+
149
+ return (
150
+ <>
151
+ <Flexbox
152
+ flexDirection="row"
153
+ flexWrap="wrap"
154
+ justifyContent="center"
155
+ alignItems="flex-start"
156
+ marginTop="96px"
157
+ >
158
+ <Button
159
+ variant="secondary"
160
+ onClick={() =>
161
+ notify({
162
+ content: 'Top-left',
163
+ placement: 'top-left',
164
+ })
165
+ }
166
+ >
167
+ Top-left
168
+ </Button>
169
+ <Button
170
+ variant="secondary"
171
+ onClick={() =>
172
+ notify({
173
+ content: 'Top-center',
174
+ placement: 'top-center',
175
+ })
176
+ }
177
+ >
178
+ Top-center
179
+ </Button>
180
+ <Button
181
+ variant="secondary"
182
+ onClick={() =>
183
+ notify({
184
+ content: 'Top-right',
185
+ placement: 'top-right',
186
+ })
187
+ }
188
+ >
189
+ Top-right
190
+ </Button>
191
+ <Button
192
+ variant="secondary"
193
+ onClick={() =>
194
+ notify({
195
+ content: 'Bottom-left',
196
+ placement: 'bottom-left',
197
+ })
198
+ }
199
+ >
200
+ Bottom-left
201
+ </Button>
202
+ <Button
203
+ variant="secondary"
204
+ onClick={() =>
205
+ notify({
206
+ content: 'Bottom-center',
207
+ placement: 'bottom-center',
208
+ })
209
+ }
210
+ >
211
+ Bottom-center
212
+ </Button>
213
+ <Button
214
+ variant="secondary"
215
+ onClick={() =>
216
+ notify({
217
+ content: 'Bottom-right',
218
+ placement: 'bottom-right',
219
+ })
220
+ }
221
+ >
222
+ Bottom-right
223
+ </Button>
224
+ </Flexbox>
225
+ <ToastContainer />
226
+ </>
227
+ );
228
+ };
229
+
230
+ export const Dismiss = () => {
231
+ const toastId = React.useRef<number | string | null>(null);
232
+ const { notify, dismiss } = useToast();
233
+
234
+ return (
235
+ <>
236
+ <Flexbox>
237
+ <Button
238
+ onClick={() => {
239
+ toastId.current = notify({
240
+ content: 'Saved!',
241
+ autoClose: false,
242
+ closeButton: false,
243
+ });
244
+ }}
245
+ >
246
+ Notify
247
+ </Button>
248
+ <Button
249
+ onClick={() => {
250
+ if (toastId.current) {
251
+ dismiss(toastId.current);
252
+ }
253
+ }}
254
+ >
255
+ Dismiss
256
+ </Button>
257
+ <Button
258
+ onClick={() => {
259
+ dismiss();
260
+ }}
261
+ >
262
+ Dismiss all
263
+ </Button>
264
+ </Flexbox>
265
+ <ToastContainer />
266
+ </>
267
+ );
268
+ };
269
+
270
+ export const Update = () => {
271
+ const toastId = React.useRef<number | string | null>(null);
272
+ const { notify, update } = useToast();
273
+
274
+ return (
275
+ <>
276
+ <Flexbox>
277
+ <Button
278
+ onClick={() => {
279
+ toastId.current = notify({
280
+ content: 'Saving...',
281
+ variant: 'loading',
282
+ autoClose: false,
283
+ closeButton: false,
284
+ });
285
+ }}
286
+ >
287
+ Notify
288
+ </Button>
289
+ <Button
290
+ onClick={() => {
291
+ if (toastId.current) {
292
+ update(toastId.current, {
293
+ content: 'Saved!',
294
+ autoClose: 5000,
295
+ });
296
+ }
297
+ }}
298
+ >
299
+ Update
300
+ </Button>
301
+ </Flexbox>
302
+ <ToastContainer />
303
+ </>
304
+ );
305
+ };
306
+
307
+ export const WithPromise = () => {
308
+ const { promise } = useToast();
309
+
310
+ return (
311
+ <>
312
+ <Flexbox>
313
+ <Button
314
+ variant="secondary"
315
+ color="success"
316
+ onClick={() => {
317
+ const resolveAfter3Sec = new Promise((resolve) =>
318
+ setTimeout(resolve, 3000)
319
+ );
320
+ promise(resolveAfter3Sec, {
321
+ pending: { content: 'Promise is pending' },
322
+ success: { content: 'Promise resolved!' },
323
+ error: { content: 'Promise rejected!' },
324
+ });
325
+ }}
326
+ >
327
+ Successful promise
328
+ </Button>
329
+ <Button
330
+ variant="secondary"
331
+ color="error"
332
+ onClick={() => {
333
+ const failAfter3Sec = new Promise((_, reject) =>
334
+ setTimeout(reject, 3000)
335
+ );
336
+ promise(failAfter3Sec, {
337
+ pending: { content: 'Promise is pending' },
338
+ success: { content: 'Promise resolved!' },
339
+ error: { content: 'Promise rejected!' },
340
+ });
341
+ }}
342
+ >
343
+ Failing promise
344
+ </Button>
345
+ </Flexbox>
346
+ <ToastContainer />
347
+ </>
348
+ );
349
+ };
@@ -0,0 +1,44 @@
1
+ import React, { forwardRef, RefObject } from 'react';
2
+ import { Slide } from 'react-toastify';
3
+
4
+ import { Comp } from '@redsift/design-system';
5
+ import { ReactToastify, StyledToastContainer } from './styles';
6
+ import { ToastContainerProps } from './types';
7
+
8
+ const COMPONENT_NAME = 'ToastContainer';
9
+ const CLASSNAME = 'redsift-toast-container';
10
+ const DEFAULT_PROPS: Partial<ToastContainerProps> = {
11
+ autoClose: 5000,
12
+ closeOnClick: false,
13
+ draggable: true,
14
+ pauseOnFocusLoss: true,
15
+ pauseOnHover: true,
16
+ placement: 'top-right',
17
+ };
18
+
19
+ /**
20
+ * The ToastContainer component.
21
+ */
22
+ export const ToastContainer: Comp<ToastContainerProps, HTMLDivElement> =
23
+ forwardRef((props, ref) => {
24
+ const { placement, ...forwardedProps } = props;
25
+
26
+ return (
27
+ <ReactToastify>
28
+ <StyledToastContainer
29
+ {...forwardedProps}
30
+ className={ToastContainer.className}
31
+ closeButton={false}
32
+ icon={false}
33
+ newestOnTop={placement!.includes('bottom')}
34
+ position={placement}
35
+ ref={ref as RefObject<HTMLDivElement>}
36
+ theme="colored"
37
+ transition={Slide}
38
+ />
39
+ </ReactToastify>
40
+ );
41
+ });
42
+ ToastContainer.className = CLASSNAME;
43
+ ToastContainer.defaultProps = DEFAULT_PROPS;
44
+ ToastContainer.displayName = COMPONENT_NAME;
@@ -0,0 +1,3 @@
1
+ export * from './types';
2
+ export * from './ToastContainer';
3
+ export * from './useToast';