@zuzjs/ui 0.7.6 → 0.7.7

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 (54) hide show
  1. package/dist/cjs/comps/AutoComplete/index.js +3 -3
  2. package/dist/cjs/comps/Drawer/index.d.ts +2 -1
  3. package/dist/cjs/comps/Drawer/index.js +12 -5
  4. package/dist/cjs/comps/Drawer/types.d.ts +1 -0
  5. package/dist/cjs/comps/Filters/index.js +1 -0
  6. package/dist/cjs/comps/Pagination/index.d.ts +5 -2
  7. package/dist/cjs/comps/Pagination/index.js +23 -13
  8. package/dist/cjs/comps/Pagination/types.d.ts +5 -2
  9. package/dist/cjs/comps/ProgressBar/index.d.ts +1 -1
  10. package/dist/cjs/comps/ProgressBar/index.js +2 -1
  11. package/dist/cjs/comps/Radio/index.d.ts +2 -2
  12. package/dist/cjs/comps/Radio/index.js +7 -5
  13. package/dist/cjs/comps/Radio/types.d.ts +1 -1
  14. package/dist/cjs/comps/Segmented/index.d.ts +2 -2
  15. package/dist/cjs/comps/Segmented/index.js +3 -3
  16. package/dist/cjs/comps/TabView/index.d.ts +1 -2
  17. package/dist/cjs/comps/TabView/index.js +2 -1
  18. package/dist/cjs/comps/Table/col.d.ts +2 -1
  19. package/dist/cjs/comps/Table/col.js +16 -4
  20. package/dist/cjs/comps/Table/index.js +12 -6
  21. package/dist/cjs/comps/Table/row.js +6 -6
  22. package/dist/cjs/comps/Table/types.d.ts +11 -4
  23. package/dist/cjs/comps/TextWheel/index.js +5 -5
  24. package/dist/cjs/funs/index.d.ts +7 -6
  25. package/dist/cjs/funs/index.js +36 -9
  26. package/dist/css/styles.css +1 -1
  27. package/dist/esm/comps/AutoComplete/index.js +3 -3
  28. package/dist/esm/comps/Drawer/index.d.ts +2 -1
  29. package/dist/esm/comps/Drawer/index.js +12 -5
  30. package/dist/esm/comps/Drawer/types.d.ts +1 -0
  31. package/dist/esm/comps/Filters/index.js +1 -0
  32. package/dist/esm/comps/Pagination/index.d.ts +5 -2
  33. package/dist/esm/comps/Pagination/index.js +23 -13
  34. package/dist/esm/comps/Pagination/types.d.ts +5 -2
  35. package/dist/esm/comps/ProgressBar/index.d.ts +1 -1
  36. package/dist/esm/comps/ProgressBar/index.js +2 -1
  37. package/dist/esm/comps/Radio/index.d.ts +2 -2
  38. package/dist/esm/comps/Radio/index.js +7 -5
  39. package/dist/esm/comps/Radio/types.d.ts +1 -1
  40. package/dist/esm/comps/Segmented/index.d.ts +2 -2
  41. package/dist/esm/comps/Segmented/index.js +3 -3
  42. package/dist/esm/comps/TabView/index.d.ts +1 -2
  43. package/dist/esm/comps/TabView/index.js +2 -1
  44. package/dist/esm/comps/Table/col.d.ts +2 -1
  45. package/dist/esm/comps/Table/col.js +16 -4
  46. package/dist/esm/comps/Table/index.js +12 -6
  47. package/dist/esm/comps/Table/row.js +6 -6
  48. package/dist/esm/comps/Table/types.d.ts +11 -4
  49. package/dist/esm/comps/TextWheel/index.js +5 -5
  50. package/dist/esm/funs/index.d.ts +7 -6
  51. package/dist/esm/funs/index.js +36 -9
  52. package/dist/tsconfig.esm.tsbuildinfo +1 -1
  53. package/dist/tsconfig.tsbuildinfo +1 -1
  54. package/package.json +1 -1
@@ -1,13 +1,13 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { forwardRef, useEffect, useMemo, useRef, useState } from "react";
4
+ import { clamp, isArray, uuid, withPost } from "../../funs";
4
5
  import { useBase, useDebounce } from "../../hooks";
5
- import Box from "../Box";
6
6
  import { Size, TRANSITION_CURVES, TRANSITIONS } from "../../types/enums";
7
+ import Box from "../Box";
7
8
  import Input from "../Input";
8
- import SVGIcons from "../svgicons";
9
- import { clamp, isArray, uuid, withPost } from "../../funs";
10
9
  import List from "../List";
