@thecb/components 9.2.0-beta.0 → 9.2.0-beta.10

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thecb/components",
3
- "version": "9.2.0-beta.0",
3
+ "version": "9.2.0-beta.10",
4
4
  "description": "Common lib for CityBase react components",
5
5
  "main": "dist/index.cjs.js",
6
6
  "typings": "dist/index.d.ts",
@@ -4,3 +4,4 @@ export * from "./editable-table";
4
4
  export * from "./footer-with-subfooter";
5
5
  export * from "./popover";
6
6
  export * from "./radio-group";
7
+ export * from "./toast-notification";
@@ -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";
@@ -1,46 +1,33 @@
1
1
  import React from "react";
2
-
3
- // import CloseIcon from "../CloseIcon";
4
- // import ErrorIcon from "../ErrorMessage/ErrorIcon";
5
- // import SuccessIcon from "../SuccessMessage/SuccessIcon";
6
- // import { SEMI_BOLD } from "@/constants/fonts";
7
- // import { CloseIconWrapper } from "./ToastNotification.styled";
8
2
  import { Box, Cluster } from "../../atoms/layouts";
9
3
  import { Paragraph } from "../../atoms";
10
4
  import {
11
5
  SuccessfulIconMedium,
12
6
  ErroredIcon,
13
- IconQuitLarge,
14
- SuccessfulIconSmall,
7
+ IconQuitLarge
15
8
  } from "../../atoms/icons";
16
- import { ERROR_COLOR, HINT_GREEN } from "../../../constants/colors";
9
+ import {
10
+ ERROR_BACKGROUND_COLOR,
11
+ HINT_GREEN,
12
+ WHITE
13
+ } from "../../../constants/colors";
17
14
  import { FONT_WEIGHT_SEMIBOLD } from "../../../constants/style_constants";
18
- import styled from "styled-components";
19
-
20
- export const CloseIconWrapper = styled.div`
21
- min-height: 24px;
22
- min-width: 24px;
23
- display: flex;
24
- margin: 16px;
25
- justify-content: center;
26
- align-items: center;
27
- cursor: pointer;
28
- `;
29
15
 
30
16
  const VARIANTS = {
31
17
  SUCCESS: "success",
32
- ERROR: "error",
18
+ ERROR: "error"
33
19
  };
34
20
 
