@spaced-out/ui-design-system 0.0.1-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (259) hide show
  1. package/.commitlintrc.json +3 -0
  2. package/.cspell/custom-words.txt +22 -0
  3. package/.editorconfig +9 -0
  4. package/.eslintignore +1 -0
  5. package/.eslintrc.yml +122 -0
  6. package/.flowconfig +45 -0
  7. package/.github/workflows/pages.yml +52 -0
  8. package/.prettierrc +11 -0
  9. package/.storybook/SenseTheme.js +12 -0
  10. package/.storybook/main.js +73 -0
  11. package/.storybook/manager-head.html +41 -0
  12. package/.storybook/manager.js +14 -0
  13. package/.storybook/preview-head.html +130 -0
  14. package/.storybook/preview.js +128 -0
  15. package/.storybook/public/favicon.ico +0 -0
  16. package/.storybook/public/favicon.svg +6 -0
  17. package/.storybook/public/fonts/CentraNo2-Book.woff +0 -0
  18. package/.storybook/public/fonts/CentraNo2-Book.woff2 +0 -0
  19. package/.storybook/public/fonts/CentraNo2-BookItalic.woff +0 -0
  20. package/.storybook/public/fonts/CentraNo2-BookItalic.woff2 +0 -0
  21. package/.storybook/public/fonts/CentraNo2-Medium.woff +0 -0
  22. package/.storybook/public/fonts/CentraNo2-Medium.woff2 +0 -0
  23. package/.vscode/extensions.json +3 -0
  24. package/CHANGELOG.md +73 -0
  25. package/README.md +178 -0
  26. package/babel.config.js +24 -0
  27. package/config.js +58 -0
  28. package/cspell.json +26 -0
  29. package/design-tokens/border/app-border.json +41 -0
  30. package/design-tokens/border/base-border.json +41 -0
  31. package/design-tokens/color/app-color.json +226 -0
  32. package/design-tokens/color/base-color.json +265 -0
  33. package/design-tokens/elevation/app-elevation.json +22 -0
  34. package/design-tokens/elevation/base-elevation.json +19 -0
  35. package/design-tokens/font/base-font.json +98 -0
  36. package/design-tokens/index.js +5 -0
  37. package/design-tokens/motion/app.motion.json +24 -0
  38. package/design-tokens/motion/base-motion.json +40 -0
  39. package/design-tokens/opacity/base-opacity.json +49 -0
  40. package/design-tokens/shadow/base-shadow.json +86 -0
  41. package/design-tokens/size/base-size.json +94 -0
  42. package/design-tokens/space/app-space.json +40 -0
  43. package/design-tokens/space/base-space.json +40 -0
  44. package/flow-typed/npm/lodash_v4.x.x.js +6407 -0
  45. package/git-conventional-commits.json +43 -0
  46. package/gulpfile.js +48 -0
  47. package/jest.config.js +9 -0
  48. package/lib/assets/fontawesome/LICENSE.txt +18 -0
  49. package/lib/assets/fontawesome/css/all.min.css +27184 -0
  50. package/lib/assets/fontawesome/webfonts/fa-brands-400.ttf +0 -0
  51. package/lib/assets/fontawesome/webfonts/fa-brands-400.woff2 +0 -0
  52. package/lib/assets/fontawesome/webfonts/fa-duotone-900.ttf +0 -0
  53. package/lib/assets/fontawesome/webfonts/fa-duotone-900.woff2 +0 -0
  54. package/lib/assets/fontawesome/webfonts/fa-light-300.ttf +0 -0
  55. package/lib/assets/fontawesome/webfonts/fa-light-300.woff2 +0 -0
  56. package/lib/assets/fontawesome/webfonts/fa-regular-400.ttf +0 -0
  57. package/lib/assets/fontawesome/webfonts/fa-regular-400.woff2 +0 -0
  58. package/lib/assets/fontawesome/webfonts/fa-solid-900.ttf +0 -0
  59. package/lib/assets/fontawesome/webfonts/fa-solid-900.woff2 +0 -0
  60. package/lib/assets/fontawesome/webfonts/fa-thin-100.ttf +0 -0
  61. package/lib/assets/fontawesome/webfonts/fa-thin-100.woff2 +0 -0
  62. package/lib/assets/fontawesome/webfonts/fa-v4compatibility.ttf +0 -0
  63. package/lib/assets/fontawesome/webfonts/fa-v4compatibility.woff2 +0 -0
  64. package/lib/components/Button/Button.js +120 -0
  65. package/lib/components/Button/Button.js.flow +166 -0
  66. package/lib/components/Button/Button.module.css +226 -0
  67. package/lib/components/Button/index.js +24 -0
  68. package/lib/components/Button/index.js.flow +4 -0
  69. package/lib/components/ButtonDropdown/ButtonDropdown.js +89 -0
  70. package/lib/components/ButtonDropdown/ButtonDropdown.js.flow +119 -0
  71. package/lib/components/ButtonDropdown/ButtonDropdown.module.css +4 -0
  72. package/lib/components/ButtonDropdown/index.js +12 -0
  73. package/lib/components/ButtonDropdown/index.js.flow +4 -0
  74. package/lib/components/Checkbox/Checkbox.js +99 -0
  75. package/lib/components/Checkbox/Checkbox.js.flow +133 -0
  76. package/lib/components/Checkbox/Checkbox.module.css +160 -0
  77. package/lib/components/Checkbox/CheckboxGroup.js +85 -0
  78. package/lib/components/Checkbox/CheckboxGroup.js.flow +105 -0
  79. package/lib/components/Checkbox/CheckboxGroup.module.css +47 -0
  80. package/lib/components/Checkbox/index.js +19 -0
  81. package/lib/components/Checkbox/index.js.flow +3 -0
  82. package/lib/components/CircularLoader/CircularLoader.js +44 -0
  83. package/lib/components/CircularLoader/CircularLoader.js.flow +44 -0
  84. package/lib/components/CircularLoader/CircularLoader.module.css +81 -0
  85. package/lib/components/CircularLoader/index.js +12 -0
  86. package/lib/components/CircularLoader/index.js.flow +3 -0
  87. package/lib/components/CodeBlock.js +26 -0
  88. package/lib/components/CodeBlock.js.flow +19 -0
  89. package/lib/components/Dialog/Dialog.js +148 -0
  90. package/lib/components/Dialog/Dialog.js.flow +165 -0
  91. package/lib/components/Dialog/Dialog.module.css +87 -0
  92. package/lib/components/Dialog/index.js +36 -0
  93. package/lib/components/Dialog/index.js.flow +14 -0
  94. package/lib/components/Dropdown/Dropdown.js +108 -0
  95. package/lib/components/Dropdown/Dropdown.js.flow +129 -0
  96. package/lib/components/Dropdown/Dropdown.module.css +14 -0
  97. package/lib/components/Dropdown/index.js +18 -0
  98. package/lib/components/Dropdown/index.js.flow +4 -0
  99. package/lib/components/Grid/Grid.js +82 -0
  100. package/lib/components/Grid/Grid.js.flow +88 -0
  101. package/lib/components/Grid/Grid.module.css +30 -0
  102. package/lib/components/Grid/index.js +16 -0
  103. package/lib/components/Grid/index.js.flow +3 -0
  104. package/lib/components/Icon/ClickableIcon.js +51 -0
  105. package/lib/components/Icon/ClickableIcon.js.flow +51 -0
  106. package/lib/components/Icon/ClickableIcon.module.css +50 -0
  107. package/lib/components/Icon/FontAwesomeLibrary.js +3 -0
  108. package/lib/components/Icon/FontAwesomeLibrary.js.flow +3 -0
  109. package/lib/components/Icon/Icon.js +38 -0
  110. package/lib/components/Icon/Icon.js.flow +51 -0
  111. package/lib/components/Icon/index.js +25 -0
  112. package/lib/components/Icon/index.js.flow +6 -0
  113. package/lib/components/InContextAlert/InContextAlert.js +121 -0
  114. package/lib/components/InContextAlert/InContextAlert.js.flow +173 -0
  115. package/lib/components/InContextAlert/InContextAlert.module.css +54 -0
  116. package/lib/components/InContextAlert/index.js +18 -0
  117. package/lib/components/InContextAlert/index.js.flow +3 -0
  118. package/lib/components/Input/Input.js +172 -0
  119. package/lib/components/Input/Input.js.flow +246 -0
  120. package/lib/components/Input/Input.module.css +122 -0
  121. package/lib/components/Input/index.js +12 -0
  122. package/lib/components/Input/index.js.flow +4 -0
  123. package/lib/components/LinearLoader/LinearLoader.js +35 -0
  124. package/lib/components/LinearLoader/LinearLoader.js.flow +34 -0
  125. package/lib/components/LinearLoader/LinearLoader.module.css +43 -0
  126. package/lib/components/LinearLoader/index.js +12 -0
  127. package/lib/components/LinearLoader/index.js.flow +3 -0
  128. package/lib/components/Menu/Menu.js +76 -0
  129. package/lib/components/Menu/Menu.js.flow +85 -0
  130. package/lib/components/Menu/Menu.module.css +124 -0
  131. package/lib/components/Menu/index.js +12 -0
  132. package/lib/components/Menu/index.js.flow +4 -0
  133. package/lib/components/Modal/Modal.js +121 -0
  134. package/lib/components/Modal/Modal.js.flow +157 -0
  135. package/lib/components/Modal/Modal.module.css +62 -0
  136. package/lib/components/Modal/index.js +12 -0
  137. package/lib/components/Modal/index.js.flow +3 -0
  138. package/lib/components/Notification/Notification.js +89 -0
  139. package/lib/components/Notification/Notification.js.flow +136 -0
  140. package/lib/components/Notification/Notification.module.css +54 -0
  141. package/lib/components/Notification/index.js +18 -0
  142. package/lib/components/Notification/index.js.flow +3 -0
  143. package/lib/components/Panel/Panel.js +96 -0
  144. package/lib/components/Panel/Panel.js.flow +109 -0
  145. package/lib/components/Panel/Panel.module.css +77 -0
  146. package/lib/components/Panel/index.js +30 -0
  147. package/lib/components/Panel/index.js.flow +10 -0
  148. package/lib/components/RadioButton/RadioButton.js +76 -0
  149. package/lib/components/RadioButton/RadioButton.js.flow +102 -0
  150. package/lib/components/RadioButton/RadioButton.module.css +122 -0
  151. package/lib/components/RadioButton/RadioGroup.js +60 -0
  152. package/lib/components/RadioButton/RadioGroup.js.flow +85 -0
  153. package/lib/components/RadioButton/RadioGroup.module.css +47 -0
  154. package/lib/components/RadioButton/index.js +19 -0
  155. package/lib/components/RadioButton/index.js.flow +3 -0
  156. package/lib/components/SearchInput/SearchInput.js +47 -0
  157. package/lib/components/SearchInput/SearchInput.js.flow +73 -0
  158. package/lib/components/SearchInput/SearchInput.module.css +11 -0
  159. package/lib/components/SearchInput/index.js +12 -0
  160. package/lib/components/SearchInput/index.js.flow +4 -0
  161. package/lib/components/Text/Text.js +195 -0
  162. package/lib/components/Text/Text.js.flow +160 -0
  163. package/lib/components/Text/index.js +103 -0
  164. package/lib/components/Text/index.js.flow +21 -0
  165. package/lib/components/Textarea/Textarea.js +95 -0
  166. package/lib/components/Textarea/Textarea.js.flow +133 -0
  167. package/lib/components/Textarea/Textarea.module.css +110 -0
  168. package/lib/components/Textarea/index.js +12 -0
  169. package/lib/components/Textarea/index.js.flow +4 -0
  170. package/lib/components/Toast/Toast.js +187 -0
  171. package/lib/components/Toast/Toast.js.flow +210 -0
  172. package/lib/components/Toast/Toast.module.css +52 -0
  173. package/lib/components/Toast/ToastContainer.js +129 -0
  174. package/lib/components/Toast/ToastContainer.js.flow +125 -0
  175. package/lib/components/Toast/ToastContainer.module.css +41 -0
  176. package/lib/components/Toast/ToastManager.js +62 -0
  177. package/lib/components/Toast/ToastManager.js.flow +67 -0
  178. package/lib/components/Toast/index.js +56 -0
  179. package/lib/components/Toast/index.js.flow +12 -0
  180. package/lib/components/Toggle/Toggle.js +69 -0
  181. package/lib/components/Toggle/Toggle.js.flow +94 -0
  182. package/lib/components/Toggle/Toggle.module.css +144 -0
  183. package/lib/components/Toggle/index.js +12 -0
  184. package/lib/components/Toggle/index.js.flow +2 -0
  185. package/lib/components/Tooltip/Tooltip.js +81 -0
  186. package/lib/components/Tooltip/Tooltip.js.flow +110 -0
  187. package/lib/components/Tooltip/Tooltip.module.css +16 -0
  188. package/lib/components/Tooltip/index.js +12 -0
  189. package/lib/components/Tooltip/index.js.flow +4 -0
  190. package/lib/components/Truncate/Truncate.js +28 -0
  191. package/lib/components/Truncate/Truncate.js.flow +22 -0
  192. package/lib/components/Truncate/Truncate.module.css +6 -0
  193. package/lib/components/Truncate/index.js +12 -0
  194. package/lib/components/Truncate/index.js.flow +4 -0
  195. package/lib/components/Typeahead/Typeahead.js +124 -0
  196. package/lib/components/Typeahead/Typeahead.js.flow +153 -0
  197. package/lib/components/Typeahead/Typeahead.module.css +10 -0
  198. package/lib/components/Typeahead/index.js +12 -0
  199. package/lib/components/Typeahead/index.js.flow +4 -0
  200. package/lib/hooks/index.js +27 -0
  201. package/lib/hooks/index.js.flow +4 -0
  202. package/lib/hooks/useMountTransition.js +25 -0
  203. package/lib/hooks/useMountTransition.js.flow +27 -0
  204. package/lib/hooks/useToastPortal.js +32 -0
  205. package/lib/hooks/useToastPortal.js.flow +30 -0
  206. package/lib/styles/animation.module.css +9 -0
  207. package/lib/styles/border.module.css +27 -0
  208. package/lib/styles/shadow.module.css +42 -0
  209. package/lib/styles/typography.module.css +227 -0
  210. package/lib/styles/variables/_border.css +21 -0
  211. package/lib/styles/variables/_border.js +29 -0
  212. package/lib/styles/variables/_border.js.flow +23 -0
  213. package/lib/styles/variables/_color.css +131 -0
  214. package/lib/styles/variables/_color.js +139 -0
  215. package/lib/styles/variables/_color.js.flow +133 -0
  216. package/lib/styles/variables/_elevation.css +11 -0
  217. package/lib/styles/variables/_elevation.js +19 -0
  218. package/lib/styles/variables/_elevation.js.flow +13 -0
  219. package/lib/styles/variables/_font.css +51 -0
  220. package/lib/styles/variables/_font.js +59 -0
  221. package/lib/styles/variables/_font.js.flow +53 -0
  222. package/lib/styles/variables/_motion.css +11 -0
  223. package/lib/styles/variables/_motion.js +19 -0
  224. package/lib/styles/variables/_motion.js.flow +13 -0
  225. package/lib/styles/variables/_opacity.css +29 -0
  226. package/lib/styles/variables/_opacity.js +37 -0
  227. package/lib/styles/variables/_opacity.js.flow +31 -0
  228. package/lib/styles/variables/_shadow.css +47 -0
  229. package/lib/styles/variables/_shadow.js +55 -0
  230. package/lib/styles/variables/_shadow.js.flow +49 -0
  231. package/lib/styles/variables/_size.css +59 -0
  232. package/lib/styles/variables/_size.js +67 -0
  233. package/lib/styles/variables/_size.js.flow +61 -0
  234. package/lib/styles/variables/_space.css +23 -0
  235. package/lib/styles/variables/_space.js +31 -0
  236. package/lib/styles/variables/_space.js.flow +25 -0
  237. package/lib/types/common.js +1 -0
  238. package/lib/types/common.js.flow +3 -0
  239. package/lib/types/toast.js +24 -0
  240. package/lib/types/toast.js.flow +41 -0
  241. package/lib/types/typography.js +22 -0
  242. package/lib/types/typography.js.flow +18 -0
  243. package/lib/utils/classify.js +33 -0
  244. package/lib/utils/classify.js.flow +29 -0
  245. package/lib/utils/click-away.js +110 -0
  246. package/lib/utils/click-away.js.flow +134 -0
  247. package/lib/utils/dom.js +202 -0
  248. package/lib/utils/dom.js.flow +238 -0
  249. package/lib/utils/helpers.js +16 -0
  250. package/lib/utils/helpers.js.flow +11 -0
  251. package/lib/utils/makeClassNameComponent.js +58 -0
  252. package/lib/utils/makeClassNameComponent.js.flow +71 -0
  253. package/lib/utils/merge-refs.js +17 -0
  254. package/lib/utils/merge-refs.js.flow +14 -0
  255. package/lint-staged.config.js +5 -0
  256. package/package.json +114 -0
  257. package/postcss.config.js +3 -0
  258. package/pull_request_template.md +48 -0
  259. package/settings.json +3 -0
