@itfin/components 1.3.20 → 1.3.21
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/package.json
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
<script>
|
|
2
2
|
import { Vue, Component, Prop, Watch, PropSync } from 'vue-property-decorator';
|
|
3
3
|
import itfButton from '../button/Button';
|
|
4
|
+
import itfDropdownMenu from './DropdownMenu';
|
|
4
5
|
|
|
5
6
|
let globalModalIndex = 0; // base modal z-index
|
|
6
7
|
|
|
7
8
|
export default @Component({
|
|
9
|
+
functional: true,
|
|
8
10
|
name: 'itfDropdown',
|
|
9
11
|
components: {
|
|
10
|
-
itfButton
|
|
12
|
+
itfButton,
|
|
13
|
+
itfDropdownMenu
|
|
11
14
|
},
|
|
12
15
|
})
|
|
13
16
|
class itfDropdown extends Vue {
|
|
@@ -20,91 +23,41 @@ class itfDropdown extends Vue {
|
|
|
20
23
|
@Prop({ type: Boolean }) shadow;
|
|
21
24
|
@Prop({ type: Boolean }) disabled;
|
|
22
25
|
@Prop({ type: Boolean }) text;
|
|
23
|
-
@Prop({ type: Boolean
|
|
26
|
+
@Prop({ type: Boolean }) appendToBody;
|
|
24
27
|
@Prop({ validator: (value) => [true, false, 'inside', 'outside'].includes(value), default: true }) autoclose;
|
|
25
28
|
@Prop({ type: Object, default: () => ({}) }) buttonOptions;
|
|
26
29
|
@Prop({ type: Object, default: () => ({}) }) menuOptions;
|
|
27
30
|
|
|
28
31
|
modalId = '';
|
|
29
|
-
modalEl = null;
|
|
30
32
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
// if (!this.modalEl) {
|
|
38
|
-
// return;
|
|
39
|
-
// }
|
|
40
|
-
// if (newValue) {
|
|
41
|
-
// this.modalEl.show();
|
|
42
|
-
// } else {
|
|
43
|
-
// this.modalEl.hide();
|
|
44
|
-
// }
|
|
45
|
-
// }
|
|
46
|
-
|
|
47
|
-
render (createElement) {
|
|
48
|
-
const modalId = `dropdownId${this._uid}`;
|
|
49
|
-
const { right, shadow, label } = this;
|
|
50
|
-
return createElement('div', {
|
|
51
|
-
staticClass: 'dropdown'
|
|
52
|
-
}, [
|
|
33
|
+
render (createElement, context) {
|
|
34
|
+
const { props, slots, data } = context;
|
|
35
|
+
const modalId = `dropdownId${globalModalIndex++}`;
|
|
36
|
+
const { buttonOptions, toggle, right, shadow, label, appendToBody } = props;
|
|
37
|
+
const { button, default: defaultSlot } = slots();
|
|
38
|
+
let elements = [
|
|
53
39
|
createElement(
|
|
54
|
-
|
|
40
|
+
itfButton,
|
|
55
41
|
{
|
|
56
|
-
props:
|
|
57
|
-
class: { 'dropdown-toggle':
|
|
42
|
+
props: buttonOptions || {},
|
|
43
|
+
class: { 'dropdown-toggle': toggle },
|
|
58
44
|
attrs: { id: modalId, 'data-bs-toggle': 'dropdown', 'aria-expanded': 'false' },
|
|
59
45
|
ref: 'toggle',
|
|
60
46
|
},
|
|
61
|
-
|
|
47
|
+
button || label
|
|
62
48
|
),
|
|
63
49
|
createElement(
|
|
64
|
-
|
|
50
|
+
itfDropdownMenu,
|
|
65
51
|
{
|
|
66
|
-
|
|
67
|
-
class: { 'dropdown-menu-end': right, 'shadow': shadow },
|
|
68
|
-
staticClass: 'itf-dropdown__menu dropdown-menu',
|
|
69
|
-
ref: 'dropdown',
|
|
52
|
+
props: { ...props, toggleId: modalId },
|
|
70
53
|
},
|
|
71
|
-
|
|
54
|
+
defaultSlot
|
|
72
55
|
)
|
|
73
|
-
]
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
created() {
|
|
77
|
-
console.info(this);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
async mounted() {
|
|
81
|
-
console.info(this);
|
|
82
|
-
if (typeof window === 'undefined' || !this.$refs.toggle) {
|
|
83
|
-
return;
|
|
56
|
+
];
|
|
57
|
+
if (!appendToBody) {
|
|
58
|
+
elements = [createElement('div', { class: `dropdown ${data.staticClass || ''}` }, elements)];
|
|
84
59
|
}
|
|
85
|
-
|
|
86
|
-
const {default: Dropdown} = await import('bootstrap/js/src/dropdown.js');
|
|
87
|
-
this.modalEl = new Dropdown(this.$refs.toggle, {
|
|
88
|
-
reference: 'toggle',
|
|
89
|
-
autoClose: this.autoclose
|
|
90
|
-
});
|
|
91
|
-
let context = document.body;
|
|
92
|
-
if (this.appendToBody && this.$refs.dropdown instanceof Node && this.$refs.dropdown.parentNode) {
|
|
93
|
-
this.$refs.dropdown.parentNode.removeChild(this.$refs.dropdown);
|
|
94
|
-
context.appendChild(this.$refs.dropdown); // should append only to body
|
|
95
|
-
}
|
|
96
|
-
} catch (err) {
|
|
97
|
-
// ignore
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
this.$el.addEventListener('shown.bs.dropdown', () => {
|
|
101
|
-
setTimeout(() => {
|
|
102
|
-
this.$emit('open');
|
|
103
|
-
}, 500);
|
|
104
|
-
});
|
|
105
|
-
this.$el.addEventListener('hidden.bs.dropdown', () => {
|
|
106
|
-
this.$emit('close');
|
|
107
|
-
});
|
|
60
|
+
return elements;
|
|
108
61
|
}
|
|
109
62
|
|
|
110
63
|
show() {
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="itf-dropdown__menu dropdown-menu" ref="dropdown" :aria-labelledby="modalId" :class="{'dropdown-menu-end': right, 'shadow': shadow}">
|
|
3
|
+
<slot></slot>
|
|
4
|
+
</div>
|
|
5
|
+
</template>
|
|
6
|
+
<script>
|
|
7
|
+
import { Vue, Component, Prop, Watch, PropSync } from 'vue-property-decorator';
|
|
8
|
+
|
|
9
|
+
let globalModalIndex = 0; // base modal z-index
|
|
10
|
+
|
|
11
|
+
export default @Component({
|
|
12
|
+
name: 'itfDropdownMenu'
|
|
13
|
+
})
|
|
14
|
+
class itfDropdownMenu extends Vue {
|
|
15
|
+
@PropSync('visible') value;
|
|
16
|
+
@Prop({ type: String, default: 'down', validator: (value) => ['down', 'start', 'end', 'up'].includes(value) }) placement;
|
|
17
|
+
@Prop({ type: String, default: 'click', validator: (value) => ['click', 'focus', 'hover', 'manual'].includes(value) }) trigger;
|
|
18
|
+
@Prop({ type: String, default: 'Dropdown' }) label;
|
|
19
|
+
@Prop({ type: Boolean }) right;
|
|
20
|
+
@Prop({ type: Boolean }) toggle;
|
|
21
|
+
@Prop({ type: Boolean }) shadow;
|
|
22
|
+
@Prop({ type: Boolean }) disabled;
|
|
23
|
+
@Prop({ type: Boolean }) text;
|
|
24
|
+
@Prop({ type: Boolean }) appendToBody;
|
|
25
|
+
@Prop({ type: String }) toggleId;
|
|
26
|
+
@Prop({ validator: (value) => [true, false, 'inside', 'outside'].includes(value), default: true }) autoclose;
|
|
27
|
+
@Prop({ type: Object, default: () => ({}) }) buttonOptions;
|
|
28
|
+
@Prop({ type: Object, default: () => ({}) }) menuOptions;
|
|
29
|
+
|
|
30
|
+
modalId = '';
|
|
31
|
+
modalEl = null;
|
|
32
|
+
|
|
33
|
+
async mounted() {
|
|
34
|
+
this.modalId = `dropdownId${globalModalIndex++}`;
|
|
35
|
+
const toggle = document.getElementById(this.toggleId);
|
|
36
|
+
if (typeof window === 'undefined' || !toggle) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const { default: Dropdown } = await import('bootstrap/js/src/dropdown.js');
|
|
40
|
+
let context = document.body;
|
|
41
|
+
this.modalEl = new Dropdown(toggle, {
|
|
42
|
+
reference: 'toggle',
|
|
43
|
+
autoClose: this.autoclose
|
|
44
|
+
});
|
|
45
|
+
if (this.appendToBody && this.$el instanceof Node && this.$el.parentNode) {
|
|
46
|
+
this.$el.parentNode.removeChild(this.$el);
|
|
47
|
+
context.appendChild(this.$el); // should append only to body
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
this.$el.addEventListener('shown.bs.dropdown', () => {
|
|
51
|
+
setTimeout(() => {
|
|
52
|
+
this.$emit('open');
|
|
53
|
+
}, 500);
|
|
54
|
+
});
|
|
55
|
+
this.$el.addEventListener('hidden.bs.dropdown', () => {
|
|
56
|
+
this.$emit('close');
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
show() {
|
|
61
|
+
if (this.modalEl) {
|
|
62
|
+
this.modalEl.show();
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
hide() {
|
|
67
|
+
if (this.modalEl) {
|
|
68
|
+
this.modalEl.hide();
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
</script>
|