Image

import Image from 'frui/fields/Image';
Copy

Props

Image accepts all props of a standard HTML Input element. See Moz for standard input attributes.

NameTypeRequiredNotes
classNamestringNoStandard HTML class names
defaultValuestringNoAlias to value
errorstring|booleanNoAny error message
namestringNoUsed for react server components.
onChangeFunctionNoEvent handler when value has changed
onUpdateFunctionNoUpdate event handler
onUploadFunctionYesCalled when image is loaded
passRefLegacyRefNoPasses ref to html input
styleCSS ObjectNoStandard CSS object
uploadingstringNoPhrased used when uploading images
valuestringNoDefault value

Basics

<Image className="bg-white w-full" value="https://images.wsj.net/im-580612/8SR" />
Copy

Events

Images have an extra prop called onUpload. This is where you should add your logic for handling the image upload. Using this in combination with onUpdate will allow you to pass values from upload to form processing.

<Image
  className="bg-white w-full" 
  onUpload={(image, next) => {
    //just a mock call
    setTimeout(() => {
      next('https://images.wsj.net/im-580612/8SR')
    }, 5000)
  }} 
  onUpdate={value => alert(value)} 
/>
Copy

On Change

The onChange event is triggered when the value has changed. The following arguments are passed to the event handler:

NameTypeSample
eventEvent Objectsee: Change Event

On Upload

The onUpload event is triggered when a image has been selected. The following arguments are passed to the event handler:

NameTypeSample
imageFilesee: File Object
next(url: string) => void
next('//cdn.ex.com/img.jpg')

On Update

The onUpdate event is triggered when the value has been updated. The following arguments are passed to the event handler:

NameTypeSample
valuestring`foobar`

Errors

You can pass the error prop to highlight the input field red.

<Image error={string|true} className="bg-white w-full" />
Copy

Custom Styles

You can add your own custom class to images or use any of the respective frui-field-image, frui-field-image-control, frui-field-image-reset, frui-field-image-file, frui-field-image-link, and frui-field-image-image CSS classes.