|
| 1 | +import * as React from 'react'; |
| 2 | +import { |
| 3 | + Card, |
| 4 | + Button, |
| 5 | + Flex, |
| 6 | + Text, |
| 7 | + Divider, |
| 8 | + Image, |
| 9 | + Loader, |
| 10 | + Icon, |
| 11 | +} from '@aws-amplify/ui-react'; |
| 12 | +import { StorageManager } from '@aws-amplify/ui-react-storage'; |
| 13 | + |
| 14 | +export const App = () => { |
| 15 | + return ( |
| 16 | + <StorageManager |
| 17 | + acceptedFileTypes={['image/*']} |
| 18 | + path="public/" |
| 19 | + maxFileCount={100} |
| 20 | + components={{ |
| 21 | + Container({ children }) { |
| 22 | + return <Card variation="elevated">{children}</Card>; |
| 23 | + }, |
| 24 | + DropZone({ children, displayText, inDropZone, ...rest }) { |
| 25 | + return ( |
| 26 | + <Flex |
| 27 | + alignItems="center" |
| 28 | + direction="column" |
| 29 | + padding="medium" |
| 30 | + backgroundColor={inDropZone ? 'primary.10' : ''} |
| 31 | + {...rest} |
| 32 | + > |
| 33 | + <Text>Drop files here</Text> |
| 34 | + <Divider size="small" label="or" maxWidth="10rem" /> |
| 35 | + {children} |
| 36 | + </Flex> |
| 37 | + ); |
| 38 | + }, |
| 39 | + FilePicker({ onClick }) { |
| 40 | + return ( |
| 41 | + <Button variation="primary" onClick={onClick}> |
| 42 | + Browse Files |
| 43 | + </Button> |
| 44 | + ); |
| 45 | + }, |
| 46 | + FileList({ files, onCancelUpload, onDeleteUpload }) { |
| 47 | + return ( |
| 48 | + <Flex direction="row"> |
| 49 | + {files.map(({ file, key, progress, id, status, uploadTask }) => ( |
| 50 | + <Flex |
| 51 | + key={key} |
| 52 | + justifyContent="center" |
| 53 | + alignItems="center" |
| 54 | + width="5rem" |
| 55 | + height="5rem" |
| 56 | + position="relative" |
| 57 | + > |
| 58 | + <Image |
| 59 | + borderRadius="small" |
| 60 | + height="100%" |
| 61 | + objectFit="cover" |
| 62 | + src={URL.createObjectURL(file)} |
| 63 | + alt={key} |
| 64 | + /> |
| 65 | + {progress < 100 ? ( |
| 66 | + <Loader |
| 67 | + position="absolute" |
| 68 | + size="large" |
| 69 | + percentage={progress} |
| 70 | + isDeterminate |
| 71 | + isPercentageTextHidden |
| 72 | + /> |
| 73 | + ) : null} |
| 74 | + |
| 75 | + <Button |
| 76 | + opacity="50" |
| 77 | + borderRadius="xxl" |
| 78 | + backgroundColor="background.primary" |
| 79 | + position="absolute" |
| 80 | + variation="link" |
| 81 | + size="small" |
| 82 | + onClick={() => { |
| 83 | + if (status === 'uploading') { |
| 84 | + onCancelUpload({ id, uploadTask }); |
| 85 | + } else { |
| 86 | + onDeleteUpload({ id }); |
| 87 | + } |
| 88 | + }} |
| 89 | + > |
| 90 | + <Icon |
| 91 | + fontSize="large" |
| 92 | + color="font.error" |
| 93 | + viewBox={{ width: 512, height: 512 }} |
| 94 | + paths={[ |
| 95 | + { |
| 96 | + d: 'M448 256c0-106-86-192-192-192S64 150 64 256s86 192 192 192 192-86 192-192z', |
| 97 | + strokeWidth: '32', |
| 98 | + fill: 'none', |
| 99 | + strokeMiterlimit: '10', |
| 100 | + stroke: 'currentColor', |
| 101 | + }, |
| 102 | + { |
| 103 | + d: 'M320 320L192 192m0 128l128-128', |
| 104 | + strokeWidth: '32', |
| 105 | + fill: 'none', |
| 106 | + strokeLinecap: 'round', |
| 107 | + stroke: 'currentColor', |
| 108 | + }, |
| 109 | + ]} |
| 110 | + /> |
| 111 | + </Button> |
| 112 | + </Flex> |
| 113 | + ))} |
| 114 | + </Flex> |
| 115 | + ); |
| 116 | + }, |
| 117 | + }} |
| 118 | + /> |
| 119 | + ); |
| 120 | +}; |
0 commit comments