Giter VIP home page Giter VIP logo

vue-proper-collapse's Introduction

vue-proper-collapse

Vue implementation of the content expand/collapse functionality in the form of factory function that produces vue compatible mixin.

Install

$ npm install vue-proper-collapse // No Longer Published //

Usage

Import the mixin in your single file component.

import withCollapsible from 'vue-proper-collapse';

API

Methods:

this.collapse(height = initialMaxHeight) // Collapse to initial setup height or provided height
this.expand() // expand to ref element height (parent)
this.makeExpandable // Recalculate changed heights manually on content change and show/hide expand button
this._toggleCollapse // toggle collapsing/expanding

Computed:

this.isExpandable_() // used to show show more button if used like "show more" component

Component example

<template>
  <div>
    <div class="intro-content">
      <div ref="collapsibleContainer" :style="_containerStyle">
        <p>{{ description || 'No description' }}</p>
      </div>
    </div>
    <button
      v-if="isExpandable_"
      @click="_toggleCollapse"
      class="toggle-button button is-white center"
    >{{ isExpanded ? 'Show less' : 'Show more' }}</button>
  </div>
</template>

<script>
import withCollapsible from "./withCollapsible";

export default {
  mixins: [withCollapsible(100, "collapsibleContainer")],
  data: () => ({
    description:
      'Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.'
  }),
};
</script>

<style lang="scss">
.intro-content {
  max-width: 30%;
  margin: 0 auto;

  p {
    padding: 1rem;
    margin: 0;
  }
}
</style>

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.