10
+ import SVGIcons from "../svgicons";
11
11
  const AutoComplete = forwardRef((props, ref) => {
12
12
  const { animate, action, data, withStyle, onChange, ...pops } = props;
13
13
  const { className: autoCompleteStyle } = useBase({ as: withStyle || `` });
@@ -1,12 +1,13 @@
1
1
  import { ReactNode } from "react";
2
+ import { DRAWER_SIDE } from "../../types/enums";
2
3
  import { BoxProps } from "../Box";
3
4
  import { DrawerHandler } from "./types";
4
- import { DRAWER_SIDE } from "../../types/enums";
5
5
  declare const Drawer: import("react").ForwardRefExoticComponent<BoxProps & {
6
6
  as?: string;
7
7
  speed?: number;
8
8
  from?: DRAWER_SIDE;
9
9
  children?: string | ReactNode | ReactNode[];
10
10
  prerender?: boolean;
11
+ onClose?: () => void;
11
12
  } & import("react").RefAttributes<DrawerHandler>>;
12
13
  export default Drawer;
@@ -1,12 +1,12 @@
1
1
  "use client";
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
- import Overlay from "../Overlay";
5
- import Box from "../Box";
6
4
  import { bindKey } from "../../funs";
7
5
  import { DRAWER_SIDE, KeyCode, TRANSITION_CURVES } from "../../types/enums";
6
+ import Box from "../Box";
7
+ import Overlay from "../Overlay";
8
8
  const Drawer = forwardRef((props, ref) => {
9
- const { as, from, speed, children, prerender, ...pops } = props;
9
+ const { as, from, speed, children, prerender, onClose, ...pops } = props;
10
10
  const [render, setRender] = useState(undefined == prerender ? true : prerender);
11
11
  const [visible, setVisible] = useState(false);
12
12
  const divRef = useRef(null);
@@ -15,7 +15,12 @@ const Drawer = forwardRef((props, ref) => {
15
15
  setContent(children);
16
16
  }, [children]);
17
17
  useEffect(() => {
18
- bindKey(KeyCode.Escape, () => visible && setVisible(false));
18
+ bindKey(KeyCode.Escape, () => {
19
+ if (visible) {
20
+ onClose?.();
21
+ setVisible(false);
22
+ }
23
+ });
19
24
  }, []);
20
25
  const style = useMemo(() => {
21
26
  switch (from) {
@@ -38,14 +43,16 @@ const Drawer = forwardRef((props, ref) => {
38
43
  setVisible(true);
39
44
  },
40
45
  close() {
46
+ onClose?.();
41
47
  setVisible(false);
42
48
  }
43
49
  }));
44
50
  return _jsxs(_Fragment, { children: [_jsx(Overlay, { onClick: (e) => {
45
51
  if (visible) {
52
+ onClose?.();
46
53
  setVisible(false);
47
54
  }
48
- }, when: visible }), _jsxs(Box, { ref: divRef, className: `--drawer flex cols --${from ? from.toLowerCase() : `left`} fixed`, animate: {
55
+ }, when: visible }), _jsxs(Box, { ref: divRef, className: `--drawer flex cols --${from ? from.toLowerCase() : `left`} fixed`, fx: {
49
56
  from: { ...style.from, opacity: 0 },
50
57
  to: { ...style.to, opacity: 1 },
51
58
  when: visible,
@@ -7,6 +7,7 @@ export type DrawerProps = BoxProps & {
7
7
  from?: DRAWER_SIDE;
8
8
  children?: string | ReactNode | ReactNode[];
9
9
  prerender?: boolean;
10
+ onClose?: () => void;
10
11
  };
11
12
  export interface DrawerHandler {
12
13
  open: (child?: string | ReactNode | ReactNode[]) => void;
@@ -1,3 +1,4 @@
1
+ "use client";
1
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
3
  import { useEffect } from "react";
3
4
  import { FILTER } from "../../types/enums";
@@ -1,10 +1,13 @@
1
- import { PaginationPage, PaginationStyle } from "./types";
1
+ import { PaginationStyle } from "./types";
2
2
  declare const Pagination: import("react").ForwardRefExoticComponent<import("..").BoxProps & {
3
3
  itemCount: number;
4
4
  itemsPerPage: number;
5
- startPage?: PaginationPage;
5
+ startPage?: number | string;
6
6
  pageRange?: number;
7
7
  paginationStyle?: PaginationStyle;
8
+ hash?: number | null;
9
+ seperator?: string;
10
+ loading?: boolean;
8
11
  breakLabel?: string;
9
12
  nextLabel?: string;
10
13
  prevLabel?: string;
@@ -1,14 +1,23 @@
1
+ "use client";
1
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
3
  import { forwardRef, useCallback, useMemo, useState } from "react";
3
- import { PaginationStyle } from "./types";
4
+ import { numberInRange, toHash } from "../..";
4
5
  import { useBase } from "../../hooks";
5
6
  import Box from "../Box";
6
7
  import Button from "../Button";
7
8
  import SVGIcons from "../svgicons";
8
- const Pagination = forwardRef((props, ref) => {
9
- const { itemCount, itemsPerPage, startPage, pageRange, paginationStyle, breakLabel, prevLabel, nextLabel, renderOnZeroPageCount, onPageChange, ...pops } = props;
10
- const [_currentPage, setCurrentPage] = useState(startPage || 1);
9
+ import { PaginationStyle } from "./types";
10
+ const Pagination = forwardRef((props, _ref) => {
11
+ const { itemCount, itemsPerPage, startPage, pageRange, paginationStyle, breakLabel, prevLabel, nextLabel, hash, loading, seperator, renderOnZeroPageCount, onPageChange, ...pops } = props;
12
+ const _hashKey = useMemo(() => toHash(numberInRange(4, 8)), []);
13
+ const _hash = useCallback((input) => `${toHash(input, hash || 6, _hashKey)}${seperator || ``}${_hashKey}`, [_hashKey]);
11
14
  const _breakLabel = useMemo(() => breakLabel || `...`, [breakLabel]);
15
+ const [_currentPage, setCurrentPage] = useState({
16
+ id: hash ?
17
+ startPage ? `number` == typeof startPage ? _hash(startPage) : startPage
18
+ : 1 : startPage || 1,
19
+ label: startPage || 1
20
+ });
12
21
  /**
13
22
  * @internal
14
23
  * const _pageType = useMemo(() => startPage ? `number` === startPage, [breakLabel])
@@ -25,28 +34,29 @@ const Pagination = forwardRef((props, ref) => {
25
34
  const prevs = Math.max(getPageValue(_currentPage) - (pageRange || 2), 1);
26
35
  const nexts = Math.min(getPageValue(_currentPage) + (pageRange || 2), totalPages);
27
36
  if (prevs > 1)
28
- _pages.push(1);
37
+ _pages.push({ id: hash ? _hash(1) : 1, label: 1 });
29
38
  if (prevs > 2)
30
- _pages.push(_breakLabel);
39
+ _pages.push({ id: -1, label: _breakLabel });
31
40
  for (let i = prevs; i <= nexts; i++)
32
- _pages.push(i);
41
+ _pages.push({ id: hash ? _hash(i) : i, label: i });
33
42
  if (nexts < totalPages - 1)
34
- _pages.push(_breakLabel);
43
+ _pages.push({ id: -1, label: _breakLabel });
35
44
  if (nexts < totalPages)
36
- _pages.push(totalPages);
45
+ _pages.push({ id: hash ? _hash(totalPages) : totalPages, label: totalPages });
37
46
  return _pages;
38
47
  }, [_currentPage]);
39
- const handlePage = useCallback((newPage) => {
40
- if (newPage < 1 || newPage > totalPages)
48
+ const handlePage = useCallback((_newPage) => {
49
+ const newPage = _newPage;
50
+ if (+newPage.label < 1 || +newPage.label > totalPages)
41
51
  return;
42
52
  setCurrentPage(newPage);
43
53
  onPageChange?.(newPage);
44
54
  }, [itemCount, itemsPerPage, _currentPage]);
45
55
  if (pages.length <= 1 && ((renderOnZeroPageCount == undefined ? false : renderOnZeroPageCount) === false))
46
56
  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: [
57
+ 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 : [{ id: 1, label: 1 }, { id: -1, label: _breakLabel }]).map((page, index, items) => _jsx(Button, { disabled: page.id == -1 || getPageValue(_currentPage) == +page.label, className: (`string` == typeof page ? page : page.label) == getPageValue(_currentPage) ? `--current-page` : ``, onClick: (ev) => handlePage(page), children: `string` == typeof page ? page : page.label }, `--pg-${index}-${page.id}`)) }), _jsx(Box, { as: `flex aic jcc flex:1 --pagination-label`, children: [
48
58
  `Showing ${(getPageValue(_currentPage) - 1) * itemsPerPage + 1} - `,
49
59
  `${Math.min(getPageValue(_currentPage) * itemsPerPage, itemCount)} of ${itemCount} items`
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 })] })] });
60
+ ].join(` `) }), _jsxs(Box, { as: `flex aic jce flex:1 --pgt-btns --pgt-nav`, children: [_jsx(Button, { disabled: getPageValue(_currentPage) <= 1, onClick: (ev) => handlePage({ id: hash ? _hash(getPageValue(_currentPage) - 1) : getPageValue(_currentPage) - 1, label: getPageValue(_currentPage) - 1 }), children: SVGIcons.chevronLeftOutline }), _jsx(Button, { disabled: pages.length <= 1 || getPageValue(_currentPage) == getPageValue(pages[pages.length - 1]), onClick: (ev) => handlePage({ id: hash ? _hash(getPageValue(_currentPage) + 1) : getPageValue(_currentPage) + 1, label: getPageValue(_currentPage) + 1 }), children: SVGIcons.chevronRightOutline })] })] });
51
61
  });
52
62
  export default Pagination;
@@ -8,13 +8,16 @@ export type PaginationPageItem = {
8
8
  label: string | number;
9
9
  };
10
10
  export type PaginationPage = number | PaginationPageItem;
11
- export type PaginationCallback = (page: PaginationPage) => void;
11
+ export type PaginationCallback = (page: PaginationPageItem) => void;
12
12
  export type PaginationProps = BoxProps & {
13
13
  itemCount: number;
14
14
  itemsPerPage: number;
15
- startPage?: PaginationPage;
15
+ startPage?: number | string;
16
16
  pageRange?: number;
17
17
  paginationStyle?: PaginationStyle;
18
+ hash?: number | null;
19
+ seperator?: string;
20
+ loading?: boolean;
18
21
  breakLabel?: string;
19
22
  nextLabel?: string;
20
23
  prevLabel?: string;
@@ -1,5 +1,5 @@
1
- import { ProgressHandler } from "./types";
2
1
  import { BoxProps } from "../Box";
2
+ import { ProgressHandler } from "./types";
3
3
  declare const ProgressBar: import("react").ForwardRefExoticComponent<BoxProps & {
4
4
  progress?: number;
5
5
  type?: import("../..").PROGRESS;
@@ -1,7 +1,8 @@
1
+ "use client";
1
2
  import { jsx as _jsx } from "react/jsx-runtime";
2
3
  import { forwardRef, useEffect, useImperativeHandle, useRef } from "react";
3
- import Box from "../Box";
4
4
  import { useBase } from "../../hooks";
5
+ import Box from "../Box";
5
6
  const ProgressBar = forwardRef((props, ref) => {
6
7
  const { progress, type, ...pops } = props;
7
8
  const bar = useRef(null);
@@ -1,8 +1,8 @@
1
- import { RadioHandler } from "./types";
2
1
  import { RADIO, Size } from "../../types/enums";
2
+ import { RadioHandler } from "./types";
3
3
  declare const Radio: import("react").ForwardRefExoticComponent<import("../..").ZuzProps & Omit<Omit<import("react").DetailedHTMLProps<import("react").InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>, "ref">, keyof import("../..").ZuzProps> & {
4
4
  type?: RADIO;
5
5
  size?: Size;
6
- onChange?: (checked: boolean, value: string | number | readonly string[]) => void;
6
+ onSwitch?: (checked: boolean, value: string | number | readonly string[]) => void;
7
7
  } & import("react").RefAttributes<RadioHandler>>;
8
8
  export default Radio;
@@ -1,15 +1,17 @@
1
+ "use client";
1
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
3
  import { forwardRef, useRef, useState } from "react";
3
- import Label from "../Label";
4
4
  import { RADIO, Size } from "../../types/enums";
5
- import Input from "../Input";
6
5
  import Box from "../Box";
7
- const Radio = forwardRef((props, ref) => {
8
- const { children, className, name, required, type, value, size, checked: defaultCheck, onChange, ...pops } = props;
6
+ import Input from "../Input";
7
+ import Label from "../Label";
8
+ const Radio = forwardRef((props, _ref) => {
9
+ const { children, className, name, required, type, value, size, checked: defaultCheck, onSwitch, ...pops } = props;
9
10
  const [checked, _setChecked] = useState(defaultCheck || false);
10
11
  const bRef = useRef(null);
11
12
  return _jsxs(Label, { className: `${className} --${(type || RADIO.Default).toLowerCase()} --radio${!type || type == RADIO.Default ? `` : `card`} --${size || Size.Default} flex aic rel`.trim(), ...pops, children: [_jsx(Input, { ...{}, ref: bRef, defaultChecked: checked, value: value || `rd`, type: `radio`, className: `abs`, name: name, required: required || false, onChange: (e) => {
12
- onChange && onChange(e.target.checked, value || `cb`);
13
+ if (onSwitch)
14
+ onSwitch(e.target.checked, value || `cb`);
13
15
  _setChecked(e.target.checked);
14
16
  } }), _jsx(Box, { className: `--dot rel`, children: _jsx(Box, { className: `--rod abs abc` }) }), _jsx(Box, { className: `--value`, children: children })] });
15
17
  });
@@ -3,7 +3,7 @@ import { RADIO, Size } from "../../types/enums";
3
3
  export type RadioProps = Props<"input"> & {
4
4
  type?: RADIO;
5
5
  size?: Size;
6
- onChange?: (checked: boolean, value: string | number | readonly string[]) => void;
6
+ onSwitch?: (checked: boolean, value: string | number | readonly string[]) => void;
7
7
  };
8
8
  export interface RadioHandler {
9
9
  setChecked: (mode: boolean, triggerChange?: boolean) => void;
@@ -1,6 +1,6 @@
1
- import { Segment } from "./types";
2
- import { BoxProps } from "../Box";
3
1
  import { Size } from "../../types/enums";
2
+ import { BoxProps } from "../Box";
3
+ import { Segment } from "./types";
4
4
  /**
5
5
  * `SelectTabs` component is a segmented control that allows switching between segments.
6
6
  *
@@ -1,9 +1,10 @@
1
+ "use client";
1
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
3
  import { forwardRef, useEffect, useRef, useState } from "react";
3
4
  import { useBase } from "../../hooks";
5
+ import { Size } from "../../types/enums";
4
6
  import Box from "../Box";
5
7
  import SegmentItem from "./item";
6
- import { Size } from "../../types/enums";
7
8
  /**
8
9
  * `SelectTabs` component is a segmented control that allows switching between segments.
9
10
  *
@@ -23,12 +24,11 @@ import { Size } from "../../types/enums";
23
24
  * <SelectTabs selected={1} items={segments} />
24
25
  */
25
26
  const Segmented = forwardRef((props, ref) => {
26
- const { animate, items, selected, size, onSwitch, ...pops } = props;
27
+ const { animate, fx, items, selected, size, onSwitch, ...pops } = props;
27
28
  const [_selected, setSelected] = useState(selected || 0);
28
29
  const { className, style, rest } = useBase(pops);
29
30
  const _tab = useRef(null);
30
31
  const _segmented = useRef(null);
31
- const [mounted, setMounted] = useState(false);
32
32
  /**
33
33
  * Handles selection of a segment.
34
34
  *
@@ -1,6 +1,5 @@
1
1
  import { Tab, TabViewHandler } from "./types";
2
- import { BoxProps } from "../Box";
3
- declare const TabView: import("react").ForwardRefExoticComponent<BoxProps & {
2
+ declare const TabView: import("react").ForwardRefExoticComponent<import("..").BoxProps & {
4
3
  onChange?: (tab: Tab, index: number) => void;
5
4
  speed?: number;
6
5
  variant?: "fixed" | "default";
@@ -1,9 +1,10 @@
1
+ "use client";
1
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
3
  import { forwardRef, useEffect, useMemo, useRef, useState } from "react";
4
+ import { SelectTabs } from "../..";
3
5
  import { uuid } from "../../funs";
4
6
  import { useBase, useResizeObserver } from "../../hooks";
5
7
  import Box from "../Box";
6
- import { SelectTabs } from "../..";
7
8
  import TabBody from "./body";
8
9
  const TabView = forwardRef((props, ref) => {
9
10
  const { tabs: _tabs, speed, prerender, variant, onChange, ...rest } = props;
@@ -1,9 +1,10 @@
1
1
  import { CSSProperties } from "react";
2
- import type { Column } from "./types";
3
2
  import { PubSub } from "../..";
3
+ import type { Column } from "./types";
4
4
  declare const TColumn: <T>(props: Column<T> & {
5
5
  idx: number;
6
6
  style?: CSSProperties;
7
7
  pubsub: PubSub;
8
+ sortBy?: string | null;
8
9
  }) => import("react/jsx-runtime").JSX.Element;
9
10
  export default TColumn;
@@ -1,10 +1,22 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useState } from "react";
3
+ import { SVGIcons } from "../..";
2
4
  import Box from "../Box";
3
5
  const TColumn = (props) => {
4
- const { idx, id, as, weight, style, value, render, resize, sort } = props;
5
- return _jsx(Box, { style: {
6
+ const { idx, id, as, weight, style, value, render, resize, sortBy, sortable, onSort } = props;
7
+ const [_sort, setSort] = useState(0);
8
+ const _onSort = () => {
9
+ if (sortable) {
10
+ onSort?.(String(id), _sort == 1 ? -1 : 1);
11
+ setSort(prev => prev == 1 ? -1 : 1);
12
+ }
13
+ };
14
+ return _jsxs(Box, { style: {
6
15
  flex: weight || 1,
7
16
  ...style
8
- }, as: `--col flex aic ${as || ``}`, children: value });
17
+ }, as: `--col flex aic ${as || ``} ${sortable ? `--sortable` : ``}`, onClick: _onSort, children: [_jsx(Box, { children: value }), idx == -1
18
+ && sortable
19
+ && sortBy == id
20
+ && _jsx(Box, { as: `--arrow flex aib`, children: _sort == 1 ? SVGIcons.arrowUp : SVGIcons.arrowDown })] });
9
21
  };
10
22
  export default TColumn;
@@ -1,14 +1,15 @@
1
+ "use client";
1
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { forwardRef, useMemo, useRef } from "react";
3
- import Box from "../Box";
3
+ import { forwardRef, useMemo, useRef, useState } from "react";
4
+ import { PubSub, uuid } from "../..";
4
5
  import { useBase } from "../../hooks";
5
- import TRow from "./row";
6
+ import Box from "../Box";
6
7
  import Pagination from "../Pagination";
7
8
  import { PaginationStyle } from "../Pagination/types";
8
- import { PubSub, uuid } from "../..";
9
+ import TRow from "./row";
9
10
  // const Table = forwardRef<HTMLDivElement, TableProps>((props, ref) => {
10
11
  const Table = (props, ref) => {
11
- const { schema, rows, rowCount, rowsPerPage, currentPage, pagination, animateRows, header, showPaginationOnZeroPageCount, rowClassName, selectableRows, hoverable, onRowSelectToggle, onPageChange, onRowContextMenu, ...pops } = props;
12
+ const { schema, rows, rowCount, rowsPerPage, currentPage, pagination, paginationHash, showPaginationOnZeroPageCount, animateRows, header, rowClassName, selectableRows, hoverable, sortBy, onSort, onRowSelectToggle, onPageChange, onRowContextMenu, ...pops } = props;
12
13
  const _schemaParsed = useMemo(() => schema.reduce((prev, c) => {
13
14
  prev[c.id] = {
14
15
  flex: c.weight || 1,
@@ -28,7 +29,12 @@ const Table = (props, ref) => {
28
29
  const _tableRef = useRef(null);
29
30
  const pubsub = useMemo(() => new PubSub(), []);
30
31
  const rowKeys = useMemo(() => rows.map(() => uuid()), [rows]);
31
- return _jsxs(Box, { as: `--table ${(hoverable ?? true) ? `--hoverable` : ``} flex cols ${className}`, ref: _tableRef, children: [_header == true && _jsx(TRow, { tableRef: _tableRef, pubsub: pubsub, selectable: selectableRows, index: -1, schema: schema, styles: _schemaParsed }), rows && rows.map((row, index) => _jsx(TRow, { tableRef: _tableRef, pubsub: pubsub, index: index, schema: schema, ids: _cols, styles: _schemaParsed, animate: animateRows, data: row, rowClassName: rowClassName, selectable: selectableRows, onSelect: onRowSelectToggle, onContextMenu: onRowContextMenu }, `--trow-${rowKeys[index]}-${schema[0].id}`)), 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 }) })] });
32
+ const [_sortBy, setSortBy] = useState(sortBy || null);
33
+ const handleSort = (col, dir) => {
34
+ setSortBy(col);
35
+ onSort?.(col, dir);
36
+ };
37
+ return _jsxs(Box, { as: `--table ${(hoverable ?? true) ? `--hoverable` : ``} flex cols ${className}`, ref: _tableRef, children: [_header == true && _jsx(TRow, { sortBy: _sortBy, onSort: handleSort, tableRef: _tableRef, pubsub: pubsub, selectable: selectableRows, index: -1, schema: schema, styles: _schemaParsed }), rows && rows.map((row, index) => _jsx(TRow, { tableRef: _tableRef, pubsub: pubsub, index: index, schema: schema, ids: _cols, styles: _schemaParsed, animate: animateRows, data: row, rowClassName: rowClassName, selectable: selectableRows, onSelect: onRowSelectToggle, onContextMenu: onRowContextMenu }, `--trow-${rowKeys[index]}-${schema[0].id}`)), pagination && _jsx(Box, { as: `--row flex aic --row-footer`, children: _jsx(Pagination, { hash: paginationHash, renderOnZeroPageCount: showPaginationOnZeroPageCount, onPageChange: onPageChange, paginationStyle: PaginationStyle.Table, startPage: currentPage, itemCount: rowCount || (rows ? rows.length : 0), itemsPerPage: rowsPerPage || 10 }) })] });
32
38
  };
33
39
  const ForwardedTable = forwardRef(Table);
34
40
  export default ForwardedTable;
@@ -1,12 +1,12 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { Fragment, useEffect, useMemo, useRef } from "react";
3
- import Box from "../Box";
4
- import TColumn from "./col";
5
- import { CHECKBOX, TRANSITION_CURVES, TRANSITIONS } from "../../types/enums";
6
3
  import { useDelayed } from "../../hooks";
4
+ import { CHECKBOX, TRANSITION_CURVES, TRANSITIONS } from "../../types/enums";
5
+ import Box from "../Box";
7
6
  import CheckBox from "../CheckBox";
7
+ import TColumn from "./col";
8
8
  const TRow = (props) => {
9
- const { index, pubsub, schema, data, ids, styles, animate, selectable, tableRef, rowClassName, onSelect, onContextMenu } = props;
9
+ const { index, pubsub, schema, data, ids, styles, animate, sortBy, selectable, tableRef, rowClassName, onSort, onSelect, onContextMenu } = props;
10
10
  const mounted = useDelayed();
11
11
  const _animation = useMemo(() => ({
12
12
  transition: TRANSITIONS.SlideInBottom,
@@ -75,11 +75,11 @@ const TRow = (props) => {
75
75
  }, []);
76
76
  return _jsxs(Box, { onContextMenu: e => onContextMenu ? onContextMenu(e, data) : null, "data-index": index, ...(animate ? { animate: { ..._animation, when: mounted } } : {}), as: `--row flex aic ${index == -1 ? `--row-head` : ``} ${rowClassName || ``}`, children: [index == -1 && schema.map((c, i) => {
77
77
  const { renderWhenHeader, render, value, ...cc } = c;
78
- return _jsxs(Fragment, { children: [selectable && i == 0 && Selector(-1, `--selector-${c.id}`, `all`), _jsx(TColumn, { idx: -1,
78
+ return _jsxs(Fragment, { children: [selectable && i == 0 && Selector(-1, `--selector-${c.id}`, `all`), _jsx(TColumn, { idx: -1, onSort: onSort, sortBy: sortBy,
79
79
  // value={renderWhenHeader && render ? render!(index == -1 ? c as dynamicObject : data as T, index) : value as string}
80
80
  value: value, ...cc, pubsub: pubsub, style: styles[c.id] })] }, `--col-${c.id}`);
81
81
  }), index > -1 && ids && data && schema.map((c, i) => {
82
- return _jsxs(Fragment, { children: [selectable && i == 0 && Selector(i, `--selector-${c.id}`, c.id.toString()), ids.includes(String(c.id)) ? _jsx(TColumn, { pubsub: pubsub, idx: i, id: String(c.id), style: styles[String(c.id)], value: c.render ? c.render(data, index) : data[c.id] }) : null] }, `--${String(c.id)}-val-${i}`);
82
+ return _jsxs(Fragment, { children: [selectable && i == 0 && Selector(i, `--selector-${c.id}`, c.id.toString()), ids.includes(String(c.id)) ? _jsx(TColumn, { pubsub: pubsub, idx: i, id: String(c.id), style: styles[String(c.id)], value: c.render ? c.render(data, index) : data[String(c.id).includes(`.`) ? String(c.id).split(`.`).reverse()[0] : c.id] }) : null] }, `--${String(c.id)}-val-${i}`);
83
83
  })] });
84
84
  };
85
85
  export default TRow;
@@ -1,9 +1,10 @@
1
1
  import { ReactNode, RefObject } from "react";
2
- import { BoxProps } from "../Box";
2
+ import { PubSub } from "../..";
3
3
  import { dynamicObject } from "../../types";
4
+ import { BoxProps } from "../Box";
4
5
  import { PaginationCallback } from "../Pagination/types";
5
- import { PubSub } from "../..";
6
6
  export type RowSelectCallback<T> = (row: T, selected: boolean) => void;
7
+ export type TableSortCallback = (col: string, dir: number) => void;
7
8
  export type Row<T> = {
8
9
  index: number;
9
10
  schema: Column<T>[];
@@ -13,14 +14,16 @@ export type Row<T> = {
13
14
  data?: T;
14
15
  rowClassName?: string;
15
16
  selectable?: boolean;
17
+ sortBy?: string | null;
16
18
  onSelect?: RowSelectCallback<T>;
19
+ onSort?: TableSortCallback;
17
20
  pubsub: PubSub;
18
21
  tableRef?: RefObject<HTMLDivElement | null>;
19
22
  onContextMenu?: (e: React.MouseEvent<HTMLDivElement, MouseEvent>, row: T) => void;
20
23
  };
21
24
  export type Column<T> = {
22
25
  id: string | number;
23
- value: string | ReactNode | dynamicObject;
26
+ value?: string | ReactNode | dynamicObject;
24
27
  weight?: number;
25
28
  w?: number | string;
26
29
  maxW?: number | string;
@@ -29,7 +32,8 @@ export type Column<T> = {
29
32
  maxH?: number | string;
30
33
  minH?: number | string;
31
34
  resize?: boolean;
32
- sort?: boolean;
35
+ sortable?: boolean;
36
+ onSort?: TableSortCallback;
33
37
  as?: string;
34
38
  renderWhenHeader?: boolean;
35
39
  render?: (row: T, index: number) => ReactNode;
@@ -42,12 +46,15 @@ export type TableProps<T> = BoxProps & {
42
46
  rowClassName?: string;
43
47
  currentPage?: number;
44
48
  pagination?: boolean;
49
+ paginationHash?: number | null;
45
50
  showPaginationOnZeroPageCount?: boolean;
46
51
  animateRows?: boolean;
47
52
  header?: boolean;
53
+ sortBy?: string;
48
54
  selectableRows?: boolean;
49
55
  hoverable?: boolean;
50
56
  onRowSelectToggle?: RowSelectCallback<T>;
51
57
  onRowContextMenu?: (e: React.MouseEvent<HTMLDivElement, MouseEvent>, row: T) => void;
52
58
  onPageChange?: PaginationCallback;
59
+ onSort?: TableSortCallback;
53
60
  };
@@ -1,6 +1,6 @@
1
+ "use client";
1
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { useEffect, useImperativeHandle, useRef, useState } from 'react';
3
- import { forwardRef } from 'react';
3
+ import { forwardRef, useEffect, useImperativeHandle, useRef, useState } from 'react';
4
4
  import Box from '../Box';
5
5
  import Span from '../Span';
6
6
  const TextWheel = forwardRef((props, ref) => {
@@ -34,11 +34,11 @@ const TextWheel = forwardRef((props, ref) => {
34
34
  // console.log(value)
35
35
  _setValue(value || 0);
36
36
  }, [value]);
37
- return _jsxs(Box, { className: `text-wheel flex aic jcc rel`, "aria-hidden": true, as: as, ref: divRef, ...rest, children: [(_value || 0).toString().split('').map((char, index) => {
37
+ return _jsxs(Box, { className: `--text-wheel flex aic jcc rel`, "aria-hidden": true, as: as, ref: divRef, ...rest, children: [(_value || 0).toString().split('').map((char, index) => {
38
38
  if (isNaN(parseInt(char, 10))) {
39
- return _jsx(Span, { className: "wheel-char wheel-char-symbol grid", children: char }, `wheel-char-${index}`);
39
+ return _jsx(Span, { className: "--wheel-char wheel-char-symbol grid", children: char }, `wheel-char-${index}`);
40
40
  }
41
- return _jsx(Span, { "data-value": char, className: `wheel-char grid ${index > char.toString().split('').length - 3 ? 'wheel-fraction' : ''}`.trim(), children: _jsxs(Span, { className: `wheel-char-track wheel-track-${direction || `down`} grid`, style: {
41
+ return _jsx(Span, { "data-value": char, className: `--wheel-char grid ${index > char.toString().split('').length - 3 ? '--wheel-fraction' : ''}`.trim(), children: _jsxs(Span, { className: `--wheel-char-track --wheel-track-${direction || `down`} grid`, style: {
42
42
  '--v': char
43
43
  }, children: [_jsx(Span, { children: !direction || direction == `down` ? 0 : 9 }), (!direction || direction == `down` ?
44
44
  [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
@@ -1,8 +1,8 @@
1
- import CSS from "./css.js";
2
- import { dynamicObject, FormatNumberParams, sortOptions } from "../types/index.js";
3
1
  import { AxiosProgressEvent } from "axios";
4
- import { KeyCode } from "../types/enums.js";
5
2
  import { ReactElement, ReactNode, Ref } from "react";
3
+ import { KeyCode } from "../types/enums.js";
4
+ import { dynamicObject, FormatNumberParams, sortOptions } from "../types/index.js";
5
+ import CSS from "./css.js";
6
6
  export declare const __SALT: string;
7
7
  export declare const FIELNAME_KEY = "__FILENAME__";
8
8
  export declare const LINE_KEY = "__LINE__";
@@ -29,8 +29,8 @@ export declare const isEmail: (e: string) => boolean;
29
29
  export declare const isUrl: (o: string) => boolean;
30
30
  export declare const toLowerCase: (o: string) => string;
31
31
  export declare const ucfirst: (o: any) => string;
32
- export declare const toHash: (n: number, len?: number) => string;
33
- export declare const fromHash: (n: string) => number;
32
+ export declare const toHash: (n: number, len?: number, SALT?: string | null) => string;
33
+ export declare const fromHash: (n: string, SALT?: string | null) => number;
34
34
  export declare const css: () => CSS;
35
35
  export declare const withCSS: (cx: string | string[]) => string;
36
36
  export declare const uuid: (len?: number) => string;
@@ -49,7 +49,8 @@ export declare const cleanProps: <T extends dynamicObject>(props: T, withProps?:
49
49
  export declare const withZuz: (cx: string | string[]) => string;
50
50
  export declare const setDeep: (object: dynamicObject, path: string, value: any, seperator?: string) => dynamicObject;
51
51
  export declare const removeDuplicatesFromArray: <T>(array: T[]) => T[];
52
- export declare const withPost: (uri: string, data: dynamicObject | FormData, timeout?: number, onProgress?: (ev: AxiosProgressEvent) => void) => Promise<dynamicObject>;
52
+ export declare const withPost: <T>(uri: string, data: dynamicObject | FormData, timeout?: number, onProgress?: (ev: AxiosProgressEvent) => void) => Promise<T>;
53
+ export declare const withGet: <T>(uri: string, timeout?: number) => Promise<T>;
53
54
  export declare const withTime: (fun: (...args: any[]) => any) => {
54
55
  result: any;
55
56
  executionTime: number;
@@ -1,14 +1,14 @@
1
- import Hashids from "hashids";
2
- import CSS from "./css.js";
3
- import { nanoid } from "nanoid";
4
- import md5 from "md5";
5
- import { colorNames } from "./colors.js";
6
- import { cssProps } from "./stylesheet.js";
7
1
  import axios from "axios";
2
+ import Hashids from "hashids";
8
3
  import Cookies from "js-cookie";
4
+ import md5 from "md5";
9
5
  import moment from "moment";
10
- import { SORT } from "../types/enums.js";
6
+ import { nanoid } from "nanoid";
11
7
  import { Children, cloneElement, isValidElement } from "react";
8
+ import { SORT } from "../types/enums.js";
9
+ import { colorNames } from "./colors.js";
10
+ import CSS from "./css.js";
11
+ import { cssProps } from "./stylesheet.js";
12
12
  let __css;
13
13
  export const __SALT = `zuzjs-ui`;
14
14
  export const FIELNAME_KEY = `__FILENAME__`;
@@ -129,8 +129,8 @@ export const isEmail = (e) => /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.te
129
129
  export const isUrl = (o) => /^(https?:\/\/)?(www\.)?([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}(\/[^\s]*)?$/.test(o);
130
130
  export const toLowerCase = (o) => (String.prototype.toLocaleLowerCase || String.prototype.toLowerCase)(o);
131
131
  export const ucfirst = (o) => `${o.charAt(0).toUpperCase()}${o.substring(1, o.length)}`;
132
- export const toHash = (n, len = 6) => new Hashids(__SALT, len).encode(n);
133
- export const fromHash = (n) => Number(new Hashids(__SALT).decode(n));
132
+ export const toHash = (n, len = 6, SALT = null) => new Hashids(SALT || __SALT, len).encode(n);
133
+ export const fromHash = (n, SALT = null) => Number(new Hashids(SALT || __SALT).decode(n));
134
134
  export const css = () => __css ? __css : __css = new CSS();
135
135
  export const withCSS = (cx) => css().Build([[`string` == typeof cx ? cx : cx.join(` `)]]).cx.join(` `);
136
136
  export const uuid = (len) => nanoid(len);
@@ -260,6 +260,33 @@ export const withPost = async (uri, data, timeout = 60, onProgress) => {
260
260
  });
261
261
  });
262
262
  };
263
+ export const withGet = async (uri, timeout = 60) => {
264
+ return new Promise((resolve, reject) => {
265
+ axios
266
+ .get(uri, { timeout: timeout * 1000 })
267
+ .then((resp) => {
268
+ if (resp.data && "kind" in resp.data) {
269
+ resolve(resp.data);
270
+ }
271
+ else {
272
+ reject(resp.data);
273
+ }
274
+ })
275
+ .catch((err) => {
276
+ if (err?.response?.data)
277
+ reject(err.response.data);
278
+ else
279
+ reject(err.code === `ERR_NETWORK`
280
+ ? {
281
+ error: err.code,
282
+ message: navigator.onLine
283
+ ? `Unable to connect to the server. It may be temporarily down.`
284
+ : `Network error: Unable to connect. Please check your internet connection and try again.`,
285
+ }
286
+ : err);
287
+ });
288
+ });
289
+ };
263
290
  export const withTime = (fun) => {
264
291
  const start = new Date().getTime();
265
292
  const result = fun();