adaprive design for add dialog

This commit is contained in:
Daniel Shleifman
2021-06-09 12:15:57 +03:00
parent 763b55c75e
commit d6b10d79d8

View File

@@ -12,6 +12,7 @@ import { v4 as uuidv4 } from 'uuid'
import useChangeLanguage from 'utils/useChangeLanguage' import useChangeLanguage from 'utils/useChangeLanguage'
import { Cancel as CancelIcon } from '@material-ui/icons' import { Cancel as CancelIcon } from '@material-ui/icons'
import { useDropzone } from 'react-dropzone' import { useDropzone } from 'react-dropzone'
import { useMediaQuery } from '@material-ui/core'
const Header = styled.div` const Header = styled.div`
background: #00a572; background: #00a572;
@@ -23,18 +24,18 @@ const Header = styled.div`
padding: 15px 24px; padding: 15px 24px;
position: relative; position: relative;
` `
const ContentWrapper = styled.div`
background: linear-gradient(145deg, #e4f6ed, #b5dec9);
display: flex;
flex-direction: column;
justify-content: space-between;
`
const Content = styled.div` const Content = styled.div`
background: linear-gradient(145deg, #e4f6ed, #b5dec9);
flex: 1; flex: 1;
display: grid; display: grid;
grid-template-columns: repeat(2, 1fr); grid-template-columns: repeat(2, 1fr);
border-bottom: 1px solid rgba(0, 0, 0, 0.12); border-bottom: 1px solid rgba(0, 0, 0, 0.12);
overflow: auto;
@media (max-width: 930px) {
grid-template-columns: 1fr;
}
` `
const LeftSide = styled.div` const LeftSide = styled.div`
@@ -69,11 +70,21 @@ const RightSideBottomSectionNoFile = styled.div`
transform: translateY(-4%); transform: translateY(-4%);
} }
} }
@media (max-width: 930px) {
height: 400px;
place-items: center;
grid-template-rows: 40% 1fr;
}
` `
const RightSideBottomSectionFileSelected = styled.div` const RightSideBottomSectionFileSelected = styled.div`
${RightSideBottomSectionBasicStyles} ${RightSideBottomSectionBasicStyles}
place-items: center; place-items: center;
@media (max-width: 930px) {
height: 400px;
}
` `
const TorrentIconWrapper = styled.div` const TorrentIconWrapper = styled.div`
@@ -101,6 +112,7 @@ const IconWrapper = styled.div`
justify-items: center; justify-items: center;
align-content: start; align-content: start;
gap: 10px; gap: 10px;
align-self: start;
svg { svg {
transition: all 0.3s; transition: all 0.3s;
@@ -108,7 +120,7 @@ const IconWrapper = styled.div`
` `
const RightSideTopSection = styled.div` const RightSideTopSection = styled.div`
background: #fff; background: #e3f2eb;
padding: 0 20px 20px 20px; padding: 0 20px 20px 20px;
transition: all 0.3s; transition: all 0.3s;
@@ -120,17 +132,57 @@ const PosterWrapper = styled.div`
display: grid; display: grid;
grid-template-columns: max-content 1fr; grid-template-columns: max-content 1fr;
grid-template-rows: 300px max-content; grid-template-rows: 300px max-content;
gap: 10px 5px; column-gap: 5px;
position: relative;
margin-bottom: 20px;
grid-template-areas:
'poster suggestions'
'clear empty';
@media (max-width: 540px) {
grid-template-columns: 1fr;
gap: 5px 0;
justify-items: center;
grid-template-areas:
'poster'
'clear'
'suggestions';
}
` `
const PosterSuggestions = styled.div` const PosterSuggestions = styled.div`
display: grid; display: grid;
grid-template-columns: repeat(3, 70px); grid-area: suggestions;
grid-template-rows: repeat(4, calc(25% - 4px)); grid-template-columns: repeat(3, max-content);
grid-auto-flow: column; grid-template-rows: repeat(4, max-content);
gap: 5px; gap: 5px;
@media (max-width: 540px) {
grid-template-columns: repeat(5, max-content);
}
@media (max-width: 375px) {
grid-template-columns: repeat(4, max-content);
}
` `
const PosterSuggestionsItem = styled.div` const PosterSuggestionsItem = styled.div`
cursor: pointer; cursor: pointer;
width: 71px;
height: 71px;
@media (max-width: 430px) {
width: 60px;
height: 60px;
}
@media (max-width: 375px) {
width: 71px;
height: 71px;
}
@media (max-width: 355px) {
width: 60px;
height: 60px;
}
img { img {
transition: all 0.3s; transition: all 0.3s;
@@ -150,6 +202,7 @@ export const Poster = styled.div`
border-radius: 5px; border-radius: 5px;
overflow: hidden; overflow: hidden;
width: 200px; width: 200px;
grid-area: poster;
${poster ${poster
? css` ? css`
@@ -169,23 +222,19 @@ export const Poster = styled.div`
transform: scale(1.5) translateY(-3px); transform: scale(1.5) translateY(-3px);
} }
`} `}
`}
${
'' /* @media (max-width: 1280px) {
align-self: start;
}
@media (max-width: 840px) {
${poster
? css`
height: 200px;
` `
: css`
display: none; const ClearPosterButton = styled(Button)`
`} grid-area: clear;
} */ justify-self: center;
transform: translateY(-50%);
position: absolute;
${({ showbutton }) => !showbutton && 'display: none'};
@media (max-width: 540px) {
transform: translateY(-140%);
} }
`}
` `
const ButtonWrapper = styled.div` const ButtonWrapper = styled.div`
@@ -232,6 +281,8 @@ export default function AddDialog({ handleClose }) {
const [currentLang] = useChangeLanguage() const [currentLang] = useChangeLanguage()
const [selectedFile, setSelectedFile] = useState() const [selectedFile, setSelectedFile] = useState()
const fullScreen = useMediaQuery('@media (max-width:930px)')
const handleCapture = useCallback(files => { const handleCapture = useCallback(files => {
const [file] = files const [file] = files
if (!file) return if (!file) return
@@ -312,10 +363,16 @@ export default function AddDialog({ handleClose }) {
} }
return ( return (
<Dialog open onClose={handleClose} aria-labelledby='form-dialog-title' fullWidth maxWidth='md'> <Dialog
open
onClose={handleClose}
aria-labelledby='form-dialog-title'
fullScreen={fullScreen}
fullWidth
maxWidth='md'
>
<Header>{t('AddNewTorrent')}</Header> <Header>{t('AddNewTorrent')}</Header>
<ContentWrapper>
<Content> <Content>
<LeftSide> <LeftSide>
<TextField <TextField
@@ -339,7 +396,6 @@ export default function AddDialog({ handleClose }) {
<Poster poster={+isPosterUrlCorrect}> <Poster poster={+isPosterUrlCorrect}>
{isPosterUrlCorrect ? <img src={posterUrl} alt='poster' /> : <NoImageIcon />} {isPosterUrlCorrect ? <img src={posterUrl} alt='poster' /> : <NoImageIcon />}
</Poster> </Poster>
<PosterSuggestions> <PosterSuggestions>
{posterList {posterList
?.filter(url => url !== posterUrl) ?.filter(url => url !== posterUrl)
@@ -351,16 +407,19 @@ export default function AddDialog({ handleClose }) {
))} ))}
</PosterSuggestions> </PosterSuggestions>
<Button <ClearPosterButton
style={{ justifySelf: 'center' }} showbutton={+isPosterUrlCorrect}
onClick={removePoster} onClick={() => {
removePoster()
setIsUserInteractedWithPoster(true)
}}
color='primary' color='primary'
variant='outlined' variant='contained'
size='small' size='small'
disabled={!posterUrl} disabled={!posterUrl}
> >
{t('Clear')} {t('Clear')}
</Button> </ClearPosterButton>
</PosterWrapper> </PosterWrapper>
</LeftSide> </LeftSide>
@@ -414,7 +473,6 @@ export default function AddDialog({ handleClose }) {
{t('Add')} {t('Add')}
</Button> </Button>
</ButtonWrapper> </ButtonWrapper>
</ContentWrapper>
</Dialog> </Dialog>
) )
} }