import { Localized } from '@fluent/react'; import classNames from 'classnames'; import { forwardRef, useImperativeHandle, useMemo, useRef, useState, } from 'react'; import { Control, Controller, UseControllerProps } from 'react-hook-form'; import { FileIcon } from './icon/FileIcon'; import { UploadFileIcon } from './icon/UploadFileIcon'; import { Typography } from './Typography'; import { CloseIcon } from './icon/CloseIcon'; import { FolderIcon } from './icon/FolderIcon'; import { UploadFolderIcon } from './icon/UploadFolderIcon'; interface InputProps { variant?: 'primary' | 'secondary'; label?: string; name: string; } export const FileInputContentBlank = ({ isDragging, label, directory = false, }: { isDragging: boolean; label: string; directory?: boolean; }) => { return (
{directory ? ( ) : ( )}
, }} > Drop files to attach, or{' '} browse
); }; export const FileInputContentFile = ({ importedFileName, directory = false, onClearPicker, }: { importedFileName: string; onClearPicker: () => any; directory?: boolean; }) => { return (
{directory ? : } {importedFileName}
{ ev.stopPropagation(); onClearPicker(); }} >
); }; export const FileInputInside = forwardRef< HTMLInputElement, { variant?: 'primary' | 'secondary'; label?: string; accept: string; capture?: boolean | 'user' | 'environment'; multiple?: boolean; value: FileList; onChange: (...event: any[]) => void; name: string; importedFileName: string | null; } >(function AppInput( { label = 'tips-file_select', name, onChange, accept, capture, multiple = false, importedFileName, }, ref ) { const innerRef = useRef(null); useImperativeHandle(ref, () => innerRef.current!); const acceptList = useMemo(() => accept.split(/, ?/), [accept]); const [isDragging, setDragging] = useState(false); const isFileImported = importedFileName !== null && !isDragging; const onClearPicker = () => { onChange([]); innerRef.current!.value = ''; }; return ( ); }); export const FileInput = ({ control, name, label, variant = 'primary', rules, accept, multiple, capture, importedFileName, }: { rules: UseControllerProps['rules']; control: Control; accept: string; multiple?: boolean; capture?: boolean | 'user' | 'environment'; /** * Use a translation key! **/ label?: string; importedFileName: string | null; } & InputProps & Partial) => { return ( ( )} /> ); };