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.
Angular: available Vue: available React: available React Native: available
Usage
PNG or JPG, up to 2 MB.
<div class="demo-stack" style="max-width: 20rem">
<div soneField>
<label soneFieldLabel for="demo-cover">Cover image</label>
<sone-image-picker
inputId="demo-cover"
label="Add a cover"
[maxSize]="2000000"
[(value)]="cover"
/>
<p soneFieldDescription>PNG or JPG, up to 2 MB.</p>
</div>
</div>Import
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)`.
| Name | Type | Default |
|---|---|---|
valuetwo-wayThe picked `File`, or the URL of a stored image — `[(value)]`. | ImagePickerValue | null |
acceptThe native `accept` list. | string | "image/*" |
maxSizeThe largest file, in bytes. | number | null | null |
disabled | boolean | false |
invalidA failed check: `aria-invalid` and the destructive border. | boolean | false |
inputIdThe input's id (a `soneFieldLabel for` points at it); generated when left out. | string | null | null |
name | string | null | null |
aspectRatioWidth over height: a number (`1`) or a CSS ratio (`"4 / 3"`). | number | string | "16 / 9" |
altThe preview's alternative text (empty: decorative). | string | "" |
labelShown in the empty field; it names the input. | — | $localize`:An empty image picker:Add image` |
changeLabelThe name of the button that replaces the image. | — | $localize`:Replaces a picked image:Change image` |
removeLabelThe name of the button that removes the image. | — | $localize`:Removes a picked image:Remove image` |
errorLabelShown when the image fails to load. | — | $localize`:A picked image that does not load:Image unavailable` |
localeThe locale the size limit is written in. | string | "en" |
| Name | Type |
|---|---|
rejectedA file `accept` or `maxSize` turned away. | FileRejection<File>[] |