Image Field

Displays an input that lets users upload an image and see its preview.

Import the component and piece the parts together.

ImageField.Root

accept

readonly ("image/jpeg" | "image/png" | "image/gif" | "image/svg+xml" | "image/webp" | "image/avif" | "image/x-icon" | "image/vnd.microsoft.icon")[] | ("image/jpeg" | "image/png" | "image/gif" | ... 4 more ... | "image/vnd.microsoft.icon")[]

defaultFile

string | File | null

file

string | File | null

maxDimensions

{ width: number; height: number; }

maxSizeKB

number

minDimensions

{ width: number; height: number; }

name

string

placeholder

string

ratio

number

state

disablednormalread-only

Also supports MarginProps: `m`, `mb`, `ml`, `mr`, `mt`, `mx`, `my`

ImageField.Preview

backgroundColor

string

src

string | null

A placeholder is rendered when no preview is displayed. Use the placeholder prop to change the default text.

Make the Root part controlled to access the uploaded file.

Use the onSrcChange prop to access the temporary URL of the preview image.

Use a URL for the defaultFile prop to create an uncontrolled field with an initial value.

You can render a custom preview layout if you pass a function as a child of the Preview part.

Use the backgroundColor prop on the Preview part to set a background color on the preview image.

Use the state prop to create a disabled or read-only Image Field.

Use the available validation props to enforce constraints upon the uploaded images. Use the onError prop to access the errors.

Dashboard

2 variants found

ImageField in Edit Application Logo Dialogdashboardstatic

/:environmentId/applications/:applicationId

<ImageField.Root accept={VALID_LOGO_TYPES} aria-label={label} file={file === undefined ? logoUrl : file} maxSizeKB={MAX_LOGO_SIZE_KB} minDimensions={{ height: MIN_LOGO_DIMENSION, width: MIN_LOGO_DIMENSION }} name={name} placeholder={label} ratio={1} state={disabled ? 'disabled' : 'normal'} onError={onError} onFileChange={onFileChange} > <ImageField.Preview backgroundColor={theme === 'dark' ? 'var(--gray-1)' : '#ffffff'} src={previewSrc} /> </ImageField.Root>
ImageField in Edit Application Logo Dialogdashboardstatic

/:environmentId/applications/:applicationId

<ImageField.Root accept={VALID_LOGO_TYPES} aria-label={label} file={file === undefined ? logoUrl : file} maxSizeKB={MAX_LOGO_SIZE_KB} minDimensions={{ height: MIN_LOGO_DIMENSION, width: MIN_LOGO_DIMENSION }} name={name} placeholder={label} ratio={1} state={disabled ? 'disabled' : 'normal'} onError={onError} onFileChange={onFileChange} > <ImageField.Preview backgroundColor={theme === 'dark' ? 'var(--gray-1)' : '#ffffff'} src={previewSrc} /> </ImageField.Root>

Context

ImageField.Root
PropTypeDefaultRequired
accept
readonly ("image/jpeg" | "image/png" | "image/gif" | "image/svg+xml" | "image/webp" | "image/avif" | "image/x-icon" | "image/vnd.microsoft.icon")[] | ("image/jpeg" | "image/png" | "image/gif" | ... 4 more ... | "image/vnd.microsoft.icon")[]no
defaultFile
string | File | nullno
file
string | File | nullno
maxDimensions
{ width: number; height: number; }no
maxSizeKB
numberno
minDimensions
{ width: number; height: number; }no
name
stringno
placeholder
stringno
ratio
numberno
state
"disabled" | "normal" | "read-only"no

Also supports MarginProps: m, mb, ml, mr, mt, mx, my

ImageField.Preview
PropTypeDefaultRequired
backgroundColor
stringno
src
string | nullno

Usage

Used 18 times across 1 package

Dashboard
18

Where it's used

3 files

/branding/edit

packages/dashboard/src/app/(private)/(chromeless)/branding/edit/edit-branding.tsx12
packages/dashboard/src/components/onboarding-flows/branding-onboarding-step-content.tsx4

/:environmentId/applications/:applicationId

packages/dashboard/src/app/(private)/(sidebar)/[environmentId]/applications/[applicationId]/edit-application-logo-dialog.tsx2