react-better-html 1.1.7 → 1.1.9

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.
@@ -0,0 +1,10 @@
1
+ import { BetterHtmlConfig, PartialBetterHtmlConfig } from "../types/config";
2
+ export declare const useBetterHtmlContext: () => BetterHtmlConfig;
3
+ export declare const useTheme: () => import("../types/theme").Theme;
4
+ type BetterHtmlProviderProps = {
5
+ value?: PartialBetterHtmlConfig;
6
+ children?: React.ReactNode;
7
+ };
8
+ declare function BetterHtmlProvider({ value, children }: BetterHtmlProviderProps): import("react/jsx-runtime").JSX.Element;
9
+ declare const _default: import("react").MemoExoticComponent<typeof BetterHtmlProvider>;
10
+ export default _default;
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useTheme = exports.useBetterHtmlContext = void 0;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const react_1 = require("react");
6
+ const betterHtmlContext = (0, react_1.createContext)(undefined);
7
+ const useBetterHtmlContext = () => {
8
+ const context = (0, react_1.useContext)(betterHtmlContext);
9
+ if (context === undefined)
10
+ throw new Error("`useBetterHtmlContext()` must be used within a `<BetterHtmlProvider>`. Make sure to add one at the root of your component tree.");
11
+ return context;
12
+ };
13
+ exports.useBetterHtmlContext = useBetterHtmlContext;
14
+ const useTheme = () => {
15
+ const context = (0, react_1.useContext)(betterHtmlContext);
16
+ if (context === undefined)
17
+ throw new Error("`useTheme()` must be used within a `<BetterHtmlProvider>`. Make sure to add one at the root of your component tree.");
18
+ return context.theme;
19
+ };
20
+ exports.useTheme = useTheme;
21
+ function BetterHtmlProvider({ value, children }) {
22
+ const readyValue = (0, react_1.useMemo)(() => ({
23
+ theme: {
24
+ styles: {
25
+ space: 16,
26
+ gap: 8,
27
+ borderRadius: 10,
28
+ fontFamily: "Arial, sans-serif",
29
+ transition: "ease 0.2s",
30
+ ...value?.theme?.styles,
31
+ },
32
+ colors: {
33
+ textPrimary: "#111111",
34
+ textSecondary: "#777777",
35
+ label: "#111111",
36
+ primary: "#6d466b",
37
+ secondary: "#412234",
38
+ success: "#28a745",
39
+ info: "#17a2b8",
40
+ warn: "#ffc107",
41
+ error: "#dc3545",
42
+ backgroundBase: "#f8f8f8",
43
+ backgroundSecondary: "#e8e8e8",
44
+ backgroundContent: "#ffffff",
45
+ border: "#ced4da",
46
+ ...value?.theme?.colors,
47
+ },
48
+ },
49
+ icons: {
50
+ ...value?.icons,
51
+ },
52
+ assets: {
53
+ ...value?.assets,
54
+ },
55
+ }), [value]);
56
+ return (0, jsx_runtime_1.jsx)(betterHtmlContext.Provider, { value: readyValue, children: children });
57
+ }
58
+ exports.default = (0, react_1.memo)(BetterHtmlProvider);
@@ -1,27 +1,37 @@
1
1
  import { JSX } from "react";
2
- import { ComponentStyle } from "../types/components";
2
+ import { ComponentHoverStyle, ComponentStyle } from "../types/components";
3
3
  import { OmitProps } from "../types/app";
