Home

Awesome

Vue It Bigger!

npm Build Status codecov Depfu

A simple image / (YouTube) video lightbox component for Vue.js 2. Based on vue-image-lightbox.

Vue It Bigger Screenshot

Click on the screenshot above for a demo.

Features

Improvements over vue-image-lightbox

Installation

You know the drill:

npm install vue-it-bigger
# or
yarn add vue-it-bigger

Usage

You can view App.vue or the demo for an usage example.

In the <script> section of your component import it:

import LightBox from 'vue-it-bigger'
import('vue-it-bigger/dist/vue-it-bigger.min.css') // when using webpack

Add it to the list of used components:

export default {
  components: {
    LightBox,
  },
}

And use it in the <template> section:

<LightBox :media="media"></LightBox>

The media prop has the following structure:

[
  { // For an image
    type: 'image', // Can be omitted for image
    thumb: 'http://example.com/thumb.jpg',
    src: 'http://example.com/image.jpg',
    caption: 'Caption to display. HTML <b>enabled</b>', // Optional
    srcset: '...' // Optional for displaying responsive images
  },
  { // For a YouTube video
    type: 'youtube',
    thumb: 'https://img.youtube.com/vi/WsptdUFthWI/hqdefault.jpg',
    id: 'WsptdUFthWI',
    caption: 'HTML <b>enabled</b> caption to display' // Optional
  },
  { // For a video that can be played in the <video> tag
    type: 'video',
    thumb: 'https://s3-us-west-1.amazonaws.com/powr/defaults/image-slider2.jpg',
    sources: [
      {
        src: 'https://www.w3schools.com/html/mov_bbb.mp4',
        type: 'video/mp4'
      }
    ],
    caption: '<h4>Monsters Inc.</h4>',
    width: 800, // Required
    height: 600, // Required
    autoplay: true // Optional: Autoplay video when the lightbox opens
  }
]

Using it with NuxtJs

Create a file named lightbox.js under the plugins directory with following contents:

import Vue from 'vue'

import LightBox from 'vue-it-bigger'
import('vue-it-bigger/dist/vue-it-bigger.min.css')

const plugin = {
  install() {
    Vue.component('LightBox', LightBox)
  },
}

Vue.use(plugin)

Add the plugin in nuxt.config.js:

plugins: [
  {
    src: '~/plugins/lightbox.js',
    ssr: false
  }
]

Use it in any of your components:

<no-ssr placeholder="Loading...">
  <!-- this component will only be rendered on client-side -->
  <LightBox
    :media="lightBoxMedia"
  ></LightBox>
</no-ssr>

Options

Properties

<table> <thead> <tr> <th>name</th> <th>type</th> <th>default</th> <th>description</th> </tr> </thead> <tbody> <tr> <td>media</td> <td>Array</td> <td>required</td> <td>Media array to display</td> </tr> <tr> <td>showLightBox</td> <td>Boolean</td> <td>true</td> <td>Whether to show lightbox or not at the beginning</td> </tr> <tr> <td>startAt</td> <td>Number</td> <td>0</td> <td>Index of the image that you want to start at</td> </tr> <tr> <td>nThumbs</td> <td>Number</td> <td>7</td> <td>Number of thumbnail images</td> </tr> <tr> <td>showThumbs</td> <td>Boolean</td> <td>true</td> <td>Whether to show thumbnails or not</td> </tr> <tr> <td>autoPlay</td> <td>Boolean</td> <td>false</td> <td>Move to next image automatically</td> </tr> <tr> <td>autoPlayTime</td> <td>Number</td> <td>3000 (ms)</td> <td>Time to stop at an image before move on to next image</td> </tr> <tr> <td>interfaceHideTime</td> <td>Number</td> <td>3000 (ms)</td> <td>Time after which the interface is hidden</td> </tr> <tr> <td>showCaption</td> <td>Boolean</td> <td>false</td> <td>Whether to show caption or not</td> </tr> <tr> <td>disableScroll</td> <td>Boolean</td> <td>true</td> <td>set to `true` to avoid scrolling views behind lightbox</td> </tr> <tr> <td>lengthToLoadMore</td> <td>Number</td> <td>0</td> <td>Minimum length unto end to emit load more event</td> </tr> <tr> <td>closable</td> <td>Boolean</td> <td>true</td> <td>Display the close button at the right top corner or not. ESC clicking-close will also be disabled if closable is set to false.</td> </tr> <tr> <td>closeText</td> <td>String</td> <td>Close (Esc)</td> <td>Text for the close button</td> </tr> <tr> <td>previousText</td> <td>String</td> <td>Previous</td> <td>Text for the previous image button</td> </tr> <tr> <td>nextText</td> <td>String</td> <td>Next</td> <td>Text for the next image button</td> </tr> </tbody> </table>

Methods

<table> <thead> <tr> <th>name</th> <th>arguments</th> <th>description</th> </tr> </thead> <tbody> <tr> <td>nextImage</td> <td>()</td> <td>Move to next image</td> </tr> <tr> <td>previousImage</td> <td>()</td> <td>Move to previous image</td> </tr> <tr> <td>closeLightBox</td> <td>()</td> <td>Close lightbox</td> </tr> <tr> <td>showImage</td> <td>(index)</td> <td>Show the image at index</td> </tr> </tbody> </table>

Slots

close

The content of the close button.

footer

The content of the footer under the image.

Slot props
<table> <thead> <tr> <th>name</th> <th>type</th> <th>description</th> </tr> </thead> <tbody> <tr> <td>current</td> <td>integer</td> <td>Number of the current image displayed</td> </tr> <tr> <td>total</td> <td>integer</td> <td>Number of images</td> </tr> </tbody> </table>

previous

The previous button on the main image.

next

The next button on the main image.

customCaption

The caption of the current image.

Slot props
<table> <thead> <tr> <th>name</th> <th>type</th> <th>description</th> </tr> </thead> <tbody> <tr> <td>currentMedia</td> <td>Object</td> <td>The currently displayed object from the media array</td> </tr> </tbody> </table>

Usage example:

<LightBox
  ref="customCaptionLightbox"
  :media="media"
  :show-caption="true"
>
  <template v-slot:customCaption="slotProps">
    {{ slotProps.currentMedia.caption }}<br>
    There could be some description here.
  </template>
</LightBox>

videoIcon

The Icon used for videos

Events

Development (NPM / Yarn)

Clone the repository, cd into it and run:

npm run dev
yarn dev

After you add or modify something make sure the tests still pass:

npm run test
yarn test

Release

  1. Make sure everything works locally by running yarn dev
  2. Bump the version in package.json
  3. Draft a new release on the releases page
    • Create a tag with the prefix v and the version, eg: v0.3.0
    • Prefix the release title with the tag, eg: v0.3.0 - An awesome release
  4. Publish the release

Credits

License

This project is licensed under the the Apache License, Version 2.0.