Lightbox Item
<wa-lightbox-item>
Lightbox items represent the individual images and videos shown in a lightbox. Each one wraps the thumbnail that opens it.
This component must be used as a child of <wa-lightbox>. Please see the Lightbox docs to see examples of this component in action.
API
Importing
If you're using the autoloader or a hosted project, components load on demand — no manual import needed. To cherry-pick a component manually, use one of the following snippets.
Import this component directly from the CDN:
import 'https://ka-f.webawesome.com/[email protected]/components/lightbox-item/lightbox-item.js';
After installing Web Awesome via npm, import this component:
import '@awesome.me/webawesome/dist/components/lightbox-item/lightbox-item.js';
If you're self-hosting Web Awesome, import this component from your server:
import './webawesome/dist/components/lightbox-item/lightbox-item.js';
To import this component for React 18 or below, use the following code:
import WaLightboxItem from '@awesome.me/webawesome/dist/react/lightbox-item/index.js';
Slots
Learn more about using slots.
| Name | Description |
|---|---|
| (default) | The item's thumbnail, usually an <img>. Clicking it opens the lightbox at this item. Leave it empty to add an item that only appears in the lightbox. To show your own content in the lightbox, such as a video player or an embed, add it in a <template>. |
play-icon
|
Optional play icon to use instead of the default. Works best with <wa-icon>. |
Attributes & Properties
Learn more about attributes and properties.
| Name | Description | Reflects |
|---|---|---|
altalt |
Alternative text for the full-size media. Defaults to the slotted thumbnail's
alt.
Type
string
Default
''
|
|
captioncaption |
A plain text caption to show with the item in the lightbox.
Type
string
Default
''
|
|
heightheight |
The intrinsic height of the full-size media in pixels.
Type
number
|
|
sizessizes |
The
sizes to use with srcset. When omitted, the lightbox uses the viewport width, and the zoomed width once
the image is zoomed in.
Type
string
Default
''
|
|
srcsrc |
The URL of the full-size image or video. The thumbnail links to it, so the item still works without JavaScript
and when opened in a new tab.
Type
string
Default
''
|
|
srcsetsrcset |
A set of image sources for the full-size image, in the same format as the
<img> srcset attribute.
Type
string
Default
''
|
|
thumbnailthumbnail |
The URL of a thumbnail to use in the lightbox's thumbnail strip and as a placeholder while the full-size media
loads. Only needed when no
<img> is slotted in.
Type
string
Default
''
|
|
typetype |
The kind of media the item shows in the lightbox. Videos show a play button over their thumbnail.
Type
'image' | 'video'
Default
'image'
|
|
widthwidth |
The intrinsic width of the full-size media in pixels. Set this with
height so the lightbox can size the slide
before the media loads.
Type
number
|
Methods
Learn more about methods.
| Name | Description | Arguments |
|---|---|---|
focus() |
Sets focus on the item's trigger. |
options: FocusOptions
|
Custom States
Learn more about custom states.
| Name | Description | CSS selector |
|---|---|---|
active |
Applied when this is the current item in an open lightbox. |
:state(active)
|
empty |
Applied when nothing is slotted in. Empty items aren't displayed on the page. |
:state(empty)
|
morphing |
Applied while the lightbox animates between this item's thumbnail and its full-size media. |
:state(morphing)
|
CSS Parts
Learn more about CSS parts.
| Name | Description | CSS selector |
|---|---|---|
play-button |
The play button shown over a video's thumbnail. |
::part(play-button)
|
trigger |
The link that wraps the thumbnail and opens the lightbox. |
::part(trigger)
|
Dependencies
This component automatically imports the following elements. Sub-dependencies, if any exist, will also be included in this list.