@unitedstatespowersquadrons/components 1.0.5 → 1.0.7
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/ActionButton.tsx +31 -2
- package/package.json +1 -1
package/ActionButton.tsx
CHANGED
|
@@ -5,7 +5,7 @@ import { ButtonColorName } from "./Colors";
|
|
|
5
5
|
import FontAwesomeIcon, { FontAwesomeProps } from "./FontAwesomeIcon";
|
|
6
6
|
import Styles from "./Styles";
|
|
7
7
|
import BaseActionButton from "./BaseActionButton";
|
|
8
|
-
import { HrefProps, MethodProps, OnClickProps } from "./types";
|
|
8
|
+
import { HrefProps, MethodProps, OnClickHandler, OnClickProps } from "./types";
|
|
9
9
|
|
|
10
10
|
const useStyles = createUseStyles({
|
|
11
11
|
big: { ...Styles.bigText },
|
|
@@ -41,14 +41,21 @@ export interface CoreActionButtonProps extends FontAwesomeProps {
|
|
|
41
41
|
title?: string | undefined;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
interface FormProps {
|
|
45
|
+
confirm?: string;
|
|
46
|
+
formId: string;
|
|
47
|
+
}
|
|
48
|
+
|
|
44
49
|
export interface ActionButtonHrefProps extends CoreActionButtonProps, HrefProps {}
|
|
45
50
|
export interface ActionButtonMethodProps extends CoreActionButtonProps, MethodProps {}
|
|
46
51
|
export interface ActionButtonOnClickProps extends CoreActionButtonProps, OnClickProps {}
|
|
52
|
+
export interface ActionButtonFormProps extends CoreActionButtonProps, FormProps {}
|
|
47
53
|
|
|
48
54
|
export type ActionButtonProps =
|
|
49
55
|
| ActionButtonHrefProps
|
|
50
56
|
| ActionButtonMethodProps
|
|
51
|
-
| ActionButtonOnClickProps
|
|
57
|
+
| ActionButtonOnClickProps
|
|
58
|
+
| ActionButtonFormProps;
|
|
52
59
|
|
|
53
60
|
const ActionButton = (props: ActionButtonProps) => {
|
|
54
61
|
const { className, color, fa, grayMode, icon, id, mode, size, style, subtext, text, title } = props;
|
|
@@ -118,6 +125,28 @@ const ActionButton = (props: ActionButtonProps) => {
|
|
|
118
125
|
{buttonContents()}
|
|
119
126
|
</BaseActionButton>
|
|
120
127
|
);
|
|
128
|
+
} else if ("formId" in props) {
|
|
129
|
+
const { confirm, formId } = props;
|
|
130
|
+
|
|
131
|
+
const onClick: OnClickHandler = () => {
|
|
132
|
+
const externalForm = document.getElementById(formId) as HTMLFormElement | undefined;
|
|
133
|
+
|
|
134
|
+
if (!externalForm) throw new Error(`Could not find form #${formId} in the DOM.`);
|
|
135
|
+
|
|
136
|
+
externalForm.requestSubmit();
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
return(
|
|
140
|
+
<BaseActionButton
|
|
141
|
+
className={classNames(classes.button, colorClassName, sizeClassName(), className)}
|
|
142
|
+
id={id}
|
|
143
|
+
onClick={onClick}
|
|
144
|
+
title={title}
|
|
145
|
+
confirm={confirm}
|
|
146
|
+
>
|
|
147
|
+
{buttonContents()}
|
|
148
|
+
</BaseActionButton>
|
|
149
|
+
);
|
|
121
150
|
} else {
|
|
122
151
|
throw new Error("Invalid ActionButton configuration: must specify props: onClick | (href & method?)");
|
|
123
152
|
}
|