@unitedstatespowersquadrons/components 1.2.23 → 1.2.24
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/Readme.md +19 -2
- package/Styles.tsx +5 -0
- package/Toasts/Readme.md +3 -40
- package/package.json +1 -1
package/Readme.md
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
# USPS React Components Library
|
|
2
2
|
|
|
3
|
+

|
|
3
4
|
[](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
|
|
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.
|
package/Styles.tsx
CHANGED
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
|
|
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 "
|
|
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
|
-
```
|