@cronocode/react-box 1.4.5 → 1.4.6

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.
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("react/jsx-runtime"),v=require("react-dom"),d=require("../box.cjs"),s=require("react"),q=require("../utils/utils.cjs");require("../box.module.css.cjs");require("../theme.cjs");function x(u){const{children:f,onPositionChange:c}=u,o=s.useRef(null),[e,p]=s.useState(),w=q.usePortalContainer(),b=s.useCallback((t,r)=>{const n=a=>{a.target.contains(t)&&r()};return document.addEventListener("scroll",n,{capture:!0}),()=>{document.removeEventListener("scroll",n,{capture:!0})}},[e]),m=s.useCallback((t,r)=>{const n=a=>{r()};return window.addEventListener("resize",n,{capture:!0}),()=>{window.removeEventListener("resize",n,{capture:!0})}},[e]),i=s.useCallback(()=>{if(o.current){const t=o.current.getBoundingClientRect(),r=t.top+window.scrollY,n=t.left+window.scrollX;((e==null?void 0:e.top)!==r||(e==null?void 0:e.left)!==n)&&(c==null||c({top:r,left:n}),p({top:t.top+window.scrollY,left:t.left+window.scrollX}))}},[e]);return s.useLayoutEffect(()=>{if(o.current){i();const t=b(o.current,i),r=m(o.current,i);return()=>{t(),r()}}},[e]),l.jsxs(l.Fragment,{children:[l.jsx(d.default,{ref:o,position:"absolute",top:0,left:0,...u,children:void 0}),e&&v.createPortal(l.jsx(d.default,{position:"absolute",top:0,left:0,transition:"none",style:{transform:`translate(${e.left}px,${e.top}px)`},children:f}),w)]})}exports.default=x;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("react/jsx-runtime"),m=require("react-dom"),d=require("../box.cjs"),s=require("react"),h=require("../utils/utils.cjs");require("../box.module.css.cjs");require("../theme.cjs");function q(u){const{children:f,onPositionChange:c}=u,o=s.useRef(null),[e,p]=s.useState(),w=h.usePortalContainer(),v=s.useCallback((t,r)=>{const n=a=>{a.target.contains(t)&&r()};return document.addEventListener("scroll",n,{capture:!0}),()=>{document.removeEventListener("scroll",n,{capture:!0})}},[e]),b=s.useCallback((t,r)=>{const n=a=>{r()};return window.addEventListener("resize",n,{capture:!0}),()=>{window.removeEventListener("resize",n,{capture:!0})}},[e]),i=s.useCallback(()=>{if(o.current){const t=o.current.getBoundingClientRect(),r=t.top+window.scrollY,n=t.left+window.scrollX;((e==null?void 0:e.top)!==r||(e==null?void 0:e.left)!==n)&&(c==null||c({top:r,left:n}),p({top:t.top+window.scrollY,left:t.left+window.scrollX,width:t.width>0?t.width:void 0}))}},[e]);return s.useLayoutEffect(()=>{if(o.current){i();const t=v(o.current,i),r=b(o.current,i);return()=>{t(),r()}}},[e]),l.jsxs(l.Fragment,{children:[l.jsx(d.default,{ref:o,position:"absolute",top:0,left:0,...u,children:void 0}),e&&m.createPortal(l.jsx(d.default,{position:"absolute",top:0,left:0,transition:"none",style:{transform:`translate(${e.left}px,${e.top}px)`,width:e.width},children:f}),w)]})}exports.default=q;
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
- import { BoxPosition } from '../types';
3
- interface Props extends BoxPosition {
2
+ import { BoxPosition, BoxSize } from '../types';
3
+ interface Props extends BoxPosition, BoxSize {
4
4
  children: React.ReactNode;
5
5
  style?: React.ComponentProps<'div'>['style'];
6
6
  onPositionChange?(position: {
@@ -1,12 +1,12 @@
1
- import { jsxs as x, Fragment as b, jsx as a } from "react/jsx-runtime";
2
- import { createPortal as E } from "react-dom";
3
- import f from "../box.mjs";
4
- import { useRef as L, useState as z, useCallback as c, useLayoutEffect as g } from "react";
5
- import { u as C } from "../utils/utils.mjs";
1
+ import { jsxs as h, Fragment as x, jsx as a } from "react/jsx-runtime";
2
+ import { createPortal as b } from "react-dom";
3
+ import d from "../box.mjs";
4
+ import { useRef as E, useState as L, useCallback as l, useLayoutEffect as z } from "react";
5
+ import { u as g } from "../utils/utils.mjs";
6
6
  import "../box.module.css.mjs";
7
7
  import "../theme.mjs";
8
- function P(i) {
9
- const { children: p, onPositionChange: s } = i, n = L(null), [t, d] = z(), m = C(), w = c(
8
+ function P(c) {
9
+ const { children: f, onPositionChange: s } = c, n = E(null), [t, p] = L(), m = g(), w = l(
10
10
  (e, r) => {
11
11
  const o = (u) => {
12
12
  u.target.contains(e) && r();
@@ -16,7 +16,7 @@ function P(i) {
16
16
  };
17
17
  },
18
18
  [t]
19
- ), v = c(
19
+ ), v = l(
20
20
  (e, r) => {
21
21
  const o = (u) => {
22
22
  r();
@@ -26,32 +26,32 @@ function P(i) {
26
26
  };
27
27
  },
28
28
  [t]
29
- ), l = c(() => {
29
+ ), i = l(() => {
30
30
  if (n.current) {
31
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 }));
32
+ ((t == null ? void 0 : t.top) !== r || (t == null ? void 0 : t.left) !== o) && (s == null || s({ top: r, left: o }), p({ top: e.top + window.scrollY, left: e.left + window.scrollX, width: e.width > 0 ? e.width : void 0 }));
33
33
  }
34
34
  }, [t]);
35
- return g(() => {
35
+ return z(() => {
36
36
  if (n.current) {
37
- l();
38
- const e = w(n.current, l), r = v(n.current, l);
37
+ i();
38
+ const e = w(n.current, i), r = v(n.current, i);
39
39
  return () => {
40
40
  e(), r();
41
41
  };
42
42
  }
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(
43
+ }, [t]), /* @__PURE__ */ h(x, { children: [
44
+ /* @__PURE__ */ a(d, { ref: n, position: "absolute", top: 0, left: 0, ...c, children: void 0 }),
45
+ t && b(
46
46
  /* @__PURE__ */ a(
47
- f,
47
+ d,
48
48
  {
49
49
  position: "absolute",
50
50
  top: 0,
51
51
  left: 0,
52
52
  transition: "none",
53
- style: { transform: `translate(${t.left}px,${t.top}px)` },
54
- children: p
53
+ style: { transform: `translate(${t.left}px,${t.top}px)`, width: t.width },
54
+ children: f
55
55
  }
56
56
  ),
57
57
  m
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cronocode/react-box",
3
- "version": "1.4.5",
3
+ "version": "1.4.6",
4
4
  "main": "./box.cjs",
5
5
  "module": "./box.mjs",
6
6
  "types": "./box.d.ts",
package/plugins.cjs CHANGED
@@ -1,11 +1,7 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function p(r){const l=Object.entries(r.colors).map(([o,e])=>`--color${o}: ${e};`).join(`
2
- `),_=Object.entries(r.shadows).map(([o,e])=>`--shadow${o}: ${e};`).join(`
3
- `),t=Object.entries(r.backgrounds).map(([o,e])=>`--background${o}: ${e};`).join(`
4
- `),c=`:root {
5
- ${l}
6
- ${_}
7
- ${t}
8
- }`,n=Object.keys(r.colors).map(o=>`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function u(r){const _=Object.entries(r.colors).map(([o,l])=>`--color${o}: ${l};`).join(`
2
+ `),t=Object.entries(r.shadows).map(([o,l])=>`--shadow${o}: ${l};`).join(`
3
+ `),c=Object.entries(r.backgrounds).map(([o,l])=>`--background${o}: ${l};`).join(`
4
+ `),e=[":root {"];_&&e.push(` ${_}`),t&&e.push(` ${t}`),c&&e.push(` ${c}`),e.push("}");const n=Object.keys(r.colors).map(o=>`
9
5
  .color_${o},
10
6
  .color_h_${o}:hover,
11
7
  ._h:hover>.color_h_${o} {
@@ -138,7 +134,7 @@
138
134
 
139
135
  .shadow_a_${o}:active {
140
136
  box-shadow: var(--shadow${o});
141
- }`),$=Object.keys(r.backgrounds).map(o=>`
137
+ }`),h=Object.keys(r.backgrounds).map(o=>`
142
138
  .bg_${o},
143
139
  .bg_h_${o}:hover,
144
140
  ._h:hover>.bg_h_${o} {
@@ -152,11 +148,11 @@
152
148
 
153
149
  .bg_a_${o}:active {
154
150
  background: var(--background${o});
155
- }`),h=Object.keys(r.colors).map(o=>`'${o}'`).join(" | "),s=Object.keys(r.backgrounds).map(o=>`'${o}'`).join(" | "),b=Object.keys(r.shadows).map(o=>`'${o}'`).join(" | "),d=`import {ColorType} from '@cronocode/react-box';
151
+ }`),s=Object.keys(r.colors).map(o=>`'${o}'`).join(" | "),$=Object.keys(r.backgrounds).map(o=>`'${o}'`).join(" | "),b=Object.keys(r.shadows).map(o=>`'${o}'`).join(" | "),p=`import {ColorType} from '@cronocode/react-box';
156
152
 
157
153
  declare module '@cronocode/react-box' {
158
- type ColorType = ${h};
159
- type BackgroundType = ${s};
154
+ type ColorType = ${s};
155
+ type BackgroundType = ${$};
160
156
  type ShadowType = ${b};
161
157
 
162
158
  namespace Augmented {
@@ -211,5 +207,6 @@ declare module '@cronocode/react-box/components/baseSvg' {
211
207
  }
212
208
  }
213
209
  }
214
- `;return{themeCss:[c,...n,...i,...$].join(`
215
- `),boxDts:d}}exports.boxTheme=p;
210
+ `;return{themeCss:[e.join(`
211
+ `),...n,...i,...h].join(`
212
+ `),boxDts:p}}exports.boxTheme=u;
package/plugins.mjs CHANGED
@@ -1,12 +1,10 @@
1
- function p(r) {
2
- const l = Object.entries(r.colors).map(([o, e]) => `--color${o}: ${e};`).join(`
3
- `), _ = Object.entries(r.shadows).map(([o, e]) => `--shadow${o}: ${e};`).join(`
4
- `), t = Object.entries(r.backgrounds).map(([o, e]) => `--background${o}: ${e};`).join(`
5
- `), c = `:root {
6
- ${l}
7
- ${_}
8
- ${t}
9
- }`, n = Object.keys(r.colors).map((o) => `
1
+ function d(r) {
2
+ const _ = Object.entries(r.colors).map(([o, l]) => `--color${o}: ${l};`).join(`
3
+ `), t = Object.entries(r.shadows).map(([o, l]) => `--shadow${o}: ${l};`).join(`
4
+ `), c = Object.entries(r.backgrounds).map(([o, l]) => `--background${o}: ${l};`).join(`
5
+ `), e = [":root {"];
6
+ _ && e.push(` ${_}`), t && e.push(` ${t}`), c && e.push(` ${c}`), e.push("}");
7
+ const n = Object.keys(r.colors).map((o) => `
10
8
  .color_${o},
11
9
  .color_h_${o}:hover,
12
10
  ._h:hover>.color_h_${o} {
@@ -139,7 +137,7 @@ function p(r) {
139
137
 
140
138
  .shadow_a_${o}:active {
141
139
  box-shadow: var(--shadow${o});
142
- }`), $ = Object.keys(r.backgrounds).map((o) => `
140
+ }`), h = Object.keys(r.backgrounds).map((o) => `
143
141
  .bg_${o},
144
142
  .bg_h_${o}:hover,
145
143
  ._h:hover>.bg_h_${o} {
@@ -153,10 +151,10 @@ function p(r) {
153
151
 
154
152
  .bg_a_${o}:active {
155
153
  background: var(--background${o});
156
- }`), h = Object.keys(r.colors).map((o) => `'${o}'`).join(" | "), s = Object.keys(r.backgrounds).map((o) => `'${o}'`).join(" | "), b = Object.keys(r.shadows).map((o) => `'${o}'`).join(" | "), d = `import {ColorType} from '@cronocode/react-box';
154
+ }`), $ = Object.keys(r.colors).map((o) => `'${o}'`).join(" | "), s = Object.keys(r.backgrounds).map((o) => `'${o}'`).join(" | "), b = Object.keys(r.shadows).map((o) => `'${o}'`).join(" | "), p = `import {ColorType} from '@cronocode/react-box';
157
155
 
158
156
  declare module '@cronocode/react-box' {
159
- type ColorType = ${h};
157
+ type ColorType = ${$};
160
158
  type BackgroundType = ${s};
161
159
  type ShadowType = ${b};
162
160
 
@@ -214,11 +212,12 @@ declare module '@cronocode/react-box/components/baseSvg' {
214
212
  }
215
213
  `;
216
214
  return {
217
- themeCss: [c, ...n, ...i, ...$].join(`
215
+ themeCss: [e.join(`
216
+ `), ...n, ...i, ...h].join(`
218
217
  `),
219
- boxDts: d
218
+ boxDts: p
220
219
  };
221
220
  }
222
221
  export {
223
- p as boxTheme
222
+ d as boxTheme
224
223
  };
package/types.d.ts CHANGED
@@ -79,7 +79,7 @@ export interface BoxPosition {
79
79
  bottom?: SizeType;
80
80
  left?: SizeType;
81
81
  }
82
- interface BoxSize {
82
+ export interface BoxSize {
83
83
  width?: BoxSizeValue;
84
84
  height?: BoxSizeValue;
85
85
  minWidth?: BoxSizeValue;