@unitedstatespowersquadrons/components 1.0.12 → 1.1.0-pre.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.
package/BaseActionButton.tsx
CHANGED
|
@@ -99,24 +99,18 @@ const BaseActionButton = (props: BaseActionButtonProps) => {
|
|
|
99
99
|
} else if ("href" in props) {
|
|
100
100
|
const { href, newTab } = props;
|
|
101
101
|
|
|
102
|
-
const onClick = () => {
|
|
103
|
-
if (newTab) {
|
|
104
|
-
open(href, "_blank");
|
|
105
|
-
} else {
|
|
106
|
-
location.href = href;
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
|
|
110
102
|
return(
|
|
111
|
-
<
|
|
112
|
-
|
|
103
|
+
<a
|
|
104
|
+
href={href}
|
|
113
105
|
id={id}
|
|
114
|
-
|
|
106
|
+
rel={newTab ? "noreferrer" : undefined}
|
|
107
|
+
target={newTab ? "_blank" : undefined}
|
|
115
108
|
title={title}
|
|
116
|
-
type="button"
|
|
117
109
|
>
|
|
118
|
-
{
|
|
119
|
-
|
|
110
|
+
<button className={classNames("action-button", classes.button, className)} type="button">
|
|
111
|
+
{children}
|
|
112
|
+
</button>
|
|
113
|
+
</a>
|
|
120
114
|
);
|
|
121
115
|
} else {
|
|
122
116
|
throw new Error("Invalid BaseActionButton configuration: must specify props: onClick | (href & method?)");
|
package/Readme.md
CHANGED
|
@@ -20,6 +20,26 @@ yarn
|
|
|
20
20
|
|
|
21
21
|
More detailed information is available for [Toasts](Toasts/Readme.md) usage.
|
|
22
22
|
|
|
23
|
+
## Reducer
|
|
24
|
+
|
|
25
|
+
To create a reducer, follow the following pattern, follow the pattern described
|
|
26
|
+
in [Reducer/Example](Reducer/Example).
|
|
27
|
+
|
|
28
|
+
### State without Dispatch
|
|
29
|
+
|
|
30
|
+
If you only need access to app state, but no dispatchable events, you can use
|
|
31
|
+
the simplified generator function:
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
import { createContext } from "react";
|
|
35
|
+
import { buildUnreducableState } from "@unitedstatespowersquadrons/components";
|
|
36
|
+
import { AppState } from "./types";
|
|
37
|
+
|
|
38
|
+
const StateContext = createContext<AppState | null>(null);
|
|
39
|
+
|
|
40
|
+
export const { AppProvider, useAppState } = buildUnreducableState<AppState>(StateContext);
|
|
41
|
+
```
|
|
42
|
+
|
|
23
43
|
## Automated Testing
|
|
24
44
|
|
|
25
45
|
GitHub Actions will automatically run `eslint` and `tsc` on branch pushes.
|
|
@@ -4,7 +4,7 @@ import * as ReducerHandlers from "./reducerHandlers";
|
|
|
4
4
|
import { AppState, ServerResponse } from "./types";
|
|
5
5
|
import { buildReducer, RailsAppAction } from "../";
|
|
6
6
|
|
|
7
|
-
// If you want to add additional data to the server response, use type `RailsAppAction<
|
|
7
|
+
// If you want to add additional data to the server response, use type `RailsAppAction<ServerResponse>`.
|
|
8
8
|
// Otherwise, just use type `RailsAppAction`.
|
|
9
9
|
//
|
|
10
10
|
// If you need to access the available `type`s for your defined AppAction, use `AppActionType<AppAction>`
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { AppAction } from "./reducer";
|
|
2
|
-
import { ServerResponse } from "./types";
|
|
3
2
|
import { DispatchFunc, DispatchHandler } from "../types";
|
|
4
3
|
import wrapDispatch from "../wrapDispatch";
|
|
5
4
|
|
|
@@ -21,5 +20,5 @@ export const doSomething = (
|
|
|
21
20
|
|
|
22
21
|
// If you want to add additional data to the server response, pass in type `ServerResponse`.
|
|
23
22
|
// Otherwise, just leave the second type parameter unspecified.
|
|
24
|
-
return wrapDispatch
|
|
23
|
+
return wrapDispatch(dispatch, [actionType], handler);
|
|
25
24
|
};
|
package/Toasts/toastHelpers.ts
CHANGED
|
@@ -13,13 +13,9 @@ export function createDismissToast(dispatch: DispatchFunc<ToastRemoveAppAction>)
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
export function handleToasts<T extends AppStateWithToasts>(draft: Draft<T>, toasts: Toast[]) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
return handleToastsFunc;
|
|
16
|
+
if (toasts.length > 0) {
|
|
17
|
+
toasts.forEach(toast => addToast(draft, toast));
|
|
18
|
+
}
|
|
23
19
|
}
|
|
24
20
|
|
|
25
21
|
export function addToast<T extends AppStateWithToasts>(draft: Draft<T>, toastOptions: Toast) {
|