@@ -0,0 +1,210 @@
1
+ // @flow strict
2
+
3
+ import * as React from 'react';
4
+ import {
5
+ // $FlowFixMe[untyped-import]
6
+ FloatingFocusManager,
7
+ // $FlowFixMe[untyped-import]
8
+ useFloating,
9
+ } from '@floating-ui/react-dom-interactions';
10
+
11
+ import classify from '../../utils/classify';
12
+ import {CloseIcon, Icon} from '../Icon';
13
+ import {
14
+ BodyMedium,
15
+ SubTitleExtraSmall,
16
+ SubTitleSmall,
17
+ TEXT_COLORS,
18
+ } from '../Text';
19
+
20
+ import css from './Toast.module.css';
21
+
22
+
23
+ type ClassNames = $ReadOnly<{wrapper?: string}>;
24
+
25
+ export const TOAST_SEMANTIC = Object.freeze({
26
+ success: 'success',
27
+ information: 'information',
28
+ warning: 'warning',
29
+ danger: 'danger',
30
+ });
31
+
32
+ const TOAST_TITLE_COLOR = {
33
+ success: TEXT_COLORS.success,
34
+ information: TEXT_COLORS.information,
35
+ warning: TEXT_COLORS.warning,
36
+ danger: TEXT_COLORS.danger,
37
+ };
38
+
39
+ export type ToastSemanticType = $Values<typeof TOAST_SEMANTIC>;
40
+
41
+ export type ToastProps = {
42
+ classNames?: ClassNames,
43
+ children?: React.Node,
44
+ time?: string,
45
+ semantic?: ToastSemanticType,
46
+ onClose?: () => void,
47
+ initialFocus?: number,
48
+ };
49
+
50
+ const ToastIcon = ({semantic}: {semantic: ToastSemanticType}) => {
51
+ switch (semantic) {
52
+ case 'success':
53
+ return (
54
+ <Icon
55
+ name="circle-check"
56
+ size="medium"
57
+ color={TEXT_COLORS.success}
58
+ type="solid"
59
+ />
60
+ );
61
+
62
+ case TOAST_SEMANTIC.information:
63
+ return (
64
+ <Icon
65
+ name="circle-info"
66
+ size="medium"
67
+ color={TEXT_COLORS.information}
68
+ type="solid"
69
+ />
70
+ );
71
+
72
+ case TOAST_SEMANTIC.warning:
73
+ return (
74
+ <Icon
75
+ name="circle-exclamation"
76
+ size="medium"
77
+ color={TEXT_COLORS.warning}
78
+ type="solid"
79
+ />
80
+ );
81
+
82
+ case TOAST_SEMANTIC.danger:
83
+ return (
84
+ <Icon
85
+ name="shield-exclamation"
86
+ size="medium"
87
+ color={TEXT_COLORS.danger}
88
+ type="solid"
89
+ />
90
+ );
91
+
92
+ default:
93
+ return (
94
+ <Icon
95
+ color={TEXT_COLORS.neutral}
96
+ name="face-smile"
97
+ size="medium"
98
+ type="solid"
99
+ />
100
+ );
101
+ }
102
+ };
103
+
104
+ export type ToastTitleProps = {
105
+ children?: React.Node,
106
+ };
107
+
108
+ export const ToastTitle = ({children}: ToastTitleProps): React.Node => children;
109
+
110
+ export type ToastBodyProps = {
111
+ children?: React.Node,
112
+ };
113
+
114
+ export const ToastBody = ({children}: ToastBodyProps): React.Node => children;
115
+
116
+ export type ToastFooterProps = {
117
+ children?: React.Node,
118
+ onClose?: () => void,
119
+ };
120
+
121
+ export const ToastFooter = ({
122
+ children,
123
+ onClose,
124
+ }: ToastFooterProps): React.Node => {
125
+ const arrayChildren = React.Children.toArray(children);
126
+ const footerActions = React.Children.map(children, (child, index) => {
127
+ const isLast = index === arrayChildren.length - 1;
128
+ if (React.isValidElement(child)) {
129
+ const {onClick} = child.props;
130
+
131
+ const buttonClickHandler = (e) => {
132
+ onClose && onClose();
133
+ onClick && onClick(e);
134
+ };
135
+
136
+ if (child?.type?.name === 'Button' && isLast) {
137
+ return React.cloneElement(child, {
138
+ size: 'small',
139
+ type: 'primary',
140
+ ...child.props,
141
+ onClick: buttonClickHandler,
142
+ });
143
+ } else if (child?.type?.name === 'Button') {
144
+ return React.cloneElement(child, {
145
+ size: 'small',
146
+ type: 'tertiary',
147
+ ...child.props,
148
+ onClick: buttonClickHandler,
149
+ });
150
+ }
151
+ }
152
+ return child;
153
+ });
154
+
155
+ return React.Children.count(children) > 0 ? (
156
+ <div className={css.toastFooterActions}>{footerActions}</div>
157
+ ) : null;
158
+ };
159
+
160
+ export const Toast = ({
161
+ classNames,
162
+ children,
163
+ time,
164
+ semantic = TOAST_SEMANTIC.success,
165
+ onClose,
166
+ initialFocus = -1,
167
+ }: ToastProps): React.Node => {
168
+ const {floating, context} = useFloating();
169
+
170
+ const getComp = (comp: string) => {
171
+ if (children instanceof Array) {
172
+ const nodes: React.Node[] = [];
173
+ for (const child of children) {
174
+ if (child?.type?.name === comp) {
175
+ nodes.push(child);
176
+ }
177
+ }
178
+ return nodes.length > 1 ? nodes : nodes[0];
179
+ }
180
+ return null;
181
+ };
182
+
183
+ const footer = getComp('ToastFooter');
184
+ // $FlowFixMe
185
+ const footerWithClose = footer ? React.cloneElement(footer, {onClose}) : null;
186
+
187
+ return (
188
+ <FloatingFocusManager context={context} initialFocus={initialFocus}>
189
+ <div
190
+ className={classify(css.toastContainer, classNames?.wrapper)}
191
+ ref={floating}
192
+ >
193
+ <ToastIcon semantic={semantic} />
194
+ <div className={css.toastMidSection}>
195
+ <div className={css.contentWrap}>
196
+ <div className={css.titleBodyWrap}>
197
+ <SubTitleSmall color={TOAST_TITLE_COLOR[semantic]}>
198
+ {getComp('ToastTitle')}
199
+ </SubTitleSmall>
200
+ <BodyMedium>{getComp('ToastBody')}</BodyMedium>
201
+ </div>
202
+ {time && <SubTitleExtraSmall>{time}</SubTitleExtraSmall>}
203
+ </div>
204
+ {footerWithClose}
205
+ </div>
206
+ <CloseIcon onClick={onClose} />
207
+ </div>
208
+ </FloatingFocusManager>
209
+ );
210
+ };
@@ -0,0 +1,52 @@
1
+ @value (spaceNone,spaceXXSmall, spaceSmall, spaceMedium) from '../../styles/variables/_space.css';
2
+
3
+ @value (size24, size400) from '../../styles/variables/_size.css';
4
+
5
+ @value (colorBorderPrimary, colorBackgroundTertiary) from '../../styles/variables/_color.css';
6
+
7
+ @value (borderWidthPrimary, borderRadiusMedium) from '../../styles/variables/_border.css';
8
+
9
+ .toastContainer {
10
+ composes: boxShadow1 from '../../styles/shadow.module.css';
11
+ composes: borderPrimary from '../../styles/border.module.css';
12
+ display: flex;
13
+ flex-direction: row;
14
+ align-items: flex-start;
15
+ padding: spaceMedium;
16
+ gap: spaceSmall;
17
+ width: size400;
18
+ min-width: size400;
19
+ border-radius: borderRadiusMedium;
20
+ background: colorBackgroundTertiary;
21
+ }
22
+
23
+ .toastMidSection {
24
+ display: flex;
25
+ flex-direction: column;
26
+ align-items: flex-start;
27
+ padding: spaceNone;
28
+ gap: spaceMedium;
29
+ }
30
+
31
+ .contentWrap {
32
+ display: flex;
33
+ flex-direction: column;
34
+ align-items: flex-start;
35
+ padding-top: spaceXXSmall;
36
+ gap: spaceSmall;
37
+ }
38
+
39
+ .titleBodyWrap {
40
+ display: flex;
41
+ flex-direction: column;
42
+ align-items: flex-start;
43
+ padding: spaceNone;
44
+ gap: spaceXXSmall;
45
+ }
46
+
47
+ .toastFooterActions {
48
+ display: flex;
49
+ flex-direction: row;
50
+ align-items: flex-start;
51
+ gap: spaceSmall;
52
+ }
@@ -0,0 +1,129 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.ToastContainer = void 0;
7
+ var _react = _interopRequireWildcard(require("react"));
8
+ var _reactDom = require("react-dom");
9
+ var _hooks = require("../../hooks");
10
+ var _classify = require("../../utils/classify");
11
+ var _ = require("./");
12
+ var _ToastContainerModule = _interopRequireDefault(require("./ToastContainer.module.css"));
13
+ var _jsxRuntime = require("react/jsx-runtime");
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
16
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
17
+
18
+ // $FlowFixMe[untyped-import]
19
+
20
+ const ADD = 'ADD';
21
+ const REMOVE = 'REMOVE';
22
+ const reducer = (state, action) => {
23
+ const {
24
+ type,
25
+ data
26
+ } = action;
27
+ if (type === ADD) {
28
+ if ( /* $FlowIgnore */
29
+ state.filter(i => i.uniqueCode && i.uniqueCode === data.uniqueCode).length) {
30
+ return state;
31
+ }
32
+ return [...state, data];
33
+ } else if (type === REMOVE) {
34
+ return state.filter(i => i.id !== data.id);
35
+ }
36
+ return state;
37
+ };
38
+ const ToastContainer = () => {
39
+ const [data, dispatch] = (0, _react.useReducer)(reducer, []);
40
+ const toastRef = (0, _react.useRef)(null);
41
+ const {
42
+ loaded
43
+ } = (0, _hooks.useToastPortal)({
44
+ toastRef
45
+ });
46
+ const callback = (actionType, content, options) => {
47
+ if (actionType === ADD) {
48
+ dispatch({
49
+ type: ADD,
50
+ data: {
51
+ content,
52
+ ...options,
53
+ key: `${options.id}`
54
+ }
55
+ });
56
+ }
57
+ if (actionType === REMOVE) {
58
+ dispatch({
59
+ type: REMOVE,
60
+ data: {
61
+ id: options.id
62
+ }
63
+ });
64
+ }
65
+ if (options.autoClose) {
66
+ window.setTimeout(() => {
67
+ dispatch({
68
+ type: REMOVE,
69
+ data: {
70
+ id: options.id
71
+ }
72
+ });
73
+ }, options.timeout);
74
+ }
75
+ };
76
+ (0, _react.useEffect)(() => {
77
+ _.toastManager.subscribe(callback);
78
+ }, []);
79
+ const positionMaintainer = () => {
80
+ const mapper = {};
81
+ /* $FlowIgnore */
82
+ data.map(_ref => {
83
+ let {
84
+ position,
85
+ ...rest
86
+ } = _ref;
87
+ if (position) {
88
+ if (!mapper[position]) {
89
+ mapper[position] = [];
90
+ }
91
+ mapper[position].push(rest);
92
+ }
93
+ });
94
+ return mapper;
95
+ };
96
+ const markup = () => {
97
+ const mapper = positionMaintainer();
98
+ return Object.keys(mapper).map(position => {
99
+ const content = mapper[position].map(_ref2 => {
100
+ let {
101
+ content,
102
+ id
103
+ } = _ref2;
104
+ return (
105
+ /*#__PURE__*/
106
+ // $FlowFixMe
107
+ _react.default.cloneElement(content, {
108
+ key: id,
109
+ onClose: () => dispatch({
110
+ type: REMOVE,
111
+ data: {
112
+ id
113
+ }
114
+ })
115
+ })
116
+ );
117
+ });
118
+ return /*#__PURE__*/(0, _jsxRuntime.js)("div", {
119
+ className: (0, _classify.classify)(_ToastContainerModule.default.toastContainer, _ToastContainerModule.default[position]),
120
+ children: content
121
+ }, position.toString());
122
+ });
123
+ };
124
+ if (!toastRef.current) {
125
+ return null;
126
+ }
127
+ return loaded ? /*#__PURE__*/(0, _reactDom.createPortal)(markup(), toastRef.current) : null;
128
+ };
129
+ exports.ToastContainer = ToastContainer;
@@ -0,0 +1,125 @@
1
+ // @flow strict
2
+
3
+ import React, {useEffect, useReducer, useRef} from 'react';
4
+ // $FlowFixMe[untyped-import]
5
+ import {createPortal} from 'react-dom';
6
+ import type {actionTypes, contentTypes, optionTypes} from 'src/types/toast';
7
+
8
+ import {useToastPortal} from '../../hooks';
9
+ import {classify} from '../../utils/classify';
10
+
11
+ import {toastManager} from './';
12
+
13
+ import css from './ToastContainer.module.css';
14
+
15
+
16
+ const ADD = 'ADD';
17
+ const REMOVE = 'REMOVE';
18
+
19
+ type stateTypes = {
20
+ ...optionTypes,
21
+ content?: contentTypes,
22
+ };
23
+
24
+ type MapperValues = {
25
+ ...optionTypes,
26
+ content: contentTypes,
27
+ };
28
+
29
+ type Actions = {
30
+ type: actionTypes,
31
+ data: stateTypes,
32
+ };
33
+
34
+ const reducer = (state: stateTypes[], action: Actions) => {
35
+ const {type, data} = action;
36
+
37
+ if (type === ADD) {
38
+ if (
39
+ /* $FlowIgnore */
40
+ state.filter((i) => i.uniqueCode && i.uniqueCode === data.uniqueCode)
41
+ .length
42
+ ) {
43
+ return state;
44
+ }
45
+
46
+ return [...state, data];
47
+ } else if (type === REMOVE) {
48
+ return state.filter((i) => i.id !== data.id);
49
+ }
50
+ return state;
51
+ };
52
+
53
+ export const ToastContainer = (): null | React$Portal => {
54
+ const [data, dispatch] = useReducer(reducer, []);
55
+ const toastRef = useRef<HTMLDivElement | null>(null);
56
+
57
+ const {loaded} = useToastPortal({toastRef});
58
+
59
+ const callback = (
60
+ actionType: actionTypes,
61
+ content: contentTypes,
62
+ options: optionTypes,
63
+ ) => {
64
+ if (actionType === ADD) {
65
+ dispatch({type: ADD, data: {content, ...options, key: `${options.id}`}});
66
+ }
67
+ if (actionType === REMOVE) {
68
+ dispatch({type: REMOVE, data: {id: options.id}});
69
+ }
70
+
71
+ if (options.autoClose) {
72
+ window.setTimeout(() => {
73
+ dispatch({type: REMOVE, data: {id: options.id}});
74
+ }, options.timeout);
75
+ }
76
+ };
77
+
78
+ useEffect(() => {
79
+ toastManager.subscribe(callback);
80
+ }, []);
81
+
82
+ const positionMaintainer = () => {
83
+ const mapper = {};
84
+ /* $FlowIgnore */
85
+ data.map(({position, ...rest}: optionTypes) => {
86
+ if (position) {
87
+ if (!mapper[position]) {
88
+ mapper[position] = [];
89
+ }
90
+ mapper[position].push(rest);
91
+ }
92
+ });
93
+
94
+ return mapper;
95
+ };
96
+
97
+ const markup = () => {
98
+ const mapper = positionMaintainer();
99
+
100
+ return Object.keys(mapper).map((position) => {
101
+ const content = mapper[position].map(({content, id}: MapperValues) =>
102
+ // $FlowFixMe
103
+ React.cloneElement(content, {
104
+ key: id,
105
+ onClose: () => dispatch({type: REMOVE, data: {id}}),
106
+ }),
107
+ );
108
+
109
+ return (
110
+ <div
111
+ key={position.toString()}
112
+ className={classify(css.toastContainer, css[position])}
113
+ >
114
+ {content}
115
+ </div>
116
+ );
117
+ });
118
+ };
119
+
120
+ if (!toastRef.current) {
121
+ return null;
122
+ }
123
+
124
+ return loaded ? createPortal(markup(), toastRef.current) : null;
125
+ };
@@ -0,0 +1,41 @@
1
+ @value (
2
+ spaceSmall,
3
+ spaceMedium,
4
+ spaceHalfFluid,
5
+ spaceNegHalfFluid
6
+ ) from '../../styles/variables/_space.css';
7
+
8
+ .toastContainer {
9
+ position: fixed;
10
+ background: transparent;
11
+ display: flex;
12
+ flex-direction: column;
13
+ gap: spaceSmall;
14
+ }
15
+ .toastContainer.topCenter {
16
+ top: spaceMedium;
17
+ left: spaceHalfFluid;
18
+ transform: translateX(spaceNegHalfFluid);
19
+ }
20
+ .toastContainer.topLeft {
21
+ top: spaceMedium;
22
+ left: spaceMedium;
23
+ }
24
+ .toastContainer.topRight {
25
+ top: spaceMedium;
26
+ right: spaceMedium;
27
+ }
28
+ .toastContainer.bottomCenter {
29
+ bottom: spaceMedium;
30
+ left: spaceHalfFluid;
31
+ transform: translateX(spaceNegHalfFluid);
32
+ }
33
+
34
+ .toastContainer.bottomLeft {
35
+ bottom: spaceMedium;
36
+ left: spaceMedium;
37
+ }
38
+ .toastContainer.bottomRight {
39
+ bottom: spaceMedium;
40
+ right: spaceMedium;
41
+ }
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.toastManager = exports.toastApi = exports.POSITIONS = exports.ACTIONS = void 0;
7
+ var _helpers = require("../../utils/helpers");
8
+
9
+ const DEFAULT_AUTOCLOSE_TIME = 8000; // default auto close time for with autoClose = true (be default true) but timeout not passed.
10
+
11
+ const POSITIONS = {
12
+ TOP_CENTER: 'topCenter',
13
+ TOP_LEFT: 'topLeft',
14
+ TOP_RIGHT: 'topRight',
15
+ BOTTOM_LEFT: 'bottomLeft',
16
+ BOTTOM_RIGHT: 'bottomRight',
17
+ BOTTOM_CENTER: 'bottomCenter'
18
+ };
19
+ exports.POSITIONS = POSITIONS;
20
+ const ACTIONS = {
21
+ ADD: 'ADD',
22
+ REMOVE: 'REMOVE'
23
+ };
24
+ exports.ACTIONS = ACTIONS;
25
+ const defaultOptions = {
26
+ autoClose: true,
27
+ timeout: DEFAULT_AUTOCLOSE_TIME,
28
+ position: POSITIONS.BOTTOM_LEFT
29
+ };
30
+ const toastManager = (() => {
31
+ let callbackFn;
32
+ const manager = {
33
+ subscribe(callback) {
34
+ callbackFn = callback;
35
+ },
36
+ add(content, options) {
37
+ const mergedOptions = {
38
+ ...defaultOptions,
39
+ ...options
40
+ };
41
+ const toastId = (0, _helpers.uuid)();
42
+ callbackFn && callbackFn(ACTIONS.ADD, content, {
43
+ ...mergedOptions,
44
+ id: toastId
45
+ });
46
+ return toastId;
47
+ },
48
+ remove(id) {
49
+ callbackFn(ACTIONS.REMOVE, null, {
50
+ id
51
+ });
52
+ return true;
53
+ }
54
+ };
55
+ return manager;
56
+ })();
57
+ exports.toastManager = toastManager;
58
+ const toastApi = {
59
+ show: (content, options) => toastManager.add(content, options),
60
+ remove: id => toastManager.remove(id)
61
+ };
62
+ exports.toastApi = toastApi;
@@ -0,0 +1,67 @@
1
+ // @flow strict
2
+
3
+ import type {
4
+ callbackFuncTypes,
5
+ contentTypes,
6
+ ToastOptions,
7
+ } from '../../types/toast';
8
+ import {uuid} from '../../utils/helpers';
9
+
10
+
11
+ const DEFAULT_AUTOCLOSE_TIME = 8000; // default auto close time for with autoClose = true (be default true) but timeout not passed.
12
+
13
+ export const POSITIONS = {
14
+ TOP_CENTER: 'topCenter',
15
+ TOP_LEFT: 'topLeft',
16
+ TOP_RIGHT: 'topRight',
17
+ BOTTOM_LEFT: 'bottomLeft',
18
+ BOTTOM_RIGHT: 'bottomRight',
19
+ BOTTOM_CENTER: 'bottomCenter',
20
+ };
21
+
22
+ export const ACTIONS = {
23
+ ADD: 'ADD',
24
+ REMOVE: 'REMOVE',
25
+ };
26
+
27
+ const defaultOptions: ToastOptions = {
28
+ autoClose: true,
29
+ timeout: DEFAULT_AUTOCLOSE_TIME,
30
+ position: POSITIONS.BOTTOM_LEFT,
31
+ };
32
+
33
+ export const toastManager: {
34
+ add(content: contentTypes, options?: ToastOptions): string,
35
+ remove(id: string): boolean,
36
+ subscribe(callback: callbackFuncTypes): void,
37
+ ...
38
+ } = (() => {
39
+ let callbackFn: callbackFuncTypes;
40
+
41
+ const manager = {
42
+ subscribe(callback: callbackFuncTypes): void {
43
+ callbackFn = callback;
44
+ },
45
+
46
+ add(content: contentTypes, options?: ToastOptions): string {
47
+ const mergedOptions = {...defaultOptions, ...options};
48
+ const toastId = uuid();
49
+ callbackFn &&
50
+ callbackFn(ACTIONS.ADD, content, {...mergedOptions, id: toastId});
51
+ return toastId;
52
+ },
53
+
54
+ remove(id: string) {
55
+ callbackFn(ACTIONS.REMOVE, null, {id});
56
+ return true;
57
+ },
58
+ };
59
+
60
+ return manager;
61
+ })();
62
+
63
+ export const toastApi = {
64
+ show: (content: contentTypes, options?: ToastOptions): string =>
65
+ toastManager.add(content, options),
66
+ remove: (id: string): boolean => toastManager.remove(id),
67
+ };