asterui 0.12.1 → 0.12.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/Checkbox.d.ts +10 -0
- package/dist/components/Dock.d.ts +38 -0
- package/dist/components/Mask.d.ts +14 -0
- package/dist/index.d.ts +5 -1
- package/dist/index.js +173 -169
- package/dist/index.js.map +1 -1
- package/dist/index10.js +85 -59
- package/dist/index10.js.map +1 -1
- package/dist/index100.js +12 -7
- package/dist/index100.js.map +1 -1
- package/dist/index101.js +13 -11
- package/dist/index101.js.map +1 -1
- package/dist/index102.js +7 -30
- package/dist/index102.js.map +1 -1
- package/dist/index103.js +11 -16
- package/dist/index103.js.map +1 -1
- package/dist/index104.js +30 -10792
- package/dist/index104.js.map +1 -1
- package/dist/index105.js +18 -5
- package/dist/index105.js.map +1 -1
- package/dist/index15.js +3 -3
- package/dist/index21.js +1 -1
- package/dist/index24.js +43 -32
- package/dist/index24.js.map +1 -1
- package/dist/index25.js +32 -41
- package/dist/index25.js.map +1 -1
- package/dist/index26.js +41 -12
- package/dist/index26.js.map +1 -1
- package/dist/index27.js +12 -33
- package/dist/index27.js.map +1 -1
- package/dist/index28.js +33 -63
- package/dist/index28.js.map +1 -1
- package/dist/index29.js +60 -77
- package/dist/index29.js.map +1 -1
- package/dist/index30.js +80 -18
- package/dist/index30.js.map +1 -1
- package/dist/index31.js +15 -217
- package/dist/index31.js.map +1 -1
- package/dist/index32.js +216 -1078
- package/dist/index32.js.map +1 -1
- package/dist/index33.js +1081 -17
- package/dist/index33.js.map +1 -1
- package/dist/index34.js +17 -121
- package/dist/index34.js.map +1 -1
- package/dist/index35.js +119 -37
- package/dist/index35.js.map +1 -1
- package/dist/index36.js +31 -182
- package/dist/index36.js.map +1 -1
- package/dist/index37.js +191 -97
- package/dist/index37.js.map +1 -1
- package/dist/index38.js +93 -158
- package/dist/index38.js.map +1 -1
- package/dist/index39.js +155 -139
- package/dist/index39.js.map +1 -1
- package/dist/index40.js +146 -15
- package/dist/index40.js.map +1 -1
- package/dist/index41.js +14 -17
- package/dist/index41.js.map +1 -1
- package/dist/index42.js +18 -21
- package/dist/index42.js.map +1 -1
- package/dist/index43.js +18 -116
- package/dist/index43.js.map +1 -1
- package/dist/index44.js +116 -10
- package/dist/index44.js.map +1 -1
- package/dist/index45.js +13 -35
- package/dist/index45.js.map +1 -1
- package/dist/index46.js +33 -114
- package/dist/index46.js.map +1 -1
- package/dist/index47.js +10 -176
- package/dist/index47.js.map +1 -1
- package/dist/index48.js +114 -145
- package/dist/index48.js.map +1 -1
- package/dist/index49.js +176 -12
- package/dist/index49.js.map +1 -1
- package/dist/index50.js +146 -21
- package/dist/index50.js.map +1 -1
- package/dist/index51.js +12 -14
- package/dist/index51.js.map +1 -1
- package/dist/index52.js +20 -5
- package/dist/index52.js.map +1 -1
- package/dist/index53.js +14 -266
- package/dist/index53.js.map +1 -1
- package/dist/index54.js +7 -17
- package/dist/index54.js.map +1 -1
- package/dist/index55.js +257 -113
- package/dist/index55.js.map +1 -1
- package/dist/index56.js +17 -110
- package/dist/index56.js.map +1 -1
- package/dist/index57.js +121 -169
- package/dist/index57.js.map +1 -1
- package/dist/index58.js +110 -32
- package/dist/index58.js.map +1 -1
- package/dist/index59.js +163 -115
- package/dist/index59.js.map +1 -1
- package/dist/index60.js +30 -84
- package/dist/index60.js.map +1 -1
- package/dist/index61.js +121 -19
- package/dist/index61.js.map +1 -1
- package/dist/index62.js +81 -69
- package/dist/index62.js.map +1 -1
- package/dist/index63.js +19 -56
- package/dist/index63.js.map +1 -1
- package/dist/index64.js +72 -43
- package/dist/index64.js.map +1 -1
- package/dist/index65.js +54 -49
- package/dist/index65.js.map +1 -1
- package/dist/index66.js +41 -58
- package/dist/index66.js.map +1 -1
- package/dist/index67.js +50 -105
- package/dist/index67.js.map +1 -1
- package/dist/index68.js +62 -41
- package/dist/index68.js.map +1 -1
- package/dist/index69.js +99 -60
- package/dist/index69.js.map +1 -1
- package/dist/index70.js +41 -21
- package/dist/index70.js.map +1 -1
- package/dist/index71.js +66 -44
- package/dist/index71.js.map +1 -1
- package/dist/index72.js +19 -132
- package/dist/index72.js.map +1 -1
- package/dist/index73.js +40 -46
- package/dist/index73.js.map +1 -1
- package/dist/index74.js +134 -22
- package/dist/index74.js.map +1 -1
- package/dist/index75.js +50 -29
- package/dist/index75.js.map +1 -1
- package/dist/index76.js +19 -19
- package/dist/index76.js.map +1 -1
- package/dist/index77.js +31 -329
- package/dist/index77.js.map +1 -1
- package/dist/index78.js +19 -53
- package/dist/index78.js.map +1 -1
- package/dist/index79.js +328 -39
- package/dist/index79.js.map +1 -1
- package/dist/index80.js +56 -23
- package/dist/index80.js.map +1 -1
- package/dist/index81.js +40 -95
- package/dist/index81.js.map +1 -1
- package/dist/index82.js +22 -129
- package/dist/index82.js.map +1 -1
- package/dist/index83.js +86 -152
- package/dist/index83.js.map +1 -1
- package/dist/index84.js +125 -60
- package/dist/index84.js.map +1 -1
- package/dist/index85.js +160 -34
- package/dist/index85.js.map +1 -1
- package/dist/index86.js +65 -234
- package/dist/index86.js.map +1 -1
- package/dist/index87.js +35 -34
- package/dist/index87.js.map +1 -1
- package/dist/index88.js +222 -198
- package/dist/index88.js.map +1 -1
- package/dist/index89.js +34 -213
- package/dist/index89.js.map +1 -1
- package/dist/index90.js +190 -275
- package/dist/index90.js.map +1 -1
- package/dist/index91.js +202 -167
- package/dist/index91.js.map +1 -1
- package/dist/index92.js +263 -226
- package/dist/index92.js.map +1 -1
- package/dist/index93.js +176 -12
- package/dist/index93.js.map +1 -1
- package/dist/index94.js +257 -32
- package/dist/index94.js.map +1 -1
- package/dist/index95.js +13 -5
- package/dist/index95.js.map +1 -1
- package/dist/index96.js +31 -12
- package/dist/index96.js.map +1 -1
- package/dist/index97.js +5 -45
- package/dist/index97.js.map +1 -1
- package/dist/index98.js +13 -12
- package/dist/index98.js.map +1 -1
- package/dist/index99.js +44 -13
- package/dist/index99.js.map +1 -1
- package/package.json +11 -4
- package/dist/index106.js +0 -45
- package/dist/index106.js.map +0 -1
- package/dist/index107.js +0 -5
- package/dist/index107.js.map +0 -1
- package/dist/index108.js +0 -10
- package/dist/index108.js.map +0 -1
- package/dist/index109.js +0 -155
- package/dist/index109.js.map +0 -1
- package/dist/index110.js +0 -33
- package/dist/index110.js.map +0 -1
- package/dist/index111.js +0 -33
- package/dist/index111.js.map +0 -1
- package/dist/index112.js +0 -5
- package/dist/index112.js.map +0 -1
- package/dist/index113.js +0 -75
- package/dist/index113.js.map +0 -1
- package/dist/index114.js +0 -42
- package/dist/index114.js.map +0 -1
- package/dist/index115.js +0 -29
- package/dist/index115.js.map +0 -1
- package/dist/index116.js +0 -24
- package/dist/index116.js.map +0 -1
- package/dist/index117.js +0 -27
- package/dist/index117.js.map +0 -1
- package/dist/index118.js +0 -23
- package/dist/index118.js.map +0 -1
- package/dist/index119.js +0 -103
- package/dist/index119.js.map +0 -1
- package/dist/index120.js +0 -363
- package/dist/index120.js.map +0 -1
- package/dist/index121.js +0 -28
- package/dist/index121.js.map +0 -1
- package/dist/index122.js +0 -76
- package/dist/index122.js.map +0 -1
- package/dist/index123.js +0 -19
- package/dist/index123.js.map +0 -1
- package/dist/index124.js +0 -69
- package/dist/index124.js.map +0 -1
- package/dist/index125.js +0 -147
- package/dist/index125.js.map +0 -1
- package/dist/index126.js +0 -5
- package/dist/index126.js.map +0 -1
- package/dist/index127.js +0 -59
- package/dist/index127.js.map +0 -1
- package/dist/index128.js +0 -5
- package/dist/index128.js.map +0 -1
- package/dist/index129.js +0 -5
- package/dist/index129.js.map +0 -1
- package/dist/index130.js +0 -5
- package/dist/index130.js.map +0 -1
- package/dist/index131.js +0 -5
- package/dist/index131.js.map +0 -1
- package/dist/index132.js +0 -5
- package/dist/index132.js.map +0 -1
- package/dist/index133.js +0 -5
- package/dist/index133.js.map +0 -1
- package/dist/index134.js +0 -5
- package/dist/index134.js.map +0 -1
- package/dist/index135.js +0 -5
- package/dist/index135.js.map +0 -1
- package/dist/index136.js +0 -35
- package/dist/index136.js.map +0 -1
- package/dist/index137.js +0 -5
- package/dist/index137.js.map +0 -1
- package/dist/index138.js +0 -11
- package/dist/index138.js.map +0 -1
- package/dist/index139.js +0 -5
- package/dist/index139.js.map +0 -1
- package/dist/index140.js +0 -5
- package/dist/index140.js.map +0 -1
- package/dist/index141.js +0 -24
- package/dist/index141.js.map +0 -1
- package/dist/index142.js +0 -5
- package/dist/index142.js.map +0 -1
- package/dist/index143.js +0 -27
- package/dist/index143.js.map +0 -1
- package/dist/index144.js +0 -74
- package/dist/index144.js.map +0 -1
- package/dist/index145.js +0 -24
- package/dist/index145.js.map +0 -1
- package/dist/index146.js +0 -37
- package/dist/index146.js.map +0 -1
- package/dist/index147.js +0 -73
- package/dist/index147.js.map +0 -1
- package/dist/index148.js +0 -5
- package/dist/index148.js.map +0 -1
- package/dist/index149.js +0 -25
- package/dist/index149.js.map +0 -1
- package/dist/index150.js +0 -5
- package/dist/index150.js.map +0 -1
- package/dist/index151.js +0 -5
- package/dist/index151.js.map +0 -1
- package/dist/index152.js +0 -5
- package/dist/index152.js.map +0 -1
- package/dist/index153.js +0 -5
- package/dist/index153.js.map +0 -1
- package/dist/index154.js +0 -7
- package/dist/index154.js.map +0 -1
package/dist/index10.js
CHANGED
|
@@ -1,51 +1,52 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
const
|
|
4
|
-
function
|
|
5
|
-
children:
|
|
6
|
-
value:
|
|
7
|
-
defaultValue:
|
|
1
|
+
import { jsxs as f, jsx as c } from "react/jsx-runtime";
|
|
2
|
+
import R, { forwardRef as G, useContext as B, createContext as I } from "react";
|
|
3
|
+
const y = I(null);
|
|
4
|
+
function P({
|
|
5
|
+
children: h,
|
|
6
|
+
value: l,
|
|
7
|
+
defaultValue: d,
|
|
8
8
|
onChange: o,
|
|
9
|
-
disabled:
|
|
10
|
-
options:
|
|
11
|
-
className:
|
|
9
|
+
disabled: n = !1,
|
|
10
|
+
options: r,
|
|
11
|
+
className: s = ""
|
|
12
12
|
}) {
|
|
13
|
-
const [
|
|
14
|
-
value:
|
|
15
|
-
onChange: (e,
|
|
16
|
-
const
|
|
17
|
-
|
|
13
|
+
const [x, k] = R.useState(d || []), i = l !== void 0 ? l : x, a = {
|
|
14
|
+
value: i,
|
|
15
|
+
onChange: (e, m) => {
|
|
16
|
+
const b = m ? [...i, e] : i.filter((C) => C !== e);
|
|
17
|
+
l === void 0 && k(b), o?.(b);
|
|
18
18
|
},
|
|
19
|
-
disabled:
|
|
19
|
+
disabled: n
|
|
20
20
|
};
|
|
21
|
-
return
|
|
22
|
-
/* @__PURE__ */
|
|
23
|
-
/* @__PURE__ */
|
|
24
|
-
] }, e) : /* @__PURE__ */
|
|
25
|
-
/* @__PURE__ */
|
|
26
|
-
/* @__PURE__ */
|
|
27
|
-
] }, e.value)) }) }) : /* @__PURE__ */
|
|
21
|
+
return r ? /* @__PURE__ */ c(y.Provider, { value: a, children: /* @__PURE__ */ c("div", { className: s, children: r.map((e) => typeof e == "string" || typeof e == "number" ? /* @__PURE__ */ f("label", { className: "label cursor-pointer justify-start gap-2", children: [
|
|
22
|
+
/* @__PURE__ */ c(u, { value: e }),
|
|
23
|
+
/* @__PURE__ */ c("span", { className: "label-text", children: e })
|
|
24
|
+
] }, e) : /* @__PURE__ */ f("label", { className: "label cursor-pointer justify-start gap-2", children: [
|
|
25
|
+
/* @__PURE__ */ c(u, { value: e.value, disabled: e.disabled }),
|
|
26
|
+
/* @__PURE__ */ c("span", { className: "label-text", children: e.label })
|
|
27
|
+
] }, e.value)) }) }) : /* @__PURE__ */ c(y.Provider, { value: a, children: /* @__PURE__ */ c("div", { className: s, children: h }) });
|
|
28
28
|
}
|
|
29
|
-
const u =
|
|
29
|
+
const u = G(
|
|
30
30
|
({
|
|
31
|
-
children:
|
|
32
|
-
size:
|
|
33
|
-
color:
|
|
31
|
+
children: h,
|
|
32
|
+
size: l,
|
|
33
|
+
color: d,
|
|
34
34
|
indeterminate: o = !1,
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
swap: n,
|
|
36
|
+
className: r = "",
|
|
37
|
+
value: s,
|
|
38
|
+
checked: x,
|
|
38
39
|
onChange: k,
|
|
39
|
-
disabled:
|
|
40
|
-
...
|
|
41
|
-
},
|
|
42
|
-
const
|
|
40
|
+
disabled: i,
|
|
41
|
+
...p
|
|
42
|
+
}, a) => {
|
|
43
|
+
const e = B(y), m = {
|
|
43
44
|
xs: "checkbox-xs",
|
|
44
45
|
sm: "checkbox-sm",
|
|
45
46
|
md: "checkbox-md",
|
|
46
47
|
lg: "checkbox-lg",
|
|
47
48
|
xl: "checkbox-xl"
|
|
48
|
-
},
|
|
49
|
+
}, b = {
|
|
49
50
|
primary: "checkbox-primary",
|
|
50
51
|
secondary: "checkbox-secondary",
|
|
51
52
|
accent: "checkbox-accent",
|
|
@@ -54,42 +55,67 @@ const u = R(
|
|
|
54
55
|
warning: "checkbox-warning",
|
|
55
56
|
info: "checkbox-info",
|
|
56
57
|
error: "checkbox-error"
|
|
57
|
-
},
|
|
58
|
+
}, C = [
|
|
58
59
|
"checkbox",
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
].filter(Boolean).join(" "),
|
|
62
|
-
|
|
63
|
-
},
|
|
64
|
-
(
|
|
65
|
-
|
|
60
|
+
l && m[l],
|
|
61
|
+
d && b[d]
|
|
62
|
+
].filter(Boolean).join(" "), g = e && s !== void 0 && (typeof s == "string" || typeof s == "number") ? e.value?.includes(s) ?? !1 : x, N = e?.disabled || i, j = (t) => {
|
|
63
|
+
e && s !== void 0 && (typeof s == "string" || typeof s == "number") && e.onChange?.(s, t.target.checked), k?.(t);
|
|
64
|
+
}, V = R.useCallback(
|
|
65
|
+
(t) => {
|
|
66
|
+
t && (t.indeterminate = o), typeof a == "function" ? a(t) : a && (a.current = t);
|
|
66
67
|
},
|
|
67
|
-
[o,
|
|
68
|
-
),
|
|
68
|
+
[o, a]
|
|
69
|
+
), v = o ? "indeterminate" : g ? "checked" : "unchecked";
|
|
70
|
+
if (n) {
|
|
71
|
+
const t = [
|
|
72
|
+
"swap",
|
|
73
|
+
n.effect === "rotate" && "swap-rotate",
|
|
74
|
+
n.effect === "flip" && "swap-flip",
|
|
75
|
+
r
|
|
76
|
+
].filter(Boolean).join(" ");
|
|
77
|
+
return /* @__PURE__ */ f("label", { className: t, children: [
|
|
78
|
+
/* @__PURE__ */ c(
|
|
79
|
+
"input",
|
|
80
|
+
{
|
|
81
|
+
ref: a,
|
|
82
|
+
type: "checkbox",
|
|
83
|
+
checked: g,
|
|
84
|
+
onChange: j,
|
|
85
|
+
disabled: N,
|
|
86
|
+
"data-state": v,
|
|
87
|
+
...p
|
|
88
|
+
}
|
|
89
|
+
),
|
|
90
|
+
/* @__PURE__ */ c("div", { className: "swap-on", children: n.on }),
|
|
91
|
+
/* @__PURE__ */ c("div", { className: "swap-off", children: n.off })
|
|
92
|
+
] });
|
|
93
|
+
}
|
|
94
|
+
const w = /* @__PURE__ */ c(
|
|
69
95
|
"input",
|
|
70
96
|
{
|
|
71
|
-
ref:
|
|
97
|
+
ref: V,
|
|
72
98
|
type: "checkbox",
|
|
73
|
-
className:
|
|
74
|
-
value:
|
|
75
|
-
checked:
|
|
76
|
-
onChange:
|
|
99
|
+
className: C,
|
|
100
|
+
value: s,
|
|
101
|
+
checked: g,
|
|
102
|
+
onChange: j,
|
|
77
103
|
disabled: N,
|
|
78
|
-
"data-state":
|
|
79
|
-
...
|
|
104
|
+
"data-state": v,
|
|
105
|
+
...p
|
|
80
106
|
}
|
|
81
107
|
);
|
|
82
|
-
return
|
|
83
|
-
|
|
84
|
-
/* @__PURE__ */
|
|
85
|
-
] }) :
|
|
108
|
+
return h ? /* @__PURE__ */ f("label", { className: `label cursor-pointer justify-start gap-2 ${r}`, children: [
|
|
109
|
+
w,
|
|
110
|
+
/* @__PURE__ */ c("span", { className: "label-text", children: h })
|
|
111
|
+
] }) : w;
|
|
86
112
|
}
|
|
87
113
|
);
|
|
88
114
|
u.displayName = "Checkbox";
|
|
89
|
-
const
|
|
90
|
-
Group:
|
|
115
|
+
const O = Object.assign(u, {
|
|
116
|
+
Group: P
|
|
91
117
|
});
|
|
92
118
|
export {
|
|
93
|
-
|
|
119
|
+
O as Checkbox
|
|
94
120
|
};
|
|
95
121
|
//# sourceMappingURL=index10.js.map
|
package/dist/index10.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index10.js","sources":["../src/components/Checkbox.tsx"],"sourcesContent":["import React, { forwardRef, createContext, useContext } from 'react'\n\nexport interface CheckboxProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, 'size' | 'type'> {\n children?: React.ReactNode\n size?: 'xs' | 'sm' | 'md' | 'lg' | 'xl'\n color?: 'primary' | 'secondary' | 'accent' | 'neutral' | 'success' | 'warning' | 'info' | 'error'\n indeterminate?: boolean\n className?: string\n}\n\nexport interface CheckboxOptionType {\n label: React.ReactNode\n value: string | number\n disabled?: boolean\n}\n\nexport interface CheckboxGroupProps {\n children?: React.ReactNode\n value?: (string | number)[]\n defaultValue?: (string | number)[]\n onChange?: (values: (string | number)[]) => void\n disabled?: boolean\n options?: (string | number | CheckboxOptionType)[]\n className?: string\n}\n\ninterface CheckboxGroupContextValue {\n value?: (string | number)[]\n onChange?: (checkedValue: string | number, checked: boolean) => void\n disabled?: boolean\n}\n\nconst CheckboxGroupContext = createContext<CheckboxGroupContextValue | null>(null)\n\nfunction CheckboxGroup({\n children,\n value,\n defaultValue,\n onChange,\n disabled = false,\n options,\n className = ''\n}: CheckboxGroupProps) {\n const [internalValue, setInternalValue] = React.useState<(string | number)[]>(defaultValue || [])\n const currentValue = value !== undefined ? value : internalValue\n\n const handleChange = (checkedValue: string | number, checked: boolean) => {\n const newValue = checked\n ? [...currentValue, checkedValue]\n : currentValue.filter((v) => v !== checkedValue)\n\n if (value === undefined) {\n setInternalValue(newValue)\n }\n onChange?.(newValue)\n }\n\n const contextValue: CheckboxGroupContextValue = {\n value: currentValue,\n onChange: handleChange,\n disabled,\n }\n\n // If options are provided, render checkboxes automatically\n if (options) {\n return (\n <CheckboxGroupContext.Provider value={contextValue}>\n <div className={className}>\n {options.map((option) => {\n if (typeof option === 'string' || typeof option === 'number') {\n return (\n <label key={option} className=\"label cursor-pointer justify-start gap-2\">\n <CheckboxRoot value={option} />\n <span className=\"label-text\">{option}</span>\n </label>\n )\n } else {\n return (\n <label key={option.value} className=\"label cursor-pointer justify-start gap-2\">\n <CheckboxRoot value={option.value} disabled={option.disabled} />\n <span className=\"label-text\">{option.label}</span>\n </label>\n )\n }\n })}\n </div>\n </CheckboxGroupContext.Provider>\n )\n }\n\n return (\n <CheckboxGroupContext.Provider value={contextValue}>\n <div className={className}>{children}</div>\n </CheckboxGroupContext.Provider>\n )\n}\n\nconst CheckboxRoot = forwardRef<HTMLInputElement, CheckboxProps>(\n (\n {\n children,\n size,\n color,\n indeterminate = false,\n className = '',\n value,\n checked,\n onChange,\n disabled: disabledProp,\n ...props\n },\n ref\n ) => {\n const groupContext = useContext(CheckboxGroupContext)\n\n const sizeClasses = {\n xs: 'checkbox-xs',\n sm: 'checkbox-sm',\n md: 'checkbox-md',\n lg: 'checkbox-lg',\n xl: 'checkbox-xl',\n }\n\n const colorClasses = {\n primary: 'checkbox-primary',\n secondary: 'checkbox-secondary',\n accent: 'checkbox-accent',\n neutral: 'checkbox-neutral',\n success: 'checkbox-success',\n warning: 'checkbox-warning',\n info: 'checkbox-info',\n error: 'checkbox-error',\n }\n\n const checkboxClasses = [\n 'checkbox',\n size && sizeClasses[size],\n color && colorClasses[color],\n ]\n .filter(Boolean)\n .join(' ')\n\n // If in a group, use group's value to determine checked state\n const isChecked = groupContext && value !== undefined && (typeof value === 'string' || typeof value === 'number')\n ? groupContext.value?.includes(value) ?? false\n : checked\n\n const isDisabled = groupContext?.disabled || disabledProp\n\n const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {\n if (groupContext && value !== undefined && (typeof value === 'string' || typeof value === 'number')) {\n groupContext.onChange?.(value, e.target.checked)\n }\n onChange?.(e)\n }\n\n // Handle indeterminate state\n const checkboxRef = React.useCallback(\n (node: HTMLInputElement | null) => {\n if (node) {\n node.indeterminate = indeterminate\n }\n if (typeof ref === 'function') {\n ref(node)\n } else if (ref) {\n ref.current = node\n }\n },\n [indeterminate, ref]\n )\n\n const dataState = indeterminate ? 'indeterminate' : isChecked ? 'checked' : 'unchecked'\n\n const checkboxInput = (\n <input\n ref={checkboxRef}\n type=\"checkbox\"\n className={checkboxClasses}\n value={value}\n checked={isChecked}\n onChange={handleChange}\n disabled={isDisabled}\n data-state={dataState}\n {...props}\n />\n )\n\n // If children provided, wrap in label\n if (children) {\n return (\n <label className={`label cursor-pointer justify-start gap-2 ${className}`}>\n {checkboxInput}\n <span className=\"label-text\">{children}</span>\n </label>\n )\n }\n\n return checkboxInput\n }\n)\n\nCheckboxRoot.displayName = 'Checkbox'\n\nexport const Checkbox = Object.assign(CheckboxRoot, {\n Group: CheckboxGroup,\n})\n"],"names":["CheckboxGroupContext","createContext","CheckboxGroup","children","value","defaultValue","onChange","disabled","options","className","internalValue","setInternalValue","React","currentValue","contextValue","checkedValue","checked","newValue","v","jsx","option","jsxs","CheckboxRoot","forwardRef","size","color","indeterminate","disabledProp","props","ref","groupContext","useContext","sizeClasses","colorClasses","checkboxClasses","isChecked","isDisabled","handleChange","e","checkboxRef","node","checkboxInput","Checkbox"],"mappings":";;AAgCA,MAAMA,IAAuBC,EAAgD,IAAI;AAEjF,SAASC,EAAc;AAAA,EACrB,UAAAC;AAAA,EACA,OAAAC;AAAA,EACA,cAAAC;AAAA,EACA,UAAAC;AAAA,EACA,UAAAC,IAAW;AAAA,EACX,SAAAC;AAAA,EACA,WAAAC,IAAY;AACd,GAAuB;AACrB,QAAM,CAACC,GAAeC,CAAgB,IAAIC,EAAM,SAA8BP,KAAgB,EAAE,GAC1FQ,IAAeT,MAAU,SAAYA,IAAQM,GAa7CI,IAA0C;AAAA,IAC9C,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;AAAA,QACV,cAXcV,IAAgB,kBAAkBS,IAAY,YAAY;AAAA,QAYvE,GAAGP;AAAA,MAAA;AAAA,IAAA;AAKR,WAAIzB,IAEA,gBAAAkB,EAAC,SAAA,EAAM,WAAW,4CAA4CZ,CAAS,IACpE,UAAA;AAAA,MAAAgC;AAAA,MACD,gBAAAtB,EAAC,QAAA,EAAK,WAAU,cAAc,UAAAhB,EAAA,CAAS;AAAA,IAAA,GACzC,IAIGsC;AAAA,EACT;AACF;AAEAnB,EAAa,cAAc;AAEpB,MAAMoB,IAAW,OAAO,OAAOpB,GAAc;AAAA,EAClD,OAAOpB;AACT,CAAC;"}
|
|
1
|
+
{"version":3,"file":"index10.js","sources":["../src/components/Checkbox.tsx"],"sourcesContent":["import React, { forwardRef, createContext, useContext } from 'react'\n\nexport interface CheckboxSwapConfig {\n /** Content shown when checked */\n on: React.ReactNode\n /** Content shown when unchecked */\n off: React.ReactNode\n /** Animation effect for the swap transition */\n effect?: 'rotate' | 'flip'\n}\n\nexport interface CheckboxProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, 'size' | 'type'> {\n children?: React.ReactNode\n size?: 'xs' | 'sm' | 'md' | 'lg' | 'xl'\n color?: 'primary' | 'secondary' | 'accent' | 'neutral' | 'success' | 'warning' | 'info' | 'error'\n indeterminate?: boolean\n /** Swap mode: toggle between two visual states instead of showing a checkbox */\n swap?: CheckboxSwapConfig\n className?: string\n}\n\nexport interface CheckboxOptionType {\n label: React.ReactNode\n value: string | number\n disabled?: boolean\n}\n\nexport interface CheckboxGroupProps {\n children?: React.ReactNode\n value?: (string | number)[]\n defaultValue?: (string | number)[]\n onChange?: (values: (string | number)[]) => void\n disabled?: boolean\n options?: (string | number | CheckboxOptionType)[]\n className?: string\n}\n\ninterface CheckboxGroupContextValue {\n value?: (string | number)[]\n onChange?: (checkedValue: string | number, checked: boolean) => void\n disabled?: boolean\n}\n\nconst CheckboxGroupContext = createContext<CheckboxGroupContextValue | null>(null)\n\nfunction CheckboxGroup({\n children,\n value,\n defaultValue,\n onChange,\n disabled = false,\n options,\n className = ''\n}: CheckboxGroupProps) {\n const [internalValue, setInternalValue] = React.useState<(string | number)[]>(defaultValue || [])\n const currentValue = value !== undefined ? value : internalValue\n\n const handleChange = (checkedValue: string | number, checked: boolean) => {\n const newValue = checked\n ? [...currentValue, checkedValue]\n : currentValue.filter((v) => v !== checkedValue)\n\n if (value === undefined) {\n setInternalValue(newValue)\n }\n onChange?.(newValue)\n }\n\n const contextValue: CheckboxGroupContextValue = {\n value: currentValue,\n onChange: handleChange,\n disabled,\n }\n\n // If options are provided, render checkboxes automatically\n if (options) {\n return (\n <CheckboxGroupContext.Provider value={contextValue}>\n <div className={className}>\n {options.map((option) => {\n if (typeof option === 'string' || typeof option === 'number') {\n return (\n <label key={option} className=\"label cursor-pointer justify-start gap-2\">\n <CheckboxRoot value={option} />\n <span className=\"label-text\">{option}</span>\n </label>\n )\n } else {\n return (\n <label key={option.value} className=\"label cursor-pointer justify-start gap-2\">\n <CheckboxRoot value={option.value} disabled={option.disabled} />\n <span className=\"label-text\">{option.label}</span>\n </label>\n )\n }\n })}\n </div>\n </CheckboxGroupContext.Provider>\n )\n }\n\n return (\n <CheckboxGroupContext.Provider value={contextValue}>\n <div className={className}>{children}</div>\n </CheckboxGroupContext.Provider>\n )\n}\n\nconst CheckboxRoot = forwardRef<HTMLInputElement, CheckboxProps>(\n (\n {\n children,\n size,\n color,\n indeterminate = false,\n swap,\n className = '',\n value,\n checked,\n onChange,\n disabled: disabledProp,\n ...props\n },\n ref\n ) => {\n const groupContext = useContext(CheckboxGroupContext)\n\n const sizeClasses = {\n xs: 'checkbox-xs',\n sm: 'checkbox-sm',\n md: 'checkbox-md',\n lg: 'checkbox-lg',\n xl: 'checkbox-xl',\n }\n\n const colorClasses = {\n primary: 'checkbox-primary',\n secondary: 'checkbox-secondary',\n accent: 'checkbox-accent',\n neutral: 'checkbox-neutral',\n success: 'checkbox-success',\n warning: 'checkbox-warning',\n info: 'checkbox-info',\n error: 'checkbox-error',\n }\n\n const checkboxClasses = [\n 'checkbox',\n size && sizeClasses[size],\n color && colorClasses[color],\n ]\n .filter(Boolean)\n .join(' ')\n\n // If in a group, use group's value to determine checked state\n const isChecked = groupContext && value !== undefined && (typeof value === 'string' || typeof value === 'number')\n ? groupContext.value?.includes(value) ?? false\n : checked\n\n const isDisabled = groupContext?.disabled || disabledProp\n\n const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {\n if (groupContext && value !== undefined && (typeof value === 'string' || typeof value === 'number')) {\n groupContext.onChange?.(value, e.target.checked)\n }\n onChange?.(e)\n }\n\n // Handle indeterminate state\n const checkboxRef = React.useCallback(\n (node: HTMLInputElement | null) => {\n if (node) {\n node.indeterminate = indeterminate\n }\n if (typeof ref === 'function') {\n ref(node)\n } else if (ref) {\n ref.current = node\n }\n },\n [indeterminate, ref]\n )\n\n const dataState = indeterminate ? 'indeterminate' : isChecked ? 'checked' : 'unchecked'\n\n // Swap mode: render as a swap toggle instead of checkbox\n if (swap) {\n const swapClasses = [\n 'swap',\n swap.effect === 'rotate' && 'swap-rotate',\n swap.effect === 'flip' && 'swap-flip',\n className,\n ]\n .filter(Boolean)\n .join(' ')\n\n return (\n <label className={swapClasses}>\n <input\n ref={ref}\n type=\"checkbox\"\n checked={isChecked}\n onChange={handleChange}\n disabled={isDisabled}\n data-state={dataState}\n {...props}\n />\n <div className=\"swap-on\">{swap.on}</div>\n <div className=\"swap-off\">{swap.off}</div>\n </label>\n )\n }\n\n const checkboxInput = (\n <input\n ref={checkboxRef}\n type=\"checkbox\"\n className={checkboxClasses}\n value={value}\n checked={isChecked}\n onChange={handleChange}\n disabled={isDisabled}\n data-state={dataState}\n {...props}\n />\n )\n\n // If children provided, wrap in label\n if (children) {\n return (\n <label className={`label cursor-pointer justify-start gap-2 ${className}`}>\n {checkboxInput}\n <span className=\"label-text\">{children}</span>\n </label>\n )\n }\n\n return checkboxInput\n }\n)\n\nCheckboxRoot.displayName = 'Checkbox'\n\nexport const Checkbox = Object.assign(CheckboxRoot, {\n Group: CheckboxGroup,\n})\n"],"names":["CheckboxGroupContext","createContext","CheckboxGroup","children","value","defaultValue","onChange","disabled","options","className","internalValue","setInternalValue","React","currentValue","contextValue","checkedValue","checked","newValue","v","jsx","option","jsxs","CheckboxRoot","forwardRef","size","color","indeterminate","swap","disabledProp","props","ref","groupContext","useContext","sizeClasses","colorClasses","checkboxClasses","isChecked","isDisabled","handleChange","e","checkboxRef","node","dataState","swapClasses","checkboxInput","Checkbox"],"mappings":";;AA2CA,MAAMA,IAAuBC,EAAgD,IAAI;AAEjF,SAASC,EAAc;AAAA,EACrB,UAAAC;AAAA,EACA,OAAAC;AAAA,EACA,cAAAC;AAAA,EACA,UAAAC;AAAA,EACA,UAAAC,IAAW;AAAA,EACX,SAAAC;AAAA,EACA,WAAAC,IAAY;AACd,GAAuB;AACrB,QAAM,CAACC,GAAeC,CAAgB,IAAIC,EAAM,SAA8BP,KAAgB,EAAE,GAC1FQ,IAAeT,MAAU,SAAYA,IAAQM,GAa7CI,IAA0C;AAAA,IAC9C,OAAOD;AAAA,IACP,UAbmB,CAACE,GAA+BC,MAAqB;AACxE,YAAMC,IAAWD,IACb,CAAC,GAAGH,GAAcE,CAAY,IAC9BF,EAAa,OAAO,CAACK,MAAMA,MAAMH,CAAY;AAEjD,MAAIX,MAAU,UACZO,EAAiBM,CAAQ,GAE3BX,IAAWW,CAAQ;AAAA,IACrB;AAAA,IAKE,UAAAV;AAAA,EAAA;AAIF,SAAIC,IAEA,gBAAAW,EAACnB,EAAqB,UAArB,EAA8B,OAAOc,GACpC,UAAA,gBAAAK,EAAC,OAAA,EAAI,WAAAV,GACF,UAAAD,EAAQ,IAAI,CAACY,MACR,OAAOA,KAAW,YAAY,OAAOA,KAAW,WAEhD,gBAAAC,EAAC,SAAA,EAAmB,WAAU,4CAC5B,UAAA;AAAA,IAAA,gBAAAF,EAACG,GAAA,EAAa,OAAOF,EAAA,CAAQ;AAAA,IAC7B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QACL,MAAK;AAAA,QACL,WAAWL;AAAA,QACX,OAAA/B;AAAA,QACA,SAASgC;AAAA,QACT,UAAUE;AAAA,QACV,UAAUD;AAAA,QACV,cAAYK;AAAA,QACX,GAAGb;AAAA,MAAA;AAAA,IAAA;AAKR,WAAI1B,IAEA,gBAAAkB,EAAC,SAAA,EAAM,WAAW,4CAA4CZ,CAAS,IACpE,UAAA;AAAA,MAAAmC;AAAA,MACD,gBAAAzB,EAAC,QAAA,EAAK,WAAU,cAAc,UAAAhB,EAAA,CAAS;AAAA,IAAA,GACzC,IAIGyC;AAAA,EACT;AACF;AAEAtB,EAAa,cAAc;AAEpB,MAAMuB,IAAW,OAAO,OAAOvB,GAAc;AAAA,EAClD,OAAOpB;AACT,CAAC;"}
|
package/dist/index100.js
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
function
|
|
3
|
-
const
|
|
4
|
-
return
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { useState as r, useEffect as c } from "react";
|
|
2
|
+
function i(e, t = 300) {
|
|
3
|
+
const [o, u] = r(e);
|
|
4
|
+
return c(() => {
|
|
5
|
+
const n = setTimeout(() => {
|
|
6
|
+
u(e);
|
|
7
|
+
}, t);
|
|
8
|
+
return () => {
|
|
9
|
+
clearTimeout(n);
|
|
10
|
+
};
|
|
11
|
+
}, [e, t]), o;
|
|
7
12
|
}
|
|
8
13
|
export {
|
|
9
|
-
|
|
14
|
+
i as useDebounce
|
|
10
15
|
};
|
|
11
16
|
//# sourceMappingURL=index100.js.map
|
package/dist/index100.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index100.js","sources":["../src/hooks/
|
|
1
|
+
{"version":3,"file":"index100.js","sources":["../src/hooks/useDebounce.ts"],"sourcesContent":["import { useState, useEffect } from 'react'\n\n/**\n * Hook that delays updating a value until after a specified delay.\n * Useful for search inputs to avoid excessive API calls.\n *\n * @param value - Value to debounce\n * @param delay - Delay in milliseconds (default: 300)\n * @returns Debounced value\n *\n * @example\n * const [search, setSearch] = useState('')\n * const debouncedSearch = useDebounce(search, 500)\n *\n * useEffect(() => {\n * // This runs 500ms after user stops typing\n * fetchResults(debouncedSearch)\n * }, [debouncedSearch])\n */\nexport function useDebounce<T>(value: T, delay = 300): T {\n const [debouncedValue, setDebouncedValue] = useState<T>(value)\n\n useEffect(() => {\n const timer = setTimeout(() => {\n setDebouncedValue(value)\n }, delay)\n\n return () => {\n clearTimeout(timer)\n }\n }, [value, delay])\n\n return debouncedValue\n}\n"],"names":["useDebounce","value","delay","debouncedValue","setDebouncedValue","useState","useEffect","timer"],"mappings":";AAmBO,SAASA,EAAeC,GAAUC,IAAQ,KAAQ;AACvD,QAAM,CAACC,GAAgBC,CAAiB,IAAIC,EAAYJ,CAAK;AAE7D,SAAAK,EAAU,MAAM;AACd,UAAMC,IAAQ,WAAW,MAAM;AAC7B,MAAAH,EAAkBH,CAAK;AAAA,IACzB,GAAGC,CAAK;AAER,WAAO,MAAM;AACX,mBAAaK,CAAK;AAAA,IACpB;AAAA,EACF,GAAG,CAACN,GAAOC,CAAK,CAAC,GAEVC;AACT;"}
|
package/dist/index101.js
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
function
|
|
3
|
-
const
|
|
4
|
-
return
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
e.removeEventListener("mouseenter", r), e.removeEventListener("mouseleave", s);
|
|
1
|
+
import { useRef as s, useEffect as c } from "react";
|
|
2
|
+
function m(t, n = !0) {
|
|
3
|
+
const r = s(null);
|
|
4
|
+
return c(() => {
|
|
5
|
+
if (!n) return;
|
|
6
|
+
const e = (o) => {
|
|
7
|
+
const u = r.current;
|
|
8
|
+
!u || u.contains(o.target) || t(o);
|
|
10
9
|
};
|
|
11
|
-
|
|
10
|
+
return document.addEventListener("mousedown", e), document.addEventListener("touchstart", e), () => {
|
|
11
|
+
document.removeEventListener("mousedown", e), document.removeEventListener("touchstart", e);
|
|
12
|
+
};
|
|
13
|
+
}, [t, n]), r;
|
|
12
14
|
}
|
|
13
15
|
export {
|
|
14
|
-
|
|
16
|
+
m as useClickOutside
|
|
15
17
|
};
|
|
16
18
|
//# sourceMappingURL=index101.js.map
|
package/dist/index101.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index101.js","sources":["../src/hooks/
|
|
1
|
+
{"version":3,"file":"index101.js","sources":["../src/hooks/useClickOutside.ts"],"sourcesContent":["import { useEffect, useRef, type RefObject } from 'react'\n\n/**\n * Hook that detects clicks outside of a referenced element.\n * Useful for closing dropdowns, modals, or menus.\n *\n * @param handler - Callback when click outside is detected\n * @param enabled - Whether the listener is active (default: true)\n * @returns Ref to attach to the element\n *\n * @example\n * const ref = useClickOutside(() => setIsOpen(false))\n *\n * <div ref={ref}>\n * <Dropdown>...</Dropdown>\n * </div>\n */\nexport function useClickOutside<T extends HTMLElement = HTMLElement>(\n handler: (event: MouseEvent | TouchEvent) => void,\n enabled = true\n): RefObject<T | null> {\n const ref = useRef<T>(null)\n\n useEffect(() => {\n if (!enabled) return\n\n const listener = (event: MouseEvent | TouchEvent) => {\n const el = ref.current\n if (!el || el.contains(event.target as Node)) {\n return\n }\n handler(event)\n }\n\n document.addEventListener('mousedown', listener)\n document.addEventListener('touchstart', listener)\n\n return () => {\n document.removeEventListener('mousedown', listener)\n document.removeEventListener('touchstart', listener)\n }\n }, [handler, enabled])\n\n return ref\n}\n"],"names":["useClickOutside","handler","enabled","ref","useRef","useEffect","listener","event","el"],"mappings":";AAiBO,SAASA,EACdC,GACAC,IAAU,IACW;AACrB,QAAMC,IAAMC,EAAU,IAAI;AAE1B,SAAAC,EAAU,MAAM;AACd,QAAI,CAACH,EAAS;AAEd,UAAMI,IAAW,CAACC,MAAmC;AACnD,YAAMC,IAAKL,EAAI;AACf,MAAI,CAACK,KAAMA,EAAG,SAASD,EAAM,MAAc,KAG3CN,EAAQM,CAAK;AAAA,IACf;AAEA,oBAAS,iBAAiB,aAAaD,CAAQ,GAC/C,SAAS,iBAAiB,cAAcA,CAAQ,GAEzC,MAAM;AACX,eAAS,oBAAoB,aAAaA,CAAQ,GAClD,SAAS,oBAAoB,cAAcA,CAAQ;AAAA,IACrD;AAAA,EACF,GAAG,CAACL,GAASC,CAAO,CAAC,GAEdC;AACT;"}
|
package/dist/index102.js
CHANGED
|
@@ -1,34 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
function
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
[n, r]
|
|
8
|
-
), s = i(
|
|
9
|
-
(e) => {
|
|
10
|
-
e.key === n && d(!1);
|
|
11
|
-
},
|
|
12
|
-
[n]
|
|
13
|
-
);
|
|
14
|
-
return l(() => {
|
|
15
|
-
const e = u ?? window;
|
|
16
|
-
return o === "keydown" ? (e.addEventListener("keydown", t), e.addEventListener("keyup", s)) : e.addEventListener("keyup", t), () => {
|
|
17
|
-
e.removeEventListener("keydown", t), e.removeEventListener("keyup", s);
|
|
18
|
-
};
|
|
19
|
-
}, [u, o, t, s]), a;
|
|
20
|
-
}
|
|
21
|
-
function y(n, f, u = {}) {
|
|
22
|
-
const { target: o, event: r = "keydown", preventDefault: a = !1 } = u;
|
|
23
|
-
l(() => {
|
|
24
|
-
const d = o ?? window, t = (s) => {
|
|
25
|
-
s.key === n && (a && s.preventDefault(), f(s));
|
|
26
|
-
};
|
|
27
|
-
return d.addEventListener(r, t), () => d.removeEventListener(r, t);
|
|
28
|
-
}, [o, n, f, r, a]);
|
|
1
|
+
import { useRef as t, useEffect as o } from "react";
|
|
2
|
+
function f(r) {
|
|
3
|
+
const e = t(void 0);
|
|
4
|
+
return o(() => {
|
|
5
|
+
e.current = r;
|
|
6
|
+
}, [r]), e.current;
|
|
29
7
|
}
|
|
30
8
|
export {
|
|
31
|
-
|
|
32
|
-
y as useKeyPressCallback
|
|
9
|
+
f as usePrevious
|
|
33
10
|
};
|
|
34
11
|
//# sourceMappingURL=index102.js.map
|
package/dist/index102.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index102.js","sources":["../src/hooks/
|
|
1
|
+
{"version":3,"file":"index102.js","sources":["../src/hooks/usePrevious.ts"],"sourcesContent":["import { useRef, useEffect } from 'react'\n\n/**\n * Hook that returns the previous value of a variable.\n * Useful for comparing current and previous values in effects.\n *\n * @param value - Current value\n * @returns Previous value (undefined on first render)\n *\n * @example\n * const [count, setCount] = useState(0)\n * const prevCount = usePrevious(count)\n *\n * // prevCount is the value from previous render\n * console.log(`Changed from ${prevCount} to ${count}`)\n */\nexport function usePrevious<T>(value: T): T | undefined {\n const ref = useRef<T | undefined>(undefined)\n\n useEffect(() => {\n ref.current = value\n }, [value])\n\n return ref.current\n}\n"],"names":["usePrevious","value","ref","useRef","useEffect"],"mappings":";AAgBO,SAASA,EAAeC,GAAyB;AACtD,QAAMC,IAAMC,EAAsB,MAAS;AAE3C,SAAAC,EAAU,MAAM;AACd,IAAAF,EAAI,UAAUD;AAAA,EAChB,GAAG,CAACA,CAAK,CAAC,GAEHC,EAAI;AACb;"}
|
package/dist/index103.js
CHANGED
|
@@ -1,21 +1,16 @@
|
|
|
1
|
-
import { useState as
|
|
2
|
-
function
|
|
3
|
-
const [
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
n({
|
|
11
|
-
width: window.innerWidth,
|
|
12
|
-
height: window.innerHeight
|
|
13
|
-
});
|
|
1
|
+
import { useState as u, useRef as v, useEffect as a } from "react";
|
|
2
|
+
function f() {
|
|
3
|
+
const [o, t] = u(!1), n = v(null);
|
|
4
|
+
return a(() => {
|
|
5
|
+
const e = n.current;
|
|
6
|
+
if (!e) return;
|
|
7
|
+
const r = () => t(!0), s = () => t(!1);
|
|
8
|
+
return e.addEventListener("mouseenter", r), e.addEventListener("mouseleave", s), () => {
|
|
9
|
+
e.removeEventListener("mouseenter", r), e.removeEventListener("mouseleave", s);
|
|
14
10
|
};
|
|
15
|
-
|
|
16
|
-
}, []), i;
|
|
11
|
+
}, []), { ref: n, isHovered: o };
|
|
17
12
|
}
|
|
18
13
|
export {
|
|
19
|
-
|
|
14
|
+
f as useHover
|
|
20
15
|
};
|
|
21
16
|
//# sourceMappingURL=index103.js.map
|
package/dist/index103.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index103.js","sources":["../src/hooks/
|
|
1
|
+
{"version":3,"file":"index103.js","sources":["../src/hooks/useHover.ts"],"sourcesContent":["import { useState, useRef, useEffect, type RefObject } from 'react'\n\nexport interface UseHoverReturn<T extends HTMLElement> {\n ref: RefObject<T | null>\n isHovered: boolean\n}\n\n/**\n * Hook that tracks hover state of an element.\n *\n * @returns Object with ref and isHovered state\n *\n * @example\n * const { ref, isHovered } = useHover<HTMLDivElement>()\n *\n * <div ref={ref} className={isHovered ? 'bg-blue-500' : 'bg-gray-500'}>\n * Hover me!\n * </div>\n */\nexport function useHover<T extends HTMLElement = HTMLElement>(): UseHoverReturn<T> {\n const [isHovered, setIsHovered] = useState(false)\n const ref = useRef<T>(null)\n\n useEffect(() => {\n const node = ref.current\n if (!node) return\n\n const handleMouseEnter = () => setIsHovered(true)\n const handleMouseLeave = () => setIsHovered(false)\n\n node.addEventListener('mouseenter', handleMouseEnter)\n node.addEventListener('mouseleave', handleMouseLeave)\n\n return () => {\n node.removeEventListener('mouseenter', handleMouseEnter)\n node.removeEventListener('mouseleave', handleMouseLeave)\n }\n }, [])\n\n return { ref, isHovered }\n}\n"],"names":["useHover","isHovered","setIsHovered","useState","ref","useRef","useEffect","node","handleMouseEnter","handleMouseLeave"],"mappings":";AAmBO,SAASA,IAAmE;AACjF,QAAM,CAACC,GAAWC,CAAY,IAAIC,EAAS,EAAK,GAC1CC,IAAMC,EAAU,IAAI;AAE1B,SAAAC,EAAU,MAAM;AACd,UAAMC,IAAOH,EAAI;AACjB,QAAI,CAACG,EAAM;AAEX,UAAMC,IAAmB,MAAMN,EAAa,EAAI,GAC1CO,IAAmB,MAAMP,EAAa,EAAK;AAEjD,WAAAK,EAAK,iBAAiB,cAAcC,CAAgB,GACpDD,EAAK,iBAAiB,cAAcE,CAAgB,GAE7C,MAAM;AACX,MAAAF,EAAK,oBAAoB,cAAcC,CAAgB,GACvDD,EAAK,oBAAoB,cAAcE,CAAgB;AAAA,IACzD;AAAA,EACF,GAAG,CAAA,CAAE,GAEE,EAAE,KAAAL,GAAK,WAAAH,EAAA;AAChB;"}
|