@destyler/toggle 0.0.6 → 0.0.7-beta.1
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/index.cjs +344 -12
- package/dist/index.d.cts +136 -4
- package/dist/index.d.mts +136 -4
- package/dist/index.d.ts +136 -4
- package/dist/index.mjs +341 -6
- package/package.json +9 -17
- package/README.md +0 -7
- package/dist/component.cjs +0 -259
- package/dist/component.d.cts +0 -549
- package/dist/component.d.mts +0 -549
- package/dist/component.d.ts +0 -549
- package/dist/component.mjs +0 -250
- package/dist/resolver.cjs +0 -22
- package/dist/resolver.d.cts +0 -6
- package/dist/resolver.d.mts +0 -6
- package/dist/resolver.d.ts +0 -6
- package/dist/resolver.mjs +0 -19
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,136 @@
|
|
|
1
|
-
|
|
2
|
-
import '
|
|
3
|
-
|
|
4
|
-
import '@
|
|
1
|
+
import * as _zag_js_anatomy from '@zag-js/anatomy';
|
|
2
|
+
import { RequiredBy, PropTypes, DirectionProperty, CommonProperties, Orientation, NormalizeProps } from '@zag-js/types';
|
|
3
|
+
export { Orientation } from '@zag-js/types';
|
|
4
|
+
import * as _zag_js_core from '@zag-js/core';
|
|
5
|
+
import { Machine, StateMachine } from '@zag-js/core';
|
|
6
|
+
|
|
7
|
+
declare const anatomy: _zag_js_anatomy.AnatomyInstance<"root" | "item">;
|
|
8
|
+
|
|
9
|
+
interface ValueChangeDetails {
|
|
10
|
+
value: string[];
|
|
11
|
+
}
|
|
12
|
+
type ElementIds = Partial<{
|
|
13
|
+
root: string;
|
|
14
|
+
item: (value: string) => string;
|
|
15
|
+
}>;
|
|
16
|
+
interface PublicContext extends DirectionProperty, CommonProperties {
|
|
17
|
+
/**
|
|
18
|
+
* The ids of the elements in the toggle. Useful for composition.
|
|
19
|
+
*/
|
|
20
|
+
ids?: ElementIds | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* Whether the toggle is disabled.
|
|
23
|
+
*/
|
|
24
|
+
disabled?: boolean | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* The values of the toggles in the group.
|
|
27
|
+
*/
|
|
28
|
+
value: string[];
|
|
29
|
+
/**
|
|
30
|
+
* Function to call when the toggle is clicked.
|
|
31
|
+
*/
|
|
32
|
+
onValueChange?: ((details: ValueChangeDetails) => void) | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* Whether to loop focus inside the toggle group.
|
|
35
|
+
* @default true
|
|
36
|
+
*/
|
|
37
|
+
loopFocus: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Whether to use roving tab index to manage focus.
|
|
40
|
+
* @default true
|
|
41
|
+
*/
|
|
42
|
+
rovingFocus?: boolean | undefined;
|
|
43
|
+
/**
|
|
44
|
+
* The orientation of the toggle group.
|
|
45
|
+
* @default "horizontal"
|
|
46
|
+
*/
|
|
47
|
+
orientation: Orientation;
|
|
48
|
+
/**
|
|
49
|
+
* Whether to allow multiple toggles to be selected.
|
|
50
|
+
*/
|
|
51
|
+
multiple?: boolean | undefined;
|
|
52
|
+
}
|
|
53
|
+
type UserDefinedContext = RequiredBy<PublicContext, 'id'>;
|
|
54
|
+
type ComputedContext = Readonly<{
|
|
55
|
+
currentLoopFocus: boolean;
|
|
56
|
+
}>;
|
|
57
|
+
interface PrivateContext {
|
|
58
|
+
/**
|
|
59
|
+
* @internal
|
|
60
|
+
* Whether the user is tabbing backward.
|
|
61
|
+
*/
|
|
62
|
+
isTabbingBackward: boolean;
|
|
63
|
+
/**
|
|
64
|
+
* @internal
|
|
65
|
+
* Whether the toggle was focused by a click.
|
|
66
|
+
*/
|
|
67
|
+
isClickFocus: boolean;
|
|
68
|
+
/**
|
|
69
|
+
* @internal
|
|
70
|
+
* The value of the toggle that was focused.
|
|
71
|
+
*/
|
|
72
|
+
focusedId: string | null;
|
|
73
|
+
/**
|
|
74
|
+
* @internal
|
|
75
|
+
* Whether the toggle group is within a toolbar.
|
|
76
|
+
* This is used to determine whether to use roving tab index.
|
|
77
|
+
*/
|
|
78
|
+
isWithinToolbar: boolean;
|
|
79
|
+
}
|
|
80
|
+
interface MachineContext extends PublicContext, PrivateContext, ComputedContext {
|
|
81
|
+
}
|
|
82
|
+
interface MachineState {
|
|
83
|
+
value: 'idle' | 'focused';
|
|
84
|
+
}
|
|
85
|
+
type State = StateMachine.State<MachineContext, MachineState>;
|
|
86
|
+
type Send = StateMachine.Send<StateMachine.AnyEventObject>;
|
|
87
|
+
type Service = Machine<MachineContext, MachineState, StateMachine.AnyEventObject>;
|
|
88
|
+
interface ItemProps {
|
|
89
|
+
value: string;
|
|
90
|
+
disabled?: boolean | undefined;
|
|
91
|
+
}
|
|
92
|
+
interface ItemState {
|
|
93
|
+
/**
|
|
94
|
+
* The underlying id of the item.
|
|
95
|
+
*/
|
|
96
|
+
id: string;
|
|
97
|
+
/**
|
|
98
|
+
* Whether the toggle item is disabled.
|
|
99
|
+
*/
|
|
100
|
+
disabled: boolean;
|
|
101
|
+
/**
|
|
102
|
+
* Whether the toggle item is pressed.
|
|
103
|
+
*/
|
|
104
|
+
pressed: boolean;
|
|
105
|
+
/**
|
|
106
|
+
* Whether the toggle item is focused.
|
|
107
|
+
*/
|
|
108
|
+
focused: boolean;
|
|
109
|
+
}
|
|
110
|
+
interface MachineApi<T extends PropTypes = PropTypes> {
|
|
111
|
+
/**
|
|
112
|
+
* The value of the toggle group.
|
|
113
|
+
*/
|
|
114
|
+
value: string[];
|
|
115
|
+
/**
|
|
116
|
+
* Function to set the value of the toggle group.
|
|
117
|
+
*/
|
|
118
|
+
setValue: (values: string[]) => void;
|
|
119
|
+
/**
|
|
120
|
+
* Returns the state of the toggle item.
|
|
121
|
+
*/
|
|
122
|
+
getItemState: (props: ItemProps) => ItemState;
|
|
123
|
+
getRootProps: () => T['element'];
|
|
124
|
+
getItemProps: (props: ItemProps) => T['button'];
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): MachineApi<T>;
|
|
128
|
+
|
|
129
|
+
declare function machine(userContext: UserDefinedContext): _zag_js_core.Machine<MachineContext, MachineState, _zag_js_core.StateMachine.AnyEventObject>;
|
|
130
|
+
|
|
131
|
+
declare const props: ("ids" | "disabled" | "value" | "onValueChange" | "loopFocus" | "rovingFocus" | "orientation" | "multiple" | "id" | "dir" | "getRootNode")[];
|
|
132
|
+
declare const splitProps: <Props extends Partial<UserDefinedContext>>(props: Props) => [Partial<UserDefinedContext>, Omit<Props, "ids" | "disabled" | "value" | "onValueChange" | "loopFocus" | "rovingFocus" | "orientation" | "multiple" | "id" | "dir" | "getRootNode">];
|
|
133
|
+
declare const itemProps: (keyof ItemProps)[];
|
|
134
|
+
declare const splitItemProps: <Props extends ItemProps>(props: Props) => [ItemProps, Omit<Props, keyof ItemProps>];
|
|
135
|
+
|
|
136
|
+
export { type MachineApi as Api, type UserDefinedContext as Context, type ElementIds, type ItemProps, type ItemState, type Service, type ValueChangeDetails, anatomy, connect, itemProps, machine, props, splitItemProps, splitProps };
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,341 @@
|
|
|
1
|
-
|
|
2
|
-
import '
|
|
3
|
-
import '@
|
|
4
|
-
import '@
|
|
5
|
-
import '@
|
|
6
|
-
import '@
|
|
1
|
+
import { createAnatomy } from '@zag-js/anatomy';
|
|
2
|
+
import { getEventKey } from '@zag-js/dom-event';
|
|
3
|
+
import { createScope, queryAll, nextById, prevById, dataAttr, isSelfTarget, isSafari, raf } from '@zag-js/dom-query';
|
|
4
|
+
import { first, last, compact, remove, add, isEqual, createSplitProps } from '@zag-js/utils';
|
|
5
|
+
import { createMachine, guards } from '@zag-js/core';
|
|
6
|
+
import { createProps } from '@zag-js/types';
|
|
7
|
+
|
|
8
|
+
const anatomy = createAnatomy("toggle").parts("root", "item");
|
|
9
|
+
const parts = anatomy.build();
|
|
10
|
+
|
|
11
|
+
const dom = createScope({
|
|
12
|
+
getRootId: (ctx) => ctx.ids?.root ?? `toggle:${ctx.id}`,
|
|
13
|
+
getItemId: (ctx, value) => ctx.ids?.item?.(value) ?? `toggle:${ctx.id}:${value}`,
|
|
14
|
+
getRootEl: (ctx) => dom.getById(ctx, dom.getRootId(ctx)),
|
|
15
|
+
getElements: (ctx) => {
|
|
16
|
+
const ownerId = CSS.escape(dom.getRootId(ctx));
|
|
17
|
+
const selector = `[data-ownedby='${ownerId}']:not([data-disabled])`;
|
|
18
|
+
return queryAll(dom.getRootEl(ctx), selector);
|
|
19
|
+
},
|
|
20
|
+
getFirstEl: (ctx) => first(dom.getElements(ctx)),
|
|
21
|
+
getLastEl: (ctx) => last(dom.getElements(ctx)),
|
|
22
|
+
getNextEl: (ctx, id) => nextById(dom.getElements(ctx), id, ctx.currentLoopFocus),
|
|
23
|
+
getPrevEl: (ctx, id) => prevById(dom.getElements(ctx), id, ctx.currentLoopFocus)
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
function connect(state, send, normalize) {
|
|
27
|
+
const value = state.context.value;
|
|
28
|
+
const disabled = state.context.disabled;
|
|
29
|
+
const isSingle = !state.context.multiple;
|
|
30
|
+
const rovingFocus = state.context.rovingFocus;
|
|
31
|
+
const isHorizontal = state.context.orientation === "horizontal";
|
|
32
|
+
function getItemState(props) {
|
|
33
|
+
const id = dom.getItemId(state.context, props.value);
|
|
34
|
+
return {
|
|
35
|
+
id,
|
|
36
|
+
disabled: Boolean(props.disabled || disabled),
|
|
37
|
+
pressed: !!value.includes(props.value),
|
|
38
|
+
focused: state.context.focusedId === id
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
value,
|
|
43
|
+
setValue(value2) {
|
|
44
|
+
send({ type: "VALUE.SET", value: value2 });
|
|
45
|
+
},
|
|
46
|
+
getRootProps() {
|
|
47
|
+
return normalize.element({
|
|
48
|
+
...parts.root.attrs,
|
|
49
|
+
"id": dom.getRootId(state.context),
|
|
50
|
+
"dir": state.context.dir,
|
|
51
|
+
"role": isSingle ? "radiogroup" : "group",
|
|
52
|
+
"tabIndex": state.context.isTabbingBackward ? -1 : 0,
|
|
53
|
+
"data-disabled": dataAttr(disabled),
|
|
54
|
+
"data-orientation": state.context.orientation,
|
|
55
|
+
"data-focus": dataAttr(state.context.focusedId != null),
|
|
56
|
+
"style": { outline: "none" },
|
|
57
|
+
onMouseDown() {
|
|
58
|
+
if (disabled)
|
|
59
|
+
return;
|
|
60
|
+
send("ROOT.MOUSE_DOWN");
|
|
61
|
+
},
|
|
62
|
+
onFocus(event) {
|
|
63
|
+
if (disabled)
|
|
64
|
+
return;
|
|
65
|
+
const evt = event.nativeEvent || event;
|
|
66
|
+
if (!isSelfTarget(evt) || !!state.context.isClickFocus || state.context.isTabbingBackward)
|
|
67
|
+
return;
|
|
68
|
+
send("ROOT.FOCUS");
|
|
69
|
+
},
|
|
70
|
+
onBlur() {
|
|
71
|
+
if (disabled)
|
|
72
|
+
return;
|
|
73
|
+
send("ROOT.BLUR");
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
},
|
|
77
|
+
getItemState,
|
|
78
|
+
getItemProps(props) {
|
|
79
|
+
const itemState = getItemState(props);
|
|
80
|
+
const rovingTabIndex = itemState.focused ? 0 : -1;
|
|
81
|
+
return normalize.button({
|
|
82
|
+
...parts.item.attrs,
|
|
83
|
+
"id": itemState.id,
|
|
84
|
+
"type": "button",
|
|
85
|
+
"data-ownedby": dom.getRootId(state.context),
|
|
86
|
+
"data-focus": dataAttr(itemState.focused),
|
|
87
|
+
"disabled": itemState.disabled,
|
|
88
|
+
"tabIndex": rovingFocus ? rovingTabIndex : void 0,
|
|
89
|
+
// radio
|
|
90
|
+
"role": isSingle ? "radio" : void 0,
|
|
91
|
+
"aria-checked": isSingle ? itemState.pressed : void 0,
|
|
92
|
+
"aria-pressed": isSingle ? void 0 : itemState.pressed,
|
|
93
|
+
//
|
|
94
|
+
"data-disabled": dataAttr(itemState.disabled),
|
|
95
|
+
"data-orientation": state.context.orientation,
|
|
96
|
+
"dir": state.context.dir,
|
|
97
|
+
"data-state": itemState.pressed ? "on" : "off",
|
|
98
|
+
onFocus() {
|
|
99
|
+
if (itemState.disabled)
|
|
100
|
+
return;
|
|
101
|
+
send({ type: "TOGGLE.FOCUS", id: itemState.id });
|
|
102
|
+
},
|
|
103
|
+
onClick(event) {
|
|
104
|
+
if (itemState.disabled)
|
|
105
|
+
return;
|
|
106
|
+
send({ type: "TOGGLE.CLICK", id: itemState.id, value: props.value });
|
|
107
|
+
if (isSafari()) {
|
|
108
|
+
event.currentTarget.focus({ preventScroll: true });
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
onKeyDown(event) {
|
|
112
|
+
if (event.defaultPrevented)
|
|
113
|
+
return;
|
|
114
|
+
if (!isSelfTarget(event))
|
|
115
|
+
return;
|
|
116
|
+
if (itemState.disabled)
|
|
117
|
+
return;
|
|
118
|
+
const keyMap = {
|
|
119
|
+
Tab(event2) {
|
|
120
|
+
const isShiftTab = event2.shiftKey;
|
|
121
|
+
send({ type: "TOGGLE.SHIFT_TAB", isShiftTab });
|
|
122
|
+
},
|
|
123
|
+
ArrowLeft() {
|
|
124
|
+
if (!rovingFocus || !isHorizontal)
|
|
125
|
+
return;
|
|
126
|
+
send("TOGGLE.FOCUS_PREV");
|
|
127
|
+
},
|
|
128
|
+
ArrowRight() {
|
|
129
|
+
if (!rovingFocus || !isHorizontal)
|
|
130
|
+
return;
|
|
131
|
+
send("TOGGLE.FOCUS_NEXT");
|
|
132
|
+
},
|
|
133
|
+
ArrowUp() {
|
|
134
|
+
if (!rovingFocus || isHorizontal)
|
|
135
|
+
return;
|
|
136
|
+
send("TOGGLE.FOCUS_PREV");
|
|
137
|
+
},
|
|
138
|
+
ArrowDown() {
|
|
139
|
+
if (!rovingFocus || isHorizontal)
|
|
140
|
+
return;
|
|
141
|
+
send("TOGGLE.FOCUS_NEXT");
|
|
142
|
+
},
|
|
143
|
+
Home() {
|
|
144
|
+
if (!rovingFocus)
|
|
145
|
+
return;
|
|
146
|
+
send("TOGGLE.FOCUS_FIRST");
|
|
147
|
+
},
|
|
148
|
+
End() {
|
|
149
|
+
if (!rovingFocus)
|
|
150
|
+
return;
|
|
151
|
+
send("TOGGLE.FOCUS_LAST");
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
const exec = keyMap[getEventKey(event)];
|
|
155
|
+
if (exec) {
|
|
156
|
+
exec(event);
|
|
157
|
+
if (event.key !== "Tab")
|
|
158
|
+
event.preventDefault();
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const { not, and } = guards;
|
|
167
|
+
const invoke = {
|
|
168
|
+
change(ctx) {
|
|
169
|
+
ctx.onValueChange?.({ value: Array.from(ctx.value) });
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
const set = {
|
|
173
|
+
value(ctx, value) {
|
|
174
|
+
if (isEqual(ctx.value, value))
|
|
175
|
+
return;
|
|
176
|
+
ctx.value = value;
|
|
177
|
+
invoke.change(ctx);
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
function machine(userContext) {
|
|
181
|
+
const ctx = compact(userContext);
|
|
182
|
+
return createMachine(
|
|
183
|
+
{
|
|
184
|
+
id: "toggle",
|
|
185
|
+
initial: "idle",
|
|
186
|
+
context: {
|
|
187
|
+
value: [],
|
|
188
|
+
disabled: false,
|
|
189
|
+
orientation: "horizontal",
|
|
190
|
+
rovingFocus: true,
|
|
191
|
+
loopFocus: true,
|
|
192
|
+
...ctx,
|
|
193
|
+
focusedId: null,
|
|
194
|
+
isTabbingBackward: false,
|
|
195
|
+
isClickFocus: false,
|
|
196
|
+
isWithinToolbar: false
|
|
197
|
+
},
|
|
198
|
+
computed: {
|
|
199
|
+
currentLoopFocus: (ctx2) => ctx2.loopFocus && !ctx2.isWithinToolbar
|
|
200
|
+
},
|
|
201
|
+
entry: ["checkIfWithinToolbar"],
|
|
202
|
+
on: {
|
|
203
|
+
"VALUE.SET": {
|
|
204
|
+
actions: ["setValue"]
|
|
205
|
+
},
|
|
206
|
+
"TOGGLE.CLICK": {
|
|
207
|
+
actions: ["setValue"]
|
|
208
|
+
},
|
|
209
|
+
"ROOT.MOUSE_DOWN": {
|
|
210
|
+
actions: ["setClickFocus"]
|
|
211
|
+
}
|
|
212
|
+
},
|
|
213
|
+
states: {
|
|
214
|
+
idle: {
|
|
215
|
+
on: {
|
|
216
|
+
"ROOT.FOCUS": {
|
|
217
|
+
target: "focused",
|
|
218
|
+
guard: not(and("isClickFocus", "isTabbingBackward")),
|
|
219
|
+
actions: ["focusFirstToggle", "clearClickFocus"]
|
|
220
|
+
},
|
|
221
|
+
"TOGGLE.FOCUS": {
|
|
222
|
+
target: "focused",
|
|
223
|
+
actions: ["setFocusedId"]
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
},
|
|
227
|
+
focused: {
|
|
228
|
+
on: {
|
|
229
|
+
"ROOT.BLUR": {
|
|
230
|
+
target: "idle",
|
|
231
|
+
actions: ["clearIsTabbingBackward"]
|
|
232
|
+
},
|
|
233
|
+
"TOGGLE.FOCUS": {
|
|
234
|
+
actions: ["setFocusedId"]
|
|
235
|
+
},
|
|
236
|
+
"TOGGLE.FOCUS_NEXT": {
|
|
237
|
+
actions: ["focusNextToggle"]
|
|
238
|
+
},
|
|
239
|
+
"TOGGLE.FOCUS_PREV": {
|
|
240
|
+
actions: ["focusPrevToggle"]
|
|
241
|
+
},
|
|
242
|
+
"TOGGLE.FOCUS_FIRST": {
|
|
243
|
+
actions: ["focusFirstToggle"]
|
|
244
|
+
},
|
|
245
|
+
"TOGGLE.FOCUS_LAST": {
|
|
246
|
+
actions: ["focusLastToggle"]
|
|
247
|
+
},
|
|
248
|
+
"TOGGLE.SHIFT_TAB": {
|
|
249
|
+
target: "idle",
|
|
250
|
+
actions: ["setIsTabbingBackward"]
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
},
|
|
256
|
+
{
|
|
257
|
+
guards: {
|
|
258
|
+
isClickFocus: (ctx2) => ctx2.isClickFocus,
|
|
259
|
+
isTabbingBackward: (ctx2) => ctx2.isTabbingBackward
|
|
260
|
+
},
|
|
261
|
+
actions: {
|
|
262
|
+
setIsTabbingBackward(ctx2) {
|
|
263
|
+
ctx2.isTabbingBackward = true;
|
|
264
|
+
},
|
|
265
|
+
clearIsTabbingBackward(ctx2) {
|
|
266
|
+
ctx2.isTabbingBackward = false;
|
|
267
|
+
},
|
|
268
|
+
setClickFocus(ctx2) {
|
|
269
|
+
ctx2.isClickFocus = true;
|
|
270
|
+
},
|
|
271
|
+
clearClickFocus(ctx2) {
|
|
272
|
+
ctx2.isClickFocus = false;
|
|
273
|
+
},
|
|
274
|
+
checkIfWithinToolbar(ctx2) {
|
|
275
|
+
const closestToolbar = dom.getRootEl(ctx2)?.closest("[role=toolbar]");
|
|
276
|
+
ctx2.isWithinToolbar = !!closestToolbar;
|
|
277
|
+
},
|
|
278
|
+
setFocusedId(ctx2, evt) {
|
|
279
|
+
ctx2.focusedId = evt.id;
|
|
280
|
+
},
|
|
281
|
+
clearFocusedId(ctx2) {
|
|
282
|
+
ctx2.focusedId = null;
|
|
283
|
+
},
|
|
284
|
+
setValue(ctx2, evt) {
|
|
285
|
+
if (!evt.value)
|
|
286
|
+
return;
|
|
287
|
+
let next = Array.from(ctx2.value);
|
|
288
|
+
if (ctx2.multiple) {
|
|
289
|
+
next = next.includes(evt.value) ? remove(next, evt.value) : add(next, evt.value);
|
|
290
|
+
} else {
|
|
291
|
+
next = isEqual(ctx2.value, [evt.value]) ? [] : [evt.value];
|
|
292
|
+
}
|
|
293
|
+
set.value(ctx2, next);
|
|
294
|
+
},
|
|
295
|
+
focusNextToggle(ctx2) {
|
|
296
|
+
raf(() => {
|
|
297
|
+
if (!ctx2.focusedId)
|
|
298
|
+
return;
|
|
299
|
+
dom.getNextEl(ctx2, ctx2.focusedId)?.focus({ preventScroll: true });
|
|
300
|
+
});
|
|
301
|
+
},
|
|
302
|
+
focusPrevToggle(ctx2) {
|
|
303
|
+
raf(() => {
|
|
304
|
+
if (!ctx2.focusedId)
|
|
305
|
+
return;
|
|
306
|
+
dom.getPrevEl(ctx2, ctx2.focusedId)?.focus({ preventScroll: true });
|
|
307
|
+
});
|
|
308
|
+
},
|
|
309
|
+
focusFirstToggle(ctx2) {
|
|
310
|
+
raf(() => {
|
|
311
|
+
dom.getFirstEl(ctx2)?.focus({ preventScroll: true });
|
|
312
|
+
});
|
|
313
|
+
},
|
|
314
|
+
focusLastToggle(ctx2) {
|
|
315
|
+
raf(() => {
|
|
316
|
+
dom.getLastEl(ctx2)?.focus({ preventScroll: true });
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
);
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
const props = createProps()([
|
|
325
|
+
"dir",
|
|
326
|
+
"disabled",
|
|
327
|
+
"getRootNode",
|
|
328
|
+
"id",
|
|
329
|
+
"ids",
|
|
330
|
+
"loopFocus",
|
|
331
|
+
"multiple",
|
|
332
|
+
"onValueChange",
|
|
333
|
+
"orientation",
|
|
334
|
+
"rovingFocus",
|
|
335
|
+
"value"
|
|
336
|
+
]);
|
|
337
|
+
const splitProps = createSplitProps(props);
|
|
338
|
+
const itemProps = createProps()(["value", "disabled"]);
|
|
339
|
+
const splitItemProps = createSplitProps(itemProps);
|
|
340
|
+
|
|
341
|
+
export { anatomy, connect, itemProps, machine, props, splitItemProps, splitProps };
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@destyler/toggle",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
5
|
-
"description": "
|
|
4
|
+
"version": "0.0.7-beta.1",
|
|
5
|
+
"description": "A two-state button that can be either on or off.",
|
|
6
6
|
"author": "Elone Hoo <elonehoo@gmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"exports": {
|
|
@@ -10,14 +10,6 @@
|
|
|
10
10
|
"types": "./dist/index.d.mts",
|
|
11
11
|
"default": "./dist/index.mjs"
|
|
12
12
|
},
|
|
13
|
-
"./resolver": {
|
|
14
|
-
"types": "./dist/resolver.d.mts",
|
|
15
|
-
"default": "./dist/resolver.mjs"
|
|
16
|
-
},
|
|
17
|
-
"./component": {
|
|
18
|
-
"types": "./dist/component.d.mts",
|
|
19
|
-
"default": "./dist/component.mjs"
|
|
20
|
-
},
|
|
21
13
|
"./*": "./*"
|
|
22
14
|
},
|
|
23
15
|
"main": "dist/index.cjs",
|
|
@@ -27,17 +19,17 @@
|
|
|
27
19
|
"*.d.ts",
|
|
28
20
|
"dist"
|
|
29
21
|
],
|
|
30
|
-
"peerDependencies": {
|
|
31
|
-
"vue": ">=3.4.21"
|
|
32
|
-
},
|
|
33
22
|
"dependencies": {
|
|
34
|
-
"@
|
|
35
|
-
"@
|
|
36
|
-
"@
|
|
37
|
-
"@
|
|
23
|
+
"@zag-js/anatomy": "^0.80.0",
|
|
24
|
+
"@zag-js/core": "^0.80.0",
|
|
25
|
+
"@zag-js/dom-event": "^0.80.0",
|
|
26
|
+
"@zag-js/dom-query": "^0.80.0",
|
|
27
|
+
"@zag-js/types": "^0.80.0",
|
|
28
|
+
"@zag-js/utils": "^0.80.0"
|
|
38
29
|
},
|
|
39
30
|
"scripts": {
|
|
40
31
|
"clear": "rimraf ./dist",
|
|
32
|
+
"clear:node_modules": "rimraf ./node_modules",
|
|
41
33
|
"build": "pnpm run clear && unbuild",
|
|
42
34
|
"stub": "unbuild --stub"
|
|
43
35
|
}
|
package/README.md
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
# @destyler/toggle
|
|
2
|
-
|
|
3
|
-
[](https://www.npmjs.com/package/@destyler/toggle)
|
|
4
|
-
|
|
5
|
-
> a two-state button that can be either on or off.
|
|
6
|
-
|
|
7
|
-
[GitHub](https://github.com/destyler/destyler) | [Documentation](https://destyler-dev.zeabur.app/)
|