@ztwoint/z-ui 0.1.97 → 0.1.98
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/segmented-control/controller.d.ts +4 -1
- package/dist/components/segmented-control/controller.js +27 -13
- package/dist/components/segmented-control/use-segmented-control.hook.d.ts +1 -0
- package/dist/components/segmented-control/use-segmented-control.hook.js +15 -15
- package/dist/types/components/segmented-control/controller.d.ts +4 -1
- package/dist/types/components/segmented-control/use-segmented-control.hook.d.ts +1 -0
- package/package.json +1 -1
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
interface SegmentedControlProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
2
|
+
value?: string;
|
|
3
|
+
defaultValue?: string;
|
|
4
|
+
onValueChange?: (id: string) => void;
|
|
2
5
|
handleOnClick?: (id?: string) => void;
|
|
3
6
|
className?: string;
|
|
4
7
|
children: React.ReactNode;
|
|
5
8
|
}
|
|
6
|
-
declare function SegmentedControl({ handleOnClick, className, children, ...props }: SegmentedControlProps): import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
declare function SegmentedControl({ value, defaultValue, onValueChange, handleOnClick, className, children, ...props }: SegmentedControlProps): import("react/jsx-runtime").JSX.Element;
|
|
7
10
|
export { SegmentedControl, type SegmentedControlProps };
|
|
@@ -1,22 +1,36 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { cn as
|
|
3
|
-
import { useSegmentedControl as
|
|
4
|
-
function
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { jsx as u } from "react/jsx-runtime";
|
|
2
|
+
import { cn as b } from "../../lib/utils.js";
|
|
3
|
+
import { useSegmentedControl as n } from "./use-segmented-control.hook.js";
|
|
4
|
+
function l({
|
|
5
|
+
value: o,
|
|
6
|
+
defaultValue: m,
|
|
7
|
+
onValueChange: r,
|
|
8
|
+
handleOnClick: t,
|
|
9
|
+
className: d,
|
|
10
|
+
children: i,
|
|
11
|
+
...s
|
|
12
|
+
}) {
|
|
13
|
+
const { containerRef: f, handleClick: c } = n({
|
|
14
|
+
onSelect: (e) => {
|
|
15
|
+
e && (r == null || r(e), t == null || t(e));
|
|
16
|
+
},
|
|
17
|
+
defaultSelectedId: o ?? m
|
|
18
|
+
});
|
|
19
|
+
return /* @__PURE__ */ u(
|
|
7
20
|
"div",
|
|
8
21
|
{
|
|
9
|
-
ref:
|
|
10
|
-
onClick:
|
|
11
|
-
className:
|
|
22
|
+
ref: f,
|
|
23
|
+
onClick: c,
|
|
24
|
+
className: b(
|
|
12
25
|
"inline-flex items-start bg-background-neutral-medium rounded-lg border-2 border-stroke-solid-medium",
|
|
13
|
-
|
|
26
|
+
d
|
|
14
27
|
),
|
|
15
|
-
...
|
|
16
|
-
|
|
28
|
+
...s,
|
|
29
|
+
"data-selected-id": o,
|
|
30
|
+
children: i
|
|
17
31
|
}
|
|
18
32
|
);
|
|
19
33
|
}
|
|
20
34
|
export {
|
|
21
|
-
|
|
35
|
+
l as SegmentedControl
|
|
22
36
|
};
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import { useRef as u, useEffect as
|
|
2
|
-
function
|
|
3
|
-
const { onSelect:
|
|
4
|
-
|
|
1
|
+
import { useRef as u, useEffect as n, useCallback as o } from "react";
|
|
2
|
+
function l(s = {}) {
|
|
3
|
+
const { onSelect: e, defaultSelectedId: a } = s, r = u(null);
|
|
4
|
+
n(() => {
|
|
5
5
|
if (!r.current) return;
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
}, [
|
|
9
|
-
const
|
|
10
|
-
(
|
|
6
|
+
const d = a ? `[data-id="${a}"]` : "[data-id]", t = r.current.querySelector(d);
|
|
7
|
+
t && !t.hasAttribute("data-selected") && (t.setAttribute("data-selected", "true"), t.dataset.id && (e == null || e(t.dataset.id)));
|
|
8
|
+
}, [e, a]);
|
|
9
|
+
const c = o(
|
|
10
|
+
(d) => {
|
|
11
11
|
if (!r.current) return;
|
|
12
|
-
const
|
|
13
|
-
|
|
12
|
+
const t = d.target.closest("[data-id]");
|
|
13
|
+
t && (Array.from(r.current.children).forEach((i) => {
|
|
14
14
|
i.removeAttribute("data-selected");
|
|
15
|
-
}),
|
|
15
|
+
}), t.setAttribute("data-selected", "true"), t.dataset.id && (e == null || e(t.dataset.id)));
|
|
16
16
|
},
|
|
17
|
-
[
|
|
17
|
+
[e]
|
|
18
18
|
);
|
|
19
|
-
return { containerRef: r, handleClick:
|
|
19
|
+
return { containerRef: r, handleClick: c };
|
|
20
20
|
}
|
|
21
21
|
export {
|
|
22
|
-
|
|
22
|
+
l as useSegmentedControl
|
|
23
23
|
};
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
interface SegmentedControlProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
2
|
+
value?: string;
|
|
3
|
+
defaultValue?: string;
|
|
4
|
+
onValueChange?: (id: string) => void;
|
|
2
5
|
handleOnClick?: (id?: string) => void;
|
|
3
6
|
className?: string;
|
|
4
7
|
children: React.ReactNode;
|
|
5
8
|
}
|
|
6
|
-
declare function SegmentedControl({ handleOnClick, className, children, ...props }: SegmentedControlProps): import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
declare function SegmentedControl({ value, defaultValue, onValueChange, handleOnClick, className, children, ...props }: SegmentedControlProps): import("react/jsx-runtime").JSX.Element;
|
|
7
10
|
export { SegmentedControl, type SegmentedControlProps };
|