@konstructio/ui 0.0.12-alpha.20 → 0.0.12-alpha.21

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,103 +1,103 @@
1
- import { jsxs as P, jsx as u } from "react/jsx-runtime";
2
- import * as p from "react";
3
- import { forwardRef as _, useState as H, useRef as A, useId as M, useImperativeHandle as $, useEffect as j, useCallback as z } from "react";
4
- import { a as B, c as q, b as F } from "../../index-Cva-e5M4.js";
5
- import { u as O } from "../../index-B_6_jmOO.js";
6
- import { u as V, a as D } from "../../index-4ecjw_Aj.js";
7
- import { P as g } from "../../index-D7QNmo_D.js";
1
+ import { jsxs as P, jsx as i } from "react/jsx-runtime";
2
+ import * as h from "react";
3
+ import { forwardRef as _, useRef as H, useId as M, useImperativeHandle as $, useEffect as j } from "react";
4
+ import { a as z, c as B, b as q } from "../../index-Cva-e5M4.js";
5
+ import { u as A } from "../../index-B_6_jmOO.js";
6
+ import { u as F, a as O } from "../../index-4ecjw_Aj.js";
7
+ import { P as R } from "../../index-D7QNmo_D.js";
8
8
  import { cn as x } from "../../utils/index.js";
