react-better-html 1.1.32 → 1.1.33
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.
|
@@ -7,6 +7,7 @@ type FormProps = {
|
|
|
7
7
|
submitButtonText?: string;
|
|
8
8
|
submitButtonLoaderName?: LoaderName | AnyOtherString;
|
|
9
9
|
submitButtonId?: string;
|
|
10
|
+
submitButtonIsDisabled?: boolean;
|
|
10
11
|
/** @default "right" */
|
|
11
12
|
actionButtonsLocation?: "left" | "center" | "right";
|
|
12
13
|
gap?: React.CSSProperties["gap"];
|
|
@@ -16,6 +17,6 @@ type FormProps = {
|
|
|
16
17
|
onSubmit?: (value: React.FormEvent<HTMLFormElement>) => void;
|
|
17
18
|
children?: React.ReactNode;
|
|
18
19
|
} & ComponentMarginProps;
|
|
19
|
-
declare function Form({ form, submitButtonText, submitButtonLoaderName, submitButtonId, actionButtonsLocation, gap, isSubmitting, isDestructive, onClickCancel, onSubmit, children, ...props }: FormProps): import("react/jsx-runtime").JSX.Element;
|
|
20
|
+
declare function Form({ form, submitButtonText, submitButtonLoaderName, submitButtonId, submitButtonIsDisabled, actionButtonsLocation, gap, isSubmitting, isDestructive, onClickCancel, onSubmit, children, ...props }: FormProps): import("react/jsx-runtime").JSX.Element;
|
|
20
21
|
declare const _default: import("react").MemoExoticComponent<typeof Form>;
|
|
21
22
|
export default _default;
|
package/dist/components/Form.js
CHANGED
|
@@ -8,19 +8,20 @@ const react_1 = require("react");
|
|
|
8
8
|
const Div_1 = __importDefault(require("./Div"));
|
|
9
9
|
const Button_1 = __importDefault(require("./Button"));
|
|
10
10
|
const BetterHtmlProvider_1 = require("./BetterHtmlProvider");
|
|
11
|
-
function Form({ form, submitButtonText, submitButtonLoaderName, submitButtonId, actionButtonsLocation = "right", gap, isSubmitting, isDestructive, onClickCancel, onSubmit, children, ...props }) {
|
|
11
|
+
function Form({ form, submitButtonText, submitButtonLoaderName, submitButtonId, submitButtonIsDisabled, actionButtonsLocation = "right", gap, isSubmitting, isDestructive, onClickCancel, onSubmit, children, ...props }) {
|
|
12
12
|
const theme = (0, BetterHtmlProvider_1.useTheme)();
|
|
13
|
-
const
|
|
13
|
+
const submitButtonIsDisabledInternal = (0, react_1.useMemo)(() => {
|
|
14
14
|
if (!form || !form.requiredFields)
|
|
15
15
|
return false;
|
|
16
16
|
return Object.entries(form.values).some(([key, value]) => form.requiredFields?.includes(key) &&
|
|
17
17
|
(value === undefined || value === null || value?.toString().trim() === ""));
|
|
18
18
|
}, [form]);
|
|
19
19
|
const SubmitButtonTag = isDestructive ? Button_1.default.destructive : Button_1.default;
|
|
20
|
+
const submitButtonIsDisabledFinal = submitButtonIsDisabled || submitButtonIsDisabledInternal;
|
|
20
21
|
return ((0, jsx_runtime_1.jsx)(Div_1.default, { ...props, children: (0, jsx_runtime_1.jsxs)("form", { onSubmit: onSubmit, children: [gap !== undefined ? (0, jsx_runtime_1.jsx)(Div_1.default.column, { gap: gap, children: children }) : children, submitButtonText && ((0, jsx_runtime_1.jsxs)(Div_1.default.row, { alignItems: "center", justifyContent: actionButtonsLocation === "left"
|
|
21
22
|
? "flex-start"
|
|
22
23
|
: actionButtonsLocation === "center"
|
|
23
24
|
? "center"
|
|
24
|
-
: "flex-end", gap: theme.styles.gap, marginTop: theme.styles.space, children: [onClickCancel && (0, jsx_runtime_1.jsx)(Button_1.default.secondary, { text: "Cancel", onClick: onClickCancel }), (0, jsx_runtime_1.jsx)(SubmitButtonTag, { text: submitButtonText, isLoading: isSubmitting, loaderName: submitButtonLoaderName, disabled:
|
|
25
|
+
: "flex-end", gap: theme.styles.gap, marginTop: theme.styles.space, children: [onClickCancel && (0, jsx_runtime_1.jsx)(Button_1.default.secondary, { text: "Cancel", onClick: onClickCancel }), (0, jsx_runtime_1.jsx)(SubmitButtonTag, { text: submitButtonText, isLoading: isSubmitting, loaderName: submitButtonLoaderName, disabled: submitButtonIsDisabledFinal, id: submitButtonId, isSubmit: true })] }))] }) }));
|
|
25
26
|
}
|
|
26
27
|
exports.default = (0, react_1.memo)(Form);
|