|
| 1 | +import { |
| 2 | + CardContent, |
| 3 | + StyleRulesCallback, |
| 4 | + Theme, |
| 5 | + Typography, |
| 6 | + WithStyles, |
| 7 | + withStyles, |
| 8 | +} from '@material-ui/core' |
| 9 | +import React, { FunctionComponent } from 'react' |
| 10 | +import Photos from '~generic/Photos' |
| 11 | +import { OnClick } from '~typings/react' |
| 12 | + |
| 13 | +const TaskPhotoEdit: FunctionComponent<TaskPhotoEditProps> = ({ |
| 14 | + classes, |
| 15 | + files, |
| 16 | + onFilesUpdate, |
| 17 | +}) => { |
| 18 | + return ( |
| 19 | + <CardContent className={classes.cardContent}> |
| 20 | + <Typography variant="h3" component="h3"> |
| 21 | + Zdjęcia |
| 22 | + <hr className={classes.underline} /> |
| 23 | + </Typography> |
| 24 | + <div |
| 25 | + className={ |
| 26 | + !files.length ? classes.contentWithAddPhotoLater : classes.content |
| 27 | + } |
| 28 | + > |
| 29 | + <div className={classes.photosWrapper}> |
| 30 | + <Photos |
| 31 | + photosPlaceholderText="Dodaj zdjęcie rozwiązania" |
| 32 | + filesLength={1} |
| 33 | + fullWidth |
| 34 | + {...{ files, onFilesUpdate }} |
| 35 | + /> |
| 36 | + </div> |
| 37 | + </div> |
| 38 | + </CardContent> |
| 39 | + ) |
| 40 | +} |
| 41 | + |
| 42 | +const styles: StyleRulesCallback = (theme: Theme) => ({ |
| 43 | + cardContent: { |
| 44 | + height: '100%', |
| 45 | + paddingBottom: '0 !important', |
| 46 | + display: 'grid', |
| 47 | + gridTemplateRows: 'max-content', |
| 48 | + }, |
| 49 | + contentWithAddPhotoLater: { |
| 50 | + height: '100%', |
| 51 | + display: 'grid', |
| 52 | + gridTemplateRows: '6fr 5fr', |
| 53 | + }, |
| 54 | + content: { |
| 55 | + display: 'grid', |
| 56 | + gridTemplateRows: '1fr', |
| 57 | + }, |
| 58 | + closeIcon: { |
| 59 | + position: 'absolute', |
| 60 | + right: '8px', |
| 61 | + color: theme.palette.secondary.main, |
| 62 | + backgroundColor: 'white', |
| 63 | + borderRadius: '100%', |
| 64 | + zIndex: 1, |
| 65 | + marginTop: '-9px', |
| 66 | + cursor: 'pointer', |
| 67 | + }, |
| 68 | + paper: { |
| 69 | + maxHeight: '100%', |
| 70 | + margin: '0.5rem 0 0.5rem', |
| 71 | + cursor: 'pointer', |
| 72 | + }, |
| 73 | + photosWrapper: { |
| 74 | + display: 'grid', |
| 75 | + gridGap: '1rem', |
| 76 | + marginTop: '2rem', |
| 77 | + }, |
| 78 | + photoPaper: { |
| 79 | + display: 'grid', |
| 80 | + gridTemplateColumns: '2fr 1fr', |
| 81 | + margin: '0.5rem 0 0.5rem', |
| 82 | + }, |
| 83 | + photoIcon: { |
| 84 | + fontSize: '6rem', |
| 85 | + }, |
| 86 | + photoNameContainer: { |
| 87 | + display: 'flex', |
| 88 | + margin: '0 5px 0 5px', |
| 89 | + alignItems: 'center', |
| 90 | + }, |
| 91 | + photoName: { |
| 92 | + width: '100%', |
| 93 | + wordBreak: 'break-all', |
| 94 | + }, |
| 95 | + browsePhotoContainer: { |
| 96 | + height: '100%', |
| 97 | + justifyContent: 'center', |
| 98 | + alignItems: 'center', |
| 99 | + display: 'flex', |
| 100 | + cursor: 'pointer', |
| 101 | + }, |
| 102 | + browsePhotoTitle: { |
| 103 | + display: 'flex', |
| 104 | + flexDirection: 'column', |
| 105 | + alignItems: 'center', |
| 106 | + }, |
| 107 | + browsePhotoParagraph: { |
| 108 | + margin: '0 0 2rem', |
| 109 | + }, |
| 110 | + fileInput: { |
| 111 | + display: 'none', |
| 112 | + }, |
| 113 | + filePicture: { |
| 114 | + backgroundColor: 'black', |
| 115 | + borderRadius: '5px', |
| 116 | + backgroundSize: 'contain', |
| 117 | + backgroundRepeat: 'no-repeat', |
| 118 | + backgroundPosition: 'center', |
| 119 | + }, |
| 120 | + underline: { |
| 121 | + height: '1px', |
| 122 | + border: 'none', |
| 123 | + backgroundColor: theme.palette.grey[300], |
| 124 | + }, |
| 125 | +}) |
| 126 | + |
| 127 | +interface TaskPhotoEditProps extends WithStyles<typeof styles> { |
| 128 | + files: ExtendedFile[] |
| 129 | + onFilesUpdate: (files: ExtendedFile[]) => void |
| 130 | + onFilesLater: OnClick |
| 131 | +} |
| 132 | + |
| 133 | +export interface ExtendedFile extends File { |
| 134 | + id: string |
| 135 | + url: string |
| 136 | +} |
| 137 | + |
| 138 | +export default withStyles(styles)(TaskPhotoEdit) |
0 commit comments