9
- import { thumbVariants as L, switchVariants as U } from "./Switch.variants.js";
10
- import { useTheme as W } from "../../contexts/theme.hook.js";
11
- var k = "Switch", [X, ie] = q(k), [G, J] = X(k), R = p.forwardRef(
12
- (e, s) => {
9
+ import { thumbVariants as V, switchVariants as D } from "./Switch.variants.js";
10
+ import { useTheme as L } from "../../contexts/theme.hook.js";
11
+ var S = "Switch", [U, ae] = B(S), [W, X] = U(S), y = h.forwardRef(
12
+ (e, d) => {
13
13
  const {
14
14
  __scopeSwitch: t,
15
- name: c,
16
- checked: n,
17
- defaultChecked: h,
18
- required: o,
19
- disabled: a,
20
- value: i = "on",
15
+ name: s,
16
+ checked: a,
17
+ defaultChecked: n,
18
+ required: u,
19
+ disabled: r,
20
+ value: o = "on",
21
21
  onCheckedChange: m,
22
- form: r,
22
+ form: c,
23
23
  ...l
24
- } = e, [d, b] = p.useState(null), v = O(s, (C) => b(C)), f = p.useRef(!1), w = d ? r || !!d.closest("form") : !0, [S = !1, T] = B({
25
- prop: n,
26
- defaultProp: h,
24
+ } = e, [p, b] = h.useState(null), w = A(d, (k) => b(k)), f = h.useRef(!1), C = p ? c || !!p.closest("form") : !0, [v = !1, g] = z({
25
+ prop: a,
26
+ defaultProp: n,
27
27
  onChange: m
28
28
  });
29
- return /* @__PURE__ */ P(G, { scope: t, checked: S, disabled: a, children: [
30
- /* @__PURE__ */ u(
31
- g.button,
29
+ return /* @__PURE__ */ P(W, { scope: t, checked: v, disabled: r, children: [
30
+ /* @__PURE__ */ i(
31
+ R.button,
32
32
  {
33
33
  type: "button",
34
34
  role: "switch",
35
- "aria-checked": S,
36
- "aria-required": o,
37
- "data-state": E(S),
38
- "data-disabled": a ? "" : void 0,
39
- disabled: a,
40
- value: i,
35
+ "aria-checked": v,
36
+ "aria-required": u,
37
+ "data-state": T(v),
38
+ "data-disabled": r ? "" : void 0,
39
+ disabled: r,
40
+ value: o,
41
41
  ...l,
42
- ref: v,
43
- onClick: F(e.onClick, (C) => {
44
- T((I) => !I), w && (f.current = C.isPropagationStopped(), f.current || C.stopPropagation());
42
+ ref: w,
43
+ onClick: q(e.onClick, (k) => {
44
+ g((I) => !I), C && (f.current = k.isPropagationStopped(), f.current || k.stopPropagation());
45
45
  })
46
46
  }
47
47
  ),
48
- w && /* @__PURE__ */ u(
49
- K,
48
+ C && /* @__PURE__ */ i(
49
+ G,
50
50
  {
51
- control: d,
51
+ control: p,
52
52
  bubbles: !f.current,
53
- name: c,
54
- value: i,
55
- checked: S,
56
- required: o,
57
- disabled: a,
58
- form: r,
53
+ name: s,
54
+ value: o,
55
+ checked: v,
56
+ required: u,
57
+ disabled: r,
58
+ form: c,
59
59
  style: { transform: "translateX(-100%)" }
60
60
  }
61
61
  )
62
62
  ] });
63
63
  }
64
64
  );
65
- R.displayName = k;
66
- var y = "SwitchThumb", N = p.forwardRef(
67
- (e, s) => {
68
- const { __scopeSwitch: t, ...c } = e, n = J(y, t);
69
- return /* @__PURE__ */ u(
70
- g.span,
65
+ y.displayName = S;
66
+ var N = "SwitchThumb", E = h.forwardRef(
67
+ (e, d) => {
68
+ const { __scopeSwitch: t, ...s } = e, a = X(N, t);
69
+ return /* @__PURE__ */ i(
70
+ R.span,
71
71
  {
72
- "data-state": E(n.checked),
73
- "data-disabled": n.disabled ? "" : void 0,
74
- ...c,
75
- ref: s
72
+ "data-state": T(a.checked),
73
+ "data-disabled": a.disabled ? "" : void 0,
74
+ ...s,
75
+ ref: d
76
76
  }
77
77
  );
78
78
  }
79
79
  );
80
- N.displayName = y;
81
- var K = (e) => {
82
- const { control: s, checked: t, bubbles: c = !0, ...n } = e, h = p.useRef(null), o = V(t), a = D(s);
83
- return p.useEffect(() => {
84
- const i = h.current, m = window.HTMLInputElement.prototype, l = Object.getOwnPropertyDescriptor(m, "checked").set;
85
- if (o !== t && l) {
86
- const d = new Event("click", { bubbles: c });
87
- l.call(i, t), i.dispatchEvent(d);
80
+ E.displayName = N;
81
+ var G = (e) => {
82
+ const { control: d, checked: t, bubbles: s = !0, ...a } = e, n = h.useRef(null), u = F(t), r = O(d);
83
+ return h.useEffect(() => {
84
+ const o = n.current, m = window.HTMLInputElement.prototype, l = Object.getOwnPropertyDescriptor(m, "checked").set;
85
+ if (u !== t && l) {
86
+ const p = new Event("click", { bubbles: s });
87
+ l.call(o, t), o.dispatchEvent(p);
88
88
  }
89
- }, [o, t, c]), /* @__PURE__ */ u(
89
+ }, [u, t, s]), /* @__PURE__ */ i(
90
90
  "input",
91
91
  {
92
92
  type: "checkbox",
93
93
  "aria-hidden": !0,
94
94
  defaultChecked: t,
95
- ...n,
95
+ ...a,
96
96
  tabIndex: -1,
97
- ref: h,
97
+ ref: n,
98
98
  style: {
99
99
  ...e.style,
100
- ...a,
100
+ ...r,
101
101
  position: "absolute",
102
102
  pointerEvents: "none",
103
103
  opacity: 0,
@@ -106,68 +106,66 @@ var K = (e) => {
106
106
  }
107
107
  );
108
108
  };
109
- function E(e) {
109
+ function T(e) {
110
110
  return e ? "checked" : "unchecked";
111
111
  }
112
- var Q = R, Y = N;
113
- const ue = _(
112
+ var J = y, K = E;
113
+ const ne = _(
114
114
  ({
115
115
  name: e,
116
- defaultChecked: s,
117
- alignment: t = "horizontal",
118
- theme: c,
119
- thumbClassName: n,
120
- className: h,
121
- label: o
122
- }, a) => {
123
- const [i, m] = H(s ?? !1), r = A(null), l = M(), { theme: d } = W(), b = c ?? d, v = e ? `${l}-${e}` : l;
124
- $(a, () => r.current, [r]), j(() => {
125
- r.current && (r.current.value = `${i}`);
126
- }, [i]);
127
- const f = z(
128
- (w) => m(w),
129
- []
130
- );
131
- return /* @__PURE__ */ P(
116
+ alignment: d = "horizontal",
117
+ theme: t,
118
+ thumbClassName: s,
119
+ className: a,
120
+ label: n,
121
+ defaultChecked: u,
122
+ onChange: r,
123
+ value: o
124
+ }, m) => {
125
+ const c = H(null), l = M(), { theme: p } = L(), b = t ?? p, w = e ? `${l}-${e}` : l;
126
+ return $(m, () => c.current, [c]), j(() => {
127
+ c.current && (c.current.value = `${o}`);
128
+ }, [o]), /* @__PURE__ */ P(
132
129
  "div",
133
130
  {
134
131
  className: x(
135
132
  "w-full flex gap-3",
136
- t === "vertical" ? "flex-col" : "flex-row"
133
+ d === "vertical" ? "flex-col" : "flex-row"
137
134
  ),
138
135
  children: [
139
- o ? /* @__PURE__ */ u(
136
+ n ? /* @__PURE__ */ i(
140
137
  "label",
141
138
  {
142
139
  className: "text-base",
143
- htmlFor: v,
140
+ htmlFor: w,
144
141
  style: { paddingRight: 15 },
145
- children: o
142
+ children: n
146
143
  }
147
144
  ) : null,
148
- /* @__PURE__ */ u(
149
- Q,
145
+ /* @__PURE__ */ i(
146
+ J,
150
147
  {
151
- id: v,
152
- defaultChecked: s,
153
- onCheckedChange: f,
154
- className: x(U({ theme: b, className: h })),
155
- "aria-label": o,
156
- children: /* @__PURE__ */ u(
157
- Y,
148
+ id: w,
149
+ defaultChecked: u,
150
+ checked: o,
151
+ onCheckedChange: (f) => r == null ? void 0 : r(f),
152
+ className: x(D({ theme: b, className: a })),
153
+ "aria-label": n,
154
+ children: /* @__PURE__ */ i(
155
+ K,
158
156
  {
159
- className: L({
157
+ className: V({
160
158
  theme: b,
161
- className: n
159
+ className: s
162
160
  })
163
161
  }
164
162
  )
165
163
  }
166
164
  ),
167
- /* @__PURE__ */ u(
165
+ /* @__PURE__ */ i(
168
166
  "input",
169
167
  {
170
- ref: r,
168
+ ref: c,
171
169
  name: e,
172
170
  type: "text",
173
171
  className: "hidden",
@@ -180,5 +178,5 @@ const ue = _(
180
178
  }
181
179
  );
182
180
  export {
183
- ue as Switch
181
+ ne as Switch
184
182
  };
package/dist/index.d.ts CHANGED
@@ -486,10 +486,12 @@ export declare const Switch: FC<SwitchProps>;
486
486
  declare interface SwitchProps extends VariantProps<typeof switchVariants> {
487
487
  alignment?: 'horizontal' | 'vertical';
488
488
  className?: string;
489
- defaultChecked?: boolean;
490
489
  label?: string;
491
490
  name?: string;
492
491
  thumbClassName?: string;
492
+ onChange?: (e: boolean) => void;
493
+ value?: boolean;
494
+ defaultChecked?: boolean;
493
495
  }
494
496
 
495
497
  declare const switchVariants: (props?: ({
package/dist/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@konstructio/ui",
3
3
  "description": "A set of reusable and customizable React components built for konstruct.io",
4
4
  "private": false,
5
- "version": "0.0.12-alpha.19",
5
+ "version": "0.0.12-alpha.20",
6
6
  "type": "module",
7
7
  "license": "MIT",
8
8
  "main": "dist/index.js",
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@konstructio/ui",
3
3
  "description": "A set of reusable and customizable React components built for konstruct.io",
4
4
  "private": false,
5
- "version": "0.0.12-alpha.20",
5
+ "version": "0.0.12-alpha.21",
6
6
  "type": "module",
7
7
  "license": "MIT",
8
8
  "main": "dist/index.js",