@winglet/react-utils
Version:
React utility library providing custom hooks, higher-order components (HOCs), and utility functions to enhance React application development with improved reusability and functionality
24 lines (23 loc) • 1.06 kB
TypeScript
import { type ComponentType } from 'react';
import type { Fn } from '../../@aileron/declare';
interface BaseProps {
onClick?: Fn<[e?: MouseEvent]>;
}
interface UploaderProps {
acceptFormat?: string[];
onChange?: Fn<[file: File]>;
}
/**
* Higher-Order Component (HOC) that adds file upload functionality to a component.
* When clicked, opens a file selection dialog and triggers onChange callback when a file is selected.
* @typeParam Props - The base component props type
* @param Component - The component to add uploader functionality to
* @returns A component with file upload functionality
* @example
* const FileUploadButton = withUploader(Button);
* <FileUploadButton acceptFormat={[".jpg", ".png"]} onChange={handleFileChange}>
* Upload Image
* </FileUploadButton>
*/
export declare const withUploader: <Props extends BaseProps>(Component: ComponentType<Props>) => import("react").MemoExoticComponent<({ onClick, onChange, acceptFormat, ...props }: Props & UploaderProps) => import("react/jsx-runtime").JSX.Element>;
export {};