UNPKG

@payfit/unity-components

Version:

53 lines (52 loc) • 2.6 kB
import { FileTriggerProps as AriaFileTriggerProps } from 'react-aria-components'; export interface FileUploadTriggerProps extends Pick<AriaFileTriggerProps, 'acceptDirectory' | 'acceptedFileTypes' | 'allowsMultiple' | 'defaultCamera' | 'onSelect'> { /** Identifies the native file input. */ id?: string; /** Names the native file input for browser form semantics. */ name?: string; /** The pressable or actionable element that opens the native file picker. */ children: AriaFileTriggerProps['children']; } /** * Gives a familiar control access to the device file picker. * FileUploadTrigger turns its pressable child into the native picker trigger * and returns selected files through `onSelect`. It only acquires files; * validation, display, and upload remain consumer-owned. * @param props - The native picker configuration and pressable child. * @param props.children - The focusable control that opens the native picker. * @param props.acceptDirectory - Lets people choose a directory when supported. * @param props.acceptedFileTypes - Filters visible file types in the native picker. * @param props.allowsMultiple - Lets people select several files at once. * @param props.defaultCamera - Selects a preferred device camera when supported. * @param props.id - Identifies the native file input. * @param props.name - Names the native file input for form submission. * @param props.onSelect - Receives the files chosen through the native picker. * @see {@link FileUploadTriggerProps} for native picker configuration. * @example * ```tsx * import { Button, FileUploadTrigger } from '@payfit/unity-components' * * export function AvatarPicker() { * return ( * <FileUploadTrigger * acceptedFileTypes={['image/jpeg', 'image/png']} * onSelect={files => { * const avatar = files?.item(0) * if (avatar) { * console.log(avatar.name) * } * }} * > * <Button variant="primary">Choose profile picture</Button> * </FileUploadTrigger> * ) * } * ``` * @remarks * - Use a focusable Button or Actionable child with a specific visible label or `aria-label`. * - Reflect disabled, pending, error, and success states on the child. * - Announce asynchronous results in a nearby live region. * - Pair `acceptedFileTypes` with visible acceptance guidance and validate the selection after it is returned. */ declare const FileUploadTrigger: import('react').ForwardRefExoticComponent<FileUploadTriggerProps & import('react').RefAttributes<HTMLInputElement>>; export { FileUploadTrigger };