@cronocode/react-box 1.3.3 → 1.3.4

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/box.mjs CHANGED
@@ -1,22 +1,20 @@
1
- import $, { forwardRef as b, useState as E } from "react";
2
- import { c } from "./box.module.css.mjs";
3
- import { C as T, a as n } from "./utils/utils.mjs";
4
- import { useTheme as g } from "./theme.mjs";
5
- function j(r, f) {
6
- const { tag: p, children: i, props: d, className: l, style: m } = r, e = l ? T.classNames(c.box, l) : [c.box], x = g(r);
7
- Object.entries(x).forEach(([s, o]) => {
8
- const a = c[s + o];
9
- a ? e.push(a) : s in n && e.push(`${n[s]}${o}`);
10
- }), Object.entries(r).forEach(([s, o]) => {
11
- const a = c[s + o];
12
- a ? e.push(a) : s in n && e.push(`${n[s]}${o}`);
13
- });
14
- const t = { ...d, className: e.join(" ") };
15
- m && (t.style = m), f && (t.ref = f);
16
- const [N, u] = E(!1), h = typeof i == "function";
17
- return h && (t.onMouseEnter = () => u(!0), t.onMouseLeave = () => u(!1)), $.createElement(p || "div", t, h ? i({ isHover: N }) : i);
1
+ import b, { forwardRef as g, useMemo as E, useState as H } from "react";
2
+ import { c as n } from "./box.module.css.mjs";
3
+ import { C as M, a as d } from "./utils/utils.mjs";
4
+ import { useTheme as P } from "./theme.mjs";
5
+ function S(e, r) {
6
+ const { tag: h, children: t, props: p, className: c, style: l } = e, N = P(e), x = E(() => {
7
+ const o = c ? M.classNames(n.box, c) : [n.box], C = { ...N, ...e };
8
+ return Object.entries(C).forEach(([a, i]) => {
9
+ const u = n[a + i];
10
+ u ? o.push(u) : a in d && o.push(`${d[a]}${i}`);
11
+ }), o.join(" ");
12
+ }, [e]), s = { ...p, className: x };
13
+ l && (s.style = l), r && (s.ref = r);
14
+ const [v, m] = H(!1), f = typeof t == "function";
15
+ return f && (s.onMouseEnter = () => m(!0), s.onMouseLeave = () => m(!1)), b.createElement(h || "div", s, f ? t({ isHover: v }) : t);
18
16
  }
19
- const A = b(j);
17
+ const y = g(S);
20
18
  export {
21
- A as default
19
+ y as default
22
20
  };
@@ -1,15 +1,15 @@
1
1
  import { jsx as n } from "react/jsx-runtime";
2
- import { forwardRef as i } from "react";
3
- import p from "../box.mjs";
4
- import { O as e } from "../utils/utils.mjs";
2
+ import { forwardRef as p } from "react";
3
+ import i from "../box.mjs";
4
+ import { O as m } from "../utils/utils.mjs";
5
5
  import "../box.module.css.mjs";
6
6
  import "../theme.mjs";
7
7
  const s = ["type", "onClick", "disabled"];
8
- function m(o, t) {
9
- const r = e.buildProps(o, s);
10
- return /* @__PURE__ */ n(p, { ref: t, tag: "button", inline: !0, cursor: "pointer", component: "button", ...r });
8
+ function e(o, t) {
9
+ const r = m.buildProps(o, s);
10
+ return /* @__PURE__ */ n(i, { ref: t, tag: "button", component: "button", ...r });
11
11
  }
12
- const d = i(m);
12
+ const l = p(e);
13
13
  export {
14
- d as default
14
+ l as default
15
15
  };
@@ -20,7 +20,7 @@ const p = [
20
20
  function m(o, r) {
21
21
  const { native: n } = o, i = a.buildProps(o, p, { type: "checkbox" });
22
22
  return /* @__PURE__ */ c(l, { inline: !0, position: "relative", children: [
23
- /* @__PURE__ */ e(t, { ref: r, tag: "input", inline: !0, b: 1, p: 2, component: "checkbox", ...i, appearance: n ? void 0 : "none" }),
23
+ /* @__PURE__ */ e(t, { ref: r, tag: "input", component: "checkbox", ...i, appearance: n ? void 0 : "none" }),
24
24
  !n && /* @__PURE__ */ e(t, { position: "absolute", pointerEvents: "none", className: d._checkedIcon, children: /* @__PURE__ */ e("svg", { xmlns: "http://www.w3.org/2000/svg", width: "100%", viewBox: "0 0 20 20", children: /* @__PURE__ */ e("g", { fill: "none", fillRule: "evenodd", children: /* @__PURE__ */ e("path", { stroke: "#000", strokeLinecap: "round", strokeLinejoin: "round", d: "M6 10.15L8.5 13 14 7" }) }) }) })
25
25
  ] });
26
26
  }
@@ -16,7 +16,6 @@ interface Props extends Omit<BoxProps, 'props'> {
16
16
  required?: boolean;
17
17
  checked?: boolean;
18
18
  defaultChecked?: boolean;
19
- native?: boolean;
20
19
  }
21
20
  declare const _default: React.ForwardRefExoticComponent<Props & React.RefAttributes<HTMLInputElement>>;
22
21
  export default _default;
@@ -1,10 +1,10 @@
1
- import { jsx as r } from "react/jsx-runtime";
2
- import { forwardRef as a } from "react";
3
- import i from "../box.mjs";
4
- import { O as d } from "../utils/utils.mjs";
1
+ import { jsx as e } from "react/jsx-runtime";
2
+ import { forwardRef as n } from "react";
3
+ import a from "../box.mjs";
4
+ import { O as i } from "../utils/utils.mjs";
5
5
  import "../box.module.css.mjs";
6
6
  import "../theme.mjs";
7
- const p = [
7
+ const d = [
8
8
  "name",
9
9
  "onInput",
10
10
  "onChange",
@@ -16,11 +16,11 @@ const p = [
16
16
  "checked",
17
17
  "defaultChecked"
18
18
  ];
19
- function u(o, t) {
20
- const { native: e } = o, n = d.buildProps(o, p, { type: "radio" });
21
- return /* @__PURE__ */ r(i, { ref: t, tag: "input", inline: !0, b: 1, p: 2, component: "radioButton", ...n, appearance: e ? void 0 : "none" });
19
+ function p(o, t) {
20
+ const r = i.buildProps(o, d, { type: "radio" });
21
+ return /* @__PURE__ */ e(a, { ref: t, tag: "input", component: "radioButton", ...r });
22
22
  }
23
- const B = a(u);
23
+ const B = n(p);
24
24
  export {
25
25
  B as default
26
26
  };
@@ -1,10 +1,10 @@
1
1
  import { jsx as r } from "react/jsx-runtime";
2
2
  import { forwardRef as a } from "react";
3
3
  import n from "../box.mjs";
4
- import { O as i } from "../utils/utils.mjs";
4
+ import { O as m } from "../utils/utils.mjs";
5
5
  import "../box.module.css.mjs";
6
6
  import "../theme.mjs";
7
- const m = [
7
+ const s = [
8
8
  "name",
9
9
  "onInput",
10
10
  "onChange",
@@ -20,11 +20,11 @@ const m = [
20
20
  "readOnly",
21
21
  "required"
22
22
  ];
23
- function s(t, e) {
24
- const o = i.buildProps(t, m);
25
- return /* @__PURE__ */ r(n, { ref: e, tag: "textarea", component: "textarea", inline: !0, ...o });
23
+ function p(t, o) {
24
+ const e = m.buildProps(t, s);
25
+ return /* @__PURE__ */ r(n, { ref: o, tag: "textarea", component: "textarea", ...e });
26
26
  }
27
- const x = a(s);
27
+ const x = a(p);
28
28
  export {
29
29
  x as default
30
30
  };
@@ -18,11 +18,11 @@ const i = [
18
18
  "value",
19
19
  "pattern"
20
20
  ];
21
- function u(t, o) {
22
- const e = p.buildProps(t, i);
23
- return /* @__PURE__ */ r(a, { ref: o, tag: "input", inline: !0, component: "textbox", ...e });
21
+ function m(o, t) {
22
+ const e = p.buildProps(o, i);
23
+ return /* @__PURE__ */ r(a, { ref: t, tag: "input", component: "textbox", ...e });
24
24
  }
25
- const c = n(u);
25
+ const c = n(m);
26
26
  export {
27
27
  c as default
28
28
  };
@@ -1,49 +1,57 @@
1
1
  import { jsxs as x, Fragment as b, jsx as a } from "react/jsx-runtime";
2
2
  import { createPortal as E } from "react-dom";
3
- import p from "../box.mjs";
4
- import { useRef as L, useState as z, useCallback as l, useLayoutEffect as g } from "react";
3
+ import f from "../box.mjs";
4
+ import { useRef as L, useState as z, useCallback as c, useLayoutEffect as g } from "react";
5
5
  import { u as C } from "../utils/utils.mjs";
6
6
  import "../box.module.css.mjs";
7
7
  import "../theme.mjs";
8
- function P(c) {
9
- const { children: d, onPositionChange: n } = c, e = L(null), [s, f] = z(), m = C(), w = l((r, t) => {
10
- const o = (u) => {
11
- u.target.contains(r) && t();
12
- };
13
- return document.addEventListener("scroll", o, { capture: !0 }), () => {
14
- document.removeEventListener("scroll", o, { capture: !0 });
15
- };
16
- }, []), v = l((r, t) => {
17
- const o = (u) => {
18
- t();
19
- };
20
- return window.addEventListener("resize", o, { capture: !0 }), () => {
21
- window.removeEventListener("resize", o, { capture: !0 });
22
- };
23
- }, []), i = l((r) => () => {
24
- const t = r.getBoundingClientRect();
25
- f({ top: t.top + window.scrollY, left: t.left + window.scrollX }), n == null || n({ top: t.top + window.scrollY, left: t.left + window.scrollX });
26
- }, []);
8
+ function P(i) {
9
+ const { children: p, onPositionChange: s } = i, n = L(null), [t, d] = z(), m = C(), w = c(
10
+ (e, r) => {
11
+ const o = (u) => {
12
+ u.target.contains(e) && r();
13
+ };
14
+ return document.addEventListener("scroll", o, { capture: !0 }), () => {
15
+ document.removeEventListener("scroll", o, { capture: !0 });
16
+ };
17
+ },
18
+ [t]
19
+ ), v = c(
20
+ (e, r) => {
21
+ const o = (u) => {
22
+ r();
23
+ };
24
+ return window.addEventListener("resize", o, { capture: !0 }), () => {
25
+ window.removeEventListener("resize", o, { capture: !0 });
26
+ };
27
+ },
28
+ [t]
29
+ ), l = c(() => {
30
+ if (n.current) {
31
+ const e = n.current.getBoundingClientRect(), r = e.top + window.scrollY, o = e.left + window.scrollX;
32
+ ((t == null ? void 0 : t.top) !== r || (t == null ? void 0 : t.left) !== o) && (s == null || s({ top: r, left: o }), d({ top: e.top + window.scrollY, left: e.left + window.scrollX }));
33
+ }
34
+ }, [t]);
27
35
  return g(() => {
28
- if (e.current) {
29
- i(e.current)();
30
- const r = w(e.current, i(e.current)), t = v(e.current, i(e.current));
36
+ if (n.current) {
37
+ l();
38
+ const e = w(n.current, l), r = v(n.current, l);
31
39
  return () => {
32
- r(), t();
40
+ e(), r();
33
41
  };
34
42
  }
35
- }, []), /* @__PURE__ */ x(b, { children: [
36
- /* @__PURE__ */ a(p, { ref: e, position: "absolute", top: 0, left: 0, ...c, children: void 0 }),
37
- s && E(
43
+ }, [t]), /* @__PURE__ */ x(b, { children: [
44
+ /* @__PURE__ */ a(f, { ref: n, position: "absolute", top: 0, left: 0, ...i, children: void 0 }),
45
+ t && E(
38
46
  /* @__PURE__ */ a(
39
- p,
47
+ f,
40
48
  {
41
49
  position: "absolute",
42
50
  top: 0,
43
51
  left: 0,
44
52
  transition: "none",
45
- style: { transform: `translate(${s.left}px,${s.top}px)` },
46
- children: d
53
+ style: { transform: `translate(${t.left}px,${t.top}px)` },
54
+ children: p
47
55
  }
48
56
  ),
49
57
  m
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cronocode/react-box",
3
- "version": "1.3.3",
3
+ "version": "1.3.4",
4
4
  "main": "./box.mjs",
5
5
  "module": "./box.mjs",
6
6
  "types": "./box.d.ts",
package/theme.mjs CHANGED
@@ -1,27 +1,77 @@
1
- import { useMemo as c } from "react";
2
- let m = {};
1
+ import { useMemo as y } from "react";
2
+ const r = {
3
+ button: {
4
+ styles: {
5
+ inline: !0,
6
+ p: 3,
7
+ cursor: "pointer",
8
+ b: 1,
9
+ borderRadius: 1
10
+ },
11
+ disabled: {
12
+ cursor: "default"
13
+ }
14
+ },
15
+ checkbox: {
16
+ styles: {
17
+ inline: !0,
18
+ b: 1,
19
+ p: 2
20
+ }
21
+ },
22
+ radioButton: {
23
+ styles: {
24
+ inline: !0,
25
+ b: 1,
26
+ p: 2
27
+ }
28
+ },
29
+ textbox: {
30
+ styles: {
31
+ inline: !0,
32
+ b: 1,
33
+ borderRadius: 1,
34
+ p: 3
35
+ }
36
+ },
37
+ textarea: {
38
+ styles: {
39
+ inline: !0,
40
+ b: 1,
41
+ borderRadius: 1
42
+ }
43
+ }
44
+ };
45
+ let n = r;
3
46
  var u;
4
- ((l) => {
5
- function s(n) {
6
- m = n;
47
+ ((d) => {
48
+ function o(t) {
49
+ n = t, i();
50
+ }
51
+ d.setup = o;
52
+ function i() {
53
+ Object.keys(r).forEach((s) => {
54
+ console.log(s);
55
+ const e = n[s], l = r[s];
56
+ e ? (e.styles = { ...l.styles, ...e.styles }, console.log(e.styles), e.disabled && l.disabled && (e.disabled = { ...l.disabled, ...e.disabled })) : n[s] = r[s];
57
+ });
7
58
  }
8
- l.setup = s;
9
59
  })(u || (u = {}));
10
- const h = u;
11
- function p(l) {
12
- const { clean: s, disabled: n, theme: t, component: o } = l;
13
- return c(() => {
14
- var i, d, a;
15
- if (s)
60
+ const m = u;
61
+ function p(d) {
62
+ const { clean: o, disabled: i, theme: t, component: s } = d;
63
+ return y(() => {
64
+ var a, b, c;
65
+ if (o)
16
66
  return {};
17
- let e = m[o] ?? ((i = m.components) == null ? void 0 : i[o]);
67
+ let e = n[s] ?? ((a = n.components) == null ? void 0 : a[s]);
18
68
  if (!e)
19
69
  return {};
20
- let r = t ? { ...e.styles, ...(d = e.themes) == null ? void 0 : d[t].styles } : e.styles;
21
- return n ? t ? { ...r, ...e.disabled, ...(a = e.themes) == null ? void 0 : a[t].disabled } : { ...r, ...e.disabled } : r;
22
- }, [o, s, n, t]);
70
+ let l = t ? { ...e.styles, ...(b = e.themes) == null ? void 0 : b[t].styles } : e.styles;
71
+ return i ? t ? { ...l, ...e.disabled, ...(c = e.themes) == null ? void 0 : c[t].disabled } : { ...l, ...e.disabled } : l;
72
+ }, [s, o, i, t]);
23
73
  }
24
74
  export {
25
- h as default,
75
+ m as default,
26
76
  p as useTheme
27
77
  };