@destyler/toggle 0.0.6 → 0.0.7-beta.2
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/component.cjs
DELETED
|
@@ -1,259 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const vue = require('vue');
|
|
4
|
-
const primitive = require('@destyler/primitive');
|
|
5
|
-
const composition = require('@destyler/composition');
|
|
6
|
-
const shared = require('@destyler/shared');
|
|
7
|
-
const rovingFocus = require('@destyler/roving-focus');
|
|
8
|
-
|
|
9
|
-
const toggleProps = {
|
|
10
|
-
...primitive.primitiveProps,
|
|
11
|
-
/**
|
|
12
|
-
* @default button
|
|
13
|
-
*/
|
|
14
|
-
as: {
|
|
15
|
-
...primitive.primitiveProps.as,
|
|
16
|
-
default: "button"
|
|
17
|
-
},
|
|
18
|
-
/**
|
|
19
|
-
* The pressed state of the toggle when it is initially rendered. Use when you do not need to control its open state.
|
|
20
|
-
*/
|
|
21
|
-
defaultValue: {
|
|
22
|
-
type: Boolean,
|
|
23
|
-
required: false
|
|
24
|
-
},
|
|
25
|
-
/**
|
|
26
|
-
* The controlled pressed state of the toggle. Can be bind as `v-model`.
|
|
27
|
-
*
|
|
28
|
-
* @default undefined
|
|
29
|
-
*/
|
|
30
|
-
pressed: {
|
|
31
|
-
type: Boolean,
|
|
32
|
-
required: false,
|
|
33
|
-
default: void 0
|
|
34
|
-
},
|
|
35
|
-
/**
|
|
36
|
-
* When `true`, prevents the user from interacting with the toggle.
|
|
37
|
-
*/
|
|
38
|
-
disabled: {
|
|
39
|
-
type: Boolean,
|
|
40
|
-
required: false,
|
|
41
|
-
default: false
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
const toggleEmits = {
|
|
45
|
-
/**
|
|
46
|
-
* Event handler called when the pressed state of the toggle changes.
|
|
47
|
-
*/
|
|
48
|
-
"update:pressed": (_value) => true
|
|
49
|
-
};
|
|
50
|
-
const Toggle = vue.defineComponent({
|
|
51
|
-
name: "DestylerToggle",
|
|
52
|
-
props: toggleProps,
|
|
53
|
-
emits: toggleEmits,
|
|
54
|
-
setup(props, { emit }) {
|
|
55
|
-
composition.useForwardExpose();
|
|
56
|
-
const pressed = composition.useVModel(props, "pressed", emit, {
|
|
57
|
-
defaultValue: props.defaultValue,
|
|
58
|
-
passive: props.pressed === void 0
|
|
59
|
-
});
|
|
60
|
-
function togglePressed() {
|
|
61
|
-
pressed.value = !pressed.value;
|
|
62
|
-
}
|
|
63
|
-
const dataState = vue.computed(() => {
|
|
64
|
-
return pressed.value ? "on" : "off";
|
|
65
|
-
});
|
|
66
|
-
return {
|
|
67
|
-
pressed,
|
|
68
|
-
togglePressed,
|
|
69
|
-
dataState
|
|
70
|
-
};
|
|
71
|
-
},
|
|
72
|
-
render() {
|
|
73
|
-
return vue.h(primitive.Primitive, {
|
|
74
|
-
"as": this.$props.as,
|
|
75
|
-
"asChild": this.$props.asChild,
|
|
76
|
-
"type": this.$props.as === "button" ? "button" : void 0,
|
|
77
|
-
"aria-pressed": this.pressed,
|
|
78
|
-
"data-state": this.dataState,
|
|
79
|
-
"data-disabled": this.$props.disabled ? "" : void 0,
|
|
80
|
-
"disabled": this.$props.disabled,
|
|
81
|
-
"onClick": () => {
|
|
82
|
-
this.togglePressed();
|
|
83
|
-
}
|
|
84
|
-
}, () => this.$slots.default?.());
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
const toggleGroupRootProps = {
|
|
89
|
-
...primitive.primitiveProps,
|
|
90
|
-
/**
|
|
91
|
-
* Determines whether a "single" or "multiple" items can be pressed at a time.
|
|
92
|
-
*
|
|
93
|
-
* This prop will be ignored if any of `v-model` or `defaultValue` is an defined, as the type will be inferred from the value.
|
|
94
|
-
*
|
|
95
|
-
* @default single
|
|
96
|
-
*/
|
|
97
|
-
type: {
|
|
98
|
-
type: String,
|
|
99
|
-
required: false,
|
|
100
|
-
default: "single"
|
|
101
|
-
},
|
|
102
|
-
/**
|
|
103
|
-
* The default active value of the item(s).
|
|
104
|
-
*
|
|
105
|
-
* Use when you do not need to control the state of the item(s).
|
|
106
|
-
*/
|
|
107
|
-
defaultValue: {
|
|
108
|
-
type: [String, Array],
|
|
109
|
-
required: false
|
|
110
|
-
},
|
|
111
|
-
/**
|
|
112
|
-
* The controlled value of the active item(s).
|
|
113
|
-
*
|
|
114
|
-
* Use this when you need to control the state of the items. Can be binded with `v-model`
|
|
115
|
-
*/
|
|
116
|
-
modelValue: {
|
|
117
|
-
type: [String, Array],
|
|
118
|
-
required: false
|
|
119
|
-
},
|
|
120
|
-
/**
|
|
121
|
-
* When `false`, navigating through the items using arrow keys will be disabled.
|
|
122
|
-
*
|
|
123
|
-
* @default true
|
|
124
|
-
*/
|
|
125
|
-
rovingFocus: {
|
|
126
|
-
type: Boolean,
|
|
127
|
-
required: false,
|
|
128
|
-
default: true
|
|
129
|
-
},
|
|
130
|
-
/**
|
|
131
|
-
* When `true`, prevents the user from interacting with the toggle group and all its items.
|
|
132
|
-
*
|
|
133
|
-
* @default false
|
|
134
|
-
*/
|
|
135
|
-
disabled: {
|
|
136
|
-
type: Boolean,
|
|
137
|
-
required: false,
|
|
138
|
-
default: false
|
|
139
|
-
},
|
|
140
|
-
/**
|
|
141
|
-
* The orientation of the component, which determines how focus moves: `horizontal` for left/right arrows and `vertical` for up/down arrows.
|
|
142
|
-
*/
|
|
143
|
-
orientation: {
|
|
144
|
-
type: String,
|
|
145
|
-
required: false
|
|
146
|
-
},
|
|
147
|
-
/**
|
|
148
|
-
* The reading direction of the combobox when applicable.
|
|
149
|
-
*/
|
|
150
|
-
dir: {
|
|
151
|
-
type: String,
|
|
152
|
-
required: false
|
|
153
|
-
},
|
|
154
|
-
/**
|
|
155
|
-
* When `loop` and `rovingFocus` is `true`, keyboard navigation will loop from last item to first, and vice versa.
|
|
156
|
-
*/
|
|
157
|
-
loop: {
|
|
158
|
-
type: Boolean,
|
|
159
|
-
required: false,
|
|
160
|
-
default: true
|
|
161
|
-
}
|
|
162
|
-
};
|
|
163
|
-
const toggleGroupRootEmits = {
|
|
164
|
-
/**
|
|
165
|
-
* Event handler called when the value changes.
|
|
166
|
-
*/
|
|
167
|
-
"update:modelValue": (_value) => true
|
|
168
|
-
};
|
|
169
|
-
const [injectToggleGroupRootContext, provideToggleGroupRootContext] = shared.createContext("DestylerToggleGroupRoot");
|
|
170
|
-
const ToggleGroupRoot = vue.defineComponent({
|
|
171
|
-
name: "DestylerToggleGroupRoot",
|
|
172
|
-
props: toggleGroupRootProps,
|
|
173
|
-
emits: toggleGroupRootEmits,
|
|
174
|
-
setup(props, { emit }) {
|
|
175
|
-
const { loop, rovingFocus, disabled, dir: propDir } = vue.toRefs(props);
|
|
176
|
-
const dir = composition.useDirection(propDir);
|
|
177
|
-
const { forwardRef } = composition.useForwardExpose();
|
|
178
|
-
const { modelValue, changeModelValue } = composition.useSingleOrMultipleValue(props, emit);
|
|
179
|
-
provideToggleGroupRootContext({
|
|
180
|
-
type: props.type,
|
|
181
|
-
modelValue,
|
|
182
|
-
changeModelValue,
|
|
183
|
-
dir,
|
|
184
|
-
orientation: props.orientation,
|
|
185
|
-
loop,
|
|
186
|
-
rovingFocus,
|
|
187
|
-
disabled
|
|
188
|
-
});
|
|
189
|
-
return {
|
|
190
|
-
rovingFocus,
|
|
191
|
-
dir,
|
|
192
|
-
loop,
|
|
193
|
-
forwardRef
|
|
194
|
-
};
|
|
195
|
-
},
|
|
196
|
-
render() {
|
|
197
|
-
return vue.h(this.rovingFocus ? rovingFocus.RovingFocusGroup : primitive.Primitive, {
|
|
198
|
-
asChild: true,
|
|
199
|
-
orientation: this.rovingFocus ? this.$props.orientation : void 0,
|
|
200
|
-
dir: this.dir,
|
|
201
|
-
loop: this.rovingFocus ? this.loop : void 0
|
|
202
|
-
}, () => vue.h(primitive.Primitive, {
|
|
203
|
-
ref: (el) => this.forwardRef(el),
|
|
204
|
-
role: "group",
|
|
205
|
-
as: this.$props.as,
|
|
206
|
-
asChild: this.$props.asChild
|
|
207
|
-
}, () => this.$slots.default?.()));
|
|
208
|
-
}
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
const toggleGroupItemProps = {
|
|
212
|
-
...toggleProps,
|
|
213
|
-
/**
|
|
214
|
-
* A string value for the toggle group item. All items within a toggle group should use a unique value.
|
|
215
|
-
*/
|
|
216
|
-
value: {
|
|
217
|
-
type: String,
|
|
218
|
-
required: true
|
|
219
|
-
}
|
|
220
|
-
};
|
|
221
|
-
const ToggleGroupItem = vue.defineComponent({
|
|
222
|
-
name: "ToggleGroupItem",
|
|
223
|
-
props: toggleGroupItemProps,
|
|
224
|
-
setup(props) {
|
|
225
|
-
const rootContext = injectToggleGroupRootContext();
|
|
226
|
-
const disabled = vue.computed(() => rootContext.disabled?.value || props.disabled);
|
|
227
|
-
const pressed = vue.computed(() => rootContext.modelValue.value?.includes(props.value));
|
|
228
|
-
const { forwardRef } = composition.useForwardExpose();
|
|
229
|
-
return {
|
|
230
|
-
rootContext,
|
|
231
|
-
disabled,
|
|
232
|
-
pressed,
|
|
233
|
-
forwardRef
|
|
234
|
-
};
|
|
235
|
-
},
|
|
236
|
-
render() {
|
|
237
|
-
return vue.h(this.rootContext.rovingFocus.value ? rovingFocus.RovingFocusItem : primitive.Primitive, {
|
|
238
|
-
asChild: true,
|
|
239
|
-
focusable: !this.disabled,
|
|
240
|
-
active: this.pressed
|
|
241
|
-
}, () => vue.h(Toggle, vue.mergeProps(this.$props, {
|
|
242
|
-
"ref": (el) => this.forwardRef(el),
|
|
243
|
-
"disabled": this.disabled,
|
|
244
|
-
"pressed": this.rootContext.type === "single" ? this.rootContext.modelValue.value === this.$props.value : this.rootContext.modelValue.value?.includes(this.$props.value),
|
|
245
|
-
"onUpdate:pressed": () => {
|
|
246
|
-
this.rootContext.changeModelValue(this.$props.value);
|
|
247
|
-
}
|
|
248
|
-
}), () => this.$slots.default?.()));
|
|
249
|
-
}
|
|
250
|
-
});
|
|
251
|
-
|
|
252
|
-
exports.Toggle = Toggle;
|
|
253
|
-
exports.ToggleGroupItem = ToggleGroupItem;
|
|
254
|
-
exports.ToggleGroupRoot = ToggleGroupRoot;
|
|
255
|
-
exports.toggleEmits = toggleEmits;
|
|
256
|
-
exports.toggleGroupItemProps = toggleGroupItemProps;
|
|
257
|
-
exports.toggleGroupRootEmits = toggleGroupRootEmits;
|
|
258
|
-
exports.toggleGroupRootProps = toggleGroupRootProps;
|
|
259
|
-
exports.toggleProps = toggleProps;
|