Skip to content

Instantly share code, notes, and snippets.

@indirectlylit
Last active March 2, 2018 21:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save indirectlylit/dea91635bf71974334c3f02ee120f29a to your computer and use it in GitHub Desktop.
Save indirectlylit/dea91635bf71974334c3f02ee120f29a to your computer and use it in GitHub Desktop.
<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