@zuzjs/ui 0.3.4 → 0.3.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.
- package/dist/ui.js +20 -6
- package/package.json +3 -2
- package/jest.config.js +0 -7
- package/rollup.config.js +0 -51
- package/src/comps/box.tsx +0 -24
- package/src/comps/button.tsx +0 -23
- package/src/comps/crumb.tsx +0 -9
- package/src/comps/form.tsx +0 -58
- package/src/comps/heading.tsx +0 -25
- package/src/comps/icon.tsx +0 -24
- package/src/comps/input.tsx +0 -24
- package/src/comps/select.tsx +0 -23
- package/src/comps/spinner.tsx +0 -24
- package/src/comps/stylesheet.tsx +0 -5
- package/src/context/AppContext.tsx +0 -3
- package/src/context/AppProvider.tsx +0 -69
- package/src/context/createSlice.tsx +0 -16
- package/src/context/index.tsx +0 -5
- package/src/core/css.ts +0 -1
- package/src/core/index.tsx +0 -241
- package/src/core/styles.ts +0 -379
- package/src/hooks/index.tsx +0 -2
- package/src/hooks/useDispatch.tsx +0 -37
- package/src/hooks/useStore.tsx +0 -25
- package/src/hooks.tsx +0 -8
- package/src/scss/mixins.scss +0 -3
- package/src/scss/props.scss +0 -92
- package/src/scss/styles.scss +0 -103
- package/src/ui.tsx +0 -13
- package/tsconfig.json +0 -21
- package/tsconfig.lib.json +0 -9
- package/tsconfig.spec.json +0 -21
package/dist/ui.js
CHANGED
|
@@ -4,6 +4,7 @@ import Cookies from 'js-cookie';
|
|
|
4
4
|
import axios from 'axios';
|
|
5
5
|
import { jsx } from 'react/jsx-runtime';
|
|
6
6
|
import { forwardRef } from 'react';
|
|
7
|
+
import Link from 'next/link';
|
|
7
8
|
import Children from 'react-children-utilities';
|
|
8
9
|
import PropTypes from 'prop-types';
|
|
9
10
|
|
|
@@ -582,6 +583,24 @@ const Heading = forwardRef((props, ref) => {
|
|
|
582
583
|
return jsx(HeadingTag, Object.assign({ className: _styles }, cleanProps(props), { children: props.html ? jsx("span", { dangerouslySetInnerHTML: { __html: props.html } }) : props.children }));
|
|
583
584
|
});
|
|
584
585
|
|
|
586
|
+
const Icon = forwardRef((props, ref) => {
|
|
587
|
+
const _styles = withStyle(Object.assign(Object.assign({}, props), { as: `icon-${props.as}`, size: props.size || 16 }));
|
|
588
|
+
return jsx("span", Object.assign({ ref: props.ref || ref, className: _styles }, cleanProps(props), { children: props.html ? jsx("span", { dangerouslySetInnerHTML: { __html: props.html } }) : props.children }));
|
|
589
|
+
});
|
|
590
|
+
|
|
591
|
+
function Crumb({ items, size }) {
|
|
592
|
+
const list = [];
|
|
593
|
+
{
|
|
594
|
+
items.map((n, i) => {
|
|
595
|
+
const h = jsx(Heading, { flex: true, size: size || 24, children: n.label }, `hc-${i}-${n.label.replace(/\s/g, '-')}`);
|
|
596
|
+
list.push(n.href ? jsx(Link, { href: n.href, className: `tdn tdnh`, children: h }, `crumb-${i}-${n.label.replace(/\s/g, '-')}`) : h);
|
|
597
|
+
if (i < items.length - 1)
|
|
598
|
+
list.push(jsx(Icon, { as: `chevron_right`, size: size || 24 }, `chev-${i}-${n.label.replace(/\s/g, '-')}`));
|
|
599
|
+
});
|
|
600
|
+
}
|
|
601
|
+
return (jsx(Box, { flex: true, aic: true, gap: 15, children: list }));
|
|
602
|
+
}
|
|
603
|
+
|
|
585
604
|
const Input = forwardRef((props, ref) => {
|
|
586
605
|
let Tag = props.tag || 'input';
|
|
587
606
|
const El = Tag;
|
|
@@ -639,11 +658,6 @@ const Form = (props) => {
|
|
|
639
658
|
}, children: jsx(Box, Object.assign({}, _props, { children: props.children })) });
|
|
640
659
|
};
|
|
641
660
|
|
|
642
|
-
const Icon = forwardRef((props, ref) => {
|
|
643
|
-
const _styles = withStyle(Object.assign(Object.assign({}, props), { as: `icon-${props.as}`, size: props.size || 16 }));
|
|
644
|
-
return jsx("span", Object.assign({ ref: props.ref || ref, className: _styles }, cleanProps(props), { children: props.html ? jsx("span", { dangerouslySetInnerHTML: { __html: props.html } }) : props.children }));
|
|
645
|
-
});
|
|
646
|
-
|
|
647
661
|
const Spinner = (props) => {
|
|
648
662
|
const { size, w, h, color, radius, anim } = props;
|
|
649
663
|
return jsx(Box, { w: size || 50, rel: true, zIndex: `1`, userSelect: `none`, h: size || 50, as: `zuz-spinner`, anim: (anim || 2).toString(), flex: true, aic: true, jcc: true, children: jsx(Box, { as: `zuz-loader`, r: radius || 4, w: w || 30, h: h || 6, bg: color || `#111` }) });
|
|
@@ -662,4 +676,4 @@ const Select = forwardRef((props, ref) => {
|
|
|
662
676
|
return jsx("select", Object.assign({ className: _styles }, cleanProps(props), { onChange: e => { props.onChange && props.onChange(e); }, children: props.options && props.options.map(o => jsx("option", { value: o.value, children: o.label }, `${props.id || props.as || props.name}-option-${o.value}`)) }));
|
|
663
677
|
});
|
|
664
678
|
|
|
665
|
-
export { Box, Button, Form, Heading, Icon, Input, Select, Spinner, Stylesheet, buildCSS, buildFormData, cleanProps, formatBytes, formatSeconds, getCookie, getStylesheet, isEmail, makeCSSValue, removeCookie, setCookie, uuid, withRest, withStyle };
|
|
679
|
+
export { Box, Button, Crumb, Form, Heading, Icon, Input, Select, Spinner, Stylesheet, buildCSS, buildFormData, cleanProps, formatBytes, formatSeconds, getCookie, getStylesheet, isEmail, makeCSSValue, removeCookie, setCookie, uuid, withRest, withStyle };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zuzjs/ui",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.6",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"exports": {
|
|
@@ -40,6 +40,7 @@
|
|
|
40
40
|
"rollup-plugin-scss": "^4.0.0",
|
|
41
41
|
"rollup-plugin-typescript2": "^0.36.0",
|
|
42
42
|
"rollup-plugin-uglify": "^6.0.4",
|
|
43
|
-
"sass": "^1.69.5"
|
|
43
|
+
"sass": "^1.69.5",
|
|
44
|
+
"next": "14.0.4"
|
|
44
45
|
}
|
|
45
46
|
}
|
package/jest.config.js
DELETED
package/rollup.config.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import typescript from 'rollup-plugin-typescript2';
|
|
2
|
-
import commonjs from '@rollup/plugin-commonjs';
|
|
3
|
-
import scss from "rollup-plugin-scss";
|
|
4
|
-
import postcss from 'postcss'
|
|
5
|
-
import livereload from 'rollup-plugin-livereload'
|
|
6
|
-
import { uglify } from 'rollup-plugin-uglify';
|
|
7
|
-
|
|
8
|
-
const isWatching = process && process.argv.includes('-w') || process.argv.includes('--watch')
|
|
9
|
-
const plugins = [
|
|
10
|
-
typescript(),
|
|
11
|
-
commonjs(),
|
|
12
|
-
scss({
|
|
13
|
-
processor: () => postcss(),
|
|
14
|
-
fileName: 'styles.css',
|
|
15
|
-
failOnError: true
|
|
16
|
-
}),
|
|
17
|
-
!isWatching && uglify()
|
|
18
|
-
// livereload()
|
|
19
|
-
]
|
|
20
|
-
const externals = [
|
|
21
|
-
"react","react-children-utilities","js-cookie","axios","nanoid","hashids","react/jsx-runtime","prop-types"
|
|
22
|
-
]
|
|
23
|
-
|
|
24
|
-
export default [
|
|
25
|
-
{
|
|
26
|
-
input: ["src/ui.tsx"],
|
|
27
|
-
output: [
|
|
28
|
-
{
|
|
29
|
-
dir: "dist",
|
|
30
|
-
entryFileNames: "[name].js",
|
|
31
|
-
format: "es",
|
|
32
|
-
exports: "named",
|
|
33
|
-
}
|
|
34
|
-
],
|
|
35
|
-
plugins: plugins,
|
|
36
|
-
externals: externals
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
input: ["src/hooks.tsx"],
|
|
40
|
-
output: [
|
|
41
|
-
{
|
|
42
|
-
dir: "dist",
|
|
43
|
-
entryFileNames: "[name].js",
|
|
44
|
-
format: "es",
|
|
45
|
-
exports: "named",
|
|
46
|
-
}
|
|
47
|
-
],
|
|
48
|
-
plugins: plugins,
|
|
49
|
-
externals: externals
|
|
50
|
-
}
|
|
51
|
-
]
|
package/src/comps/box.tsx
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
forwardRef
|
|
3
|
-
} from "react";
|
|
4
|
-
import {
|
|
5
|
-
cleanProps,
|
|
6
|
-
withStyle,
|
|
7
|
-
getStylesheet
|
|
8
|
-
} from "../core";
|
|
9
|
-
|
|
10
|
-
const Box = forwardRef(( props: { [ key: string ] : any }, ref) => {
|
|
11
|
-
|
|
12
|
-
const _styles = withStyle(props)
|
|
13
|
-
|
|
14
|
-
return <div
|
|
15
|
-
ref={props.ref || ref}
|
|
16
|
-
className={_styles}
|
|
17
|
-
{ ...cleanProps(props) }>
|
|
18
|
-
{props.html ? <span dangerouslySetInnerHTML={{ __html: props.html }} /> : props.children}
|
|
19
|
-
{/* {getStylesheet().join("")} */}
|
|
20
|
-
</div>
|
|
21
|
-
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
export default Box
|
package/src/comps/button.tsx
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
LegacyRef,
|
|
3
|
-
forwardRef
|
|
4
|
-
} from "react";
|
|
5
|
-
import {
|
|
6
|
-
cleanProps,
|
|
7
|
-
withStyle
|
|
8
|
-
} from "../core";
|
|
9
|
-
|
|
10
|
-
const Button = forwardRef(( props: { [ key: string ] : any }, ref : LegacyRef<HTMLButtonElement>) => {
|
|
11
|
-
|
|
12
|
-
const _styles = withStyle(props)
|
|
13
|
-
|
|
14
|
-
return <button
|
|
15
|
-
ref={props.ref || ref}
|
|
16
|
-
className={_styles}
|
|
17
|
-
{ ...cleanProps(props) }>
|
|
18
|
-
{props.html ? <span dangerouslySetInnerHTML={{ __html: props.html }} /> : props.children}
|
|
19
|
-
</button>
|
|
20
|
-
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
export default Button
|
package/src/comps/crumb.tsx
DELETED
package/src/comps/form.tsx
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import Box from './box'
|
|
2
|
-
import { buildFormData, isEmail } from '../core'
|
|
3
|
-
// import { useEffect, useState } from 'react'
|
|
4
|
-
import Children from 'react-children-utilities'
|
|
5
|
-
|
|
6
|
-
const Form = (props: any) => {
|
|
7
|
-
|
|
8
|
-
const _props = { ...props }
|
|
9
|
-
delete _props['children']
|
|
10
|
-
const formName = `form-${props.name}`
|
|
11
|
-
const fields = []
|
|
12
|
-
|
|
13
|
-
const validateForm = () => {
|
|
14
|
-
const _data = buildFormData(document.querySelector(`form[name="${formName}"]`))
|
|
15
|
-
const data = []
|
|
16
|
-
_data.map(f => {
|
|
17
|
-
const id = Object.keys(f)[0]
|
|
18
|
-
const field = fields.find(x => x.name == id)
|
|
19
|
-
if(field){
|
|
20
|
-
const value = decodeURIComponent(f[id])
|
|
21
|
-
let valid = 'should' in field ? field.value != "" : true
|
|
22
|
-
if('should' in field){
|
|
23
|
-
switch(field.should){
|
|
24
|
-
case "email":
|
|
25
|
-
valid = isEmail(value)
|
|
26
|
-
break;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
data.push({ name: field.name, value: value, valid: valid })
|
|
30
|
-
}
|
|
31
|
-
})
|
|
32
|
-
if(props.onSubmit){
|
|
33
|
-
props.onSubmit({ validation: !data.find(x => x.valid == false), data: data })
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
Children.deepMap(props.children, c => {
|
|
38
|
-
if(c['props'].name && !fields.find(x => x.name == c['props'].name)){
|
|
39
|
-
let xyz = { name: c['props'].name, touched: false }
|
|
40
|
-
if('should' in c['props']){
|
|
41
|
-
xyz['should'] = c['props'].should
|
|
42
|
-
}
|
|
43
|
-
fields.push(xyz)
|
|
44
|
-
}
|
|
45
|
-
return null
|
|
46
|
-
})
|
|
47
|
-
|
|
48
|
-
return <form name={formName} method={props.method || undefined} onSubmit={e => {
|
|
49
|
-
e.preventDefault(); e.stopPropagation();
|
|
50
|
-
validateForm()
|
|
51
|
-
}} >
|
|
52
|
-
<Box {..._props}>
|
|
53
|
-
{props.children}
|
|
54
|
-
</Box>
|
|
55
|
-
</form>
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export default Form
|
package/src/comps/heading.tsx
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
LegacyRef,
|
|
3
|
-
forwardRef
|
|
4
|
-
} from "react";
|
|
5
|
-
import {
|
|
6
|
-
cleanProps,
|
|
7
|
-
withStyle
|
|
8
|
-
} from "../core";
|
|
9
|
-
|
|
10
|
-
const Heading = forwardRef(( props: { [ key: string ] : any }, ref : LegacyRef<HTMLHeadingElement>) => {
|
|
11
|
-
|
|
12
|
-
const _styles = withStyle(props)
|
|
13
|
-
|
|
14
|
-
const Tag : string = `h${props.h || 1}`;
|
|
15
|
-
const HeadingTag = Tag as `h1` | `h2` | `h3` | `h4` | `h5` | `h6`
|
|
16
|
-
|
|
17
|
-
return <HeadingTag
|
|
18
|
-
className={_styles}
|
|
19
|
-
{ ...cleanProps(props) }>
|
|
20
|
-
{props.html ? <span dangerouslySetInnerHTML={{ __html: props.html }} /> : props.children}
|
|
21
|
-
</HeadingTag>
|
|
22
|
-
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
export default Heading
|
package/src/comps/icon.tsx
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
forwardRef
|
|
3
|
-
} from "react";
|
|
4
|
-
import {
|
|
5
|
-
cleanProps,
|
|
6
|
-
withStyle,
|
|
7
|
-
getStylesheet
|
|
8
|
-
} from "../core";
|
|
9
|
-
|
|
10
|
-
const Icon = forwardRef(( props: { [ key: string ] : any }, ref) => {
|
|
11
|
-
|
|
12
|
-
const _styles = withStyle({ ...props, as: `icon-${props.as}`, size: props.size || 16 })
|
|
13
|
-
|
|
14
|
-
return <span
|
|
15
|
-
ref={props.ref || ref}
|
|
16
|
-
className={_styles}
|
|
17
|
-
{ ...cleanProps(props) }>
|
|
18
|
-
{props.html ? <span dangerouslySetInnerHTML={{ __html: props.html }} /> : props.children}
|
|
19
|
-
{/* {getStylesheet().join("")} */}
|
|
20
|
-
</span>
|
|
21
|
-
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
export default Icon
|
package/src/comps/input.tsx
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Ref,
|
|
3
|
-
forwardRef
|
|
4
|
-
} from "react";
|
|
5
|
-
import {
|
|
6
|
-
cleanProps,
|
|
7
|
-
withStyle
|
|
8
|
-
} from "../core";
|
|
9
|
-
|
|
10
|
-
const Input = forwardRef(( props: { [ key: string ] : any }, ref : Ref<HTMLTextAreaElement|HTMLInputElement>) => {
|
|
11
|
-
|
|
12
|
-
let Tag : string = props.tag || 'input';
|
|
13
|
-
const El = Tag as `textarea` | `input`
|
|
14
|
-
const _styles = withStyle(props)
|
|
15
|
-
|
|
16
|
-
return <El
|
|
17
|
-
className={_styles}
|
|
18
|
-
onChange={e => { props.onChange && props.onChange(e) }}
|
|
19
|
-
{ ...cleanProps(props) }
|
|
20
|
-
/>
|
|
21
|
-
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
export default Input
|
package/src/comps/select.tsx
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Ref,
|
|
3
|
-
forwardRef
|
|
4
|
-
} from "react";
|
|
5
|
-
import {
|
|
6
|
-
cleanProps,
|
|
7
|
-
withStyle
|
|
8
|
-
} from "../core";
|
|
9
|
-
|
|
10
|
-
const Select = forwardRef(( props: { [ key: string ] : any }, ref : Ref<HTMLTextAreaElement|HTMLInputElement>) => {
|
|
11
|
-
|
|
12
|
-
const _styles = withStyle(props)
|
|
13
|
-
|
|
14
|
-
return <select
|
|
15
|
-
className={_styles}
|
|
16
|
-
{ ...cleanProps(props) }
|
|
17
|
-
onChange={e => { props.onChange && props.onChange(e) }}>
|
|
18
|
-
{props.options && props.options.map(o => <option key={`${props.id || props.as || props.name}-option-${o.value}`} value={o.value}>{o.label}</option>)}
|
|
19
|
-
</select>
|
|
20
|
-
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
export default Select
|
package/src/comps/spinner.tsx
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import Box from './box'
|
|
3
|
-
import PropTypes from 'prop-types'
|
|
4
|
-
|
|
5
|
-
const Spinner = (props : any) => {
|
|
6
|
-
|
|
7
|
-
const { size, w, h, color, radius, anim } = props
|
|
8
|
-
|
|
9
|
-
return <Box w={size || 50} rel zIndex={`1`} userSelect={`none`} h={size || 50} as={`zuz-spinner`} anim={(anim || 2).toString()} flex aic jcc>
|
|
10
|
-
<Box as={`zuz-loader`} r={radius || 4} w={w || 30} h={h || 6} bg={color || `#111`} />
|
|
11
|
-
</Box>
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
Spinner.propTypes = {
|
|
16
|
-
size: PropTypes.number,
|
|
17
|
-
w: PropTypes.number,
|
|
18
|
-
h: PropTypes.number,
|
|
19
|
-
radius: PropTypes.number,
|
|
20
|
-
color: PropTypes.string,
|
|
21
|
-
anim: PropTypes.oneOfType([PropTypes.number, PropTypes.string])
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export default Spinner;
|
package/src/comps/stylesheet.tsx
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
useCallback,
|
|
3
|
-
useEffect,
|
|
4
|
-
useMemo,
|
|
5
|
-
useReducer
|
|
6
|
-
} from 'react'
|
|
7
|
-
import AppContext from './AppContext'
|
|
8
|
-
|
|
9
|
-
let isMounted = true;
|
|
10
|
-
export const STORE_KEY = `__zuzjs`
|
|
11
|
-
export const STORE_FORM_KEY = `${STORE_KEY}forms`
|
|
12
|
-
export const STORE_DEFAUTLS = [`${STORE_KEY}base`, `${STORE_KEY}forms`]
|
|
13
|
-
|
|
14
|
-
const defaultState = {
|
|
15
|
-
[`${STORE_KEY}base`] : {
|
|
16
|
-
debug: true,
|
|
17
|
-
loading: false,
|
|
18
|
-
_tmp: Math.random()
|
|
19
|
-
},
|
|
20
|
-
[STORE_FORM_KEY] : {
|
|
21
|
-
forms: {}
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const rootReducer = (state, action ) => ({
|
|
26
|
-
...state,
|
|
27
|
-
...action.payload
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
const AppProvider = ({
|
|
31
|
-
children,
|
|
32
|
-
initialState = {}
|
|
33
|
-
}) => {
|
|
34
|
-
|
|
35
|
-
useEffect(() => {
|
|
36
|
-
isMounted = true;
|
|
37
|
-
return () => {
|
|
38
|
-
isMounted = false;
|
|
39
|
-
}
|
|
40
|
-
}, [])
|
|
41
|
-
|
|
42
|
-
const rootState = useMemo(() => ({
|
|
43
|
-
...defaultState,
|
|
44
|
-
...initialState
|
|
45
|
-
}), [initialState])
|
|
46
|
-
|
|
47
|
-
const [state, _dispatch] = useReducer(rootReducer, rootState);
|
|
48
|
-
|
|
49
|
-
const dispatch = useCallback((args) => {
|
|
50
|
-
if (isMounted) {
|
|
51
|
-
_dispatch({ ...args });
|
|
52
|
-
}
|
|
53
|
-
},
|
|
54
|
-
[_dispatch],
|
|
55
|
-
);
|
|
56
|
-
|
|
57
|
-
const providedValue = useMemo(
|
|
58
|
-
() => ({
|
|
59
|
-
...state,
|
|
60
|
-
dispatch
|
|
61
|
-
}),
|
|
62
|
-
[state]
|
|
63
|
-
)
|
|
64
|
-
|
|
65
|
-
return <AppContext.Provider value={providedValue}>{children}</AppContext.Provider>
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export default AppProvider
|
package/src/context/index.tsx
DELETED
package/src/core/css.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default {}
|