vue-fit2box

1.0.0 • Public • Published

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,

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
  1. Add directive globally to your src/main.js
import { createApp, ... } from 'vue';
import Fit2Box from 'vue-fit2box';
...
const app = createApp({ ... });
...
app.directive('fit2box', Fit2Box);
...
  1. 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.

Package Sidebar

Install

npm i vue-fit2box

Weekly Downloads

27

Version

1.0.0

License

Apache-2.0

Unpacked Size

15.6 kB

Total Files

5

Last publish

Collaborators

  • 554c46