@zuzjs/ui 0.5.4 → 0.5.5

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 (57) hide show
  1. package/dist/bin.js +26 -0
  2. package/dist/comps/accordion.d.ts +12 -0
  3. package/dist/comps/accordion.js +13 -0
  4. package/dist/comps/animate.d.ts +1 -1
  5. package/dist/comps/base.d.ts +4 -13
  6. package/dist/comps/base.js +3 -2
  7. package/dist/comps/box.d.ts +2 -2
  8. package/dist/comps/box.js +10 -3
  9. package/dist/comps/button.d.ts +3 -5
  10. package/dist/comps/button.js +12 -3
  11. package/dist/comps/checkbox.d.ts +1 -1
  12. package/dist/comps/checkbox.js +19 -0
  13. package/dist/comps/contextmenu.d.ts +1 -1
  14. package/dist/comps/cover.d.ts +1 -1
  15. package/dist/comps/cover.js +15 -0
  16. package/dist/comps/editor.js +8 -1
  17. package/dist/comps/form.d.ts +35 -5
  18. package/dist/comps/form.js +67 -21
  19. package/dist/comps/heading.js +13 -0
  20. package/dist/comps/icon.d.ts +4 -5
  21. package/dist/comps/icon.js +15 -3
  22. package/dist/comps/image.d.ts +1 -1
  23. package/dist/comps/input.d.ts +2 -8
  24. package/dist/comps/input.js +5 -5
  25. package/dist/comps/password.d.ts +3 -0
  26. package/dist/comps/password.js +30 -0
  27. package/dist/comps/select.d.ts +2 -1
  28. package/dist/comps/select.js +28 -3
  29. package/dist/comps/sheet.js +3 -0
  30. package/dist/comps/spinner.d.ts +1 -1
  31. package/dist/comps/spinner.js +1 -0
  32. package/dist/comps/tabview.js +8 -1
  33. package/dist/comps/textwheel.d.ts +1 -1
  34. package/dist/comps/textwheel.js +2 -0
  35. package/dist/comps/useBase/base.types.d.ts +64 -0
  36. package/dist/comps/useBase/base.types.js +1 -0
  37. package/dist/comps/useBase/index.d.ts +10 -0
  38. package/dist/comps/useBase/index.js +62 -0
  39. package/dist/funs/colors.d.ts +6 -0
  40. package/dist/funs/colors.js +6 -0
  41. package/dist/funs/css.js +127 -17
  42. package/dist/funs/events.js +3 -0
  43. package/dist/funs/index.d.ts +4 -0
  44. package/dist/funs/index.js +28 -2
  45. package/dist/funs/stylesheet.js +15 -1
  46. package/dist/hooks/useKeyBind.js +1 -0
  47. package/dist/hooks/useMounted.d.ts +15 -0
  48. package/dist/hooks/useMounted.js +16 -1
  49. package/dist/hooks/useToast.d.ts +1 -1
  50. package/dist/hooks/useToast.js +1 -1
  51. package/dist/index.d.ts +3 -0
  52. package/dist/index.js +3 -0
  53. package/dist/styles.css +1 -1
  54. package/dist/types/enums.d.ts +15 -10
  55. package/dist/types/enums.js +25 -0
  56. package/dist/types/interfaces.d.ts +11 -2
  57. package/package.json +1 -1
package/dist/bin.js CHANGED
@@ -13,6 +13,7 @@ program
13
13
  .option(`-f, --file <char>`);
14
14
  program.parse();
15
15
  const options = program.opts();
16
+ // extendGlobals()
16
17
  const getAllFiles = (dir, extn, files, result, regex) => {
17
18
  files = files || readdirSync(dir);
18
19
  result = result || [];
@@ -54,6 +55,7 @@ const rebuild = (f) => {
54
55
  }
55
56
  return arr;
56
57
  }, []).join(` `);
58
+ //
57
59
  }
58
60
  if (v2.startsWith(`[`) && v2.endsWith(`]`))
59
61
  v2 = v2.slice(1, -1);
