1.2.0 ⢠Published 7 months ago
@nextrap/image v1.2.0
Nextrap Element Image
A versatile and powerful image component for modern web applications that provides advanced image handling capabilities including slideshows, positioning, and fullscreen viewing.
Features
- š¼ļø Flexible Image Positioning: Control image position (top, bottom, left, right, center) using
object-position - š Responsive Aspect Ratio: Maintain aspect ratios across different breakpoints
- š Slideshow Capabilities:
- Smooth blend effects between slides
- Left/right navigation
- Caption support using alt text or data-caption
- š Fullsize View: Display images in a modal with centered positioning and blurred background
- āļø Image Cropping: Virtual crop functionality with percentage-based dimensions
- š± Touch Support: Swipe detection for mobile-friendly navigation
Installation
# Installation instructions will depend on your package manager
npm i @nextrap/imageUsage Examples
Basic Image with Fullsize Capability
<nxa-image style="width: 600px; height: 400px;" data-features="fullsize">
<img src="path/to/your/image.jpg" alt="Sample image">
</nxa-image>Image with Rounded Borders
<nxa-image style="width: 600px; height: 400px;" data-features="round-borders">
<img src="path/to/your/image.jpg" alt="Sample image with rounded borders">
</nxa-image>Image Cropping
Percentage-based Cropping
<nxa-image style="width: 300px; height: 300px">
<img src="path/to/your/image.jpg"
data-crop="top: 10%; bottom: 10%; right: 10%; left: 10%"
alt="Cropped image">
</nxa-image>Pixel-based Cropping
<nxa-image style="width: 300px; height: 300px">
<img src="path/to/your/image.jpg"
data-crop="top: 50px; bottom: 50px; right: 50px; left: 50px"
alt="Cropped image">
</nxa-image>Slideshow Examples
Basic Slideshow
<nxa-image style="width: 100%; height: 400px" data-features="slideshow">
<img src="path/to/image1.jpg" alt="Slide 1">
<img src="path/to/image2.jpg" alt="Slide 2">
<img src="path/to/image3.jpg" alt="Slide 3">
</nxa-image>Slideshow with Navigation and Indicators
<nxa-image style="width: 100%; height: 400px"
data-features="slideshow arrows indicators">
<img src="path/to/image1.jpg" alt="Slide 1">
<img src="path/to/image2.jpg" alt="Slide 2">
<img src="path/to/image3.jpg" alt="Slide 3">
</nxa-image>Slideshow with Captions
<nxa-image style="width: 100%; height: 400px"
data-features="slideshow arrows indicators">
<img src="path/to/image1.jpg"
data-caption="Beautiful mountain landscape"
alt="Mountain landscape">
<img src="path/to/image2.jpg"
data-caption="Serene ocean view"
alt="Ocean view">
<img src="path/to/image3.jpg"
data-caption="Urban cityscape"
alt="Cityscape">
</nxa-image>Custom Slideshow Settings
<!-- Custom interval (2 seconds) -->
<nxa-image style="width: 100%; height: 400px"
data-features="slideshow arrows indicators"
interval="2000">
<img src="path/to/image1.jpg" alt="Slide 1">
<img src="path/to/image2.jpg" alt="Slide 2">
<img src="path/to/image3.jpg" alt="Slide 3">
</nxa-image>
<!-- Continuous slideshow (no pause on hover) -->
<nxa-image style="width: 100%; height: 400px"
data-features="slideshow arrows indicators dont-pause-on-hover">
<img src="path/to/image1.jpg" alt="Slide 1">
<img src="path/to/image2.jpg" alt="Slide 2">
<img src="path/to/image3.jpg" alt="Slide 3">
</nxa-image>Complete Example with All Features
<nxa-image style="width: 100%; height: 500px"
data-features="slideshow blend fullsize arrows indicators round-borders"
interval="4000">
<img src="path/to/image1.jpg"
style="object-position: center center;"
data-caption="Beautiful mountain landscape"
alt="Mountain landscape">
<img src="path/to/image2.jpg"
style="object-position: center center;"
data-caption="Serene ocean view"
alt="Ocean view">
<img src="path/to/image3.jpg"
style="object-position: center center;"
alt="Cityscape">
</nxa-image>Example with Event Callbacks
<nxa-image
style="width: 100%; height: 400px"
data-features="slideshow arrows indicators fullsize"
id="myImageComponent">
<img src="path/to/image1.jpg" alt="Slide 1">
<img src="path/to/image2.jpg" alt="Slide 2">
<img src="path/to/image3.jpg" alt="Slide 3">
</nxa-image>
<script>
// Get the component instance
const imageComponent = document.getElementById('myImageComponent');
// Add event listeners
imageComponent.onSlideChange = (index, image) => {
console.log(`Slide changed to index ${index}`);
};
imageComponent.onFullscreenEnter = (image) => {
console.log('Entered fullscreen mode');
};
imageComponent.onFullscreenExit = (image) => {
console.log('Exited fullscreen mode');
};
imageComponent.onSlideshowPause = (image) => {
console.log('Slideshow paused');
};
imageComponent.onSlideshowResume = (image) => {
console.log('Slideshow resumed');
};
imageComponent.onImageClick = (image, event) => {
console.log('Image clicked', event);
};
</script>API Reference
NxaImage Component
The main component that handles all image functionality.
Attributes
style: Standard CSS styling (width, height required)data-features: Space-separated list of features to enable:slideshow: Enables slideshow functionalityblend: Adds blend effect between slidesfullsize: Enables fullscreen modal viewarrows: Shows navigation arrowsindicators: Shows slide indicatorsround-borders: Applies rounded cornersdont-pause-on-hover: Prevents slideshow from pausing on hover
interval: Custom interval for slideshow transitions (in milliseconds)
Event Callbacks
onSlideChange: Called when the active slide changes. Receives the index of the new active slide and the image element.onFullscreenEnter: Called when entering fullscreen mode. Receives the image element that was clicked.onFullscreenExit: Called when exiting fullscreen mode. Receives the image element that was in fullscreen.onSlideshowPause: Called when the slideshow is paused. Receives the current active image element.onSlideshowResume: Called when the slideshow is resumed. Receives the current active image element.onImageClick: Called when an image is clicked. Receives the clicked image element and the click event.
Image Element Attributes
style.object-position: Controls image positioningdata-caption: Adds a caption to the imagedata-crop: Specifies crop dimensions in percentages or pixelsalt: Alternative text for accessibility
Browser Support
The component is designed to work in all modern browsers that support Web Components.
Development
The project uses modern web development tools and practices:
- Vite for fast development and building
- TypeScript for type safety
- Storybook for component development and documentation
- Web Components for framework-agnostic usage
Project Structure
src/
āāā index.ts # Main entry point
āāā stories/ # Storybook stories and documentation
āāā image/
āāā nxa-image.ts # Core component implementation
āāā style.ts # Styling definitions
āāā nxa-image.utils.ts # Utility functions
āāā nxa-image.types.ts # TypeScript type definitions
āāā nxa-image.test.js # Component tests
āāā pixel-matrix.png # Test image asset
āāā README.md # Component-specific documentationDevelopment Setup
- Clone the repository
- Install dependencies:
npm install - Start the development server:
npm run dev - View Storybook documentation:
apt install xdg-open npm run storybook - Run tests:
npm test
License
This project is licensed under the terms specified in the LICENSE.txt file.
Release Notes
For detailed information about changes in each version, please refer to the RELEASE_NOTES.md file.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.