@unitedstatespowersquadrons/components 1.2.23 → 1.2.25-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 (99) hide show
  1. package/ActionButton.tsx +21 -0
  2. package/Colors.tsx +3 -0
  3. package/Flags/Officer.tsx +7 -2
  4. package/Flags/Signal.tsx +7 -2
  5. package/Flags/Signals.tsx +7 -2
  6. package/FontAwesomeIcon.tsx +6 -0
  7. package/IconButton.tsx +17 -0
  8. package/RailsForm.tsx +7 -2
  9. package/Readme.md +19 -2
  10. package/Reducer/buildReducer.tsx +7 -0
  11. package/Reducer/buildUnreducibleState.tsx +5 -0
  12. package/SelectionIconButton.tsx +7 -2
  13. package/StripedTable/Body.tsx +7 -2
  14. package/StripedTable/Foot.tsx +7 -2
  15. package/StripedTable/Head.tsx +7 -2
  16. package/StripedTable/Table.tsx +7 -2
  17. package/StripedTable/TableStyles.ts +3 -0
  18. package/Styles.tsx +8 -0
  19. package/Toasts/Readme.md +3 -40
  20. package/Toasts/Toast.tsx +11 -3
  21. package/Toasts/Toasts.tsx +8 -3
  22. package/Toasts/toastHelpers.ts +17 -0
  23. package/docs/.nojekyll +1 -0
  24. package/docs/assets/hierarchy.js +1 -0
  25. package/docs/assets/highlight.css +99 -0
  26. package/docs/assets/icons.js +18 -0
  27. package/docs/assets/icons.svg +1 -0
  28. package/docs/assets/main.js +60 -0
  29. package/docs/assets/navigation.js +1 -0
  30. package/docs/assets/search.js +1 -0
  31. package/docs/assets/style.css +1633 -0
  32. package/docs/enums/Toast_Status.html +4 -0
  33. package/docs/functions/ActionButton.html +3 -0
  34. package/docs/functions/FontAwesomeIcon.html +3 -0
  35. package/docs/functions/IconButton.html +3 -0
  36. package/docs/functions/OfficerFlag.html +2 -0
  37. package/docs/functions/RailsForm.html +2 -0
  38. package/docs/functions/SelectionIconButton.html +2 -0
  39. package/docs/functions/SignalFlag.html +2 -0
  40. package/docs/functions/SignalFlags.html +2 -0
  41. package/docs/functions/StripedBody.html +2 -0
  42. package/docs/functions/StripedHead.html +2 -0
  43. package/docs/functions/StripedTable.html +2 -0
  44. package/docs/functions/Toasts.html +2 -0
  45. package/docs/functions/addToast.html +2 -0
  46. package/docs/functions/buildReducer.html +4 -0
  47. package/docs/functions/buildUnreducibleState.html +2 -0
  48. package/docs/functions/createDismissToast.html +3 -0
  49. package/docs/functions/getCsrfTokenHeader.html +1 -0
  50. package/docs/functions/handleToasts.html +2 -0
  51. package/docs/functions/mount.html +2 -0
  52. package/docs/functions/railsFetchJson.html +2 -0
  53. package/docs/functions/removeToast.html +2 -0
  54. package/docs/functions/removeToastById.html +3 -0
  55. package/docs/functions/wrapDispatch.html +1 -0
  56. package/docs/hierarchy.html +1 -0
  57. package/docs/index.html +33 -0
  58. package/docs/interfaces/ActionButtonFormProps.html +18 -0
  59. package/docs/interfaces/ActionButtonHrefProps.html +20 -0
  60. package/docs/interfaces/ActionButtonMethodProps.html +21 -0
  61. package/docs/interfaces/ActionButtonOnClickProps.html +18 -0
  62. package/docs/interfaces/AppStateWithToasts.html +3 -0
  63. package/docs/interfaces/CoreActionButtonProps.html +15 -0
  64. package/docs/interfaces/FontAwesomeProps.html +7 -0
  65. package/docs/interfaces/GenericAppAction.html +2 -0
  66. package/docs/interfaces/IconButtonHrefProps.html +13 -0
  67. package/docs/interfaces/IconButtonMethodProps.html +15 -0
  68. package/docs/interfaces/IconButtonOnClickProps.html +12 -0
  69. package/docs/interfaces/RailsResponse.html +4 -0
  70. package/docs/interfaces/Toast.html +7 -0
  71. package/docs/interfaces/ToastProps.html +8 -0
  72. package/docs/media/Readme.md +73 -0
  73. package/docs/modules.html +1 -0
  74. package/docs/types/ActionButtonProps.html +1 -0
  75. package/docs/types/AppActionType.html +1 -0
  76. package/docs/types/ButtonColorName.html +1 -0
  77. package/docs/types/CableAction.html +3 -0
  78. package/docs/types/DismissFunc.html +1 -0
  79. package/docs/types/DispatchFunc.html +1 -0
  80. package/docs/types/DispatchHandler.html +1 -0
  81. package/docs/types/IconButtonProps.html +1 -0
  82. package/docs/types/OnClickHandler.html +1 -0
  83. package/docs/types/OnClickOrKeyboardHandler.html +1 -0
  84. package/docs/types/OnInputChangeHandler.html +1 -0
  85. package/docs/types/OnMouseMoveHandler.html +1 -0
  86. package/docs/types/RailsAppAction.html +1 -0
  87. package/docs/types/ReducerHandler.html +1 -0
  88. package/docs/types/ToastAppAction.html +1 -0
  89. package/docs/types/ToastRemoveAppAction.html +1 -0
  90. package/docs/variables/Colors.html +2 -0
  91. package/docs/variables/Flags.html +4 -0
  92. package/docs/variables/Striped.html +4 -0
  93. package/docs/variables/Styles.html +2 -0
  94. package/eslint.config.mjs +1 -0
  95. package/mount.tsx +3 -0
  96. package/package.json +2 -1
  97. package/railsFetchJson.tsx +4 -1
  98. package/typedoc.json +3 -0
  99. package/types.ts +9 -0