4
- type DivProps<Value> = {
4
+ export type DivProps<Value> = {
5
5
  value?: Value;
6
+ /** @default "div" */
6
7
  as?: keyof JSX.IntrinsicElements;
7
8
  isTabAccessed?: boolean;
8
9
  onClickWithValue?: (value: Value) => void;
9
- } & OmitProps<React.ComponentProps<"div">, "style"> & ComponentStyle;
10
- type DivComponent = {
10
+ } & OmitProps<React.ComponentProps<"div">, "style"> & ComponentStyle & ComponentHoverStyle;
11
+ type DivComponentType = {
11
12
  <Value>(props: DivProps<Value> & {
12
13
  ref?: React.Ref<HTMLDivElement>;
13
14
  }): React.ReactElement;
14
- row: <Value>(props: DivProps<Value> & {
15
+ row: <Value>(props: OmitProps<DivProps<Value>, "display" | "flexDirection"> & {
16
+ invertFlexDirection?: boolean;
15
17
  ref?: React.Ref<HTMLDivElement>;
18
+ }) => React.ReactElement;
19
+ column: <Value>(props: OmitProps<DivProps<Value>, "display" | "flexDirection"> & {
16
20
  invertFlexDirection?: boolean;
21
+ ref?: React.Ref<HTMLDivElement>;
17
22
  }) => React.ReactElement;
18
- column: <Value>(props: DivProps<Value> & {
23
+ grid: <Value>(props: OmitProps<DivProps<Value>, "display" | "flexDirection"> & {
19
24
  ref?: React.Ref<HTMLDivElement>;
20
- invertFlexDirection?: boolean;
21
25
  }) => React.ReactElement;
22
- grid: <Value>(props: DivProps<Value> & {
26
+ box: <Value>(props: DivProps<Value> & {
23
27
  ref?: React.Ref<HTMLDivElement>;
24
28
  }) => React.ReactElement;
25
29
  };
26
- declare const _default: import("react").MemoExoticComponent<DivComponent>;
27
- export default _default;
30
+ declare const DivComponent: DivComponentType;
31
+ declare const Div: typeof DivComponent & {
32
+ row: typeof DivComponent.row;
33
+ column: typeof DivComponent.column;
34
+ grid: typeof DivComponent.grid;
35
+ box: typeof DivComponent.box;
36
+ };
37
+ export default Div;
@@ -8,7 +8,8 @@ const react_1 = require("react");
8
8
  const styled_components_1 = __importDefault(require("styled-components"));
9
9
  const constants_1 = require("../constants");
10
10
  const hooks_1 = require("../utils/hooks");
11
- const DivElement = styled_components_1.default.div.withConfig({
11
+ const BetterHtmlProvider_1 = require("./BetterHtmlProvider");
12
+ const DivStylesComponent = styled_components_1.default.div.withConfig({
12
13
  shouldForwardProp: (prop) => !["normalStyle", "hoverStyle"].includes(prop),
13
14
  }) `
14
15
  ${(props) => props.normalStyle}
@@ -17,8 +18,9 @@ const DivElement = styled_components_1.default.div.withConfig({
17
18
  ${(props) => props.hoverStyle}
18
19
  }
19
20
  `;
20
- const Div = (0, react_1.forwardRef)(function Div({ value, as, isTabAccessed, onClickWithValue, role, onClick, onKeyDown, ...props }, ref) {
21
- const styledComponentStyles = (0, hooks_1.useStyledComponentStyles)(props);
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);
22
24
  const dataProps = (0, hooks_1.useComponentPropsWithPrefix)(props, "data");
23
25
  const ariaProps = (0, hooks_1.useComponentPropsWithPrefix)(props, "aria");
24
26
  const restProps = (0, hooks_1.useComponentPropsWithoutStyle)(props);
@@ -35,6 +37,24 @@ const Div = (0, react_1.forwardRef)(function Div({ value, as, isTabAccessed, onC
35
37
  event.currentTarget.click();
36
38
  }
37
39
  }, [onKeyDown, isTabAccessed]);
38
- return ((0, jsx_runtime_1.jsx)(DivElement, { as: as, tabIndex: isTabAccessed && !constants_1.isMobileDevice ? 0 : undefined, role: role ?? (onClick ? "button" : undefined), onClick: onClickElement, onKeyDown: onKeyDownElement, ...styledComponentStyles, ...dataProps, ...ariaProps, ...restProps, ref: ref }));
40
+ return ((0, jsx_runtime_1.jsx)(DivStylesComponent, { 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 }));
39
41
  });
40
- exports.default = (0, react_1.memo)(Div);
42
+ DivComponent.row = (0, react_1.forwardRef)(function Row(props, ref) {
43
+ return ((0, jsx_runtime_1.jsx)(DivComponent, { display: "flex", flexDirection: props.invertFlexDirection ? "column" : "row", ref: ref, ...props }));
44
+ });
45
+ DivComponent.column = (0, react_1.forwardRef)(function Column(props, ref) {
46
+ return ((0, jsx_runtime_1.jsx)(DivComponent, { display: "flex", flexDirection: props.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;
@@ -0,0 +1,19 @@
1
+ import { Color } from "../types/theme";
2
+ import { OmitProps } from "../types/app";
3
+ import { DivProps } from "./Div";
4
+ type LoaderProps = {
5
+ /** @default textPrimary */
6
+ color?: Color;
7
+ /** @default 16 */
8
+ size?: number;
9
+ /** @default 5 */
10
+ width?: number;
11
+ /** @default false */
12
+ disabled?: boolean;
13
+ } & OmitProps<DivProps<unknown>, "width" | "height" | "color" | "background" | "borderRadius" | "mask" | "WebkitMask" | "padding" | "animation" | "animationName">;
14
+ type LoaderComponentType = {
15
+ (props: LoaderProps): React.ReactElement;
16
+ };
17
+ declare const LoaderComponent: LoaderComponentType;
18
+ declare const Loader: typeof LoaderComponent & {};
19
+ export default Loader;
@@ -0,0 +1,32 @@
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 Div_1 = __importDefault(require("./Div"));
10
+ const BetterHtmlProvider_1 = require("./BetterHtmlProvider");
11
+ const StyledDiv = (0, styled_components_1.default)(Div_1.default) `
12
+ @keyframes loaderAnimation {
13
+ to {
14
+ transform: rotate(360deg);
15
+ }
16
+ }
17
+
18
+ @keyframes textLoaderAnimation {
19
+ to {
20
+ clip-path: inset(0 -1ch 0 0);
21
+ }
22
+ }
23
+ `;
24
+ const LoaderComponent = function Loader({ color, size = 16, width, disabled, ...props }) {
25
+ const theme = (0, BetterHtmlProvider_1.useTheme)();
26
+ const readyColor = color ?? theme.colors.textPrimary;
27
+ const readyWidth = width ?? size / 3;
28
+ const mask = `radial-gradient(farthest-side, #0000 calc(100% - ${readyWidth}px), #000 0)`;
29
+ return ((0, jsx_runtime_1.jsx)(StyledDiv, { width: size + readyWidth * 2, height: size + readyWidth * 2, background: `radial-gradient(farthest-side, ${readyColor} 94%, #0000) top/${readyWidth}px ${readyWidth}px no-repeat, conic-gradient(#0000 30%, ${readyColor})`, borderRadius: 999, mask: mask, WebkitMask: mask, padding: readyWidth, animation: !disabled ? "loaderAnimation .6s infinite linear" : undefined, ...props }));
30
+ };
31
+ const Loader = (0, react_1.memo)(LoaderComponent);
32
+ exports.default = Loader;
@@ -0,0 +1,23 @@
1
+ import { ComponentHoverStyle, ComponentStyle } from "../types/components";
2
+ import { OmitProps } from "../types/app";
3
+ export type TextProps = {
4
+ /** @default "p" */
5
+ as?: "h1" | "h2" | "h3" | "h4" | "h5" | "h6" | "p" | "span" | "label";
6
+ } & OmitProps<React.ComponentProps<"div">, "style"> & ComponentStyle & ComponentHoverStyle;
7
+ type TextComponentType = {
8
+ (props: TextProps & {
9
+ ref?: React.Ref<HTMLDivElement>;
10
+ }): React.ReactElement;
11
+ unknown: (props: TextProps & {
12
+ ref?: React.Ref<HTMLDivElement>;
13
+ }) => React.ReactElement;
14
+ oneLine: (props: TextProps & {
15
+ ref?: React.Ref<HTMLDivElement>;
16
+ }) => React.ReactElement;
17
+ };
18
+ declare const TextComponent: TextComponentType;
19
+ declare const Text: typeof TextComponent & {
20
+ unknown: typeof TextComponent.unknown;
21
+ oneLine: typeof TextComponent.oneLine;
22
+ };
23
+ export default Text;
@@ -0,0 +1,38 @@
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 hooks_1 = require("../utils/hooks");
10
+ const BetterHtmlProvider_1 = require("./BetterHtmlProvider");
11
+ const TextStyledComponent = styled_components_1.default.div.withConfig({
12
+ shouldForwardProp: (prop) => !["normalStyle", "hoverStyle"].includes(prop),
13
+ }) `
14
+ ${(props) => props.normalStyle}
15
+
16
+ &:hover {
17
+ ${(props) => props.hoverStyle}
18
+ }
19
+ `;
20
+ const TextComponent = (0, react_1.forwardRef)(function Text({ as = "p", children, ...props }, ref) {
21
+ const theme = (0, BetterHtmlProvider_1.useTheme)();
22
+ const styledComponentStyles = (0, hooks_1.useStyledComponentStyles)(props, theme);
23
+ const dataProps = (0, hooks_1.useComponentPropsWithPrefix)(props, "data");
24
+ const ariaProps = (0, hooks_1.useComponentPropsWithPrefix)(props, "aria");
25
+ const restProps = (0, hooks_1.useComponentPropsWithoutStyle)(props);
26
+ return ((0, jsx_runtime_1.jsx)(TextStyledComponent, { as: as, ...styledComponentStyles, ...dataProps, ...ariaProps, ...restProps, ref: ref, children: children }));
27
+ });
28
+ TextComponent.unknown = (0, react_1.forwardRef)(function Unknown(props, ref) {
29
+ const theme = (0, BetterHtmlProvider_1.useTheme)();
30
+ return ((0, jsx_runtime_1.jsx)(TextComponent, { fontStyle: "italic", textAlign: "center", color: theme.colors.textSecondary, ref: ref, ...props }));
31
+ });
32
+ TextComponent.oneLine = (0, react_1.forwardRef)(function OneLine(props, ref) {
33
+ return (0, jsx_runtime_1.jsx)(TextComponent, { textOverflow: "ellipsis", whiteSpace: "nowrap", overflow: "hidden", ref: ref, ...props });
34
+ });
35
+ const Text = (0, react_1.memo)(TextComponent);
36
+ Text.unknown = TextComponent.unknown;
37
+ Text.oneLine = TextComponent.oneLine;
38
+ exports.default = Text;
package/dist/index.d.ts CHANGED
@@ -1,2 +1,4 @@
1
1
  import Div from "./components/Div";
2
- export { Div };
2
+ import Text from "./components/Text";
3
+ import Loader from "./components/Loader";
4
+ export { Div, Text, Loader };
package/dist/index.js CHANGED
@@ -3,6 +3,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.Div = void 0;
6
+ exports.Loader = exports.Text = exports.Div = void 0;
7
7
  const Div_1 = __importDefault(require("./components/Div"));
8
8
  exports.Div = Div_1.default;
9
+ const Text_1 = __importDefault(require("./components/Text"));
10
+ exports.Text = Text_1.default;
11
+ const Loader_1 = __importDefault(require("./components/Loader"));
12
+ exports.Loader = Loader_1.default;
@@ -2,21 +2,5 @@ export type ComponentStyle = React.CSSProperties;
2
2
  export type ComponentHoverStyle = {
3
3
  [CSSProperty in keyof ComponentStyle as `${CSSProperty & string}Hover`]: ComponentStyle[CSSProperty];
4
4
  };
5
- export type ComponentMarginProps = {
6
- margin?: ComponentStyle["margin"];
7
- marginTop?: ComponentStyle["marginTop"];
8
- marginBottom?: ComponentStyle["marginBottom"];
9
- marginLeft?: ComponentStyle["marginLeft"];
10
- marginRight?: ComponentStyle["marginRight"];
11
- marginBlock?: ComponentStyle["marginBlock"];
12
- marginInline?: ComponentStyle["marginInline"];
13
- };
14
- export type ComponentPaddingProps = {
15
- padding?: ComponentStyle["padding"];
16
- paddingTop?: ComponentStyle["paddingTop"];
17
- paddingBottom?: ComponentStyle["paddingBottom"];
18
- paddingLeft?: ComponentStyle["paddingLeft"];
19
- paddingRight?: ComponentStyle["paddingRight"];
20
- paddingBlock?: ComponentStyle["paddingBlock"];
21
- paddingInline?: ComponentStyle["paddingInline"];
22
- };
5
+ export type ComponentMarginProps = Pick<ComponentStyle, "margin" | "marginTop" | "marginBottom" | "marginLeft" | "marginRight" | "marginBlock" | "marginInline">;
6
+ export type ComponentPaddingProps = Pick<ComponentStyle, "padding" | "paddingTop" | "paddingBottom" | "paddingLeft" | "paddingRight" | "paddingBlock" | "paddingInline">;
@@ -0,0 +1,13 @@
1
+ import { PartialTheme, Theme } from "./theme";
2
+ import { AssetsConfig } from "./asset";
3
+ import { IconsConfig } from "./icon";
4
+ export type BetterHtmlConfig = {
5
+ theme: Theme;
6
+ icons: Partial<IconsConfig>;
7
+ assets: Partial<AssetsConfig>;
8
+ };
9
+ export type PartialBetterHtmlConfig = {
10
+ theme?: PartialTheme;
11
+ icons?: Partial<IconsConfig>;
12
+ assets?: Partial<AssetsConfig>;
13
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,14 +1,12 @@
1
1
  export type Styles = {
2
- sideSpace: number;
3
- borderRadius: number;
4
- borderRadiusSmall?: number;
2
+ space: number;
5
3
  gap: number;
6
- fontSize?: number;
4
+ borderRadius: number;
7
5
  fontFamily: string;
8
6
  transition: string;
9
7
  };
10
8
  export type Color = `#${string}` | "transparent";
11
- export type Colors = Record<"textPrimary" | "textSecondary" | "brand" | "brandSecondary" | "success" | "info" | "warn" | "error" | "errorSecondary" | "backgroundBase" | "backgroundSecondary" | "backgroundTertiary" | "border", Color>;
9
+ export type Colors = Record<"textPrimary" | "textSecondary" | "label" | "primary" | "secondary" | "success" | "info" | "warn" | "error" | "backgroundBase" | "backgroundSecondary" | "backgroundContent" | "border", Color>;
12
10
  export type Theme = {
13
11
  styles: Styles;
14
12
  colors: Colors;
@@ -5,7 +5,7 @@ exports.useComponentPropsWithPrefix = useComponentPropsWithPrefix;
5
5
  exports.useComponentPropsWithoutStyle = useComponentPropsWithoutStyle;
6
6
  const react_1 = require("react");
7
7
  const cssProps = Object.keys(document.documentElement.style).reduce((previousValue, currentValue) => {
8
- previousValue[currentValue] = true;
8
+ previousValue[currentValue.toLowerCase()] = true;
9
9
  return previousValue;
10
10
  }, {});
11
11
  function useStyledComponentStyles(props, theme) {
@@ -20,7 +20,7 @@ function useStyledComponentStyles(props, theme) {
20
20
  hoverStyle[normalKey] = props[key];
21
21
  }
22
22
  else {
23
- if (key.startsWith("data-") || key.startsWith("aria-"))
23
+ if (!cssProps[key.toLowerCase()])
24
24
  continue;
25
25
  normalStyle[key] = props[key];
26
26
  }
@@ -47,7 +47,7 @@ function useComponentPropsWithPrefix(props, prefix) {
47
47
  }
48
48
  function useComponentPropsWithoutStyle(props) {
49
49
  return (0, react_1.useMemo)(() => Object.keys(props).reduce((previousValue, currentValue) => {
50
- if (!cssProps[currentValue])
50
+ if (!cssProps[currentValue.toLowerCase()])
51
51
  previousValue[currentValue] = props[currentValue];
52
52
  return previousValue;
53
53
  }, {}), [props]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-better-html",
3
- "version": "1.1.7",
3
+ "version": "1.1.9",
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": [
@@ -35,11 +35,9 @@
35
35
  ],
36
36
  "author": "Kristiyan Valchev (kriss.vv)",
37
37
  "license": "ISC",
38
- "dependencies": {
39
- "rimraf": "^6.0.1"
40
- },
41
38
  "devDependencies": {
42
39
  "@types/react": "^19.0.10",
40
+ "rimraf": "^6.0.1",
43
41
  "typescript": "^5.5.3"
44
42
  },
45
43
  "peerDependencies": {