react-better-html 1.1.10 → 1.1.12
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.
- package/README.md +28 -1
- package/dist/components/BetterHtmlProvider.d.ts +13 -3
- package/dist/components/BetterHtmlProvider.js +103 -24
- package/dist/components/Button.d.ts +63 -0
- package/dist/components/Button.js +157 -0
- package/dist/components/Chip.d.ts +20 -0
- package/dist/components/Chip.js +20 -0
- package/dist/components/Div.d.ts +9 -17
- package/dist/components/Div.js +2 -2
- package/dist/components/Divider.d.ts +21 -0
- package/dist/components/Divider.js +20 -0
- package/dist/components/Dropdown.d.ts +36 -0
- package/dist/components/Dropdown.js +157 -0
- package/dist/components/Icon.d.ts +13 -0
- package/dist/components/Icon.js +36 -0
- package/dist/components/Image.d.ts +18 -0
- package/dist/components/Image.js +44 -0
- package/dist/components/InputField.d.ts +33 -0
- package/dist/components/InputField.js +146 -0
- package/dist/components/Loader.d.ts +16 -1
- package/dist/components/Loader.js +11 -0
- package/dist/components/Modal.d.ts +41 -0
- package/dist/components/Modal.js +93 -0
- package/dist/components/PageHolder.d.ts +8 -0
- package/dist/components/PageHolder.js +15 -0
- package/dist/components/Text.d.ts +5 -11
- package/dist/components/ToggleInput.d.ts +19 -0
- package/dist/components/ToggleInput.js +122 -0
- package/dist/constants/app.d.ts +2 -0
- package/dist/constants/app.js +6 -0
- package/dist/constants/assets.d.ts +2 -0
- package/dist/constants/assets.js +10 -0
- package/dist/constants/icons.d.ts +2 -0
- package/dist/constants/icons.js +85 -0
- package/dist/constants/theme.d.ts +2 -0
- package/dist/constants/theme.js +46 -0
- package/dist/index.d.ts +13 -1
- package/dist/index.js +29 -1
- package/dist/types/app.d.ts +1 -0
- package/dist/types/asset.d.ts +4 -2
- package/dist/types/components.d.ts +3 -0
- package/dist/types/config.d.ts +8 -7
- package/dist/types/icon.d.ts +6 -3
- package/dist/types/loader.d.ts +3 -0
- package/dist/types/theme.d.ts +7 -5
- package/dist/utils/hooks.d.ts +34 -1
- package/dist/utils/hooks.js +107 -3
- package/package.json +1 -1
package/dist/utils/hooks.js
CHANGED
|
@@ -2,18 +2,54 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useStyledComponentStyles = useStyledComponentStyles;
|
|
4
4
|
exports.useComponentPropsWithPrefix = useComponentPropsWithPrefix;
|
|
5
|
+
exports.useComponentPropsWithExcludedStyle = useComponentPropsWithExcludedStyle;
|
|
5
6
|
exports.useComponentPropsWithoutStyle = useComponentPropsWithoutStyle;
|
|
7
|
+
exports.usePageResize = usePageResize;
|
|
8
|
+
exports.useMediaQuery = useMediaQuery;
|
|
9
|
+
exports.useBooleanState = useBooleanState;
|
|
10
|
+
exports.useDebounceState = useDebounceState;
|
|
6
11
|
const react_1 = require("react");
|
|
7
12
|
const cssProps = Object.keys(document.documentElement.style).reduce((previousValue, currentValue) => {
|
|
8
13
|
previousValue[currentValue.toLowerCase()] = true;
|
|
14
|
+
previousValue[`${currentValue}Hover`.toLowerCase()] = true;
|
|
9
15
|
return previousValue;
|
|
10
16
|
}, {});
|
|
11
|
-
|
|
12
|
-
|
|
17
|
+
const cssPropsToExclude = [
|
|
18
|
+
"position",
|
|
19
|
+
"top",
|
|
20
|
+
"right",
|
|
21
|
+
"bottom",
|
|
22
|
+
"left",
|
|
23
|
+
"width",
|
|
24
|
+
"height",
|
|
25
|
+
"minWidth",
|
|
26
|
+
"minHeight",
|
|
27
|
+
"maxWidth",
|
|
28
|
+
"maxHeight",
|
|
29
|
+
"margin",
|
|
30
|
+
"marginTop",
|
|
31
|
+
"marginBottom",
|
|
32
|
+
"marginLeft",
|
|
33
|
+
"marginRight",
|
|
34
|
+
"marginBlock",
|
|
35
|
+
"marginInline",
|
|
36
|
+
"marginBlockStart",
|
|
37
|
+
"marginBlockEnd",
|
|
38
|
+
"marginInlineStart",
|
|
39
|
+
"marginInlineEnd",
|
|
40
|
+
"marginTrim",
|
|
41
|
+
"zIndex",
|
|
42
|
+
];
|
|
43
|
+
function useStyledComponentStyles(props, theme,
|
|
44
|
+
/** @default false */
|
|
45
|
+
excludeProps) {
|
|
46
|
+
return (0, react_1.useMemo)(() => {
|
|
13
47
|
const normalStyle = {};
|
|
14
48
|
const hoverStyle = {};
|
|
15
49
|
let haveHover = false;
|
|
16
50
|
for (const key in props) {
|
|
51
|
+
if (excludeProps && cssPropsToExclude.includes(key))
|
|
52
|
+
continue;
|
|
17
53
|
if (key.endsWith("Hover")) {
|
|
18
54
|
haveHover = true;
|
|
19
55
|
const normalKey = key.slice(0, -5);
|
|
@@ -32,7 +68,6 @@ function useStyledComponentStyles(props, theme) {
|
|
|
32
68
|
hoverStyle,
|
|
33
69
|
};
|
|
34
70
|
}, [props, theme]);
|
|
35
|
-
return styles;
|
|
36
71
|
}
|
|
37
72
|
function useComponentPropsWithPrefix(props, prefix) {
|
|
38
73
|
return (0, react_1.useMemo)(() => {
|
|
@@ -45,6 +80,15 @@ function useComponentPropsWithPrefix(props, prefix) {
|
|
|
45
80
|
return returnValue;
|
|
46
81
|
}, [props, prefix]);
|
|
47
82
|
}
|
|
83
|
+
function useComponentPropsWithExcludedStyle(props) {
|
|
84
|
+
return (0, react_1.useMemo)(() => Object.keys(props).reduce((previousValue, currentValue) => {
|
|
85
|
+
const key = currentValue;
|
|
86
|
+
if (!cssPropsToExclude.includes(key))
|
|
87
|
+
return previousValue;
|
|
88
|
+
previousValue[key] = props[key];
|
|
89
|
+
return previousValue;
|
|
90
|
+
}, {}), [props]);
|
|
91
|
+
}
|
|
48
92
|
function useComponentPropsWithoutStyle(props) {
|
|
49
93
|
return (0, react_1.useMemo)(() => Object.keys(props).reduce((previousValue, currentValue) => {
|
|
50
94
|
if (!cssProps[currentValue.toLowerCase()])
|
|
@@ -52,3 +96,63 @@ function useComponentPropsWithoutStyle(props) {
|
|
|
52
96
|
return previousValue;
|
|
53
97
|
}, {}), [props]);
|
|
54
98
|
}
|
|
99
|
+
function usePageResize() {
|
|
100
|
+
const [width, setWidth] = (0, react_1.useState)(window.innerWidth);
|
|
101
|
+
const [height, setHeight] = (0, react_1.useState)(window.innerHeight);
|
|
102
|
+
(0, react_1.useEffect)(() => {
|
|
103
|
+
const onResize = () => {
|
|
104
|
+
setWidth(window.innerWidth);
|
|
105
|
+
setHeight(window.innerHeight);
|
|
106
|
+
};
|
|
107
|
+
window.addEventListener("resize", onResize);
|
|
108
|
+
return () => {
|
|
109
|
+
window.removeEventListener("resize", onResize);
|
|
110
|
+
};
|
|
111
|
+
}, []);
|
|
112
|
+
return {
|
|
113
|
+
width,
|
|
114
|
+
height,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
function useMediaQuery() {
|
|
118
|
+
const { width } = usePageResize();
|
|
119
|
+
return {
|
|
120
|
+
size320: width <= 320,
|
|
121
|
+
size400: width <= 400,
|
|
122
|
+
size500: width <= 500,
|
|
123
|
+
size600: width <= 600,
|
|
124
|
+
size700: width <= 700,
|
|
125
|
+
size800: width <= 800,
|
|
126
|
+
size900: width <= 900,
|
|
127
|
+
size1000: width <= 1000,
|
|
128
|
+
size1100: width <= 1100,
|
|
129
|
+
size1200: width <= 1200,
|
|
130
|
+
size1300: width <= 1300,
|
|
131
|
+
size1400: width <= 1400,
|
|
132
|
+
size1500: width <= 1500,
|
|
133
|
+
size1600: width <= 1600,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
function useBooleanState(initialValue = false) {
|
|
137
|
+
const [state, setState] = (0, react_1.useState)(initialValue);
|
|
138
|
+
const setTrue = (0, react_1.useCallback)(() => setState(true), []);
|
|
139
|
+
const setFalse = (0, react_1.useCallback)(() => setState(false), []);
|
|
140
|
+
const toggle = (0, react_1.useCallback)(() => setState((oldValue) => !oldValue), []);
|
|
141
|
+
return [state, { setState, setTrue, setFalse, toggle }];
|
|
142
|
+
}
|
|
143
|
+
function useDebounceState(initialValue, delay = 0.5) {
|
|
144
|
+
const [value, setValue] = (0, react_1.useState)(initialValue);
|
|
145
|
+
const [debouncedValue, setDebouncedValue] = (0, react_1.useState)(initialValue);
|
|
146
|
+
const [isLoading, setIsLoading] = useBooleanState();
|
|
147
|
+
(0, react_1.useEffect)(() => {
|
|
148
|
+
setIsLoading.setTrue();
|
|
149
|
+
const timer = setTimeout(() => {
|
|
150
|
+
setDebouncedValue(value);
|
|
151
|
+
setIsLoading.setFalse();
|
|
152
|
+
}, delay * 1000);
|
|
153
|
+
return () => {
|
|
154
|
+
clearTimeout(timer);
|
|
155
|
+
};
|
|
156
|
+
}, [value, delay]);
|
|
157
|
+
return [value, debouncedValue, setValue, isLoading];
|
|
158
|
+
}
|