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.
Files changed (48) hide show
  1. package/README.md +28 -1
  2. package/dist/components/BetterHtmlProvider.d.ts +13 -3
  3. package/dist/components/BetterHtmlProvider.js +103 -24
  4. package/dist/components/Button.d.ts +63 -0
  5. package/dist/components/Button.js +157 -0
  6. package/dist/components/Chip.d.ts +20 -0
  7. package/dist/components/Chip.js +20 -0
  8. package/dist/components/Div.d.ts +9 -17
  9. package/dist/components/Div.js +2 -2
  10. package/dist/components/Divider.d.ts +21 -0
  11. package/dist/components/Divider.js +20 -0
  12. package/dist/components/Dropdown.d.ts +36 -0
  13. package/dist/components/Dropdown.js +157 -0
  14. package/dist/components/Icon.d.ts +13 -0
  15. package/dist/components/Icon.js +36 -0
  16. package/dist/components/Image.d.ts +18 -0
  17. package/dist/components/Image.js +44 -0
  18. package/dist/components/InputField.d.ts +33 -0
  19. package/dist/components/InputField.js +146 -0
  20. package/dist/components/Loader.d.ts +16 -1
  21. package/dist/components/Loader.js +11 -0
  22. package/dist/components/Modal.d.ts +41 -0
  23. package/dist/components/Modal.js +93 -0
  24. package/dist/components/PageHolder.d.ts +8 -0
  25. package/dist/components/PageHolder.js +15 -0
  26. package/dist/components/Text.d.ts +5 -11
  27. package/dist/components/ToggleInput.d.ts +19 -0
  28. package/dist/components/ToggleInput.js +122 -0
  29. package/dist/constants/app.d.ts +2 -0
  30. package/dist/constants/app.js +6 -0
  31. package/dist/constants/assets.d.ts +2 -0
  32. package/dist/constants/assets.js +10 -0
  33. package/dist/constants/icons.d.ts +2 -0
  34. package/dist/constants/icons.js +85 -0
  35. package/dist/constants/theme.d.ts +2 -0
  36. package/dist/constants/theme.js +46 -0
  37. package/dist/index.d.ts +13 -1
  38. package/dist/index.js +29 -1
  39. package/dist/types/app.d.ts +1 -0
  40. package/dist/types/asset.d.ts +4 -2
  41. package/dist/types/components.d.ts +3 -0
  42. package/dist/types/config.d.ts +8 -7
  43. package/dist/types/icon.d.ts +6 -3
  44. package/dist/types/loader.d.ts +3 -0
  45. package/dist/types/theme.d.ts +7 -5
  46. package/dist/utils/hooks.d.ts +34 -1
  47. package/dist/utils/hooks.js +107 -3
  48. package/package.json +1 -1
@@ -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
- function useStyledComponentStyles(props, theme) {
12
- const styles = (0, react_1.useMemo)(() => {
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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-better-html",
3
- "version": "1.1.10",
3
+ "version": "1.1.12",
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": [