@cronocode/react-box 1.7.2 → 1.7.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.d.ts CHANGED
@@ -1,21 +1,16 @@
1
1
  import React, { RefAttributes } from 'react';
2
- import ClassNameUtils from './utils/className/classNameUtils';
3
- import { DoxStyleProps } from './components/dox/doxStyles';
4
- import { StylesContext } from './components/dox/stylesContext';
5
- type ExtractElementType<T> = T extends React.DetailedHTMLProps<React.HTMLAttributes<infer E>, infer E> ? E : T extends React.SVGProps<infer E> ? E : never;
6
- type ExtractElementFromTag<T extends keyof React.JSX.IntrinsicElements> = ExtractElementType<React.JSX.IntrinsicElements[T]>;
2
+ import { BoxStyleProps, ExtractElementFromTag } from './core/types';
3
+ import { ClassNameType } from './core/classNames';
7
4
  type AllProps<TTag extends keyof React.JSX.IntrinsicElements> = React.ComponentProps<TTag>;
8
5
  type TagPropsType<TTag extends keyof React.JSX.IntrinsicElements> = Omit<AllProps<TTag>, 'className' | 'style' | 'ref'>;
9
- interface Props<TTag extends keyof React.JSX.IntrinsicElements> extends DoxStyleProps {
6
+ interface Props<TTag extends keyof React.JSX.IntrinsicElements> extends BoxStyleProps {
10
7
  children?: React.ReactNode | ((props: {
11
8
  isHover: boolean;
12
9
  }) => React.ReactNode);
13
10
  tag?: TTag;
14
11
  props?: TagPropsType<TTag>;
15
- className?: ClassNameUtils.ClassNameType;
12
+ className?: ClassNameType;
16
13
  style?: React.ComponentProps<TTag>['style'];
17
14
  }
18
- declare const _default: <TTag extends keyof React.JSX.IntrinsicElements = "div">(props: Props<TTag> & React.RefAttributes<ExtractElementType<React.JSX.IntrinsicElements[TTag]>>) => React.ReactNode;
15
+ declare const _default: <TTag extends keyof React.JSX.IntrinsicElements = "div">(props: Props<TTag> & React.RefAttributes<ExtractElementFromTag<TTag>>) => React.ReactNode;
19
16
  export default _default;
20
- declare const flushStyles: typeof StylesContext.flush;
21
- export { flushStyles };
package/box.js CHANGED
@@ -1,14 +1,12 @@
1
- import y, { forwardRef as N, useMemo as v, useState as S } from "react";
2
- import { C as p } from "./utils.js";
3
- import { u as C, S as d } from "./components/dox.js";
4
- function g(e, o) {
5
- const { tag: a = "div", children: t, props: c, className: f, style: n } = e, m = C(e, a === "svg"), u = v(() => p.classNames(f, m).join(" "), [e]), s = { ...c, className: u };
6
- n && (s.style = n), o && (s.ref = o);
7
- const [i, l] = S(!1), r = typeof t == "function";
8
- return r && (s.onMouseEnter = () => l(!0), s.onMouseLeave = () => l(!1)), y.createElement(a, s, r ? t({ isHover: i }) : t);
1
+ import v, { forwardRef as d, useMemo as y, useState as g } from "react";
2
+ import { u as p, c as N } from "./core.js";
3
+ function x(s, o) {
4
+ const { tag: a = "div", children: t, props: l, className: f, style: n } = s, u = p(s, a === "svg"), i = y(() => N(u, f).join(" "), [s]), e = { ...l, className: i };
5
+ n && (e.style = n), o && (e.ref = o);
6
+ const [m, r] = g(!1), c = typeof t == "function";
7
+ return c && (e.onMouseEnter = () => r(!0), e.onMouseLeave = () => r(!1)), v.createElement(a, e, c ? t({ isHover: m }) : t);
9
8
  }
10
- const M = N(g), { flush: E } = d;
9
+ const S = d(x);
11
10
  export {
12
- M as B,
13
- E as f
11
+ S as default
14
12
  };
@@ -1,16 +1,16 @@
1
1
  /// <reference types="react" />
2
2
  import Box from '../box';
3
- import ClassNameUtils from '../utils/className/classNameUtils';
4
- import { DoxSvgStyles } from './dox/doxStyles';
3
+ import { BoxSvgStyles } from '../core/types';
4
+ import { ClassNameType } from '../core/classNames';
5
5
  type SvgTagProps = Required<React.ComponentProps<typeof Box<'svg'>>>['props'];
6
- type DoxSvgTagProps = Omit<SvgTagProps, 'viewBox' | 'width' | 'height'>;
7
- interface Props extends DoxSvgStyles {
6
+ type BoxSvgTagProps = Omit<SvgTagProps, 'viewBox' | 'width' | 'height'>;
7
+ interface Props extends BoxSvgStyles {
8
8
  children?: React.ReactNode | ((props: {
9
9
  isHover: boolean;
10
10
  }) => React.ReactNode);
11
- props?: DoxSvgTagProps;
11
+ props?: BoxSvgTagProps;
12
12
  style?: React.ComponentProps<'svg'>['style'];
13
- className?: ClassNameUtils.ClassNameType;
13
+ className?: ClassNameType;
14
14
  viewBox?: string;
15
15
  width?: string;
16
16
  height?: string;
@@ -1,19 +1,20 @@
1
- import { jsx as i } from "react/jsx-runtime";
2
- import { forwardRef as m } from "react";
3
- import { B as n } from "../box.js";
4
- function a(o, r) {
5
- const { viewBox: s = "0 0 24 24", width: t = "1.5rem", height: p, props: e, ...g } = o;
6
- return /* @__PURE__ */ i(
7
- n,
1
+ import { jsx as m } from "react/jsx-runtime";
2
+ import { forwardRef as f } from "react";
3
+ import g from "../box.js";
4
+ import "../core.js";
5
+ function n(o, r) {
6
+ const { viewBox: t = "0 0 24 24", width: s = "1.5rem", height: p, props: e, ...i } = o;
7
+ return /* @__PURE__ */ m(
8
+ g,
8
9
  {
9
10
  tag: "svg",
10
11
  ref: r,
11
- props: { ...e, viewBox: s, width: t, height: p, xmlns: "http://www.w3.org/2000/svg", fill: "none" },
12
- ...g
12
+ props: { ...e, viewBox: t, width: s, height: p, xmlns: "http://www.w3.org/2000/svg", fill: "none" },
13
+ ...i
13
14
  }
14
15
  );
15
16
  }
16
- const x = m(a);
17
+ const h = f(n);
17
18
  export {
18
- x as b
19
+ h as default
19
20
  };
@@ -1,13 +1,14 @@
1
1
  import { jsx as n } from "react/jsx-runtime";
2
- import { forwardRef as s } from "react";
3
- import { B as p } from "../box.js";
2
+ import { forwardRef as p } from "react";
3
+ import s from "../box.js";
4
4
  import { O as i } from "../utils.js";
5
+ import "../core.js";
5
6
  const m = ["type", "onClick", "disabled"];
6
7
  function e(o, t) {
7
8
  const r = i.buildProps(o, m);
8
- return /* @__PURE__ */ n(p, { ref: t, tag: "button", component: "button", ...r });
9
+ return /* @__PURE__ */ n(s, { ref: t, tag: "button", component: "button", ...r });
9
10
  }
10
- const u = s(e);
11
+ const d = p(e);
11
12
  export {
12
- u as b
13
+ d as default
13
14
  };
@@ -1,10 +1,10 @@
1
- import { jsxs as s, jsx as e } from "react/jsx-runtime";
2
- import { forwardRef as c } from "react";
3
- import { B as t } from "../box.js";
1
+ import { jsxs as c, jsx as e } from "react/jsx-runtime";
2
+ import { forwardRef as s } from "react";
3
+ import t from "../box.js";
4
4
  import { O as a } from "../utils.js";
5
- import { F as l } from "./flex.js";
6
- import { c as d } from "../box.module.css.js";
7
- const p = [
5
+ import d from "./flex.js";
6
+ import "../core.js";
7
+ const l = [
8
8
  "name",
9
9
  "onInput",
10
10
  "onChange",
@@ -16,14 +16,14 @@ const p = [
16
16
  "checked",
17
17
  "defaultChecked"
18
18
  ];
19
- function m(o, r) {
20
- const { native: n } = o, i = a.buildProps(o, p, { type: "checkbox" });
21
- return /* @__PURE__ */ s(l, { inline: !0, position: "relative", children: [
19
+ function p(o, r) {
20
+ const { native: n } = o, i = a.buildProps(o, l, { type: "checkbox" });
21
+ return /* @__PURE__ */ c(d, { inline: !0, position: "relative", children: [
22
22
  /* @__PURE__ */ e(t, { ref: r, tag: "input", component: "checkbox", ...i, appearance: n ? void 0 : "none" }),
23
- !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" }) }) }) })
23
+ !n && /* @__PURE__ */ e(t, { position: "absolute", pointerEvents: "none", 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" }) }) }) })
24
24
  ] });
25
25
  }
26
- const b = c(m);
26
+ const v = s(p);
27
27
  export {
28
- b as c
28
+ v as default
29
29
  };
@@ -1,32 +1,34 @@
1
- import { jsx as i, Fragment as m, jsxs as c } from "react/jsx-runtime";
2
- import { B as t } from "../box.js";
3
- function u(n) {
4
- if (!(n != null && n.length))
1
+ import { jsx as o, Fragment as m, jsxs as u } from "react/jsx-runtime";
2
+ import s from "../box.js";
3
+ import "react";
4
+ import "../core.js";
5
+ function c(e) {
6
+ if (!(e != null && e.length))
5
7
  return {
6
8
  rows: [],
7
9
  columns: []
8
10
  };
9
- const s = Object.keys(n[0]);
11
+ const i = Object.keys(e[0]);
10
12
  return {
11
- rows: n.map((r) => ({
13
+ rows: e.map((r) => ({
12
14
  dataRow: r,
13
- cells: s.map((e) => ({
14
- key: e,
15
- value: r[e]
15
+ cells: i.map((n) => ({
16
+ key: n,
17
+ value: r[n]
16
18
  }))
17
19
  })),
18
- columns: s.map((r) => ({
20
+ columns: i.map((r) => ({
19
21
  key: r
20
22
  }))
21
23
  };
22
24
  }
23
- function d(n) {
24
- const { data: s } = n, r = u(s);
25
- return /* @__PURE__ */ i(t, { display: "grid", b: 1, borderRadius: 1, children: r.columns.length === 0 ? /* @__PURE__ */ i(m, { children: "empty grid" }) : /* @__PURE__ */ c(m, { children: [
26
- r.columns.map((e, o) => /* @__PURE__ */ i(t, { style: { gridColumn: o + 1 }, children: e.key.toString() }, e.key.toString())),
27
- r.rows.map((e, o) => e.cells.map((l) => /* @__PURE__ */ i(t, { children: l.value }, l.key.toString() + o)))
25
+ function y(e) {
26
+ const { data: i } = e, r = c(i);
27
+ return /* @__PURE__ */ o(s, { display: "grid", b: 1, borderRadius: 1, children: r.columns.length === 0 ? /* @__PURE__ */ o(m, { children: "empty grid" }) : /* @__PURE__ */ u(m, { children: [
28
+ r.columns.map((n, t) => /* @__PURE__ */ o(s, { style: { gridColumn: t + 1 }, children: n.key.toString() }, n.key.toString())),
29
+ r.rows.map((n, t) => n.cells.map((l) => /* @__PURE__ */ o(s, { children: l.value }, l.key.toString() + t)))
28
30
  ] }) });
29
31
  }
30
32
  export {
31
- d as D
33
+ y as default
32
34
  };
@@ -1,11 +1,12 @@
1
- import { jsx as n } from "react/jsx-runtime";
2
- import { forwardRef as t } from "react";
3
- import { B as f } from "../box.js";
4
- function s(o, r) {
5
- const { inline: e, ...i } = o;
6
- return /* @__PURE__ */ n(f, { ref: r, display: e ? "inline-flex" : "flex", ...i });
1
+ import { jsx as i } from "react/jsx-runtime";
2
+ import { forwardRef as f } from "react";
3
+ import n from "../box.js";
4
+ import "../core.js";
5
+ function l(o, r) {
6
+ const { inline: e, ...t } = o;
7
+ return /* @__PURE__ */ i(n, { ref: r, display: e ? "inline-flex" : "flex", ...t });
7
8
  }
8
- const p = t(s);
9
+ const a = f(l);
9
10
  export {
10
- p as F
11
+ a as default
11
12
  };
@@ -1,15 +1,16 @@
1
- import { jsx as a } from "react/jsx-runtime";
2
- import { useRef as i, useCallback as p } from "react";
3
- import { B as u } from "../box.js";
1
+ import { jsx as i } from "react/jsx-runtime";
2
+ import { useRef as p, useCallback as u } from "react";
3
+ import a from "../box.js";
4
4
  import { F as c } from "../utils.js";
5
- function x(o) {
6
- const { onSubmit: m, props: n } = o, r = i(null), s = p((t) => {
5
+ import "../core.js";
6
+ function S(o) {
7
+ const { onSubmit: m, props: n } = o, r = p(null), e = u((t) => {
7
8
  t.preventDefault();
8
9
  const f = c.getFormEntries(r.current);
9
10
  m(f, t);
10
- }, []), e = { ...n, onSubmit: s, ref: r };
11
- return /* @__PURE__ */ a(u, { tag: "form", ...o, props: e });
11
+ }, []), s = { ...n, onSubmit: e, ref: r };
12
+ return /* @__PURE__ */ i(a, { tag: "form", ...o, props: s });
12
13
  }
13
14
  export {
14
- x as F
15
+ S as default
15
16
  };
@@ -1,11 +1,12 @@
1
- import { jsx as t } from "react/jsx-runtime";
2
- import { forwardRef as s } from "react";
3
- import { B as d } from "../box.js";
4
- function e(r, i) {
5
- const { inline: o, ...n } = r;
6
- return /* @__PURE__ */ t(d, { ref: i, display: o ? "inline-grid" : "grid", ...n });
1
+ import { jsx as n } from "react/jsx-runtime";
2
+ import { forwardRef as d } from "react";
3
+ import e from "../box.js";
4
+ import "../core.js";
5
+ function f(r, i) {
6
+ const { inline: o, ...t } = r;
7
+ return /* @__PURE__ */ n(e, { ref: i, display: o ? "inline-grid" : "grid", ...t });
7
8
  }
8
- const a = s(e);
9
+ const l = d(f);
9
10
  export {
10
- a as g
11
+ l as default
11
12
  };
@@ -1,7 +1,8 @@
1
1
  import { jsx as e } from "react/jsx-runtime";
2
2
  import { forwardRef as n } from "react";
3
- import { B as a } from "../box.js";
3
+ import a from "../box.js";
4
4
  import { O as i } from "../utils.js";
5
+ import "../core.js";
5
6
  const d = [
6
7
  "name",
7
8
  "onInput",
@@ -14,11 +15,11 @@ const d = [
14
15
  "checked",
15
16
  "defaultChecked"
16
17
  ];
17
- function s(o, t) {
18
+ function u(o, t) {
18
19
  const r = i.buildProps(o, d, { type: "radio" });
19
20
  return /* @__PURE__ */ e(a, { ref: t, tag: "input", component: "radioButton", ...r });
20
21
  }
21
- const f = n(s);
22
+ const l = n(u);
22
23
  export {
23
- f as r
24
+ l as default
24
25
  };
@@ -1,7 +1,8 @@
1
1
  import { jsx as r } from "react/jsx-runtime";
2
2
  import { forwardRef as a } from "react";
3
- import { B as n } from "../box.js";
3
+ import n from "../box.js";
4
4
  import { O as s } from "../utils.js";
5
+ import "../core.js";
5
6
  const m = [
6
7
  "name",
7
8
  "onInput",
@@ -22,7 +23,7 @@ function p(t, e) {
22
23
  const o = s.buildProps(t, m);
23
24
  return /* @__PURE__ */ r(n, { ref: e, tag: "textarea", component: "textarea", ...o });
24
25
  }
25
- const d = a(p);
26
+ const f = a(p);
26
27
  export {
27
- d as t
28
+ f as default
28
29
  };
@@ -1,7 +1,8 @@
1
1
  import { jsx as r } from "react/jsx-runtime";
2
2
  import { forwardRef as n } from "react";
3
- import { B as a } from "../box.js";
3
+ import a from "../box.js";
4
4
  import { O as p } from "../utils.js";
5
+ import "../core.js";
5
6
  const s = [
6
7
  "name",
7
8
  "onInput",
@@ -20,7 +21,7 @@ function u(o, t) {
20
21
  const e = p.buildProps(o, s);
21
22
  return /* @__PURE__ */ r(a, { ref: t, tag: "input", component: "textbox", ...e });
22
23
  }
23
- const c = n(u);
24
+ const x = n(u);
24
25
  export {
25
- c as t
26
+ x as default
26
27
  };
@@ -1,57 +1,64 @@
1
- import { jsxs as v, Fragment as x, jsx as a } from "react/jsx-runtime";
2
- import { createPortal as b } from "react-dom";
3
- import { B as u } from "../box.js";
4
- import { useRef as E, useState as L, useCallback as d, useLayoutEffect as g } from "react";
5
- import { u as z } from "../utils.js";
6
- const i = 2;
7
- function j(f) {
8
- const { onPositionChange: c } = f, s = E(null), [t, p] = L(), m = z(), w = d(
9
- (o, e) => {
10
- const r = (n) => {
11
- n.target.contains(o) && e(o);
1
+ import { jsxs as v, Fragment as b, jsx as a } from "react/jsx-runtime";
2
+ import { createPortal as x } from "react-dom";
3
+ import d from "../box.js";
4
+ import { useMemo as E, useRef as C, useState as g, useCallback as f, useLayoutEffect as L } from "react";
5
+ import "../core.js";
6
+ function y() {
7
+ return E(() => {
8
+ const i = "crono-box";
9
+ let r = document.getElementById(i);
10
+ return r || (r = document.createElement("div"), r.id = i, document.body.appendChild(r)), r;
11
+ }, []);
12
+ }
13
+ const l = 2;
14
+ function R(i) {
15
+ const { onPositionChange: r } = i, c = C(null), [t, p] = g(), m = y(), w = f(
16
+ (n, e) => {
17
+ const o = (s) => {
18
+ s.target.contains(n) && e(n);
12
19
  };
13
- return document.addEventListener("scroll", r, { capture: !0 }), () => {
14
- document.removeEventListener("scroll", r, { capture: !0 });
20
+ return document.addEventListener("scroll", o, { capture: !0 }), () => {
21
+ document.removeEventListener("scroll", o, { capture: !0 });
15
22
  };
16
23
  },
17
24
  [t]
18
- ), h = d(
19
- (o, e) => {
20
- const r = (n) => {
21
- e(o);
25
+ ), h = f(
26
+ (n, e) => {
27
+ const o = (s) => {
28
+ e(n);
22
29
  };
23
- return window.addEventListener("resize", r, { capture: !0 }), () => {
24
- window.removeEventListener("resize", r, { capture: !0 });
30
+ return window.addEventListener("resize", o, { capture: !0 }), () => {
31
+ window.removeEventListener("resize", o, { capture: !0 });
25
32
  };
26
33
  },
27
34
  [t]
28
- ), l = d(
29
- (o) => {
30
- const e = o.getBoundingClientRect(), r = Math.round((e.top + window.scrollY) * i) / i, n = Math.round((e.left + window.scrollX) * i) / i;
31
- ((t == null ? void 0 : t.top) !== r || (t == null ? void 0 : t.left) !== n) && (c == null || c({ top: r, left: n }), p({ top: r, left: n, width: e.width > 0 ? e.width : void 0 }));
35
+ ), u = f(
36
+ (n) => {
37
+ const e = n.getBoundingClientRect(), o = Math.round((e.top + window.scrollY) * l) / l, s = Math.round((e.left + window.scrollX) * l) / l;
38
+ ((t == null ? void 0 : t.top) !== o || (t == null ? void 0 : t.left) !== s) && (r == null || r({ top: o, left: s }), p({ top: o, left: s, width: e.width > 0 ? e.width : void 0 }));
32
39
  },
33
40
  [t]
34
41
  );
35
- return g(() => {
36
- if (s.current) {
37
- l(s.current);
38
- const o = w(s.current, l), e = h(s.current, l);
42
+ return L(() => {
43
+ if (c.current) {
44
+ u(c.current);
45
+ const n = w(c.current, u), e = h(c.current, u);
39
46
  return () => {
40
- o(), e();
47
+ n(), e();
41
48
  };
42
49
  }
43
- }, [t]), /* @__PURE__ */ v(x, { children: [
44
- /* @__PURE__ */ a(u, { ref: s }),
45
- t && b(
50
+ }, [t]), /* @__PURE__ */ v(b, { children: [
51
+ /* @__PURE__ */ a(d, { ref: c }),
52
+ t && x(
46
53
  /* @__PURE__ */ a(
47
- u,
54
+ d,
48
55
  {
49
56
  position: "absolute",
50
57
  top: 0,
51
58
  left: 0,
52
59
  transition: "none",
53
60
  style: { transform: `translate(${t.left}px,${t.top}px)`, width: t.width },
54
- children: /* @__PURE__ */ a(u, { position: "absolute", width: "fit", ...f })
61
+ children: /* @__PURE__ */ a(d, { position: "absolute", width: "fit", ...i })
55
62
  }
56
63
  ),
57
64
  m
@@ -59,5 +66,5 @@ function j(f) {
59
66
  ] });
60
67
  }
61
68
  export {
62
- j as T
69
+ R as default
63
70
  };