@vue-interface/btn-dropdown 2.0.0-beta.0 → 2.0.0-beta.10

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,429 +0,0 @@
1
- import { createPopper } from '@popperjs/core';
2
- import { Btn } from '@vue-interface/btn';
3
- import { BtnGroup } from '@vue-interface/btn-group';
4
- import { DropdownMenu } from '@vue-interface/dropdown-menu';
5
- import BtnDropdownAction from './BtnDropdownAction.vue';
6
-
7
- const TAB_KEYCODE = 9;
8
-
9
- export default {
10
-
11
- components: {
12
- BtnDropdownAction,
13
- BtnGroup,
14
- DropdownMenu
15
- },
16
-
17
- extends: Btn,
18
-
19
- props: {
20
-
21
- /**
22
- * Display the dropdown menu aligned left or right
23
- *
24
- * @property String
25
- */
26
- align: {
27
- type: String,
28
- default: 'left',
29
- validate(value) {
30
- return ['left', 'right'].indexOf(value.toLowerCase()) !== -1;
31
- }
32
- },
33
-
34
- /**
35
- * Should animate the dropdown opening.
36
- *
37
- * @property {Boolean}
38
- */
39
- animated: {
40
- type: Boolean,
41
- default: true
42
- },
43
-
44
- /**
45
- * Additional button classes.
46
- *
47
- * @property {Object|String}
48
- */
49
- buttonClass: [Object, String],
50
-
51
- /**
52
- * Show the caret.
53
- *
54
- * @property {Boolean}
55
- */
56
- caret: {
57
- type: Boolean,
58
- default: true
59
- },
60
-
61
- /**
62
- * Should display the toggle button as a circle.
63
- *
64
- * @property Boolean
65
- */
66
-
67
- // circle: {
68
- // type: Boolean,
69
- // default: false
70
- // },
71
-
72
- /**
73
- * Display as a dropup instead of a dropdown.
74
- *
75
- * @property Boolean
76
- */
77
- dropup: {
78
- type: Boolean,
79
- default: false
80
- },
81
-
82
- /**
83
- * Display as a dropright instead of a dropdown.
84
- *
85
- * @property Boolean
86
- */
87
- dropright: {
88
- type: Boolean,
89
- default: false
90
- },
91
-
92
- /**
93
- * Display as a dropleft instead of a dropdown.
94
- *
95
- * @property Boolean
96
- */
97
- dropleft: {
98
- type: Boolean,
99
- default: false
100
- },
101
-
102
- /**
103
- * The action height.
104
- *
105
- * @property {String}
106
- */
107
- height: String,
108
-
109
- /**
110
- * The href action.
111
- *
112
- * @property {String}
113
- */
114
- href: String,
115
-
116
- /**
117
- * Is the dropdown a nav item?
118
- *
119
- * @property {Boolean}
120
- */
121
- nav: Boolean,
122
-
123
- /**
124
- * The toggle button's label. If not defined as an attribute,
125
- * you can override with the component's slot (inner html).
126
- *
127
- * @property {String}
128
- */
129
- label: String,
130
-
131
- offset: {
132
- type: Number,
133
- default: 5,
134
- },
135
-
136
- /**
137
- * Should rotate the toggle button when opened.
138
- *
139
- * @property {Boolean}
140
- */
141
- rotate: {
142
- type: Boolean,
143
- default: false
144
- },
145
-
146
- /**
147
- * Display the dropdown button with a split toggle button.
148
- *
149
- * @property {Boolean}
150
- */
151
- split: {
152
- type: Boolean,
153
- default: false
154
- },
155
-
156
- /**
157
- * The "to" path, used for vue-router.
158
- *
159
- * @property {String|Object}
160
- */
161
- to: [String, Object],
162
-
163
- /**
164
- * The button type attribute.
165
- *
166
- * @property {String}
167
- */
168
- type: {
169
- type: String,
170
- default: 'button'
171
- },
172
-
173
- /**
174
- * The action width.
175
- *
176
- * @property {String}
177
- */
178
- width: String,
179
-
180
- },
181
-
182
- data() {
183
- return {
184
- popper: null,
185
- triggerAnimation: false,
186
- expanded: false
187
- };
188
- },
189
-
190
- computed: {
191
- scope() {
192
- return {
193
- // Pass the computed props.
194
- placement: this.placement,
195
- variantClassPrefix: this.variantClassPrefix,
196
- sizeableClassPrefix: this.sizeableClassPrefix,
197
- classes: this.classes,
198
- actionClasses: this.actionClasses,
199
- toggleStyle: this.toggleStyle,
200
- toggleClasses: this.toggleClasses,
201
-
202
- // Pass the methods
203
- focus: this.focus,
204
- queryFocusable: this.queryFocusable,
205
- isFocusable: this.isFocusable,
206
- toggle: this.toggle,
207
- show: this.show,
208
- hide: this.hide,
209
- onBlur: this.onBlur,
210
- onClickItem: this.onClickItem,
211
- onClickToggle: this.onClickToggle
212
- };
213
- },
214
-
215
- placement() {
216
- if(this.dropup) {
217
- return 'top';
218
- }
219
-
220
- if(this.dropleft) {
221
- return 'left';
222
- }
223
-
224
- if(this.dropright) {
225
- return 'right';
226
- }
227
-
228
- return 'bottom';
229
- },
230
-
231
- variantClassPrefix() {
232
- return 'btn' + (this.outline ? '-outline' : '');
233
- },
234
-
235
- sizeableClassPrefix() {
236
- return 'btn';
237
- },
238
-
239
- classes() {
240
- return {
241
- 'dropdown': this.dropup && this.dropright && this.dropleft,
242
- 'dropup': this.dropup,
243
- 'dropright': this.dropright,
244
- 'dropleft': this.dropleft,
245
- 'icon-only': !this.nav && !this.split && !!this.$slots.icon && !this.$slots.label,
246
- 'hide-caret': !this.caret,
247
- 'expanded': this.expanded,
248
- 'rotate-90': !this.nav && this.split && this.rotate && this.expanded,
249
- };
250
- },
251
-
252
- actionClasses() {
253
- return Object.assign({
254
- 'btn': !this.nav,
255
- [this.variantClass]: !this.nav && !!this.variant,
256
- [this.sizeableClass]: !!this.size,
257
- }, typeof this.buttonClass === 'object' ? this.buttonClass : {
258
- [this.buttonClass]: !!this.buttonClass
259
- });
260
- },
261
-
262
- toggleStyle() {
263
- return {
264
- width: this.width,
265
- height: this.height,
266
- };
267
- },
268
-
269
- toggleClasses() {
270
- return Object.assign({
271
- 'active': this.active,
272
- 'btn': !this.nav,
273
- 'btn-block': !!this.block,
274
- 'nav-link': !!this.nav,
275
- 'rotate-90': !this.split && this.rotate && this.expanded,
276
- 'dropdown-toggle': true,
277
- 'dropdown-toggle-split': !this.nav && this.split,
278
- [this.variantClass]: !this.nav && !!this.variant,
279
- [this.sizeableClass]: !!this.size,
280
- }, typeof this.buttonClass === 'object' ? this.buttonClass : {
281
- [this.buttonClass]: !!this.buttonClass
282
- });
283
- }
284
- },
285
-
286
- beforeDestroy() {
287
- this.popper && this.popper.destroy();
288
- },
289
-
290
- methods: {
291
-
292
- /**
293
- * Focus on the the dropdown toggle button
294
- *
295
- * @return void
296
- */
297
- focus() {
298
- this.$el.querySelector('.dropdown-toggle').focus();
299
- },
300
-
301
- /**
302
- * Focus on the the dropdown toggle button
303
- *
304
- * @return void
305
- */
306
- queryFocusable() {
307
- return this.$el.querySelector('.dropdown-menu').querySelectorAll('label, input, select, textarea, [tabindex]:not([tabindex="-1"])');
308
- },
309
-
310
- /**
311
- * Method to check if the given element is focusable.
312
- *
313
- * @return void
314
- */
315
- isFocusable(element) {
316
- const nodes = this.queryFocusable();
317
-
318
- for(let i in nodes) {
319
- if(element === nodes[i]) {
320
- return true;
321
- }
322
- }
323
-
324
- return false;
325
- },
326
-
327
- /**
328
- * Toggle the dropdown menu
329
- *
330
- * @return void
331
- */
332
- toggle(e) {
333
- !this.expanded ? this.show() : this.hide();
334
- },
335
-
336
- /**
337
- * Show the dropdown menu
338
- *
339
- * @return void
340
- */
341
- show() {
342
- this.expanded = true;
343
-
344
- const target = this.$refs.split && this.$refs.split.$el || this.$el;
345
-
346
- // Hack for popper for align="right"
347
- // this.$refs.menu.$el.style.left = 'auto';
348
- // this.$refs.menu.$el.style.right = 'auto';
349
-
350
- if(!this.nav && !this.popper) {
351
- this.popper = createPopper(target, this.$refs.menu.$el, {
352
- placement: `${this.placement}-${this.align === 'left' ? 'start' : 'end'}`,
353
- onFirstUpdate: () => {
354
- this.triggerAnimation = this.animated;
355
- },
356
- modifiers: [
357
- {
358
- name: 'offset',
359
- options: {
360
- offset: [0, !this.nav ? this.offset : 1]
361
- // offset: ['.125rem', !this.nav ? 4 : 1],
362
- },
363
- },
364
- ]
365
- });
366
- }
367
- else if(this.popper) {
368
- this.popper.update();
369
- }
370
- },
371
-
372
- /**
373
- * Hide the dropdown menu
374
- *
375
- * @return void
376
- */
377
- hide() {
378
- this.expanded = false;
379
- },
380
-
381
- /**
382
- * A callback function for the `blur-item` event.
383
- *
384
- * @return void
385
- */
386
- onBlur(e) {
387
- if(!this.$el.contains(e.relatedTarget)) {
388
- this.hide();
389
- }
390
- },
391
-
392
- /**
393
- * A callback function for the `click-item` event.
394
- *
395
- * @return void
396
- */
397
- onClickItem(e) {
398
- if(!this.isFocusable(e.target)) {
399
- this.hide();
400
- }
401
- },
402
-
403
- /**
404
- * A callback function for the `click-toggle` event.
405
- *
406
- * @return void
407
- */
408
- onClickToggle(e) {
409
- e.target.focus();
410
-
411
- this.$emit('click-toggle', e);
412
-
413
- if(!e.defaultPrevented) {
414
- this.toggle();
415
- }
416
- }
417
-
418
- },
419
-
420
- watch: {
421
- expanded(value) {
422
- this.$nextTick(() => {
423
- this.$emit(value ? 'show' : 'hide');
424
- this.$emit('toggle', value);
425
- });
426
- }
427
- }
428
-
429
- };
File without changes