Last active
March 2, 2018 21:04
-
-
Save indirectlylit/dea91635bf71974334c3f02ee120f29a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<span :title="tooltip">{{ title }}</span> | |
</template> | |
<script> | |
import shave from 'shave'; | |
import responsiveElement from 'kolibri.coreVue.mixins.responsiveElement'; | |
export default { | |
mixins: [responsiveElement], | |
props: { | |
title: { | |
type: String, | |
required: true, | |
}, | |
maxheight: { | |
type: Number, | |
required: true, | |
validator(value) { | |
return value > 0; | |
}, | |
}, | |
}, | |
data() { | |
return { | |
hasTooltip: false, | |
}; | |
}, | |
computed: { | |
tooltip() { | |
if (!this.hasTooltip) { | |
return null; | |
} | |
return this.title; | |
}, | |
}, | |
watch: { | |
// use the responsive element sensor to detect size changes | |
elSize: { | |
handler() { | |
shave(this.$el, this.maxheight); | |
this.$nextTick(() => { | |
this.hasTooltip = Boolean(this.$el.querySelector('.js-shave')); | |
}); | |
}, | |
deep: true, | |
}, | |
}, | |
}; | |
</script> | |
<style lang="stylus" scoped></style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment