react-better-html 1.1.16 → 1.1.18

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.
@@ -131,6 +131,9 @@ function BetterHtmlProvider({ value, children }) {
131
131
  },
132
132
  loaders,
133
133
  setLoaders,
134
+ components: {
135
+ ...value?.components,
136
+ },
134
137
  }), [value, loaders]);
135
138
  return ((0, jsx_runtime_1.jsx)(betterHtmlContext.Provider, { value: readyValue, children: (0, jsx_runtime_1.jsx)(BetterHtmlProviderContent, { children: children }) }));
136
139
  }
@@ -4,7 +4,7 @@ import { AssetName } from "../types/asset";
4
4
  import { LoaderName } from "../types/loader";
5
5
  import { AnyOtherString, OmitProps } from "../types/app";
6
6
  import { ComponentHoverStyle, ComponentStyle } from "../types/components";
7
- type ButtonProps<Value> = {
7
+ export type ButtonProps<Value> = {
8
8
  href?: string;
9
9
  text?: string;
10
10
  value?: Value;
@@ -34,7 +34,7 @@ type ButtonProps<Value> = {
34
34
  /** @default false */
35
35
  isSubmit?: boolean;
36
36
  onClickWithValue?: (value: Value) => void;
37
- } & OmitProps<React.ComponentProps<"button">, "style" | "defaultValue"> & ComponentStyle & ComponentHoverStyle;
37
+ } & OmitProps<React.ComponentProps<"button">, "style" | "defaultValue" | "translate"> & ComponentStyle & ComponentHoverStyle;
38
38
  type ButtonComponent = {
39
39
  <Value>(props: ButtonProps<Value>): React.ReactElement;
40
40
  secondary: <Value>(props: ButtonProps<Value>) => React.ReactElement;
@@ -107,8 +107,12 @@ const ButtonElement = styled_components_1.default.button.withConfig({
107
107
  const ButtonComponent = function Button({ href, text, value, icon, iconPosition = "left", iconColor, iconSize, image, imagePosition = "left", imageWidth, imageHeight, loaderName, loaderSize, isLoading, disabled, isSmall, isSubmit, onClick, onClickWithValue, ...props }) {
108
108
  const theme = (0, BetterHtmlProvider_1.useTheme)();
109
109
  const isLoadingHook = (0, BetterHtmlProvider_1.useLoader)(loaderName);
110
+ const betterHtmlContext = (0, BetterHtmlProvider_1.useBetterHtmlContext)();
110
111
  const isLoadingElement = isLoading ?? isLoadingHook;
111
- const styledComponentStyles = (0, hooks_1.useStyledComponentStyles)(props, theme);
112
+ const styledComponentStyles = (0, hooks_1.useStyledComponentStyles)({
113
+ ...betterHtmlContext.components.button?.default,
114
+ ...props,
115
+ }, theme);
112
116
  const dataProps = (0, hooks_1.useComponentPropsWithPrefix)(props, "data");
113
117
  const ariaProps = (0, hooks_1.useComponentPropsWithPrefix)(props, "aria");
114
118
  const restProps = (0, hooks_1.useComponentPropsWithoutStyle)(props);
@@ -118,23 +122,27 @@ const ButtonComponent = function Button({ href, text, value, icon, iconPosition
118
122
  }, [onClick, onClickWithValue, value]);
119
123
  const iconComponent = icon ? ((0, jsx_runtime_1.jsx)(Div_1.default.row, { height: 20, alignItems: "center", justifyContent: "center", children: (0, jsx_runtime_1.jsx)(Icon_1.default, { name: icon, color: iconColor ?? props.color ?? theme.colors.base, size: iconSize ?? parseInt(styledComponentStyles.normalStyle.fontSize?.toString() ?? "16") }) })) : undefined;
120
124
  const imageComponent = image ? ((0, jsx_runtime_1.jsx)(Image_1.default, { name: image, color: iconColor ?? props.color ?? theme.colors.base, width: imageWidth ?? parseInt(styledComponentStyles.normalStyle.fontSize?.toString() ?? "16"), height: imageHeight })) : undefined;
121
- return ((0, jsx_runtime_1.jsxs)(ButtonElement, { as: href ? "a" : "button", theme: theme, isSmall: isSmall, withText: text !== undefined, isLoading: isLoadingElement, disabled: disabled, href: href, type: isSubmit && !isLoadingElement ? "submit" : "button", onClick: !disabled && !isLoadingElement ? onClickElement : undefined, ...styledComponentStyles, ...dataProps, ...ariaProps, ...restProps, children: [(0, jsx_runtime_1.jsxs)(Div_1.default.row, { alignItems: "center", justifyContent: "center", gap: 10, pointerEvents: "none", opacity: isLoadingElement ? 0 : 1, transition: theme.styles.transition, children: [iconPosition === "left" && iconComponent, imagePosition === "left" && imageComponent, text, iconPosition === "right" && iconComponent, imagePosition === "right" && imageComponent] }), (0, jsx_runtime_1.jsx)(Div_1.default.row, { position: "absolute", width: "100%", height: "100%", top: 0, left: 0, pointerEvents: "none", alignItems: "center", justifyContent: "center", opacity: isLoadingElement ? 1 : 0, transition: theme.styles.transition, children: (0, jsx_runtime_1.jsx)(Loader_1.default, { color: props.color ?? theme.colors.base, size: loaderSize, disabled: !isLoadingElement }) })] }));
125
+ return ((0, jsx_runtime_1.jsxs)(ButtonElement, { as: (href ? "a" : "button"), theme: theme, isSmall: isSmall, withText: text !== undefined, isLoading: isLoadingElement, disabled: disabled, href: href, type: isSubmit && !isLoadingElement ? "submit" : "button", onClick: !disabled && !isLoadingElement ? onClickElement : undefined, ...styledComponentStyles, ...dataProps, ...ariaProps, ...restProps, children: [(0, jsx_runtime_1.jsxs)(Div_1.default.row, { alignItems: "center", justifyContent: "center", gap: 10, pointerEvents: "none", opacity: isLoadingElement ? 0 : 1, transition: theme.styles.transition, children: [iconPosition === "left" && iconComponent, imagePosition === "left" && imageComponent, text, iconPosition === "right" && iconComponent, imagePosition === "right" && imageComponent] }), (0, jsx_runtime_1.jsx)(Div_1.default.row, { position: "absolute", width: "100%", height: "100%", top: 0, left: 0, pointerEvents: "none", alignItems: "center", justifyContent: "center", opacity: isLoadingElement ? 1 : 0, transition: theme.styles.transition, children: (0, jsx_runtime_1.jsx)(Loader_1.default, { color: props.color ?? theme.colors.base, size: loaderSize, disabled: !isLoadingElement }) })] }));
122
126
  };
123
127
  ButtonComponent.secondary = function Secondary({ className, ...props }) {
124
128
  const theme = (0, BetterHtmlProvider_1.useTheme)();
125
- return ((0, jsx_runtime_1.jsx)(ButtonComponent, { className: `secondary${className ? ` ${className}` : ""}`, color: theme.colors.textPrimary, ...props }));
129
+ const betterHtmlContext = (0, BetterHtmlProvider_1.useBetterHtmlContext)();
130
+ return ((0, jsx_runtime_1.jsx)(ButtonComponent, { ...betterHtmlContext.components.button?.secondary, className: `secondary${className ? ` ${className}` : ""}`, color: theme.colors.textPrimary, ...props }));
126
131
  };
127
132
  ButtonComponent.destructive = function Destructive(props) {
128
133
  const theme = (0, BetterHtmlProvider_1.useTheme)();
129
- return (0, jsx_runtime_1.jsx)(ButtonComponent, { backgroundColor: theme.colors.error, color: theme.colors.base, ...props });
134
+ const betterHtmlContext = (0, BetterHtmlProvider_1.useBetterHtmlContext)();
135
+ return ((0, jsx_runtime_1.jsx)(ButtonComponent, { ...betterHtmlContext.components.button?.destructive, backgroundColor: theme.colors.error, color: theme.colors.base, ...props }));
130
136
  };
131
137
  ButtonComponent.icon = function Icon({ size = 16, backgroundButtonColor, ...props }) {
132
138
  const theme = (0, BetterHtmlProvider_1.useTheme)();
139
+ const betterHtmlContext = (0, BetterHtmlProvider_1.useBetterHtmlContext)();
133
140
  const buttonSize = size + theme.styles.space;
134
141
  const backgroundButtonColorReady = backgroundButtonColor ?? theme.colors.textPrimary;
135
- return ((0, jsx_runtime_1.jsx)(ButtonComponent, { width: buttonSize, height: buttonSize, color: theme.colors.textPrimary, backgroundColor: backgroundButtonColorReady + "00", backgroundImage: "none", backgroundColorHover: backgroundButtonColorReady + "20", borderRadius: 999, iconSize: size, loaderSize: 12, border: "none", padding: 0, filterHover: "none !important", ...props }));
142
+ return ((0, jsx_runtime_1.jsx)(ButtonComponent, { ...betterHtmlContext.components.button?.icon, width: buttonSize, height: buttonSize, color: theme.colors.textPrimary, backgroundColor: backgroundButtonColorReady + "00", backgroundImage: "none", backgroundColorHover: backgroundButtonColorReady + "20", borderRadius: 999, iconSize: size, loaderSize: 12, border: "none", padding: 0, filterHover: "none !important", ...props }));
136
143
  };
137
144
  ButtonComponent.upload = function Upload({ accept, multiple, onUpload, ...props }) {
145
+ const betterHtmlContext = (0, BetterHtmlProvider_1.useBetterHtmlContext)();
138
146
  const onClickElement = (0, react_1.useCallback)(() => {
139
147
  const input = document.createElement("input");
140
148
  input.setAttribute("type", "file");
@@ -147,7 +155,7 @@ ButtonComponent.upload = function Upload({ accept, multiple, onUpload, ...props
147
155
  });
148
156
  input.click();
149
157
  }, [accept]);
150
- return (0, jsx_runtime_1.jsx)(ButtonComponent, { text: "Upload", icon: "uploadCloud", onClick: onClickElement, ...props });
158
+ return ((0, jsx_runtime_1.jsx)(ButtonComponent, { ...betterHtmlContext.components.button?.upload, text: "Upload", icon: "uploadCloud", onClick: onClickElement, ...props }));
151
159
  };
152
160
  const Button = (0, react_1.memo)(ButtonComponent);
153
161
  Button.secondary = ButtonComponent.secondary;
@@ -10,6 +10,6 @@ const BetterHtmlProvider_1 = require("./BetterHtmlProvider");
10
10
  function PageHolder({ noMaxContentWidth, children }) {
11
11
  const theme = (0, BetterHtmlProvider_1.useTheme)();
12
12
  const { app } = (0, BetterHtmlProvider_1.useBetterHtmlContext)();
13
- return ((0, jsx_runtime_1.jsx)(Div_1.default, { as: "main", width: "100%", maxWidth: !noMaxContentWidth ? app.contentMaxWidth : undefined, margin: "0px auto", paddingBlock: theme.styles.gap, paddingInline: theme.styles.space, children: children }));
13
+ return ((0, jsx_runtime_1.jsx)(Div_1.default, { as: "main", width: "100%", maxWidth: !noMaxContentWidth ? app.contentMaxWidth : undefined, margin: "0px auto", padding: theme.styles.space, children: children }));
14
14
  }
15
15
  exports.default = (0, react_1.memo)(PageHolder);
@@ -0,0 +1 @@
1
+ export declare const cssProps: Record<string, boolean>;