chesai-ui 0.16.4 → 0.16.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.
@@ -1,55 +1,87 @@
1
- import { jsx as e, jsxs as o } from "react/jsx-runtime";
2
- import { X as E } from "lucide-react";
3
- import { forwardRef as L, useMemo as g } from "react";
4
- import { useInput as N } from "./use-input.mjs";
5
- const y = L((P, f) => {
1
+ import { jsx as e, jsxs as l } from "react/jsx-runtime";
2
+ import { X as H, EyeOff as L, Eye as O } from "lucide-react";
3
+ import R, { forwardRef as S, useMemo as v } from "react";
4
+ import { useInput as V } from "./use-input.mjs";
5
+ const _ = S((P, C) => {
6
6
  const {
7
- Component: C,
8
- label: s,
9
- description: r,
7
+ Component: I,
8
+ value: a,
9
+ label: i,
10
+ description: n,
10
11
  isClearable: p,
11
- startContent: b,
12
- endContent: n,
13
- shouldLabelBeOutside: l,
14
- errorMessage: t,
15
- isInvalid: i,
16
- getBaseProps: I,
17
- getLabelProps: v,
18
- getInputProps: W,
19
- getInnerWrapperProps: w,
20
- getInputWrapperProps: x,
21
- getHelperWrapperProps: a,
22
- getDescriptionProps: d,
23
- getErrorMessageProps: u,
24
- getClearButtonProps: c
25
- } = N({ ...P, ref: f }), h = s ? /* @__PURE__ */ e("label", { ...v(), children: s }) : null, B = g(() => p ? /* @__PURE__ */ e("button", { ...c(), children: n || /* @__PURE__ */ e(E, { className: "h-4 w-4" }) }) : n, [p, c, n]), M = g(() => {
26
- const m = i && t;
27
- return m || r ? /* @__PURE__ */ e("div", { ...a(), children: m ? /* @__PURE__ */ e("div", { ...u(), children: t }) : /* @__PURE__ */ e("div", { ...d(), children: r }) }) : null;
12
+ startContent: y,
13
+ endContent: s,
14
+ shouldLabelBeOutside: c,
15
+ errorMessage: o,
16
+ isInvalid: d,
17
+ // Dynamic password toggle context fetched from hook
18
+ originalType: u,
19
+ isPasswordVisible: t,
20
+ setIsPasswordVisible: h,
21
+ getBaseProps: x,
22
+ getLabelProps: N,
23
+ getInputProps: E,
24
+ getInnerWrapperProps: W,
25
+ getInputWrapperProps: B,
26
+ getHelperWrapperProps: m,
27
+ getDescriptionProps: f,
28
+ getErrorMessageProps: g,
29
+ getClearButtonProps: b
30
+ } = V({ ...P, ref: C }), w = i ? /* @__PURE__ */ e("label", { ...N(), children: i }) : null, M = v(() => {
31
+ const r = [];
32
+ return p && a && r.push(
33
+ /* @__PURE__ */ e("button", { ...b(), children: /* @__PURE__ */ e(H, { className: "h-4 w-4" }) }, "clear")
34
+ ), u === "password" && r.push(
35
+ /* @__PURE__ */ e(
36
+ "button",
37
+ {
38
+ type: "button",
39
+ onClick: () => h(!t),
40
+ "aria-label": t ? "Hide password" : "Show password",
41
+ className: "p-2 -m-2 z-10 select-none transition-opacity text-on-surface-variant hover:text-on-surface cursor-pointer active:opacity-70 rounded-full",
42
+ children: t ? /* @__PURE__ */ e(L, { className: "h-4 w-4" }) : /* @__PURE__ */ e(O, { className: "h-4 w-4" })
43
+ },
44
+ "password-toggle"
45
+ )
46
+ ), s && r.push(
47
+ /* @__PURE__ */ e(R.Fragment, { children: s }, "custom-end")
48
+ ), r.length === 0 ? null : /* @__PURE__ */ e("div", { className: "flex items-center gap-2 shrink-0", children: r });
28
49
  }, [
29
- i,
30
- t,
31
- r,
50
+ p,
32
51
  a,
33
52
  u,
34
- d
35
- ]), j = /* @__PURE__ */ o("div", { ...w(), children: [
53
+ t,
54
+ h,
36
55
  b,
37
- /* @__PURE__ */ e("input", { ...W() }),
38
- B
56
+ s
57
+ ]), j = v(() => {
58
+ const r = d && o;
59
+ return r || n ? /* @__PURE__ */ e("div", { ...m(), children: r ? /* @__PURE__ */ e("div", { ...g(), children: o }) : /* @__PURE__ */ e("div", { ...f(), children: n }) }) : null;
60
+ }, [
61
+ d,
62
+ o,
63
+ n,
64
+ m,
65
+ g,
66
+ f
67
+ ]), k = /* @__PURE__ */ l("div", { ...W(), children: [
68
+ y,
69
+ /* @__PURE__ */ e("input", { ...E() }),
70
+ M
39
71
  ] });
40
72
  return (
41
73
  // @ts-ignore
42
- /* @__PURE__ */ o(C, { ...I(), children: [
43
- l ? h : null,
44
- /* @__PURE__ */ o("div", { ...x(), children: [
45
- l ? null : h,
46
- j
74
+ /* @__PURE__ */ l(I, { ...x(), children: [
75
+ c ? w : null,
76
+ /* @__PURE__ */ l("div", { ...B(), children: [
77
+ c ? null : w,
78
+ k
47
79
  ] }),
48
- M
80
+ j
49
81
  ] })
50
82
  );
51
83
  });
52
- y.displayName = "Input";
84
+ _.displayName = "Input";
53
85
  export {
54
- y as Input
86
+ _ as Input
55
87
  };
@@ -23,6 +23,7 @@ export interface UseInputProps extends Omit<React.InputHTMLAttributes<HTMLInputE
23
23
  export declare function useInput(props: UseInputProps): {
24
24
  Component: React.ElementType<any, keyof React.JSX.IntrinsicElements>;
25
25
  domRef: React.RefObject<HTMLInputElement | null>;
26
+ value: string | number | readonly string[];
26
27
  label: React.ReactNode;
27
28
  description: React.ReactNode;
28
29
  isClearable: boolean;
@@ -34,6 +35,9 @@ export declare function useInput(props: UseInputProps): {
34
35
  shouldLabelBeOutside: boolean;
35
36
  errorMessage: React.ReactNode;
36
37
  isInvalid: boolean;
38
+ originalType: React.HTMLInputTypeAttribute | undefined;
39
+ isPasswordVisible: boolean;
40
+ setIsPasswordVisible: React.Dispatch<React.SetStateAction<boolean>>;
37
41
  getBaseProps: () => {
38
42
  'data-slot': string;
39
43
  'data-filled': boolean;
@@ -62,7 +66,6 @@ export declare function useInput(props: UseInputProps): {
62
66
  formNoValidate?: boolean | undefined | undefined;
63
67
  formTarget?: string | undefined | undefined;
64
68
  name?: string | undefined | undefined;
65
- type?: React.HTMLInputTypeAttribute | undefined;
66
69
  defaultChecked?: boolean | undefined | undefined;
67
70
  suppressContentEditableWarning?: boolean | undefined | undefined;
68
71
  suppressHydrationWarning?: boolean | undefined | undefined;
@@ -358,6 +361,7 @@ export declare function useInput(props: UseInputProps): {
358
361
  disabled: boolean | undefined;
359
362
  readOnly: boolean | undefined;
360
363
  value: string | number | readonly string[];
364
+ type: string | (string & {}) | undefined;
361
365
  onChange: (e: React.ChangeEvent<HTMLInputElement>) => void;
362
366
  };
363
367
  getInputWrapperProps: () => {
@@ -1,100 +1,109 @@
1
1
  import { clsx as t } from "clsx";
2
- import T, { useRef as j, useState as I, useCallback as N } from "react";
3
- import { getInputSlotClassNames as q, inputSlots as a, inputStyles as A } from "./input-styles.mjs";
4
- function re(B) {
2
+ import A, { useRef as G, useState as m, useCallback as w } from "react";
3
+ import { getInputSlotClassNames as J, inputSlots as a, inputStyles as K } from "./input-styles.mjs";
4
+ function ne(B) {
5
5
  const {
6
- ref: y,
6
+ ref: V,
7
7
  as: S = "div",
8
- label: d,
9
- description: w,
10
- errorMessage: L,
11
- className: M,
8
+ type: i,
9
+ // Destructured here to handle dynamic input state switches
10
+ label: f,
11
+ description: L,
12
+ errorMessage: M,
13
+ className: E,
12
14
  classNames: e,
13
- variant: V = "filled",
14
- color: G = "primary",
15
- size: E = "md",
16
- shape: F = "minimal",
15
+ variant: F = "filled",
16
+ color: Q = "primary",
17
+ size: O = "md",
18
+ shape: k = "minimal",
17
19
  labelPlacement: s = "inside",
18
- startContent: g,
19
- endContent: O,
20
- isClearable: k = !1,
21
- isInvalid: i = !1,
22
- placeholder: H,
23
- onClear: m,
24
- onValueChange: o,
25
- onChange: f,
26
- value: b,
27
- defaultValue: R,
28
- readOnly: P,
29
- disabled: C,
30
- ...x
31
- } = B, r = j(null), [p, h] = I(!1), [D, v] = I(R || ""), n = b !== void 0, W = n ? b : D, u = !!W || p;
32
- T.useImperativeHandle(y, () => r.current);
33
- const _ = N(() => {
34
- n || v(""), r.current && (r.current.value = "", r.current.focus()), m?.(), o?.("");
20
+ startContent: b,
21
+ endContent: x,
22
+ isClearable: H = !1,
23
+ isInvalid: u = !1,
24
+ placeholder: R,
25
+ onClear: P,
26
+ onValueChange: n,
27
+ onChange: C,
28
+ value: h,
29
+ defaultValue: D,
30
+ readOnly: v,
31
+ disabled: I,
32
+ ...T
33
+ } = B, r = G(null), [p, W] = m(!1), [_, N] = m(D || ""), [y, z] = m(!1), o = h !== void 0, c = o ? h : _, d = !!c || p;
34
+ A.useImperativeHandle(V, () => r.current);
35
+ const j = w(() => {
36
+ o || N(""), r.current && (r.current.value = "", r.current.focus()), P?.(), n?.("");
35
37
  const l = new Event("input", { bubbles: !0 });
36
38
  r.current?.dispatchEvent(l);
37
- }, [n, m, o]), z = N(
39
+ }, [o, P, n]), q = w(
38
40
  (l) => {
39
- n || v(l.target.value), f?.(l), o?.(l.target.value);
41
+ o || N(l.target.value), C?.(l), n?.(l.target.value);
40
42
  },
41
- [n, f, o]
42
- ), c = q({
43
- variant: V,
44
- size: E,
45
- shape: F,
43
+ [o, C, n]
44
+ ), g = J({
45
+ variant: F,
46
+ size: O,
47
+ shape: k,
46
48
  labelPlacement: s,
47
- isInvalid: i,
48
- isFilled: u,
49
- hasStartContent: !!g,
50
- hasLabel: !!d
49
+ isInvalid: u,
50
+ isFilled: d,
51
+ hasStartContent: !!b,
52
+ hasLabel: !!f
51
53
  });
52
54
  return {
53
55
  Component: S,
54
56
  domRef: r,
55
- label: d,
56
- description: w,
57
- isClearable: k,
58
- startContent: g,
59
- endContent: O,
57
+ value: c,
58
+ label: f,
59
+ description: L,
60
+ isClearable: H,
61
+ startContent: b,
62
+ endContent: x,
60
63
  labelPlacement: s,
61
64
  isOutsideLeft: s === "outside-left",
62
65
  isOutsideTop: s === "outside",
63
66
  shouldLabelBeOutside: s === "outside" || s === "outside-left",
64
- errorMessage: L,
65
- isInvalid: i,
67
+ errorMessage: M,
68
+ isInvalid: u,
69
+ // Exported properties to manage password visibility inside the UI render
70
+ originalType: i,
71
+ isPasswordVisible: y,
72
+ setIsPasswordVisible: z,
66
73
  getBaseProps: () => ({
67
74
  "data-slot": "base",
68
- "data-filled": u,
69
- "data-filled-within": u || p,
75
+ "data-filled": d,
76
+ "data-filled-within": d || p,
70
77
  "data-focus": p,
71
- "data-invalid": i,
72
- "data-disabled": C,
73
- "data-readonly": P,
78
+ "data-invalid": u,
79
+ "data-disabled": I,
80
+ "data-readonly": v,
74
81
  "data-label-placement": s,
75
- className: t(a.base, A({ labelPlacement: s }), M, e?.base)
82
+ className: t(a.base, K({ labelPlacement: s }), E, e?.base)
76
83
  }),
77
84
  getLabelProps: () => ({
78
85
  "data-slot": "label",
79
- className: t(a.label, c.label, e?.label)
86
+ className: t(a.label, g.label, e?.label)
80
87
  }),
81
88
  getInputProps: () => ({
82
89
  ref: r,
83
90
  "data-slot": "input",
84
- className: t(a.input, c.input, e?.input),
85
- placeholder: H,
86
- disabled: C,
87
- readOnly: P,
88
- value: W,
89
- onChange: z,
90
- onFocus: () => h(!0),
91
- onBlur: () => h(!1),
92
- ...x
91
+ className: t(a.input, g.input, e?.input),
92
+ placeholder: R,
93
+ disabled: I,
94
+ readOnly: v,
95
+ value: c,
96
+ // Evaluate type dynamically depending on visibility status if type is 'password'
97
+ type: i === "password" ? y ? "text" : "password" : i,
98
+ onChange: q,
99
+ onFocus: () => W(!0),
100
+ onBlur: () => W(!1),
101
+ ...T
93
102
  }),
94
103
  getInputWrapperProps: () => ({
95
104
  "data-slot": "input-wrapper",
96
105
  "data-focus": p,
97
- className: t(a.inputWrapper, c.inputWrapper, e?.inputWrapper),
106
+ className: t(a.inputWrapper, g.inputWrapper, e?.inputWrapper),
98
107
  onClick: () => {
99
108
  r.current?.focus();
100
109
  }
@@ -118,11 +127,11 @@ function re(B) {
118
127
  getClearButtonProps: () => ({
119
128
  "data-slot": "clear-button",
120
129
  type: "button",
121
- onClick: _,
130
+ onClick: j,
122
131
  className: t(a.clearButton, e?.clearButton)
123
132
  })
124
133
  };
125
134
  }
126
135
  export {
127
- re as useInput
136
+ ne as useInput
128
137
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "chesai-ui",
3
3
  "private": false,
4
- "version": "0.16.4",
4
+ "version": "0.16.5",
5
5
  "packageManager": "pnpm@10.12.1",
6
6
  "repository": {
7
7
  "type": "git",