@zuzjs/ui 0.7.1 → 0.7.3

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 (45) hide show
  1. package/dist/bin.js +5 -1
  2. package/dist/comps/Accordion/index.d.ts +1 -1
  3. package/dist/comps/Accordion/types.d.ts +1 -1
  4. package/dist/comps/Avatar/index.d.ts +2 -2
  5. package/dist/comps/Avatar/types.d.ts +2 -2
  6. package/dist/comps/Button/index.d.ts +1 -1
  7. package/dist/comps/Button/index.js +2 -4
  8. package/dist/comps/Button/types.d.ts +3 -3
  9. package/dist/comps/CheckBox/index.d.ts +2 -1
  10. package/dist/comps/CheckBox/index.js +3 -21
  11. package/dist/comps/CheckBox/types.d.ts +2 -1
  12. package/dist/comps/ContextMenu/index.js +0 -56
  13. package/dist/comps/Drawer/index.d.ts +1 -1
  14. package/dist/comps/Drawer/types.d.ts +1 -1
  15. package/dist/comps/Form/index.d.ts +5 -2
  16. package/dist/comps/Form/index.js +24 -6
  17. package/dist/comps/Pagination/index.d.ts +1 -1
  18. package/dist/comps/Pagination/index.js +5 -3
  19. package/dist/comps/Pagination/types.d.ts +1 -1
  20. package/dist/comps/Select/index.js +2 -1
  21. package/dist/comps/Sheet/index.d.ts +7 -1
  22. package/dist/comps/Sheet/index.js +23 -11
  23. package/dist/comps/Switch/index.d.ts +1 -0
  24. package/dist/comps/Table/col.js +0 -8
  25. package/dist/comps/Table/index.d.ts +4 -0
  26. package/dist/comps/Table/index.js +3 -2
  27. package/dist/comps/Table/row.js +6 -3
  28. package/dist/comps/Table/types.d.ts +9 -2
  29. package/dist/comps/TextArea/index.d.ts +3 -0
  30. package/dist/comps/TextArea/index.js +3 -2
  31. package/dist/comps/Treeview/index.js +1 -1
  32. package/dist/comps/Treeview/item.js +1 -1
  33. package/dist/funs/css.d.ts +10 -7
  34. package/dist/funs/css.js +51 -14
  35. package/dist/funs/stylesheet.js +1 -0
  36. package/dist/hooks/useBase.js +1 -1
  37. package/dist/hooks/useColorScheme.d.ts +3 -1
  38. package/dist/hooks/useColorScheme.js +7 -7
  39. package/dist/hooks/useDB.js +2 -2
  40. package/dist/styles.css +1 -1
  41. package/dist/types/enums.d.ts +7 -1
  42. package/dist/types/enums.js +7 -0
  43. package/dist/types/index.d.ts +3 -0
  44. package/dist/types/interfaces.d.ts +6 -0
  45. package/package.json +1 -1
package/dist/bin.js CHANGED
@@ -16,7 +16,8 @@ program
16
16
  .option(`-h, --cache`)
17
17
  .option(`-e, --cleaned`)
18
18
  .option(`-t, --sheet`)
19
- .option(`-m, --media`);
19
+ .option(`-m, --media`)
20
+ .option(`-s, --dark`);
20
21
  program.parse();
21
22
  const options = program.opts();
22
23
  // extendGlobals()
@@ -112,6 +113,7 @@ const rebuildAll = () => {
112
113
  }
