1.1.0 • Published 4 years ago

overlay-image v1.1.0

Weekly downloads
8
License
-
Repository
-
Last release
4 years ago

Overlay Image component for Vue

Demo: https://mattiasahlsen.github.io/overlay-image

Install and import

npm install overlay-image or yarn add overlay-image

<script>
import OverlayImage from 'overlay-image'
...

export default {
...
  components: {
    ...
    OverlayImage,
  }
...
}
</script>

Usage

Single box (300px height)
<template>
  ...
  <OverlayImage
    :image="require('../assets/my-image.jpg')"
    text="Overlay text"
    @click="$router.push('/link-to')"
    :height="300"
    containerClass="overlay-container overflow-hidden"
    :overlayClass="['overlay', 'p-1']"
    :textClass="{ 'text-gray-200': greyText }"
  >
  ...
</template>
In a grid (using tailwind.css)
<template>
  ...
  <div class="grid md:grid-cols-2 grid-cols-1">
    <OverlayImage
      v-for="(link, index) in links"
      :key="index"

      :image="require(`../assets/${link.image}`)"
      :text="link.text"
      @click="$router.push(link.to)"
    />
  </div>
  ...
</template>

<script>
export default {
  ...
  data() {
    return {
      ...
      links: [
        {
          image: 'link1.jpg',
          text: 'Link 1',
          to: '/link1',
        },
        {
          image: 'link2.jpg',
          text: 'Link 2',
          to: '/link2',
        },
        ...
      ]
    }
  }
}
</script>

Props and event handlers

NameTypeDefaultDescriptionRequired
imageStringundefinedThe path to the image file.true
textString''The text on the overlay.false
heightString/NumberundefinedThe height of the box. E.g. '100%' or 300 (300px). If you control the height with css, leave this undefined.false
containerClassString/Array/ObjectundefinedClasses that will be applied to the container div. Same syntax as :class in vue.false
overlayClassString/Array/ObjectundefinedClasses that will be applied to the overlay div. Same syntax as :class in vue.false
textClassString/Array/ObjectundefinedClasses that will be applied to the text on the overlay. Same syntax as :class in vue.false
@clickFunctionundefined@click handler for the container.false