@zuzjs/ui 0.5.5 → 0.5.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/dist/bin.js +8 -2
  2. package/dist/comps/accordion.js +2 -5
  3. package/dist/comps/box.d.ts +4 -1
  4. package/dist/comps/box.js +6 -9
  5. package/dist/comps/button.d.ts +1 -0
  6. package/dist/comps/button.js +4 -2
  7. package/dist/comps/form.d.ts +4 -0
  8. package/dist/comps/form.js +54 -11
  9. package/dist/comps/grid/index.d.ts +10 -0
  10. package/dist/comps/grid/index.js +16 -0
  11. package/dist/comps/heading.d.ts +4 -3
  12. package/dist/comps/heading.js +12 -19
  13. package/dist/comps/icon.d.ts +1 -0
  14. package/dist/comps/icon.js +5 -2
  15. package/dist/comps/input.d.ts +4 -1
  16. package/dist/comps/input.js +14 -4
  17. package/dist/comps/otp/index.d.ts +6 -0
  18. package/dist/comps/otp/index.js +50 -0
  19. package/dist/comps/search/index.d.ts +7 -0
  20. package/dist/comps/search/index.js +46 -0
  21. package/dist/comps/segmented/index.d.ts +46 -0
  22. package/dist/comps/segmented/index.js +59 -0
  23. package/dist/comps/segmented/item.d.ts +8 -0
  24. package/dist/comps/segmented/item.js +26 -0
  25. package/dist/comps/select/index.d.ts +15 -0
  26. package/dist/comps/select/index.js +79 -0
  27. package/dist/comps/select/select.d.ts +0 -0
  28. package/dist/comps/select/select.js +1 -0
  29. package/dist/comps/sheet.d.ts +1 -0
  30. package/dist/comps/sheet.js +27 -0
  31. package/dist/comps/span.d.ts +6 -0
  32. package/dist/comps/span.js +12 -0
  33. package/dist/comps/svgicons.d.ts +3 -0
  34. package/dist/comps/svgicons.js +8 -0
  35. package/dist/comps/useBase/base.types.d.ts +21 -5
  36. package/dist/funs/css.d.ts +3 -1
  37. package/dist/funs/css.js +55 -14
  38. package/dist/funs/events.d.ts +4 -2
  39. package/dist/funs/events.js +7 -7
  40. package/dist/funs/index.d.ts +5 -0
  41. package/dist/funs/index.js +34 -0
  42. package/dist/funs/stylesheet.js +1 -1
  43. package/dist/hooks/index.d.ts +1 -0
  44. package/dist/hooks/index.js +1 -0
  45. package/dist/hooks/useDB.d.ts +25 -0
  46. package/dist/hooks/useDB.js +101 -0
  47. package/dist/hooks/useIntersectionObserver.d.ts +1 -1
  48. package/dist/hooks/useIntersectionObserver.js +28 -11
  49. package/dist/index.d.ts +7 -2
  50. package/dist/index.js +8 -2
  51. package/dist/styles.css +1 -1
  52. package/dist/types/interfaces.d.ts +26 -1
  53. package/package.json +1 -1
  54. package/dist/comps/select.d.ts +0 -19
  55. package/dist/comps/select.js +0 -56
package/dist/bin.js CHANGED
@@ -10,7 +10,13 @@ program
10
10
  .option(`-d, --debug`)
11
11
  .option(`-v, --version`)
12
12
  .option(`-root, --root <char>`)
13
- .option(`-f, --file <char>`);
13
+ .option(`-f, --file <char>`)
14
+ .option(`-lx, --lexer`)
15
+ .option(`-cx, --classes`)
16
+ .option(`-ch, --cache`)
17
+ .option(`-cl, --cleaned`)
18
+ .option(`-sh, --sheet`)
19
+ .option(`-mq, --media`);
14
20
  program.parse();
15
21
  const options = program.opts();
16
22
  // extendGlobals()
@@ -92,7 +98,7 @@ const rebuild = (f) => {
92
98
  };
93
99
  const rebuildAll = () => {
94
100
  console.log(pc.gray(`○ Building Zuz CSS`));
95
- const cssBuilder = new CSS();
101
+ const cssBuilder = new CSS({}, options);
96
102
  const files = getAllFiles(process.cwd(), `.jsx`);
97
103
  if (files.length > 0) {
98
104
  const as = [];
@@ -1,13 +1,10 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { forwardRef, useState } from "react";
3
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
- };
4
+ import SVGIcons from "./svgicons";
8
5
  const Accordion = forwardRef((props, ref) => {
9
6
  const { title, message, ...rest } = props;
10
7
  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 })] });
8
+ 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 ? SVGIcons.ArrowUp : SVGIcons.ArrowDown })] }), visible && _jsx(With, { className: `--detail`, children: message })] });
12
9
  });
13
10
  export default Accordion;
@@ -1,3 +1,6 @@
1
1
  import { Props } from "./useBase/base.types";
2
- declare const Box: import("react").ForwardRefExoticComponent<Props<"div"> & import("react").RefAttributes<HTMLDivElement>>;
2
+ export interface BoxProps extends Props<'div'> {
3
+ name?: string;
4
+ }
5
+ declare const Box: import("react").ForwardRefExoticComponent<BoxProps & import("react").RefAttributes<HTMLDivElement>>;
3
6
  export default Box;
package/dist/comps/box.js CHANGED
@@ -2,14 +2,11 @@ import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { forwardRef } from "react";
3
3
  import useBase from "./useBase";
4
4
  const Box = forwardRef((props, ref) => {
5
- const { className, style, rest } = useBase(props);
6
- return _jsx("div", { ref: ref, className: className, style: style, ...rest });
5
+ const { style, ...pops } = props;
6
+ const { className, style: _style, rest } = useBase(pops);
7
+ return _jsx("div", { ref: ref, className: className, style: {
8
+ ..._style,
9
+ ...(style || {})
10
+ }, ...rest });
7
11
  });
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
- // });
15
12
  export default Box;
@@ -1,6 +1,7 @@
1
1
  import { Props } from "./useBase/base.types";
2
2
  export interface ButtonProps extends Props<`button`> {
3
3
  icon?: string;
4
+ withLabel?: boolean;
4
5
  }
5
6
  declare const Button: import("react").ForwardRefExoticComponent<ButtonProps & import("react").RefAttributes<HTMLButtonElement>>;
6
7
  export default Button;
@@ -3,9 +3,11 @@ import { forwardRef } from "react";
3
3
  // import With, { Props } from "./base";
4
4
  import useBase from "./useBase";
5
5
  const Button = forwardRef((props, ref) => {
6
- const { icon, children, ...pops } = props;
6
+ const { icon, children, withLabel, ...pops } = props;
7
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 })] });
8
+ return _jsxs("button", { className: `${className} flex aic ${icon ? `ico-btn` : ``}`, style: style, ref: ref, ...rest, children: [icon && _jsx("div", { ...{ className: `icon-${icon}` } }), undefined == withLabel || withLabel == true ?
9
+ _jsx("span", { ...{ className: `b-label` }, children: children })
10
+ : children] });
9
11
  });
10
12
  // const Button = forwardRef<HTMLButtonElement, ButtonProps>((props, ref ) => {
11
13
  // const { as, icon, ...rest } = props;
@@ -18,6 +18,8 @@ export interface FormProps extends Props<`div`> {
18
18
  spinner?: SpinnerProps;
19
19
  /** Additional data to include with form submission */
20
20
  withData?: dynamicObject;
21
+ /** Handler function called before form submission with validated form data */
22
+ beforeSubmit?: (data: FormData | dynamicObject) => void;
21
23
  /** Handler function called on form submission with validated form data */
22
24
  onSubmit?: (data: FormData | dynamicObject) => void;
23
25
  /** Callback triggered upon successful form submission */
@@ -40,6 +42,8 @@ export interface FormHandler {
40
42
  setLoading: (mode: boolean) => void;
41
43
  /** Hides any currently displayed error message */
42
44
  hideError: () => void;
45
+ /** Resets the form to its initial state */
46
+ init: () => void;
43
47
  }
44
48
  /**
45
49
  * {@link Form} is a controlled component designed to handle form data submission, validation, and display of loading or error states.
@@ -16,7 +16,7 @@ import { isEmail, withPost } from "../funs";
16
16
  * @param ref - Reference to the {@link FormHandler} interface, exposing methods to control loading and error states from the parent.
17
17
  */
18
18
  const Form = forwardRef((props, ref) => {
19
- const { name, cover, spinner, errors, action, children, withData, onSubmit, onError, onSuccess, ...pops } = props;
19
+ const { name, cover, spinner, errors, action, children, withData, beforeSubmit, onSubmit, onError, onSuccess, ...pops } = props;
20
20
  const { className, style, rest } = useBase(pops);
21
21
  const [loading, setLoading] = useState(false);
22
22
  const sheet = useRef(null);
@@ -30,6 +30,21 @@ const Form = forwardRef((props, ref) => {
30
30
  return innerRef.current.querySelectorAll(query);
31
31
  return [];
32
32
  }, [innerRef.current]);
33
+ const _getFields = (el) => {
34
+ return {
35
+ name: el.name || el.getAttribute(`name`) || el.getAttribute(`data-name`),
36
+ required: el.required ? true
37
+ : el.getAttribute(`data-required`) ? el.getAttribute(`data-required`) == `true` : false,
38
+ with: el.with || el.getAttribute(`with`)
39
+ };
40
+ };
41
+ const _getPinValue = (el) => {
42
+ const _pin = [];
43
+ el.querySelectorAll(`.--input`).forEach((input) => {
44
+ _pin.push(input.value);
45
+ });
46
+ return _pin.join('');
47
+ };
33
48
  /**
34
49
  * Validates form fields based on their type and custom attributes.
35
50
  *
@@ -37,13 +52,20 @@ const Form = forwardRef((props, ref) => {
37
52
  * @returns Whether the element meets the required validation criteria.
38
53
  */
39
54
  const _validate = useCallback((el) => {
40
- if (el.required) {
55
+ const { name: _name, required: _required, with: _with } = _getFields(el);
56
+ if (_required) {
41
57
  /**
42
58
  * @internal
43
59
  * Required field validation */
44
60
  if (el.type == `checkbox` && el.checked == false) {
45
61
  return false;
46
62
  }
63
+ if (el.classList.contains(`--otp`)) {
64
+ const _pin = _getPinValue(el);
65
+ if (_pin == `` || _pin.length < parseInt(el.getAttribute(`data-size`))) {
66
+ return false;
67
+ }
68
+ }
47
69
  if (el.classList.contains(`--select`) && el.dataset.value == `-1`) {
48
70
  return false;
49
71
  }
@@ -102,26 +124,41 @@ const Form = forwardRef((props, ref) => {
102
124
  let _errorMsg = null;
103
125
  Array.from(_nodes(`[name]`))
104
126
  .forEach((el) => {
127
+ const { name: _name, required: _required, with: _with } = _getFields(el);
105
128
  let valid = true;
106
- if (el.required || el.with)
129
+ if (_required || _with)
107
130
  valid = _validate(el);
108
- data[el.name] = {
131
+ data[_name] = {
109
132
  valid: valid,
110
- value: el.classList.contains(`--select`) ? el.dataset.value : el.value
133
+ value: el.classList.contains(`--otp`) ? _getPinValue(el)
134
+ : el.classList.contains(`--select`) ? el.dataset.value : el.value
111
135
  };
112
- payload[el.name] = el.classList.contains(`--select`) ? el.dataset.value : el.value;
136
+ payload[_name] = el.classList.contains(`--otp`) ? _getPinValue(el)
137
+ : el.classList.contains(`--select`) ? el.dataset.value : el.value;
113
138
  if (!valid) {
114
139
  if (_error == null && errors) {
115
140
  _error = el;
116
- _errorMsg = errors[el.name];
141
+ _errorMsg = errors[_name];
117
142
  }
118
143
  el.classList.add(`input-with-error`);
119
144
  }
120
145
  else
121
146
  el.classList.remove(`input-with-error`);
122
147
  });
123
- if (_error)
124
- _error.focus();
148
+ if (_error) {
149
+ const _nxt = _error;
150
+ if (_nxt.classList.contains(`--otp`)) {
151
+ for (const i of Array.from(_nxt.querySelectorAll(`.--input`))) {
152
+ const input = i;
153
+ if (input.value == ``) {
154
+ input.focus();
155
+ break;
156
+ }
157
+ }
158
+ }
159
+ else
160
+ _nxt.focus();
161
+ }
125
162
  return {
126
163
  error: _error != null,
127
164
  errorMsg: _errorMsg || `Fix errors to continue...`,
@@ -139,6 +176,7 @@ const Form = forwardRef((props, ref) => {
139
176
  else if (action) {
140
177
  // If `action` is defined, submit the form data to the specified endpoint
141
178
  startTransition(async () => {
179
+ beforeSubmit && beforeSubmit(payload);
142
180
  setLoading(true);
143
181
  sheet.current.hide();
144
182
  withPost(action, { ...payload, ...(withData || {}) })
@@ -147,11 +185,13 @@ const Form = forwardRef((props, ref) => {
147
185
  setLoading(false);
148
186
  if (onSuccess)
149
187
  onSuccess(resp);
150
- else
188
+ else {
151
189
  sheet.current.hide();
152
- sheet.current.show(resp.message || `Redirecting..`, 4, SHEET.Success);
190
+ sheet.current.show(resp.message || `Redirecting..`, 4, SHEET.Success);
191
+ }
153
192
  })
154
193
  .catch(err => {
194
+ console.warn(`Error occurred while submitting form`, err);
155
195
  setLoading(false);
156
196
  if (onError)
157
197
  onError(err);
@@ -190,6 +230,9 @@ const Form = forwardRef((props, ref) => {
190
230
  },
191
231
  hideError() {
192
232
  sheet.current.hide();
233
+ },
234
+ init() {
235
+ _init();
193
236
  }
194
237
  }));
195
238
  useEffect(_init, []);
@@ -0,0 +1,10 @@
1
+ import { Props } from "../useBase/base.types";
2
+ export declare enum GRID {
3
+ Default = 0
4
+ }
5
+ declare const Grid: import("react").ForwardRefExoticComponent<Props<"div"> & {
6
+ rows?: number;
7
+ cols?: number;
8
+ gap?: number;
9
+ } & import("react").RefAttributes<HTMLInputElement>>;
10
+ export default Grid;
@@ -0,0 +1,16 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { forwardRef } from "react";
3
+ import Box from "../box";
4
+ import useBase from "../useBase";
5
+ export var GRID;
6
+ (function (GRID) {
7
+ GRID[GRID["Default"] = 0] = "Default";
8
+ })(GRID || (GRID = {}));
9
+ const Grid = forwardRef((props, ref) => {
10
+ const { animate, children, rows, cols, gap, ...pops } = props;
11
+ const { className, style } = useBase(props);
12
+ return _jsx(Box, { style: style, ...{
13
+ className: `--grid grid ${className}`.trim()
14
+ }, children: children });
15
+ });
16
+ export default Grid;
@@ -1,7 +1,8 @@
1
1
  import { ReactNode } from "react";
2
- import { BaseProps } from "../types/interfaces";
3
- declare const Heading: import("react").ForwardRefExoticComponent<{
2
+ import { Props } from "./useBase/base.types";
3
+ export interface HeadingProps extends Props<"h1" | "h2" | "h3" | "h4" | "h5" | "h6"> {
4
4
  h?: number | string;
5
5
  html?: ReactNode | string;
6
- } & BaseProps & Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLHeadingElement>, HTMLHeadingElement>, "ref"> & import("react").RefAttributes<HTMLDivElement>>;
6
+ }
7
+ declare const Heading: import("react").ForwardRefExoticComponent<HeadingProps & import("react").RefAttributes<HTMLHeadingElement>>;
7
8
  export default Heading;
@@ -1,23 +1,16 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import { forwardRef } from "react";
3
- import With from "./base";
2
+ import { createElement, forwardRef } from "react";
3
+ import useBase from "./useBase";
4
4
  const Heading = forwardRef((props, ref) => {
5
- const { as, h, html, ...rest } = props;
6
- return _jsx(With, { tag: `h${h || 1}`, as: as, ref: ref, ...rest, children: props.children ?
7
- props.html ? _jsx("span", { ...({ dangerouslySetInnerHTML: { __html: html } }) }) : props.children
8
- : null });
5
+ const { h, html, children, ...pops } = props;
6
+ const { className, style, rest } = useBase(pops);
7
+ const Tag = `h${h || 1}`;
8
+ return createElement(Tag, {
9
+ ref,
10
+ style,
11
+ className,
12
+ ...rest,
13
+ children: html ? _jsx("span", { ...{ dangerouslySetInnerHTML: { __html: html } } }) : children
14
+ });
9
15
  });
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
- // }
23
16
  export default Heading;
@@ -1,6 +1,7 @@
1
1
  import { Props } from "./useBase/base.types";
2
2
  export interface IconProps extends Props<`div`> {
3
3
  name: string;
4
+ pathCount?: number;
4
5
  }
5
6
  declare const Icon: import("react").ForwardRefExoticComponent<IconProps & import("react").RefAttributes<HTMLDivElement>>;
6
7
  export default Icon;
@@ -3,14 +3,17 @@ import { forwardRef } from "react";
3
3
  // import With, { Props } from "./base";
4
4
  import Box from "./box";
5
5
  import useBase from "./useBase";
6
+ import Span from "./span";
6
7
  const Icon = forwardRef((props, ref) => {
7
- const { name, ...pops } = props;
8
+ const { name, pathCount, ...pops } = props;
8
9
  const { className, style, rest } = useBase(pops);
9
10
  return _jsx(Box, { ...{
10
11
  className: `${className} icon-${name}`,
11
12
  style,
12
13
  ...rest
13
- } });
14
+ }, children: Array(pathCount || 0).fill(0).map((p, i) => _jsx(Span, { ...{
15
+ className: `path${i + 1}`
16
+ } }, `${name}-layer-${i}`)) });
14
17
  // return <With
15
18
  // className={`icon-${name}`}
16
19
  // as={as}
@@ -1,3 +1,6 @@
1
1
  import { Props } from "./useBase/base.types";
2
- declare const Input: import("react").ForwardRefExoticComponent<Props<"input"> & import("react").RefAttributes<HTMLInputElement>>;
2
+ export interface InputProps extends Props<`input`> {
3
+ numeric?: boolean;
4
+ }
5
+ declare const Input: import("react").ForwardRefExoticComponent<InputProps & import("react").RefAttributes<HTMLInputElement>>;
3
6
  export default Input;
@@ -1,9 +1,19 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import { forwardRef, useRef } from "react";
2
+ import { forwardRef, useEffect } from "react";
3
3
  import useBase from "./useBase";
4
4
  const Input = forwardRef((props, ref) => {
5
- const _innerRef = useRef(null);
6
- const { className, style, rest } = useBase(props);
7
- return _jsx("input", { className: className, style: style, ref: _innerRef, ...rest });
5
+ /**
6
+ * @internal
7
+ * const _innerRef = useRef<HTMLInputElement>(null)
8
+ */
9
+ const { numeric, ...pops } = props;
10
+ const handleInput = (event) => {
11
+ if (numeric) {
12
+ event.currentTarget.value = event.currentTarget.value.replace(/[^0-9.]/g, '').replace(/(\..*?)\..*/g, '$1');
13
+ }
14
+ };
15
+ const { className, style, rest } = useBase(pops);
16
+ useEffect(() => { }, []);
17
+ return _jsx("input", { className: `${className} --input`, style: style, ref: ref, onInput: handleInput, ...rest });
8
18
  });
9
19
  export default Input;
@@ -0,0 +1,6 @@
1
+ import { Props } from "../useBase/base.types";
2
+ declare const OTP: import("react").ForwardRefExoticComponent<Props<"input"> & {
3
+ mask?: boolean;
4
+ size?: number;
5
+ } & import("react").RefAttributes<HTMLInputElement>>;
6
+ export default OTP;
@@ -0,0 +1,50 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { forwardRef, useEffect, useRef } from "react";
3
+ import Input from "../input";
4
+ import Box from "../box";
5
+ import useBase from "../useBase";
6
+ const OTP = forwardRef((props, ref) => {
7
+ const { animate, size, mask, ...pops } = props;
8
+ const { style } = useBase(props);
9
+ const inputs = useRef([]);
10
+ let name = `pinput`;
11
+ let required = false;
12
+ if (`type` in pops) {
13
+ delete pops.type;
14
+ }
15
+ if (`name` in pops) {
16
+ name = pops.name;
17
+ delete pops.name;
18
+ }
19
+ if (`required` in pops) {
20
+ required = true;
21
+ delete pops.required;
22
+ }
23
+ const handleInput = (event) => {
24
+ const input = event.currentTarget;
25
+ const nextInput = inputs.current[parseInt(input.dataset.index) + 1];
26
+ const prevInput = inputs.current[parseInt(input.dataset.index) - 1];
27
+ if (input.value.length === 1 && nextInput) {
28
+ nextInput.focus();
29
+ }
30
+ else if (input.value.length === 0 && prevInput) {
31
+ prevInput.focus();
32
+ }
33
+ };
34
+ useEffect(() => {
35
+ inputs.current = inputs.current.slice(0, size);
36
+ }, [size]);
37
+ return _jsx(Box, { ...{ name }, "data-required": required, "data-size": size || 4, style: style, ...{
38
+ className: `--otp flex aic rel`
39
+ }, children: Array(size || 4).fill(1).map((a, i) => _jsx(Input, { "data-index": i, ref: (el) => {
40
+ inputs.current[i] = el;
41
+ }, ...{
42
+ numeric: true,
43
+ onChange: handleInput,
44
+ maxLength: 1,
45
+ placeholder: `0`,
46
+ type: mask ? `password` : 'text',
47
+ ...pops
48
+ } }, `pin-${i}`)) });
49
+ });
50
+ export default OTP;
@@ -0,0 +1,7 @@
1
+ import { Props } from "../useBase/base.types";
2
+ declare const Search: import("react").ForwardRefExoticComponent<Props<"input"> & {
3
+ onSubmit?: (value: string) => void;
4
+ onChange?: (value: string) => void;
5
+ withStyle?: string;
6
+ } & import("react").RefAttributes<HTMLInputElement>>;
7
+ export default Search;
@@ -0,0 +1,46 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { forwardRef, useEffect, useRef, useState } from "react";
3
+ import Input from "../input";
4
+ import Box from "../box";
5
+ import Button from "../button";
6
+ import useBase from "../useBase";
7
+ import SVGIcons from "../svgicons";
8
+ const Search = forwardRef((props, ref) => {
9
+ const { animate, withStyle, onChange, ...pops } = props;
10
+ const { style } = useBase(pops);
11
+ const { className: searchStyle } = useBase({ as: withStyle || `` });
12
+ const [query, setQuery] = useState(``);
13
+ const innerRef = useRef(null);
14
+ if (`type` in props) {
15
+ delete props[`type`];
16
+ }
17
+ const handleChange = (e) => {
18
+ setQuery(e.target.value);
19
+ onChange?.(e.target.value);
20
+ };
21
+ const handleSubmit = (e) => {
22
+ e.preventDefault();
23
+ if (query.trim() !== ``) {
24
+ setQuery(``);
25
+ onChange?.(``);
26
+ if (innerRef.current) {
27
+ innerRef.current.value = ``;
28
+ }
29
+ }
30
+ // onSubmit?.(query)
31
+ };
32
+ useEffect(() => { }, []);
33
+ return _jsxs(Box, { style: style, ...{
34
+ className: `--search flex aic rel ${searchStyle}`.trim()
35
+ }, children: [_jsx(Input, { ...{
36
+ ref: innerRef,
37
+ onChange: handleChange,
38
+ ...pops
39
+ } }), _jsx(Button, { ...{
40
+ withLabel: false,
41
+ tabIndex: -1,
42
+ onClick: handleSubmit,
43
+ className: `--send flex aic jcc abs`
44
+ }, children: query !== `` ? SVGIcons.Close : SVGIcons.Search })] });
45
+ });
46
+ export default Search;
@@ -0,0 +1,46 @@
1
+ import { Props } from "../useBase/base.types";
2
+ /**
3
+ * Individual segment in the `SelectTabs` component.
4
+ * @typedef {Object} Segment
5
+ * @property {number} index - The index of the segment.
6
+ * @property {string} [icon] - The optional icon to display for the segment.
7
+ * @property {string} [label] - The optional label to display for the segment.
8
+ */
9
+ export interface Segment {
10
+ tag?: string;
11
+ index: number;
12
+ icon?: string;
13
+ label?: string;
14
+ }
15
+ /**
16
+ * Props for the `SelectTabs` component.
17
+ * @typedef {Object} SegmentProps
18
+ * @extends {Props<'div'>}
19
+ * @property {number} [selected] - The index of the initially selected segment.
20
+ * @property {Segment[]} items - Array of segments to display.
21
+ */
22
+ export interface SegmentProps extends Props<`div`> {
23
+ selected?: number;
24
+ onSwitch?: (segment: Segment) => void;
25
+ items: Segment[];
26
+ }
27
+ /**
28
+ * `SelectTabs` component is a segmented control that allows switching between segments.
29
+ *
30
+ * @component
31
+ * @param {SegmentProps} props - Props for the segmented control component.
32
+ * @param {React.Ref<HTMLDivElement>} ref - Ref for the root div element.
33
+ * @returns {JSX.Element} The rendered segmented control.
34
+ *
35
+ * @example
36
+ * // Usage example
37
+ * const segments = [
38
+ * { index: 0, label: "Home", icon: "home_icon" },
39
+ * { index: 1, label: "Profile", icon: "profile_icon" },
40
+ * { index: 2, label: "Settings", icon: "settings_icon" }
41
+ * ];
42
+ *
43
+ * <SelectTabs selected={1} items={segments} />
44
+ */
45
+ declare const Segmented: import("react").ForwardRefExoticComponent<SegmentProps & import("react").RefAttributes<HTMLDivElement>>;
46
+ export default Segmented;
@@ -0,0 +1,59 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { forwardRef, useEffect, useRef, useState } from "react";
3
+ import useBase from "../useBase";
4
+ import Box from "../box";
5
+ import SegmentItem from "./item";
6
+ /**
7
+ * `SelectTabs` component is a segmented control that allows switching between segments.
8
+ *
9
+ * @component
10
+ * @param {SegmentProps} props - Props for the segmented control component.
11
+ * @param {React.Ref<HTMLDivElement>} ref - Ref for the root div element.
12
+ * @returns {JSX.Element} The rendered segmented control.
13
+ *
14
+ * @example
15
+ * // Usage example
16
+ * const segments = [
17
+ * { index: 0, label: "Home", icon: "home_icon" },
18
+ * { index: 1, label: "Profile", icon: "profile_icon" },
19
+ * { index: 2, label: "Settings", icon: "settings_icon" }
20
+ * ];
21
+ *
22
+ * <SelectTabs selected={1} items={segments} />
23
+ */
24
+ const Segmented = forwardRef((props, ref) => {
25
+ const { animate, items, selected, onSwitch, ...pops } = props;
26
+ const [_selected, setSelected] = useState(selected || 0);
27
+ const { className, style, rest } = useBase(pops);
28
+ const _tab = useRef(null);
29
+ const _segmented = useRef(null);
30
+ /**
31
+ * Handles selection of a segment.
32
+ *
33
+ * @param {number} index - The index of the selected segment.
34
+ * @param {number} width - The width of the selected segment.
35
+ * @param {number} x - The x-coordinate of the selected segment.
36
+ */
37
+ const handleSelect = (index, width, x, meta) => {
38
+ setSelected(index);
39
+ if (_tab.current) {
40
+ const _sp = _segmented.current?.getBoundingClientRect();
41
+ _tab.current.style.setProperty(`--w`, `${width}px`);
42
+ _tab.current.style.setProperty(`--x`, `${_sp ? x - _sp.left : x}px`);
43
+ if (onSwitch)
44
+ onSwitch(meta);
45
+ }
46
+ };
47
+ useEffect(() => { }, []);
48
+ return _jsxs(Box, { ref: _segmented, ...{
49
+ className: `${className} --segmented flex aic rel`,
50
+ style,
51
+ ...rest
52
+ }, children: [_jsx(Box, { ref: _tab, ...{
53
+ className: `--segment-tab abs`,
54
+ } }), items.map((item, i) => _jsx(SegmentItem, { onSelect: handleSelect, selected: _selected == i, meta: {
55
+ ...item,
56
+ index: i
57
+ } }, `segment-${item.label}-${i}`))] });
58
+ });
59
+ export default Segmented;
@@ -0,0 +1,8 @@
1
+ import { Segment } from ".";
2
+ interface SegmentItemProps {
3
+ meta: Segment;
4
+ selected: boolean;
5
+ onSelect: (index: number, width: number, x: number, segment: Segment) => void;
6
+ }
7
+ declare const SegmentItem: ({ onSelect, meta, selected }: SegmentItemProps) => import("react/jsx-runtime").JSX.Element;
8
+ export default SegmentItem;
@@ -0,0 +1,26 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useEffect, useRef, useState } from "react";
3
+ import Box from "../box";
4
+ import Button from "../button";
5
+ const SegmentItem = ({ onSelect, meta, selected }) => {
6
+ const ref = useRef(null);
7
+ const { index, icon, label } = meta;
8
+ const [pos, setPos] = useState({ x: 0, width: 0 });
9
+ useEffect(() => {
10
+ if (ref.current) {
11
+ const { width, x } = ref.current.getBoundingClientRect();
12
+ setPos({ x, width });
13
+ }
14
+ if (selected) {
15
+ onSelect(index, pos.width, pos.x, meta);
16
+ }
17
+ }, [ref.current]);
18
+ return _jsxs(Button, { onClick: () => onSelect(index, pos.width, pos.x, meta), ref: ref, ...{
19
+ className: `--segment-item flex aic rel ${selected ? `--segement-active` : ``}`.trim(),
20
+ }, children: [icon && _jsx(Box, { ...{
21
+ className: `--segment-icon icon-${icon}`
22
+ } }), _jsx(Box, { ...{
23
+ className: `--segment-label`
24
+ }, children: label || `Item ${index}` })] });
25
+ };
26
+ export default SegmentItem;