Skip to content

Image ​

A versatile image component with responsive features, lazy loading, aspect ratios, object fit, rounded corners, overlays, zoom, and more. Includes several helper subcomponents for advanced use cases.


Import ​

ts
import { Image } from '@odyssee/components';
// Helpers (optional)
import { ImageZoom, ImageOverlay, BackgroundImage, AvatarImage } from '@odyssee/components';

Basic Usage ​

Code Éditable
Résultat

Object Fit ​

Code Éditable
Résultat

Rounded Corners ​

Code Éditable
Résultat

Aspect Ratios ​

Code Éditable
Résultat

Lazy Loading ​

Code Éditable
Résultat

Image with Zoom on Hover ​

Code Éditable
Résultat

Image with Overlay Content ​

Code Éditable
Résultat

Background Image ​

Code Éditable
Résultat

Avatar Image ​

Code Éditable
Résultat

Props ​

NameTypeDefaultDescription
srcstring—Image source URL (required)
altstring—Alt text for accessibility (required)
widthstring | number—Image width (e.g. '96', 'full', 'auto')
heightstring | number—Image height (e.g. '96', 'full', 'auto')
objectFit'contain' | 'cover' | 'fill' | 'none' | 'scale-down'—Object fit behavior
objectPosition'center' | 'top' | 'right' | 'bottom' | 'left' ...—Object position
rounded'none' | 'sm' | 'md' | 'lg' | 'xl' | '2xl' | '3xl' | 'full''none'Border radius
loading'eager' | 'lazy''lazy'Loading strategy
display'block' | 'inline' | 'inline-block''block'Display type
aspectRatio'square' | 'video' | '4/3' | '16/9' | '21/9' | 'auto'—Aspect ratio
onLoad() => void—Callback on image load
onError() => void—Callback on image error
fallbackSrcstring—Fallback image source on error
classNamestring—Additional CSS classes
idstringautoDOM id (auto-generated if not provided)
stylestring—Inline styles
...restany—Other props are spread to the root <img>

ImageZoom Props ​

All Image props, plus:

NameTypeDefaultDescription
zoomScalenumber105Zoom scale on hover (percent)
durationnumber500Transition duration in ms

ImageOverlay Props ​

All Image props (except children), plus:

NameTypeDefaultDescription
childrenPulse.JSX.Element | ... | string—Overlay content
overlayPosition'top' | 'bottom' | 'center' | 'full''bottom'Overlay position
hoverShadowbooleantrueEnable hover shadow
hrefstring—Link URL (renders as <a> if provided)

BackgroundImage Props ​

NameTypeDefaultDescription
srcstring—Background image URL
size'auto' | 'cover' | 'contain''cover'Background size
position'center' | 'top' | 'right' ...'center'Background position
repeat'repeat' | 'no-repeat' | 'repeat-x' | 'repeat-y''no-repeat'Background repeat
attachment'fixed' | 'local' | 'scroll''scroll'Background attachment
childrenPulse.JSX.Element | ... | string—Content to overlay
minHeightstring'min-h-60'Minimum height
rounded'none' | 'sm' | 'md' | 'lg' ...'none'Border radius
classNamestring—Additional CSS classes
idstring—DOM id
stylestring—Inline styles

AvatarImage Props ​

All Image props (except rounded), plus:

NameTypeDefaultDescription
size'xs' | 'sm' | 'md' | 'lg' | 'xl' | '2xl''md'Avatar size (applies width/height)

Accessibility ​

  • Always provide a meaningful alt attribute for images.
  • Uses semantic <img> or <div> containers.
  • Overlay and background images should ensure sufficient color contrast for text.
  • Avoid using images as the only means of conveying important information.

Best Practices ​

  • Use objectFit and aspectRatio for responsive, consistent layouts.
  • Prefer loading='lazy' for images below the fold.
  • Use ImageOverlay for captions or actions over images.
  • Use AvatarImage for user profile pictures.
  • Test images for accessibility (alt text, contrast, keyboard focus for overlays).
  • Use fallbackSrc for robust error handling.

Subcomponents & Helpers ​

  • ImageZoom: Image with zoom effect on hover.
  • ImageOverlay: Image with overlay content and optional link.
  • BackgroundImage: Div with background image and overlay content.
  • AvatarImage: Circular image for avatars.

Released under the MIT License.