| 1 |
import { useState } from 'react'; |
| 2 |
import { Button, Flex } from '@patternfly/react-core'; |
| 3 |
import UploadIcon from '@patternfly/react-icons/dist/esm/icons/upload-icon'; |
| 4 |
|
| 5 |
interface LoadingPropsType { |
| 6 |
spinnerAriaValueText: string; |
| 7 |
spinnerAriaLabelledBy?: string; |
| 8 |
spinnerAriaLabel?: string; |
| 9 |
isLoading: boolean; |
| 10 |
} |
| 11 |
|
| 12 |
export const ButtonProgress: React.FunctionComponent = () => { |
| 13 |
const [isPrimaryLoading, setIsPrimaryLoading] = useState<boolean>(true); |
| 14 |
const [isSecondaryLoading, setIsSecondaryLoading] = useState<boolean>(true); |
| 15 |
const [isInlineLoading, setIsInlineLoading] = useState<boolean>(true); |
| 16 |
const [isUploading, setIsUploading] = useState<boolean>(false); |
| 17 |
|
| 18 |
const primaryLoadingProps = {} as LoadingPropsType; |
| 19 |
primaryLoadingProps.spinnerAriaValueText = 'Loading'; |
| 20 |
primaryLoadingProps.spinnerAriaLabelledBy = 'primary-loading-button'; |
| 21 |
primaryLoadingProps.isLoading = isPrimaryLoading; |
| 22 |
|
| 23 |
const secondaryLoadingProps = {} as LoadingPropsType; |
| 24 |
secondaryLoadingProps.spinnerAriaValueText = 'Loading'; |
| 25 |
secondaryLoadingProps.spinnerAriaLabel = 'Content being loaded'; |
| 26 |
secondaryLoadingProps.isLoading = isSecondaryLoading; |
| 27 |
|
| 28 |
const inlineLoadingProps = {} as LoadingPropsType; |
| 29 |
inlineLoadingProps.spinnerAriaValueText = 'Loading'; |
| 30 |
inlineLoadingProps.spinnerAriaLabel = 'Content being loaded'; |
| 31 |
inlineLoadingProps.isLoading = isInlineLoading; |
| 32 |
|
| 33 |
const uploadingProps = {} as LoadingPropsType; |
| 34 |
uploadingProps.spinnerAriaValueText = 'Loading'; |
| 35 |
uploadingProps.spinnerAriaLabel = 'Uploading data'; |
| 36 |
uploadingProps.isLoading = isUploading; |
| 37 |
|
| 38 |
return ( |
| 39 |
<> |
| 40 |
<Flex columnGap={{ default: 'columnGapSm' }}> |
| 41 |
<Button |
| 42 |
variant="primary" |
| 43 |
id="primary-loading-button" |
| 44 |
onClick={() => setIsPrimaryLoading(!isPrimaryLoading)} |
| 45 |
{...primaryLoadingProps} |
| 46 |
> |
| 47 |
{isPrimaryLoading ? 'Click to stop loading' : 'Click to start loading'} |
| 48 |
</Button> |
| 49 |
<Button |
| 50 |
variant="secondary" |
| 51 |
onClick={() => setIsSecondaryLoading(!isSecondaryLoading)} |
| 52 |
{...secondaryLoadingProps} |
| 53 |
> |
| 54 |
{isSecondaryLoading ? 'Click to stop loading' : 'Click to start loading'} |
| 55 |
</Button> |
| 56 |
</Flex> |
| 57 |
<br /> |
| 58 |
<Button |
| 59 |
variant="plain" |
| 60 |
{...(!isUploading && { 'aria-label': 'Upload' })} |
| 61 |
onClick={() => setIsUploading(!isUploading)} |
| 62 |
icon={<UploadIcon />} |
| 63 |
{...uploadingProps} |
| 64 |
/> |
| 65 |
<br /> |
| 66 |
<br /> |
| 67 |
<Button variant="link" isInline onClick={() => setIsInlineLoading(!isInlineLoading)} {...inlineLoadingProps}> |
| 68 |
{isInlineLoading ? 'Pause loading logs' : 'Resume loading logs'} |
| 69 |
</Button> |
| 70 |
</> |
| 71 |
); |
| 72 |
}; |