Image
Image renders images with preview and placeholder behavior.
@duskmoon-dev/components/image Usage
When to use
- Use it to clarify state, metadata, content hierarchy, or loading without creating a new workflow.
- Pair it with semantic content so visual treatment never becomes the only source of meaning.
Implementation notes
Features
Focuses on status, metadata, empty/loading states, or content grouping without owning application state.
Uses DuskMoon tokens so the component follows the active docs theme.
Image is most often configured through `src`, `alt`, `fallback`, `placeholder`.
Renders image props and classes
Feature Demos
Feature demos are authored for the component page, then supplemented with behavior scenarios from the component test coverage.
Basic usage
Import the component stylesheet and Image from its package subpath, then render it with the core props.
import "@duskmoon-dev/components/styles.css";
import { Image } from "@duskmoon-dev/components/image";
export function Example() {
return (<Image
src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='100' viewBox='0 0 160 100'%3E%3Crect width='160' height='100' rx='12' fill='%23e58f00'/%3E%3Ccircle cx='118' cy='34' r='20' fill='%23fff7d6'/%3E%3Cpath d='M24 72h112' stroke='%23fff7d6' stroke-width='8' stroke-linecap='round'/%3E%3C/svg%3E"
alt="DuskMoon preview"
width={160}
height={100}
placeholder="Loading image"
/>);
} Renders image props and classes
test-backedImage scenario from the component test coverage: renders image props and classes.
import "@duskmoon-dev/components/styles.css";
import { Image } from "@duskmoon-dev/components/image";
export function ImageRendersImagePropsAndDemo() {
return (<Image
src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='100' viewBox='0 0 160 100'%3E%3Crect width='160' height='100' rx='12' fill='%23e58f00'/%3E%3Ccircle cx='118' cy='34' r='20' fill='%23fff7d6'/%3E%3Cpath d='M24 72h112' stroke='%23fff7d6' stroke-width='8' stroke-linecap='round'/%3E%3C/svg%3E"
alt="DuskMoon preview"
width={160}
height={100}
placeholder="Loading image"
/>);
} Shows placeholder while loading and hides it after load
test-backedImage scenario from the component test coverage: shows placeholder while loading and hides it after load.
import "@duskmoon-dev/components/styles.css";
import { Image } from "@duskmoon-dev/components/image";
export function ImageShowsPlaceholderWhileLoadingDemo() {
return (<Image
src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='100' viewBox='0 0 160 100'%3E%3Crect width='160' height='100' rx='12' fill='%23e58f00'/%3E%3Ccircle cx='118' cy='34' r='20' fill='%23fff7d6'/%3E%3Cpath d='M24 72h112' stroke='%23fff7d6' stroke-width='8' stroke-linecap='round'/%3E%3C/svg%3E"
alt="DuskMoon preview"
width={160}
height={100}
placeholder="Loading image"
/>);
} Shows placeholder when src is missing
test-backedImage scenario from the component test coverage: shows placeholder when src is missing.
import "@duskmoon-dev/components/styles.css";
import { Image } from "@duskmoon-dev/components/image";
export function ImageShowsPlaceholderWhenSrcDemo() {
return (<Image
src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='100' viewBox='0 0 160 100'%3E%3Crect width='160' height='100' rx='12' fill='%23e58f00'/%3E%3Ccircle cx='118' cy='34' r='20' fill='%23fff7d6'/%3E%3Cpath d='M24 72h112' stroke='%23fff7d6' stroke-width='8' stroke-linecap='round'/%3E%3C/svg%3E"
alt="DuskMoon preview"
width={160}
height={100}
placeholder="Loading image"
/>);
} Uses fallback source when the original image errors
test-backedImage scenario from the component test coverage: uses fallback source when the original image errors.
import "@duskmoon-dev/components/styles.css";
import { Image } from "@duskmoon-dev/components/image";
export function ImageUsesFallbackSourceWhenDemo() {
return (<Image
src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='100' viewBox='0 0 160 100'%3E%3Crect width='160' height='100' rx='12' fill='%23e58f00'/%3E%3Ccircle cx='118' cy='34' r='20' fill='%23fff7d6'/%3E%3Cpath d='M24 72h112' stroke='%23fff7d6' stroke-width='8' stroke-linecap='round'/%3E%3C/svg%3E"
alt="DuskMoon preview"
width={160}
height={100}
placeholder="Loading image"
/>);
} Calls onError when image fails
test-backedImage scenario from the component test coverage: calls onerror when image fails.
import "@duskmoon-dev/components/styles.css";
import { Image } from "@duskmoon-dev/components/image";
export function ImageCallsOnErrorWhenImageDemo() {
return (<Image
src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='100' viewBox='0 0 160 100'%3E%3Crect width='160' height='100' rx='12' fill='%23e58f00'/%3E%3Ccircle cx='118' cy='34' r='20' fill='%23fff7d6'/%3E%3Cpath d='M24 72h112' stroke='%23fff7d6' stroke-width='8' stroke-linecap='round'/%3E%3C/svg%3E"
alt="DuskMoon preview"
width={160}
height={100}
placeholder="Loading image"
/>);
} Renders PreviewGroup
test-backedImage scenario from the component test coverage: renders previewgroup.
import "@duskmoon-dev/components/styles.css";
import { Image } from "@duskmoon-dev/components/image";
export function ImageRendersPreviewGroupDemo() {
return (<Image
src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='100' viewBox='0 0 160 100'%3E%3Crect width='160' height='100' rx='12' fill='%23e58f00'/%3E%3Ccircle cx='118' cy='34' r='20' fill='%23fff7d6'/%3E%3Cpath d='M24 72h112' stroke='%23fff7d6' stroke-width='8' stroke-linecap='round'/%3E%3C/svg%3E"
alt="DuskMoon preview"
width={160}
height={100}
placeholder="Loading image"
/>);
} Theme aware
Docs previews inherit the DuskMoon data-theme value. Use the header switch to compare light and dark rendering.
<div data-theme="sunshine">
<Image
src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='100' viewBox='0 0 160 100'%3E%3Crect width='160' height='100' rx='12' fill='%23e58f00'/%3E%3Ccircle cx='118' cy='34' r='20' fill='%23fff7d6'/%3E%3Cpath d='M24 72h112' stroke='%23fff7d6' stroke-width='8' stroke-linecap='round'/%3E%3C/svg%3E"
alt="DuskMoon preview"
width={160}
height={100}
placeholder="Loading image"
/>
</div>
<div data-theme="moonlight">
<Image
src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='100' viewBox='0 0 160 100'%3E%3Crect width='160' height='100' rx='12' fill='%23e58f00'/%3E%3Ccircle cx='118' cy='34' r='20' fill='%23fff7d6'/%3E%3Cpath d='M24 72h112' stroke='%23fff7d6' stroke-width='8' stroke-linecap='round'/%3E%3C/svg%3E"
alt="DuskMoon preview"
width={160}
height={100}
placeholder="Loading image"
/>
</div> API
The API reference below lists every parsed exported type or interface for Image. Start with `src`, `alt`, `fallback`, `placeholder` for common usage.
packages/components/src/components/image/Image.types.ts
Scenarios: packages/components/src/components/image/Image.test.tsx | Prop | Type | Required | Description |
|---|---|---|---|
src | string | No | src configures Image. |
alt | string | No | alt configures Image. |
fallback | string | No | fallback configures Image. |
placeholder | ReactNode | boolean | No | placeholder configures Image. |
preview | ImagePreview | No | preview configures Image. |
imgClassName | string | No | imgClassName configures Image. |
wrapperClassName | string | No | wrapperClassName configures Image. |
| Prop | Type | Required | Description |
|---|---|---|---|
visible | boolean | No | visible configures Image. |
mask | ReactNode | No | mask configures Image. |
src | string | No | src configures Image. |
onVisibleChange | (visible: boolean, prevVisible: boolean) => void | No | onVisibleChange configures Image. |
| Prop | Type | Required | Description |
|---|---|---|---|
preview | ImagePreview | No | preview configures Image. |
children | ReactNode | No | children configures Image. |
boolean | ImagePreviewConfig ForwardRefExoticComponent< ImagePreviewGroupProps & RefAttributes<HTMLDivElement> > ForwardRefExoticComponent< ImageProps & RefAttributes<HTMLDivElement> > & { PreviewGroup: ImagePreviewGroupComponent