diff options
author | eug-vs <eug-vs@keemail.me> | 2020-10-08 15:51:19 +0300 |
---|---|---|
committer | eug-vs <eug-vs@keemail.me> | 2020-10-08 15:51:19 +0300 |
commit | 3cbf292b6d4976589428d0841cd1201057d104d4 (patch) | |
tree | 605f1019197f4000fe92911e519c52f63f58ac3e | |
parent | c73a0d7643ac335dbcdc64b90467ba7d3a45c4f4 (diff) | |
download | which-ui-3cbf292b6d4976589428d0841cd1201057d104d4.tar.gz |
feat: use icon in header instead of submit button
-rw-r--r-- | src/components/ModalScreen/ModalScreen.tsx | 13 | ||||
-rw-r--r-- | src/containers/PollCreation/PollCreation.tsx | 29 |
2 files changed, 19 insertions, 23 deletions
diff --git a/src/components/ModalScreen/ModalScreen.tsx b/src/components/ModalScreen/ModalScreen.tsx index 81e5c5a..110bd8b 100644 --- a/src/components/ModalScreen/ModalScreen.tsx +++ b/src/components/ModalScreen/ModalScreen.tsx @@ -12,11 +12,12 @@ import { useTheme } from '@material-ui/core'; import { makeStyles } from '@material-ui/core/styles'; -import CloseIcon from '@material-ui/icons/Close'; import { TransitionProps } from '@material-ui/core/transitions'; +import CloseIcon from '@material-ui/icons/Close'; interface PropTypes { title: string; + rightIcon?: JSX.Element; } const useStyles = makeStyles(theme => ({ @@ -37,7 +38,7 @@ const Transition = React.forwardRef(( ref: React.Ref<unknown> ) => <Slide direction="left" ref={ref} {...props} />); -const ModalScreen: React.FC<PropTypes> = ({ title, children }) => { +const ModalScreen: React.FC<PropTypes> = ({ title, rightIcon, children }) => { const [isOpen, setIsOpen] = useState<boolean>(true); const classes = useStyles(); const theme = useTheme(); @@ -64,9 +65,11 @@ const ModalScreen: React.FC<PropTypes> = ({ title, children }) => { <Typography variant="h6"> { title } </Typography> - <IconButton style={{ opacity: 0, pointerEvents: 'none' }}> - <CloseIcon /> - </IconButton> + { rightIcon || ( + <IconButton style={{ visibility: 'hidden' }}> + <CloseIcon /> + </IconButton> + )} </Toolbar> </AppBar> <Divider /> diff --git a/src/containers/PollCreation/PollCreation.tsx b/src/containers/PollCreation/PollCreation.tsx index b7ee00a..18c3c6b 100644 --- a/src/containers/PollCreation/PollCreation.tsx +++ b/src/containers/PollCreation/PollCreation.tsx @@ -3,11 +3,12 @@ import Bluebird from 'bluebird'; import { useHistory } from 'react-router-dom'; import { makeStyles } from '@material-ui/core/styles'; import { - Button, + IconButton, Card, Container, LinearProgress } from '@material-ui/core'; +import SendIcon from '@material-ui/icons/Send'; import { useSnackbar } from 'notistack'; import useS3Preupload from './useS3Preupload'; @@ -46,7 +47,7 @@ const PollCreation: React.FC = () => { progress: rightProgress } = useS3Preupload(); - const handleClick = async () => { + const handleSubmit = async () => { try { const [leftUrl, rightUrl] = await Bluebird.all([resolveLeft(), resolveRight()]); @@ -67,8 +68,14 @@ const PollCreation: React.FC = () => { } }; + const submitIcon = ( + <IconButton onClick={handleSubmit} disabled={!(left && right)}> + <SendIcon /> + </IconButton> + ); + return ( - <ModalScreen title="Create a poll"> + <ModalScreen title="Create a poll" rightIcon={submitIcon}> <Container maxWidth="sm" disableGutters> <Card elevation={3}> {user && <UserStrip user={user} info="" />} @@ -76,21 +83,7 @@ const PollCreation: React.FC = () => { <ImageInput callback={setLeft} progress={leftProgress} /> <ImageInput callback={setRight} progress={rightProgress} /> </div> - { - leftProgress || rightProgress - ? <LinearProgress color="primary" /> - : ( - <Button - color="primary" - disabled={!(left && right)} - variant="contained" - onClick={handleClick} - fullWidth - > - Submit - </Button> - ) - } + {(leftProgress > 0 || rightProgress > 0) && <LinearProgress color="primary" />} </Card> </Container> </ModalScreen> |