@zuzjs/ui 0.5.2 → 0.5.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.
Files changed (46) hide show
  1. package/dist/bin.js +3 -3
  2. package/dist/comps/alert.d.ts +15 -0
  3. package/dist/comps/alert.js +15 -0
  4. package/dist/comps/avatar.d.ts +13 -0
  5. package/dist/comps/avatar.js +11 -0
  6. package/dist/comps/base.d.ts +3 -1
  7. package/dist/comps/base.js +38 -4
  8. package/dist/comps/box.d.ts +2 -5
  9. package/dist/comps/checkbox.js +3 -3
  10. package/dist/comps/contextmenu.js +1 -1
  11. package/dist/comps/drawer.js +5 -1
  12. package/dist/comps/form.d.ts +1 -0
  13. package/dist/comps/form.js +12 -3
  14. package/dist/comps/heading.d.ts +2 -4
  15. package/dist/comps/heading.js +4 -2
  16. package/dist/comps/progressbar.d.ts +11 -0
  17. package/dist/comps/progressbar.js +14 -0
  18. package/dist/comps/select.js +4 -5
  19. package/dist/comps/sheet.d.ts +5 -2
  20. package/dist/comps/sheet.js +24 -8
  21. package/dist/comps/tabview.d.ts +5 -1
  22. package/dist/comps/tabview.js +14 -4
  23. package/dist/comps/treeview/index.d.ts +28 -0
  24. package/dist/comps/treeview/index.js +24 -0
  25. package/dist/comps/treeview/item.d.ts +15 -0
  26. package/dist/comps/treeview/item.js +23 -0
  27. package/dist/funs/css.d.ts +3 -1
  28. package/dist/funs/css.js +64 -6
  29. package/dist/funs/index.d.ts +9 -1
  30. package/dist/funs/index.js +118 -0
  31. package/dist/funs/stylesheet.d.ts +1 -0
  32. package/dist/funs/stylesheet.js +51 -0
  33. package/dist/hooks/index.d.ts +1 -0
  34. package/dist/hooks/index.js +1 -0
  35. package/dist/hooks/useImage.d.ts +2 -0
  36. package/dist/hooks/useImage.js +22 -0
  37. package/dist/hooks/useKeyBind.d.ts +3 -0
  38. package/dist/hooks/useKeyBind.js +3 -0
  39. package/dist/index.d.ts +5 -1
  40. package/dist/index.js +5 -1
  41. package/dist/styles.css +1 -1
  42. package/dist/types/enums.d.ts +127 -1
  43. package/dist/types/enums.js +133 -0
  44. package/dist/types/index.d.ts +8 -0
  45. package/dist/types/interfaces.d.ts +10 -0
  46. package/package.json +1 -1
