@zag-js/tabs 0.10.5 → 0.11.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/dist/{tabs.types.d.ts → index.d.mts} +51 -10
- package/dist/index.d.ts +134 -4
- package/dist/index.js +492 -8
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +468 -3
- package/dist/index.mjs.map +1 -0
- package/package.json +10 -10
- package/dist/tabs.anatomy.d.ts +0 -3
- package/dist/tabs.anatomy.js +0 -11
- package/dist/tabs.anatomy.mjs +0 -6
- package/dist/tabs.connect.d.ts +0 -34
- package/dist/tabs.connect.js +0 -163
- package/dist/tabs.connect.mjs +0 -159
- package/dist/tabs.dom.d.ts +0 -51
- package/dist/tabs.dom.js +0 -60
- package/dist/tabs.dom.mjs +0 -56
- package/dist/tabs.machine.d.ts +0 -3
- package/dist/tabs.machine.js +0 -251
- package/dist/tabs.machine.mjs +0 -247
package/dist/tabs.connect.js
DELETED
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
|
|
5
|
-
const domEvent = require('@zag-js/dom-event');
|
|
6
|
-
const domQuery = require('@zag-js/dom-query');
|
|
7
|
-
const tabs_anatomy = require('./tabs.anatomy.js');
|
|
8
|
-
const tabs_dom = require('./tabs.dom.js');
|
|
9
|
-
|
|
10
|
-
function connect(state, send, normalize) {
|
|
11
|
-
const translations = state.context.translations;
|
|
12
|
-
const isFocused = state.matches("focused");
|
|
13
|
-
return {
|
|
14
|
-
/**
|
|
15
|
-
* The current value of the tabs.
|
|
16
|
-
*/
|
|
17
|
-
value: state.context.value,
|
|
18
|
-
/**
|
|
19
|
-
* The value of the tab that is currently focused.
|
|
20
|
-
*/
|
|
21
|
-
focusedValue: state.context.focusedValue,
|
|
22
|
-
/**
|
|
23
|
-
* The previous values of the tabs in sequence of selection.
|
|
24
|
-
*/
|
|
25
|
-
previousValues: Array.from(state.context.previousValues),
|
|
26
|
-
/**
|
|
27
|
-
* Sets the value of the tabs.
|
|
28
|
-
*/
|
|
29
|
-
setValue(value) {
|
|
30
|
-
send({ type: "SET_VALUE", value });
|
|
31
|
-
},
|
|
32
|
-
/**
|
|
33
|
-
* Clears the value of the tabs.
|
|
34
|
-
*/
|
|
35
|
-
clearValue() {
|
|
36
|
-
send({ type: "CLEAR_VALUE" });
|
|
37
|
-
},
|
|
38
|
-
/**
|
|
39
|
-
* Sets the indicator rect to the tab with the given id.
|
|
40
|
-
*/
|
|
41
|
-
setIndicatorRect(id) {
|
|
42
|
-
send({ type: "SET_INDICATOR_RECT", id });
|
|
43
|
-
},
|
|
44
|
-
rootProps: normalize.element({
|
|
45
|
-
...tabs_anatomy.parts.root.attrs,
|
|
46
|
-
id: tabs_dom.dom.getRootId(state.context),
|
|
47
|
-
"data-orientation": state.context.orientation,
|
|
48
|
-
"data-focus": domQuery.dataAttr(isFocused),
|
|
49
|
-
dir: state.context.dir
|
|
50
|
-
}),
|
|
51
|
-
tablistProps: normalize.element({
|
|
52
|
-
...tabs_anatomy.parts.tablist.attrs,
|
|
53
|
-
id: tabs_dom.dom.getTablistId(state.context),
|
|
54
|
-
role: "tablist",
|
|
55
|
-
"data-focus": domQuery.dataAttr(isFocused),
|
|
56
|
-
"aria-orientation": state.context.orientation,
|
|
57
|
-
"data-orientation": state.context.orientation,
|
|
58
|
-
"aria-label": translations.tablistLabel,
|
|
59
|
-
onKeyDown(event) {
|
|
60
|
-
const keyMap = {
|
|
61
|
-
ArrowDown() {
|
|
62
|
-
send("ARROW_DOWN");
|
|
63
|
-
},
|
|
64
|
-
ArrowUp() {
|
|
65
|
-
send("ARROW_UP");
|
|
66
|
-
},
|
|
67
|
-
ArrowLeft() {
|
|
68
|
-
send("ARROW_LEFT");
|
|
69
|
-
},
|
|
70
|
-
ArrowRight() {
|
|
71
|
-
send("ARROW_RIGHT");
|
|
72
|
-
},
|
|
73
|
-
Home() {
|
|
74
|
-
send("HOME");
|
|
75
|
-
},
|
|
76
|
-
End() {
|
|
77
|
-
send("END");
|
|
78
|
-
},
|
|
79
|
-
Enter() {
|
|
80
|
-
send({ type: "ENTER", value: state.context.focusedValue });
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
let key = domEvent.getEventKey(event, state.context);
|
|
84
|
-
const exec = keyMap[key];
|
|
85
|
-
if (exec) {
|
|
86
|
-
event.preventDefault();
|
|
87
|
-
exec(event);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}),
|
|
91
|
-
getTriggerProps(props) {
|
|
92
|
-
const { value, disabled } = props;
|
|
93
|
-
const selected = state.context.value === value;
|
|
94
|
-
return normalize.button({
|
|
95
|
-
...tabs_anatomy.parts.trigger.attrs,
|
|
96
|
-
role: "tab",
|
|
97
|
-
type: "button",
|
|
98
|
-
disabled,
|
|
99
|
-
"data-orientation": state.context.orientation,
|
|
100
|
-
"data-disabled": domQuery.dataAttr(disabled),
|
|
101
|
-
"aria-disabled": disabled,
|
|
102
|
-
"data-value": value,
|
|
103
|
-
"aria-selected": selected,
|
|
104
|
-
"data-selected": domQuery.dataAttr(selected),
|
|
105
|
-
"aria-controls": tabs_dom.dom.getContentId(state.context, value),
|
|
106
|
-
"data-ownedby": tabs_dom.dom.getTablistId(state.context),
|
|
107
|
-
id: tabs_dom.dom.getTriggerId(state.context, value),
|
|
108
|
-
tabIndex: selected ? 0 : -1,
|
|
109
|
-
onFocus() {
|
|
110
|
-
send({ type: "TAB_FOCUS", value });
|
|
111
|
-
},
|
|
112
|
-
onBlur(event) {
|
|
113
|
-
const target = event.relatedTarget;
|
|
114
|
-
if (target?.getAttribute("role") !== "tab") {
|
|
115
|
-
send({ type: "TAB_BLUR" });
|
|
116
|
-
}
|
|
117
|
-
},
|
|
118
|
-
onClick(event) {
|
|
119
|
-
if (disabled)
|
|
120
|
-
return;
|
|
121
|
-
if (domQuery.isSafari()) {
|
|
122
|
-
event.currentTarget.focus();
|
|
123
|
-
}
|
|
124
|
-
send({ type: "TAB_CLICK", value });
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
},
|
|
128
|
-
contentGroupProps: normalize.element({
|
|
129
|
-
...tabs_anatomy.parts.contentGroup.attrs,
|
|
130
|
-
id: tabs_dom.dom.getContentGroupId(state.context),
|
|
131
|
-
"data-orientation": state.context.orientation
|
|
132
|
-
}),
|
|
133
|
-
getContentProps({ value }) {
|
|
134
|
-
const selected = state.context.value === value;
|
|
135
|
-
return normalize.element({
|
|
136
|
-
...tabs_anatomy.parts.content.attrs,
|
|
137
|
-
id: tabs_dom.dom.getContentId(state.context, value),
|
|
138
|
-
tabIndex: 0,
|
|
139
|
-
"aria-labelledby": tabs_dom.dom.getTriggerId(state.context, value),
|
|
140
|
-
role: "tabpanel",
|
|
141
|
-
"data-ownedby": tabs_dom.dom.getTablistId(state.context),
|
|
142
|
-
hidden: !selected
|
|
143
|
-
});
|
|
144
|
-
},
|
|
145
|
-
indicatorProps: normalize.element({
|
|
146
|
-
id: tabs_dom.dom.getIndicatorId(state.context),
|
|
147
|
-
...tabs_anatomy.parts.indicator.attrs,
|
|
148
|
-
"data-orientation": state.context.orientation,
|
|
149
|
-
style: {
|
|
150
|
-
"--transition-duration": "150ms",
|
|
151
|
-
"--transition-property": "left, right, top, bottom, width, height",
|
|
152
|
-
position: "absolute",
|
|
153
|
-
willChange: "var(--transition-property)",
|
|
154
|
-
transitionProperty: "var(--transition-property)",
|
|
155
|
-
transitionDuration: state.context.canIndicatorTransition ? "var(--transition-duration)" : "0ms",
|
|
156
|
-
transitionTimingFunction: "var(--transition-timing-function)",
|
|
157
|
-
...state.context.indicatorRect
|
|
158
|
-
}
|
|
159
|
-
})
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
exports.connect = connect;
|
package/dist/tabs.connect.mjs
DELETED
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
import { getEventKey } from '@zag-js/dom-event';
|
|
2
|
-
import { dataAttr, isSafari } from '@zag-js/dom-query';
|
|
3
|
-
import { parts } from './tabs.anatomy.mjs';
|
|
4
|
-
import { dom } from './tabs.dom.mjs';
|
|
5
|
-
|
|
6
|
-
function connect(state, send, normalize) {
|
|
7
|
-
const translations = state.context.translations;
|
|
8
|
-
const isFocused = state.matches("focused");
|
|
9
|
-
return {
|
|
10
|
-
/**
|
|
11
|
-
* The current value of the tabs.
|
|
12
|
-
*/
|
|
13
|
-
value: state.context.value,
|
|
14
|
-
/**
|
|
15
|
-
* The value of the tab that is currently focused.
|
|
16
|
-
*/
|
|
17
|
-
focusedValue: state.context.focusedValue,
|
|
18
|
-
/**
|
|
19
|
-
* The previous values of the tabs in sequence of selection.
|
|
20
|
-
*/
|
|
21
|
-
previousValues: Array.from(state.context.previousValues),
|
|
22
|
-
/**
|
|
23
|
-
* Sets the value of the tabs.
|
|
24
|
-
*/
|
|
25
|
-
setValue(value) {
|
|
26
|
-
send({ type: "SET_VALUE", value });
|
|
27
|
-
},
|
|
28
|
-
/**
|
|
29
|
-
* Clears the value of the tabs.
|
|
30
|
-
*/
|
|
31
|
-
clearValue() {
|
|
32
|
-
send({ type: "CLEAR_VALUE" });
|
|
33
|
-
},
|
|
34
|
-
/**
|
|
35
|
-
* Sets the indicator rect to the tab with the given id.
|
|
36
|
-
*/
|
|
37
|
-
setIndicatorRect(id) {
|
|
38
|
-
send({ type: "SET_INDICATOR_RECT", id });
|
|
39
|
-
},
|
|
40
|
-
rootProps: normalize.element({
|
|
41
|
-
...parts.root.attrs,
|
|
42
|
-
id: dom.getRootId(state.context),
|
|
43
|
-
"data-orientation": state.context.orientation,
|
|
44
|
-
"data-focus": dataAttr(isFocused),
|
|
45
|
-
dir: state.context.dir
|
|
46
|
-
}),
|
|
47
|
-
tablistProps: normalize.element({
|
|
48
|
-
...parts.tablist.attrs,
|
|
49
|
-
id: dom.getTablistId(state.context),
|
|
50
|
-
role: "tablist",
|
|
51
|
-
"data-focus": dataAttr(isFocused),
|
|
52
|
-
"aria-orientation": state.context.orientation,
|
|
53
|
-
"data-orientation": state.context.orientation,
|
|
54
|
-
"aria-label": translations.tablistLabel,
|
|
55
|
-
onKeyDown(event) {
|
|
56
|
-
const keyMap = {
|
|
57
|
-
ArrowDown() {
|
|
58
|
-
send("ARROW_DOWN");
|
|
59
|
-
},
|
|
60
|
-
ArrowUp() {
|
|
61
|
-
send("ARROW_UP");
|
|
62
|
-
},
|
|
63
|
-
ArrowLeft() {
|
|
64
|
-
send("ARROW_LEFT");
|
|
65
|
-
},
|
|
66
|
-
ArrowRight() {
|
|
67
|
-
send("ARROW_RIGHT");
|
|
68
|
-
},
|
|
69
|
-
Home() {
|
|
70
|
-
send("HOME");
|
|
71
|
-
},
|
|
72
|
-
End() {
|
|
73
|
-
send("END");
|
|
74
|
-
},
|
|
75
|
-
Enter() {
|
|
76
|
-
send({ type: "ENTER", value: state.context.focusedValue });
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
let key = getEventKey(event, state.context);
|
|
80
|
-
const exec = keyMap[key];
|
|
81
|
-
if (exec) {
|
|
82
|
-
event.preventDefault();
|
|
83
|
-
exec(event);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}),
|
|
87
|
-
getTriggerProps(props) {
|
|
88
|
-
const { value, disabled } = props;
|
|
89
|
-
const selected = state.context.value === value;
|
|
90
|
-
return normalize.button({
|
|
91
|
-
...parts.trigger.attrs,
|
|
92
|
-
role: "tab",
|
|
93
|
-
type: "button",
|
|
94
|
-
disabled,
|
|
95
|
-
"data-orientation": state.context.orientation,
|
|
96
|
-
"data-disabled": dataAttr(disabled),
|
|
97
|
-
"aria-disabled": disabled,
|
|
98
|
-
"data-value": value,
|
|
99
|
-
"aria-selected": selected,
|
|
100
|
-
"data-selected": dataAttr(selected),
|
|
101
|
-
"aria-controls": dom.getContentId(state.context, value),
|
|
102
|
-
"data-ownedby": dom.getTablistId(state.context),
|
|
103
|
-
id: dom.getTriggerId(state.context, value),
|
|
104
|
-
tabIndex: selected ? 0 : -1,
|
|
105
|
-
onFocus() {
|
|
106
|
-
send({ type: "TAB_FOCUS", value });
|
|
107
|
-
},
|
|
108
|
-
onBlur(event) {
|
|
109
|
-
const target = event.relatedTarget;
|
|
110
|
-
if (target?.getAttribute("role") !== "tab") {
|
|
111
|
-
send({ type: "TAB_BLUR" });
|
|
112
|
-
}
|
|
113
|
-
},
|
|
114
|
-
onClick(event) {
|
|
115
|
-
if (disabled)
|
|
116
|
-
return;
|
|
117
|
-
if (isSafari()) {
|
|
118
|
-
event.currentTarget.focus();
|
|
119
|
-
}
|
|
120
|
-
send({ type: "TAB_CLICK", value });
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
},
|
|
124
|
-
contentGroupProps: normalize.element({
|
|
125
|
-
...parts.contentGroup.attrs,
|
|
126
|
-
id: dom.getContentGroupId(state.context),
|
|
127
|
-
"data-orientation": state.context.orientation
|
|
128
|
-
}),
|
|
129
|
-
getContentProps({ value }) {
|
|
130
|
-
const selected = state.context.value === value;
|
|
131
|
-
return normalize.element({
|
|
132
|
-
...parts.content.attrs,
|
|
133
|
-
id: dom.getContentId(state.context, value),
|
|
134
|
-
tabIndex: 0,
|
|
135
|
-
"aria-labelledby": dom.getTriggerId(state.context, value),
|
|
136
|
-
role: "tabpanel",
|
|
137
|
-
"data-ownedby": dom.getTablistId(state.context),
|
|
138
|
-
hidden: !selected
|
|
139
|
-
});
|
|
140
|
-
},
|
|
141
|
-
indicatorProps: normalize.element({
|
|
142
|
-
id: dom.getIndicatorId(state.context),
|
|
143
|
-
...parts.indicator.attrs,
|
|
144
|
-
"data-orientation": state.context.orientation,
|
|
145
|
-
style: {
|
|
146
|
-
"--transition-duration": "150ms",
|
|
147
|
-
"--transition-property": "left, right, top, bottom, width, height",
|
|
148
|
-
position: "absolute",
|
|
149
|
-
willChange: "var(--transition-property)",
|
|
150
|
-
transitionProperty: "var(--transition-property)",
|
|
151
|
-
transitionDuration: state.context.canIndicatorTransition ? "var(--transition-duration)" : "0ms",
|
|
152
|
-
transitionTimingFunction: "var(--transition-timing-function)",
|
|
153
|
-
...state.context.indicatorRect
|
|
154
|
-
}
|
|
155
|
-
})
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
export { connect };
|
package/dist/tabs.dom.d.ts
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import type { MachineContext as Ctx } from "./tabs.types";
|
|
2
|
-
export declare const dom: {
|
|
3
|
-
getRootNode: (ctx: {
|
|
4
|
-
getRootNode?: (() => Node | ShadowRoot | Document) | undefined;
|
|
5
|
-
}) => ShadowRoot | Document;
|
|
6
|
-
getDoc: (ctx: {
|
|
7
|
-
getRootNode?: (() => Node | ShadowRoot | Document) | undefined;
|
|
8
|
-
}) => Document;
|
|
9
|
-
getWin: (ctx: {
|
|
10
|
-
getRootNode?: (() => Node | ShadowRoot | Document) | undefined;
|
|
11
|
-
}) => Window & typeof globalThis;
|
|
12
|
-
getActiveElement: (ctx: {
|
|
13
|
-
getRootNode?: (() => Node | ShadowRoot | Document) | undefined;
|
|
14
|
-
}) => HTMLElement | null;
|
|
15
|
-
getById: <T extends HTMLElement = HTMLElement>(ctx: {
|
|
16
|
-
getRootNode?: (() => Node | ShadowRoot | Document) | undefined;
|
|
17
|
-
}, id: string) => T | null;
|
|
18
|
-
queryById: <T_1 extends HTMLElement = HTMLElement>(ctx: {
|
|
19
|
-
getRootNode?: (() => Node | ShadowRoot | Document) | undefined;
|
|
20
|
-
}, id: string) => T_1;
|
|
21
|
-
} & {
|
|
22
|
-
getRootId: (ctx: Ctx) => string;
|
|
23
|
-
getTablistId: (ctx: Ctx) => string;
|
|
24
|
-
getContentId: (ctx: Ctx, id: string) => string;
|
|
25
|
-
getContentGroupId: (ctx: Ctx) => string;
|
|
26
|
-
getTriggerId: (ctx: Ctx, id: string) => string;
|
|
27
|
-
getIndicatorId: (ctx: Ctx) => string;
|
|
28
|
-
getTablistEl: (ctx: Ctx) => HTMLElement | null;
|
|
29
|
-
getContentEl: (ctx: Ctx, id: string) => HTMLElement | null;
|
|
30
|
-
getTriggerEl: (ctx: Ctx, id: string) => HTMLElement | null;
|
|
31
|
-
getIndicatorEl: (ctx: Ctx) => HTMLElement | null;
|
|
32
|
-
getElements: (ctx: Ctx) => HTMLElement[];
|
|
33
|
-
getFirstEl: (ctx: Ctx) => HTMLElement | undefined;
|
|
34
|
-
getLastEl: (ctx: Ctx) => HTMLElement | undefined;
|
|
35
|
-
getNextEl: (ctx: Ctx, id: string) => HTMLElement;
|
|
36
|
-
getPrevEl: (ctx: Ctx, id: string) => HTMLElement | null;
|
|
37
|
-
getActiveContentEl: (ctx: Ctx) => HTMLElement | null | undefined;
|
|
38
|
-
getActiveTabEl: (ctx: Ctx) => HTMLElement | null | undefined;
|
|
39
|
-
getOffsetRect: (el: HTMLElement | undefined) => {
|
|
40
|
-
left: number;
|
|
41
|
-
top: number;
|
|
42
|
-
width: number;
|
|
43
|
-
height: number;
|
|
44
|
-
};
|
|
45
|
-
getRectById: (ctx: Ctx, id: string) => {
|
|
46
|
-
[x: string]: string;
|
|
47
|
-
};
|
|
48
|
-
resolveRect(rect: Record<"width" | "height" | "left" | "top", number>, orientation?: "horizontal" | "vertical"): {
|
|
49
|
-
[x: string]: string;
|
|
50
|
-
};
|
|
51
|
-
};
|
package/dist/tabs.dom.js
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
|
|
5
|
-
const domQuery = require('@zag-js/dom-query');
|
|
6
|
-
const utils = require('@zag-js/utils');
|
|
7
|
-
|
|
8
|
-
const dom = domQuery.createScope({
|
|
9
|
-
getRootId: (ctx) => ctx.ids?.root ?? `tabs:${ctx.id}`,
|
|
10
|
-
getTablistId: (ctx) => ctx.ids?.tablist ?? `tabs:${ctx.id}:list`,
|
|
11
|
-
getContentId: (ctx, id) => ctx.ids?.content ?? `tabs:${ctx.id}:content-${id}`,
|
|
12
|
-
getContentGroupId: (ctx) => ctx.ids?.contentGroup ?? `tabs:${ctx.id}:content-group`,
|
|
13
|
-
getTriggerId: (ctx, id) => ctx.ids?.trigger ?? `tabs:${ctx.id}:trigger-${id}`,
|
|
14
|
-
getIndicatorId: (ctx) => ctx.ids?.indicator ?? `tabs:${ctx.id}:indicator`,
|
|
15
|
-
getTablistEl: (ctx) => dom.getById(ctx, dom.getTablistId(ctx)),
|
|
16
|
-
getContentEl: (ctx, id) => dom.getById(ctx, dom.getContentId(ctx, id)),
|
|
17
|
-
getTriggerEl: (ctx, id) => dom.getById(ctx, dom.getTriggerId(ctx, id)),
|
|
18
|
-
getIndicatorEl: (ctx) => dom.getById(ctx, dom.getIndicatorId(ctx)),
|
|
19
|
-
getElements: (ctx) => {
|
|
20
|
-
const ownerId = CSS.escape(dom.getTablistId(ctx));
|
|
21
|
-
const selector = `[role=tab][data-ownedby='${ownerId}']:not([disabled])`;
|
|
22
|
-
return domQuery.queryAll(dom.getTablistEl(ctx), selector);
|
|
23
|
-
},
|
|
24
|
-
getFirstEl: (ctx) => utils.first(dom.getElements(ctx)),
|
|
25
|
-
getLastEl: (ctx) => utils.last(dom.getElements(ctx)),
|
|
26
|
-
getNextEl: (ctx, id) => domQuery.nextById(dom.getElements(ctx), dom.getTriggerId(ctx, id), ctx.loop),
|
|
27
|
-
getPrevEl: (ctx, id) => domQuery.prevById(dom.getElements(ctx), dom.getTriggerId(ctx, id), ctx.loop),
|
|
28
|
-
getActiveContentEl: (ctx) => {
|
|
29
|
-
if (!ctx.value)
|
|
30
|
-
return;
|
|
31
|
-
return dom.getContentEl(ctx, ctx.value);
|
|
32
|
-
},
|
|
33
|
-
getActiveTabEl: (ctx) => {
|
|
34
|
-
if (!ctx.value)
|
|
35
|
-
return;
|
|
36
|
-
return dom.getTriggerEl(ctx, ctx.value);
|
|
37
|
-
},
|
|
38
|
-
getOffsetRect: (el) => {
|
|
39
|
-
return {
|
|
40
|
-
left: el?.offsetLeft ?? 0,
|
|
41
|
-
top: el?.offsetTop ?? 0,
|
|
42
|
-
width: el?.offsetWidth ?? 0,
|
|
43
|
-
height: el?.offsetHeight ?? 0
|
|
44
|
-
};
|
|
45
|
-
},
|
|
46
|
-
getRectById: (ctx, id) => {
|
|
47
|
-
const tab = domQuery.itemById(dom.getElements(ctx), dom.getTriggerId(ctx, id));
|
|
48
|
-
return dom.resolveRect(dom.getOffsetRect(tab), ctx.orientation);
|
|
49
|
-
},
|
|
50
|
-
resolveRect(rect, orientation) {
|
|
51
|
-
const sizeProp = orientation === "vertical" ? "height" : "width";
|
|
52
|
-
const placementProp = orientation === "vertical" ? "top" : "left";
|
|
53
|
-
return {
|
|
54
|
-
[placementProp]: `${rect[placementProp]}px`,
|
|
55
|
-
[sizeProp]: `${rect[sizeProp]}px`
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
exports.dom = dom;
|
package/dist/tabs.dom.mjs
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { createScope, queryAll, nextById, prevById, itemById } from '@zag-js/dom-query';
|
|
2
|
-
import { first, last } from '@zag-js/utils';
|
|
3
|
-
|
|
4
|
-
const dom = createScope({
|
|
5
|
-
getRootId: (ctx) => ctx.ids?.root ?? `tabs:${ctx.id}`,
|
|
6
|
-
getTablistId: (ctx) => ctx.ids?.tablist ?? `tabs:${ctx.id}:list`,
|
|
7
|
-
getContentId: (ctx, id) => ctx.ids?.content ?? `tabs:${ctx.id}:content-${id}`,
|
|
8
|
-
getContentGroupId: (ctx) => ctx.ids?.contentGroup ?? `tabs:${ctx.id}:content-group`,
|
|
9
|
-
getTriggerId: (ctx, id) => ctx.ids?.trigger ?? `tabs:${ctx.id}:trigger-${id}`,
|
|
10
|
-
getIndicatorId: (ctx) => ctx.ids?.indicator ?? `tabs:${ctx.id}:indicator`,
|
|
11
|
-
getTablistEl: (ctx) => dom.getById(ctx, dom.getTablistId(ctx)),
|
|
12
|
-
getContentEl: (ctx, id) => dom.getById(ctx, dom.getContentId(ctx, id)),
|
|
13
|
-
getTriggerEl: (ctx, id) => dom.getById(ctx, dom.getTriggerId(ctx, id)),
|
|
14
|
-
getIndicatorEl: (ctx) => dom.getById(ctx, dom.getIndicatorId(ctx)),
|
|
15
|
-
getElements: (ctx) => {
|
|
16
|
-
const ownerId = CSS.escape(dom.getTablistId(ctx));
|
|
17
|
-
const selector = `[role=tab][data-ownedby='${ownerId}']:not([disabled])`;
|
|
18
|
-
return queryAll(dom.getTablistEl(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), dom.getTriggerId(ctx, id), ctx.loop),
|
|
23
|
-
getPrevEl: (ctx, id) => prevById(dom.getElements(ctx), dom.getTriggerId(ctx, id), ctx.loop),
|
|
24
|
-
getActiveContentEl: (ctx) => {
|
|
25
|
-
if (!ctx.value)
|
|
26
|
-
return;
|
|
27
|
-
return dom.getContentEl(ctx, ctx.value);
|
|
28
|
-
},
|
|
29
|
-
getActiveTabEl: (ctx) => {
|
|
30
|
-
if (!ctx.value)
|
|
31
|
-
return;
|
|
32
|
-
return dom.getTriggerEl(ctx, ctx.value);
|
|
33
|
-
},
|
|
34
|
-
getOffsetRect: (el) => {
|
|
35
|
-
return {
|
|
36
|
-
left: el?.offsetLeft ?? 0,
|
|
37
|
-
top: el?.offsetTop ?? 0,
|
|
38
|
-
width: el?.offsetWidth ?? 0,
|
|
39
|
-
height: el?.offsetHeight ?? 0
|
|
40
|
-
};
|
|
41
|
-
},
|
|
42
|
-
getRectById: (ctx, id) => {
|
|
43
|
-
const tab = itemById(dom.getElements(ctx), dom.getTriggerId(ctx, id));
|
|
44
|
-
return dom.resolveRect(dom.getOffsetRect(tab), ctx.orientation);
|
|
45
|
-
},
|
|
46
|
-
resolveRect(rect, orientation) {
|
|
47
|
-
const sizeProp = orientation === "vertical" ? "height" : "width";
|
|
48
|
-
const placementProp = orientation === "vertical" ? "top" : "left";
|
|
49
|
-
return {
|
|
50
|
-
[placementProp]: `${rect[placementProp]}px`,
|
|
51
|
-
[sizeProp]: `${rect[sizeProp]}px`
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
export { dom };
|
package/dist/tabs.machine.d.ts
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import type { Machine, StateMachine } from '@zag-js/core';
|
|
2
|
-
import type { MachineContext, MachineState, UserDefinedContext } from "./tabs.types";
|
|
3
|
-
export declare function machine(userContext: UserDefinedContext): Machine<MachineContext, MachineState, StateMachine.AnyEventObject>;
|