react-better-html 1.1.72 → 1.1.74

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.
Files changed (97) hide show
  1. package/dist/index.d.mts +686 -0
  2. package/dist/index.d.ts +686 -34
  3. package/dist/index.js +6302 -101
  4. package/dist/index.js.map +1 -0
  5. package/dist/index.mjs +6231 -0
  6. package/dist/index.mjs.map +1 -0
  7. package/package.json +4 -3
  8. package/dist/components/BetterHtmlProvider.d.ts +0 -29
  9. package/dist/components/BetterHtmlProvider.js +0 -161
  10. package/dist/components/Button.d.ts +0 -65
  11. package/dist/components/Button.js +0 -166
  12. package/dist/components/Chip.d.ts +0 -20
  13. package/dist/components/Chip.js +0 -20
  14. package/dist/components/ColorThemeSwitch.d.ts +0 -15
  15. package/dist/components/ColorThemeSwitch.js +0 -54
  16. package/dist/components/Div.d.ts +0 -30
  17. package/dist/components/Div.js +0 -60
  18. package/dist/components/Divider.d.ts +0 -21
  19. package/dist/components/Divider.js +0 -20
  20. package/dist/components/Dropdown.d.ts +0 -48
  21. package/dist/components/Dropdown.js +0 -160
  22. package/dist/components/ExampleComponent.d.ts +0 -5
  23. package/dist/components/ExampleComponent.js +0 -10
  24. package/dist/components/Form.d.ts +0 -25
  25. package/dist/components/Form.js +0 -27
  26. package/dist/components/FormRow.d.ts +0 -32
  27. package/dist/components/FormRow.js +0 -28
  28. package/dist/components/Icon.d.ts +0 -13
  29. package/dist/components/Icon.js +0 -36
  30. package/dist/components/Image.d.ts +0 -18
  31. package/dist/components/Image.js +0 -44
  32. package/dist/components/InputField.d.ts +0 -44
  33. package/dist/components/InputField.js +0 -270
  34. package/dist/components/Label.d.ts +0 -11
  35. package/dist/components/Label.js +0 -14
  36. package/dist/components/Loader.d.ts +0 -34
  37. package/dist/components/Loader.js +0 -43
  38. package/dist/components/Modal.d.ts +0 -46
  39. package/dist/components/Modal.js +0 -123
  40. package/dist/components/PageHeader.d.ts +0 -18
  41. package/dist/components/PageHeader.js +0 -19
  42. package/dist/components/PageHolder.d.ts +0 -8
  43. package/dist/components/PageHolder.js +0 -15
  44. package/dist/components/Table.d.ts +0 -45
  45. package/dist/components/Table.js +0 -159
  46. package/dist/components/Text.d.ts +0 -18
  47. package/dist/components/Text.js +0 -38
  48. package/dist/components/ToggleInput.d.ts +0 -20
  49. package/dist/components/ToggleInput.js +0 -161
  50. package/dist/constants/app.d.ts +0 -2
  51. package/dist/constants/app.js +0 -6
  52. package/dist/constants/assets.d.ts +0 -2
  53. package/dist/constants/assets.js +0 -6
  54. package/dist/constants/countries.d.ts +0 -2
  55. package/dist/constants/countries.js +0 -1482
  56. package/dist/constants/css.d.ts +0 -1
  57. package/dist/constants/css.js +0 -1291
  58. package/dist/constants/icons.d.ts +0 -2
  59. package/dist/constants/icons.js +0 -85
  60. package/dist/constants/theme.d.ts +0 -2
  61. package/dist/constants/theme.js +0 -50
  62. package/dist/constants.d.ts +0 -1
  63. package/dist/constants.js +0 -4
  64. package/dist/plugins/index.d.ts +0 -1
  65. package/dist/plugins/index.js +0 -17
  66. package/dist/plugins/react-router-dom.d.ts +0 -2
  67. package/dist/plugins/react-router-dom.js +0 -14
  68. package/dist/types/app.d.ts +0 -15
  69. package/dist/types/app.js +0 -2
  70. package/dist/types/asset.d.ts +0 -4
  71. package/dist/types/asset.js +0 -2
  72. package/dist/types/components.d.ts +0 -13
  73. package/dist/types/components.js +0 -2
  74. package/dist/types/config.d.ts +0 -23
  75. package/dist/types/config.js +0 -2
  76. package/dist/types/countries.d.ts +0 -7
  77. package/dist/types/countries.js +0 -2
  78. package/dist/types/icon.d.ts +0 -11
  79. package/dist/types/icon.js +0 -2
  80. package/dist/types/loader.d.ts +0 -4
  81. package/dist/types/loader.js +0 -2
  82. package/dist/types/other.d.ts +0 -1
  83. package/dist/types/other.js +0 -2
  84. package/dist/types/plugin.d.ts +0 -7
  85. package/dist/types/plugin.js +0 -2
  86. package/dist/types/theme.d.ts +0 -19
  87. package/dist/types/theme.js +0 -2
  88. package/dist/utils/functions.d.ts +0 -16
  89. package/dist/utils/functions.js +0 -77
  90. package/dist/utils/hooks.d.ts +0 -86
  91. package/dist/utils/hooks.js +0 -450
  92. package/dist/utils/logger.d.ts +0 -41
  93. package/dist/utils/logger.js +0 -66
  94. package/dist/utils/variableFunctions.d.ts +0 -6
  95. package/dist/utils/variableFunctions.js +0 -28
  96. package/dist/utils/withPlugin.d.ts +0 -4
  97. package/dist/utils/withPlugin.js +0 -15
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-better-html",
3
- "version": "1.1.72",
3
+ "version": "1.1.74",
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": [
@@ -23,7 +23,7 @@
23
23
  "scripts": {
24
24
  "clean": "rimraf dist",
25
25
  "prebuild": "npm run clean",
26
- "build": "tsc",
26
+ "build": "tsup",
27
27
  "predeploy": "npm run build",
28
28
  "deploy": "npm publish"
29
29
  },
