npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@yeger/vue2-masonry-wall

v5.0.10

Published

Responsive masonry layout with SSR support and zero dependencies for Vue 2.

Downloads

6,610

Readme

Features

  • 📱 Responsive: Responsive with configurable column width and gaps. Based on ResizeObserver.
  • 🔁 Reactive: Reacts to property changes.
  • 🪶 Lightweight: Zero external dependencies. Less than 2 kB.
  • ⬅️ RTL: Supports LTR and RTL layouts.

Links

Installation

# yarn
$ yarn add @yeger/vue2-masonry-wall

# npm
$ npm install @yeger/vue2-masonry-wall

Usage

import Vue from 'vue'
import MasonryWall from '@yeger/vue2-masonry-wall'

Vue.use(MasonryWall)

Props:

  • items: Array of items. Required.
  • column-width: Minimal width of columns in px. Can be either a number, or a non-empty array of numbers. Defaults to 300. If an array is passed, the first value will be used for the first column, the second value for the second column, and so on. If the array is shorter than the number of columns, the pattern will be repeated starting at the first value.
  • gap: Spacing between items in px. Defaults to 0.
  • rtl: Toggles between LTR (false) and RTL (true) layouts. Defaults to false.
  • ssr-columns: Number of server-side-rendered columns. Optional.
  • scroll-container: Scrolling HTMLElement parent element that will be used for restoring scroll position. If omitted, window is used.
  • min-columns: Minimum number of columns. undefined implies no constraint. Defaults to undefined, but will always be at least 1 in the output.
  • max-columns: Maximum number of columns. undefined implies no constraint. Defaults to undefined. If min-columns is greater than max-columns, min-columns will take precedence.
  • keyMapper: Optional mapper function that receives an item, its column index, its row index, and its index w.r.t. the items array and returns a unique key. Defaults to (_item, _column, _row, index) => index.
<script>
export default {
  data() {
    return {
      items: [
        { title: 'First', description: 'The first item.' },
        { title: 'Second', description: 'The second item.' },
      ],
    }
  },
}
</script>

<template>
  <masonry-wall :items="items" :ssr-columns="1" :column-width="300" :gap="16">
    <template #default="{ item, index }">
      <div style="height: 100px">
        <h1>{{ item.title }} ({{ index }})</h1>
        <span>{{ item.description }}</span>
      </div>
    </template>
  </masonry-wall>
</template>

Adding items

To add new items, assign a new value to the items property, e.g., items.value = [...items.value, newItem]. DO NOT push items to the array (e.g., items.value.push(newItem)), as such mutations will not be detected by the reactivity.

Limitations

This library intentionally doesn't handle elements with dynamically changing height, as this would cause constant changes of the column distribution. As a consequence, the initial height of items is used. For images, specifying aspect ratios can prevent unbalanced distributions.

All columns have the same width, specified by the column-width property. In addition, the elements of items should not set a specific width and instead be full-width, e.g., use width: 100%.

Nuxt 2

Nuxt 2 only supports v2.2.1 or lower of this library. See https://github.com/DerYeger/yeger/issues/129#issuecomment-1437322140 for more information.

Development

# install dependencies
$ pnpm install

# develop in watch mode
$ pnpm dev

# build for production
$ pnpm build

# lint project files
$ pnpm lint

# run tests
$ pnpm test

Disclaimer

This component originated as a modified version of vue-masonry-wall by Fuxing Loh.

License

MIT - Copyright © Fuxing Loh, Jan Müller