Image Picker

A tappable image field over a native file input: a dashed placeholder, then the preview with change and remove buttons, holding the picked file or the URL of a stored image.

Available in
  • Angular: available
  • Vue: available
  • React: available
  • React Native: available

Usage

PNG or JPG, up to 2 MB.

Import

ts
import {
  SoneImagePickerComponent,
} from "@surface-one/angular/image-picker";

API reference

SoneImagePickerComponentComponent

`<sone-image-picker>` — a tappable image field (the web twin of the React Native `SoneImagePicker`): a dashed placeholder over a native `<input type="file" accept="image/*">` (a click, Enter / Space or a drop pick an image), then the preview with change and remove buttons. `[(value)]` is the picked `File` or the URL of an image that is already stored (also `ngModel` / `formControl`); a `File` is mirrored into the input, so a native form posts it, and its preview's object URL is revoked as soon as it goes. A file `accept` or `maxSize` turns away is announced and emitted as `(rejected)`.

Selector
sone-image-picker
Inputs
NameType Default
valuetwo-way

The picked `File`, or the URL of a stored image — `[(value)]`.

ImagePickerValuenull
accept

The native `accept` list.

string"image/*"
maxSize

The largest file, in bytes.

number | nullnull
disabledbooleanfalse
invalid

A failed check: `aria-invalid` and the destructive border.

booleanfalse
inputId

The input's id (a `soneFieldLabel for` points at it); generated when left out.

string | nullnull
namestring | nullnull
aspectRatio

Width over height: a number (`1`) or a CSS ratio (`"4 / 3"`).

number | string"16 / 9"
alt

The preview's alternative text (empty: decorative).

string""
label

Shown in the empty field; it names the input.

—$localize`:An empty image picker:Add image`
changeLabel

The name of the button that replaces the image.

—$localize`:Replaces a picked image:Change image`
removeLabel

The name of the button that removes the image.

—$localize`:Removes a picked image:Remove image`
errorLabel

Shown when the image fails to load.

—$localize`:A picked image that does not load:Image unavailable`
locale

The locale the size limit is written in.

string"en"
Outputs
NameType
rejected

A file `accept` or `maxSize` turned away.

FileRejection<File>[]