35
21
  const ToastNotification = ({
22
+ variant = VARIANTS.SUCCESS,
36
23
  message = "",
24
+ toastOpen,
25
+ closeToastNotification,
37
26
  extraStyles,
38
27
  minWidth = "112px",
39
28
  maxWidth = "350px",
40
29
  height = "56px",
41
- closeToastNotification,
42
- toastOpen,
43
- variant = VARIANTS.SUCCESS,
30
+ childGap = "1rem",
44
31
  backgroundColor
45
32
  }) => (
46
33
  <Box
@@ -51,14 +38,14 @@ const ToastNotification = ({
51
38
  : variant === VARIANTS.SUCCESS
52
39
  ? HINT_GREEN
53
40
  : variant === "error"
54
- ? ERROR_COLOR
41
+ ? ERROR_BACKGROUND_COLOR
55
42
  : WHITE
56
43
  }
57
44
  minWidth={minWidth}
58
45
  minHeight={height && parseInt(height) < 100 ? height : "100px"}
59
46
  height={height ? height : "auto"}
60
47
  tabIndex={toastOpen ? "-1" : "0"}
61
- padding="0"
48
+ padding="0rem 1rem"
62
49
  borderRadius="4px"
63
50
  boxShadow="0px 4px 4px rgba(41, 42, 51, 0.15),
64
51
  0px 1px 7px rgba(41, 42, 51, 0.2),
@@ -67,10 +54,11 @@ const ToastNotification = ({
67
54
  display: ${toastOpen ? "block" : "none"};
68
55
  position: fixed; bottom: 4rem; left: 4rem;
69
56
  ${extraStyles};
57
+ cursor: pointer;
70
58
  `}
71
59
  >
72
- <Cluster align="center" childGap="0">
73
- {variant === "success" && <SuccessfulIconSmall />}
60
+ <Cluster align="center" childGap={childGap}>
61
+ {variant === "success" && <SuccessfulIconMedium />}
74
62
  {variant === "error" && <ErroredIcon />}
75
63
  <Box padding="1rem 0" maxWidth={maxWidth}>
76
64
  <Paragraph
@@ -80,9 +68,7 @@ const ToastNotification = ({
80
68
  {message}
81
69
  </Paragraph>
82
70
  </Box>
83
- <CloseIconWrapper>
84
- <IconQuitLarge />
85
- </CloseIconWrapper>
71
+ <IconQuitLarge />
86
72
  </Cluster>
87
73
  </Box>
88
74
  );
@@ -1,28 +1,59 @@
1
- import React, { useState } from "react";
1
+ import React, { useEffect } from "react";
2
2
  import ToastNotification from "./ToastNotification";
3
3
  import page from "../../../../.storybook/page";
4
+ import { useToastNotification } from "../../../util";
5
+ import { ToastVariants } from "../../../types/common";
4
6
 
5
7
  export const toastNotificationSuccess = () => {
6
- const [toastOpen, setToastOpen] = useState(true);
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
+
7
23
  return (
8
24
  <ToastNotification
9
- toastOpen={toastOpen}
10
- closeToastNotification={() => setToastOpen(false)}
11
- message="Successful"
12
- variant="success"
25
+ variant={toastVariant}
26
+ message={toastMessage}
27
+ toastOpen={isToastOpen}
28
+ closeToastNotification={() => hideToast()}
13
29
  />
14
30
  );
15
31
  };
32
+
16
33
  toastNotificationSuccess.storyName = "Success Toast";
17
34
 
18
35
  export const toastNotificationError = () => {
19
- const [toastOpen, setToastOpen] = useState(true);
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
+
20
51
  return (
21
52
  <ToastNotification
22
- toastOpen={toastOpen}
23
- closeToastNotification={() => setToastOpen(false)}
24
- message="Errored"
25
- variant="error"
53
+ variant={toastVariant}
54
+ message={toastMessage}
55
+ toastOpen={isToastOpen}
56
+ closeToastNotification={() => hideToast()}
26
57
  />
27
58
  );
28
59
  };
@@ -30,7 +61,7 @@ toastNotificationError.storyName = "Error Toast";
30
61
 
31
62
  const story = page({
32
63
  title: "Components|Molecules/ToastNotification",
33
- Component: ToastNotification
64
+ Component: ToastNotification,
34
65
  });
35
66
 
36
67
  export default story;
@@ -1 +1,18 @@
1
- // TODO - add types
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>>;
@@ -97,6 +97,7 @@ export const COSMOS_RED: Color;
97
97
  export const BLUSH_RED: Color;
98
98
 
99
99
  export const ERROR_COLOR: Color;
100
+ export const ERROR_BACKGROUND_COLOR: Color;
100
101
 
101
102
  export const ALERT_COLORS: {
102
103
  warn: ColorSet;
@@ -90,6 +90,7 @@ const BLUSH_RED = "#FFF0F5";
90
90
 
91
91
  // Second level color constants
92
92
  const ERROR_COLOR = RAZZMATAZZ_RED;
93
+ const ERROR_BACKGROUND_COLOR = "#FFF4F8";
93
94
 
94
95
  // These colors are sequestered so that the alert component can reference them // by type of alert
95
96
  const ALERT_COLORS = {
@@ -221,5 +222,6 @@ export {
221
222
  RASPBERRY,
222
223
  ALERT_COLORS,
223
224
  PILL_COLORS,
224
- ERROR_COLOR
225
+ ERROR_COLOR,
226
+ ERROR_BACKGROUND_COLOR
225
227
  };
package/src/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import * as constants from "./constants";
2
+ import * as hooks from "./util/hooks";
2
3
  export * from "./components";
3
4
  export * from "./types/common";
4
- export { constants };
5
+ export { constants, hooks };
@@ -0,0 +1,6 @@
1
+ enum ToastVariants {
2
+ ERROR = "error",
3
+ SUCCESS = "success",
4
+ }
5
+
6
+ export default ToastVariants;
@@ -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";
@@ -0,0 +1 @@
1
+ export { default as useToastNotification } from "./use-toast-notification";
@@ -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: "" | ToastVariants;
10
+ toastMessage: string;
11
+ showToast: ({
12
+ message,
13
+ variant,
14
+ }: {
15
+ message: string;
16
+ variant: 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/util/index.js CHANGED
@@ -3,5 +3,13 @@ import * as general from "./general";
3
3
  import * as theme from "./themeUtils";
4
4
  import useFocusInvalidInput from "./focusFirstInvalidInputHook";
5
5
  import useOutsideClick from "./useOutsideClick";
6
+ import useToastNotification from "./hooks/use-toast-notification";
6
7
 
7
- export { formats, general, theme, useFocusInvalidInput, useOutsideClick };
8
+ export {
9
+ formats,
10
+ general,
11
+ theme,
12
+ useFocusInvalidInput,
13
+ useOutsideClick,
14
+ useToastNotification
15
+ };