Thumbnail Component

Accessible-first image gallery component with auto-generated ARIA labels

Introduction

The Thumbnail component is a comprehensive, accessible-first solution for showcasing images with captions, overlays, buttons, and modal integration. Built with UX and accessibility at its core, it automatically generates ARIA labels and ALT tags from your content, eliminating the need for manual accessibility markup.

Accessible by Default

Auto-generates ARIA labels and ALT tags from captions, headers, and link text.

Keyboard Navigation

Full keyboard support with Tab, Enter, Space, and Escape keys.

Customizable Overlays

Choose from 8 overlay colors and 3 opacity levels via data attributes.

Modal Support

Built-in modal integration for viewing enlarged images with captions.

Grid Showcase

Perfect integration with RSL's grid system for responsive layouts.

Dark Mode Ready

Automatic dark mode support that adapts to user preferences.

Quick Start

1. Include Required Files

Required Files • HTML
<!-- CSS -->
<link rel="stylesheet" href="styles/grid.css">
<link rel="stylesheet" href="styles/thumbnail.css">

<!-- Optional: Modal support -->
<link rel="stylesheet" href="styles/modal.css">

<!-- JavaScript -->
<script src="javascript/layout.js"></script>
<script src="javascript/thumbnail.js"></script>

<!-- Optional: Modal support -->
<script src="javascript/modal.js"></script>

2. Basic Usage

Minimal Setup • HTML
<!-- JavaScript automatically generates ARIA labels and ALT tags -->
<div data-thumbnail-image="https://images.unsplash.com/photo-1506905925346-21bda4d32df4?w=600&h=400&fit=crop"
     data-thumbnail-header="Modern Architecture"
     data-thumbnail-description="Contemporary design with clean lines">
</div>
Note: The thumbnail component automatically builds the HTML structure, generates accessibility attributes, and handles all interactions. You only need to provide the data attributes!

Data Attributes Reference

Image Configuration

Attribute Type Default Description
data-thumbnail-image String Required Path to the thumbnail image
data-thumbnail-image-alt String Auto-generated Manual override for ALT text (not recommended - let JS handle it)
data-thumbnail-aspect String 3:2 Image aspect ratio. Options: 1:1, 3:2, 4:3, 16:9, 21:9
data-thumbnail-lazy Boolean false Enable lazy loading for image

Content/Caption

Attribute Type Default Description
data-thumbnail-header String '' Main heading/title for the thumbnail
data-thumbnail-description String '' Description text displayed below header

Link Configuration

Attribute Type Default Description
data-thumbnail-link String '' URL for the thumbnail link
data-thumbnail-link-text String Learn More Text for the link button
data-thumbnail-link-target String _self Link target. Options: _self, _blank

Overlay Configuration

