1.0.1 • Published 3 years ago

@miraidesigns/lightbox v1.0.1

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

Lightbox

Lightbox creates a modal carousel from a set of media elements such as images or videos.


HTML

<a href="images/1.jpg" data-lightbox="id" data-lightbox-alt="Image alt description">
    <img src="images/1_thumbnail.jpg" alt="Image thumbnail">
</a>

Sass

// Include default styles without configuration
@forward '@miraidesigns/lightbox/styles';
// Configure appearance
@use '@miraidesigns/lightbox' with (
    $variable: value
);

@include lightbox.styles();

TypeScript

import { MDFLightbox } from '@miraidesigns/lightbox';

new MDFLightbox(document.querySelectorAll('[data-lightbox="id"]'), {
    icons: {
        type: 'svg',
        control: 'icons.svg#arrow-keyboard',
        close: 'icons.svg#clear'
    }
});

Implementation

Attributes

NameElementDescription
data-lightbox<a>Lightbox id. Use this attribute to group elements together
data-lightbox-title<a>Set lightbox item title
data-lightbox-description<a>Set lightbox item description
data-lightbox-alt<a>Set alt attribute text for images
data-lightbox-type<a>Content type. Allowed values are video or embed

Classes

NameTypeDescription
mdf-lightbox-containerParentContains the lightbox and backdrop
mdf-lightbox-container--activeModifier1. Prepares the lightbox to be visible
mdf-lightbox-container--fade-inModifier2. Fades-in the lightbox and allows for interaction
mdf-lightboxParent / ChildContains the header, items and controls. Child to .mdf-lightbox-container
mdf-lightbox__itemsParent / ChildContains the lightbox items. Child to .mdf-lightbox
mdf-lightbox__itemParent / ChildLightbox item. Contains the item info and media element. Child to .mdf-lightbox__items
mdf-lightbox__item--scaleModifierPlays animation on item when opening the lightbox
mdf-lightbox__infoParent / ChildContains the title and description. Child to .mdf-lightbox__item
mdf-lightbox__titleChildItem title. Child to .mdf-lightbox__info
mdf-lightbox__descriptionChildItem description. Child to .mdf-lightbox__info
mdf-lightbox__media-wrapperParent / ChildMedia wrapper element. Allows for scaling of videos and iframes. Child to .mdf-lightbox__item
mdf-lightbox__media-wrapper--borderedModifierAdd border to media element, used for iframes
mdf-lightbox__mediaChildMedia element. Child to .mdf-lightbox__media-wrapper
mdf-lightbox__controlChildLightbox control button element. Child to .mdf-lightbox
mdf-lightbox__control--closeModifierClose button element
mdf-lightbox__control--prevModifierPrevious button element
mdf-lightbox__control--nextModifierNext button element
mdf-lightbox-backdropChildLightbox backdrop. Child to .mdf-lightbox-container

Events

NameDataDescription
MDFLightbox:openednullFires when the lightbox opens
MDFLightbox:changed{index: number, item: HTMLElement}Fires whenever the active lightbox item changes. Includes the item itself and its index
MDFLightbox:closednullFires when the lightbox closes

Properties

NameTypeDescription
.activeItemHTMLElementReturns the current lightbox item on display
.containerHTMLElementReturns the lightbox container element
.indexnumberReturns the index of the current lightbox item
.itemsHTMLCollectionReturns a HTMLCollection holding all lightbox items
.itemsContainerHTMLElementReturns the lightbox items container element
.lightboxHTMLElementReturns the lightbox element
.linksHTMLLinkElement[]Returns an Array holding all lightbox links
.refresh()(): voidRefresh the lightbox, adding new items without re-creating the entire lightbox element

Options

NameTypeDefaultDescription
onOpen() => voidnullFunction will run when the lightbox is opened
onChange() => voidnullFunction will run when the lightbox item changes
onClose() => voidnullFunction will run when the lightbox is closed
titlePosstringbottomSet title position. Allowed values are top or bottom
titleAlignstringcenterSet title text alignment. Allowed values are left center or right
iframeAddBorderbooleanfalseAdd border to embedded iframes
sandboxingbooleanfalseEnable sandboxing for iframes
sandboxingRulesstringnullSee: HTML iframe sandbox Attribute
enableSwipebooleantrueAllow for navigation by swiping left and right on touch devices
hideOnClickbooleantrueLightbox will be hidden when clicked outside of it's content