@unitedstatespowersquadrons/components 1.0.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.
- package/.github/workflows/main.yml +33 -0
- package/ActionButton.tsx +126 -0
- package/BaseActionButton.tsx +126 -0
- package/Colors.tsx +124 -0
- package/FontAwesomeIcon.tsx +33 -0
- package/IconButton.tsx +87 -0
- package/Readme.md +25 -0
- package/SelectionIconButton.tsx +35 -0
- package/StripedTable/Body.tsx +22 -0
- package/StripedTable/Foot.tsx +22 -0
- package/StripedTable/Head.tsx +22 -0
- package/StripedTable/Table.tsx +27 -0
- package/StripedTable/TableStyles.ts +46 -0
- package/StripedTable/index.tsx +9 -0
- package/Styles.tsx +67 -0
- package/Toasts/Readme.md +110 -0
- package/Toasts/Toast.tsx +162 -0
- package/Toasts/Toasts.tsx +36 -0
- package/Toasts/createDismissToast.ts +16 -0
- package/Toasts/index.tsx +5 -0
- package/Toasts/types.ts +28 -0
- package/eslint.config.mjs +212 -0
- package/index.tsx +30 -0
- package/package.json +33 -0
- package/railsFetchJson.tsx +37 -0
- package/tsconfig.json +30 -0
- package/types.ts +51 -0
package/index.tsx
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export { default as FontAwesomeIcon } from "./FontAwesomeIcon";
|
|
2
|
+
export { default as railsFetchJson, getCsrfTokenHeader } from "./railsFetchJson";
|
|
3
|
+
export { default as Striped, StripedTable, StripedHead, StripedBody } from "./StripedTable";
|
|
4
|
+
export { default as ActionButton } from "./ActionButton";
|
|
5
|
+
export { default as IconButton } from "./IconButton";
|
|
6
|
+
export { default as SelectionIconButton } from "./SelectionIconButton";
|
|
7
|
+
export { Toasts, createDismissToast, Toast_Status } from "./Toasts";
|
|
8
|
+
export { default as Colors } from "./Colors";
|
|
9
|
+
export { default as Styles } from "./Styles";
|
|
10
|
+
|
|
11
|
+
export type {
|
|
12
|
+
AppStateWithToasts,
|
|
13
|
+
DispatchFunc,
|
|
14
|
+
DispatchHandler,
|
|
15
|
+
OnClickHandler,
|
|
16
|
+
OnClickOrKeyboardHandler,
|
|
17
|
+
OnInputChangeHandler,
|
|
18
|
+
RailsResponse,
|
|
19
|
+
} from "./types";
|
|
20
|
+
export type { ButtonColorName } from "./Colors";
|
|
21
|
+
export type { FontAwesomeProps } from "./FontAwesomeIcon";
|
|
22
|
+
export type {
|
|
23
|
+
ActionButtonProps,
|
|
24
|
+
ActionButtonHrefProps,
|
|
25
|
+
ActionButtonMethodProps,
|
|
26
|
+
ActionButtonOnClickProps,
|
|
27
|
+
CoreActionButtonProps,
|
|
28
|
+
} from "./ActionButton";
|
|
29
|
+
export type { IconButtonProps, IconButtonHrefProps, IconButtonOnClickProps } from "./IconButton";
|
|
30
|
+
export type { Toast, ToastAppAction, ToastProps } from "./Toasts";
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@unitedstatespowersquadrons/components",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "USPS shared React components library",
|
|
5
|
+
"main": "index.tsx",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+ssh://git@github.com/unitedstatespowersquadrons/components.git"
|
|
12
|
+
},
|
|
13
|
+
"author": "Julian Fiander",
|
|
14
|
+
"license": "ISC",
|
|
15
|
+
"bugs": {
|
|
16
|
+
"url": "https://github.com/unitedstatespowersquadrons/components/issues"
|
|
17
|
+
},
|
|
18
|
+
"homepage": "https://github.com/unitedstatespowersquadrons/components#readme",
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"classnames": "^2.5.1",
|
|
21
|
+
"react": "^19.1.0",
|
|
22
|
+
"react-jss": "^10.10.0",
|
|
23
|
+
"typescript": "^5.8.3"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@stylistic/eslint-plugin": "^5.1.0",
|
|
27
|
+
"@types/react": "^19.1.8",
|
|
28
|
+
"eslint": "^9.30.1",
|
|
29
|
+
"eslint-plugin-react": "^7.37.5",
|
|
30
|
+
"eslint-plugin-react-hooks": "^5.2.0",
|
|
31
|
+
"typescript-eslint": "^8.36.0"
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
const oldFetch = window.fetch;
|
|
2
|
+
|
|
3
|
+
interface FetchJsonOptions extends RequestInit {
|
|
4
|
+
bodyJson?: object;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export const getCsrfTokenHeader = () => {
|
|
8
|
+
const token = document.querySelector("meta[name='csrf-token']");
|
|
9
|
+
return token ? token.getAttribute("content")! : "";
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const railsFetchJson = <T = object>(url: RequestInfo, options?: FetchJsonOptions) => {
|
|
13
|
+
options ||= {};
|
|
14
|
+
const optionHeaders = options.headers;
|
|
15
|
+
delete(options.headers);
|
|
16
|
+
const baseheaders = {
|
|
17
|
+
...optionHeaders,
|
|
18
|
+
Credentials: "same-origin",
|
|
19
|
+
"X-CSRF-Token": getCsrfTokenHeader(),
|
|
20
|
+
"X-Exams-Client": "React-2025",
|
|
21
|
+
"X-Requested-With": "XMLHttpRequest",
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const jsonPost = options.method !== "GET" && options?.bodyJson;
|
|
25
|
+
const jsonHeaders = {
|
|
26
|
+
Accept: "application/json",
|
|
27
|
+
"Content-Type": "application/json",
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const headers = new Headers(jsonPost ? { ...baseheaders, ...jsonHeaders } : { ...baseheaders });
|
|
31
|
+
|
|
32
|
+
if (jsonPost) options.body = JSON.stringify(options.bodyJson);
|
|
33
|
+
|
|
34
|
+
return oldFetch(url, { headers, ...options }).then(res => res.json() as Promise<T>);
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export default railsFetchJson;
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"allowUnreachableCode": false,
|
|
4
|
+
"emitDecoratorMetadata": false,
|
|
5
|
+
"esModuleInterop": true,
|
|
6
|
+
"exactOptionalPropertyTypes": true,
|
|
7
|
+
"forceConsistentCasingInFileNames": true,
|
|
8
|
+
"isolatedModules": true,
|
|
9
|
+
"jsx": "react",
|
|
10
|
+
"module": "commonjs",
|
|
11
|
+
"noEmit": true,
|
|
12
|
+
"noFallthroughCasesInSwitch": true,
|
|
13
|
+
"noImplicitOverride": true,
|
|
14
|
+
"noImplicitReturns": true,
|
|
15
|
+
"noPropertyAccessFromIndexSignature": true,
|
|
16
|
+
"noUncheckedIndexedAccess": true,
|
|
17
|
+
"noUnusedLocals": true,
|
|
18
|
+
"noUnusedParameters": true,
|
|
19
|
+
"strict": true,
|
|
20
|
+
"skipLibCheck": true,
|
|
21
|
+
"target": "ES2019",
|
|
22
|
+
},
|
|
23
|
+
"exclude": [
|
|
24
|
+
"app/javascript/mount.tsx",
|
|
25
|
+
"node_modules",
|
|
26
|
+
"public",
|
|
27
|
+
"vendor",
|
|
28
|
+
"tmp"
|
|
29
|
+
]
|
|
30
|
+
}
|
package/types.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Toast, ToastProps } from "./Toasts";
|
|
3
|
+
|
|
4
|
+
export interface AppStateWithToasts {
|
|
5
|
+
toasts: ToastProps[];
|
|
6
|
+
toastId?: number;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export type DispatchFunc<T> = (action: T) => void;
|
|
10
|
+
export type DispatchHandler<T> = (action: T) => {
|
|
11
|
+
body?: string;
|
|
12
|
+
bodyJson?: object;
|
|
13
|
+
headers?: { [key: string]: string };
|
|
14
|
+
href?: string;
|
|
15
|
+
method?: string;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export type OnClickHandler = (event: React.MouseEvent<HTMLButtonElement>) => void;
|
|
19
|
+
export type OnInputChangeHandler = (event: React.ChangeEvent<HTMLInputElement | HTMLSelectElement>) => void;
|
|
20
|
+
export type OnClickOrKeyboardHandler = (event: OnClickOrKeyboardEvent) => void;
|
|
21
|
+
|
|
22
|
+
type OnClickOrKeyboardEvent =
|
|
23
|
+
| React.MouseEvent<HTMLButtonElement>
|
|
24
|
+
| React.KeyboardEvent<HTMLInputElement>;
|
|
25
|
+
|
|
26
|
+
export interface HrefProps {
|
|
27
|
+
href: string;
|
|
28
|
+
newTab?: boolean | undefined;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
type HttpMethod =
|
|
32
|
+
| "POST" | "post"
|
|
33
|
+
| "PUT" | "put "
|
|
34
|
+
| "PATCH" | "patch"
|
|
35
|
+
| "DELETE" | "delete";
|
|
36
|
+
|
|
37
|
+
export interface MethodProps extends HrefProps {
|
|
38
|
+
confirm?: string | undefined;
|
|
39
|
+
method: HttpMethod;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface OnClickProps {
|
|
43
|
+
confirm?: string | undefined;
|
|
44
|
+
onClick: OnClickHandler;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface RailsResponse {
|
|
48
|
+
reload?: boolean;
|
|
49
|
+
status: "OK" | "ERROR";
|
|
50
|
+
toasts: Toast[];
|
|
51
|
+
}
|