mirror of
https://github.com/Hopiu/vue-material.git
synced 2026-05-25 23:33:45 +00:00
* [new] md-tabs improvements : md-tooltip * [fix] Set the bottom default value on the prop definition
97 lines
2.1 KiB
Vue
97 lines
2.1 KiB
Vue
<template>
|
|
<div class="md-tab" :id="tabId" :style="styles">
|
|
<slot></slot>
|
|
</div>
|
|
</template>
|
|
|
|
<script>
|
|
import uniqueId from '../../core/utils/uniqueId';
|
|
import getClosestVueParent from '../../core/utils/getClosestVueParent';
|
|
|
|
export default {
|
|
props: {
|
|
id: [String, Number],
|
|
mdLabel: [String, Number],
|
|
mdIcon: String,
|
|
mdActive: Boolean,
|
|
mdDisabled: Boolean,
|
|
mdTooltip: String,
|
|
mdTooltipDirection: {
|
|
type: String,
|
|
default: 'bottom'
|
|
}
|
|
},
|
|
data() {
|
|
return {
|
|
mounted: false,
|
|
tabId: this.id || 'tab-' + uniqueId(),
|
|
width: '0px',
|
|
left: '0px'
|
|
};
|
|
},
|
|
watch: {
|
|
mdActive() {
|
|
this.updateTabData();
|
|
},
|
|
mdDisabled() {
|
|
this.updateTabData();
|
|
},
|
|
mdIcon() {
|
|
this.updateTabData();
|
|
},
|
|
mdLabel() {
|
|
this.updateTabData();
|
|
},
|
|
mdTooltip() {
|
|
this.updateTabData();
|
|
},
|
|
mdTooltipDirection() {
|
|
this.updateTabData();
|
|
}
|
|
},
|
|
computed: {
|
|
styles() {
|
|
return {
|
|
width: this.width,
|
|
left: this.left
|
|
};
|
|
}
|
|
},
|
|
methods: {
|
|
getTabData() {
|
|
return {
|
|
id: this.tabId,
|
|
label: this.mdLabel,
|
|
icon: this.mdIcon,
|
|
active: this.mdActive,
|
|
disabled: this.mdDisabled,
|
|
tooltip: this.mdTooltip,
|
|
tooltipDirection: this.mdTooltipDirection,
|
|
ref: this
|
|
};
|
|
},
|
|
updateTabData() {
|
|
this.parentTabs.updateTab(this.getTabData());
|
|
}
|
|
},
|
|
mounted() {
|
|
this.parentTabs = getClosestVueParent(this.$parent, 'md-tabs');
|
|
|
|
if (!this.parentTabs) {
|
|
throw new Error('You must wrap the md-tab in a md-tabs');
|
|
}
|
|
|
|
this.$nextTick(() => {
|
|
this.mounted = true;
|
|
this.parentTabs.registerTab(this.getTabData());
|
|
|
|
if (this.mdActive) {
|
|
this.parentTabs.activeTab = this.tabId;
|
|
}
|
|
});
|
|
},
|
|
beforeDestroy() {
|
|
this.parentTabs.unregisterTab(this.getTabData());
|
|
}
|
|
};
|
|
</script>
|