Socket
Socket
Sign inDemoInstall

vue-tinybox

Package Overview
Dependencies
21
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    vue-tinybox

A slick, yet tiny lightbox gallery for Vue.js


Version published
Weekly downloads
722
decreased by-3.22%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

vue-tinybox

Milky Way emoji

A slick, yet tiny lightbox gallery for Vue 3.

  • Slick. No excessive design. Pictures, thumbnails, controls.
  • Tiny. Dependency-free. 3 KB minified and gzipped.
  • Adaptive. Works on computers. Works on tablets. Works on phones.

Demo

Observe the live demo here: os.karamoff.dev/vue-tinybox

Basic usage

<Tinybox v-model:index="index" :images="images" loop no-thumbs />

Install

  • In modern browsers, you can import Tinybox from a CDN URL along with the Vue import:

    <script type="module">
    	import { createApp } from "https://cdn.jsdelivr.net/npm/vue@3/dist/vue.esm-browser.js";
    	import Tinybox from "https://cdn.jsdelivr.net/npm/vue-tinybox@2/dist/vue-tinybox.js";
    
    	// ...
    </script>
    

    You'll also need the CSS file:

    <link
    	href="https://cdn.jsdelivr.net/npm/vue-tinybox@2/dist/vue-tinybox.css"
    	rel="stylesheet"
    />
    
  • In Node, install the vue-tinybox package:

     pnpm add vue-tinybox
    
    npm install vue-tinybox
    
    yarn add vue-tinybox
    

    ...and then import Tinybox like you usually would:

    import Tinybox from "vue-tinybox";
    import "vue-tinybox/css";
    // or const Tinybox = require("vue-tinybox");
    

After you have imported Tinybox, you can bind it to your application instance like you usually do:

const app = createApp({
	components: {
		Tinybox,
	},
});

// or app.component("Tinybox", Tinybox);

// or app.use(Tinybox);
For older browsers

If you need to use the component in a browser without ESM support, include the IIFE version:

<link
	href="https://cdn.jsdelivr.net/npm/vue-tinybox@2/dist/vue-tinybox.css"
	rel="stylesheet"
/>
<script src="https://cdn.jsdelivr.net/npm/vue-tinybox@2/dist/vue-tinybox.iife.js"></script>

This exposes the Tinybox component in the global scope. Include it in your app:

<script>
	app = createApp({
		// ...
	});

	app.component("Tinybox", Tinybox);
</script>

API

Image object

An Image object is an object with following fields:

Field nameTypeDescription
srcStringImage URL
thumbnailString(optional) Thumbnail URL. If omitted, the image URL will be used
captionString(optional) Caption text to be overlayed on the image
altString(optional) Alt text. If omitted, the caption will be used

Props

Prop nameTypeDefaultDescription
imagesArray[]List of either image URLs or Image objects
loopBooleanfalseIndicates whether the images should loop
no-thumbsBooleanfalseWhen enabled, the thumbnails are hidden

v-model

You can use v-model on a Number variable, which will hold the index of the image currently open. If no image is open (i.e. Tinybox is closed), the value becomes null.

Instead of v-model you can use the index prop and change event:

<Tinybox v-model:index="index" :images="images" />

<!-- is equivalent to -->

<Tinybox :images="images" :index="index" @update:index="(i) => {index = i}" />

Events

Event namePayloadDescription
changeindex of the image changed toIs emitted on any image change (thumbnail navigation, prev/next, close)
prev/nextindex of the image changed toIs emitted specifically when the user clicks "Prev"/"Next" or presses Left/Right arrow key
closeindex of the image Tinybox was closed atIs emitted specifically when the user clicks "Close" or presses the Esc key

Events can come in handy for business logic cases:

<Tinybox
	:images="images"
	v-model:index="index"
	@update:index="onChange"
	@prev="onPrevious"
	@next="onNext"
	@close="onClose"
/>
export default {
	// ...
	methods: {
		onChange(index) {
			console.log("User navigated to the photo: ", index);
		},
		onPrevious(index) {
			console.log("User clicked 'previous' to switch to: ", index);
		},
		onNext(index) {
			console.log("User clicked 'previous' to switch to: ", index);
		},
		onClose(index) {
			console.log("User closed TinyBox on this photo: ", index);
		},
	},
};

Browser support

ChromeFirefoxSafariEdge
51+28+10+16+

Keywords

FAQs

Last updated on 04 Feb 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc