react-better-html 1.1.27 → 1.1.28

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.
@@ -28,16 +28,12 @@ export type ModalRef = {
28
28
  type ModalComponent = {
29
29
  (props: ComponentPropWithRef<ModalRef, ModalProps>): React.ReactElement;
30
30
  confirmation: (props: ComponentPropWithRef<ModalRef, OmitProps<ModalProps, "maxWidth" | "children" | "overflow"> & {
31
- continueButtonText?: string;
32
31
  continueButtonLoaderName?: LoaderName | AnyOtherString;
33
- cancelButtonText?: string;
34
32
  onContinue?: () => void;
35
33
  onCancel?: () => void;
36
34
  }>) => React.ReactElement;
37
35
  destructive: (props: ComponentPropWithRef<ModalRef, OmitProps<ModalProps, "maxWidth" | "children" | "overflow"> & {
38
- deleteButtonText?: string;
39
36
  deleteButtonLoaderName?: LoaderName | AnyOtherString;
40
- cancelButtonText?: string;
41
37
  onDelete?: () => void;
42
38
  onCancel?: () => void;
43
39
  }>) => React.ReactElement;
@@ -88,13 +88,13 @@ const ModalComponent = (0, react_1.forwardRef)(function Modal({ maxWidth, title,
88
88
  }, [onClickOpen, onClickClose, isOpened]);
89
89
  return ((0, jsx_runtime_1.jsx)(DialogStylesElement, { theme: theme, opacity: !isOpened ? 0 : 1, onClose: onClickClose, ref: dialogRef, children: isOpenedLate ? ((0, jsx_runtime_1.jsx)(Div_1.default.column, { position: "relative", width: "100%", maxWidth: maxWidth ?? app.contentMaxWidth / 1.3, minHeight: `calc(100% - ${theme.styles.space * 2}px)`, alignItems: "center", justifyContent: "center", marginBlock: theme.styles.space, marginInline: "auto", transform: `translateY(${theme.styles.space}px)`, transition: theme.styles.transition, animation: isOpened ? "fadeInAnimation 0.2s ease forwards" : "fadeOutAnimation 0.2s ease forwards", children: (0, jsx_runtime_1.jsxs)(Div_1.default, { position: "relative", width: "100%", minHeight: 32 + theme.styles.space * 2, backgroundColor: theme.colors.backgroundBase, borderRadius: theme.styles.borderRadius * 2, paddingInline: !title ? theme.styles.space + theme.styles.gap : undefined, paddingBlock: !title ? theme.styles.space : undefined, overflow: overflow, children: [title ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)(Div_1.default.row, { alignItems: "center", gap: theme.styles.gap, backgroundColor: headerBackgroundColor, borderTopLeftRadius: theme.styles.borderRadius * 2, borderTopRightRadius: theme.styles.borderRadius * 2, paddingInline: theme.styles.space + theme.styles.gap, paddingBlock: theme.styles.space, children: [(0, jsx_runtime_1.jsxs)(Div_1.default.column, { flex: 1, gap: theme.styles.gap / 2, children: [(0, jsx_runtime_1.jsx)(Text_1.default, { as: "h1", color: titleColor ?? theme.colors.textPrimary, children: title }), description && ((0, jsx_runtime_1.jsx)(Text_1.default, { color: descriptionColor ?? theme.colors.textSecondary, children: description }))] }), (0, jsx_runtime_1.jsx)(Button_1.default.icon, { icon: "XMark", marginTop: 1, iconColor: titleColor, onClick: onClickClose })] }), (0, jsx_runtime_1.jsx)(Divider_1.default.horizontal, {})] })) : ((0, jsx_runtime_1.jsx)(Div_1.default, { position: "absolute", top: theme.styles.space, right: theme.styles.space, children: (0, jsx_runtime_1.jsx)(Button_1.default.icon, { icon: "XMark", onClick: onClickClose }) })), (0, jsx_runtime_1.jsx)(Div_1.default, { paddingInline: title ? theme.styles.space + theme.styles.gap : undefined, paddingBlock: title ? theme.styles.space : undefined, children: children })] }) })) : undefined }));
90
90
  });