package/ActionButton.tsx CHANGED
@@ -63,9 +63,24 @@ interface InlineProps {
63
63
  inline?: boolean;
64
64
  }
65
65
 
66
+ /**
67
+ * Props for a standard link button
68
+ */
66
69
  export interface ActionButtonHrefProps extends CoreActionButtonProps, HrefProps, InlineProps {}
70
+
71
+ /**
72
+ * Props for a link button with a form wrapper for HTTP verb requests
73
+ */
67
74
  export interface ActionButtonMethodProps extends CoreActionButtonProps, MethodProps {}
75
+
76
+ /**
77
+ * Props for a button with a custom `onClick` handler
78
+ */
68
79
  export interface ActionButtonOnClickProps extends CoreActionButtonProps, OnClickProps {}
80
+
81
+ /**
82
+ * Props for a button to submit a form
83
+ */
69
84
  export interface ActionButtonFormProps extends CoreActionButtonProps, FormProps {}
70
85
 
71
86
  export type ActionButtonProps =
@@ -74,6 +89,12 @@ export type ActionButtonProps =
74
89
  | ActionButtonOnClickProps
75
90
  | ActionButtonFormProps;
76
91
 
92
+ /**
93
+ * Stylized button with icon and text, for handling dispatch actions, form
94
+ * submissions, and other general links
95
+ *
96
+ * @category Components
97
+ */
77
98
  const ActionButton = (props: ActionButtonProps) => {
78
99
  const { className, color, fa, grayMode, icon, id, mode, rightIcon, size, style, subtext, text, title } = props;
79
100
  const classes = useStyles();
package/Colors.tsx CHANGED
@@ -126,6 +126,9 @@ const specificColors = {
126
126
  },
127
127
  };
128
128
 