113
114
  else {
114
115
  const mediaQueries = {};
116
+ let darkQueries = {};
115
117
  files.map(f => {
116
118
  // if ( f.endsWith(`header.jsx`) ){
117
119
  const r = rebuild(f);
@@ -122,6 +124,7 @@ const rebuildAll = () => {
122
124
  // : cssBuilder.Build([r], true).sheet)
123
125
  const _built = cssBuilder.Build([r], true, f.replace(path.resolve(`./`), ``));
124
126
  as.push(_built.sheet);
127
+ darkQueries = { ...darkQueries, ..._built.darkQueries };
125
128
  Object.keys(_built.mediaQuery).map(mq => {
126
129
  if (!mediaQueries[mq])
127
130
  mediaQueries[mq] = [];
@@ -136,6 +139,7 @@ const rebuildAll = () => {
136
139
  // as.push(r)
137
140
  });
138
141
  as.push(cssBuilder.buildMediaQueries(mediaQueries));
142
+ as.push(cssBuilder.buildDarkModeQueries(darkQueries));
139
143
  }
140
144
  // console.log(as)
141
145
  // const { sheet } = new CSS().Build(as, true)
@@ -1,6 +1,6 @@
1
1
  import { AccordionHandler } from "./types";
2
2
  declare const Accordion: import("react").ForwardRefExoticComponent<import("../Box").BoxProps & {
3
- message?: string;
3
+ message?: string | import("react").ReactNode;
4
4
  title: string | import("react").ReactNode | import("react").ReactNode[];
5
5
  } & import("react").RefAttributes<AccordionHandler>>;
6
6
  export default Accordion;
@@ -1,7 +1,7 @@
1
1
  import { ReactNode } from "react";
2
2
  import { BoxProps } from "../Box";
3
3
  export type AccordionProps = BoxProps & {
4
- message?: string;
4
+ message?: string | ReactNode;
5
5
  title: string | ReactNode | ReactNode[];
6
6
  };
7
7
  export interface AccordionHandler {
@@ -1,9 +1,9 @@
1
- import { AVATAR, Size } from "../../types/enums";
1
+ import { AVATAR } from "../../types/enums";
2
2
  import { AvatarHandler } from "./types";
3
3
  declare const Avatar: import("react").ForwardRefExoticComponent<import("../../types").ZuzProps & Omit<Omit<import("react").DetailedHTMLProps<import("react").ImgHTMLAttributes<HTMLImageElement>, HTMLImageElement>, "ref">, keyof import("../../types").ZuzProps> & {
4
4
  type?: AVATAR;
5
5
  size?: number;
6
- variant?: Size;
6
+ variant?: import("../../types/enums").Variant;
7
7
  src?: string;
8
8
  color?: string;
9
9
  crossOrigin?: "anonymous" | "use-credentials";
@@ -1,9 +1,9 @@
1
1
  import { Props } from "../../types";
2
- import { AVATAR, Size } from "../../types/enums";
2
+ import { AVATAR, Variant } from "../../types/enums";
3
3
  export type AvatarProps = Props<"img"> & {
4
4
  type?: AVATAR;
5
5
  size?: number;
6
- variant?: Size;
6
+ variant?: Variant;
7
7
  src?: string;
8
8
  color?: string;
9
9
  crossOrigin?: 'anonymous' | 'use-credentials';
@@ -1,6 +1,6 @@
1
1
  import { ButtonState } from './types';
2
2
  import { Size } from '../../types/enums';
3
- declare const Button: import("react").ForwardRefExoticComponent<import("../../types").ZuzProps & Omit<Omit<import("react").DetailedHTMLProps<import("react").ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "ref">, keyof import("../../types").ZuzProps> & {
3
+ declare const Button: import("react").ForwardRefExoticComponent<import("../..").ZuzProps & Omit<Omit<import("react").DetailedHTMLProps<import("react").ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "ref">, keyof import("../..").ZuzProps> & {
4
4
  icon?: string;
5
5
  iconSize?: Size;
6
6
  withLabel?: boolean;
@@ -8,11 +8,9 @@ import { ButtonState } from './types';
8
8
  import Spinner from '../Spinner';
9
9
  import { Size } from '../../types/enums';
10
10
  const Button = forwardRef((props, ref) => {
11
- const { reset, size, variant, icon, iconSize, children, withLabel, spinner, state, ...pops } = props;
11
+ const { reset, size, variant, icon, iconSize, children, withLabel, spinner, state, disabled, ...pops } = props;
12
12
  const { style, className, rest } = useBase(pops);
13
- return _jsxs("button", {
14
- // className={`${reset ? `flex` : `--button ${size ? `--${size}` : ``} flex aic jcc`.trim()} ${icon ? `ico-btn` : ``} ${className}`.trim()}
15
- className: `--button ${variant ? `--${variant}` : ``} ${size ? `--${size}` : ``} flex aic ${!reset ? `jcc` : ``} ${icon ? `ico-btn` : ``} ${className}`.trim(), style: style, ref: ref, ...rest, children: [state == ButtonState.Loading && _jsx(Spinner, { size: Size.Small, color: `#ffffff`,
13
+ return _jsxs("button", { className: `--button ${variant ? `--${variant}` : ``} ${size ? `--${size}` : ``} flex aic ${!reset ? `jcc` : ``} ${icon ? `ico-btn` : ``} ${className}`.trim(), style: style, ref: ref, disabled: state == ButtonState.Loading || props.skeleton?.enabled || disabled, ...rest, children: [state == ButtonState.Loading && _jsx(Spinner, { size: Size.Small, color: `#ffffff`,
16
14
  ...(spinner || {}) }), (!state || state == ButtonState.Normal) && _jsxs(_Fragment, { children: [icon && _jsx(Icon, { size: iconSize, name: icon }), withLabel === true ? _jsx(Span, { children: children }) : children] })] });
17
15
  });
18
16
  export default Button;
@@ -1,15 +1,15 @@
1
1
  import { Props } from "../../types";
2
2
  import { Size, Variant } from "../../types/enums";
3
3
  import { SpinnerProps } from "../Spinner";
4
- /**
5
- * @deprecated Use `variant` instead.
6
- */
7
4
  export type ButtonProps = Props<`button`> & {
8
5
  icon?: string;
9
6
  iconSize?: Size;
10
7
  withLabel?: boolean;
11
8
  spinner?: SpinnerProps;
12
9
  state?: ButtonState;
10
+ /**
11
+ * @deprecated "Use `variant` instead. `size` will be removed in the next major release."
12
+ */
13
13
  size?: Size;
14
14
  variant?: Size | Variant;
15
15
  reset?: boolean;
@@ -1,8 +1,9 @@
1
- import { CHECKBOX, Size } from "../../types/enums";
1
+ import { CHECKBOX, Size, Variant } from "../../types/enums";
2
2
  import { CheckboxHandler } from "./types";
3
3
  declare const CheckBox: import("react").ForwardRefExoticComponent<import("../..").ZuzProps & Omit<Omit<import("react").DetailedHTMLProps<import("react").InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>, "ref">, keyof import("../..").ZuzProps> & {
4
4
  type?: CHECKBOX;
5
5
  size?: Size;
6
+ variant?: Variant;
6
7
  onSwitch?: (checked: boolean, value: string | number | readonly string[]) => void;
7
8
  } & import("react").RefAttributes<CheckboxHandler>>;
8
9
  export default CheckBox;
@@ -1,12 +1,12 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { forwardRef, useImperativeHandle, useRef, useState } from "react";
4
- import { CHECKBOX, Size } from "../../types/enums";
4
+ import { CHECKBOX, Variant } from "../../types/enums";
5
5
  import Label from "../Label";
6
6
  import Input from "../Input";
7
7
  import SVGIcons from "../svgicons";
8
8
  const CheckBox = forwardRef((props, ref) => {
9
- const { name, required, type, value, size, checked: defaultCheck, onSwitch, ...pops } = props;
9
+ const { name, required, type, value, size, variant, checked: defaultCheck, onSwitch, ...pops } = props;
10
10
  const [checked, _setChecked] = useState(defaultCheck || false);
11
11
  const bRef = useRef(null);
12
12
  useImperativeHandle(ref, () => ({
@@ -26,27 +26,9 @@ const CheckBox = forwardRef((props, ref) => {
26
26
  _setChecked(!checked);
27
27
  }
28
28
  }));
29
- return _jsxs(Label, { className: `--${(type || CHECKBOX.Default).toLowerCase()} ${!type || type == CHECKBOX.Default ? `--checkbox` : `--switch`} --${size || Size.Default} flex aic jcc ${checked ? `is-checked` : ``} rel`.trim(), ...pops, children: [(!type || type == CHECKBOX.Default) && SVGIcons.check, _jsx(Input, { ...{}, ref: bRef, defaultChecked: checked, value: value || `cb`, type: `checkbox`, className: `abs`, name: name, required: required || false, onChange: (e) => {
29
+ return _jsxs(Label, { className: `--${(type || CHECKBOX.Default).toLowerCase()} ${!type || type == CHECKBOX.Default ? `--checkbox` : `--switch`} --${(variant || size) || Variant.Default} flex aic jcc ${checked ? `is-checked` : ``} rel`.trim(), ...pops, children: [(!type || type == CHECKBOX.Default) && SVGIcons.check, _jsx(Input, { ...{}, ref: bRef, defaultChecked: checked, value: value || `cb`, type: `checkbox`, className: `abs`, name: name, required: required || false, onChange: (e) => {
30
30
  onSwitch && onSwitch(e.target.checked, value || `cb`);
31
31
  _setChecked(e.target.checked);
32
32
  } })] });
33
33
  });
34
- // import { DetailedHTMLProps, HTMLAttributes, ReactNode, Ref, useState } from "react";
35
- // import { cleanProps, css } from "../funs";
36
- // import { UIProps } from "../types/interfaces";
37
- // const CheckBox = ( props : UIProps<HTMLInputElement> ) => {
38
- // const { cx } = css.Build(props.as)
39
- // const [ checked, setChecked ] = useState(props.checked || false)
40
- // return <label { ...({
41
- // className: `zuz-checkbox${checked ? ` is-checked` : ``} rel${cx.length > 0 ? ` ` + cx.join(` `) : ``}`
42
- // }) as UIProps<HTMLLabelElement>}>
43
- // <input type='checkbox'
44
- // ref={props.ref}
45
- // onChange={e => {
46
- // setChecked(e.target.checked)
47
- // }}
48
- // className={`abs`}
49
- // {...(cleanProps(props) as UIProps<HTMLInputElement>)} />
50
- // </label>
51
- // }
52
34
  export default CheckBox;
@@ -1,5 +1,5 @@
1
1
  import { Props } from "../../types";
2
- import { CHECKBOX, Size } from "../../types/enums";
2
+ import { CHECKBOX, Size, Variant } from "../../types/enums";
3
3
  /**
4
4
  * Props for the CheckBox component.
5
5
  *
@@ -11,6 +11,7 @@ import { CHECKBOX, Size } from "../../types/enums";
11
11
  export type CheckBoxProps = Props<"input"> & {
12
12
  type?: CHECKBOX;
13
13
  size?: Size;
14
+ variant?: Variant;
14
15
  onSwitch?: (checked: boolean, value: string | number | readonly string[]) => void;
15
16
  };
16
17
  /**
@@ -19,19 +19,6 @@ const ContextMenu = forwardRef((props, ref) => {
19
19
  show: (e, menuItems) => {
20
20
  if (!parent)
21
21
  event.current = e;
22
- // let x = 0, y = 0;
23
- // if ( parent ){
24
- // const { x: px, y: py, width, height } = _parent || parent.getBoundingClientRect()
25
- // // x = right + 5
26
- // // y = top + height + 5
27
- // }
28
- // else{
29
- // x = e instanceof MouseEvent ? e.clientX
30
- // : e instanceof TouchEvent && e.touches.length > 0 ? e.touches[0].clientX : (e as dynamicObject).clientX || 0;
31
- // y = e instanceof MouseEvent ? e.clientY
32
- // : e instanceof TouchEvent && e.touches.length > 0 ? e.touches[0].clientY : (e as dynamicObject).clientY || 0;
33
- // }
34
- // setPosition({ x, y })
35
22
  if (menuItems) {
36
23
  setItems(menuItems);
37
24
  }
@@ -39,49 +26,6 @@ const ContextMenu = forwardRef((props, ref) => {
39
26
  },
40
27
  hide: (e) => setVisible(false),
41
28
  }));
42
- // useEffect(() => {
43
- // if ( !visible || !_menu.current ) return;
44
- // const menu = _menu.current;
45
- // const { offsetWidth: w, offsetHeight: h } = menu;
46
- // let { x, y } = position;
47
- // // Prevent overflow on the right
48
- // if (x + w > window.innerWidth) {
49
- // x = window.innerWidth - w - 10;
50
- // }
51
- // // Prevent overflow on the bottom
52
- // if (y + h > window.innerHeight) {
53
- // y = window.innerHeight - h - 10;
54
- // }
55
- // // Prevent going off the left side
56
- // if (x < 0) x = 10;
57
- // // Prevent going off the top side
58
- // if (y < 0) y = 10;
59
- // setPosition({ x, y })
60
- // }, [visible])
61
- // useEffect(() => {
62
- // if ( visible ){
63
- // let px, py = 0
64
- // if ( parent ){
65
- // const { x, y, width, height } = _parent || parent.getBoundingClientRect()
66
- // px = x
67
- // py = y
68
- // }
69
- // const { width: w, height: h } = _menu.current!.getBoundingClientRect()
70
- // // Prevent overflow on the right
71
- // if (px! + w > window.innerWidth) {
72
- // px = window.innerWidth - w - 10;
73
- // }
74
- // setPosition({ x: px!, y: py! })
75
- // }
76
- // }, [visible])
77
- // useEffect(() => {
78
- // if ( parent && !position ){
79
- // const { x, y, width, height } = parent.getBoundingClientRect()
80
- // setParent({ x, y, width, height })
81
- // setPosition({ x, y })
82
- // }
83
- // }, [parent])
84
- // if ( !visible ) return null
85
29
  return _jsx(Box, { className: `--contextmenu abs flex cols ${className}`.trim(), "aria-hidden": !visible, style: {
86
30
  ...style,
87
31
  top: position.top,
@@ -6,7 +6,7 @@ declare const Drawer: import("react").ForwardRefExoticComponent<BoxProps & {
6
6
  as?: string;
7
7
  speed?: number;
8
8
  from?: DRAWER_SIDE;
9
- children: string | ReactNode | ReactNode[];
9
+ children?: string | ReactNode | ReactNode[];
10
10
  prerender?: boolean;
11
11
  } & import("react").RefAttributes<DrawerHandler>>;
12
12
  export default Drawer;
@@ -5,7 +5,7 @@ export type DrawerProps = BoxProps & {
5
5
  as?: string;
6
6
  speed?: number;
7
7
  from?: DRAWER_SIDE;
8
- children: string | ReactNode | ReactNode[];
8
+ children?: string | ReactNode | ReactNode[];
9
9
  prerender?: boolean;
10
10
  };
11
11
  export interface DrawerHandler {
@@ -1,5 +1,6 @@
1
1
  import { BoxProps } from "../Box";
2
2
  import { dynamicObject } from "../../types";
3
+ import { SheetHandler } from "../Sheet";
3
4
  import { SPINNER } from "../../types/enums";
4
5
  export type FormProps = BoxProps & {
5
6
  /** Name of form, will be appended to --form-{name} in className
@@ -28,7 +29,8 @@ export type FormProps = BoxProps & {
28
29
  color?: string;
29
30
  /** Message displayed during loading */
30
31
  message?: string;
31
- };
32
+ } | SheetHandler;
33
+ resetOnSuccess?: boolean;
32
34
  };
33
35
  /**
34
36
  * Exposes control methods for the Form component, such as setting loading states or hiding errors.
@@ -77,6 +79,7 @@ declare const Form: import("react").ForwardRefExoticComponent<BoxProps & {
77
79
  color?: string;
78
80
  /** Message displayed during loading */
79
81
  message?: string;
80
- };
82
+ } | SheetHandler;
83
+ resetOnSuccess?: boolean;
81
84
  } & import("react").RefAttributes<FormHandler>>;
82
85
  export default Form;
@@ -3,7 +3,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { forwardRef, startTransition, useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState } from "react";
4
4
  import Box from "../Box";
5
5
  import { useBase } from "../../hooks";
6
- import Sheet from "../Sheet";
6
+ import Sheet, { isSheetHandler } from "../Sheet";
7
7
  import Cover from "../Cover";
8
8
  import { FORMVALIDATION, SHEET } from "../../types/enums";
9
9
  import { addPropsToChildren, isEmail, withPost } from "../../funs";
@@ -17,7 +17,7 @@ import { addPropsToChildren, isEmail, withPost } from "../../funs";
17
17
  * @param ref - Reference to the {@link FormHandler} interface, exposing methods to control loading and error states from the parent.
18
18
  */
19
19
  const Form = forwardRef((props, ref) => {
20
- const { name, cover, spinner, errors, action, children, withData, beforeSubmit, onSubmit, onError, onSuccess, ...pops } = props;
20
+ const { name, cover, spinner, errors, action, children, withData, beforeSubmit, onSubmit, onError, onSuccess, resetOnSuccess, ...pops } = props;
21
21
  const { className, style, rest } = useBase(pops);
22
22
  const [loading, setLoading] = useState(false);
23
23
  const innerRef = useRef(null);
@@ -181,14 +181,28 @@ const Form = forwardRef((props, ref) => {
181
181
  // If `action` is defined, submit the form data to the specified endpoint
182
182
  startTransition(async () => {
183
183
  beforeSubmit && beforeSubmit(payload);
184
- setLoading(true);
184
+ if (isSheetHandler(cover)) {
185
+ cover.setLoading(true);
186
+ }
187
+ else
188
+ setLoading(true);
185
189
  sheet.current.hide();
186
190
  // submit.current?.setState(ButtonState.Loading)
187
191
  withPost(action, { ...payload, ...(withData || {}) })
188
192
  .then(_resp => {
189
193
  const resp = _resp;
190
- setLoading(false);
191
194
  // submit.current?.reset()
195
+ if (isSheetHandler(cover)) {
196
+ cover.setLoading(false);
197
+ }
198
+ else
199
+ setLoading(false);
200
+ if (resetOnSuccess) {
201
+ Array.from(_nodes(`[name]`)).forEach((el) => {
202
+ if (el instanceof HTMLInputElement)
203
+ el.value = ``;
204
+ });
205
+ }
192
206
  if (onSuccess)
193
207
  onSuccess(resp);
194
208
  else {
@@ -198,7 +212,11 @@ const Form = forwardRef((props, ref) => {
198
212
  })
199
213
  .catch(err => {
200
214
  // console.warn(`Error occurred while submitting form`, err)
201
- setLoading(false);
215
+ if (isSheetHandler(cover)) {
216
+ cover.setLoading(false);
217
+ }
218
+ else
219
+ setLoading(false);
202
220
  // submit.current?.reset()
203
221
  if (onError)
204
222
  onError(err);
@@ -244,6 +262,6 @@ const Form = forwardRef((props, ref) => {
244
262
  }
245
263
  }));
246
264
  useEffect(_init, []);
247
- return _jsxs(Box, { ref: innerRef, style: style, className: `--form flex rel ${className} ${name ? `--form-${name.replace(/\s+/g, `-`)}` : ``}`, propsToRemove: [`withData`, `action`, `onSubmit`, `onSuccess`, `onError`], children: [_jsx(Sheet, { ref: sheet, as: `--sheet-form` }), _jsx(Cover, { message: cover ? cover.message || undefined : `working`, spinner: spinner, color: cover ? `color` in cover ? cover.color : `#ffffff` : `#ffffff`, when: loading }), buildChildren] });
265
+ return _jsxs(Box, { ref: innerRef, style: style, className: `--form flex rel ${className} ${name ? `--form-${name.replace(/\s+/g, `-`)}` : ``}`, propsToRemove: [`withData`, `action`, `onSubmit`, `onSuccess`, `onError`], children: [_jsx(Sheet, { ref: sheet, as: `--sheet-form` }), !isSheetHandler(cover) && _jsx(Cover, { message: cover ? cover.message || undefined : `working`, spinner: spinner, color: cover ? `color` in cover ? cover.color : `#ffffff` : `#ffffff`, when: loading }), buildChildren] });
248
266
  });
249
267
  export default Form;
@@ -8,7 +8,7 @@ declare const Pagination: import("react").ForwardRefExoticComponent<import("../B
8
8
  breakLabel?: string;
9
9
  nextLabel?: string;
10
10
  prevLabel?: string;
11
- renderEmpty?: boolean;
11
+ renderOnZeroPageCount?: boolean;
12
12
  onPageChange?: import("./types").PaginationCallback;
13
13
  } & import("react").RefAttributes<HTMLDivElement>>;
14
14
  export default Pagination;
@@ -6,7 +6,7 @@ import Box from "../Box";
6
6
  import Button from "../Button";
7
7
  import SVGIcons from "../svgicons";
8
8
  const Pagination = forwardRef((props, ref) => {
9
- const { itemCount, itemsPerPage, startPage, pageRange, paginationStyle, breakLabel, prevLabel, nextLabel, renderEmpty, onPageChange, ...pops } = props;
9
+ const { itemCount, itemsPerPage, startPage, pageRange, paginationStyle, breakLabel, prevLabel, nextLabel, renderOnZeroPageCount, onPageChange, ...pops } = props;
10
10
  const [_currentPage, setCurrentPage] = useState(startPage || 1);
11
11
  const _breakLabel = useMemo(() => breakLabel || `...`, [breakLabel]);
12
12
  /**
@@ -42,9 +42,11 @@ const Pagination = forwardRef((props, ref) => {
42
42
  setCurrentPage(newPage);
43
43
  onPageChange?.(newPage);
44
44
  }, [itemCount, itemsPerPage, _currentPage]);
45
- return _jsxs(Box, { as: `--pagination --pgt-${paginationStyle || PaginationStyle.Table} flex aic w:100% jcc ${className}`, children: [_jsx(Box, { as: `flex flex:1 aic --pgt-btns`, children: pages.map((page, index, items) => _jsx(Button, { disabled: page == _breakLabel, className: page == getPageValue(_currentPage) ? `--current-page` : ``, onClick: (ev) => typeof page == `number` && handlePage(page), children: page }, `--pg-${index}-${page}`)) }), _jsx(Box, { as: `flex aic jcc --pagination-label`, children: [
45
+ if (pages.length <= 1 && ((renderOnZeroPageCount == undefined ? false : renderOnZeroPageCount) === false))
46
+ return null;
47
+ return _jsxs(Box, { as: `--pagination --pgt-${paginationStyle || PaginationStyle.Table} flex aic w:100% jcc ${className}`, children: [_jsx(Box, { as: `flex flex:1 aic --pgt-btns`, children: (pages.length > 1 ? pages : [1, _breakLabel]).map((page, index, items) => _jsx(Button, { disabled: page == _breakLabel || getPageValue(_currentPage) == page, className: page == getPageValue(_currentPage) ? `--current-page` : ``, onClick: (ev) => typeof page == `number` && handlePage(page), children: page }, `--pg-${index}-${page}`)) }), _jsx(Box, { as: `flex aic jcc flex:1 --pagination-label`, children: [
46
48
  `Showing ${(getPageValue(_currentPage) - 1) * itemsPerPage + 1} - `,
47
49
  `${Math.min(getPageValue(_currentPage) * itemsPerPage, itemCount)} of ${itemCount} items`
48
- ].join(` `) }), _jsxs(Box, { as: `flex aic jce --pgt-btns --pgt-nav`, children: [_jsx(Button, { onClick: (ev) => handlePage(getPageValue(_currentPage) - 1), children: SVGIcons.chevronLeftOutline }), _jsx(Button, { onClick: (ev) => handlePage(getPageValue(_currentPage) - 1), children: SVGIcons.chevronRightOutline })] })] });
50
+ ].join(` `) }), _jsxs(Box, { as: `flex aic jce flex:1 --pgt-btns --pgt-nav`, children: [_jsx(Button, { disabled: getPageValue(_currentPage) <= 1, onClick: (ev) => handlePage(getPageValue(_currentPage) - 1), children: SVGIcons.chevronLeftOutline }), _jsx(Button, { disabled: pages.length <= 1 || getPageValue(_currentPage) == pages[pages.length - 1], onClick: (ev) => handlePage(getPageValue(_currentPage) - 1), children: SVGIcons.chevronRightOutline })] })] });
49
51
  });
50
52
  export default Pagination;
@@ -18,6 +18,6 @@ export type PaginationProps = BoxProps & {
18
18
  breakLabel?: string;
19
19
  nextLabel?: string;
20
20
  prevLabel?: string;
21
- renderEmpty?: boolean;
21
+ renderOnZeroPageCount?: boolean;
22
22
  onPageChange?: PaginationCallback;
23
23
  };
@@ -17,7 +17,8 @@ const Select = forwardRef((props, ref) => {
17
17
  const [query, setQuery] = useState(null);
18
18
  const _ref = useRef(null);
19
19
  const _search = useRef(null);
20
- const _id = useMemo(() => name || useId(), []);
20
+ const _did = useId();
21
+ const _id = useMemo(() => name || _did, []);
21
22
  const { className, style, rest } = useBase(pops);
22
23
  const updateValue = (o) => {
23
24
  setValue(o);
@@ -1,5 +1,5 @@
1
1
  import { ReactNode } from "react";
2
- import { SHEET, SHEET_ACTION_POSITION, TRANSITION_CURVES, TRANSITIONS } from "../../types/enums";
2
+ import { SHEET, SHEET_ACTION_POSITION, SPINNER, TRANSITION_CURVES, TRANSITIONS } from "../../types/enums";
3
3
  import { ZuzProps } from "../../types";
4
4
  export type SheetProps = ZuzProps & {
5
5
  title?: string;
@@ -8,6 +8,8 @@ export type SheetProps = ZuzProps & {
8
8
  curve?: TRANSITION_CURVES;
9
9
  speed?: Number;
10
10
  type?: SHEET;
11
+ spinner?: SPINNER;
12
+ loadingMessage?: string;
11
13
  actionPosition?: SHEET_ACTION_POSITION;
12
14
  };
13
15
  export interface SheetActionHandler {
@@ -17,6 +19,7 @@ export interface SheetActionHandler {
17
19
  onClick?: () => void;
18
20
  }
19
21
  export interface SheetHandler {
22
+ setLoading: (mode: boolean) => void;
20
23
  showDialog: (title: string | ReactNode, message: string | ReactNode, action?: SheetActionHandler[], onShow?: () => void) => void;
21
24
  dialog: (title: string | ReactNode, message: string | ReactNode, action?: SheetActionHandler[], onShow?: () => void) => void;
22
25
  show: (message: string | ReactNode, duration?: number, type?: SHEET) => void;
@@ -32,6 +35,9 @@ declare const Sheet: import("react").ForwardRefExoticComponent<ZuzProps & {
32
35
  curve?: TRANSITION_CURVES;
33
36
  speed?: Number;
34
37
  type?: SHEET;
38
+ spinner?: SPINNER;
39
+ loadingMessage?: string;
35
40
  actionPosition?: SHEET_ACTION_POSITION;
36
41
  } & import("react").RefAttributes<SheetHandler>>;
42
+ export declare const isSheetHandler: (src: unknown) => src is SheetHandler;
37
43
  export default Sheet;
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
- import { forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState } from "react";
3
+ import { forwardRef, useEffect, useImperativeHandle, useMemo, useRef, useState } from "react";
4
4
  import { SHEET, SHEET_ACTION_POSITION, TRANSITION_CURVES } from "../../types/enums";
5
5
  import Box from "../Box";
6
6
  import { useBase } from "../../hooks";
@@ -12,10 +12,10 @@ import Overlay from "../Overlay";
12
12
  let _sheetTimeout = null;
13
13
  let _sheetWobbleTimeout = null;
14
14
  const Sheet = forwardRef((props, ref) => {
15
- const { title: _title, message, transition, curve, speed, type, actionPosition, ...pops } = props;
15
+ const { title: _title, message, transition, curve, speed, type, actionPosition, spinner, loadingMessage, ...pops } = props;
16
16
  const { className, style, rest } = useBase(pops);
17
- const [title, setTitle] = useState(``);
18
- const [msg, setMsg] = useState(``);
17
+ const [title, setTitle] = useState(_title || ``);
18
+ const [msg, setMsg] = useState(message || ``);
19
19
  const [action, setAction] = useState(null);
20
20
  const [sheetType, setSheetType] = useState(type || SHEET.Default);
21
21
  const sheetID = useMemo(() => uuid(), []);
@@ -25,6 +25,7 @@ const Sheet = forwardRef((props, ref) => {
25
25
  const [loading, setLoading] = useState(false);
26
26
  const [render, setRender] = useState(true);
27
27
  const _render = useRef(null);
28
+ const renderMessage = msg; //useMemo(() => msg, [msg])
28
29
  useImperativeHandle(ref, () => ({
29
30
  setLoading(mode) {
30
31
  setLoading(mode);
@@ -43,8 +44,10 @@ const Sheet = forwardRef((props, ref) => {
43
44
  }, 500);
44
45
  }
45
46
  setSheetType(SHEET.Dialog);
46
- setMsg(message);
47
- setTitle(title);
47
+ if (message)
48
+ setMsg(message);
49
+ if (title)
50
+ setTitle(title);
48
51
  if (action)
49
52
  setAction(action.reduce((ar, b) => {
50
53
  ar.push({
@@ -56,7 +59,9 @@ const Sheet = forwardRef((props, ref) => {
56
59
  setVisible(true);
57
60
  setTimeout(() => onShow ? onShow() : () => { }, 1000);
58
61
  },
59
- dialog(title, message, action, onShow) {
62
+ dialog(title, message, action,
63
+ // actionRef?: React.RefObject<HTMLElement>,
64
+ onShow) {
60
65
  if (_sheetTimeout) {
61
66
  clearTimeout(_sheetTimeout);
62
67
  if (_sheetWobbleTimeout) {
@@ -125,7 +130,7 @@ const Sheet = forwardRef((props, ref) => {
125
130
  setVisible(false);
126
131
  }
127
132
  }));
128
- const buildAnimation = useCallback(() => {
133
+ const buildAnimation = useMemo(() => {
129
134
  const base = {
130
135
  when: visible,
131
136
  duration: speed || 0.3,
@@ -156,7 +161,7 @@ const Sheet = forwardRef((props, ref) => {
156
161
  ...base
157
162
  };
158
163
  }
159
- }, [visible]);
164
+ }, [visible, sheetType]);
160
165
  useEffect(() => {
161
166
  if (_render.current)
162
167
  clearTimeout(_render.current);
@@ -168,8 +173,15 @@ const Sheet = forwardRef((props, ref) => {
168
173
  }
169
174
  }, [visible]);
170
175
  if (sheetType == SHEET.Dialog) {
171
- return _jsxs(_Fragment, { children: [_jsx(Overlay, { when: visible }), _jsxs(Box, { className: `--sheet --sheet-${sheetType.toLowerCase()} ${className} fixed`.trim(), style: style, animate: buildAnimation(), ...rest, ref: innerRef, children: [_jsx(Cover, { when: loading }), _jsxs(Box, { className: `--head flex aic rel`, children: [_jsx(Box, { className: `--${title ? `title` : `dot`} flex aic rel`, children: title || `` }), _jsx(Button, { onClick: (e) => setVisible(false), className: `--closer abs`, children: "\u00D7" })] }), _jsx(Box, { className: `--body flex aic rel ${action ? `` : `--no-action`}`.trim(), children: render ? msg : null }), action && _jsx(Box, { className: `--footer flex aic rel ${actionPosition ? actionPosition == SHEET_ACTION_POSITION.Center ? `jcc` : `` : `jce`}`.trim(), children: action.map((a, i) => _jsx(Button, { onClick: (e) => a.handler ? a.handler() : a.onClick ? a.onClick() : console.log(`onClick Handler missing`), className: `--action`, children: a.label }, `sheet-${sheetID}-action-${a.key}`)) })] })] });
176
+ return _jsxs(_Fragment, { children: [_jsx(Overlay, { when: visible }), _jsxs(Box, { className: `--sheet --sheet-${sheetType.toLowerCase()} ${className} fixed`.trim(), style: style, animate: buildAnimation, ...rest, ref: innerRef, children: [_jsx(Cover, { when: loading, spinner: spinner, message: loadingMessage }), _jsxs(Box, { className: `--head flex aic rel`, children: [_jsx(Box, { className: `--${title ? `title` : `dot`} flex aic rel`, children: title || `` }), _jsx(Button, { onClick: (e) => setVisible(false), className: `--closer abs`, children: "\u00D7" })] }), _jsx(Box, { className: `--body flex aic rel ${action ? `` : `--no-action`}`.trim(), children: render ? renderMessage : null }), action && _jsx(Box, { className: `--footer flex aic rel ${actionPosition ? actionPosition == SHEET_ACTION_POSITION.Center ? `jcc` : `` : `jce`}`.trim(), children: action.map((a, i) => _jsx(Button, { onClick: (e) => a.handler ? a.handler() : a.onClick ? a.onClick() : console.log(`onClick Handler missing`), className: `--action`, children: a.label }, `sheet-${sheetID}-action-${a.key}`)) })] })] });
172
177
  }
173
- return _jsx(Box, { className: `--sheet --sheet-${sheetType.toLowerCase()} ${className} abs`.trim(), style: style, ...rest, animate: buildAnimation(), ref: innerRef, children: visible ? msg : null });
178
+ return _jsx(Box, { className: `--sheet --sheet-${sheetType.toLowerCase()} ${className} abs`.trim(), style: style, ...rest, animate: buildAnimation, ref: innerRef, children: visible ? msg : null });
174
179
  });
180
+ export const isSheetHandler = (src) => {
181
+ return typeof src === `object`
182
+ && null != src
183
+ && `setLoading` in src
184
+ && `success` in src
185
+ && `error` in src;
186
+ };
175
187
  export default Sheet;
@@ -3,6 +3,7 @@ import { CHECKBOX } from "../../types/enums";
3
3
  declare const Switch: import("react").ForwardRefExoticComponent<import("../..").ZuzProps & Omit<Omit<import("react").DetailedHTMLProps<import("react").InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>, "ref">, keyof import("../..").ZuzProps> & {
4
4
  type?: CHECKBOX;
5
5
  size?: import("../../types/enums").Size;
6
+ variant?: import("../../types/enums").Variant;
6
7
  onSwitch?: (checked: boolean, value: string | number | readonly string[]) => void;
7
8
  } & import("react").RefAttributes<CheckboxHandler>>;
8
9
  export default Switch;
@@ -2,14 +2,6 @@ import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import Box from "../Box";
3
3
  const TColumn = (props) => {
4
4
  const { idx, id, weight, style, value, render, resize, sort } = props;
5
- // const style = useMemo(() : CSSStyleDeclaration => style || {
6
- // ...(w && { width: w }),
7
- // ...(maxW && { maxWidth: maxW }),
8
- // ...(minW && { minWidth: minW }),
9
- // ...(h && { height: h }),
10
- // ...(maxH && { maxHeight: maxH }),
11
- // ...(minH && { minHeight: minH }),
12
- // }), [w, maxW, minW, h, minH, maxH, weight]);
13
5
  return _jsx(Box, { style: {
14
6
  flex: weight || 1,
15
7
  ...style
@@ -5,9 +5,13 @@ declare const Table: import("react").ForwardRefExoticComponent<import("../Box").
5
5
  rows?: dynamicObject[];
6
6
  rowCount?: number;
7
7
  rowsPerPage?: number;
8
+ rowClassName?: string;
8
9
  currentPage?: number;
9
10
  pagination?: boolean;
11
+ showPaginationOnZeroPageCount?: boolean;
10
12
  animateRows?: boolean;
13
+ header?: boolean;
14
+ onRowContextMenu?: (e: React.MouseEvent<HTMLDivElement, MouseEvent>, row: dynamicObject) => void;
11
15
  onPageChange?: import("../Pagination/types").PaginationCallback;
12
16
  } & import("react").RefAttributes<HTMLDivElement>>;
13
17
  export default Table;
@@ -6,7 +6,7 @@ import TRow from "./row";
6
6
  import Pagination from "../Pagination";
7
7
  import { PaginationStyle } from "../Pagination/types";
8
8
  const Table = forwardRef((props, ref) => {
9
- const { schema, rows, rowCount, rowsPerPage, currentPage, pagination, animateRows, onPageChange, ...pops } = props;
9
+ const { schema, rows, rowCount, rowsPerPage, currentPage, pagination, animateRows, header, showPaginationOnZeroPageCount, rowClassName, onPageChange, onRowContextMenu, ...pops } = props;
10
10
  const _schemaParsed = useMemo(() => schema.reduce((prev, c) => {
11
11
  prev[c.id] = {
12
12
  flex: c.weight || 1,
@@ -21,7 +21,8 @@ const Table = forwardRef((props, ref) => {
21
21
  return prev;
22
22
  }, {}), [schema]);
23
23
  const _cols = useMemo(() => Object.keys(_schemaParsed), [schema]);
24
+ const _header = useMemo(() => header == undefined ? true : header, [header]);
24
25
  const { style, className, rest } = useBase(pops);
25
- return _jsxs(Box, { as: `--table flex cols ${className}`, children: [_jsx(TRow, { index: -1, schema: schema, styles: _schemaParsed }), rows && rows.map((row, index) => _jsx(TRow, { index: index, schema: schema, ids: _cols, styles: _schemaParsed, animate: animateRows, data: row }, `--trow-${index}`)), pagination && _jsx(Box, { as: `--row flex aic --row-footer`, children: _jsx(Pagination, { onPageChange: onPageChange, paginationStyle: PaginationStyle.Table, itemCount: rowCount || (rows ? rows.length : 0), itemsPerPage: rowsPerPage || 10 }) })] });
26
+ return _jsxs(Box, { as: `--table flex cols ${className}`, children: [_header == true && _jsx(TRow, { index: -1, schema: schema, styles: _schemaParsed }), rows && rows.map((row, index) => _jsx(TRow, { index: index, schema: schema, ids: _cols, styles: _schemaParsed, animate: animateRows, data: row, rowClassName: rowClassName, onContextMenu: onRowContextMenu }, `--trow-${index}`)), pagination && _jsx(Box, { as: `--row flex aic --row-footer`, children: _jsx(Pagination, { renderOnZeroPageCount: showPaginationOnZeroPageCount, onPageChange: onPageChange, paginationStyle: PaginationStyle.Table, itemCount: rowCount || (rows ? rows.length : 0), itemsPerPage: rowsPerPage || 10 }) })] });
26
27
  });
27
28
  export default Table;