91
- ModalComponent.confirmation = (0, react_1.forwardRef)(function Confirmation({ continueButtonText, continueButtonLoaderName, cancelButtonText, onContinue, onCancel, ...props }, ref) {
91
+ ModalComponent.confirmation = (0, react_1.forwardRef)(function Confirmation({ continueButtonLoaderName, onContinue, onCancel, ...props }, ref) {
92
92
  const theme = (0, BetterHtmlProvider_1.useTheme)();
93
- return ((0, jsx_runtime_1.jsxs)(Modal, { title: "Are you sure?", maxWidth: 660, ...props, ref: ref, children: [(0, jsx_runtime_1.jsx)(Text_1.default, { color: theme.colors.textSecondary, children: "Do you really want to continue? This action may be irreversible." }), (0, jsx_runtime_1.jsxs)(Div_1.default.row, { alignItems: "center", justifyContent: "flex-end", gap: theme.styles.gap, marginTop: theme.styles.space * 2, children: [(0, jsx_runtime_1.jsx)(Button_1.default.secondary, { text: cancelButtonText ?? "Cancel", onClick: onCancel }), (0, jsx_runtime_1.jsx)(Button_1.default, { text: continueButtonText ?? "Continue", loaderName: continueButtonLoaderName, onClick: onContinue })] })] }));
93
+ return ((0, jsx_runtime_1.jsxs)(Modal, { title: "Are you sure?", maxWidth: 660, ...props, ref: ref, children: [(0, jsx_runtime_1.jsx)(Text_1.default, { color: theme.colors.textSecondary, children: "Do you really want to continue? This action may be irreversible." }), (0, jsx_runtime_1.jsxs)(Div_1.default.row, { alignItems: "center", justifyContent: "flex-end", gap: theme.styles.gap, marginTop: theme.styles.space * 2, children: [(0, jsx_runtime_1.jsx)(Button_1.default.secondary, { text: "Cancel", onClick: onCancel }), (0, jsx_runtime_1.jsx)(Button_1.default, { text: "Continue", loaderName: continueButtonLoaderName, onClick: onContinue })] })] }));
94
94
  });
95
- ModalComponent.destructive = (0, react_1.forwardRef)(function Destructive({ deleteButtonText, deleteButtonLoaderName, cancelButtonText, onDelete, onCancel, ...props }, ref) {
95
+ ModalComponent.destructive = (0, react_1.forwardRef)(function Destructive({ deleteButtonLoaderName, onDelete, onCancel, ...props }, ref) {
96
96
  const theme = (0, BetterHtmlProvider_1.useTheme)();
97
- return ((0, jsx_runtime_1.jsxs)(Modal, { title: "Are you sure?", maxWidth: 660, ...props, ref: ref, children: [(0, jsx_runtime_1.jsx)(Text_1.default, { color: theme.colors.textSecondary, children: "Do you really want to continue with the deleting of the item? This action may be irreversible." }), (0, jsx_runtime_1.jsxs)(Div_1.default.row, { alignItems: "center", justifyContent: "flex-end", gap: theme.styles.gap, marginTop: theme.styles.space * 2, children: [(0, jsx_runtime_1.jsx)(Button_1.default.secondary, { text: cancelButtonText ?? "Cancel", onClick: onCancel }), (0, jsx_runtime_1.jsx)(Button_1.default.destructive, { icon: "trash", text: deleteButtonText ?? "Delete", loaderName: deleteButtonLoaderName, onClick: onDelete })] })] }));
97
+ return ((0, jsx_runtime_1.jsxs)(Modal, { title: "Are you sure?", maxWidth: 660, ...props, ref: ref, children: [(0, jsx_runtime_1.jsx)(Text_1.default, { color: theme.colors.textSecondary, children: "Do you really want to continue with the deleting of the item? This action may be irreversible." }), (0, jsx_runtime_1.jsxs)(Div_1.default.row, { alignItems: "center", justifyContent: "flex-end", gap: theme.styles.gap, marginTop: theme.styles.space * 2, children: [(0, jsx_runtime_1.jsx)(Button_1.default.secondary, { text: "Cancel", onClick: onCancel }), (0, jsx_runtime_1.jsx)(Button_1.default.destructive, { icon: "trash", text: "Delete", loaderName: deleteButtonLoaderName, onClick: onDelete })] })] }));
98
98
  });
99
99
  const Modal = (0, react_1.memo)(ModalComponent);
100
100
  Modal.confirmation = ModalComponent.confirmation;
@@ -52,6 +52,7 @@ export declare function useForm<FormFields extends Record<string, string | numbe
52
52
  errors: Partial<Record<keyof FormFields, string>>;
53
53
  isSubmitting: boolean;
54
54
  setFieldValue: <FieldName extends keyof FormFields>(field: FieldName, value: FormFields[FieldName] | undefined) => void;
55
+ setFieldsValue: (values: Partial<FormFields>) => void;
55
56
  getInputFieldProps: <FieldName extends keyof FormFields>(field: FieldName) => ComponentPropWithRef<HTMLInputElement, InputFieldProps>;
56
57
  getDropdownFieldProps: <FieldName extends keyof FormFields>(field: FieldName) => OmitProps<ComponentPropWithRef<HTMLDivElement, DropdownProps<FormFields[FieldName], unknown>>, "options">;
57
58
  getCheckboxProps: <FieldName extends keyof FormFields>(field: FieldName) => ComponentPropWithRef<ToggleInputRef, ToggleInputProps<FormFields[FieldName]>>;
@@ -172,6 +172,18 @@ function useForm({ defaultValues, onSubmit, validate, }) {
172
172
  [field]: undefined,
173
173
  }));
174
174
  }, []);
175
+ const setFieldsValue = (0, react_1.useCallback)((values) => {
176
+ setValues((oldValue) => ({
177
+ ...oldValue,
178
+ ...values,
179
+ }));
180
+ setErrors((oldValue) => {
181
+ const newErrors = {};
182
+ for (const key in values)
183
+ newErrors[key] = undefined;
184
+ return newErrors;
185
+ });
186
+ }, []);
175
187
  const getInputFieldProps = (0, react_1.useCallback)((field) => {
176
188
  const type = inputTypes[field] ?? "text";
177
189
  return {
@@ -241,6 +253,7 @@ function useForm({ defaultValues, onSubmit, validate, }) {
241
253
  errors,
242
254
  isSubmitting,
243
255
  setFieldValue,
256
+ setFieldsValue,
244
257
  getInputFieldProps,
245
258
  getDropdownFieldProps,
246
259
  getCheckboxProps,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-better-html",
3
- "version": "1.1.27",
3
+ "version": "1.1.28",
4
4
  "description": "A component library for react that is as close to plane html as possible",
5
5
  "main": "dist/index.js",
6
6
  "files": [