Attribute Type Default Description
data-overlay-color String dark Overlay color. Preset options: primary, secondary, success, danger, info, warning, dark, light. Also accepts custom colors: hex (#c9a96e), rgba (rgba(201, 169, 110, 0.9)), or any valid CSS color.
data-overlay-opacity String medium Overlay opacity on hover. Options: light (50%), medium (75%), heavy (95%)
data-thumbnail-show-buttons Boolean true Show overlay buttons on hover
data-button-color String #333 Custom button text/icon color. Accepts any CSS color value.
data-button-bg-color String rgba(255,255,255,0.95) Custom button background color. Accepts any CSS color value including transparent.
data-button-hover-color String inherits from button-color Custom button text/icon color on hover.
data-button-hover-bg-color String #fff Custom button background color on hover.
data-button-icon-color String inherits from button-color Custom icon color. Useful when you want the icon to be a different color than the text.
data-button-icon-hover-color String inherits from icon-color Custom icon color on hover.

Button Configuration

Attribute Type Default Description
data-thumbnail-button1-text String '' Text for first overlay button
data-thumbnail-button1-action String '' Global function name to call when button clicked
data-thumbnail-button1-link String '' Direct URL (makes button a link instead of action)
data-thumbnail-button1-icon String '' FontAwesome icon class (e.g., fas fa-eye)
data-thumbnail-button2-text String '' Text for second overlay button
data-thumbnail-button2-action String '' Global function name to call when button clicked
data-thumbnail-button2-link String '' Direct URL (makes button a link instead of action)
data-thumbnail-button2-icon String '' FontAwesome icon class

Modal Configuration

Attribute Type Default Description
data-thumbnail-modal Boolean false Enable modal for viewing larger image
data-thumbnail-modal-header String Uses data-thumbnail-header Modal title (defaults to thumbnail header)
data-thumbnail-modal-description String Uses data-thumbnail-description Modal description (defaults to thumbnail description)

Behavior

Attribute Type Default Description
data-thumbnail-disabled Boolean false Disable thumbnail interactions

JavaScript API

Auto-Initialization

Thumbnails are automatically initialized on page load:

Auto-Init • JavaScript
// Automatically runs on DOMContentLoaded
document.addEventListener('DOMContentLoaded', function() {
    RSL.Thumbnail.init();
});

Manual Initialization

Manual Init • JavaScript
// Initialize all thumbnails
RSL.Thumbnail.init();

// Initialize a specific thumbnail
var element = document.querySelector('[data-thumbnail-image]');
var instance = RSL.Thumbnail.create(element);

Public Methods

Method Parameters Description
init() None Initialize all thumbnails on the page
create(element) HTMLElement Create a single thumbnail instance
openModal(element) HTMLElement Open modal for a specific thumbnail
closeModal(modalId) String Close a specific modal by ID
destroy(element) HTMLElement Remove thumbnail instance and cleanup
getInstance(element) HTMLElement Get thumbnail instance for an element

Custom Button Actions

Define global functions that will be called when buttons are clicked:

Custom Actions • JavaScript
// Define custom action function
window.viewDetails = function(element, instance) {
    console.log('View details for:', instance.config.header);
    // Your custom logic here
};

// HTML: data-thumbnail-button1-action="viewDetails"

Accessibility Features

Auto-Generated ALT Tags

The component intelligently generates ALT text for images following this priority:

  1. Manual override via data-thumbnail-image-alt
  2. Header + Description combined
  3. Header only
  4. Description only
  5. Link destination announced
  6. Empty (decorative image)

Auto-Generated ARIA Labels

Comprehensive ARIA labels are generated from your content, including:

Keyboard Navigation

Key Action
Tab Navigate to thumbnail and buttons
Enter or Space Activate thumbnail (open modal or navigate to link)
Escape Close modal (if RSL Modal component is included)

Screen Reader Support

Additional Accessibility

JSON Layout API Integration

The Thumbnail component works seamlessly with the RSL JSON Layout API. Components are automatically initialized when rendered through JSON configuration.

✅ Automatic Initialization: When you render a layout containing thumbnail elements with data-thumbnail-image attributes using the JSON API, thumbnails are automatically initialized without manual setup.

Basic JSON API Example

JSON API Usage • JavaScript
const config = {
    version: 1,
    layoutId: "thumbnail-gallery",
    breakpoints: { xs: 1, sm: 2, md: 3 },
    items: [
        {
            id: "thumb-1",
            content: {
                type: "html",
                value: \`
                    <div data-thumbnail-image="https://images.unsplash.com/photo-1506905925346-21bda4d32df4?w=600&h=400&fit=crop"
                         data-thumbnail-header="Mountain Vista"
                         data-thumbnail-description="Breathtaking mountain scenery"
                         data-thumbnail-button1-text="View"
                         data-thumbnail-button1-link="/view/1">
                    </div>
                \`
            }
        },
        {
            id: "thumb-2",
            content: {
                type: "html",
                value: \`
                    <div data-thumbnail-image="https://images.unsplash.com/photo-1469474968028-56623f02e42e?w=600&h=400&fit=crop"
                         data-thumbnail-header="Ocean Waves"
                         data-thumbnail-modal="true">
                    </div>
                \`
            }
        }
    ]
};

// Thumbnails are auto-initialized!
RSL.JSONLayout.renderLayout('#container', config);

Public API Methods

Method Description
RSL.Thumbnail.init() Initialize all thumbnails on the page
RSL.Thumbnail.create(element) Create thumbnail instance for specific element
RSL.Thumbnail.openModal(element) Open modal for thumbnail element
RSL.Thumbnail.closeModal(modalId) Close specific modal by ID
RSL.Thumbnail.destroy(element) Remove thumbnail instance

See More: Browse all JSON API component examples →

Learn More

For complete usage examples and demonstrations, visit: