Vue Height Collapsible

0.1.1 · active · verified Sun Apr 19

Vue HeightCollapsible is a UI component library offering a flexible and accessible collapsible content area for Vue.js applications. Currently at version 0.1.1, it provides a `HeightCollapsible` component that leverages CSS transitions for smooth expand/collapse animations, distinguishing itself by automatically handling elements with variable and dynamic heights. It supports both Vue 2 (2.6.x) and Vue 3 simultaneously through distinct import paths, making it versatile for projects migrating or supporting both ecosystems. While the release cadence isn't explicitly defined, its low version number suggests it may be a utility that receives updates as needed rather than on a fixed schedule. A key differentiator is its reliance on custom CSS for the transition properties, giving developers full control over the animation timing and curve, rather than embedding these styles directly.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates how to integrate `HeightCollapsible` into a Vue 3 component, toggle its state with a button, display its internal collapse state, and apply the required CSS transition for animation. It also includes basic ARIA attributes for accessibility.

<template>
  <div class="my-component">
    <button @click="isOpen = !isOpen" :aria-expanded="isOpen" aria-controls="my-collapsible-1">
      <span>Toggle {{ collapseState }}</span>
    </button>
    <HeightCollapsible
      :isOpen="isOpen"
      @update="onUpdate"
      v-slot="{ state }"
      id="my-collapsible-1"
    >
      <p>I know the collapse state: {{ state }}</p>
      <p>Paragraph of text.</p>
      <p>Another paragraph is also OK.</p>
      <p>Images and any other content are ok too.</p>
    </HeightCollapsible>
  </div>
</template>

<script lang="ts">
import { defineComponent } from 'vue';
import HeightCollapsible from 'vue-height-collapsible/vue3'; // Assuming Vue 3 context

export default defineComponent({
  name: 'MyComponent',
  components: {
    HeightCollapsible,
  },
  data() {
    return {
      isOpen: true,
      collapseState: '' as string,
    };
  },
  methods: {
    onUpdate({ state }: { state: string }) {
      this.collapseState = state;
    },
  },
});
</script>

<style>
/* Essential for animation */
[data-height-collapsible] {
  transition: height 280ms cubic-bezier(0.4, 0, 0.2, 1);
}
/* Add any other styling as needed */
.my-component {
  border: 1px solid #eee;
  padding: 1rem;
  margin-top: 1rem;
}
button {
  background-color: #007bff;
  color: white;
  border: none;
  padding: 0.5rem 1rem;
  cursor: pointer;
  border-radius: 4px;
}
button:hover {
  background-color: #0056b3;
}
</style>

view raw JSON →