@@ -39,12 +39,13 @@
39
39
  "devDependencies": {
40
40
  "@types/react": "^19.0.10",
41
41
  "rimraf": "^6.0.1",
42
+ "tsup": "^8.5.0",
42
43
  "typescript": "^5.5.3"
43
44
  },
44
45
  "peerDependencies": {
45
46
  "react": "^19.0.0",
46
- "react-router-dom": "^7.6.0",
47
47
  "react-dom": "^19.1.0",
48
+ "react-router-dom": "^7.6.0",
48
49
  "styled-components": "^6.1.15"
49
50
  }
50
51
  }
@@ -1,29 +0,0 @@
1
- import { BetterHtmlConfig } from "../types/config";
2
- import { AnyOtherString, DeepPartialRecord, OmitProps } from "../types/app";
3
- import { LoaderConfig, LoaderName } from "../types/loader";
4
- import { BetterHtmlPlugin, PluginName } from "../types/plugin";
5
- export type BetterHtmlInternalConfig = BetterHtmlConfig & {
6
- setLoaders: React.Dispatch<React.SetStateAction<Partial<LoaderConfig>>>;
7
- plugins: BetterHtmlPlugin[];
8
- };
9
- export declare let externalBetterHtmlContextValue: BetterHtmlInternalConfig | undefined;
10
- export declare const useBetterHtmlContext: () => BetterHtmlConfig;
11
- export declare const useTheme: () => {
12
- colors: import("../types/theme").Colors;
13
- styles: import("../types/theme").Styles;
14
- };
15
- export declare const useLoader: (loaderName?: LoaderName | AnyOtherString) => boolean;
16
- export declare const useLoaderControls: () => {
17
- startLoading: (loaderName: LoaderName | AnyOtherString) => void;
18
- stopLoading: (loaderName: LoaderName | AnyOtherString) => void;
19
- };
20
- export declare const usePlugin: (pluginName: PluginName) => BetterHtmlPlugin | undefined;
21
- export type BetterHtmlProviderValue = DeepPartialRecord<OmitProps<BetterHtmlConfig, "colorTheme">>;
22
- type BetterHtmlProviderProps = {
23
- value?: BetterHtmlProviderValue;
24
- plugins?: BetterHtmlPlugin[];
25
- children?: React.ReactNode;
26
- };
27
- declare function BetterHtmlProvider({ value, plugins: pluginsToUse, children }: BetterHtmlProviderProps): import("react/jsx-runtime").JSX.Element;
28
- declare const _default: import("react").MemoExoticComponent<typeof BetterHtmlProvider>;
29
- export default _default;
@@ -1,161 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.usePlugin = exports.useLoaderControls = exports.useLoader = exports.useTheme = exports.useBetterHtmlContext = exports.externalBetterHtmlContextValue = void 0;
4
- const jsx_runtime_1 = require("react/jsx-runtime");
5
- const react_1 = require("react");
6
- const styled_components_1 = require("styled-components");
7
- const theme_1 = require("../constants/theme");
8
- const icons_1 = require("../constants/icons");
9
- const assets_1 = require("../constants/assets");
10
- const app_1 = require("../constants/app");
11
- const GlobalStyle = (0, styled_components_1.createGlobalStyle) `
12
- body {
13
- font-family: ${(props) => props.fontFamily};
14
- color: ${(props) => props.color};
15
- background-color: ${(props) => props.backgroundColor};
16
- }
17
-
18
- * {
19
- box-sizing: border-box;
20
- margin: 0;
21
- padding: 0;
22
- -webkit-tap-highlight-color: transparent;
23
- }
24
-
25
- a {
26
- text-decoration: none;
27
- color: inherit;
28
- }
29
-
30
- .react-better-html-no-scrollbar::-webkit-scrollbar {
31
- display: none;
32
- }
33
- `;
34
- const betterHtmlContext = (0, react_1.createContext)(undefined);
35
- const useBetterHtmlContext = () => {
36
- const context = (0, react_1.useContext)(betterHtmlContext);
37
- if (context === undefined)
38
- throw new Error("`useBetterHtmlContext()` must be used within a `<BetterHtmlProvider>`. Make sure to add one at the root of your component tree.");
39
- const { setLoaders, plugins, ...rest } = context;
40
- return rest;
41
- };
42
- exports.useBetterHtmlContext = useBetterHtmlContext;
43
- const useTheme = () => {
44
- const context = (0, react_1.useContext)(betterHtmlContext);
45
- if (context === undefined)
46
- throw new Error("`useTheme()` must be used within a `<BetterHtmlProvider>`. Make sure to add one at the root of your component tree.");
47
- return {
48
- ...context.theme,
49
- colors: context.theme.colors[context.colorTheme] ?? context.theme.colors.light,
50
- };
51
- };
52
- exports.useTheme = useTheme;
53
- const useLoader = (loaderName) => {
54
- const context = (0, react_1.useContext)(betterHtmlContext);
55
- if (context === undefined)
56
- throw new Error("`useLoader()` must be used within a `<BetterHtmlProvider>`. Make sure to add one at the root of your component tree.");
57
- return loaderName ? context.loaders[loaderName.toString()] ?? false : false;
58
- };
59
- exports.useLoader = useLoader;
60
- const useLoaderControls = () => {
61
- const context = (0, react_1.useContext)(betterHtmlContext);
62
- if (context === undefined)
63
- throw new Error("`useLoaderControls()` must be used within a `<BetterHtmlProvider>`. Make sure to add one at the root of your component tree.");
64
- const startLoading = (0, react_1.useCallback)((loaderName) => {
65
- context.setLoaders((oldValue) => ({
66
- ...oldValue,
67
- [loaderName.toString()]: true,
68
- }));
69
- }, []);
70
- const stopLoading = (0, react_1.useCallback)((loaderName) => {
71
- context.setLoaders((oldValue) => ({
72
- ...oldValue,
73
- [loaderName.toString()]: false,
74
- }));
75
- }, []);
76
- return {
77
- startLoading,
78
- stopLoading,
79
- };
80
- };
81
- exports.useLoaderControls = useLoaderControls;
82
- const usePlugin = (pluginName) => {
83
- const context = (0, react_1.useContext)(betterHtmlContext);
84
- if (context === undefined) {
85
- throw new Error("`usePlugin()` must be used within a `<BetterHtmlProvider>`. Make sure to add one at the root of your component tree.");
86
- }
87
- return context.plugins.find((plugin) => plugin.name === pluginName);
88
- };
89
- exports.usePlugin = usePlugin;
90
- function BetterHtmlProviderContent({ children }) {
91
- const theme = (0, exports.useTheme)();
92
- return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(GlobalStyle, { fontFamily: theme.styles.fontFamily, color: theme.colors.textPrimary, backgroundColor: theme.colors.backgroundBase }), children] }));
93
- }
94
- function BetterHtmlProvider({ value, plugins: pluginsToUse, children }) {
95
- const [loaders, setLoaders] = (0, react_1.useState)(value?.loaders ?? {});
96
- const [plugins] = (0, react_1.useState)(pluginsToUse ?? []);
97
- const [colorTheme, setColorTheme] = (0, react_1.useState)(localStorage.getItem("theme") === "dark" ? "dark" : "light");
98
- const readyValue = (0, react_1.useMemo)(() => ({
99
- app: {
100
- ...app_1.appConfig,
101
- ...value?.app,
102
- },
103
- theme: {
104
- styles: {
105
- ...theme_1.theme.styles,
106
- ...value?.theme?.styles,
107
- },
108
- colors: {
109
- light: {
110
- ...theme_1.theme.colors.light,
111
- ...value?.theme?.colors?.light,
112
- },
113
- dark: {
114
- ...theme_1.theme.colors.dark,
115
- ...value?.theme?.colors?.dark,
116
- },
117
- },
118
- },
119
- colorTheme,
120
- icons: {
121
- ...icons_1.icons,
122
- ...value?.icons,
123
- },
124
- assets: {
125
- ...assets_1.assets,
126
- ...value?.assets,
127
- },
128
- loaders,
129
- setLoaders,
130
- components: {
131
- ...value?.components,
132
- },
133
- plugins,
134
- }), [value, colorTheme, loaders, plugins]);
135
- (0, react_1.useEffect)(() => {
136
- plugins.forEach((plugin) => {
137
- plugin.initialize?.();
138
- });
139
- }, [plugins]);
140
- (0, react_1.useEffect)(() => {
141
- const html = document.querySelector("html");
142
- if (!html)
143
- return;
144
- const observer = new MutationObserver((mutations) => {
145
- mutations.forEach((mutation) => {
146
- if (mutation.type === "attributes") {
147
- setColorTheme(html.getAttribute("data-theme") === "dark" ? "dark" : "light");
148
- }
149
- });
150
- });
151
- observer.observe(html, {
152
- attributes: true,
153
- });
154
- return () => {
155
- observer.disconnect();
156
- };
157
- }, []);
158
- exports.externalBetterHtmlContextValue = readyValue;
159
- return ((0, jsx_runtime_1.jsx)(betterHtmlContext.Provider, { value: readyValue, children: (0, jsx_runtime_1.jsx)(BetterHtmlProviderContent, { children: children }) }));
160
- }
161
- exports.default = (0, react_1.memo)(BetterHtmlProvider);
@@ -1,65 +0,0 @@
1
- import { ComponentProps } from "react";
2
- import { IconName } from "../types/icon";
3
- import { AssetName } from "../types/asset";
4
- import { LoaderName } from "../types/loader";
5
- import { AnyOtherString, OmitProps } from "../types/app";
6
- import { ComponentHoverStyle, ComponentStyle } from "../types/components";
7
- export type ButtonProps<Value> = {
8
- text?: string;
9
- value?: Value;
10
- href?: string;
11
- download?: string;
12
- target?: React.ComponentProps<"a">["target"];
13
- icon?: IconName | AnyOtherString;
14
- /** @default "left" */
15
- iconPosition?: "left" | "right";
16
- /** @default Same as text color */
17
- iconColor?: string;
18
- /** @default 16 */
19
- iconSize?: number;
20
- image?: AssetName | AnyOtherString;
21
- /** @default "left" */
22
- imagePosition?: "left" | "right";
23
- /** @default 16 */
24
- imageWidth?: number;
25
- /** @default undefined */
26
- imageHeight?: number;
27
- loaderName?: LoaderName | AnyOtherString;
28
- /** @default 16 */
29
- loaderSize?: number;
30
- /** @default false */
31
- isLoading?: boolean;
32
- /** @default false */
33
- disabled?: boolean;
34
- /** @default false */
35
- isSmall?: boolean;
36
- /** @default false */
37
- isSubmit?: boolean;
38
- onClickWithValue?: (value: Value) => void;
39
- } & OmitProps<React.ComponentProps<"button">, "style" | "defaultValue" | "translate" | "value"> & ComponentStyle & ComponentHoverStyle;
40
- type ButtonComponent = {
41
- <Value>(props: ButtonProps<Value>): React.ReactElement;
42
- secondary: <Value>(props: ButtonProps<Value>) => React.ReactElement;
43
- destructive: <Value>(props: ButtonProps<Value>) => React.ReactElement;
44
- icon: <Value>(props: OmitProps<ButtonProps<Value>, "icon" | "width" | "height" | "isSmall"> & {
45
- icon: IconName | AnyOtherString;
46
- /** @default 16 */
47
- size?: number;
48
- /** @default "#000000" */
49
- backgroundButtonColor?: string;
50
- }) => React.ReactElement;
51
- upload: <Value>(props: OmitProps<ButtonProps<Value>, "onClick"> & {
52
- accept?: ComponentProps<"input">["accept"];
53
- /** @default false */
54
- multiple?: boolean;
55
- onUpload?: (files: FileList | null) => void;
56
- }) => React.ReactElement;
57
- };
58
- declare const ButtonComponent: ButtonComponent;
59
- declare const Button: typeof ButtonComponent & {
60
- secondary: typeof ButtonComponent.secondary;
61
- destructive: typeof ButtonComponent.destructive;
62
- icon: typeof ButtonComponent.icon;
63
- upload: typeof ButtonComponent.upload;
64
- };
65
- export default Button;
@@ -1,166 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- var __importDefault = (this && this.__importDefault) || function (mod) {
36
- return (mod && mod.__esModule) ? mod : { "default": mod };
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- const jsx_runtime_1 = require("react/jsx-runtime");
40
- const react_1 = require("react");
41
- const styled_components_1 = __importStar(require("styled-components"));
42
- const hooks_1 = require("../utils/hooks");
43
- const Div_1 = __importDefault(require("./Div"));
44
- const Icon_1 = __importDefault(require("./Icon"));
45
- const Loader_1 = __importDefault(require("./Loader"));
46
- const Image_1 = __importDefault(require("./Image"));
47
- const BetterHtmlProvider_1 = require("./BetterHtmlProvider");
48
- const ButtonElement = styled_components_1.default.button.withConfig({
49
- shouldForwardProp: (prop) => !["theme", "normalStyle", "hoverStyle", "isSmall", "withText", "isLoading"].includes(prop),
50
- }) `
51
- display: block;
52
- position: relative;
53
- width: fit-content;
54
- min-width: max-content;
55
- font-family: ${(props) => props.theme.styles.fontFamily};
56
- font-size: 16px;
57
- line-height: 20px;
58
- text-decoration: none;
59
- color: ${(props) => props.theme.colors.base};
60
- background-color: ${(props) => props.theme.colors.primary};
61
- border: none;
62
- border-radius: ${(props) => props.theme.styles.borderRadius}px;
63
- padding: ${(props) => props.isSmall
64
- ? `${props.theme.styles.gap + 1}px ${props.theme.styles.space}px`
65
- : `${(props.theme.styles.gap + props.theme.styles.space) / 2 + 1}px ${props.theme.styles.space + (props.withText ? props.theme.styles.gap : 0)}px`};
66
- user-select: none;
67
- flex-shrink: 0;
68
- transition: ${(props) => props.theme.styles.transition};
69
-
70
- ${(props) => props.disabled
71
- ? (0, styled_components_1.css) `
72
- opacity: 0.6;
73
- cursor: not-allowed;
74
-
75
- &.secondary:disabled {
76
- filter: brightness(0.9);
77
- }
78
- `
79
- : !props.isLoading
80
- ? (0, styled_components_1.css) `
81
- cursor: pointer;
82
-
83
- &:not(.secondary):hover {
84
- filter: brightness(0.9);
85
- }
86
-
87
- &.secondary:hover {
88
- border-color: ${props.theme.colors.primary};
89
- }
90
- `
91
- : ""}
92
-
93
- &.secondary {
94
- padding-block: ${(props) => props.isSmall ? props.theme.styles.gap : (props.theme.styles.space + props.theme.styles.gap) / 2}px;
95
- border: solid 1px ${(props) => props.theme.colors.border};
96
- background-color: ${(props) => props.theme.colors.backgroundContent};
97
- background-image: none;
98
-
99
- ${(props) => props.normalStyle}
100
- }
101
-
102
- ${(props) => props.normalStyle}
103
-
104
- &:hover {
105
- ${(props) => props.hoverStyle}
106
- }
107
- `;
108
- const ButtonComponent = function Button({ href, text, value, download, target, icon, iconPosition = "left", iconColor, iconSize, image, imagePosition = "left", imageWidth, imageHeight, loaderName, loaderSize, isLoading, disabled, isSmall, isSubmit, onClick, onClickWithValue, ...props }) {
109
- const theme = (0, BetterHtmlProvider_1.useTheme)();
110
- const isLoadingHook = (0, BetterHtmlProvider_1.useLoader)(loaderName);
111
- const betterHtmlContext = (0, BetterHtmlProvider_1.useBetterHtmlContext)();
112
- const isLoadingElement = isLoading ?? isLoadingHook;
113
- const styledComponentStyles = (0, hooks_1.useStyledComponentStyles)({
114
- ...betterHtmlContext.components.button?.default,
115
- ...props,
116
- }, theme);
117
- const dataProps = (0, hooks_1.useComponentPropsWithPrefix)(props, "data");
118
- const ariaProps = (0, hooks_1.useComponentPropsWithPrefix)(props, "aria");
119
- const restProps = (0, hooks_1.useComponentPropsWithoutStyle)(props);
120
- const onClickElement = (0, react_1.useCallback)((event) => {
121
- onClick?.(event);
122
- onClickWithValue?.(value);
123
- }, [onClick, onClickWithValue, value]);
124
- 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;
125
- 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;
126
- return ((0, jsx_runtime_1.jsxs)(ButtonElement, { as: (href ? "a" : "button"), theme: theme, isSmall: isSmall, withText: text !== undefined, isLoading: isLoadingElement, disabled: disabled, href: href, download: download, target: target, 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 }) })] }));
127
- };
128
- ButtonComponent.secondary = function Secondary({ className, ...props }) {
129
- const theme = (0, BetterHtmlProvider_1.useTheme)();
130
- const betterHtmlContext = (0, BetterHtmlProvider_1.useBetterHtmlContext)();
131
- return ((0, jsx_runtime_1.jsx)(ButtonComponent, { ...betterHtmlContext.components.button?.secondary, className: `secondary${className ? ` ${className}` : ""}`, color: theme.colors.textPrimary, ...props }));
132
- };
133
- ButtonComponent.destructive = function Destructive(props) {
134
- const theme = (0, BetterHtmlProvider_1.useTheme)();
135
- const betterHtmlContext = (0, BetterHtmlProvider_1.useBetterHtmlContext)();
136
- return ((0, jsx_runtime_1.jsx)(ButtonComponent, { ...betterHtmlContext.components.button?.destructive, backgroundColor: theme.colors.error, color: theme.colors.base, ...props }));
137
- };
138
- ButtonComponent.icon = function Icon({ size = 16, backgroundButtonColor, ...props }) {
139
- const theme = (0, BetterHtmlProvider_1.useTheme)();
140
- const betterHtmlContext = (0, BetterHtmlProvider_1.useBetterHtmlContext)();
141
- const buttonSize = size + theme.styles.space;
142
- const backgroundButtonColorReady = backgroundButtonColor ?? theme.colors.textPrimary;
143
- 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 }));
144
- };
145
- ButtonComponent.upload = function Upload({ accept, multiple, onUpload, ...props }) {
146
- const betterHtmlContext = (0, BetterHtmlProvider_1.useBetterHtmlContext)();
147
- const onClickElement = (0, react_1.useCallback)(() => {
148
- const input = document.createElement("input");
149
- input.setAttribute("type", "file");
150
- if (accept)
151
- input.setAttribute("accept", accept);
152
- if (multiple)
153
- input.setAttribute("multiple", "true");
154
- input.addEventListener("change", () => {
155
- onUpload?.(input.files);
156
- });
157
- input.click();
158
- }, [accept]);
159
- return ((0, jsx_runtime_1.jsx)(ButtonComponent, { ...betterHtmlContext.components.button?.upload, text: "Upload", icon: "uploadCloud", onClick: onClickElement, ...props }));
160
- };
161
- const Button = (0, react_1.memo)(ButtonComponent);
162
- Button.secondary = ButtonComponent.secondary;
163
- Button.destructive = ButtonComponent.destructive;
164
- Button.icon = ButtonComponent.icon;
165
- Button.upload = ButtonComponent.upload;
166
- exports.default = Button;
@@ -1,20 +0,0 @@
1
- import { ComponentPropWithRef } from "../types/components";
2
- import { OmitProps } from "../types/app";
3
- export type ChipProps = {
4
- text: string;
5
- /** @default theme.colors.textPrimary */
6
- color?: string;
7
- /** @default backgroundSecondary */
8
- backgroundColor?: string;
9
- /** @default theme.styles.borderRadius / 1.3 */
10
- borderRadius?: number;
11
- };
12
- type ChipComponentType = {
13
- (props: ComponentPropWithRef<HTMLDivElement, ChipProps>): React.ReactElement;
14
- circle: (props: ComponentPropWithRef<HTMLDivElement, OmitProps<ChipProps, "borderRadius">>) => React.ReactElement;
15
- };
16
- declare const ChipComponent: ChipComponentType;
17
- declare const Chip: typeof ChipComponent & {
18
- circle: typeof ChipComponent.circle;
19
- };
20
- export default Chip;
@@ -1,20 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const jsx_runtime_1 = require("react/jsx-runtime");
7
- const react_1 = require("react");
8
- const Div_1 = __importDefault(require("./Div"));
9
- const Text_1 = __importDefault(require("./Text"));
10
- const BetterHtmlProvider_1 = require("./BetterHtmlProvider");
11
- const ChipComponent = (0, react_1.forwardRef)(function Chip({ text, color, backgroundColor, borderRadius }, ref) {
12
- const theme = (0, BetterHtmlProvider_1.useTheme)();
13
- return ((0, jsx_runtime_1.jsx)(Div_1.default, { width: "fit-content", backgroundColor: backgroundColor ?? theme.colors.backgroundSecondary, borderRadius: borderRadius ?? theme.styles.borderRadius / 1.3, paddingBlock: theme.styles.gap, paddingInline: theme.styles.space, ref: ref, children: (0, jsx_runtime_1.jsx)(Text_1.default, { color: color ?? theme.colors.textPrimary, children: text }) }));
14
- });
15
- ChipComponent.circle = (0, react_1.forwardRef)(function Circle(props, ref) {
16
- return (0, jsx_runtime_1.jsx)(ChipComponent, { borderRadius: 999, ref: ref, ...props });
17
- });
18
- const Chip = (0, react_1.memo)(ChipComponent);
19
- Chip.circle = ChipComponent.circle;
20
- exports.default = Chip;
@@ -1,15 +0,0 @@
1
- import { ComponentMarginProps } from "../types/components";
2
- export type ColorThemeSwitchProps = {
3
- /** @default false */
4
- withMoon?: boolean;
5
- className?: string;
6
- } & ComponentMarginProps;
7
- type ColorThemeSwitchComponentType = {
8
- (props: ColorThemeSwitchProps): React.ReactElement;
9
- withText: (props: ColorThemeSwitchProps) => React.ReactElement;
10
- };
11
- declare const ColorThemeSwitchComponent: ColorThemeSwitchComponentType;
12
- declare const ColorThemeSwitch: typeof ColorThemeSwitchComponent & {
13
- withText: typeof ColorThemeSwitchComponent.withText;
14
- };
15
- export default ColorThemeSwitch;
@@ -1,54 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const jsx_runtime_1 = require("react/jsx-runtime");
7
- const react_1 = require("react");
8
- const hooks_1 = require("../utils/hooks");
9
- const Div_1 = __importDefault(require("./Div"));
10
- const Text_1 = __importDefault(require("./Text"));
11
- const ToggleInput_1 = __importDefault(require("./ToggleInput"));
12
- const BetterHtmlProvider_1 = require("./BetterHtmlProvider");
13
- const ColorThemeSwitchComponent = function ColorThemeSwitch({ withMoon, className, ...props }) {
14
- const form = (0, hooks_1.useForm)({
15
- defaultValues: {
16
- darkMode: localStorage.getItem("theme") === "dark",
17
- },
18
- });
19
- (0, react_1.useEffect)(() => {
20
- const timeout = setTimeout(() => {
21
- window.document.body.parentElement?.setAttribute("data-theme", form.values.darkMode ? "dark" : "light");
22
- localStorage.setItem("theme", form.values.darkMode ? "dark" : "light");
23
- }, 0.2 * 1000);
24
- return () => {
25
- clearTimeout(timeout);
26
- };
27
- }, [form.values.darkMode]);
28
- (0, react_1.useEffect)(() => {
29
- const html = document.querySelector("html");
30
- if (!html)
31
- return;
32
- const observer = new MutationObserver((mutations) => {
33
- mutations.forEach((mutation) => {
34
- if (mutation.type === "attributes") {
35
- form.setFieldValue("darkMode", html.getAttribute("data-theme") === "dark");
36
- }
37
- });
38
- });
39
- observer.observe(html, {
40
- attributes: true,
41
- });
42
- return () => {
43
- observer.disconnect();
44
- };
45
- }, []);
46
- return ((0, jsx_runtime_1.jsx)(ToggleInput_1.default.switch, { className: `react-better-html-color-theme-switch ${withMoon ? ` react-better-html-color-theme-switch-with-moon` : ""}${className ? ` ${className}` : ""}`, ...form.getSwitchProps("darkMode"), ...props }));
47
- };
48
- ColorThemeSwitchComponent.withText = function WithText({ withMoon, className, ...props }) {
49
- const theme = (0, BetterHtmlProvider_1.useTheme)();
50
- return ((0, jsx_runtime_1.jsxs)(Div_1.default.row, { width: "fit-content", alignItems: "center", gap: theme.styles.gap, userSelect: "none", ...props, children: [(0, jsx_runtime_1.jsx)(Text_1.default, { children: "Light" }), (0, jsx_runtime_1.jsx)(ColorThemeSwitchComponent, { withMoon: withMoon, className: className }), (0, jsx_runtime_1.jsx)(Text_1.default, { children: "Dark" })] }));
51
- };
52
- const ColorThemeSwitch = (0, react_1.memo)(ColorThemeSwitchComponent);
53
- ColorThemeSwitch.withText = ColorThemeSwitchComponent.withText;
54
- exports.default = ColorThemeSwitch;
@@ -1,30 +0,0 @@
1
- import { WebTarget } from "styled-components";
2
- import { ComponentHoverStyle, ComponentPropWithRef, ComponentStyle } from "../types/components";
3
- import { OmitProps } from "../types/app";
4
- export type DivProps<Value> = {
5
- value?: Value;
6
- /** @default "div" */
7
- as?: WebTarget;
8
- /** @default false */
9
- isTabAccessed?: boolean;
10
- onClickWithValue?: (value: Value) => void;
11
- } & OmitProps<React.ComponentProps<"div">, "style" | "defaultValue"> & ComponentStyle & ComponentHoverStyle;
12
- type DivComponentType = {
13
- <Value>(props: ComponentPropWithRef<HTMLDivElement, DivProps<Value>>): React.ReactElement;
14
- row: <Value>(props: ComponentPropWithRef<HTMLDivElement, OmitProps<DivProps<Value>, "display" | "flexDirection"> & {
15
- invertFlexDirection?: boolean;
16
- }>) => React.ReactElement;
17
- column: <Value>(props: ComponentPropWithRef<HTMLDivElement, OmitProps<DivProps<Value>, "display" | "flexDirection"> & {
18
- invertFlexDirection?: boolean;
19
- }>) => React.ReactElement;
20
- grid: <Value>(props: ComponentPropWithRef<HTMLDivElement, OmitProps<DivProps<Value>, "display">>) => React.ReactElement;
21
- box: <Value>(props: ComponentPropWithRef<HTMLDivElement, DivProps<Value>>) => React.ReactElement;
22
- };
23
- declare const DivComponent: DivComponentType;
24
- declare const Div: typeof DivComponent & {
25
- row: typeof DivComponent.row;
26
- column: typeof DivComponent.column;
27
- grid: typeof DivComponent.grid;
28
- box: typeof DivComponent.box;
29
- };
30
- export default Div;
@@ -1,60 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const jsx_runtime_1 = require("react/jsx-runtime");
7
- const react_1 = require("react");
8
- const styled_components_1 = __importDefault(require("styled-components"));
9
- const constants_1 = require("../constants");
10
- const hooks_1 = require("../utils/hooks");
11
- const BetterHtmlProvider_1 = require("./BetterHtmlProvider");
12
- const DivStyledComponent = styled_components_1.default.div.withConfig({
13
- shouldForwardProp: (prop) => !["normalStyle", "hoverStyle"].includes(prop),
14
- }) `
15
- ${(props) => props.normalStyle}
16
-
17
- &:hover {
18
- ${(props) => props.hoverStyle}
19
- }
20
- `;
21
- const DivComponent = (0, react_1.forwardRef)(function Div({ value, as, isTabAccessed, onClickWithValue, role, onClick, onKeyDown, children, ...props }, ref) {
22
- const theme = (0, BetterHtmlProvider_1.useTheme)();
23
- const styledComponentStyles = (0, hooks_1.useStyledComponentStyles)(props, theme);
24
- const dataProps = (0, hooks_1.useComponentPropsWithPrefix)(props, "data");
25
- const ariaProps = (0, hooks_1.useComponentPropsWithPrefix)(props, "aria");
26
- const restProps = (0, hooks_1.useComponentPropsWithoutStyle)(props);
27
- const onClickElement = (0, react_1.useCallback)((event) => {
28
- onClick?.(event);
29
- onClickWithValue?.(value);
30
- }, [onClick, onClickWithValue, value]);
31
- const onKeyDownElement = (0, react_1.useCallback)((event) => {
32
- onKeyDown?.(event);
33
- if (!isTabAccessed)
34
- return;
35
- if (event.key === "Enter" || event.key === " ") {
36
- event.preventDefault();
37
- event.currentTarget.click();
38
- }
39
- }, [onKeyDown, isTabAccessed]);
40
- return ((0, jsx_runtime_1.jsx)(DivStyledComponent, { as: as, tabIndex: isTabAccessed && !constants_1.isMobileDevice ? 0 : undefined, role: role ?? (onClick ? "button" : undefined), onClick: onClickElement, onKeyDown: onKeyDownElement, ...styledComponentStyles, ...dataProps, ...ariaProps, ...restProps, ref: ref, children: children }));
41
- });
42
- DivComponent.row = (0, react_1.forwardRef)(function Row({ invertFlexDirection, ...props }, ref) {
43
- return (0, jsx_runtime_1.jsx)(DivComponent, { display: "flex", flexDirection: invertFlexDirection ? "column" : "row", ref: ref, ...props });
44
- });
45
- DivComponent.column = (0, react_1.forwardRef)(function Column({ invertFlexDirection, ...props }, ref) {
46
- return (0, jsx_runtime_1.jsx)(DivComponent, { display: "flex", flexDirection: invertFlexDirection ? "row" : "column", ref: ref, ...props });
47
- });
48
- DivComponent.grid = (0, react_1.forwardRef)(function Grid(props, ref) {
49
- return (0, jsx_runtime_1.jsx)(DivComponent, { display: "grid", ref: ref, ...props });
50
- });
51
- DivComponent.box = (0, react_1.forwardRef)(function Box(props, ref) {
52
- const theme = (0, BetterHtmlProvider_1.useTheme)();
53
- return ((0, jsx_runtime_1.jsx)(DivComponent, { backgroundColor: theme.colors.backgroundContent, border: `1px solid ${theme.colors.border}`, borderRadius: theme.styles.borderRadius, paddingBlock: theme.styles.gap, paddingInline: theme.styles.space, ref: ref, ...props }));
54
- });
55
- const Div = (0, react_1.memo)(DivComponent);
56
- Div.row = DivComponent.row;
57
- Div.column = DivComponent.column;
58
- Div.grid = DivComponent.grid;
59
- Div.box = DivComponent.box;
60
- exports.default = Div;