Custom Image

Last edit: Febuary 16th 2025

image

I created this to show a loading skeleton while an image loads instead of abruptly popping in, it also includes a dropdown menu, and the image will still cache normally.

It is built ontop of next/image so it is best used in a Next.js project.

Installation

npx shadcn@latest add "https://c-g.dev/c-image.json"

Props

loadingIndicator

This adds a loading indidcator ontop of the skeleton.

image

hide

This hides the image behind a blur.

image

skeleton

Wether to show a loading skeleton or not.

image

cache

Wether to cache the image or always load it.

image

dropdown

Wether to show a dropdown menu or not.

image

children

The intended purpose of children is to place a title on the image.

image

Component API

NameTypeDefaultDescription
srcstringThe image source
altstringimageThe image alt text
skeletonbooleantrueShow a loading skeleton
pausebooleanfalsePause the skeleton, mainly for demonstration purposes
dropdownbooleanfalseShow a dropdown menu
widthnumber500The image width
hidebooleanfalseHide the image
childrenstringThe image title
heightnumber500The image height
layoutstringresponsiveThe image layout
loadingIndicatorbooleanfalseShow a loading indicator ontop of the skeleton
cachebooleantrueCache the image
classNamestringThe image class
styleobjectThe image style
delaynumberThe delay before the image loads