@@ -62,19 +64,29 @@ const rebuild = (f) => {
62
64
  if (matches && matches.length > 0) {
63
65
  matches.map((m) => {
64
66
  let v2;
67
+ // m = m.replace(/\s+|\n/gm, ` `)
65
68
  if (type == `as`) {
66
69
  const [x, v1] = m.split(/as\s*=/);
67
70
  v2 = makeV2(v1);
68
71
  }
69
72
  else if (type == `css`) {
70
73
  const v1 = m.split(/css\s*\(/)[1].slice(0, -1);
74
+ // console.log(v1)
71
75
  v2 = makeV2(v1.trim());
72
76
  }
77
+ // console.log(`v2 ->`, `"${v2}"`)
73
78
  list.push(v2);
74
79
  });
75
80
  }
76
81
  };
82
+ /**
83
+ * match as={?}
84
+ */
85
+ // processMatch(raw.match(/as\s*=\s*\{([^{}]|{([^{}]|{[^{}]*})*})*\}/g), `as`)
77
86
  processMatch(raw.match(/as\s*=\s*(?:\{([^{}]|{([^{}]|{[^{}]*})*})*\}|'([^']*)'|"([^"]*)")/g), `as`);
87
+ /**
88
+ * match css()
89
+ */
78
90
  processMatch(raw.match(/css\(\s*(?:\[\s*([\s\S]*?)\s*\]|\s*`([\s\S]*?)`)\s*\)/g), `css`);
79
91
  return list;
80
92
  };
@@ -87,14 +99,21 @@ const rebuildAll = () => {
87
99
  if (options.file) {
88
100
  const r = rebuild(files.filter(f => f.endsWith(options.file.replace(path.resolve(`./`), ``)))[0]);
89
101
  if (r && r.length > 0) {
102
+ // console.log(r)
90
103
  as.push(cssBuilder.Build([r], true, options.file).sheet);
104
+ // as.push(r)
91
105
  }
92
106
  }
93
107
  else {
94
108
  const mediaQueries = {};
95
109
  files.map(f => {
110
+ // if ( f.endsWith(`header.jsx`) ){
96
111
  const r = rebuild(f);
97
112
  if (r && r.length > 0) {
113
+ // as.push(cssBuilder.Build([r], true).sheet)
114
+ // as.push( f.endsWith(`header.jsx`) ?
115
+ // `.header{${cssBuilder.Build([r], true).sheet}}`
116
+ // : cssBuilder.Build([r], true).sheet)
98
117
  const _built = cssBuilder.Build([r], true, f.replace(path.resolve(`./`), ``));
99
118
  as.push(_built.sheet);
100
119
  Object.keys(_built.mediaQuery).map(mq => {
@@ -105,14 +124,21 @@ const rebuildAll = () => {
105
124
  ..._built.mediaQuery[mq]
106
125
  ];
107
126
  });
127
+ // as.push(new CSS().Build([[r]], true).sheet)
108
128
  }
129
+ // }
130
+ // as.push(r)
109
131
  });
110
132
  as.push(cssBuilder.buildMediaQueries(mediaQueries));
111
133
  }
134
+ // console.log(as)
135
+ // const { sheet } = new CSS().Build(as, true)
136
+ // console.log(cache)
112
137
  const sheet = as.join(`\n`);
113
138
  if (!fs.existsSync(path.join(process.cwd(), `src`, `app`, `css`))) {
114
139
  fs.mkdirSync(path.join(process.cwd(), `src`, `app`, `css`));
115
140
  }
141
+ // console.log(sheet)
116
142
  fs.writeFileSync(path.join(process.cwd(), `src`, `app`, `css`, `zuz.scss`), sheet, {
117
143
  encoding: `utf8`,
118
144
  flag: `w+`
@@ -0,0 +1,12 @@
1
+ import { ReactNode } from "react";
2
+ import { BaseProps } from "../types/interfaces";
3
+ export interface AccordionProps {
4
+ message?: string;
5
+ title: string | ReactNode | ReactNode[];
6
+ }
7
+ export interface AccordionHandler {
8
+ open: () => void;
9
+ close: () => void;
10
+ }
11
+ declare const Accordion: import("react").ForwardRefExoticComponent<AccordionProps & BaseProps & import("react").RefAttributes<AccordionHandler>>;
12
+ export default Accordion;
@@ -0,0 +1,13 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { forwardRef, useState } from "react";
3
+ import With from "./base";
4
+ const Icons = {
5
+ ArrowDown: _jsx("svg", { xmlns: "http://www.w3.org/2000/svg", fill: "none", viewBox: "0 0 24 24", children: _jsx("path", { fill: "#292D32", d: "M17.919 8.18H6.079c-.96 0-1.44 1.16-.76 1.84l5.18 5.18c.83.83 2.18.83 3.01 0l1.97-1.97 3.21-3.21c.67-.68.19-1.84-.77-1.84z" }) }),
6
+ ArrowUp: _jsx("svg", { xmlns: "http://www.w3.org/2000/svg", fill: "none", viewBox: "0 0 24 24", children: _jsx("path", { fill: "#292D32", d: "M18.68 13.978l-3.21-3.21-1.96-1.97a2.13 2.13 0 00-3.01 0l-5.18 5.18c-.68.68-.19 1.84.76 1.84h11.84c.96 0 1.44-1.16.76-1.84z" }) })
7
+ };
8
+ const Accordion = forwardRef((props, ref) => {
9
+ const { title, message, ...rest } = props;
10
+ const [visible, setVisible] = useState(false);
11
+ return _jsxs(With, { className: `--accordion flex cols`, ...rest, children: [_jsxs(With, { onClick: (e) => setVisible(!visible), tag: `button`, className: `--toggle flex aic ${visible ? `--open` : ``}`.trim(), children: [_jsx(With, { tag: `h1`, className: `--label flex`, children: title }), _jsx(With, { className: `--arrow flex`, children: visible ? Icons.ArrowUp : Icons.ArrowDown })] }), visible && _jsx(With, { className: `--detail`, children: message })] });
12
+ });
13
+ export default Accordion;
@@ -1,4 +1,4 @@
1
- import { animationProps } from "./base";
1
+ import { animationProps } from "../types/interfaces";
2
2
  declare const Animate: import("react").ForwardRefExoticComponent<{
3
3
  as?: string;
4
4
  animate?: animationProps;
@@ -1,16 +1,6 @@
1
1
  import { ComponentPropsWithoutRef, ElementType } from "react";
2
- import { dynamicObject } from "../types";
3
- import { TRANSITION_CURVES, TRANSITIONS } from "../types/enums";
4
- import { Skeleton } from "../types/interfaces";
5
- export interface animationProps {
6
- transition?: TRANSITIONS;
7
- from?: dynamicObject;
8
- to?: dynamicObject;
9
- when?: boolean;
10
- duration?: number;
11
- delay?: number;
12
- curve?: string | TRANSITION_CURVES;
13
- }
2
+ import { SHIMMER } from "../types/enums";
3
+ import { animationProps, Skeleton } from "../types/interfaces";
14
4
  interface BaseProps<T extends ElementType> {
15
5
  tag?: T;
16
6
  as?: string | string[];
@@ -18,7 +8,8 @@ interface BaseProps<T extends ElementType> {
18
8
  className?: string;
19
9
  propsToRemove?: string[];
20
10
  skeleton?: Skeleton;
11
+ shimmer?: SHIMMER;
21
12
  }
22
- export type Props<T extends ElementType> = BaseProps<T> & ComponentPropsWithoutRef<T>;
13
+ export type Props<T extends ElementType> = BaseProps<T> & Omit<ComponentPropsWithoutRef<T>, keyof BaseProps<T>>;
23
14
  declare const With: import("react").ForwardRefExoticComponent<Omit<Props<ElementType>, "ref"> & import("react").RefAttributes<Element>>;
24
15
  export default With;
@@ -45,7 +45,7 @@ const With = forwardRef(({ tag, as, animate, className, propsToRemove, style, sk
45
45
  else {
46
46
  _style = transition ? getAnimationTransition(transition, false, true) : from || {};
47
47
  }
48
- const { children, ...restProps } = cleanProps(rest, propsToRemove ? [...propsToRemove, `skeleton`] : [`skeleton`]);
48
+ const { children, shimmer, ...restProps } = cleanProps(rest, propsToRemove ? [...propsToRemove, `skeleton`] : [`skeleton`]);
49
49
  return createElement(Comp, {
50
50
  style: {
51
51
  ...buildWithStyles(_style),
@@ -56,7 +56,8 @@ const With = forwardRef(({ tag, as, animate, className, propsToRemove, style, sk
56
56
  className: [
57
57
  className,
58
58
  ...cx,
59
- skeleton?.enabled ? `--skeleton` : ``
59
+ skeleton?.enabled ? `--skeleton` : ``,
60
+ shimmer ? `--shimmer --${shimmer.toLowerCase()}` : ``,
60
61
  ].join(' ').trim(),
61
62
  children: skeleton?.enabled ? ` `.repeat(6)
62
63
  : children,
@@ -1,3 +1,3 @@
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>>;
1
+ import { Props } from "./useBase/base.types";
2
+ declare const Box: import("react").ForwardRefExoticComponent<Props<"div"> & import("react").RefAttributes<HTMLDivElement>>;
3
3
  export default Box;
package/dist/comps/box.js CHANGED
@@ -1,8 +1,15 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { forwardRef } from "react";
3
- import With from "./base";
3
+ import useBase from "./useBase";
4
4
  const Box = forwardRef((props, ref) => {
5
- const { as, ...rest } = props;
6
- return _jsx(With, { as: as, ...rest, ref: ref });
5
+ const { className, style, rest } = useBase(props);
6
+ return _jsx("div", { ref: ref, className: className, style: style, ...rest });
7
7
  });
8
+ // export interface BoxProps extends Props<'div'> {}
9
+ // const Box = forwardRef<HTMLDivElement, BoxProps>((props, ref ) => {
10
+ // const { as, children, className, ...rest } = props
11
+ // return <With className={className} as={as} {...rest} ref={ref}>
12
+ // {children}
13
+ // </With>
14
+ // });
8
15
  export default Box;
@@ -1,8 +1,6 @@
1
- import { animationProps } from "./base";
2
- export interface ButtonProps {
3
- as?: string;
4
- animate?: animationProps;
1
+ import { Props } from "./useBase/base.types";
2
+ export interface ButtonProps extends Props<`button`> {
5
3
  icon?: string;
6
4
  }
7
- declare const Button: import("react").ForwardRefExoticComponent<ButtonProps & Omit<import("react").DetailedHTMLProps<import("react").ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "ref"> & import("react").RefAttributes<HTMLButtonElement>>;
5
+ declare const Button: import("react").ForwardRefExoticComponent<ButtonProps & import("react").RefAttributes<HTMLButtonElement>>;
8
6
  export default Button;
@@ -1,8 +1,17 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { forwardRef } from "react";
3
- import With from "./base";
3
+ // import With, { Props } from "./base";
4
+ import useBase from "./useBase";
4
5
  const Button = forwardRef((props, ref) => {
5
- const { as, icon, ...rest } = props;
6
- return _jsxs(With, { tag: `button`, as: as, className: `flex aic ${icon ? `ico-btn` : ``}`.trim(), ...rest, ref: ref, children: [icon && _jsx(With, { className: `icon-${icon}` }), _jsx(With, { tag: `span`, className: `b-label`, children: props.children })] });
6
+ const { icon, children, ...pops } = props;
7
+ const { className, style, rest } = useBase(pops);
8
+ return _jsxs("button", { className: `${className} flex aic ${icon ? `ico-btn` : ``}`, style: style, ref: ref, ...rest, children: [icon && _jsx("div", { ...{ className: `icon-${icon}` } }), _jsx("span", { ...{ className: `b-label` }, children: children })] });
7
9
  });
10
+ // const Button = forwardRef<HTMLButtonElement, ButtonProps>((props, ref ) => {
11
+ // const { as, icon, ...rest } = props;
12
+ // return <With tag={`button`} as={as} className={`flex aic ${icon ? `ico-btn` : ``}`.trim()} {...rest} ref={ref}>
13
+ // {icon && <With className={`icon-${icon}`} />}
14
+ // <With tag={`span`} className={`b-label`}>{props.children}</With>
15
+ // </With>
16
+ // });
8
17
  export default Button;
@@ -1,5 +1,5 @@
1
- import { animationProps } from "./base";
2
1
  import { CHECKBOX } from "../types/enums";
2
+ import { animationProps } from "../types/interfaces";
3
3
  export interface CheckboxProps {
4
4
  as?: string;
5
5
  type?: CHECKBOX;
@@ -3,6 +3,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
3
3
  import { forwardRef, useImperativeHandle, useRef, useState } from "react";
4
4
  import With from "./base";
5
5
  import { CHECKBOX } from "../types/enums";
6
+ // const CheckBox = forwardRef<HTMLButtonElement, { as?: string, type?: CHECKBOX, animate?: animationProps } & ComponentPropsWithoutRef<`input`>>((props, ref) => {
6
7
  const CheckBox = forwardRef((props, ref) => {
7
8
  const { as, name, required, type, value, checked: defaultCheck, onChange, ...rest } = props;
8
9
  const [checked, _setChecked] = useState(defaultCheck || false);
@@ -29,4 +30,22 @@ const CheckBox = forwardRef((props, ref) => {
29
30
  _setChecked(e.target.checked);
30
31
  } }) });
31
32
  });
33
+ // import { DetailedHTMLProps, HTMLAttributes, ReactNode, Ref, useState } from "react";
34
+ // import { cleanProps, css } from "../funs";
35
+ // import { UIProps } from "../types/interfaces";
36
+ // const CheckBox = ( props : UIProps<HTMLInputElement> ) => {
37
+ // const { cx } = css.Build(props.as)
38
+ // const [ checked, setChecked ] = useState(props.checked || false)
39
+ // return <label { ...({
40
+ // className: `zuz-checkbox${checked ? ` is-checked` : ``} rel${cx.length > 0 ? ` ` + cx.join(` `) : ``}`
41
+ // }) as UIProps<HTMLLabelElement>}>
42
+ // <input type='checkbox'
43
+ // ref={props.ref}
44
+ // onChange={e => {
45
+ // setChecked(e.target.checked)
46
+ // }}
47
+ // className={`abs`}
48
+ // {...(cleanProps(props) as UIProps<HTMLInputElement>)} />
49
+ // </label>
50
+ // }
32
51
  export default CheckBox;
@@ -1,4 +1,4 @@
1
- import { animationProps } from "./base";
1
+ import { animationProps } from "../types/interfaces";
2
2
  export interface ContextMenuItem {
3
3
  label: string;
4
4
  labelColor?: string;
@@ -1,6 +1,6 @@
1
1
  import { ComponentPropsWithoutRef } from "react";
2
- import { animationProps } from "./base";
3
2
  import { SpinnerProps } from "./spinner";
3
+ import { animationProps } from "../types/interfaces";
4
4
  export interface CoverProps extends ComponentPropsWithoutRef<`div`> {
5
5
  tag?: string;
6
6
  message?: string;
@@ -12,5 +12,20 @@ const Cover = forwardRef((props, ref) => {
12
12
  }, as: as, ...rest, children: [_jsx(Spinner, { ...{
13
13
  ...spinner
14
14
  } }), !hideMessage && _jsx(With, { tag: `h1`, className: `label`, style: { color: `var(--cover-label)` }, children: message || `loading` })] }));
15
+ // return (
16
+ // <With
17
+ // className={`zuz-cover flex aic jcc cols abs fill nope nous`}
18
+ // ref={ref}
19
+ // style={{
20
+ // backgroundColor: color ? !color.startsWith(`#`) ? hexToRgba(color, .9) : color : hexToRgba(color || `var(--cover)`, .9)
21
+ // }}
22
+ // as={as}
23
+ // {...rest}
24
+ // >
25
+ // {<Spinner {...spinner} />}
26
+ // {<With tag={`h1`} className={`label`}>{message || `loading`}</With>}
27
+ // {/* {message && <With tag={`h1`} className={`label`}>{message}</With>} */}
28
+ // </With>
29
+ // );
15
30
  });
16
31
  export default Cover;
@@ -12,6 +12,9 @@ const ComponentEditor = forwardRef((props, ref) => {
12
12
  const { title, attrs, element } = props;
13
13
  const mounted = useMounted(500);
14
14
  const getVariable = (v) => {
15
+ // console.log(element!.current)
16
+ // const elm = document.querySelector(element!);
17
+ // return getComputedStyle(document.querySelector(element)!).getPropertyValue(`--${v}`).trim()
15
18
  const a = getComputedStyle(document.querySelector(element)).getPropertyValue(`--${v}`).trim();
16
19
  const b = getComputedStyle(document.body).getPropertyValue(`--${v}`).trim();
17
20
  const d = getComputedStyle(document.documentElement).getPropertyValue(`--${v}`).trim();
@@ -25,19 +28,23 @@ const ComponentEditor = forwardRef((props, ref) => {
25
28
  };
26
29
  const rangeSlider = (k, value, min, max, step, unit) => {
27
30
  return _jsxs(_Fragment, { children: [_jsx(With, { tag: `input`, type: `range`, defaultValue: value, min: min, max: max, step: step, name: `editor-prop-range-${k}`, onChange: (e) => {
31
+ // document.body.style.setProperty(`--${k}`,`${e.currentTarget.value}${unit || ``}`);
28
32
  document.querySelector(element).style.setProperty(`--${k}`, `${e.currentTarget.value}${unit || ``}`);
29
33
  document.querySelector(`input[name="editor-prop-num-${k}"]`).value = e.currentTarget.value;
30
34
  } }), _jsx(With, { tag: `input`, type: `number`, name: `editor-prop-num-${k}`, defaultValue: value, min: min, max: max, onChange: (e) => {
31
35
  document.querySelector(element).style.setProperty(`--${k}`, `${e.currentTarget.value}${unit || ``}`);
36
+ // document.body.style.setProperty(`--${k}`,`${e.currentTarget.value}${unit || ``}`);
32
37
  document.querySelector(`input[name="editor-prop-range-${k}"]`).value = e.currentTarget.value;
33
38
  } })] });
34
39
  };
35
40
  const colorPicker = (k, value) => {
36
41
  return _jsxs(_Fragment, { children: [_jsx(With, { tag: `input`, type: `color`, defaultValue: expandHex(value.toString()), name: `editor-prop-color-${k}`, onChange: (e) => {
42
+ // document.body.style.setProperty(`--${k}`, e.currentTarget.value);
37
43
  document.querySelector(element).style.setProperty(`--${k}`, e.currentTarget.value);
38
44
  document.querySelector(`input[name="editor-prop-num-${k}"]`).value = e.currentTarget.value;
39
45
  } }), _jsx(With, { tag: `input`, name: `editor-prop-num-${k}`, defaultValue: expandHex(value.toString()), onChange: (e) => {
40
46
  document.querySelector(element).style.setProperty(`--${k}`, `${e.currentTarget.value}`);
47
+ // document.body.style.setProperty(`--${k}`,`${e.currentTarget.value}px`);
41
48
  document.querySelector(`input[name="editor-prop-color-${k}"]`).value = e.currentTarget.value;
42
49
  } })] });
43
50
  };
@@ -67,7 +74,7 @@ const ComponentEditor = forwardRef((props, ref) => {
67
74
  c.push(`--${k}: ${value == `auto` ? type == `range` ? parseFloat(getVariable(k)) : getVariable(k) : value}${unit || ``};`);
68
75
  }
69
76
  });
70
- return c;
77
+ return c; //.join(`\n`)
71
78
  };
72
79
  if (!mounted)
73
80
  return null;
@@ -1,24 +1,54 @@
1
- import { animationProps } from "./base";
1
+ import { Props } from "./useBase/base.types";
2
2
  import { SpinnerProps } from "./spinner";
3
3
  import { dynamicObject } from "../types";
4
- export interface FormProps {
5
- as?: string;
6
- animate?: animationProps;
4
+ /**
5
+ * `FormProps` defines properties for the `Form` component, including action handlers,
6
+ * spinner, and error handling configuration.
7
+ */
8
+ export interface FormProps extends Props<`div`> {
9
+ /** Name of form, will be appended to --form-{name} in className
10
+ * whitespace will be replaced with dash (-)
11
+ */
12
+ name?: string;
13
+ /** The URL to which the form data is submitted */
7
14
  action?: string;
15
+ /** List of error messages for form validation */
8
16
  errors?: string[];
17
+ /** Spinner properties for loading indicator */
9
18
  spinner?: SpinnerProps;
19
+ /** Additional data to include with form submission */
10
20
  withData?: dynamicObject;
21
+ /** Handler function called on form submission with validated form data */
11
22
  onSubmit?: (data: FormData | dynamicObject) => void;
23
+ /** Callback triggered upon successful form submission */
12
24
  onSuccess?: (data: dynamicObject) => void;
25
+ /** Callback triggered when form submission encounters an error */
13
26
  onError?: (error: any) => void;
27
+ /** Cover properties to display loading or processing message */
14
28
  cover?: {
29
+ /** Background color of the loading cover */
15
30
  color?: string;
31
+ /** Message displayed during loading */
16
32
  message?: string;
17
33
  };
18
34
  }
35
+ /**
36
+ * Exposes control methods for the Form component, such as setting loading states or hiding errors.
37
+ */
19
38
  export interface FormHandler {
39
+ /** Sets the loading state of the form */
20
40
  setLoading: (mode: boolean) => void;
41
+ /** Hides any currently displayed error message */
21
42
  hideError: () => void;
22
43
  }
23
- declare const Form: import("react").ForwardRefExoticComponent<FormProps & Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & import("react").RefAttributes<FormHandler>>;
44
+ /**
45
+ * {@link Form} is a controlled component designed to handle form data submission, validation, and display of loading or error states.
46
+ * It allows for optional server-side submission through an action endpoint and customizable success/error handling callbacks.
47
+ *
48
+ * The component also provides an interface for controlling loading and error states from a parent component using {@link FormHandler}.
49
+ *
50
+ * @param props - Properties to configure form behavior, validation messages, submission handling, and visual feedback.
51
+ * @param ref - Reference to the {@link FormHandler} interface, exposing methods to control loading and error states from the parent.
52
+ */
53
+ declare const Form: import("react").ForwardRefExoticComponent<FormProps & import("react").RefAttributes<FormHandler>>;
24
54
  export default Form;
@@ -1,21 +1,46 @@
1
- "use client";
2
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { forwardRef, useEffect, useImperativeHandle, useRef, useState, useTransition } from "react";
4
- import With from "./base";
5
- import { isEmail, withPost } from "../funs";
2
+ import { forwardRef, startTransition, useCallback, useEffect, useImperativeHandle, useRef, useState } from "react";
3
+ import Box from "./box";
4
+ import useBase from "./useBase";
6
5
  import Sheet from "./sheet";
7
- import { FORMVALIDATION, SHEET } from "../types/enums";
8
6
  import Cover from "./cover";
7
+ import { FORMVALIDATION, SHEET } from "../types/enums";
8
+ import { isEmail, withPost } from "../funs";
9
+ /**
10
+ * {@link Form} is a controlled component designed to handle form data submission, validation, and display of loading or error states.
11
+ * It allows for optional server-side submission through an action endpoint and customizable success/error handling callbacks.
12
+ *
13
+ * The component also provides an interface for controlling loading and error states from a parent component using {@link FormHandler}.
14
+ *
15
+ * @param props - Properties to configure form behavior, validation messages, submission handling, and visual feedback.
16
+ * @param ref - Reference to the {@link FormHandler} interface, exposing methods to control loading and error states from the parent.
17
+ */
9
18
  const Form = forwardRef((props, ref) => {
10
- const { as, spinner, action, errors, cover, children, withData, onSuccess, onSubmit, onError, ...rest } = props;
19
+ const { name, cover, spinner, errors, action, children, withData, onSubmit, onError, onSuccess, ...pops } = props;
20
+ const { className, style, rest } = useBase(pops);
11
21
  const [loading, setLoading] = useState(false);
12
- const [isLoading, startTransition] = useTransition();
13
- const [sheetType, setSheetType] = useState(SHEET.Default);
14
22
  const sheet = useRef(null);
15
- const _ref = useRef(null);
16
- const _nodes = (query) => _ref.current.querySelectorAll(query);
17
- const _validate = (el) => {
23
+ const innerRef = useRef(null);
24
+ /**
25
+ * Utility function to select multiple DOM elements within the form based on a CSS query.
26
+ * @param query - CSS selector to match elements inside the form.
27
+ */
28
+ const _nodes = useCallback((query) => {
29
+ if (innerRef.current)
30
+ return innerRef.current.querySelectorAll(query);
31
+ return [];
32
+ }, [innerRef.current]);
33
+ /**
34
+ * Validates form fields based on their type and custom attributes.
35
+ *
36
+ * @param el - The element to validate.
37
+ * @returns Whether the element meets the required validation criteria.
38
+ */
39
+ const _validate = useCallback((el) => {
18
40
  if (el.required) {
41
+ /**
42
+ * @internal
43
+ * Required field validation */
19
44
  if (el.type == `checkbox` && el.checked == false) {
20
45
  return false;
21
46
  }
@@ -25,6 +50,10 @@ const Form = forwardRef((props, ref) => {
25
50
  if (el.value == ``)
26
51
  return false;
27
52
  }
53
+ /**
54
+ * @internal
55
+ * Additional validation based on `with` attribute
56
+ */
28
57
  if (el.getAttribute(`with`)) {
29
58
  let _with = el.getAttribute(`with`);
30
59
  if (_with.includes(`@`)) {
@@ -50,7 +79,7 @@ const Form = forwardRef((props, ref) => {
50
79
  const _el = document.querySelector(`[name=${field.trim()}]`);
51
80
  if (!_el)
52
81
  return false;
53
- console.log(`matching`, _el.name, _el.value, el.name, el.value);
82
+ // console.log(`matching`, _el.name, _el.value, el.name, el.value)
54
83
  if (_el && _el.value != el.value) {
55
84
  return false;
56
85
  }
@@ -60,8 +89,13 @@ const Form = forwardRef((props, ref) => {
60
89
  }
61
90
  }
62
91
  return true;
63
- };
64
- const _buildFormData = () => {
92
+ }, [innerRef.current]);
93
+ /**
94
+ * Constructs the form data and validates the fields.
95
+ *
96
+ * @returns Form data object along with validation status and error information.
97
+ */
98
+ const _buildFormData = useCallback(() => {
65
99
  const data = {};
66
100
  const payload = {};
67
101
  let _error = null;
@@ -93,13 +127,17 @@ const Form = forwardRef((props, ref) => {
93
127
  errorMsg: _errorMsg || `Fix errors to continue...`,
94
128
  data, payload
95
129
  };
96
- };
97
- const _onSubmit = () => {
130
+ }, [innerRef.current]);
131
+ /**
132
+ * Handler for form submission that validates and processes the form data.
133
+ */
134
+ const _onSubmit = useCallback(() => {
98
135
  const { error, errorMsg, payload } = _buildFormData();
99
136
  if (error) {
100
137
  sheet.current.show(errorMsg, 4, SHEET.Error);
101
138
  }
102
139
  else if (action) {
140
+ // If `action` is defined, submit the form data to the specified endpoint
103
141
  startTransition(async () => {
104
142
  setLoading(true);
105
143
  sheet.current.hide();
@@ -125,18 +163,21 @@ const Form = forwardRef((props, ref) => {
125
163
  else {
126
164
  onSubmit && onSubmit(payload);
127
165
  }
128
- };
129
- const _init = () => {
166
+ }, [action, sheet.current, innerRef.current]);
167
+ /**
168
+ * Initializes the form by adding click event listeners to submit buttons.
169
+ */
170
+ const _init = useCallback(() => {
130
171
  const _submit = _nodes(`[type=submit]`);
131
172
  if (!_submit || _submit.length == 0) {
132
- console.error(`You should add at least 1 button with type=\`SUBMIT\``);
173
+ console.warn(`You should add at least 1 button with type=\`SUBMIT\``);
133
174
  }
134
175
  else {
135
176
  _submit.forEach(el => {
136
177
  el.addEventListener(`click`, _onSubmit);
137
178
  });
138
179
  }
139
- };
180
+ }, [innerRef.current]);
140
181
  useImperativeHandle(ref, () => ({
141
182
  setLoading(mod) {
142
183
  if (mod) {
@@ -152,6 +193,11 @@ const Form = forwardRef((props, ref) => {
152
193
  }
153
194
  }));
154
195
  useEffect(_init, []);
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] });
196
+ return _jsxs(Box, { ...{
197
+ className: `${className} rel --form${name ? `-${name.replace(/\s+/g, `-`)}` : ``}`,
198
+ style,
199
+ propsToRemove: [`withData`, `action`, `onSubmit`, `onSuccess`, `onError`],
200
+ ...rest
201
+ }, ref: innerRef, 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] });
156
202
  });
157
203
  export default Form;
@@ -7,4 +7,17 @@ const Heading = forwardRef((props, ref) => {
7
7
  props.html ? _jsx("span", { ...({ dangerouslySetInnerHTML: { __html: html } }) }) : props.children
8
8
  : null });
9
9
  });
10
+ // import { Ref } from "react"
11
+ // import { css, cleanProps } from "../funs";
12
+ // import { UIProps } from "../types/interfaces";
13
+ // const Heading = ( props: UIProps<HTMLHeadingElement> ) => {
14
+ // const { children, ref, h, html } = props
15
+ // let Tag : string = `h${h || 1}`;
16
+ // const HeadingTag = Tag as `h1` | `h2` | `h3` | `h4` | `h5` | `h6`
17
+ // const { cx } = css.Build(props.as)
18
+ // return <HeadingTag
19
+ // ref={ref}
20
+ // className={cx.join(` `)}
21
+ // {...(cleanProps(props) as UIProps<HTMLHeadingElement>)}>{props.html ? <span { ...({dangerouslySetInnerHTML:{ __html: html }}) as UIProps<HTMLSpanElement>} /> : children}</HeadingTag>
22
+ // }
10
23
  export default Heading;
@@ -1,7 +1,6 @@
1
- import { animationProps } from "./base";
2
- declare const Icon: import("react").ForwardRefExoticComponent<{
1
+ import { Props } from "./useBase/base.types";
2
+ export interface IconProps extends Props<`div`> {
3
3
  name: string;
4
- as?: string;
5
- animate?: animationProps;
6
- } & Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & import("react").RefAttributes<HTMLDivElement>>;
4
+ }
5
+ declare const Icon: import("react").ForwardRefExoticComponent<IconProps & import("react").RefAttributes<HTMLDivElement>>;
7
6
  export default Icon;
@@ -1,8 +1,20 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { forwardRef } from "react";
3
- import With from "./base";
3
+ // import With, { Props } from "./base";
4
+ import Box from "./box";
5
+ import useBase from "./useBase";
4
6
  const Icon = forwardRef((props, ref) => {
5
- const { as, name, ...rest } = props;
6
- return _jsx(With, { className: `icon-${name}`, as: as, ...rest, ref: ref });
7
+ const { name, ...pops } = props;
8
+ const { className, style, rest } = useBase(pops);
9
+ return _jsx(Box, { ...{
10
+ className: `${className} icon-${name}`,
11
+ style,
12
+ ...rest
13
+ } });
14
+ // return <With
15
+ // className={`icon-${name}`}
16
+ // as={as}
17
+ // {...rest}
18
+ // ref={ref} />
7
19
  });
8
20
  export default Icon;
@@ -1,5 +1,5 @@
1
- import { animationProps } from "./base";
2
1
  import React from "react";
2
+ import { animationProps } from "../types/interfaces";
3
3
  interface ImageProps {
4
4
  width: string | number;
5
5
  height: string | number;