@arun-dev/headless 0.4.0 → 2.0.0
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/README.md +18 -0
- package/dist/button/index.cjs +253 -0
- package/dist/button/index.d.cts +44 -0
- package/dist/button/index.d.ts +44 -0
- package/dist/button/index.js +33 -0
- package/dist/chunk-ER7IAVR5.js +96 -0
- package/dist/{chunk-I477HMLD.js → chunk-IGKX2XWC.js} +13 -83
- package/dist/chunk-UEIB3I3T.js +36 -0
- package/dist/index.cjs +12 -50
- package/dist/index.d.cts +12 -26
- package/dist/index.d.ts +12 -26
- package/dist/index.js +4 -6
- package/dist/switch/index.cjs +168 -100
- package/dist/switch/index.d.cts +14 -4
- package/dist/switch/index.d.ts +14 -4
- package/dist/switch/index.js +34 -24
- package/package.json +11 -1
package/dist/switch/index.js
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useControlled
|
|
3
|
+
} from "../chunk-UEIB3I3T.js";
|
|
4
|
+
import {
|
|
5
|
+
retractActivationProps,
|
|
6
|
+
useButton
|
|
7
|
+
} from "../chunk-ER7IAVR5.js";
|
|
1
8
|
import {
|
|
2
9
|
__export,
|
|
3
10
|
booleanAttribute,
|
|
4
11
|
disabledAttribute,
|
|
5
|
-
useButton,
|
|
6
|
-
useControlled,
|
|
7
12
|
useRender
|
|
8
|
-
} from "../chunk-
|
|
13
|
+
} from "../chunk-IGKX2XWC.js";
|
|
9
14
|
|
|
10
15
|
// src/switch/index.parts.ts
|
|
11
16
|
var index_parts_exports = {};
|
|
@@ -15,7 +20,7 @@ __export(index_parts_exports, {
|
|
|
15
20
|
});
|
|
16
21
|
|
|
17
22
|
// src/switch/root/SwitchRoot.tsx
|
|
18
|
-
import { useMemo } from "react";
|
|
23
|
+
import { cloneElement, useMemo } from "react";
|
|
19
24
|
|
|
20
25
|
// src/switch/SwitchRootContext.ts
|
|
21
26
|
import { createContext, useContext } from "react";
|
|
@@ -39,6 +44,7 @@ import { jsx, jsxs } from "react/jsx-runtime";
|
|
|
39
44
|
function SwitchRoot({
|
|
40
45
|
checked: checkedProp,
|
|
41
46
|
defaultChecked,
|
|
47
|
+
nativeButton,
|
|
42
48
|
onCheckedChange,
|
|
43
49
|
disabled = false,
|
|
44
50
|
name,
|
|
@@ -55,29 +61,32 @@ function SwitchRoot({
|
|
|
55
61
|
state: "checked"
|
|
56
62
|
});
|
|
57
63
|
const state = useMemo(() => ({ checked, disabled }), [checked, disabled]);
|
|
58
|
-
const isNativeButton = render === void 0 || render.type === "button";
|
|
59
|
-
const
|
|
64
|
+
const isNativeButton = nativeButton ?? (render === void 0 || render.type === "button");
|
|
65
|
+
const { props: consumerProps, ref: buttonRef } = useButton({
|
|
66
|
+
disabled,
|
|
67
|
+
native: isNativeButton,
|
|
68
|
+
props: rest
|
|
69
|
+
});
|
|
70
|
+
const safeRender = disabled && !isNativeButton && render !== void 0 ? cloneElement(render, retractActivationProps(render.props)) : render;
|
|
60
71
|
const element = useRender({
|
|
61
|
-
render,
|
|
72
|
+
render: safeRender,
|
|
62
73
|
defaultTagName: "button",
|
|
63
74
|
state,
|
|
64
75
|
stateAttributes: switchStateAttributes,
|
|
65
|
-
props:
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
consumerProps
|
|
80
|
-
]
|
|
76
|
+
props: {
|
|
77
|
+
role: "switch",
|
|
78
|
+
"aria-checked": checked,
|
|
79
|
+
className,
|
|
80
|
+
children,
|
|
81
|
+
ref: buttonRef,
|
|
82
|
+
onClick() {
|
|
83
|
+
if (disabled) return;
|
|
84
|
+
const next = !checked;
|
|
85
|
+
setChecked(next);
|
|
86
|
+
onCheckedChange?.(next);
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
consumerProps
|
|
81
90
|
});
|
|
82
91
|
return /* @__PURE__ */ jsxs(SwitchRootContext.Provider, { value: state, children: [
|
|
83
92
|
element,
|
|
@@ -98,7 +107,8 @@ function SwitchThumb({
|
|
|
98
107
|
defaultTagName: "span",
|
|
99
108
|
state,
|
|
100
109
|
stateAttributes: switchStateAttributes,
|
|
101
|
-
props:
|
|
110
|
+
props: { "aria-hidden": true, className, children },
|
|
111
|
+
consumerProps: rest
|
|
102
112
|
});
|
|
103
113
|
}
|
|
104
114
|
export {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arun-dev/headless",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Unstyled React behaviour primitives — render engine, controlled/uncontrolled state, and data-* state projection. Ships no CSS and no class names.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -34,6 +34,16 @@
|
|
|
34
34
|
"default": "./dist/index.cjs"
|
|
35
35
|
}
|
|
36
36
|
},
|
|
37
|
+
"./button": {
|
|
38
|
+
"import": {
|
|
39
|
+
"types": "./dist/button/index.d.ts",
|
|
40
|
+
"default": "./dist/button/index.js"
|
|
41
|
+
},
|
|
42
|
+
"require": {
|
|
43
|
+
"types": "./dist/button/index.d.cts",
|
|
44
|
+
"default": "./dist/button/index.cjs"
|
|
45
|
+
}
|
|
46
|
+
},
|
|
37
47
|
"./switch": {
|
|
38
48
|
"import": {
|
|
39
49
|
"types": "./dist/switch/index.d.ts",
|