package/dist/bin.js CHANGED
@@ -85,9 +85,9 @@ const rebuildAll = () => {
85
85
  if (files.length > 0) {
86
86
  const as = [];
87
87
  if (options.file) {
88
- const r = rebuild(files.filter(f => f.endsWith(options.file))[0]);
88
+ const r = rebuild(files.filter(f => f.endsWith(options.file.replace(path.resolve(`./`), ``)))[0]);
89
89
  if (r && r.length > 0) {
90
- as.push(cssBuilder.Build([r], true).sheet);
90
+ as.push(cssBuilder.Build([r], true, options.file).sheet);
91
91
  }
92
92
  }
93
93
  else {
@@ -95,7 +95,7 @@ const rebuildAll = () => {
95
95
  files.map(f => {
96
96
  const r = rebuild(f);
97
97
  if (r && r.length > 0) {
98
- const _built = cssBuilder.Build([r], true);
98
+ const _built = cssBuilder.Build([r], true, f.replace(path.resolve(`./`), ``));
99
99
  as.push(_built.sheet);
100
100
  Object.keys(_built.mediaQuery).map(mq => {
101
101
  if (!mediaQueries[mq])
@@ -0,0 +1,15 @@
1
+ import { BaseProps } from "../types/interfaces";
2
+ import { ALERT } from "../types/enums";
3
+ export interface AlertProps {
4
+ type?: ALERT;
5
+ icon?: string;
6
+ iconSize?: number;
7
+ message?: string;
8
+ title: string;
9
+ }
10
+ export interface AlertHandler {
11
+ open: () => void;
12
+ close: () => void;
13
+ }
14
+ declare const Alert: import("react").ForwardRefExoticComponent<AlertProps & BaseProps & import("react").RefAttributes<AlertHandler>>;
15
+ export default Alert;
@@ -0,0 +1,15 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { forwardRef } from "react";
3
+ import { ALERT } from "../types/enums";
4
+ import With from "./base";
5
+ const Icons = {
6
+ [ALERT.Info]: _jsx("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", fill: "none", children: _jsx("path", { fill: "#292D32", d: "M21.56 10.738l-1.35-1.58c-.25-.3-.46-.86-.46-1.26v-1.7c0-1.06-.87-1.93-1.93-1.93h-1.7c-.4 0-.97-.21-1.27-.46l-1.58-1.35c-.69-.59-1.82-.59-2.51 0l-1.6 1.35c-.3.25-.86.46-1.26.46H6.17c-1.06 0-1.93.87-1.93 1.93v1.7c0 .39-.2.95-.45 1.25l-1.35 1.59c-.58.7-.58 1.82 0 2.5l1.35 1.59c.25.29.45.86.45 1.25v1.71c0 1.06.87 1.93 1.93 1.93h1.74c.39 0 .96.21 1.26.46l1.58 1.35c.69.59 1.82.59 2.51 0l1.58-1.35c.3-.25.86-.46 1.26-.46h1.7c1.06 0 1.93-.87 1.93-1.93v-1.7c0-.4.21-.96.46-1.26l1.35-1.58c.61-.68.61-1.81.02-2.51zm-10.31-2.61c0-.41.34-.75.75-.75s.75.34.75.75v4.83c0 .41-.34.75-.75.75s-.75-.34-.75-.75v-4.83zm.75 8.74c-.55 0-1-.45-1-1s.44-1 1-1c.55 0 1 .45 1 1s-.44 1-1 1z" }) }),
7
+ [ALERT.Warning]: _jsx("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", fill: "none", children: _jsx("path", { fill: "#292D32", d: "M19.51 5.85l-5.94-3.43c-.97-.56-2.17-.56-3.15 0L4.49 5.85a3.15 3.15 0 00-1.57 2.73v6.84c0 1.12.6 2.16 1.57 2.73l5.94 3.43c.97.56 2.17.56 3.15 0l5.94-3.43a3.15 3.15 0 001.57-2.73V8.58a3.192 3.192 0 00-1.58-2.73zm-8.26 1.9c0-.41.34-.75.75-.75s.75.34.75.75V13c0 .41-.34.75-.75.75s-.75-.34-.75-.75V7.75zm1.67 8.88c-.05.12-.12.23-.21.33a.99.99 0 01-1.09.21c-.13-.05-.23-.12-.33-.21-.09-.1-.16-.21-.22-.33a.986.986 0 01-.07-.38c0-.26.1-.52.29-.71.1-.09.2-.16.33-.21.37-.16.81-.07 1.09.21.09.1.16.2.21.33.05.12.08.25.08.38s-.03.26-.08.38z" }) }),
8
+ [ALERT.Error]: _jsx("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", fill: "none", children: _jsx("path", { d: "M1 21h22L12 2 1 21zm12-3h-2v-2h2v2zm0-4h-2v-4h2v4z" }) }),
9
+ [ALERT.Success]: _jsx("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", fill: "none", children: _jsx("path", { d: "M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-2 15l-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z" }) })
10
+ };
11
+ const Alert = forwardRef((props, ref) => {
12
+ const { type, icon, title, message, iconSize, ...rest } = props;
13
+ return _jsxs(With, { className: `--alert --${(type || ALERT.Info).toLowerCase()} flex aic`, ...rest, children: [_jsx(With, { className: `--icon icon-${icon || `auto-matic`}`, style: iconSize ? { width: iconSize, height: iconSize } : {}, children: !icon && Icons[type || ALERT.Info] }), _jsxs(With, { className: `--meta flex cols`, tag: `h1`, children: [_jsx(With, { className: `--title ${message ? `--tm` : ``}`, tag: `h1`, children: title || `Lorem ipsum dolor sit amet, consectetur adipiscing elit.` }), message && _jsx(With, { className: `--message`, tag: `h2`, children: message })] })] });
14
+ });
15
+ export default Alert;
@@ -0,0 +1,13 @@
1
+ import { BaseProps } from "../types/interfaces";
2
+ import { AVATAR } from "../types/enums";
3
+ export interface AvatarProps {
4
+ type?: AVATAR;
5
+ size?: number;
6
+ src: string;
7
+ crossOrigin?: 'anonymous' | 'use-credentials';
8
+ referrerPolicy?: 'no-referrer' | 'no-referrer-when-downgrade' | 'origin' | 'origin-when-cross-origin' | 'same-origin' | 'strict-origin' | 'strict-origin-when-cross-origin' | 'unsafe-url';
9
+ }
10
+ export interface AvatarHandler {
11
+ }
12
+ declare const Avatar: import("react").ForwardRefExoticComponent<AvatarProps & BaseProps & import("react").RefAttributes<AvatarHandler>>;
13
+ export default Avatar;
@@ -0,0 +1,11 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { forwardRef } from "react";
3
+ import { AVATAR } from "../types/enums";
4
+ import With from "./base";
5
+ import { useImage } from "../hooks";
6
+ const Avatar = forwardRef((props, ref) => {
7
+ const { src, size, type, crossOrigin, referrerPolicy, ...rest } = props;
8
+ const [img, imgStatus, imgError] = useImage(src, crossOrigin, referrerPolicy);
9
+ return _jsx(With, { tag: `img`, src: img, style: size ? { width: size, height: size } : {}, crossOrigin: crossOrigin, referrerPolicy: referrerPolicy, className: `--avatar --${(type || AVATAR.Circle).toLowerCase()}`, ...rest });
10
+ });
11
+ export default Avatar;
@@ -1,6 +1,7 @@
1
1
  import { ComponentPropsWithoutRef, ElementType } from "react";
2
2
  import { dynamicObject } from "../types";
3
3
  import { TRANSITION_CURVES, TRANSITIONS } from "../types/enums";
4
+ import { Skeleton } from "../types/interfaces";
4
5
  export interface animationProps {
5
6
  transition?: TRANSITIONS;
6
7
  from?: dynamicObject;
@@ -13,9 +14,10 @@ export interface animationProps {
13
14
  interface BaseProps<T extends ElementType> {
14
15
  tag?: T;
15
16
  as?: string | string[];
17
+ animate?: animationProps;
16
18
  className?: string;
17
19
  propsToRemove?: string[];
18
- animate?: animationProps;
20
+ skeleton?: Skeleton;
19
21
  }
20
22
  export type Props<T extends ElementType> = BaseProps<T> & ComponentPropsWithoutRef<T>;
21
23
  declare const With: import("react").ForwardRefExoticComponent<Omit<Props<ElementType>, "ref"> & import("react").RefAttributes<Element>>;
@@ -1,7 +1,33 @@
1
1
  import { createElement, forwardRef } from "react";
2
2
  import { css, cleanProps } from "../funs";
3
3
  import { buildWithStyles, getAnimationCurve, getAnimationTransition } from "../funs/css";
4
- const With = forwardRef(({ tag, as, animate, className, propsToRemove, style, ...rest }, ref) => {
4
+ const buildSkeletonStyle = (s) => {
5
+ const makeValue = (v, unit = `px`) => {
6
+ return v ?
7
+ `string` == typeof v ? v : `${v}${unit}`
8
+ : `inherit`;
9
+ };
10
+ const style = {};
11
+ if (s.radius) {
12
+ style.borderRadius = makeValue(s.radius);
13
+ }
14
+ if (s.size) {
15
+ style.width = style.minWidth = style.maxWidth = style.height = style.minHeight = style.maxHeight = makeValue(s.size);
16
+ }
17
+ else if (s.width || s.height) {
18
+ if (s.width) {
19
+ style.width = style.minWidth = style.maxWidth = makeValue(s.width);
20
+ }
21
+ if (s.height) {
22
+ style.height = style.minHeight = style.maxHeight = makeValue(s.height);
23
+ }
24
+ }
25
+ else {
26
+ style.minWidth = style.minHeight = `100%`;
27
+ }
28
+ return style;
29
+ };
30
+ const With = forwardRef(({ tag, as, animate, className, propsToRemove, style, skeleton, ...rest }, ref) => {
5
31
  const Comp = tag || 'div';
6
32
  let cx = [];
7
33
  if (as) {
@@ -19,14 +45,22 @@ const With = forwardRef(({ tag, as, animate, className, propsToRemove, style, ..
19
45
  else {
20
46
  _style = transition ? getAnimationTransition(transition, false, true) : from || {};
21
47
  }
48
+ const { children, ...restProps } = cleanProps(rest, propsToRemove ? [...propsToRemove, `skeleton`] : [`skeleton`]);
22
49
  return createElement(Comp, {
23
50
  style: {
24
51
  ...buildWithStyles(_style),
25
52
  ..._transition,
26
- ...style
53
+ ...style,
54
+ ...(skeleton?.enabled ? buildSkeletonStyle(skeleton) : {})
27
55
  },
28
- className: [className, ...cx].join(' ').trim(),
29
- ...cleanProps(rest, propsToRemove || []),
56
+ className: [
57
+ className,
58
+ ...cx,
59
+ skeleton?.enabled ? `--skeleton` : ``
60
+ ].join(' ').trim(),
61
+ children: skeleton?.enabled ? ` `.repeat(6)
62
+ : children,
63
+ ...restProps,
30
64
  ref
31
65
  });
32
66
  });
@@ -1,6 +1,3 @@
1
- import { animationProps } from "./base";
2
- declare const Box: import("react").ForwardRefExoticComponent<{
3
- as?: string;
4
- animate?: animationProps;
5
- } & Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & import("react").RefAttributes<HTMLDivElement>>;
1
+ import { BaseProps } from "../types/interfaces";
2
+ declare const Box: import("react").ForwardRefExoticComponent<BaseProps & Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & import("react").RefAttributes<HTMLDivElement>>;
6
3
  export default Box;
@@ -4,8 +4,8 @@ import { forwardRef, useImperativeHandle, useRef, useState } from "react";
4
4
  import With from "./base";
5
5
  import { CHECKBOX } from "../types/enums";
6
6
  const CheckBox = forwardRef((props, ref) => {
7
- const { as, name, required, type, value, onChange, ...rest } = props;
8
- const [checked, _setChecked] = useState(props.checked || false);
7
+ const { as, name, required, type, value, checked: defaultCheck, onChange, ...rest } = props;
8
+ const [checked, _setChecked] = useState(defaultCheck || false);
9
9
  const bRef = useRef(null);
10
10
  useImperativeHandle(ref, () => ({
11
11
  setChecked(mod, triggerChange = true) {
@@ -24,7 +24,7 @@ const CheckBox = forwardRef((props, ref) => {
24
24
  _setChecked(!checked);
25
25
  }
26
26
  }));
27
- return _jsx(With, { tag: `label`, className: `${type == CHECKBOX.Default ? `checkbox icon-check` : `zuz-checkbox`} flex aic jcc ${checked ? `is-checked` : ``} rel`.trim(), as: as, ...rest, children: _jsx(With, { tag: `input`, ref: bRef, value: value || `cb`, type: `checkbox`, className: `abs`, name: name, required: required || false, onChange: (e) => {
27
+ return _jsx(With, { tag: `label`, className: `${type == CHECKBOX.Default ? `checkbox icon-check` : `zuz-checkbox`} flex aic jcc ${checked ? `is-checked` : ``} rel`.trim(), as: as, ...rest, children: _jsx(With, { tag: `input`, ref: bRef, defaultChecked: checked, value: value || `cb`, type: `checkbox`, className: `abs`, name: name, required: required || false, onChange: (e) => {
28
28
  onChange && onChange(e.target.checked, value || `cb`);
29
29
  _setChecked(e.target.checked);
30
30
  } }) });
@@ -3,7 +3,7 @@ import { forwardRef } from "react";
3
3
  import With from "./base";
4
4
  const ContextMenu = forwardRef((props, ref) => {
5
5
  const { as, items, ...rest } = props;
6
- return _jsx(With, { as: as, className: `zuz-context-menu abs flex cols`, ...rest, ref: ref, children: items.map((item, index) => item.label == `-` ? _jsx(With, { as: `context-line` }, `${index}-line`) :
6
+ return _jsx(With, { as: as, className: `context-menu abs flex cols`, ...rest, ref: ref, children: items.map((item, index) => item.label == `-` ? _jsx(With, { as: `context-line` }, `${index}-line`) :
7
7
  _jsxs(With, { onClick: item.onSelect, as: `button`, className: `context-menu-item flex aic ${item.className || ``}`.trim(), children: [_jsx(With, { as: `div`, className: `ico icon-${item.icon}`.trim(), style: item.iconColor ? { color: item.iconColor } : {} }), _jsx(With, { as: `h1`, className: `flex aic`, style: item.labelColor ? { color: item.labelColor } : {}, children: item.label })] }, `item-${item.label.replace(/\s/g, `-`)}-${index}`)) });
8
8
  });
9
9
  export default ContextMenu;
@@ -1,7 +1,8 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  import { forwardRef, useEffect, useImperativeHandle, useMemo, useRef, useState } from "react";
3
3
  import With from "./base";
4
- import { DRAWER_SIDE, TRANSITION_CURVES, TRANSITIONS } from "../types/enums";
4
+ import { DRAWER_SIDE, KeyCode, TRANSITION_CURVES, TRANSITIONS } from "../types/enums";
5
+ import { bindKey } from "../funs";
5
6
  const Drawer = forwardRef((props, ref) => {
6
7
  const { as, from, speed, children, prerender, ...rest } = props;
7
8
  const [render, setRender] = useState(undefined == prerender ? true : prerender);
@@ -11,6 +12,9 @@ const Drawer = forwardRef((props, ref) => {
11
12
  useEffect(() => {
12
13
  setContent(children);
13
14
  }, [children]);
15
+ useEffect(() => {
16
+ bindKey(KeyCode.Escape, () => visible && setVisible(false));
17
+ }, []);
14
18
  const style = useMemo(() => {
15
19
  switch (from) {
16
20
  case DRAWER_SIDE.Left:
@@ -18,6 +18,7 @@ export interface FormProps {
18
18
  }
19
19
  export interface FormHandler {
20
20
  setLoading: (mode: boolean) => void;
21
+ hideError: () => void;
21
22
  }
22
23
  declare const Form: import("react").ForwardRefExoticComponent<FormProps & Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & import("react").RefAttributes<FormHandler>>;
23
24
  export default Form;
@@ -19,6 +19,9 @@ const Form = forwardRef((props, ref) => {
19
19
  if (el.type == `checkbox` && el.checked == false) {
20
20
  return false;
21
21
  }
22
+ if (el.classList.contains(`--select`) && el.dataset.value == `-1`) {
23
+ return false;
24
+ }
22
25
  if (el.value == ``)
23
26
  return false;
24
27
  }
@@ -70,9 +73,9 @@ const Form = forwardRef((props, ref) => {
70
73
  valid = _validate(el);
71
74
  data[el.name] = {
72
75
  valid: valid,
73
- value: el.value
76
+ value: el.classList.contains(`--select`) ? el.dataset.value : el.value
74
77
  };
75
- payload[el.name] = el.value;
78
+ payload[el.name] = el.classList.contains(`--select`) ? el.dataset.value : el.value;
76
79
  if (!valid) {
77
80
  if (_error == null && errors) {
78
81
  _error = el;
@@ -136,13 +139,19 @@ const Form = forwardRef((props, ref) => {
136
139
  };
137
140
  useImperativeHandle(ref, () => ({
138
141
  setLoading(mod) {
142
+ if (mod) {
143
+ sheet.current.hide();
144
+ }
139
145
  setLoading(mod);
140
146
  },
141
147
  showError(errorMsg) {
142
148
  sheet.current.show(errorMsg, 4, SHEET.Error);
149
+ },
150
+ hideError() {
151
+ sheet.current.hide();
143
152
  }
144
153
  }));
145
154
  useEffect(_init, []);
146
- return _jsxs(With, { as: as, className: `rel`, ref: _ref, propsToRemove: [`withData`, `action`, `onSubmit`, `onSuccess`, `onError`], ...rest, children: [_jsx(Sheet, { ref: sheet }), loading && _jsx(Cover, { message: cover ? cover.message || undefined : `working`, ...{ spinner, color: cover ? `color` in cover ? cover.color : `#ffffff` : `#ffffff` } }), children] });
155
+ return _jsxs(With, { as: as, className: `rel`, ref: _ref, propsToRemove: [`withData`, `action`, `onSubmit`, `onSuccess`, `onError`], ...rest, children: [_jsx(Sheet, { ref: sheet, as: `toast-form` }), loading && _jsx(Cover, { message: cover ? cover.message || undefined : `working`, ...{ spinner, color: cover ? `color` in cover ? cover.color : `#ffffff` : `#ffffff` } }), children] });
147
156
  });
148
157
  export default Form;
@@ -1,9 +1,7 @@
1
1
  import { ReactNode } from "react";
2
- import { animationProps } from "./base";
2
+ import { BaseProps } from "../types/interfaces";
3
3
  declare const Heading: import("react").ForwardRefExoticComponent<{
4
- as?: string;
5
4
  h?: number | string;
6
5
  html?: ReactNode | string;
7
- animate?: animationProps;
8
- } & Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLHeadingElement>, HTMLHeadingElement>, "ref"> & import("react").RefAttributes<HTMLDivElement>>;
6
+ } & BaseProps & Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLHeadingElement>, HTMLHeadingElement>, "ref"> & import("react").RefAttributes<HTMLDivElement>>;
9
7
  export default Heading;
@@ -2,7 +2,9 @@ import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { forwardRef } from "react";
3
3
  import With from "./base";
4
4
  const Heading = forwardRef((props, ref) => {
5
- const { as, h, html, children, ...rest } = props;
6
- return _jsx(With, { tag: `h${h || 1}`, as: as, ref: ref, ...rest, children: props.html ? _jsx("span", { ...({ dangerouslySetInnerHTML: { __html: html } }) }) : children });
5
+ const { as, h, html, ...rest } = props;
6
+ return _jsx(With, { tag: `h${h || 1}`, as: as, ref: ref, ...rest, children: props.children ?
7
+ props.html ? _jsx("span", { ...({ dangerouslySetInnerHTML: { __html: html } }) }) : props.children
8
+ : null });
7
9
  });
8
10
  export default Heading;
@@ -0,0 +1,11 @@
1
+ import { BaseProps } from "../types/interfaces";
2
+ import { PROGRESS } from "../types/enums";
3
+ export interface ProgressBarProps {
4
+ progress: number;
5
+ type?: PROGRESS;
6
+ }
7
+ export interface ProgressHandler {
8
+ setWidth?: (w: number) => void;
9
+ }
10
+ declare const ProgressBar: import("react").ForwardRefExoticComponent<ProgressBarProps & BaseProps & import("react").RefAttributes<ProgressHandler>>;
11
+ export default ProgressBar;
@@ -0,0 +1,14 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { forwardRef, useImperativeHandle, useRef } from "react";
3
+ import With from "./base";
4
+ const ProgressBar = forwardRef((props, ref) => {
5
+ const { as } = props;
6
+ const bar = useRef(null);
7
+ useImperativeHandle(ref, () => ({
8
+ setWidth: (progress) => {
9
+ bar.current.style.width = `${progress * 100}%`;
10
+ }
11
+ }), []);
12
+ return _jsx(With, { className: `--progress flex rel`, as: as, children: _jsx(With, { ref: bar, className: `--bar rel` }) });
13
+ });
14
+ export default ProgressBar;
@@ -19,14 +19,13 @@ const Select = forwardRef((props, ref) => {
19
19
  setChoosing(false);
20
20
  });
21
21
  }, []);
22
- return _jsxs(With, { className: `zuz-select-wrap rel`, children: [_jsxs(With, { popovertarget: _id, tag: `button`, as: as, className: `zuz-select rel flex aic`, ref: _ref, onClick: (e) => setChoosing(true), ...rest, children: [_jsx(With, { tag: `h2`, className: `zuz-selected`, children: value ? `string` == typeof value ? value : value.label : label || `Choose` }), chevronExpand()] }), _jsx(With, { popover: "true", id: _id, className: `zuz-select-options abs flex cols`, style: {
22
+ return _jsxs(With, { className: `zuz-select-wrap rel`, children: [_jsxs(With, { "data-value": value ? `string` == typeof value ? value : value.value : value || `-1`, name: name, tag: `button`, as: as, className: `zuz-select rel flex aic --select`, ref: _ref, onClick: (e) => setChoosing(true), ...rest, children: [_jsx(With, { tag: `h2`, className: `zuz-selected`, children: value ? `string` == typeof value ? value : value.label : label || `Choose` }), chevronExpand()] }), _jsx(With, { id: _id, className: `zuz-select-options abs flex cols`, style: {
23
23
  pointerEvents: choosing ? `auto` : `none`,
24
24
  }, animate: {
25
- from: { height: 0, opacity: 0 },
26
- to: { height: `auto`, opacity: 1 },
25
+ from: { y: 5, opacity: 0 },
26
+ to: { y: 0, opacity: 1 },
27
27
  when: choosing,
28
- curve: `spring`,
29
- duration: .4
28
+ duration: .05
30
29
  }, children: options.map((o) => _jsx(With, { onClick: (e) => updateValue(o), className: value && (`string` == typeof o ? o : o.value) == (`string` == typeof value ? value : value.value) ? `selected` : ``, tag: `button`, children: `string` == typeof o ? o : o.label }, `option-${(`string` == typeof o ? o : o.label).replace(/\s+/g, `-`)}-${`string` == typeof o ? o : o.value}`)) })] });
31
30
  });
32
31
  export default Select;
@@ -1,5 +1,5 @@
1
1
  import { ReactNode } from "react";
2
- import { SHEET, TRANSITION_CURVES, TRANSITIONS } from "../types/enums";
2
+ import { SHEET, SHEET_ACTION_POSITION, TRANSITION_CURVES, TRANSITIONS } from "../types/enums";
3
3
  import { BaseProps } from "../types/interfaces";
4
4
  export interface SheetProps {
5
5
  title?: string;
@@ -8,10 +8,13 @@ export interface SheetProps {
8
8
  curve?: TRANSITION_CURVES;
9
9
  speed?: Number;
10
10
  type?: SHEET;
11
+ actionPosition?: SHEET_ACTION_POSITION;
11
12
  }
12
13
  export interface SheetActionHandler {
14
+ key?: string;
13
15
  label: string;
14
- handler: () => void;
16
+ handler?: () => void;
17
+ onClick?: () => void;
15
18
  }
16
19
  export interface SheetHandler {
17
20
  showDialog: (title: string | ReactNode, message: string | ReactNode, action?: SheetActionHandler[], onShow?: () => void) => void;
@@ -2,22 +2,24 @@
2
2
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
3
  import { forwardRef, useEffect, useImperativeHandle, useMemo, useRef, useState } from "react";
4
4
  import With from "./base";
5
- import { SHEET, TRANSITION_CURVES, TRANSITIONS } from "../types/enums";
5
+ import { SHEET, SHEET_ACTION_POSITION, TRANSITION_CURVES, TRANSITIONS } from "../types/enums";
6
6
  import Cover from "./cover";
7
7
  import { animationTransition } from "../funs/css";
8
- import useComponentEditor from "../hooks/useCompEditor";
9
8
  import ComponentEditor from "./editor";
9
+ import { uuid } from "../funs";
10
10
  let _sheetTimeout = null;
11
11
  let _sheetWobbleTimeout = null;
12
12
  const Sheet = forwardRef((props, ref) => {
13
- const { as, transition, curve, speed, editor, type, ...rest } = props;
14
- const _editor = useComponentEditor();
13
+ const { as, transition, curve, speed, editor, type, actionPosition, ...rest } = props;
14
+ const sheetID = useMemo(() => uuid(), []);
15
15
  const [visible, setVisible] = useState(false);
16
16
  const [title, setTitle] = useState(``);
17
17
  const [msg, setMsg] = useState(``);
18
18
  const [action, setAction] = useState(null);
19
19
  const [_errorType, setErrorType] = useState(type || SHEET.Default);
20
20
  const [loading, setLoading] = useState(false);
21
+ const [render, setRender] = useState(true);
22
+ const _render = useRef(null);
21
23
  const divRef = useRef(null);
22
24
  const lastTransform = useRef(null);
23
25
  useImperativeHandle(ref, () => ({
@@ -41,7 +43,13 @@ const Sheet = forwardRef((props, ref) => {
41
43
  setMsg(message);
42
44
  setTitle(title);
43
45
  if (action)
44
- setAction(action);
46
+ setAction(action.reduce((ar, b) => {
47
+ ar.push({
48
+ ...b,
49
+ key: b.key || uuid()
50
+ });
51
+ return ar;
52
+ }, []));
45
53
  setVisible(true);
46
54
  setTimeout(() => onShow ? onShow() : () => { }, 1000);
47
55
  },
@@ -167,17 +175,25 @@ const Sheet = forwardRef((props, ref) => {
167
175
  }
168
176
  }), []);
169
177
  useEffect(() => {
170
- }, []);
178
+ if (_render.current)
179
+ clearTimeout(_render.current);
180
+ if (!visible) {
181
+ _render.current = setTimeout(() => setRender(false), 1000);
182
+ }
183
+ else {
184
+ setRender(true);
185
+ }
186
+ }, [visible]);
171
187
  if (_errorType == SHEET.Dialog) {
172
188
  return _jsxs(_Fragment, { children: [_jsx(With, { "aria-hidden": !visible, className: `zuz-overlay fixed fill`, animate: {
173
189
  transition: TRANSITIONS.FadeIn,
174
190
  when: visible,
175
191
  duration: 0.1,
176
- } }), _jsxs(With, { animate: buildAnimation(), as: as, className: `zuz-sheet toast-${_errorType.toLowerCase()} fixed`.trim(), ...rest, ref: divRef, children: [_jsx(Cover, { ...({ when: loading }) }), _jsxs(With, { className: `sheet-head flex aic rel`, children: [_jsx(With, { className: `sheet-${title ? `title` : `dot`}`, children: title || `` }), _jsx(With, { tag: `button`, onClick: (e) => setVisible(false), className: `sheet-closer abs`, children: "\u00D7" })] }), _jsx(With, { className: `sheet-body flex aic rel`, children: msg }), action && _jsx(With, { className: `sheet-footer flex aic rel`, children: action.map((a, i) => _jsx(With, { onClick: a.handler, tag: `button`, as: `sheet-action-btn`, children: a.label })) })] }), props.editor && visible && _jsx(ComponentEditor, { element: `.zuz-sheet`, title: `Sheet`, attrs: {
192
+ } }), _jsxs(With, { animate: buildAnimation(), as: as, className: `zuz-sheet toast-${_errorType.toLowerCase()} fixed`.trim(), ...rest, ref: divRef, children: [_jsx(Cover, { ...({ when: loading }) }), _jsxs(With, { className: `sheet-head flex aic rel`, children: [_jsx(With, { className: `sheet-${title ? `title` : `dot`}`, children: title || `` }), _jsx(With, { tag: `button`, onClick: (e) => setVisible(false), className: `sheet-closer abs`, children: "\u00D7" })] }), _jsx(With, { className: `sheet-body flex aic rel ${action ? `` : `--no-action`}`.trim(), children: render ? msg : null }), action && _jsx(With, { className: `sheet-footer flex aic rel ${actionPosition ? actionPosition == SHEET_ACTION_POSITION.Center ? `jcc` : `` : `jce`}`, children: action.map((a, i) => _jsx(With, { onClick: (e) => a.handler ? a.handler() : a.onClick ? a.onClick() : console.log(`onClick Handler missing`), tag: `button`, as: `sheet-action-btn`, children: a.label }, `sheet-${sheetID}-action-${a.key}`)) })] }), props.editor && visible && _jsx(ComponentEditor, { element: `.zuz-sheet`, title: `Sheet`, attrs: {
177
193
  ...sheetProps,
178
194
  ...(_errorType == SHEET.Dialog ? dialogProps : toastProps)
179
195
  } })] });
180
196
  }
181
- return _jsx(With, { animate: buildAnimation(), as: as, className: `zuz-sheet toast-${_errorType.toLowerCase()} fixed`.trim(), ...rest, ref: divRef, children: visible ? msg : null });
197
+ return _jsx(With, { animate: buildAnimation(), as: as, className: `zuz-sheet toast-${_errorType.toLowerCase()} abs`.trim(), ...rest, ref: divRef, children: visible ? msg : null });
182
198
  });
183
199
  export default Sheet;
@@ -1,14 +1,18 @@
1
1
  import { ReactNode } from "react";
2
2
  import { BaseProps } from "../types/interfaces";
3
3
  export interface Tab {
4
- onSelect: (index: number) => void;
4
+ onSelect: (tab: Tab, index: number) => void;
5
+ tag?: string;
6
+ key?: string;
5
7
  label: string | ReactNode | ReactNode[];
6
8
  body: string | ReactNode | ReactNode[];
7
9
  render?: boolean;
8
10
  }
9
11
  export interface TabViewProps {
12
+ onChange?: (tab: Tab, index: number) => void;
10
13
  speed?: number;
11
14
  tabs: Tab[];
15
+ prerender?: boolean;
12
16
  }
13
17
  export interface TabViewHandler {
14
18
  setTab: (index: number) => void;
@@ -5,27 +5,37 @@ import { uuid } from "../funs";
5
5
  import { useResizeObserver } from "../hooks";
6
6
  import ComponentEditor from "./editor";
7
7
  const TabView = forwardRef((props, ref) => {
8
- const { as, tabs, speed, ...rest } = props;
8
+ const { as, tabs: _tabs, speed, prerender, onChange, ...rest } = props;
9
+ const tabs = useMemo(() => _tabs.reduce((ts, t) => {
10
+ ts.push({
11
+ ...t,
12
+ key: t.key || uuid()
13
+ });
14
+ return ts;
15
+ }, []), [_tabs]);
9
16
  const tabview = useRef(null);
10
17
  const tabViewID = useMemo(() => uuid(), []);
11
18
  const [activeTab, setActiveTab] = useState(0);
12
19
  const size = useResizeObserver(tabview);
20
+ const render = useMemo(() => prerender == undefined || prerender == true ? true : false, []);
13
21
  const handleTabClick = (index) => {
14
22
  setActiveTab(index);
15
23
  };
16
24
  useEffect(() => {
25
+ onChange && onChange(tabs[0], 0);
17
26
  }, []);
18
27
  return _jsxs(_Fragment, { children: [_jsxs(With, { ref: tabview, className: `tabview flex cols`, ...rest, children: [_jsx(With, { className: `tab-head flex aic`, children: tabs.map((tab, index) => _jsx(With, { tag: `button`, className: `tab-label rel ${index === activeTab ? 'active' : ''}`.trim(), onClick: () => {
19
28
  handleTabClick(index);
20
- tab.onSelect && tab.onSelect(index);
21
- }, children: tab.label }, `tab-label-${tabViewID}-${index}`)) }), _jsx(With, { className: `tab-content rel`, children: _jsx(With, { className: `tabs-track flex aic`, style: { transition: `all ${speed || 0.3}s ease-in-out 0s`, transform: `translate(-${activeTab * size.width}px, 0)` }, children: tabs.map((tab, index) => {
29
+ tab.onSelect && tab.onSelect(tab, index);
30
+ onChange && onChange(tab, index);
31
+ }, children: tab.label }, `tab-${tabViewID}-${tab.key}`)) }), _jsx(With, { className: `tab-content rel`, children: _jsx(With, { className: `tabs-track flex aic`, style: { transition: `all ${speed || 0.3}s ease-in-out 0s`, transform: `translate(-${activeTab * size.width}px, 0)` }, children: tabs.map((tab, index) => {
22
32
  return _jsx(With, { className: `tab-body rel`, style: {
23
33
  width: size.width,
24
34
  minWidth: size.width,
25
35
  maxWidth: size.width,
26
36
  opacity: index === activeTab ? 1 : 0,
27
37
  transition: 'opacity 0.5s ease',
28
- }, children: tab.body }, `tab-body-${tabViewID}-${index}`);
38
+ }, children: (render || activeTab == index) && tab.body }, `tab-body-${tabViewID}-${tab.key}`);
29
39
  }) }) })] }), props.editor && _jsx(ComponentEditor, { element: `.tabview`, title: `TabView`, attrs: {
30
40
  "@group-Head": {
31
41
  label: "Head",
@@ -0,0 +1,28 @@
1
+ import { ReactNode } from "react";
2
+ import { BaseProps } from "../../types/interfaces";
3
+ export interface TreeNodeIcons {
4
+ dirOpen: ReactNode;
5
+ dirClose: ReactNode;
6
+ arrowOpen: ReactNode;
7
+ arrowClose: ReactNode;
8
+ }
9
+ export interface TreeViewProps {
10
+ tag?: string;
11
+ roots: string[];
12
+ nodes: TreeNode[];
13
+ onSelect: (tag: string) => void;
14
+ icons?: TreeNodeIcons;
15
+ selected?: string;
16
+ }
17
+ export interface TreeViewHandler {
18
+ getSelected?: () => String;
19
+ }
20
+ export interface TreeNode {
21
+ tag: string;
22
+ label: string;
23
+ under?: string;
24
+ selected?: string;
25
+ expanded?: boolean;
26
+ }
27
+ declare const TreeView: import("react").ForwardRefExoticComponent<TreeViewProps & BaseProps & import("react").RefAttributes<TreeViewHandler>>;
28
+ export default TreeView;
@@ -0,0 +1,24 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { forwardRef, useEffect, useImperativeHandle, useState } from "react";
3
+ import With from "../base";
4
+ import TreeItem from "./item";
5
+ const TreeView = forwardRef((props, ref) => {
6
+ const { as, nodes, onSelect, tag: treeViewTag, icons, roots, selected: _selected, ...rest } = props;
7
+ const [selected, setSelected] = useState(_selected);
8
+ useImperativeHandle(ref, () => ({
9
+ getSelected: () => selected
10
+ }), [onSelect]);
11
+ const handleSelect = (tag) => {
12
+ setSelected(tag);
13
+ onSelect && onSelect(tag);
14
+ };
15
+ useEffect(() => {
16
+ if (selected != _selected) {
17
+ setSelected(_selected);
18
+ }
19
+ }, [_selected]);
20
+ return _jsx(With, { className: `treeview flex cols`, children: nodes
21
+ .filter(node => roots.includes(node.tag))
22
+ .map(node => _jsx(TreeItem, { treeTag: treeViewTag ? `-${treeViewTag}` : ``, selected: selected, onSelect: handleSelect, icons: icons, meta: node, nodes: nodes }, `tree-node-${node.tag}`)) });
23
+ });
24
+ export default TreeView;
@@ -0,0 +1,15 @@
1
+ import { TreeNode, TreeNodeIcons } from ".";
2
+ import { BaseProps } from "../../types/interfaces";
3
+ export interface TreeItemProps {
4
+ treeTag: string;
5
+ meta: TreeNode;
6
+ nodes: TreeNode[];
7
+ onSelect: (tag: string) => void;
8
+ selected?: String;
9
+ icons?: TreeNodeIcons;
10
+ }
11
+ export interface TreeItemHandler {
12
+ onSelect?: (v: TreeNode) => void;
13
+ }
14
+ declare const TreeItem: import("react").ForwardRefExoticComponent<TreeItemProps & BaseProps & import("react").RefAttributes<TreeItemHandler>>;
15
+ export default TreeItem;
@@ -0,0 +1,23 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { forwardRef, useEffect, useState } from "react";
3
+ import With from "../base";
4
+ const TreeItem = forwardRef((props, ref) => {
5
+ const { as, meta, nodes, icons, onSelect, treeTag, selected, ...rest } = props;
6
+ const { tag, label, under } = meta;
7
+ const [isOpen, setIsOpen] = useState(tag == `root`);
8
+ const toggle = () => {
9
+ localStorage.setItem(`--tn${treeTag}-${tag}`, isOpen ? `0` : `1`);
10
+ setIsOpen(!isOpen);
11
+ };
12
+ useEffect(() => {
13
+ if (tag == `root` && !localStorage.getItem(`--tn${treeTag}-${tag}`)) {
14
+ localStorage.setItem(`--tn${treeTag}-${tag}`, `1`);
15
+ setIsOpen(true);
16
+ }
17
+ else
18
+ setIsOpen(localStorage.getItem(`--tn${treeTag}-${tag}`) == `1`);
19
+ }, []);
20
+ const _nodes = nodes.filter(x => x.under == tag);
21
+ return _jsxs(With, { as: `tree-node tree-node-${tag} flex cols`, children: [_jsxs(With, { as: `--node --node-${tag} flex aic${selected == tag ? ` --selected` : ``}`, children: [_jsx(With, { tag: `button`, onClick: toggle, className: `--node-aro-btn`, children: _jsx(With, { className: `--node-aro-icon icon-${isOpen ? icons?.arrowOpen : icons?.arrowClose}` }) }), _jsxs(With, { tag: `button`, className: `--node-meta flex aic`, onClick: (e) => onSelect(tag), children: [_jsx(With, { className: `--node-icon icon-${isOpen ? icons?.dirOpen : icons?.dirClose}` }), _jsx(With, { tag: `h1`, className: `--node-label`, children: label })] })] }), isOpen && _nodes.length > 0 && _jsx(With, { className: `--sub-node tree-sub-node-${tag} flex cols`, children: _nodes.map(node => _jsx(TreeItem, { treeTag: treeTag, selected: selected, onSelect: onSelect, icons: icons, meta: node, nodes: nodes }, `tree-node-${node.tag}`)) })] });
22
+ });
23
+ export default TreeItem;