asterui 0.12.62 → 0.12.63
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/Anchor.d.ts +2 -0
- package/dist/components/Anchor.js +79 -75
- package/dist/components/Anchor.js.map +1 -1
- package/dist/components/Autocomplete.d.ts +1 -0
- package/dist/components/Autocomplete.js +115 -110
- package/dist/components/Autocomplete.js.map +1 -1
- package/dist/components/Breadcrumb.d.ts +4 -2
- package/dist/components/Breadcrumb.js +54 -29
- package/dist/components/Breadcrumb.js.map +1 -1
- package/dist/components/Button.d.ts +5 -1
- package/dist/components/Button.js +117 -107
- package/dist/components/Button.js.map +1 -1
- package/dist/components/Chart.d.ts +1 -0
- package/dist/components/Chart.js +31 -30
- package/dist/components/Chart.js.map +1 -1
- package/dist/components/Chat.d.ts +1 -0
- package/dist/components/Chat.js +32 -30
- package/dist/components/Chat.js.map +1 -1
- package/dist/components/Command.d.ts +5 -2
- package/dist/components/Command.js +262 -233
- package/dist/components/Command.js.map +1 -1
- package/dist/components/ContextMenu.d.ts +4 -0
- package/dist/components/ContextMenu.js +149 -130
- package/dist/components/ContextMenu.js.map +1 -1
- package/dist/components/Dock.d.ts +2 -0
- package/dist/components/Dock.js +70 -46
- package/dist/components/Dock.js.map +1 -1
- package/dist/components/FileInput.d.ts +1 -0
- package/dist/components/FileInput.js +26 -26
- package/dist/components/FileInput.js.map +1 -1
- package/dist/components/Filter.d.ts +1 -0
- package/dist/components/Filter.js +43 -40
- package/dist/components/Filter.js.map +1 -1
- package/dist/components/Flex.d.ts +1 -0
- package/dist/components/Flex.js +43 -42
- package/dist/components/Flex.js.map +1 -1
- package/dist/components/FloatButton.d.ts +3 -0
- package/dist/components/FloatButton.js +178 -127
- package/dist/components/FloatButton.js.map +1 -1
- package/dist/components/Input.d.ts +1 -0
- package/dist/components/Input.js +201 -184
- package/dist/components/Input.js.map +1 -1
- package/dist/components/Loading.d.ts +1 -0
- package/dist/components/Loading.js +40 -37
- package/dist/components/Loading.js.map +1 -1
- package/dist/components/Masonry.d.ts +1 -0
- package/dist/components/Masonry.js +45 -42
- package/dist/components/Masonry.js.map +1 -1
- package/dist/components/Mention.d.ts +1 -0
- package/dist/components/Mention.js +95 -91
- package/dist/components/Mention.js.map +1 -1
- package/dist/components/MonthCalendar.d.ts +1 -0
- package/dist/components/MonthCalendar.js +104 -97
- package/dist/components/MonthCalendar.js.map +1 -1
- package/dist/components/QRCode.d.ts +1 -0
- package/dist/components/QRCode.js +84 -55
- package/dist/components/QRCode.js.map +1 -1
- package/dist/components/RadialProgress.d.ts +1 -0
- package/dist/components/RadialProgress.js +19 -17
- package/dist/components/RadialProgress.js.map +1 -1
- package/dist/components/Range.d.ts +1 -0
- package/dist/components/Range.js +45 -43
- package/dist/components/Range.js.map +1 -1
- package/dist/components/Rating.d.ts +4 -2
- package/dist/components/Rating.js +83 -79
- package/dist/components/Rating.js.map +1 -1
- package/dist/components/Responsive.d.ts +4 -2
- package/dist/components/Responsive.js +10 -9
- package/dist/components/Responsive.js.map +1 -1
- package/dist/components/Result.d.ts +1 -0
- package/dist/components/Result.js +24 -22
- package/dist/components/Result.js.map +1 -1
- package/dist/components/Select.d.ts +1 -0
- package/dist/components/Select.js +72 -62
- package/dist/components/Select.js.map +1 -1
- package/dist/components/Splitter.d.ts +2 -0
- package/dist/components/Splitter.js +137 -131
- package/dist/components/Splitter.js.map +1 -1
- package/dist/components/Stat.d.ts +4 -2
- package/dist/components/Stat.js +19 -18
- package/dist/components/Stat.js.map +1 -1
- package/dist/components/Steps.d.ts +4 -2
- package/dist/components/Steps.js +56 -52
- package/dist/components/Steps.js.map +1 -1
- package/dist/components/TextRotate.d.ts +1 -0
- package/dist/components/TextRotate.js +14 -12
- package/dist/components/TextRotate.js.map +1 -1
- package/dist/components/Textarea.d.ts +1 -0
- package/dist/components/Textarea.js +31 -30
- package/dist/components/Textarea.js.map +1 -1
- package/dist/components/ThemeController.d.ts +6 -3
- package/dist/components/ThemeController.js +101 -92
- package/dist/components/ThemeController.js.map +1 -1
- package/dist/components/Typography.d.ts +10 -5
- package/dist/components/Typography.js +84 -81
- package/dist/components/Typography.js.map +1 -1
- package/dist/components/VirtualList.d.ts +2 -1
- package/dist/components/VirtualList.js +40 -36
- package/dist/components/VirtualList.js.map +1 -1
- package/dist/components/Watermark.d.ts +1 -0
- package/dist/components/Watermark.js +74 -71
- package/dist/components/Watermark.js.map +1 -1
- package/dist/components/WeekCalendar.d.ts +1 -0
- package/dist/components/WeekCalendar.js +91 -76
- package/dist/components/WeekCalendar.js.map +1 -1
- package/package.json +1 -1
|
@@ -39,6 +39,7 @@ export interface AnchorProps {
|
|
|
39
39
|
className?: string;
|
|
40
40
|
/** Anchor.Link children */
|
|
41
41
|
children?: React.ReactNode;
|
|
42
|
+
'data-testid'?: string;
|
|
42
43
|
}
|
|
43
44
|
export interface AnchorLinkProps {
|
|
44
45
|
/** Target element id (without #) */
|
|
@@ -49,6 +50,7 @@ export interface AnchorLinkProps {
|
|
|
49
50
|
children?: React.ReactNode;
|
|
50
51
|
/** Custom class name */
|
|
51
52
|
className?: string;
|
|
53
|
+
'data-testid'?: string;
|
|
52
54
|
}
|
|
53
55
|
export declare const Anchor: React.FC<AnchorProps> & {
|
|
54
56
|
Link: React.FC<AnchorLinkProps>;
|
|
@@ -1,116 +1,120 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { useState as
|
|
3
|
-
const
|
|
4
|
-
const o =
|
|
1
|
+
import { jsx as l, jsxs as Z } from "react/jsx-runtime";
|
|
2
|
+
import { useState as C, useRef as D, useCallback as $, useEffect as T, createContext as _, useContext as O } from "react";
|
|
3
|
+
const H = _(null), tt = () => {
|
|
4
|
+
const o = O(H);
|
|
5
5
|
if (!o)
|
|
6
6
|
throw new Error("Anchor.Link must be used within an Anchor");
|
|
7
7
|
return o;
|
|
8
|
-
},
|
|
8
|
+
}, q = ({
|
|
9
9
|
href: o,
|
|
10
10
|
title: h,
|
|
11
11
|
children: c,
|
|
12
|
-
className:
|
|
12
|
+
className: x = "",
|
|
13
|
+
"data-testid": i
|
|
13
14
|
}) => {
|
|
14
|
-
const { activeLink:
|
|
15
|
-
|
|
16
|
-
const
|
|
17
|
-
return /* @__PURE__ */
|
|
18
|
-
/* @__PURE__ */
|
|
15
|
+
const { activeLink: b, direction: d, registerLink: w, unregisterLink: v, handleClick: m } = tt();
|
|
16
|
+
T(() => (w(o), () => v(o)), [o, w, v]);
|
|
17
|
+
const p = b === o, a = d === "vertical";
|
|
18
|
+
return /* @__PURE__ */ Z("div", { className: a ? "" : "inline-block", children: [
|
|
19
|
+
/* @__PURE__ */ l(
|
|
19
20
|
"a",
|
|
20
21
|
{
|
|
21
22
|
href: `#${o}`,
|
|
22
|
-
onClick: (
|
|
23
|
+
onClick: (y) => m(y, o, h),
|
|
23
24
|
className: `
|
|
24
25
|
block text-sm transition-colors
|
|
25
|
-
${
|
|
26
|
-
${
|
|
27
|
-
${
|
|
26
|
+
${a ? "py-1 pl-3 border-l-2" : "px-3 py-1 border-b-2"}
|
|
27
|
+
${p ? "text-primary border-primary font-medium" : "text-base-content/70 border-transparent hover:text-base-content hover:border-base-content/30"}
|
|
28
|
+
${x}
|
|
28
29
|
`.trim(),
|
|
30
|
+
"data-testid": i,
|
|
29
31
|
children: h
|
|
30
32
|
}
|
|
31
33
|
),
|
|
32
|
-
c && /* @__PURE__ */
|
|
34
|
+
c && /* @__PURE__ */ l("div", { className: a ? "pl-3" : "inline-flex", children: c })
|
|
33
35
|
] });
|
|
34
|
-
},
|
|
36
|
+
}, et = ({
|
|
35
37
|
items: o,
|
|
36
38
|
direction: h = "vertical",
|
|
37
39
|
offsetTop: c = 0,
|
|
38
|
-
bounds:
|
|
39
|
-
getContainer:
|
|
40
|
-
getCurrentAnchor:
|
|
41
|
-
onChange:
|
|
40
|
+
bounds: x = 5,
|
|
41
|
+
getContainer: i,
|
|
42
|
+
getCurrentAnchor: b,
|
|
43
|
+
onChange: d,
|
|
42
44
|
onClick: w,
|
|
43
|
-
activeLink:
|
|
44
|
-
affix:
|
|
45
|
-
affixOffsetTop:
|
|
46
|
-
replace:
|
|
47
|
-
className:
|
|
48
|
-
children:
|
|
45
|
+
activeLink: v,
|
|
46
|
+
affix: m = !1,
|
|
47
|
+
affixOffsetTop: p = 0,
|
|
48
|
+
replace: a = !1,
|
|
49
|
+
className: y = "",
|
|
50
|
+
children: F,
|
|
51
|
+
"data-testid": B
|
|
49
52
|
}) => {
|
|
50
|
-
const [
|
|
51
|
-
|
|
52
|
-
}, []),
|
|
53
|
-
|
|
54
|
-
}, []),
|
|
55
|
-
const
|
|
56
|
-
if (
|
|
57
|
-
const
|
|
58
|
-
|
|
53
|
+
const [G, N] = C(""), [r, S] = C([]), [g, J] = C(!1), f = D(null), E = D(null), k = v !== void 0, L = k ? v : G, K = b ? b(L) : L, M = $((t) => {
|
|
54
|
+
S((e) => e.includes(t) ? e : [...e, t]);
|
|
55
|
+
}, []), Q = $((t) => {
|
|
56
|
+
S((e) => e.filter((n) => n !== t));
|
|
57
|
+
}, []), I = $((t) => {
|
|
58
|
+
const e = document.getElementById(t);
|
|
59
|
+
if (e) {
|
|
60
|
+
const n = i?.() ?? window, s = e.getBoundingClientRect().top, u = n === window ? 0 : n.getBoundingClientRect().top, R = n === window ? window.scrollY : n.scrollTop, A = s - u + R - c;
|
|
61
|
+
n === window ? window.scrollTo({ top: A, behavior: "smooth" }) : n.scrollTo({ top: A, behavior: "smooth" }), a ? window.history.replaceState(null, "", `#${t}`) : window.history.pushState(null, "", `#${t}`);
|
|
59
62
|
}
|
|
60
|
-
}, [
|
|
61
|
-
|
|
62
|
-
}, [w,
|
|
63
|
-
|
|
64
|
-
if (!
|
|
65
|
-
const
|
|
66
|
-
if (!
|
|
67
|
-
const
|
|
68
|
-
u !==
|
|
63
|
+
}, [i, c, a]), U = $((t, e, n) => {
|
|
64
|
+
t.preventDefault(), w?.(t, { href: e, title: n }), I(e), k || N(e), d?.(e);
|
|
65
|
+
}, [w, I, k, d]);
|
|
66
|
+
T(() => {
|
|
67
|
+
if (!m || !f.current) return;
|
|
68
|
+
const t = i?.() ?? window, e = () => {
|
|
69
|
+
if (!f.current || !E.current) return;
|
|
70
|
+
const n = E.current.getBoundingClientRect(), s = t === window ? 0 : t.getBoundingClientRect().top, u = n.top - s <= p;
|
|
71
|
+
u !== g && J(u);
|
|
69
72
|
};
|
|
70
|
-
return
|
|
71
|
-
}, [
|
|
72
|
-
if (
|
|
73
|
-
const
|
|
74
|
-
let
|
|
75
|
-
const s =
|
|
76
|
-
if (
|
|
77
|
-
|
|
73
|
+
return t.addEventListener("scroll", e, { passive: !0 }), e(), () => t.removeEventListener("scroll", e);
|
|
74
|
+
}, [m, p, i, g]), T(() => {
|
|
75
|
+
if (r.length === 0) return;
|
|
76
|
+
const t = i?.() ?? window, e = () => {
|
|
77
|
+
let n = "";
|
|
78
|
+
const s = t === window ? document.documentElement : t, u = t === window ? 0 : s.getBoundingClientRect().top, R = t === window ? window.scrollY : s.scrollTop, A = s.scrollHeight, X = t === window ? window.innerHeight : s.clientHeight;
|
|
79
|
+
if (R + X >= A - 10 && r.length > 0)
|
|
80
|
+
n = r[r.length - 1];
|
|
78
81
|
else {
|
|
79
|
-
for (const
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
+
for (const V of r) {
|
|
83
|
+
const Y = document.getElementById(V);
|
|
84
|
+
Y && Y.getBoundingClientRect().top - u - c <= x && (n = V);
|
|
82
85
|
}
|
|
83
|
-
!
|
|
86
|
+
!n && r.length > 0 && (n = r[0]);
|
|
84
87
|
}
|
|
85
|
-
|
|
88
|
+
n && n !== L && (k || N(n), d?.(n));
|
|
86
89
|
};
|
|
87
|
-
return
|
|
88
|
-
}, [
|
|
89
|
-
const
|
|
90
|
-
activeLink:
|
|
90
|
+
return t.addEventListener("scroll", e, { passive: !0 }), e(), () => t.removeEventListener("scroll", e);
|
|
91
|
+
}, [r, i, c, x, L, k, d]);
|
|
92
|
+
const j = {
|
|
93
|
+
activeLink: K,
|
|
91
94
|
direction: h,
|
|
92
95
|
offsetTop: c,
|
|
93
|
-
registerLink:
|
|
94
|
-
unregisterLink:
|
|
95
|
-
handleClick:
|
|
96
|
-
},
|
|
96
|
+
registerLink: M,
|
|
97
|
+
unregisterLink: Q,
|
|
98
|
+
handleClick: U
|
|
99
|
+
}, W = (t) => B ? `${B}-${t}` : void 0, z = (t) => t.map((e) => /* @__PURE__ */ l(q, { href: e.href, title: e.title, "data-testid": W(`link-${e.href}`), children: e.children && z(e.children) }, e.href)), P = /* @__PURE__ */ l(
|
|
97
100
|
"nav",
|
|
98
101
|
{
|
|
99
|
-
ref:
|
|
102
|
+
ref: f,
|
|
100
103
|
className: `
|
|
101
104
|
${h === "horizontal" ? "flex items-center" : "flex flex-col"}
|
|
102
|
-
${
|
|
103
|
-
${
|
|
105
|
+
${g ? "fixed bg-base-100 shadow-sm z-10" : ""}
|
|
106
|
+
${y}
|
|
104
107
|
`.trim(),
|
|
105
|
-
style:
|
|
106
|
-
|
|
108
|
+
style: g ? { top: p } : void 0,
|
|
109
|
+
"data-testid": B,
|
|
110
|
+
children: o ? z(o) : F
|
|
107
111
|
}
|
|
108
112
|
);
|
|
109
|
-
return
|
|
110
|
-
},
|
|
111
|
-
Link:
|
|
113
|
+
return m ? /* @__PURE__ */ l(H.Provider, { value: j, children: /* @__PURE__ */ l("div", { ref: E, style: g && f.current ? { height: f.current.offsetHeight } : void 0, children: P }) }) : /* @__PURE__ */ l(H.Provider, { value: j, children: P });
|
|
114
|
+
}, st = Object.assign(et, {
|
|
115
|
+
Link: q
|
|
112
116
|
});
|
|
113
117
|
export {
|
|
114
|
-
|
|
118
|
+
st as Anchor
|
|
115
119
|
};
|
|
116
120
|
//# sourceMappingURL=Anchor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Anchor.js","sources":["../../src/components/Anchor.tsx"],"sourcesContent":["import React, { useState, useEffect, useCallback, createContext, useContext, useRef } from 'react'\n\nexport interface AnchorLinkItem {\n /** Target element id (without #) */\n href: string\n /** Link title */\n title: React.ReactNode\n /** Nested links */\n children?: AnchorLinkItem[]\n}\n\nexport interface AnchorProps {\n /** Anchor links (alternative to Anchor.Link children) */\n items?: AnchorLinkItem[]\n /** Layout direction */\n direction?: 'horizontal' | 'vertical'\n /** Offset from top when calculating scroll position */\n offsetTop?: number\n /** Bounding distance of anchor area */\n bounds?: number\n /** Target scroll container (default: window) */\n getContainer?: () => HTMLElement | Window\n /** Customize the anchor highlight */\n getCurrentAnchor?: (activeLink: string) => string\n /** Callback when active link changes */\n onChange?: (activeLink: string) => void\n /** Callback when link is clicked */\n onClick?: (e: React.MouseEvent, link: { href: string; title: React.ReactNode }) => void\n /** Currently active link (controlled) */\n activeLink?: string\n /** Whether to fix the anchor when scrolling */\n affix?: boolean\n /** Pixels to offset from top when affix is true */\n affixOffsetTop?: number\n /** Replace history instead of push */\n replace?: boolean\n /** Custom class name */\n className?: string\n /** Anchor.Link children */\n children?: React.ReactNode\n}\n\nexport interface AnchorLinkProps {\n /** Target element id (without #) */\n href: string\n /** Link title */\n title: React.ReactNode\n /** Nested links */\n children?: React.ReactNode\n /** Custom class name */\n className?: string\n}\n\ninterface AnchorContextValue {\n activeLink: string\n direction: 'horizontal' | 'vertical'\n offsetTop: number\n registerLink: (href: string) => void\n unregisterLink: (href: string) => void\n handleClick: (e: React.MouseEvent, href: string, title: React.ReactNode) => void\n}\n\nconst AnchorContext = createContext<AnchorContextValue | null>(null)\n\nconst useAnchorContext = () => {\n const context = useContext(AnchorContext)\n if (!context) {\n throw new Error('Anchor.Link must be used within an Anchor')\n }\n return context\n}\n\nconst AnchorLink: React.FC<AnchorLinkProps> = ({\n href,\n title,\n children,\n className = '',\n}) => {\n const { activeLink, direction, registerLink, unregisterLink, handleClick } = useAnchorContext()\n\n useEffect(() => {\n registerLink(href)\n return () => unregisterLink(href)\n }, [href, registerLink, unregisterLink])\n\n const isActive = activeLink === href\n const isVertical = direction === 'vertical'\n\n return (\n <div className={isVertical ? '' : 'inline-block'}>\n <a\n href={`#${href}`}\n onClick={(e) => handleClick(e, href, title)}\n className={`\n block text-sm transition-colors\n ${isVertical ? 'py-1 pl-3 border-l-2' : 'px-3 py-1 border-b-2'}\n ${isActive\n ? 'text-primary border-primary font-medium'\n : 'text-base-content/70 border-transparent hover:text-base-content hover:border-base-content/30'\n }\n ${className}\n `.trim()}\n >\n {title}\n </a>\n {children && (\n <div className={isVertical ? 'pl-3' : 'inline-flex'}>\n {children}\n </div>\n )}\n </div>\n )\n}\n\nconst AnchorComponent: React.FC<AnchorProps> = ({\n items,\n direction = 'vertical',\n offsetTop = 0,\n bounds = 5,\n getContainer,\n getCurrentAnchor,\n onChange,\n onClick,\n activeLink: controlledActiveLink,\n affix = false,\n affixOffsetTop = 0,\n replace = false,\n className = '',\n children,\n}) => {\n const [internalActiveLink, setInternalActiveLink] = useState('')\n const [links, setLinks] = useState<string[]>([])\n const [isAffixed, setIsAffixed] = useState(false)\n const anchorRef = useRef<HTMLDivElement>(null)\n const placeholderRef = useRef<HTMLDivElement>(null)\n\n const isControlled = controlledActiveLink !== undefined\n const rawActiveLink = isControlled ? controlledActiveLink : internalActiveLink\n const activeLink = getCurrentAnchor ? getCurrentAnchor(rawActiveLink) : rawActiveLink\n\n const registerLink = useCallback((href: string) => {\n setLinks((prev) => (prev.includes(href) ? prev : [...prev, href]))\n }, [])\n\n const unregisterLink = useCallback((href: string) => {\n setLinks((prev) => prev.filter((link) => link !== href))\n }, [])\n\n const scrollToTarget = useCallback((href: string) => {\n const target = document.getElementById(href)\n if (target) {\n const container = getContainer?.() ?? window\n const targetTop = target.getBoundingClientRect().top\n const containerTop = container === window\n ? 0\n : (container as HTMLElement).getBoundingClientRect().top\n const scrollTop = container === window\n ? window.scrollY\n : (container as HTMLElement).scrollTop\n\n const top = targetTop - containerTop + scrollTop - offsetTop\n\n if (container === window) {\n window.scrollTo({ top, behavior: 'smooth' })\n } else {\n (container as HTMLElement).scrollTo({ top, behavior: 'smooth' })\n }\n\n // Update URL hash\n if (replace) {\n window.history.replaceState(null, '', `#${href}`)\n } else {\n window.history.pushState(null, '', `#${href}`)\n }\n }\n }, [getContainer, offsetTop, replace])\n\n const handleClick = useCallback((\n e: React.MouseEvent,\n href: string,\n title: React.ReactNode\n ) => {\n e.preventDefault()\n onClick?.(e, { href, title })\n scrollToTarget(href)\n\n if (!isControlled) {\n setInternalActiveLink(href)\n }\n onChange?.(href)\n }, [onClick, scrollToTarget, isControlled, onChange])\n\n // Affix logic\n useEffect(() => {\n if (!affix || !anchorRef.current) return\n\n const container = getContainer?.() ?? window\n\n const handleScroll = () => {\n if (!anchorRef.current || !placeholderRef.current) return\n\n const placeholderRect = placeholderRef.current.getBoundingClientRect()\n const containerTop = container === window\n ? 0\n : (container as HTMLElement).getBoundingClientRect().top\n\n const shouldAffix = placeholderRect.top - containerTop <= affixOffsetTop\n\n if (shouldAffix !== isAffixed) {\n setIsAffixed(shouldAffix)\n }\n }\n\n container.addEventListener('scroll', handleScroll, { passive: true })\n handleScroll()\n\n return () => container.removeEventListener('scroll', handleScroll)\n }, [affix, affixOffsetTop, getContainer, isAffixed])\n\n // Scroll spy\n useEffect(() => {\n if (links.length === 0) return\n\n const container = getContainer?.() ?? window\n\n const handleScroll = () => {\n let currentActive = ''\n const containerEl = container === window ? document.documentElement : container as HTMLElement\n const containerTop = container === window\n ? 0\n : containerEl.getBoundingClientRect().top\n\n // Check if scrolled to near the bottom\n const scrollTop = container === window ? window.scrollY : containerEl.scrollTop\n const scrollHeight = containerEl.scrollHeight\n const clientHeight = container === window ? window.innerHeight : containerEl.clientHeight\n const isNearBottom = scrollTop + clientHeight >= scrollHeight - 10\n\n // If near bottom, use the last link\n if (isNearBottom && links.length > 0) {\n currentActive = links[links.length - 1]\n } else {\n // Find the last element that has scrolled past the top (standard scroll spy behavior)\n for (const href of links) {\n const element = document.getElementById(href)\n if (element) {\n const rect = element.getBoundingClientRect()\n const distance = rect.top - containerTop - offsetTop\n\n // If element's top is within bounds of the threshold, it's the current section\n if (distance <= bounds) {\n currentActive = href\n }\n }\n }\n\n // If nothing matched, use the first link\n if (!currentActive && links.length > 0) {\n currentActive = links[0]\n }\n }\n\n if (currentActive && currentActive !== rawActiveLink) {\n if (!isControlled) {\n setInternalActiveLink(currentActive)\n }\n onChange?.(currentActive)\n }\n }\n\n container.addEventListener('scroll', handleScroll, { passive: true })\n handleScroll() // Initial check\n\n return () => container.removeEventListener('scroll', handleScroll)\n }, [links, getContainer, offsetTop, bounds, rawActiveLink, isControlled, onChange])\n\n const contextValue: AnchorContextValue = {\n activeLink,\n direction,\n offsetTop,\n registerLink,\n unregisterLink,\n handleClick,\n }\n\n const renderItems = (linkItems: AnchorLinkItem[]): React.ReactNode => {\n return linkItems.map((item) => (\n <AnchorLink key={item.href} href={item.href} title={item.title}>\n {item.children && renderItems(item.children)}\n </AnchorLink>\n ))\n }\n\n const anchorContent = (\n <nav\n ref={anchorRef}\n className={`\n ${direction === 'horizontal' ? 'flex items-center' : 'flex flex-col'}\n ${isAffixed ? 'fixed bg-base-100 shadow-sm z-10' : ''}\n ${className}\n `.trim()}\n style={isAffixed ? { top: affixOffsetTop } : undefined}\n >\n {items ? renderItems(items) : children}\n </nav>\n )\n\n if (affix) {\n return (\n <AnchorContext.Provider value={contextValue}>\n <div ref={placeholderRef} style={isAffixed && anchorRef.current ? { height: anchorRef.current.offsetHeight } : undefined}>\n {anchorContent}\n </div>\n </AnchorContext.Provider>\n )\n }\n\n return (\n <AnchorContext.Provider value={contextValue}>\n {anchorContent}\n </AnchorContext.Provider>\n )\n}\n\nexport const Anchor = Object.assign(AnchorComponent, {\n Link: AnchorLink,\n})\n"],"names":["AnchorContext","createContext","useAnchorContext","context","useContext","AnchorLink","href","title","children","className","activeLink","direction","registerLink","unregisterLink","handleClick","useEffect","isActive","isVertical","jsxs","jsx","e","AnchorComponent","items","offsetTop","bounds","getContainer","getCurrentAnchor","onChange","onClick","controlledActiveLink","affix","affixOffsetTop","replace","internalActiveLink","setInternalActiveLink","useState","links","setLinks","isAffixed","setIsAffixed","anchorRef","useRef","placeholderRef","isControlled","rawActiveLink","useCallback","prev","link","scrollToTarget","target","container","targetTop","containerTop","scrollTop","top","handleScroll","placeholderRect","shouldAffix","currentActive","containerEl","scrollHeight","clientHeight","element","contextValue","renderItems","linkItems","item","anchorContent","Anchor"],"mappings":";;AA8DA,MAAMA,IAAgBC,EAAyC,IAAI,GAE7DC,IAAmB,MAAM;AAC7B,QAAMC,IAAUC,EAAWJ,CAAa;AACxC,MAAI,CAACG;AACH,UAAM,IAAI,MAAM,2CAA2C;AAE7D,SAAOA;AACT,GAEME,IAAwC,CAAC;AAAA,EAC7C,MAAAC;AAAA,EACA,OAAAC;AAAA,EACA,UAAAC;AAAA,EACA,WAAAC,IAAY;AACd,MAAM;AACJ,QAAM,EAAE,YAAAC,GAAY,WAAAC,GAAW,cAAAC,GAAc,gBAAAC,GAAgB,aAAAC,EAAA,IAAgBZ,EAAA;AAE7E,EAAAa,EAAU,OACRH,EAAaN,CAAI,GACV,MAAMO,EAAeP,CAAI,IAC/B,CAACA,GAAMM,GAAcC,CAAc,CAAC;AAEvC,QAAMG,IAAWN,MAAeJ,GAC1BW,IAAaN,MAAc;AAEjC,SACE,gBAAAO,EAAC,OAAA,EAAI,WAAWD,IAAa,KAAK,gBAChC,UAAA;AAAA,IAAA,gBAAAE;AAAA,MAAC;AAAA,MAAA;AAAA,QACC,MAAM,IAAIb,CAAI;AAAA,QACd,SAAS,CAACc,MAAMN,EAAYM,GAAGd,GAAMC,CAAK;AAAA,QAC1C,WAAW;AAAA;AAAA,YAEPU,IAAa,yBAAyB,sBAAsB;AAAA,YAC5DD,IACE,4CACA,8FACJ;AAAA,YACEP,CAAS;AAAA,UACX,KAAA;AAAA,QAED,UAAAF;AAAA,MAAA;AAAA,IAAA;AAAA,IAEFC,KACC,gBAAAW,EAAC,OAAA,EAAI,WAAWF,IAAa,SAAS,eACnC,UAAAT,EAAA,CACH;AA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A,GAD5BA,EAAK,IAEtB,CACD,GAGGC,IACJ,gBAAAhD;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,KAAKqB;AAAA,MACL,WAAW;AAAA,UACP7B,MAAc,eAAe,sBAAsB,eAAe;AAAA,UAClE2B,IAAY,qCAAqC,EAAE;AAAA,UACnD7B,CAAS;AAAA,QACX,KAAA;AAAA,MACF,OAAO6B,IAAY,EAAE,KAAKP,MAAmB;AAAA,MAE5C,UAAAT,IAAQ0C,EAAY1C,CAAK,IAAId;AAAA,IAAA;AAAA,EAAA;AAIlC,SAAIsB,IAEA,gBAAAX,EAACnB,EAAc,UAAd,EAAuB,OAAO+D,GAC7B,UAAA,gBAAA5C,EAAC,OAAA,EAAI,KAAKuB,GAAgB,OAAOJ,KAAaE,EAAU,UAAU,EAAE,QAAQA,EAAU,QAAQ,aAAA,IAAiB,QAC5G,UAAA2B,EAAA,CACH,EAAA,CACF,sBAKDnE,EAAc,UAAd,EAAuB,OAAO+D,GAC5B,UAAAI,GACH;AAEJ,GAEaC,KAAS,OAAO,OAAO/C,GAAiB;AAAA,EACnD,MAAMhB;AACR,CAAC;"}
|
|
1
|
+
{"version":3,"file":"Anchor.js","sources":["../../src/components/Anchor.tsx"],"sourcesContent":["import React, { useState, useEffect, useCallback, createContext, useContext, useRef } from 'react'\n\nexport interface AnchorLinkItem {\n /** Target element id (without #) */\n href: string\n /** Link title */\n title: React.ReactNode\n /** Nested links */\n children?: AnchorLinkItem[]\n}\n\nexport interface AnchorProps {\n /** Anchor links (alternative to Anchor.Link children) */\n items?: AnchorLinkItem[]\n /** Layout direction */\n direction?: 'horizontal' | 'vertical'\n /** Offset from top when calculating scroll position */\n offsetTop?: number\n /** Bounding distance of anchor area */\n bounds?: number\n /** Target scroll container (default: window) */\n getContainer?: () => HTMLElement | Window\n /** Customize the anchor highlight */\n getCurrentAnchor?: (activeLink: string) => string\n /** Callback when active link changes */\n onChange?: (activeLink: string) => void\n /** Callback when link is clicked */\n onClick?: (e: React.MouseEvent, link: { href: string; title: React.ReactNode }) => void\n /** Currently active link (controlled) */\n activeLink?: string\n /** Whether to fix the anchor when scrolling */\n affix?: boolean\n /** Pixels to offset from top when affix is true */\n affixOffsetTop?: number\n /** Replace history instead of push */\n replace?: boolean\n /** Custom class name */\n className?: string\n /** Anchor.Link children */\n children?: React.ReactNode\n 'data-testid'?: string\n}\n\nexport interface AnchorLinkProps {\n /** Target element id (without #) */\n href: string\n /** Link title */\n title: React.ReactNode\n /** Nested links */\n children?: React.ReactNode\n /** Custom class name */\n className?: string\n 'data-testid'?: string\n}\n\ninterface AnchorContextValue {\n activeLink: string\n direction: 'horizontal' | 'vertical'\n offsetTop: number\n registerLink: (href: string) => void\n unregisterLink: (href: string) => void\n handleClick: (e: React.MouseEvent, href: string, title: React.ReactNode) => void\n}\n\nconst AnchorContext = createContext<AnchorContextValue | null>(null)\n\nconst useAnchorContext = () => {\n const context = useContext(AnchorContext)\n if (!context) {\n throw new Error('Anchor.Link must be used within an Anchor')\n }\n return context\n}\n\nconst AnchorLink: React.FC<AnchorLinkProps> = ({\n href,\n title,\n children,\n className = '',\n 'data-testid': testId,\n}) => {\n const { activeLink, direction, registerLink, unregisterLink, handleClick } = useAnchorContext()\n\n useEffect(() => {\n registerLink(href)\n return () => unregisterLink(href)\n }, [href, registerLink, unregisterLink])\n\n const isActive = activeLink === href\n const isVertical = direction === 'vertical'\n\n return (\n <div className={isVertical ? '' : 'inline-block'}>\n <a\n href={`#${href}`}\n onClick={(e) => handleClick(e, href, title)}\n className={`\n block text-sm transition-colors\n ${isVertical ? 'py-1 pl-3 border-l-2' : 'px-3 py-1 border-b-2'}\n ${isActive\n ? 'text-primary border-primary font-medium'\n : 'text-base-content/70 border-transparent hover:text-base-content hover:border-base-content/30'\n }\n ${className}\n `.trim()}\n data-testid={testId}\n >\n {title}\n </a>\n {children && (\n <div className={isVertical ? 'pl-3' : 'inline-flex'}>\n {children}\n </div>\n )}\n </div>\n )\n}\n\nconst AnchorComponent: React.FC<AnchorProps> = ({\n items,\n direction = 'vertical',\n offsetTop = 0,\n bounds = 5,\n getContainer,\n getCurrentAnchor,\n onChange,\n onClick,\n activeLink: controlledActiveLink,\n affix = false,\n affixOffsetTop = 0,\n replace = false,\n className = '',\n children,\n 'data-testid': testId,\n}) => {\n const [internalActiveLink, setInternalActiveLink] = useState('')\n const [links, setLinks] = useState<string[]>([])\n const [isAffixed, setIsAffixed] = useState(false)\n const anchorRef = useRef<HTMLDivElement>(null)\n const placeholderRef = useRef<HTMLDivElement>(null)\n\n const isControlled = controlledActiveLink !== undefined\n const rawActiveLink = isControlled ? controlledActiveLink : internalActiveLink\n const activeLink = getCurrentAnchor ? getCurrentAnchor(rawActiveLink) : rawActiveLink\n\n const registerLink = useCallback((href: string) => {\n setLinks((prev) => (prev.includes(href) ? prev : [...prev, href]))\n }, [])\n\n const unregisterLink = useCallback((href: string) => {\n setLinks((prev) => prev.filter((link) => link !== href))\n }, [])\n\n const scrollToTarget = useCallback((href: string) => {\n const target = document.getElementById(href)\n if (target) {\n const container = getContainer?.() ?? window\n const targetTop = target.getBoundingClientRect().top\n const containerTop = container === window\n ? 0\n : (container as HTMLElement).getBoundingClientRect().top\n const scrollTop = container === window\n ? window.scrollY\n : (container as HTMLElement).scrollTop\n\n const top = targetTop - containerTop + scrollTop - offsetTop\n\n if (container === window) {\n window.scrollTo({ top, behavior: 'smooth' })\n } else {\n (container as HTMLElement).scrollTo({ top, behavior: 'smooth' })\n }\n\n // Update URL hash\n if (replace) {\n window.history.replaceState(null, '', `#${href}`)\n } else {\n window.history.pushState(null, '', `#${href}`)\n }\n }\n }, [getContainer, offsetTop, replace])\n\n const handleClick = useCallback((\n e: React.MouseEvent,\n href: string,\n title: React.ReactNode\n ) => {\n e.preventDefault()\n onClick?.(e, { href, title })\n scrollToTarget(href)\n\n if (!isControlled) {\n setInternalActiveLink(href)\n }\n onChange?.(href)\n }, [onClick, scrollToTarget, isControlled, onChange])\n\n // Affix logic\n useEffect(() => {\n if (!affix || !anchorRef.current) return\n\n const container = getContainer?.() ?? window\n\n const handleScroll = () => {\n if (!anchorRef.current || !placeholderRef.current) return\n\n const placeholderRect = placeholderRef.current.getBoundingClientRect()\n const containerTop = container === window\n ? 0\n : (container as HTMLElement).getBoundingClientRect().top\n\n const shouldAffix = placeholderRect.top - containerTop <= affixOffsetTop\n\n if (shouldAffix !== isAffixed) {\n setIsAffixed(shouldAffix)\n }\n }\n\n container.addEventListener('scroll', handleScroll, { passive: true })\n handleScroll()\n\n return () => container.removeEventListener('scroll', handleScroll)\n }, [affix, affixOffsetTop, getContainer, isAffixed])\n\n // Scroll spy\n useEffect(() => {\n if (links.length === 0) return\n\n const container = getContainer?.() ?? window\n\n const handleScroll = () => {\n let currentActive = ''\n const containerEl = container === window ? document.documentElement : container as HTMLElement\n const containerTop = container === window\n ? 0\n : containerEl.getBoundingClientRect().top\n\n // Check if scrolled to near the bottom\n const scrollTop = container === window ? window.scrollY : containerEl.scrollTop\n const scrollHeight = containerEl.scrollHeight\n const clientHeight = container === window ? window.innerHeight : containerEl.clientHeight\n const isNearBottom = scrollTop + clientHeight >= scrollHeight - 10\n\n // If near bottom, use the last link\n if (isNearBottom && links.length > 0) {\n currentActive = links[links.length - 1]\n } else {\n // Find the last element that has scrolled past the top (standard scroll spy behavior)\n for (const href of links) {\n const element = document.getElementById(href)\n if (element) {\n const rect = element.getBoundingClientRect()\n const distance = rect.top - containerTop - offsetTop\n\n // If element's top is within bounds of the threshold, it's the current section\n if (distance <= bounds) {\n currentActive = href\n }\n }\n }\n\n // If nothing matched, use the first link\n if (!currentActive && links.length > 0) {\n currentActive = links[0]\n }\n }\n\n if (currentActive && currentActive !== rawActiveLink) {\n if (!isControlled) {\n setInternalActiveLink(currentActive)\n }\n onChange?.(currentActive)\n }\n }\n\n container.addEventListener('scroll', handleScroll, { passive: true })\n handleScroll() // Initial check\n\n return () => container.removeEventListener('scroll', handleScroll)\n }, [links, getContainer, offsetTop, bounds, rawActiveLink, isControlled, onChange])\n\n const contextValue: AnchorContextValue = {\n activeLink,\n direction,\n offsetTop,\n registerLink,\n unregisterLink,\n handleClick,\n }\n const getTestId = (suffix: string) => (testId ? `${testId}-${suffix}` : undefined)\n\n const renderItems = (linkItems: AnchorLinkItem[]): React.ReactNode => {\n return linkItems.map((item) => (\n <AnchorLink key={item.href} href={item.href} title={item.title} data-testid={getTestId(`link-${item.href}`)}>\n {item.children && renderItems(item.children)}\n </AnchorLink>\n ))\n }\n\n const anchorContent = (\n <nav\n ref={anchorRef}\n className={`\n ${direction === 'horizontal' ? 'flex items-center' : 'flex flex-col'}\n ${isAffixed ? 'fixed bg-base-100 shadow-sm z-10' : ''}\n ${className}\n `.trim()}\n style={isAffixed ? { top: affixOffsetTop } : undefined}\n data-testid={testId}\n >\n {items ? renderItems(items) : children}\n </nav>\n )\n\n if (affix) {\n return (\n <AnchorContext.Provider value={contextValue}>\n <div ref={placeholderRef} style={isAffixed && anchorRef.current ? { height: anchorRef.current.offsetHeight } : undefined}>\n {anchorContent}\n </div>\n </AnchorContext.Provider>\n )\n }\n\n return (\n <AnchorContext.Provider value={contextValue}>\n {anchorContent}\n </AnchorContext.Provider>\n )\n}\n\nexport const Anchor = Object.assign(AnchorComponent, {\n Link: AnchorLink,\n})\n"],"names":["AnchorContext","createContext","useAnchorContext","context","useContext","AnchorLink","href","title","children","className","testId","activeLink","direction","registerLink","unregisterLink","handleClick","useEffect","isActive","isVertical","jsxs","jsx","e","AnchorComponent","items","offsetTop","bounds","getContainer","getCurrentAnchor","onChange","onClick","controlledActiveLink","affix","affixOffsetTop","replace","internalActiveLink","setInternalActiveLink","useState","links","setLinks","isAffixed","setIsAffixed","anchorRef","useRef","placeholderRef","isControlled","rawActiveLink","useCallback","prev","link","scrollToTarget","target","container","targetTop","containerTop","scrollTop","top","handleScroll","placeholderRect","shouldAffix","currentActive","containerEl","scrollHeight","clientHeight","element","contextValue","getTestId","suffix","renderItems","linkItems","item","anchorContent","Anchor"],"mappings":";;AAgEA,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IAAC;AAAA,IAAA;AAAA,MACC,KAAKqB;AAAA,MACL,WAAW;AAAA,UACP7B,MAAc,eAAe,sBAAsB,eAAe;AAAA,UAClE2B,IAAY,qCAAqC,EAAE;AAAA,UACnD9B,CAAS;AAAA,QACX,KAAA;AAAA,MACF,OAAO8B,IAAY,EAAE,KAAKP,MAAmB;AAAA,MAC7C,eAAatB;AAAA,MAEZ,UAAAa,IAAQ4C,EAAY5C,CAAK,IAAIf;AAAA,IAAA;AAAA,EAAA;AAIlC,SAAIuB,IAEA,gBAAAX,EAACpB,EAAc,UAAd,EAAuB,OAAOgE,GAC7B,UAAA,gBAAA5C,EAAC,OAAA,EAAI,KAAKuB,GAAgB,OAAOJ,KAAaE,EAAU,UAAU,EAAE,QAAQA,EAAU,QAAQ,aAAA,IAAiB,QAC5G,UAAA6B,EAAA,CACH,EAAA,CACF,sBAKDtE,EAAc,UAAd,EAAuB,OAAOgE,GAC5B,UAAAM,GACH;AAEJ,GAEaC,KAAS,OAAO,OAAOjD,IAAiB;AAAA,EACnD,MAAMjB;AACR,CAAC;"}
|
|
@@ -34,5 +34,6 @@ export interface AutocompleteProps extends Omit<React.HTMLAttributes<HTMLDivElem
|
|
|
34
34
|
onOpenChange?: (open: boolean) => void;
|
|
35
35
|
/** Activate first option by default */
|
|
36
36
|
defaultActiveFirstOption?: boolean;
|
|
37
|
+
'data-testid'?: string;
|
|
37
38
|
}
|
|
38
39
|
export declare const Autocomplete: React.FC<AutocompleteProps>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import { useId as
|
|
3
|
-
import { useConfig as
|
|
4
|
-
const
|
|
1
|
+
import { jsxs as z, jsx as o } from "react/jsx-runtime";
|
|
2
|
+
import { useId as pe, useState as D, useRef as A, useEffect as T } from "react";
|
|
3
|
+
import { useConfig as fe } from "../providers/ConfigProvider.js";
|
|
4
|
+
const be = "dropdown", he = "dropdown-bottom", me = "dropdown-open", ge = "dropdown-content", Ie = "menu", we = "input", xe = "input-xs", ve = "input-sm", ye = "input-md", Ce = "input-lg", $e = "input-xl", ke = "input-neutral", De = "input-primary", Ne = "input-secondary", je = "input-accent", Ee = "input-info", Se = "input-success", R = "input-warning", V = "input-error", Be = ({ onClick: l, className: I }) => /* @__PURE__ */ o(
|
|
5
5
|
"button",
|
|
6
6
|
{
|
|
7
7
|
type: "button",
|
|
@@ -11,169 +11,174 @@ const pe = "dropdown", fe = "dropdown-bottom", he = "dropdown-open", be = "dropd
|
|
|
11
11
|
tabIndex: -1,
|
|
12
12
|
children: /* @__PURE__ */ o("svg", { className: "w-4 h-4", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", "aria-hidden": "true", children: /* @__PURE__ */ o("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M6 18L18 6M6 6l12 12" }) })
|
|
13
13
|
}
|
|
14
|
-
),
|
|
14
|
+
), Te = ({
|
|
15
15
|
value: l,
|
|
16
16
|
defaultValue: I = "",
|
|
17
|
-
onChange:
|
|
18
|
-
onSelect:
|
|
19
|
-
onSearch:
|
|
20
|
-
options:
|
|
21
|
-
placeholder:
|
|
22
|
-
disabled:
|
|
23
|
-
size:
|
|
24
|
-
color:
|
|
25
|
-
status:
|
|
26
|
-
className:
|
|
27
|
-
allowCustomValue:
|
|
28
|
-
filterOption:
|
|
29
|
-
notFoundContent:
|
|
30
|
-
allowClear:
|
|
31
|
-
onClear:
|
|
32
|
-
open:
|
|
33
|
-
defaultOpen:
|
|
34
|
-
onOpenChange:
|
|
35
|
-
defaultActiveFirstOption:
|
|
36
|
-
|
|
17
|
+
onChange: w,
|
|
18
|
+
onSelect: K,
|
|
19
|
+
onSearch: P,
|
|
20
|
+
options: U,
|
|
21
|
+
placeholder: W = "Type to search...",
|
|
22
|
+
disabled: f = !1,
|
|
23
|
+
size: X,
|
|
24
|
+
color: N,
|
|
25
|
+
status: x,
|
|
26
|
+
className: F = "",
|
|
27
|
+
allowCustomValue: j = !0,
|
|
28
|
+
filterOption: E,
|
|
29
|
+
notFoundContent: H = "No results found",
|
|
30
|
+
allowClear: b,
|
|
31
|
+
onClear: q,
|
|
32
|
+
open: S,
|
|
33
|
+
defaultOpen: G = !1,
|
|
34
|
+
onOpenChange: J,
|
|
35
|
+
defaultActiveFirstOption: v = !0,
|
|
36
|
+
"data-testid": y,
|
|
37
|
+
...Q
|
|
37
38
|
}) => {
|
|
38
|
-
const { componentSize:
|
|
39
|
+
const { componentSize: Y } = fe(), Z = X ?? Y ?? "md", C = pe(), _ = `${C}-input`, B = `${C}-listbox`, $ = U.map(
|
|
39
40
|
(e) => typeof e == "string" ? { value: e, label: e } : e
|
|
40
|
-
), [h,
|
|
41
|
-
|
|
41
|
+
), [h, m] = D(I), [ee, te] = D(G), [n, r] = D(-1), g = A(null), i = A(null), L = S !== void 0, d = L ? S : ee, c = (e) => {
|
|
42
|
+
L || te(e), J?.(e);
|
|
42
43
|
};
|
|
43
|
-
|
|
44
|
+
T(() => {
|
|
44
45
|
if (l !== void 0) {
|
|
45
|
-
const e =
|
|
46
|
-
|
|
46
|
+
const e = $.find((t) => t.value === l);
|
|
47
|
+
m(e?.label || l);
|
|
47
48
|
}
|
|
48
|
-
}, [l,
|
|
49
|
-
const
|
|
50
|
-
(e) =>
|
|
51
|
-
), u = a.filter((e) => !e.disabled),
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
},
|
|
55
|
-
e.disabled || (
|
|
56
|
-
},
|
|
49
|
+
}, [l, $]);
|
|
50
|
+
const ne = (e, t) => e.label.toLowerCase().includes(t.toLowerCase()), a = $.filter(
|
|
51
|
+
(e) => E ? E(e, h) : ne(e, h)
|
|
52
|
+
), u = a.filter((e) => !e.disabled), se = (e) => {
|
|
53
|
+
const t = e.target.value;
|
|
54
|
+
m(t), c(!0), v && u.length > 0 ? r(0) : r(-1), P?.(t), j && w?.(t);
|
|
55
|
+
}, k = (e) => {
|
|
56
|
+
e.disabled || (m(e.label), c(!1), r(-1), w?.(e.value), K?.(e.value, e), g.current?.focus());
|
|
57
|
+
}, oe = (e) => {
|
|
57
58
|
if (!d && (e.key === "ArrowDown" || e.key === "ArrowUp")) {
|
|
58
|
-
c(!0),
|
|
59
|
+
c(!0), v && u.length > 0 && r(0);
|
|
59
60
|
return;
|
|
60
61
|
}
|
|
61
62
|
switch (e.key) {
|
|
62
63
|
case "ArrowDown":
|
|
63
|
-
e.preventDefault(), r((
|
|
64
|
-
for (let s =
|
|
64
|
+
e.preventDefault(), r((t) => {
|
|
65
|
+
for (let s = t + 1; s < a.length; s++)
|
|
65
66
|
if (!a[s].disabled) return s;
|
|
66
|
-
return
|
|
67
|
+
return t;
|
|
67
68
|
});
|
|
68
69
|
break;
|
|
69
70
|
case "ArrowUp":
|
|
70
|
-
e.preventDefault(), r((
|
|
71
|
-
for (let s =
|
|
71
|
+
e.preventDefault(), r((t) => {
|
|
72
|
+
for (let s = t - 1; s >= 0; s--)
|
|
72
73
|
if (!a[s].disabled) return s;
|
|
73
|
-
return
|
|
74
|
+
return t;
|
|
74
75
|
});
|
|
75
76
|
break;
|
|
76
77
|
case "Enter":
|
|
77
|
-
e.preventDefault(),
|
|
78
|
+
e.preventDefault(), n >= 0 && a[n] && !a[n].disabled ? k(a[n]) : !j && u.length > 0 && k(u[0]);
|
|
78
79
|
break;
|
|
79
80
|
case "Escape":
|
|
80
|
-
c(!1), r(-1),
|
|
81
|
+
c(!1), r(-1), g.current?.blur();
|
|
81
82
|
break;
|
|
82
83
|
}
|
|
83
|
-
},
|
|
84
|
-
c(!0),
|
|
85
|
-
},
|
|
84
|
+
}, re = () => {
|
|
85
|
+
c(!0), v && u.length > 0 && r(0);
|
|
86
|
+
}, ae = (e) => {
|
|
86
87
|
i.current && i.current.contains(e.relatedTarget) || setTimeout(() => c(!1), 200);
|
|
87
|
-
},
|
|
88
|
-
e.stopPropagation(),
|
|
89
|
-
},
|
|
90
|
-
xs:
|
|
91
|
-
sm:
|
|
92
|
-
md:
|
|
93
|
-
lg:
|
|
94
|
-
xl:
|
|
95
|
-
},
|
|
96
|
-
error:
|
|
97
|
-
warning:
|
|
98
|
-
}[
|
|
99
|
-
neutral:
|
|
100
|
-
primary:
|
|
101
|
-
secondary:
|
|
102
|
-
accent:
|
|
103
|
-
info:
|
|
104
|
-
success:
|
|
105
|
-
warning:
|
|
106
|
-
error:
|
|
107
|
-
}[
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
}, [
|
|
111
|
-
const
|
|
112
|
-
`${
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
].filter(Boolean).join(" ");
|
|
117
|
-
return /* @__PURE__ */
|
|
88
|
+
}, le = (e) => {
|
|
89
|
+
e.stopPropagation(), m(""), w?.(""), q?.(), g.current?.focus();
|
|
90
|
+
}, ce = {
|
|
91
|
+
xs: xe,
|
|
92
|
+
sm: ve,
|
|
93
|
+
md: ye,
|
|
94
|
+
lg: Ce,
|
|
95
|
+
xl: $e
|
|
96
|
+
}, ie = x ? {
|
|
97
|
+
error: V,
|
|
98
|
+
warning: R
|
|
99
|
+
}[x] : N ? {
|
|
100
|
+
neutral: ke,
|
|
101
|
+
primary: De,
|
|
102
|
+
secondary: Ne,
|
|
103
|
+
accent: je,
|
|
104
|
+
info: Ee,
|
|
105
|
+
success: Se,
|
|
106
|
+
warning: R,
|
|
107
|
+
error: V
|
|
108
|
+
}[N] : "";
|
|
109
|
+
T(() => {
|
|
110
|
+
n >= 0 && i.current && i.current.children[n]?.scrollIntoView({ block: "nearest" });
|
|
111
|
+
}, [n]);
|
|
112
|
+
const M = b && h && !f, de = typeof b == "object" && b.clearIcon ? b.clearIcon : null, O = (e) => `${C}-option-${e}`, ue = [
|
|
113
|
+
`${we} w-full`,
|
|
114
|
+
ce[Z],
|
|
115
|
+
ie,
|
|
116
|
+
M && "pr-10"
|
|
117
|
+
].filter(Boolean).join(" "), p = (e) => y ? `${y}-${e}` : void 0;
|
|
118
|
+
return /* @__PURE__ */ z(
|
|
118
119
|
"div",
|
|
119
120
|
{
|
|
120
|
-
className: `${
|
|
121
|
+
className: `${be} ${he} w-full ${d && !f ? me : ""} ${F}`,
|
|
121
122
|
"data-state": d ? "open" : "closed",
|
|
122
|
-
|
|
123
|
+
"data-testid": y,
|
|
124
|
+
...Q,
|
|
123
125
|
children: [
|
|
124
|
-
/* @__PURE__ */
|
|
126
|
+
/* @__PURE__ */ z("div", { className: "relative w-full", children: [
|
|
125
127
|
/* @__PURE__ */ o(
|
|
126
128
|
"input",
|
|
127
129
|
{
|
|
128
|
-
ref:
|
|
129
|
-
id:
|
|
130
|
+
ref: g,
|
|
131
|
+
id: _,
|
|
130
132
|
type: "text",
|
|
131
133
|
role: "combobox",
|
|
132
134
|
"aria-expanded": d,
|
|
133
135
|
"aria-haspopup": "listbox",
|
|
134
|
-
"aria-controls":
|
|
136
|
+
"aria-controls": B,
|
|
135
137
|
"aria-autocomplete": "list",
|
|
136
|
-
"aria-activedescendant":
|
|
137
|
-
"aria-invalid":
|
|
138
|
+
"aria-activedescendant": n >= 0 ? O(n) : void 0,
|
|
139
|
+
"aria-invalid": x === "error" ? !0 : void 0,
|
|
138
140
|
value: h,
|
|
139
|
-
onChange:
|
|
140
|
-
onKeyDown:
|
|
141
|
-
onFocus:
|
|
142
|
-
onBlur:
|
|
143
|
-
placeholder:
|
|
144
|
-
disabled:
|
|
145
|
-
className:
|
|
141
|
+
onChange: se,
|
|
142
|
+
onKeyDown: oe,
|
|
143
|
+
onFocus: re,
|
|
144
|
+
onBlur: ae,
|
|
145
|
+
placeholder: W,
|
|
146
|
+
disabled: f,
|
|
147
|
+
className: ue,
|
|
148
|
+
"data-testid": p("input")
|
|
146
149
|
}
|
|
147
150
|
),
|
|
148
|
-
|
|
151
|
+
M && /* @__PURE__ */ o("span", { className: "absolute right-3 top-1/2 -translate-y-1/2 z-10", "data-testid": p("clear"), children: de || /* @__PURE__ */ o(Be, { onClick: le }) })
|
|
149
152
|
] }),
|
|
150
|
-
d && !
|
|
153
|
+
d && !f && /* @__PURE__ */ o(
|
|
151
154
|
"ul",
|
|
152
155
|
{
|
|
153
156
|
ref: i,
|
|
154
|
-
id:
|
|
157
|
+
id: B,
|
|
155
158
|
role: "listbox",
|
|
156
159
|
"aria-label": "Suggestions",
|
|
157
160
|
tabIndex: -1,
|
|
158
|
-
className: `${
|
|
159
|
-
|
|
161
|
+
className: `${ge} ${Ie} bg-base-100 rounded-box z-50 w-full shadow-lg border border-base-300 max-h-60 overflow-auto flex-nowrap`,
|
|
162
|
+
"data-testid": p("listbox"),
|
|
163
|
+
children: a.length > 0 ? a.map((e, t) => /* @__PURE__ */ o("li", { children: /* @__PURE__ */ o(
|
|
160
164
|
"a",
|
|
161
165
|
{
|
|
162
|
-
id:
|
|
166
|
+
id: O(t),
|
|
163
167
|
role: "option",
|
|
164
|
-
"aria-selected":
|
|
168
|
+
"aria-selected": n === t,
|
|
165
169
|
"aria-disabled": e.disabled,
|
|
166
170
|
onMouseDown: (s) => {
|
|
167
|
-
s.preventDefault(),
|
|
171
|
+
s.preventDefault(), k(e);
|
|
168
172
|
},
|
|
169
|
-
onMouseEnter: () => !e.disabled && r(
|
|
173
|
+
onMouseEnter: () => !e.disabled && r(t),
|
|
170
174
|
className: [
|
|
171
|
-
|
|
175
|
+
t === n && !e.disabled && "active",
|
|
172
176
|
e.disabled && "disabled text-base-content/40 cursor-not-allowed"
|
|
173
177
|
].filter(Boolean).join(" "),
|
|
178
|
+
"data-testid": p(`option-${e.value || t}`),
|
|
174
179
|
children: e.label
|
|
175
180
|
}
|
|
176
|
-
) }, e.value)) : /* @__PURE__ */ o("li", { className: "disabled", children: /* @__PURE__ */ o("span", { className: "text-base-content/60 text-center cursor-default", children:
|
|
181
|
+
) }, e.value)) : /* @__PURE__ */ o("li", { className: "disabled", "data-testid": p("empty"), children: /* @__PURE__ */ o("span", { className: "text-base-content/60 text-center cursor-default", children: H }) })
|
|
177
182
|
}
|
|
178
183
|
)
|
|
179
184
|
]
|
|
@@ -181,6 +186,6 @@ const pe = "dropdown", fe = "dropdown-bottom", he = "dropdown-open", be = "dropd
|
|
|
181
186
|
);
|
|
182
187
|
};
|
|
183
188
|
export {
|
|
184
|
-
|
|
189
|
+
Te as Autocomplete
|
|
185
190
|
};
|
|
186
191
|
//# sourceMappingURL=Autocomplete.js.map
|