react-better-html 1.1.25 → 1.1.27

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.
@@ -1,5 +1,6 @@
1
1
  import { ComponentPropWithRef } from "../types/components";
2
- import { OmitProps } from "../types/app";
2
+ import { AnyOtherString, OmitProps } from "../types/app";
3
+ import { LoaderName } from "../types/loader";
3
4
  type ModalProps = {
4
5
  /**
5
6
  * If you want to have a small modal, you can use 660px as it looks good on most screens.
@@ -27,10 +28,16 @@ export type ModalRef = {
27
28
  type ModalComponent = {
28
29
  (props: ComponentPropWithRef<ModalRef, ModalProps>): React.ReactElement;
29
30
  confirmation: (props: ComponentPropWithRef<ModalRef, OmitProps<ModalProps, "maxWidth" | "children" | "overflow"> & {
30
- onConfirm?: () => void;
31
+ continueButtonText?: string;
32
+ continueButtonLoaderName?: LoaderName | AnyOtherString;
33
+ cancelButtonText?: string;
34
+ onContinue?: () => void;
31
35
  onCancel?: () => void;
32
36
  }>) => React.ReactElement;
33
37
  destructive: (props: ComponentPropWithRef<ModalRef, OmitProps<ModalProps, "maxWidth" | "children" | "overflow"> & {
38
+ deleteButtonText?: string;
39
+ deleteButtonLoaderName?: LoaderName | AnyOtherString;
40
+ cancelButtonText?: string;
34
41
  onDelete?: () => void;
35
42
  onCancel?: () => void;
36
43
  }>) => 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({ onConfirm, onCancel, ...props }, ref) {
91
+ ModalComponent.confirmation = (0, react_1.forwardRef)(function Confirmation({ continueButtonText, continueButtonLoaderName, cancelButtonText, 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: "Cancel", onClick: onCancel }), (0, jsx_runtime_1.jsx)(Button_1.default, { text: "Continue", onClick: onConfirm })] })] }));
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 })] })] }));
94
94
  });
95
- ModalComponent.destructive = (0, react_1.forwardRef)(function Destructive({ onDelete, onCancel, ...props }, ref) {
95
+ ModalComponent.destructive = (0, react_1.forwardRef)(function Destructive({ deleteButtonText, deleteButtonLoaderName, cancelButtonText, 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: "Cancel", onClick: onCancel }), (0, jsx_runtime_1.jsx)(Button_1.default.destructive, { icon: "trash", text: "Delete", 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: cancelButtonText ?? "Cancel", onClick: onCancel }), (0, jsx_runtime_1.jsx)(Button_1.default.destructive, { icon: "trash", text: deleteButtonText ?? "Delete", loaderName: deleteButtonLoaderName, onClick: onDelete })] })] }));
98
98
  });
99
99
  const Modal = (0, react_1.memo)(ModalComponent);
100
100
  Modal.confirmation = ModalComponent.confirmation;
@@ -16,8 +16,8 @@ const InputElement = styled_components_1.default.input.withConfig({
16
16
  }) `
17
17
  position: relative;
18
18
  appearance: none;
19
- width: 24px;
20
- height: 24px;
19
+ width: 26px;
20
+ height: 26px;
21
21
  background-color: ${(props) => props.theme.colors.backgroundContent};
22
22
  border: 1px solid ${(props) => props.theme.colors.border};
23
23
  border-radius: ${(props) => props.theme.styles.borderRadius / 2}px;
@@ -89,9 +89,15 @@ const ToggleInputComponent = (0, react_1.forwardRef)(function ToggleInput({ labe
89
89
  if (controlledChecked === undefined)
90
90
  setInternalChecked(newValue);
91
91
  onChange?.(newValue, value);
92
- }, [onChange, controlledChecked, value, props.type]);
92
+ }, [onChange, controlledChecked, value]);
93
93
  const checked = controlledChecked ?? internalChecked;
94
- return ((0, jsx_runtime_1.jsxs)(Div_1.default.column, { width: "100%", gap: theme.styles.gap / 2, ...styledComponentStylesWithExcluded, children: [label && ((0, jsx_runtime_1.jsxs)(Text_1.default, { as: "label", height: 16, fontSize: 14, color: errorText ? theme.colors.error : theme.colors.textSecondary, children: [label, required && ((0, jsx_runtime_1.jsxs)(Text_1.default, { as: "span", fontSize: 16, color: theme.colors.error, children: [" ", "*"] }))] })), (0, jsx_runtime_1.jsxs)(Div_1.default.row, { alignItems: "center", gap: theme.styles.gap, children: [(0, jsx_runtime_1.jsxs)(Div_1.default.row, { position: "relative", alignItems: "center", children: [(0, jsx_runtime_1.jsx)(InputElement, { theme: theme, type: props.type ?? "checkbox", checked: checked, onChange: onChangeElement, ...styledComponentStyles, ...dataProps, ...ariaProps, ...restProps }), props.type === "checkbox" ? ((0, jsx_runtime_1.jsx)(Icon_1.default, { name: "check", position: "absolute", top: "50%", left: "50%", color: theme.colors.base, size: 14, transform: `translate(-50%, -50%)${checked ? "" : " scale(0.4)"}`, opacity: checked ? 1 : 0, pointerEvents: "none", transition: theme.styles.transition })) : props.type === "radio" ? ((0, jsx_runtime_1.jsx)(Div_1.default, { position: "absolute", width: 10, height: 10, top: "50%", left: "50%", backgroundColor: theme.colors.base, borderRadius: 999, transform: `translate(-50%, -50%)${checked ? "" : " scale(0.4)"}`, opacity: checked ? 1 : 0, pointerEvents: "none" })) : undefined] }), text && (0, jsx_runtime_1.jsx)(Text_1.default, { children: text })] }), (errorText || infoText) && ((0, jsx_runtime_1.jsx)(Text_1.default, { as: "span", display: "block", fontSize: 14, color: errorText ? theme.colors.error : theme.colors.textSecondary, children: errorText || infoText }))] }));
94
+ const onClickText = (0, react_1.useCallback)(() => {
95
+ const newValue = !checked;
96
+ if (controlledChecked === undefined)
97
+ setInternalChecked(newValue);
98
+ onChange?.(newValue, value);
99
+ }, [checked, controlledChecked, onChange, value]);
100
+ return ((0, jsx_runtime_1.jsxs)(Div_1.default.column, { width: "100%", gap: theme.styles.gap / 2, ...styledComponentStylesWithExcluded, children: [label && ((0, jsx_runtime_1.jsxs)(Text_1.default, { as: "label", height: 16, fontSize: 14, color: errorText ? theme.colors.error : theme.colors.textSecondary, children: [label, required && ((0, jsx_runtime_1.jsxs)(Text_1.default, { as: "span", fontSize: 16, color: theme.colors.error, children: [" ", "*"] }))] })), (0, jsx_runtime_1.jsxs)(Div_1.default.row, { alignItems: "center", gap: theme.styles.gap, children: [(0, jsx_runtime_1.jsxs)(Div_1.default.row, { position: "relative", alignItems: "center", children: [(0, jsx_runtime_1.jsx)(InputElement, { theme: theme, type: props.type ?? "checkbox", checked: checked, onChange: onChangeElement, ...styledComponentStyles, ...dataProps, ...ariaProps, ...restProps }), props.type === "checkbox" ? ((0, jsx_runtime_1.jsx)(Icon_1.default, { name: "check", position: "absolute", top: "50%", left: "50%", color: theme.colors.base, size: 14, transform: `translate(-50%, -50%)${checked ? "" : " scale(0.4)"}`, opacity: checked ? 1 : 0, pointerEvents: "none", transition: theme.styles.transition })) : props.type === "radio" ? ((0, jsx_runtime_1.jsx)(Div_1.default, { position: "absolute", width: 10, height: 10, top: "50%", left: "50%", backgroundColor: theme.colors.base, borderRadius: 999, transform: `translate(-50%, -50%)${checked ? "" : " scale(0.4)"}`, opacity: checked ? 1 : 0, pointerEvents: "none" })) : undefined] }), text && ((0, jsx_runtime_1.jsx)(Text_1.default, { userSelect: "none", cursor: "pointer", onClick: onClickText, children: text }))] }), (errorText || infoText) && ((0, jsx_runtime_1.jsx)(Text_1.default, { as: "span", display: "block", fontSize: 14, color: errorText ? theme.colors.error : theme.colors.textSecondary, children: errorText || infoText }))] }));
95
101
  });
96
102
  exports.default = {
97
103
  checkbox: (0, react_1.forwardRef)(function Checkbox(props, ref) {
@@ -204,7 +204,7 @@ function useForm({ defaultValues, onSubmit, validate, }) {
204
204
  }, [values, errors, setFieldValue]);
205
205
  const getCheckboxProps = (0, react_1.useCallback)((field) => {
206
206
  return {
207
- value: values[field],
207
+ checked: values[field],
208
208
  onChange: (checked) => {
209
209
  setFieldValue(field, checked);
210
210
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-better-html",
3
- "version": "1.1.25",
3
+ "version": "1.1.27",
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": [