5.0.16 • Published 2 months ago

@yeger/vue-masonry-wall v5.0.16

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

Features

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

Links

Installation

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

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

Usage

import { createApp } from 'vue'
import MasonryWall from '@yeger/vue-masonry-wall'

const app = createApp()

app.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 setup lang="ts">
const 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: `${(index + 1) * 100}px` }">
        <h1>{{ item.title }}</h1>
        <span>{{ item.description }}</span>
      </div>
    </template>
  </masonry-wall>
</template>

Adding items, removing items, and changing items

To add/remove/change items, assign a new value to the items property, e.g., items.value = [...items.value, newItem]. DO NOT push items to the array, pop items from the array, or change items of the array (e.g., items.value.push(newItem)), as such mutations will not be detected by the reactivity and may result in rendering issues. This is intentional, as the deep watchers required to properly handle those mutations would be too expensive for complex item types and large arrays.

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 3

Create a plugin (e.g., plugins/vue-masonry-wall.ts) with the following code:

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

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

Also, see https://github.com/DerYeger/yeger/issues/43.

Development

To serve or build the demo, the library has to be built first using pnpm dev or pnpm build.

# 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

5.0.16

2 months ago

5.0.15

4 months ago

5.0.14

5 months ago

5.0.13

5 months ago

5.0.11

6 months ago

5.0.12

6 months ago

5.0.10

8 months ago

5.0.9

9 months ago

5.0.8

10 months ago

5.0.7

11 months ago

5.0.6

11 months ago

5.0.5

11 months ago

5.0.4

12 months ago

5.0.3

1 year ago

4.0.4

1 year ago

5.0.2

1 year ago

5.0.1

1 year ago

5.0.0

1 year ago

4.2.1

1 year ago

4.2.0

1 year ago

4.1.0

1 year ago

3.6.1

2 years ago

3.6.0

2 years ago

4.0.1

2 years ago

4.0.0

2 years ago

4.0.3

2 years ago

4.0.2

2 years ago

3.5.0

2 years ago

3.7.0

2 years ago

3.4.4

2 years ago

3.2.24

2 years ago

3.2.23

2 years ago

3.2.26

2 years ago

3.2.25

2 years ago

3.2.27

2 years ago

3.2.20

2 years ago

3.2.22

2 years ago

3.2.21

2 years ago

3.2.2

2 years ago

3.2.1

2 years ago

3.2.0

2 years ago

3.2.6

2 years ago

3.2.5

2 years ago

3.2.4

2 years ago

3.2.3

2 years ago

3.2.9

2 years ago

3.2.8

2 years ago

3.2.7

2 years ago

3.2.13

2 years ago

3.1.3

2 years ago

3.2.12

2 years ago

3.1.2

2 years ago

3.2.15

2 years ago

3.1.1

2 years ago

3.2.14

2 years ago

3.1.0

2 years ago

3.2.17

2 years ago

3.2.16

2 years ago

3.2.19

2 years ago

3.2.18

2 years ago

3.1.4

2 years ago

3.2.11

2 years ago

3.2.10

2 years ago

3.0.45

2 years ago

3.0.46

2 years ago

3.0.43

2 years ago

3.0.44

2 years ago

3.0.49

2 years ago

3.0.47

2 years ago

3.0.48

2 years ago

3.0.41

2 years ago

3.0.42

2 years ago

3.0.40

2 years ago

3.4.0

2 years ago

3.4.3

2 years ago

3.4.2

2 years ago

3.4.1

2 years ago

3.0.50

2 years ago

3.0.51

2 years ago

3.0.23

3 years ago

3.0.24

3 years ago

3.0.27

3 years ago

3.0.28

3 years ago

3.0.25

3 years ago

3.0.26

3 years ago

3.3.1

2 years ago

3.0.34

3 years ago

3.3.0

2 years ago

3.0.35

3 years ago

3.0.32

3 years ago

3.0.33

3 years ago

3.0.38

2 years ago

3.0.39

2 years ago

3.0.36

3 years ago

3.3.2

2 years ago

3.0.37

2 years ago

3.0.30

3 years ago

3.0.31

3 years ago

3.0.29

3 years ago

3.0.21

3 years ago

3.0.22

3 years ago

3.0.20

3 years ago

3.0.18

3 years ago

3.0.19

3 years ago

3.0.9

3 years ago

3.0.12

3 years ago

3.0.13

3 years ago

3.0.10

3 years ago

3.0.11

3 years ago

3.0.16

3 years ago

3.0.8

3 years ago

3.0.17

3 years ago

3.0.7

3 years ago

3.0.14

3 years ago

3.0.6

3 years ago

3.0.15

3 years ago

3.0.5

3 years ago

3.0.4

3 years ago

3.0.3

3 years ago

3.0.2

3 years ago

3.0.1

3 years ago

3.0.0

3 years ago

2.2.9

3 years ago

2.2.8

3 years ago

2.2.7

3 years ago

2.2.6

3 years ago

2.2.5

3 years ago

2.2.4

3 years ago

2.2.3

3 years ago

2.2.2

3 years ago

2.2.1

3 years ago

2.2.0

3 years ago

2.1.0

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago