@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.
@@ -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 m } from "react/jsx-runtime";
2
- import { cn as d } from "../../lib/utils.js";
3
- import { useSegmentedControl as l } from "./use-segmented-control.hook.js";
4
- function a({ handleOnClick: e, className: o, children: r, ...n }) {
5
- const { containerRef: t, handleClick: i } = l({ onSelect: e });
6
- return /* @__PURE__ */ m(
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: t,
10
- onClick: i,
11
- className: d(
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
- o
26
+ d
14
27
  ),
15
- ...n,
16
- children: r
28
+ ...s,
29
+ "data-selected-id": o,
30
+ children: i
17
31
  }
18
32
  );
19
33
  }
20
34
  export {
21
- a as SegmentedControl
35
+ l as SegmentedControl
22
36
  };
@@ -1,5 +1,6 @@
1
1
  type UseSegmentedControlOptions = {
2
2
  onSelect?: (id?: string) => void;
3
+ defaultSelectedId?: string;
3
4
  };
4
5
  type UseSegmentedControlResult = {
5
6
  containerRef: React.RefObject<HTMLDivElement | null>;
@@ -1,23 +1,23 @@
1
- import { useRef as u, useEffect as c, useCallback as n } from "react";
2
- function o(d = {}) {
3
- const { onSelect: t } = d, r = u(null);
4
- c(() => {
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 e = r.current.querySelector("[data-id]");
7
- e && !e.hasAttribute("data-selected") && (e.setAttribute("data-selected", "true"), e.dataset.id && (t == null || t(e.dataset.id)));
8
- }, [t]);
9
- const s = n(
10
- (e) => {
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 a = e.target.closest("[data-id]");
13
- a && (Array.from(r.current.children).forEach((i) => {
12
+ const t = d.target.closest("[data-id]");
13
+ t && (Array.from(r.current.children).forEach((i) => {
14
14
  i.removeAttribute("data-selected");
15
- }), a.setAttribute("data-selected", "true"), a.dataset.id && (t == null || t(a.dataset.id)));
15
+ }), t.setAttribute("data-selected", "true"), t.dataset.id && (e == null || e(t.dataset.id)));
16
16
  },
17
- [t]
17
+ [e]
18
18
  );
19
- return { containerRef: r, handleClick: s };
19
+ return { containerRef: r, handleClick: c };
20
20
  }
21
21
  export {
22
- o as useSegmentedControl
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 };
@@ -1,5 +1,6 @@
1
1
  type UseSegmentedControlOptions = {
2
2
  onSelect?: (id?: string) => void;
3
+ defaultSelectedId?: string;
3
4
  };
4
5
  type UseSegmentedControlResult = {
5
6
  containerRef: React.RefObject<HTMLDivElement | null>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ztwoint/z-ui",
3
- "version": "0.1.97",
3
+ "version": "0.1.98",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",