@vue-interface/btn-dropdown 2.0.0-beta.2 → 2.0.0-beta.20

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