A simple component to fit text inside a container.
TODO add npm and stuffs TODO make compiled version for use without build tools
Browser | Tested version |
---|---|
Chrome (OSX) | 57.0.2987.133 |
Safari | 9.1 (10601.5.17.4) |
Firefox (OSX) | 44.0.2 |
TODO test other browsers
You can register this component globally or just import it when you need it in one of your own custom components.
Install the component with Vue.use()
import FitText from 'vue-fit-text/index.js';
Vue.use(FitText);
From now on you can use the <fit-text>
component anywhere in your Vue app.
Example usage in single file component
<template>
<div>
<h1>
<fit-text>This text should always fit one line.</fit-text>
</h1>
</div>
</template>
<script>
import fitText from 'vue-fit-text/fitText.vue';
export default {
components: {
fitText,
},
}
</script>
The component has a few properties that can be passed through for a little customisation
Default: 1
The maximum amount of lines the text should occupy.
Default: 'em'
What unit to use for the "font-size" property.
Default: 0.5
The minimum font size to use.
Default: 1
The maximum font size. The script will start there and gradually scale down the text until it fits the target line count.
TODO