Coder Social home page Coder Social logo

ajobi / vue-snip Goto Github PK

View Code? Open in Web Editor NEW
65.0 1.0 7.0 1.55 MB

Vue.js directive that clamps the content of a text element if it exceeds specified number of lines.

Home Page: https://www.npmjs.com/package/vue-snip

License: MIT License

JavaScript 18.05% HTML 29.10% TypeScript 52.85%

vue-snip's Introduction

vue-snip

GitHub js-standard-style npm bundle size

Vue.js directive that clamps the content of a text element if it exceeds the specified number of lines.

Key features:

  • two snipping approaches (CSS / JavaScript) picked on a per-element basis
  • no need to specify line heights
  • re-snipping on element resize and reactive data change

To get a hands-on experience try the Interactive Demo.

Installation

# install with npm
npm install vue-snip

# or with yarn
yarn add vue-snip

Vue 2

import Vue from 'vue'
import VueSnip from 'vue-snip'
import App from './App'

Vue.use(VueSnip)

new Vue({ render: h => h(App) }).$mount('#app')

Vue 3

import { createApp } from 'vue'
import VueSnip from 'vue-snip'
import App from './App'

createApp(App).use(VueSnip).mount('#app')

Usage

<!-- minimal example -->
<template>
  <p v-snip> ... </p>
</template>
<!-- with options -->
<template>
  <p v-snip="{ lines: 3 }"> ... </p>
</template>
<!-- with several options -->
<template>
  <p v-snip="{ lines: 3, mode: 'js', midWord: false }"> ... </p>
</template>
<!-- with options and callback -->
<template>
  <p v-snip="{ lines: 3, onSnipped }"> ... </p>
</template>

<script>
export default {
  data () {
    return {
      hasEllipsis: false,
    }
  },
  methods: {
    onSnipped (newState) {
      this.hasEllipsis = newState.hasEllipsis
    }
  }
}
</script>

How it works

The library uses js-snip under the hood. You can find more about the options and how snipping works in its documentation.

Change Log

All changes are documented in the change log.

vue-snip's People

Contributors

ajobi avatar dependabot[bot] avatar revelstoke-tim avatar

Stargazers

Banana Energy avatar  avatar Arturo Armando González Fernández avatar Oleksii avatar  avatar  avatar Heunsig Jo avatar James Smith avatar Dino avatar czh avatar  avatar Amir Adel avatar FQIP avatar zhengxs2018 avatar Kanata Miyahana avatar Enzo Notario avatar Dariusz Habiak avatar Emmanuel Salomon avatar Németh Gábor avatar luxing avatar Toemme avatar Timmy avatar Mark avatar Egor avatar  avatar Michał Olejniczak avatar Giovane Cardoso avatar  avatar Hau Nguyen avatar Nhật  Phạm avatar  avatar Roman Drahan avatar yuhang avatar Mohamed Hussein avatar Guillaume Pellerin avatar Volker Rose avatar Mortexa avatar  avatar Marko Rapaic avatar Phantas Weng avatar Ean avatar  avatar sidouglas avatar Alan Bloom avatar  avatar 湛蓝 avatar  avatar  avatar Daniel Pereira avatar Yo avatar Pixelomo avatar Paul Harrer avatar Nils Müller avatar Leo Oliveira avatar Arkshine avatar Kayode Samson Adelola  avatar Curtis avatar Danny Spangenberg avatar Jie Luo avatar AmirHossein avatar Yan avatar dami avatar 99corps avatar Mike Syomin avatar Ben Larcey avatar

Watchers

 avatar

vue-snip's Issues

Nuxt 3 compatibility

I wrote a simple plugin for VueShip

import VueShip from 'vue-snip'

export default defineNuxtPlugin((nuxtApp) => {
  nuxtApp.vueApp.use(VueShip);
});

I use it like this

<span v-ship="{lines: 2}">My long text</span

But I get an error
[Vue warn]: Failed to resolve directive: ship

VueJS: 3.3.4
Nuxt: 3.5.3
VueShip: 2.0.1

Performance problems

I am using this in a v-for loop that has items that use v-snip as follows:

v-snip="{ lines: 2 }"

Once I add that, my render time for 2000 items goes from under 1 second to over 10 seconds. Ideas what I could be doing wrong? I even have a keep-alive around the whole thing and it still takes forever.

Vue 3 Compatibilty

Hello, I see in your Readme that this is compatible with Vue 3 - is there something different that I need to do within a Vue 3 use case? It is not working in any situations for me currently...

Noticed this error in the console: Uncaught (in promise) TypeError: Cannot read property 'maxLines' of undefined

ResizeObserver loop error thrown

Found out about this error after my browser error tracker quota got filled. It is not normally visible in the console but the error tracker picks it up, a lot. Probably each time a page that contains v-snip is rendered.

How to reproduce:

  1. Go to demo page https://ajobi.github.io/vue-snip/
  2. Write to console: window.onerror = console.log
  3. Adjust max lines prop in the form.
  4. Observe ResizeObserver loop completed with undelivered notifications appearing in the console.

The error is thrown in other cases as well when visibility of ellipsis needs checking . Some of them:

  1. toggle "Snip the card text" checkbox value,
  2. change window width after removing demo page's 500px width style. Window with change should be in the range to trigger changes to ellipsis state,
  3. change card width to make ellipsis appear or disappear.

Versions used:
vue-snip: 2.0.1
js-snip: 1.2.0

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.