@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.
- package/dist/components/Switch/Switch.js +99 -101
- package/dist/index.d.ts +3 -1
- package/dist/package.json +1 -1
- package/package.json +1 -1
|
@@ -1,103 +1,103 @@
|
|
|
1
|
-
import { jsxs as P, jsx as
|
|
2
|
-
import * as
|
|
3
|
-
import { forwardRef as _,
|
|
4
|
-
import { a as
|
|
5
|
-
import { u as
|
|
6
|
-
import { u as
|
|
7
|
-
import { P as
|
|
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
|
|
10
|
-
import { useTheme as
|
|
11
|
-
var
|
|
12
|
-
(e,
|
|
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:
|
|
16
|
-
checked:
|
|
17
|
-
defaultChecked:
|
|
18
|
-
required:
|
|
19
|
-
disabled:
|
|
20
|
-
value:
|
|
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:
|
|
22
|
+
form: c,
|
|
23
23
|
...l
|
|
24
|
-
} = e, [
|
|
25
|
-
prop:
|
|
26
|
-
defaultProp:
|
|
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(
|
|
30
|
-
/* @__PURE__ */
|
|
31
|
-
|
|
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":
|
|
36
|
-
"aria-required":
|
|
37
|
-
"data-state":
|
|
38
|
-
"data-disabled":
|
|
39
|
-
disabled:
|
|
40
|
-
value:
|
|
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:
|
|
43
|
-
onClick:
|
|
44
|
-
|
|
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
|
-
|
|
49
|
-
|
|
48
|
+
C && /* @__PURE__ */ i(
|
|
49
|
+
G,
|
|
50
50
|
{
|
|
51
|
-
control:
|
|
51
|
+
control: p,
|
|
52
52
|
bubbles: !f.current,
|
|
53
|
-
name:
|
|
54
|
-
value:
|
|
55
|
-
checked:
|
|
56
|
-
required:
|
|
57
|
-
disabled:
|
|
58
|
-
form:
|
|
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
|
-
|
|
66
|
-
var
|
|
67
|
-
(e,
|
|
68
|
-
const { __scopeSwitch: t, ...
|
|
69
|
-
return /* @__PURE__ */
|
|
70
|
-
|
|
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":
|
|
73
|
-
"data-disabled":
|
|
74
|
-
...
|
|
75
|
-
ref:
|
|
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
|
-
|
|
81
|
-
var
|
|
82
|
-
const { control:
|
|
83
|
-
return
|
|
84
|
-
const
|
|
85
|
-
if (
|
|
86
|
-
const
|
|
87
|
-
l.call(
|
|
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
|
-
}, [
|
|
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
|
-
...
|
|
95
|
+
...a,
|
|
96
96
|
tabIndex: -1,
|
|
97
|
-
ref:
|
|
97
|
+
ref: n,
|
|
98
98
|
style: {
|
|
99
99
|
...e.style,
|
|
100
|
-
...
|
|
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
|
|
109
|
+
function T(e) {
|
|
110
110
|
return e ? "checked" : "unchecked";
|
|
111
111
|
}
|
|
112
|
-
var
|
|
113
|
-
const
|
|
112
|
+
var J = y, K = E;
|
|
113
|
+
const ne = _(
|
|
114
114
|
({
|
|
115
115
|
name: e,
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
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
|
-
|
|
133
|
+
d === "vertical" ? "flex-col" : "flex-row"
|
|
137
134
|
),
|
|
138
135
|
children: [
|
|
139
|
-
|
|
136
|
+
n ? /* @__PURE__ */ i(
|
|
140
137
|
"label",
|
|
141
138
|
{
|
|
142
139
|
className: "text-base",
|
|
143
|
-
htmlFor:
|
|
140
|
+
htmlFor: w,
|
|
144
141
|
style: { paddingRight: 15 },
|
|
145
|
-
children:
|
|
142
|
+
children: n
|
|
146
143
|
}
|
|
147
144
|
) : null,
|
|
148
|
-
/* @__PURE__ */
|
|
149
|
-
|
|
145
|
+
/* @__PURE__ */ i(
|
|
146
|
+
J,
|
|
150
147
|
{
|
|
151
|
-
id:
|
|
152
|
-
defaultChecked:
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
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:
|
|
157
|
+
className: V({
|
|
160
158
|
theme: b,
|
|
161
|
-
className:
|
|
159
|
+
className: s
|
|
162
160
|
})
|
|
163
161
|
}
|
|
164
162
|
)
|
|
165
163
|
}
|
|
166
164
|
),
|
|
167
|
-
/* @__PURE__ */
|
|
165
|
+
/* @__PURE__ */ i(
|
|
168
166
|
"input",
|
|
169
167
|
{
|
|
170
|
-
ref:
|
|
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
|
-
|
|
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.
|
|
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.
|
|
5
|
+
"version": "0.0.12-alpha.21",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"main": "dist/index.js",
|