@cronocode/react-box 2.0.0 → 2.0.2
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/README.md +91 -1
- package/box.cjs +1 -1
- package/box.mjs +3 -3
- package/components/baseSvg.cjs +1 -1
- package/components/button.cjs +1 -1
- package/components/checkbox.cjs +1 -1
- package/components/flex.cjs +1 -1
- package/components/form.cjs +1 -1
- package/components/grid.cjs +1 -1
- package/components/radioButton.cjs +1 -1
- package/components/textbox.cjs +1 -1
- package/components/tooltip.cjs +1 -1
- package/core/boxStyles.d.ts +56 -56
- package/core/theme.cjs +1 -0
- package/core/theme.mjs +4 -0
- package/core.cjs +3 -3
- package/core.mjs +15 -1
- package/package.json +5 -5
- package/ssg.cjs +1 -105
- package/ssg.mjs +19 -9837
- package/core/useStyles.cssClass.test.d.ts +0 -1
- package/core/useStyles.styles.test.d.ts +0 -1
- package/ssg.test.d.ts +0 -1
- package/theme.cjs +0 -1
- package/theme.d.ts +0 -3
- package/theme.mjs +0 -4
package/README.md
CHANGED
|
@@ -68,9 +68,99 @@ import Textbox from "@cronocode/react-box/components/textbox";
|
|
|
68
68
|
import Tooltip from "@cronocode/react-box/components/tooltip";
|
|
69
69
|
```
|
|
70
70
|
|
|
71
|
-
##
|
|
71
|
+
## Extend props
|
|
72
|
+
|
|
73
|
+
1. It is possible to extend some props like `color`, `background`, `backgroundImage` and `shadow`
|
|
74
|
+
|
|
75
|
+
```JS
|
|
76
|
+
function themePlugin() {
|
|
77
|
+
return {
|
|
78
|
+
name: 'themePlugin',
|
|
79
|
+
configResolved() {
|
|
80
|
+
const result = Theme.setupAugmentedProps({
|
|
81
|
+
colors: {
|
|
82
|
+
primary: '#445566'
|
|
83
|
+
},
|
|
84
|
+
backgroundImages: {
|
|
85
|
+
gradient: 'linear-gradient(to right, #77A1D3 0%, #79CBCA 51%, #77A1D3 100%)'
|
|
86
|
+
},
|
|
87
|
+
shadows: {
|
|
88
|
+
1: '0 4px 10px rgb(224 224 224 / 52%)',
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
fs.writeFileSync('./src/box-theme.generated.css', result.variables);
|
|
93
|
+
fs.writeFileSync('./src/box.generated.d.ts', result.boxDts);
|
|
94
|
+
},
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
2. Add this plugin to your build tool
|
|
101
|
+
|
|
102
|
+
Vitejs
|
|
103
|
+
|
|
104
|
+
```JS
|
|
105
|
+
// https://vitejs.dev/config/
|
|
106
|
+
export default defineConfig({
|
|
107
|
+
plugins: [..., themePlugin()],
|
|
108
|
+
})
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
3. Include `box-theme.generated.css` in your root file
|
|
112
|
+
|
|
113
|
+
```JS
|
|
114
|
+
import './box-theme.generated.css';
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Theme for components
|
|
118
|
+
|
|
119
|
+
In the project root file (main.tsx) use `Theme.setup`
|
|
120
|
+
|
|
121
|
+
```JS
|
|
122
|
+
import Theme from '@cronocode/react-box/theme';
|
|
72
123
|
|
|
124
|
+
Theme.setup({
|
|
125
|
+
button: {
|
|
126
|
+
styles: {
|
|
127
|
+
px: 4
|
|
128
|
+
},
|
|
129
|
+
themes: {
|
|
130
|
+
mytheme: {
|
|
131
|
+
px: 8
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
...
|
|
136
|
+
})
|
|
73
137
|
```
|
|
138
|
+
|
|
139
|
+
All styles will be applied to Button component
|
|
140
|
+
|
|
141
|
+
```JS
|
|
142
|
+
import Button from '@cronocode/react-box/components/button';
|
|
143
|
+
|
|
144
|
+
function MyComponent() {
|
|
145
|
+
return <Button>Click me</Button>
|
|
146
|
+
}
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
or is possible to use Button with specific theme
|
|
150
|
+
|
|
151
|
+
```JS
|
|
152
|
+
import Button from '@cronocode/react-box/components/button';
|
|
153
|
+
|
|
154
|
+
function MyComponent() {
|
|
155
|
+
return <Button theme="mytheme">Click me</Button>
|
|
156
|
+
}
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## Theme variables
|
|
160
|
+
|
|
161
|
+
In CSS file is possible to override default values for:
|
|
162
|
+
|
|
163
|
+
```CSS
|
|
74
164
|
--borderColor: black;
|
|
75
165
|
--outlineColor: black;
|
|
76
166
|
--lineHeight: 1.2;
|
package/box.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const s=require("react"),u=require("./core.cjs");function g(t,
|
|
1
|
+
"use strict";const s=require("react"),u=require("./core.cjs");function g(t,r){const{tag:n="div",children:o,props:f,className:d,style:c,disabled:a}=t,y=u.useStyles(t,n==="svg"),m=s.useMemo(()=>u.classNames(y,d).join(" "),[t]),e={...f,className:m,disabled:Array.isArray(a)?a[0]:a};c&&(e.style=c),r&&(e.ref=r);const[v,l]=s.useState(!1),i=typeof o=="function";return i&&(e.onMouseEnter=()=>l(!0),e.onMouseLeave=()=>l(!1)),s.createElement(n,e,i?o({isHover:v}):o)}const N=s.forwardRef(g);module.exports=N;
|
package/box.mjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import y, { forwardRef as v, useMemo as g, useState as p } from "react";
|
|
2
2
|
import { u as N, c as x } from "./core.mjs";
|
|
3
3
|
function H(s, o) {
|
|
4
|
-
const { tag: r = "div", children: t, props: i, className:
|
|
4
|
+
const { tag: r = "div", children: t, props: i, className: f, style: n, disabled: a } = s, u = N(s, r === "svg"), m = g(() => x(u, f).join(" "), [s]), e = { ...i, className: m, disabled: Array.isArray(a) ? a[0] : a };
|
|
5
5
|
n && (e.style = n), o && (e.ref = o);
|
|
6
6
|
const [d, l] = p(!1), c = typeof t == "function";
|
|
7
7
|
return c && (e.onMouseEnter = () => l(!0), e.onMouseLeave = () => l(!1)), y.createElement(r, e, c ? t({ isHover: d }) : t);
|
|
8
8
|
}
|
|
9
|
-
const
|
|
9
|
+
const b = v(H);
|
|
10
10
|
export {
|
|
11
|
-
|
|
11
|
+
b as default
|
|
12
12
|
};
|
package/components/baseSvg.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const
|
|
1
|
+
"use strict";const c=require("react/jsx-runtime"),g=require("react"),p=require("../box.cjs");function u(s,e){const{viewBox:r="0 0 24 24",width:t="1.5rem",height:o,props:n,...i}=s;return c.jsx(p,{tag:"svg",ref:e,props:{...n,viewBox:r,width:t,height:o,xmlns:"http://www.w3.org/2000/svg",fill:"none"},...i})}const w=g.forwardRef(u);module.exports=w;
|
package/components/button.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const
|
|
1
|
+
"use strict";const e=require("react/jsx-runtime"),r=require("react"),s=require("../box.cjs"),u=require("../utils.cjs"),c=["type","onClick"];function i(t,o){const n=u.ObjectUtils.buildProps(t,c);return e.jsx(s,{ref:o,tag:"button",component:"button",...n})}const b=r.forwardRef(i);module.exports=b;
|
package/components/checkbox.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const u=require("react/jsx-runtime"),t=require("react"),s=require("../box.cjs"),i=require("../utils.cjs"),a=["name","onInput","onChange","autoFocus","readOnly","required","value","checked","defaultChecked"];function d(n,
|
|
1
|
+
"use strict";const u=require("react/jsx-runtime"),t=require("react"),s=require("../box.cjs"),i=require("../utils.cjs"),a=["name","onInput","onChange","autoFocus","readOnly","required","value","checked","defaultChecked"];function d(n,r){const{indeterminate:c}=n,o=i.ObjectUtils.buildProps(n,a,{type:"checkbox"}),e=t.useRef(null);return t.useImperativeHandle(r,()=>e.current),t.useEffect(()=>{e.current&&(e.current.indeterminate=!!c)},[e,c]),u.jsx(s,{tag:"input",ref:e,component:"checkbox",...o})}const f=t.forwardRef(d);module.exports=f;
|
package/components/flex.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const
|
|
1
|
+
"use strict";const t=require("react/jsx-runtime"),i=require("react"),o=require("../box.cjs");function c(e,r){const{inline:n,...s}=e;return t.jsx(o,{ref:r,display:n?"inline-flex":"flex",...s})}const x=i.forwardRef(c);module.exports=x;
|
package/components/form.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const m=require("react/jsx-runtime"),o=require("react"),
|
|
1
|
+
"use strict";const m=require("react/jsx-runtime"),o=require("react"),a=require("../box.cjs"),f=require("../utils.cjs");function l(t){const{onSubmit:s,props:n}=t,r=o.useRef(null),u=o.useCallback(e=>{e.preventDefault();const i=f.FormUtils.getFormEntries(r.current);s(i,e)},[]),c={...n,onSubmit:u,ref:r};return m.jsx(a,{tag:"form",...t,props:c})}module.exports=l;
|
package/components/grid.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const s=require("react/jsx-runtime"),t=require("react"),o=require("../box.cjs");function
|
|
1
|
+
"use strict";const s=require("react/jsx-runtime"),t=require("react"),o=require("../box.cjs");function c(r,e){const{inline:i,...n}=r;return s.jsx(o,{ref:e,display:i?"inline-grid":"grid",...n})}const u=t.forwardRef(c);module.exports=u;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const
|
|
1
|
+
"use strict";const n=require("react/jsx-runtime"),r=require("react"),u=require("../box.cjs"),s=require("../utils.cjs"),c=["name","onInput","onChange","value","autoFocus","readOnly","required","checked","defaultChecked"];function i(t,e){const o=s.ObjectUtils.buildProps(t,c,{type:"radio"});return n.jsx(u,{ref:e,tag:"input",component:"radioButton",...o})}const a=r.forwardRef(i);module.exports=a;
|
package/components/textbox.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const
|
|
1
|
+
"use strict";const n=require("react/jsx-runtime"),r=require("react"),s=require("../box.cjs"),u=require("../utils.cjs"),c=["name","onInput","onChange","type","placeholder","defaultValue","autoFocus","readOnly","required","value","pattern"];function a(e,t){const o=u.ObjectUtils.buildProps(e,c);return n.jsx(s,{ref:t,tag:"input",component:"textbox",...o})}const i=r.forwardRef(a);module.exports=i;
|
package/components/tooltip.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const
|
|
1
|
+
"use strict";const u=require("react/jsx-runtime"),h=require("react-dom"),f=require("../box.cjs"),s=require("react");function v(){return s.useMemo(()=>{const i="crono-box";let r=document.getElementById(i);return r||(r=document.createElement("div"),r.id=i,document.body.appendChild(r)),r},[])}const a=2;function x(i){const{onPositionChange:r}=i,l=s.useRef(null),[e,p]=s.useState(),m=v(),w=s.useCallback((o,t)=>{const n=c=>{c.target.contains(o)&&t(o)};return document.addEventListener("scroll",n,{capture:!0}),()=>{document.removeEventListener("scroll",n,{capture:!0})}},[e]),b=s.useCallback((o,t)=>{const n=c=>{t(o)};return window.addEventListener("resize",n,{capture:!0}),()=>{window.removeEventListener("resize",n,{capture:!0})}},[e]),d=s.useCallback(o=>{const t=o.getBoundingClientRect(),n=Math.round((t.top+window.scrollY)*a)/a,c=Math.round((t.left+window.scrollX)*a)/a;((e==null?void 0:e.top)!==n||(e==null?void 0:e.left)!==c)&&(r==null||r({top:n,left:c}),p({top:n,left:c,width:t.width>0?t.width:void 0}))},[e]);return s.useLayoutEffect(()=>{if(l.current){d(l.current);const o=w(l.current,d),t=b(l.current,d);return()=>{o(),t()}}},[e]),u.jsxs(u.Fragment,{children:[u.jsx(f,{ref:l}),e&&h.createPortal(u.jsx(f,{position:"absolute",top:0,left:0,transition:"none",style:{transform:`translate(${e.left}px,${e.top}px)`,width:e.width},children:u.jsx(f,{position:"absolute",width:"fit",...i})}),m)]})}module.exports=x;
|