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