@mskcc/carbon-react
Version:
Carbon react components for the MSKCC DSM
174 lines (173 loc) • 5.53 kB
TypeScript
/**
* MSKCC DSM 2021, 2023
*/
import PropTypes from 'prop-types';
import React from 'react';
import { ReactAttr } from '../../types/common';
import { ButtonKind } from '../Button';
export interface FileUploaderProps extends ReactAttr<HTMLSpanElement> {
/**
* Specify the types of files that this input should be able to receive
*/
accept?: string[];
/**
* Specify the type of the `<FileUploaderButton>`
*/
buttonKind?: ButtonKind;
/**
* Provide the label text to be read by screen readers when interacting with
* the `<FileUploaderButton>`
*/
buttonLabel?: string;
/**
* Provide a custom className to be applied to the container node
*/
className?: string;
/**
* Specify whether file input is disabled
*/
disabled?: boolean;
/**
* Specify the status of the File Upload
*/
filenameStatus: 'edit' | 'complete' | 'uploading';
/**
* Provide a description for the complete/close icon that can be read by screen readers
*/
iconDescription: string;
/**
* Specify the description text of this `<FileUploader>`
*/
labelDescription?: string;
/**
* Specify the title text of this `<FileUploader>`
*/
labelTitle?: string;
/**
* Specify if the component should accept multiple files to upload
*/
multiple?: boolean;
/**
* Provide a name for the underlying `<input>` node
*/
name?: string;
/**
* Provide an optional `onChange` hook that is called each time the input is
* changed
*/
onChange?: (event: any) => void;
/**
* Provide an optional `onClick` hook that is called each time the
* FileUploader is clicked
*/
onClick?: (event: any) => void;
/**
* Provide an optional `onDelete` hook that is called when an uploaded item
* is removed
*/
onDelete?: (event: any) => void;
/**
* Specify the size of the FileUploaderButton, from a list of available
* sizes.
*/
size?: 'sm' | 'md' | 'lg';
}
export default class FileUploader extends React.Component<FileUploaderProps, {
filenames: string[];
}> {
static propTypes: {
/**
* Specify the types of files that this input should be able to receive
*/
accept: PropTypes.Requireable<(string | null | undefined)[]>;
/**
* Specify the type of the `<FileUploaderButton>`
*/
buttonKind: PropTypes.Requireable<"primary" | "secondary" | "danger" | "ghost" | "danger--primary" | "danger--ghost" | "danger--tertiary" | "tertiary">;
/**
* Provide the label text to be read by screen readers when interacting with
* the `<FileUploaderButton>`
*/
buttonLabel: PropTypes.Requireable<string>;
/**
* Provide a custom className to be applied to the container node
*/
className: PropTypes.Requireable<string>;
/**
* Specify whether file input is disabled
*/
disabled: PropTypes.Requireable<boolean>;
/**
* Specify the status of the File Upload
*/
filenameStatus: PropTypes.Validator<string>;
/**
* Provide a description for the complete/close icon that can be read by screen readers
*/
iconDescription: PropTypes.Validator<string>;
/**
* Specify the description text of this `<FileUploader>`
*/
labelDescription: PropTypes.Requireable<string>;
/**
* Specify the title text of this `<FileUploader>`
*/
labelTitle: PropTypes.Requireable<string>;
/**
* Specify if the component should accept multiple files to upload
*/
multiple: PropTypes.Requireable<boolean>;
/**
* Provide a name for the underlying `<input>` node
*/
name: PropTypes.Requireable<string>;
/**
* Provide an optional `onChange` hook that is called each time the input is
* changed
*/
onChange: PropTypes.Requireable<(...args: any[]) => any>;
/**
* Provide an optional `onClick` hook that is called each time the
* FileUploader is clicked
*/
onClick: PropTypes.Requireable<(...args: any[]) => any>;
/**
* Provide an optional `onDelete` hook that is called when an uploaded item
* is removed
*/
onDelete: PropTypes.Requireable<(...args: any[]) => any>;
/**
* Specify the size of the FileUploaderButton, from a list of available
* sizes.
*/
size: PropTypes.Requireable<string>;
};
static contextType: React.Context<string>;
static defaultProps: {
disabled: boolean;
filenameStatus: string;
buttonLabel: string;
buttonKind: string;
multiple: boolean;
onClick: () => void;
accept: never[];
};
state: {
filenames: string[];
};
nodes: HTMLElement[];
uploaderButton: React.RefObject<HTMLLabelElement>;
static getDerivedStateFromProps({ filenameStatus }: {
filenameStatus: any;
}, state: any): {
filenameStatus: any;
prevFilenameStatus: any;
} | null;
handleChange: (evt: any) => void;
handleClick: (evt: any, { index, filenameStatus }: {
index: any;
filenameStatus: any;
}) => void;
clearFiles: () => void;
render(): JSX.Element;
}