129
+ /**
130
+ * Shared JSS color styles
131
+ */
129
132
  const Colors = {
130
133
  ...baseColors,
131
134
  ...insigniaColors,
package/Flags/Officer.tsx CHANGED
@@ -9,7 +9,7 @@ type FlagRank =
9
9
  | "PDLTC" | "PDC" | "DAIDE" | "DFLT" | "D1LT"
10
10
  | "PNFLT" | "PSTFC" | "PRC" | "PVC" | "PCC" | "NAIDE" | "NFLT";
11
11
 
12
- interface Props {
12
+ interface OfficerProps {
13
13
  className?: string;
14
14
  flag?: string; // FlagRank | jobcode
15
15
  format?: "svg" | "png";
@@ -19,7 +19,12 @@ interface Props {
19
19
  size?: number | "thumb";
20
20
  }
21
21
 
22
- const OfficerFlag = (props: Props) => {
22
+ /**
23
+ * An officer flag image
24
+ *
25
+ * @category Components
26
+ */
27
+ const OfficerFlag = (props: OfficerProps) => {
23
28
  const { className, flag, format, jobcode, insignia, rank, size } = props;
24
29
 
25
30
  if (!flag && !jobcode && !rank) {
package/Flags/Signal.tsx CHANGED
@@ -1,13 +1,18 @@
1
1
  import React from "react";
2
2
 
3
- interface Props {
3
+ interface SignalProps {
4
4
  alt?: string;
5
5
  className?: string;
6
6
  flag: string;
7
7
  format?: "svg" | "png" | undefined;
8
8
  }
9
9
 
10
- const SignalFlag = (props: Props) => {
10
+ /**
11
+ * An individual signal flag image
12
+ *
13
+ * @category Components
14
+ */
15
+ const SignalFlag = (props: SignalProps) => {
11
16
  const { alt, className, flag, format } = props;
12
17
 
13
18
  const special = ["\uE000", "\uE001", "\uE002", "\uE003"];
package/Flags/Signals.tsx CHANGED
@@ -14,7 +14,7 @@ type Size =
14
14
  | "vertical"
15
15
  | "center";
16
16
 
17
- interface Props {
17
+ interface SignalsProps {
18
18
  className?: string;
19
19
  format?: "svg" | "png";
20
20
  orientation?: Orientation;
@@ -70,7 +70,12 @@ const useStyles = createUseStyles({
70
70
  },
71
71
  });
72
72
 
73
- const SignalFlags = (props: Props) => {
73
+ /**
74
+ * A colleciton of signal flag images generated from a string
75
+ *
76
+ * @category Components
77
+ */
78
+ const SignalFlags = (props: SignalsProps) => {
74
79
  const { className, format, orientation, size, text, title } = props;
75
80
  const classes = useStyles();
76
81
 
@@ -17,6 +17,12 @@ const useStyles = createUseStyles({
17
17
  },
18
18
  });
19
19
 
20
+ /**
21
+ * A formatted FontAwesome icon placeholder `<i>` tag, which will be replaced by
22
+ * the FontAwesome JS with the corresponding SVG
23
+ *
24
+ * @category Components
25
+ */
20
26
  const FontAwesomeIcon = (props: FontAwesomeProps) => {
21
27
  const { css, fa, icon, mode, style, title } = props;
22
28
  const classes = useStyles();
package/IconButton.tsx CHANGED
@@ -25,8 +25,19 @@ interface CoreIconProps extends FontAwesomeProps {
25
25
  title: string;
26
26
  }
27
27
 
28
+ /**
29
+ * Props for a standard link button
30
+ */
28
31
  export interface IconButtonHrefProps extends CoreIconProps, HrefProps {}
32
+
33
+ /**
34
+ * Props for a link button with a form wrapper for HTTP verb requests
35
+ */
29
36
  export interface IconButtonMethodProps extends CoreIconProps, MethodProps {}
37
+
38
+ /**
39
+ * Props for a button with a custom `onClick` handler
40
+ */
30
41
  export interface IconButtonOnClickProps extends CoreIconProps, OnClickProps {}
31
42
 
32
43
  export type IconButtonProps =
@@ -34,6 +45,12 @@ export type IconButtonProps =
34
45
  | IconButtonMethodProps
35
46
  | IconButtonOnClickProps;
36
47
 
48
+ /**
49
+ * Stylized icon-only button, for handling dispatch actions, form submissions,
50
+ * and other general links
51
+ *
52
+ * @category Components
53
+ */
37
54
  const IconButton = (props: IconButtonProps) => {
38
55
  const { className, fa, icon, id, mode, style, title } = props;
39
56
  const classes = useStyles();
package/RailsForm.tsx CHANGED
@@ -1,6 +1,6 @@
1
1
  import React from "react";
2
2
 
3
- interface Props {
3
+ interface RailsFormProps {
4
4
  action: string;
5
5
  fileUpload?: boolean;
6
6
  id?: string;
@@ -8,7 +8,12 @@ interface Props {
8
8
  children: React.ReactNode[];
9
9
  }
10
10
 
11
- const RailsForm = (props: Props) => {
11
+ /**
12
+ * A `form` tag that includes the Rails CSRF params
13
+ *
14
+ * @category Components
15
+ */
16
+ const RailsForm = (props: RailsFormProps) => {
12
17
  const { action, children, fileUpload, id, method } = props;
13
18
 
14
19
  const token = document.querySelector("meta[name='csrf-token']");
package/Readme.md CHANGED
@@ -1,5 +1,6 @@
1
1
  # USPS React Components Library
2
2
 
3
+ ![NPM Version](https://img.shields.io/npm/v/@unitedstatespowersquadrons/components)
3
4
  [![Testing Status](https://github.com/unitedstatespowersquadrons/components/actions/workflows/main.yml/badge.svg)](https://github.com/unitedstatespowersquadrons/components/actions)
4
5
 
5
6
  ## Usage
@@ -46,12 +47,28 @@ More detailed information is available for [Toasts](Toasts/Readme.md) usage.
46
47
 
47
48
  ## Reducer
48
49
 
49
- To create a reducer, follow the following pattern, follow the pattern described
50
- in [Reducer/Example](Reducer/Example).
50
+ To create a reducer, follow the pattern described in [Reducer/Example](Reducer/Example).
51
51
 
52
52
  There is also an example in `appstate.tsx` for if you only need access to app
53
53
  state, but do not have any dispatchable events.
54
54
 
55
+ ## Shared TSC Config
56
+
57
+ To include the TSC config from this library, create `./tsconfig.json`:
58
+
59
+ ```json
60
+ {
61
+ "extends": "./node_modules/@unitedstatespowersquadrons/components/tsconfig.json",
62
+ "exclude": [
63
+ "**/proto",
64
+ "node_modules",
65
+ "public",
66
+ "vendor",
67
+ "tmp"
68
+ ]
69
+ }
70
+ ```
71
+
55
72
  ## Automated Testing
56
73
 
57
74
  GitHub Actions will automatically run `eslint` and `tsc` on branch pushes.
@@ -9,6 +9,13 @@ interface InitialAppProps<AppState> {
9
9
  children: React.ReactNode;
10
10
  }
11
11
 
12
+ /**
13
+ * Construct the exports from a reducer
14
+ *
15
+ * @param reducer The specific reducer function for the component
16
+ * @param handlers Handlers for individual dispatch actions
17
+ * @returns { AppProvider, useAppCableSubscription, useAppDispatch, useAppState }
18
+ */
12
19
  export default function buildReducer<AppState, AppAction>(
13
20
  reducer: (draft: Draft<AppState>, action: AppAction) => void,
14
21
  handlers: ReducerHandler<AppAction>[] = []
@@ -5,6 +5,11 @@ interface InitialAppProps<AppState> {
5
5
  children: React.ReactNode;
6
6
  }
7
7
 
8
+ /**
9
+ * Construct the exports to access appState for a component without a reducer
10
+ *
11
+ * @returns { AppProvider, useAppState }
12
+ */
8
13
  export default function buildUnreducibleState<AppState>() {
9
14
  const StateContext = createContext<AppState | null>(null);
10
15
 
@@ -7,12 +7,17 @@ const useStyles = createUseStyles({
7
7
  icon: { cursor: "pointer" },
8
8
  });
9
9
 
10
- interface Props extends Omit<IconButtonOnClickProps, "icon"> {
10
+ interface SelectionIconButtonProps extends Omit<IconButtonOnClickProps, "icon"> {
11
11
  id?: string;
12
12
  selected: boolean;
13
13
  }
14
14
 
15
- const SelectionIconButton = (props: Props) => {
15
+ /**
16
+ * Stylized icon-only button, intended for handling add/remove dispatch actions
17
+ *
18
+ * @category Components
19
+ */
20
+ const SelectionIconButton = (props: SelectionIconButtonProps) => {
16
21
  const { id, onClick, selected } = props;
17
22
  const classes = useStyles();
18
23
 
@@ -6,11 +6,16 @@ const useStyles = createUseStyles({
6
6
  tbody: TableStyles.tbody,
7
7
  });
8
8
 
9
- interface Props {
9
+ interface BodyProps {
10
10
  children: React.ReactNode;
11
11
  }
12
12
 
13
- const Body = (props: Props) => {
13
+ /**
14
+ * Table body with automatic row striping
15
+ *
16
+ * @category Components
17
+ */
18
+ const Body = (props: BodyProps) => {
14
19
  const { children } = props;
15
20
  const classes = useStyles();
16
21
 
@@ -6,11 +6,16 @@ const useStyles = createUseStyles({
6
6
  tfoot: TableStyles.tfoot,
7
7
  });
8
8
 
9
- interface Props {
9
+ interface FootProps {
10
10
  children: React.ReactNode;
11
11
  }
12
12
 
13
- const Head = (props: Props) => {
13
+ /**
14
+ * Table foot with automatic row striping
15
+ *
16
+ * @category Components
17
+ */
18
+ const Head = (props: FootProps) => {
14
19
  const { children } = props;
15
20
  const classes = useStyles();
16
21
 
@@ -6,11 +6,16 @@ const useStyles = createUseStyles({
6
6
  thead: TableStyles.thead,
7
7
  });
8
8
 
9
- interface Props {
9
+ interface HeadProps {
10
10
  children: React.ReactNode;
11
11
  }
12
12
 
13
- const Head = (props: Props) => {
13
+ /**
14
+ * Table head with automatic row striping
15
+ *
16
+ * @category Components
17
+ */
18
+ const Head = (props: HeadProps) => {
14
19
  const { children } = props;
15
20
  const classes = useStyles();
16
21
 
@@ -10,7 +10,7 @@ const useStyles = createUseStyles({
10
10
  tableStripedTbody: TableStyles.tableStripedTbody,
11
11
  });
12
12
 
13
- interface Props {
13
+ interface TableProps {
14
14
  borderCollapse?: boolean;
15
15
  children: React.ReactNode;
16
16
  className?: string;
@@ -18,7 +18,12 @@ interface Props {
18
18
  stripedTbody?: boolean;
19
19
  }
20
20
 
21
- const Table = (props: Props) => {
21
+ /**
22
+ * Table with automatic row striping
23
+ *
24
+ * @category Components
25
+ */
26
+ const Table = (props: TableProps) => {
22
27
  const { borderCollapse, children, className, id, stripedTbody } = props;
23
28
  const classes = useStyles();
24
29
 
@@ -58,6 +58,9 @@ const tableStripedTbody = {
58
58
  "& > thead": thead,
59
59
  };
60
60
 
61
+ /**
62
+ * Shared JSS styles for striped tables and sections
63
+ */
61
64
  const TableStyles = { table, tableStripedTbody, tbody, tfoot, thead };
62
65
 
63
66
  export default TableStyles;
package/Styles.tsx CHANGED
@@ -40,6 +40,9 @@ const colorizeButton = (color: ButtonColorName) => {
40
40
  });
41
41
  };
42
42
 
43
+ /**
44
+ * Shared JSS styles
45
+ */
43
46
  const Styles = {
44
47
  bigText: { fontSize: "1.5em" },
45
48
  button: {
@@ -59,6 +62,11 @@ const Styles = {
59
62
  textDecoration: "none",
60
63
  width: "fit-content",
61
64
  },
65
+ flexColumn: {
66
+ display: "flex",
67
+ flexDirection: "column",
68
+ gap: "0.5em",
69
+ },
62
70
  flexRow: {
63
71
  alignItems: "center",
64
72
  display: "flex",
package/Toasts/Readme.md CHANGED
@@ -5,16 +5,15 @@ root components, while supporting app state and reducer dispatching.
5
5
 
6
6
  ```tsx
7
7
  // NewComponent.tsx
8
+ import { Toasts } from "@unitedstatespowersquadrons/components";
8
9
  import { useAppState, useAppDispatch } from "./reducer";
9
- import { createDismissToast, Toasts } from "../shared";
10
10
 
11
11
  const NewComponent = () => {
12
12
  const { toasts } = useAppState();
13
13
  const dispatch = useAppDispatch();
14
- const dismissToast = createDismissToast(dispatch);
15
14
 
16
15
  return (
17
- <Toasts dismiss={dismissToast} toasts={toasts} />
16
+ <Toasts dispatch={dispatch} toasts={toasts} />
18
17
  );
19
18
  };
20
19
 
@@ -23,8 +22,7 @@ export default NewComponent;
23
22
 
24
23
  ```tsx
25
24
  // reducer.tsx
26
- import { Toast, ToastAppAction, ToastProps } from "../shared";
27
- import { addToast, handleToasts } from "./reducerHelpers";
25
+ import { addToast, handleToasts, Toast, ToastAppAction, ToastProps } from "@unitedstatespowersquadrons/components";
28
26
 
29
27
  export type AppAction =
30
28
  // ...
@@ -73,38 +71,3 @@ function reducer(draft: Draft<AppState>, action: AppAction) {
73
71
  // ...
74
72
  };
75
73
  ```
76
-
77
- ```tsx
78
- // reducerHelpers.tsx
79
- import { Draft } from "immer";
80
- import { AppState } from "./types";
81
- import { Toast, ToastProps } from "../shared";
82
-
83
- export const handleToasts = (draft: Draft<AppState>, toasts: Toast[]) => {
84
- if (toasts.length > 0) {
85
- toasts.forEach(toast => addToast(draft, toast));
86
- }
87
- };
88
-
89
- export const addToast = (draft: Draft<AppState>, toastOptions: Proto.Shared.Toast) => {
90
- const { body, status, timeout, title } = toastOptions;
91
-
92
- const id = draft.toastId = draft.toastId ? draft.toastId + 1 : 1;
93
-
94
- const toast = { body, id, status, timeout, title } as ToastProps;
95
-
96
- if (!draft.toasts) draft.toasts = [];
97
-
98
- // Do not store multiple identical toasts
99
- if (draft.toasts.some(t => {
100
- return (
101
- toast.body === t.body &&
102
- toast.status === t.status &&
103
- toast.title === t.title
104
- );
105
- })) return;
106
-
107
- draft.toasts.push(toast);
108
- };
109
-
110
- ```
package/Toasts/Toast.tsx CHANGED
@@ -5,7 +5,7 @@ import { DismissFunc, Toast_Status, ToastProps } from "./types";
5
5
  import FontAwesomeIcon from "../FontAwesomeIcon";
6
6
  import Styles from "../Styles";
7
7
 
8
- interface Props {
8
+ interface ToastComponentProps {
9
9
  dismiss: DismissFunc;
10
10
  toast: ToastProps;
11
11
  }
@@ -26,7 +26,10 @@ const useStyles = createUseStyles({
26
26
  color: "#009900",
27
27
  },
28
28
  toast: {
29
- "@media print, screen and (max-width: 1000px)": { maxWidth: "100%" },
29
+ "@media print, screen and (max-width: 1000px)": {
30
+ maxWidth: "100%",
31
+ width: "auto",
32
+ },
30
33
  animation: "fadeIn 1s",
31
34
  backgroundColor: "#EEEEEE",
32
35
  border: "thin solid white",
@@ -69,7 +72,12 @@ const useStyles = createUseStyles({
69
72
  visible: { opacity: "1" },
70
73
  });
71
74
 
72
- const Toast = (props: Props) => {
75
+ /**
76
+ * An individual toast message
77
+ *
78
+ * @category Components
79
+ */
80
+ const Toast = (props: ToastComponentProps) => {
73
81
  const classes = useStyles();
74
82
 
75
83
  const { dismiss, toast } = props;
package/Toasts/Toasts.tsx CHANGED
@@ -23,9 +23,9 @@ type Props = DismissProps | DispatchProps;
23
23
  const useStyles = createUseStyles({
24
24
  toastsContainer: {
25
25
  "@media print, screen and (max-width: 1000px)": {
26
- fontSize: "0.7em",
27
- marginLeft: "0.5em",
28
- maxWidth: "100%",
26
+ fontSize: "1.5em",
27
+ margin: "0.5em",
28
+ width: "90vw",
29
29
  },
30
30
  display: "flex",
31
31
  flexDirection: "column",
@@ -38,6 +38,11 @@ const useStyles = createUseStyles({
38
38
  },
39
39
  });
40
40
 
41
+ /**
42
+ * Container for handling toast messages
43
+ *
44
+ * @category Components
45
+ */
41
46
  const Toasts = (props: Props) => {
42
47
  const { toasts } = props;
43
48
  const classes = useStyles();
@@ -2,6 +2,10 @@ import { Draft } from "immer";
2
2
  import { Toast, ToastProps, ToastRemoveAppAction } from "./types";
3
3
  import { AppStateWithToasts, DispatchFunc } from "../";
4
4
 
5
+ /**
6
+ * Wrap a reducer's dispatch function to create the dismissToast function for a
7
+ * component
8
+ */
5
9
  export function createDismissToast(dispatch: DispatchFunc<ToastRemoveAppAction>) {
6
10
  const dismissToast = (toastId: number) => {
7
11
  dispatch({ toastId, type: "dismissToast" });
@@ -12,12 +16,18 @@ export function createDismissToast(dispatch: DispatchFunc<ToastRemoveAppAction>)
12
16
  return dismissToast;
13
17
  }
14
18
 
19
+ /**
20
+ * Handle toasts received from the server, or generated by an action
21
+ */
15
22
  export function handleToasts<T extends AppStateWithToasts>(draft: Draft<T>, toasts: Toast[]) {
16
23
  if (toasts.length > 0) {
17
24
  toasts.forEach(toast => addToast(draft, toast));
18
25
  }
19
26
  }
20
27
 
28
+ /**
29
+ * Add a toast to the current toasts container
30
+ */
21
31
  export function addToast<T extends AppStateWithToasts>(draft: Draft<T>, toastOptions: Toast) {
22
32
  const { body, id, status, timeout, title } = toastOptions;
23
33
 
@@ -42,6 +52,9 @@ export function addToast<T extends AppStateWithToasts>(draft: Draft<T>, toastOpt
42
52
  draft.toasts.push(toast);
43
53
  }
44
54
 
55
+ /**
56
+ * Remove a toast from the current toasts container
57
+ */
45
58
  export function removeToast<T extends AppStateWithToasts>(draft: Draft<T>, toast: ToastProps) {
46
59
  const beforeToasts: ToastProps[] = [];
47
60
  const afterToasts: ToastProps[] = [];
@@ -61,6 +74,10 @@ export function removeToast<T extends AppStateWithToasts>(draft: Draft<T>, toast
61
74
  });
62
75
  }
63
76
 
77
+ /**
78
+ * Remove a toast from the current toasts container corresponding to a specific
79
+ * known toastId (usually, a static toast generated by the server)
80
+ */
64
81
  export function removeToastById<T extends AppStateWithToasts>(draft: Draft<T>, toastId: number) {
65
82
  const toast = draft.toasts.find(t => t.id === toastId);
66
83
 
package/docs/.nojekyll ADDED
@@ -0,0 +1 @@
1
+ TypeDoc added this file to prevent GitHub Pages from using Jekyll. You can turn off this behavior by setting the `githubPages` option to false.
@@ -0,0 +1 @@
1
+ window.hierarchyData = "eJyVkrFuwyAQht/lZtIWxziWtzRS1KVqh25VBsu+yCiYq4CoQ+R378VDiqJYgoUB7uf7juMCjih4aL5lUYpNdRDg8GiwC5osb19A1dfVtiNCA1/U+vDp6MeDgJO2PTSFqgScneFTbQO6Y9uhf/4vfBrCaLi6M63nCyH4fnVNrm7VMAnYVPeUFEDC3Xw4aNM7tNyjqg/M4k4j2J5s2P6ipxFTGrsvz1WQazk7rGXksCOH2/nJX88hkE0ReZjJtikrISslZK1E8VLMZmU8ipjwxj8jxexhJu0bsMsC/B3DQH0uPkolCtRLAh92Z3R3yjWIY2kKPIcFhT25MZd/y6TAp+kPKrFfRA=="
@@ -0,0 +1,99 @@
1
+ :root {
2
+ --light-hl-0: #AF00DB;
3
+ --dark-hl-0: #C586C0;
4
+ --light-hl-1: #000000;
5
+ --dark-hl-1: #D4D4D4;
6
+ --light-hl-2: #0000FF;
7
+ --dark-hl-2: #569CD6;
8
+ --light-hl-3: #A31515;
9
+ --dark-hl-3: #CE9178;
10
+ --light-hl-4: #795E26;
11
+ --dark-hl-4: #DCDCAA;
12
+ --light-hl-5: #001080;
13
+ --dark-hl-5: #9CDCFE;
14
+ --light-hl-6: #800000;
15
+ --dark-hl-6: #808080;
16
+ --light-hl-7: #800000;
17
+ --dark-hl-7: #569CD6;
18
+ --light-hl-8: #E50000;
19
+ --dark-hl-8: #9CDCFE;
20
+ --light-hl-9: #0000FF;
21
+ --dark-hl-9: #CE9178;
22
+ --light-hl-10: #0451A5;
23
+ --dark-hl-10: #9CDCFE;
24
+ --light-code-background: #FFFFFF;
25
+ --dark-code-background: #1E1E1E;
26
+ }
27
+
28
+ @media (prefers-color-scheme: light) { :root {
29
+ --hl-0: var(--light-hl-0);
30
+ --hl-1: var(--light-hl-1);
31
+ --hl-2: var(--light-hl-2);
32
+ --hl-3: var(--light-hl-3);
33
+ --hl-4: var(--light-hl-4);
34
+ --hl-5: var(--light-hl-5);
35
+ --hl-6: var(--light-hl-6);
36
+ --hl-7: var(--light-hl-7);
37
+ --hl-8: var(--light-hl-8);
38
+ --hl-9: var(--light-hl-9);
39
+ --hl-10: var(--light-hl-10);
40
+ --code-background: var(--light-code-background);
41
+ } }
42
+
43
+ @media (prefers-color-scheme: dark) { :root {
44
+ --hl-0: var(--dark-hl-0);
45
+ --hl-1: var(--dark-hl-1);
46
+ --hl-2: var(--dark-hl-2);
47
+ --hl-3: var(--dark-hl-3);
48
+ --hl-4: var(--dark-hl-4);
49
+ --hl-5: var(--dark-hl-5);
50
+ --hl-6: var(--dark-hl-6);
51
+ --hl-7: var(--dark-hl-7);
52
+ --hl-8: var(--dark-hl-8);
53
+ --hl-9: var(--dark-hl-9);
54
+ --hl-10: var(--dark-hl-10);
55
+ --code-background: var(--dark-code-background);
56
+ } }
57
+
58
+ :root[data-theme='light'] {
59
+ --hl-0: var(--light-hl-0);
60
+ --hl-1: var(--light-hl-1);
61
+ --hl-2: var(--light-hl-2);
62
+ --hl-3: var(--light-hl-3);
63
+ --hl-4: var(--light-hl-4);
64
+ --hl-5: var(--light-hl-5);
65
+ --hl-6: var(--light-hl-6);
66
+ --hl-7: var(--light-hl-7);
67
+ --hl-8: var(--light-hl-8);
68
+ --hl-9: var(--light-hl-9);
69
+ --hl-10: var(--light-hl-10);
70
+ --code-background: var(--light-code-background);
71
+ }
72
+
73
+ :root[data-theme='dark'] {
74
+ --hl-0: var(--dark-hl-0);
75
+ --hl-1: var(--dark-hl-1);
76
+ --hl-2: var(--dark-hl-2);
77
+ --hl-3: var(--dark-hl-3);
78
+ --hl-4: var(--dark-hl-4);
79
+ --hl-5: var(--dark-hl-5);
80
+ --hl-6: var(--dark-hl-6);
81
+ --hl-7: var(--dark-hl-7);
82
+ --hl-8: var(--dark-hl-8);
83
+ --hl-9: var(--dark-hl-9);
84
+ --hl-10: var(--dark-hl-10);
85
+ --code-background: var(--dark-code-background);
86
+ }
87
+
88
+ .hl-0 { color: var(--hl-0); }
89
+ .hl-1 { color: var(--hl-1); }
90
+ .hl-2 { color: var(--hl-2); }
91
+ .hl-3 { color: var(--hl-3); }
92
+ .hl-4 { color: var(--hl-4); }
93
+ .hl-5 { color: var(--hl-5); }
94
+ .hl-6 { color: var(--hl-6); }
95
+ .hl-7 { color: var(--hl-7); }
96
+ .hl-8 { color: var(--hl-8); }
97
+ .hl-9 { color: var(--hl-9); }
98
+ .hl-10 { color: var(--hl-10); }
99
+ pre, code { background: var(--code-background); }