Image Picker

覆盖原生文件输入框的可点按图片字段:先是虚线占位区,然后是带更换和移除按钮的预览,值为所选文件或已存储图片的 URL。

可用框架
  • Angular: 可用
  • Vue: 可用
  • React: 可用
  • React Native: 可用

用法

PNG or JPG, up to 2 MB.

导入

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

API 参考

SoneImagePickerComponent组件

`<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)`.

选择器
sone-image-picker
输入
名称类型 默认值
value双向

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"
输出
名称类型
rejected

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

FileRejection<File>[]