| 1 |
import { useContext } from 'react'; |
| 2 |
import styles from '@patternfly/react-styles/css/components/MultipleFileUpload/multiple-file-upload'; |
| 3 |
import { css } from '@patternfly/react-styles'; |
| 4 |
import { MultipleFileUploadContext } from './MultipleFileUpload'; |
| 5 |
import { Button } from '../Button'; |
| 6 |
|
| 7 |
export interface MultipleFileUploadButtonProps extends React.HTMLProps<HTMLDivElement> { |
| 8 |
/** Class to add to outer div */ |
| 9 |
className?: string; |
| 10 |
/** Aria-label for the button */ |
| 11 |
'aria-label'?: string; |
| 12 |
/** Visible text label for the button */ |
| 13 |
browseButtonText?: string; |
| 14 |
} |
| 15 |
|
| 16 |
export const MultipleFileUploadButton: React.FunctionComponent<MultipleFileUploadButtonProps> = ({ |
| 17 |
className, |
| 18 |
'aria-label': ariaLabel, |
| 19 |
browseButtonText = 'Upload', |
| 20 |
...props |
| 21 |
}: MultipleFileUploadButtonProps) => { |
| 22 |
if (!ariaLabel && !browseButtonText) { |
| 23 |
// eslint-disable-next-line no-console |
| 24 |
console.warn( |
| 25 |
"For accessibility reasons an aria-label should be specified on MultipleFileUploadButton if a browseButtonText isn't" |
| 26 |
); |
| 27 |
} |
| 28 |
const { open } = useContext(MultipleFileUploadContext); |
| 29 |
|
| 30 |
return ( |
| 31 |
<div className={css(styles.multipleFileUploadUpload, className)} {...props}> |
| 32 |
<Button variant="secondary" aria-label={ariaLabel} onClick={open}> |
| 33 |
{browseButtonText} |
| 34 |
</Button> |
| 35 |
</div> |
| 36 |
); |
| 37 |
}; |
| 38 |
|
| 39 |
MultipleFileUploadButton.displayName = 'MultipleFileUploadButton'; |