Giter Club home page Giter Club logo

vue-resize-text's Introduction

Vue Resize Text

A vue directive which automatically resize font size based on element width.

It makes the font-size flexible on fluid or responsive layout.

npm npm Build Status npm

Live Demo: Resize the browser viewport to see the effect in action

For Vue.js 3.x see the vue3-resize-text

vue-resize-text

Installation

Install via NPM

$ npm install vue-resize-text --save

Install via CDN

<script src="https://unpkg.com/vue"></script>
<script src="https://unpkg.com/vue-resize-text"></script>

Global

Register VueResizeText globally:

import Vue from 'Vue';
import VueResizeText from 'vue-resize-text';

Vue.use(VueResizeText)

Directive v-resize-text then can be used in any of Component

<template>
  <div v-resize-text>Hello Vue</div>
</template>

Local

Include the VueResizeText directive directly into your component using import:

<template>
  <div v-resize-text>Hello Vue</div>
</template>
<script>
import ResizeText from 'vue-resize-text'
export default {
 directives: {
    ResizeText
 }
}
</script>

Usage

Basic usage

<template>
  <div>
    <div v-resize-text="{ratio:1.3, minFontSize: '30px', maxFontSize: '100px', delay: 200}">Hello Vue</div>
  </div>
</template>

<script>
  import ResizeText from 'vue-resize-text'
  export default {
    directives: {
        ResizeText
     }
  };
</script>

Directive Arguments

v-resize-text="{ratio:1.5, minFontSize: '30px', maxFontSize: '100px', delay: 200}"

Argument Description Type Default
ratio Font Ratio is the tweek to make the text resize properly, greater then 1 makes the font smaller and less then 1 make the font bigger Number 1
minFontSize Minimum font-size threshold in px Number/String 16px or 16
maxFontSize Maximum font-size threshold in px Number/String 500px or 500
delay Debound time delay on window resize Number 200

License

MIT

vue-resize-text's People

Contributors

jayeshlab avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

vue-resize-text's Issues

Possible to use this directive with nuxt. js

I've tried to create a plugin vue-resize-text.client.js
but when I apply the directive to some text, I get a warning in the console (terminal)

in ./node_modules/Vue/dist/vue.runtime.esm.js friendly-errors 18:32:57

There are multiple modules with names that only differ in casing. friendly-errors 18:32:57
This can lead to unexpected behavior when compiling on a filesystem with other case-semantic.
Use equal casing. Compare these module identifiers:

  • /Users/f/Sites/poche21/node_modules/Vue/dist/vue.runtime.esm.js
    Used by 2 module(s), i. e.
    /Users/f/Sites/poche21/node_modules/babel-loader/lib/index.js??ref--2-0!/Users/f/Sites/poche21/plugins/vue-resize-text.client.js
  • /Users/f/Sites/poche21/node_modules/vue/dist/vue.runtime.esm.js
    Used by 145 module(s), i. e.
    /Users/f/Sites/poche21/node_modules/babel-loader/lib/index.js??ref--2-0!/Users/f/Sites/poche21/.nuxt/client.js

and in the browser console I have another warning:


vue.runtime.esm.js?2b0e:619 [Vue warn]: Failed to resolve directive: resize-text

(found in at components/PostTags.vue)

Any example ?
Thank you.

Overwrite default arguments

Hi,

Is there a way to overwrite default arguments?

For example: My minFontSize should be lower than the default 16px globally.

Thanks!

Doesn't start at the correct size

This library only seems to kick in after I resize the viewport, I need the initial size to be reasonable too but it always starts at minFontSize.

Does not work in flex containers...

If I have text in a flex container child, even if the container is set to grow, the text is set to the largest size even if it doesn't fit in the container, it is never made smaller.

stay resized on page

Hi, firstly thanks for the component, its a really cool/useful idea. However it seems that the resizing doesn't apply when you reload the page, it would be very cool if it did. I'm not sure if this is a bug or if it is intentional, just thought I'd bring it up.

Text not resizing to fit into div

I am sizing / positioning a div relative to it's parent in % values (see attached screen).

Screen Shot 2023-02-27 at 2 57 41 PM

The text overflows the div. The only way to fix this is by manually changing the ratio, but I don't know in advance the length of each text.

Why isn't the text resizing properly to fit it's parent?

Quasar Support

Hi, I have tried to use this excellent package for a Vue3 project but now working with Quasar plugin I can't figure out how to use it in the project. As said in the docs packages can be integrated on the boot files, but it does not seem to be working on my end.

`import VueResizeText from 'vue-resize-text';
import { boot } from 'quasar/wrappers';

export default boot(({ app }) => {
app.use(VueResizeText);
});`

is it supported to use with Quasar? and if it is what are the proper steps to use. thanks!

[Bug] SSR (Gridsome)

Hi, I'm using this lib with Gridsome and I've got this error:

6:35:42 PM: ReferenceError: window is not defined
6:35:42 PM:     at Object.b635 (node_modules/vue-resize-text/dist/vue-resize-text.common.js:210:0)
6:35:42 PM:     at __webpack_require__ (node_modules/vue-resize-text/dist/vue-resize-text.common.js:21:0)
6:35:42 PM:     at Module.fb15 (node_modules/vue-resize-text/dist/vue-resize-text.common.js:272:0)
6:35:42 PM:     at __webpack_require__ (node_modules/vue-resize-text/dist/vue-resize-text.common.js:21:0)
6:35:42 PM:     at exports.modules.315.module.exports.1eb2.i (node_modules/vue-resize-text/dist/vue-resize-text.common.js:85:0)
6:35:42 PM:     at Object.315 (node_modules/vue-resize-text/dist/vue-resize-text.common.js:88:0)
6:35:42 PM:     at __webpack_require__ (webpack/bootstrap:25:0)
6:35:42 PM:     at Module.368 (assets/js/page--src--pages--index-vue.a5043cb5.js:1352:30)
6:35:42 PM:     at __webpack_require__ (webpack/bootstrap:25:0)
6:35:42 PM: error Command failed with exit code 1.

This is how I'm using:

<template>
<ClientOnly>
  <h1
    class="text-center text-md-left flex-column mb-4 mx-auto w-100"
    v-resize-text="{ ratio: .8, maxFontSize: '60px' }"
    v-html="content"
  />
</ClientOnly>
</template>
<script>
import ResizeText from 'vue-resize-text'

export default {
  /* ... */
  directives: {
    ResizeText
  }
}
</script>

Cloud you help me?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.