1.0.0 • Published 4 years ago

vue-fit2box v1.0.0

Weekly downloads
1
License
Apache-2.0
Repository
github
Last release
4 years ago

npm version DOI

v-fit2box directive for Vue3

Resize the font-size in rem units so that the text fits into the html element.

In other words the font size is smaller for long texts, and bigger for shorter text passages. For example,

npm.io

Important Note

The branch main and all npm versions @1.*.* refer to fit2box as Vue3 directive. For legacy code the old Vue2 directive is available in the branch main-vue2 where the npm versions @0.*.* of the Vue2 v-fit2box directive are maintained.

Getting Started

1) Install into your project

yarn add vue-fit2box@1.0.0

2) Add directive globally to your src/main.js

import { createApp, ... } from 'vue';
import Fit2Box from 'vue-fit2box';
...
const app = createApp({ ... });
...
app.directive('fit2box', Fit2Box);
...

3) Apply directive in the Vue component

<template>
  <div>
    <div v-fit2box="mytext" class="mybox"></div>
    <button @click="nextExample">Next</button>
  </div>
</template>
<script>
export default {
  name: "DemoFit2Box",
  data() {  
    return {
      myexamples: [
        "Lorem ipsum dolor sit amet",
        "Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.",
        "Duis aute irure dolor in  reprehenderit in voluptate velit esse."
      ],
      index: 0
    }
  },
  computed: {
    mytext(){
      return this.myexamples[this.index];
    }
  },
  methods: {
    nextExample(){
      this.index = (this.index + 1) % this.myexamples.length;
    }
  },
}
</script>
.mybox {
  height: 100px;
  width: 50%;
  border: solid 1px black;
}

Appendix

Misc commands

  • Login into yarn: yarn login
  • Publish the package: yarn publish

Support

Please open an issue for support.

Contributing

Please contribute using Github Flow. Create a branch, add commits, and open a pull request.

Acknowledgements

This work was funded by the Deutsche Forschungsgemeinschaft (DFG, German Research Foundation) - 433249742. Project duration: 2020-2023.