diff options
author | Michael Muré <batolettre@gmail.com> | 2021-01-31 20:17:30 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-31 20:17:30 +0100 |
commit | abd16ff345c5246d3bdf0382b69bea59637f73e1 (patch) | |
tree | 180c69f0ff553be44f882ab2eabbc1ae68bf9576 /webui/src/pages/bug | |
parent | 1b4eeb0690b543462d23c35a95d2243ff8c5aa7a (diff) | |
parent | 32eb1819aa1fbba9f423414a2200307f9b84be82 (diff) | |
download | git-bug-abd16ff345c5246d3bdf0382b69bea59637f73e1.tar.gz |
Merge pull request #538 from claudioantonio/webui_158
Webui - Allow to create bugs #158
Diffstat (limited to 'webui/src/pages/bug')
-rw-r--r-- | webui/src/pages/bug/CommentInput.tsx | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/webui/src/pages/bug/CommentInput.tsx b/webui/src/pages/bug/CommentInput.tsx new file mode 100644 index 00000000..540a53f7 --- /dev/null +++ b/webui/src/pages/bug/CommentInput.tsx @@ -0,0 +1,96 @@ +import React, { useState, useEffect } from 'react'; + +import Tab from '@material-ui/core/Tab'; +import Tabs from '@material-ui/core/Tabs'; +import TextField from '@material-ui/core/TextField'; +import { makeStyles } from '@material-ui/core/styles'; + +import Content from 'src/components/Content'; + +const useStyles = makeStyles((theme) => ({ + container: { + margin: theme.spacing(2, 0), + padding: theme.spacing(0, 2, 2, 2), + }, + textarea: {}, + tabContent: { + margin: theme.spacing(2, 0), + }, + preview: { + borderBottom: `solid 3px ${theme.palette.grey['200']}`, + minHeight: '5rem', + }, + actions: { + display: 'flex', + justifyContent: 'flex-end', + }, +})); + +type TabPanelProps = { + children: React.ReactNode; + value: number; + index: number; +} & React.HTMLProps<HTMLDivElement>; +function TabPanel({ children, value, index, ...props }: TabPanelProps) { + return ( + <div + role="tabpanel" + hidden={value !== index} + id={`editor-tabpanel-${index}`} + aria-labelledby={`editor-tab-${index}`} + {...props} + > + {value === index && children} + </div> + ); +} + +const a11yProps = (index: number) => ({ + id: `editor-tab-${index}`, + 'aria-controls': `editor-tabpanel-${index}`, +}); + +type Props = { + loading: boolean; + onChange: (comment: string) => void; +}; + +function CommentInput({ loading, onChange }: Props) { + const [input, setInput] = useState<string>(''); + const [tab, setTab] = useState(0); + const classes = useStyles(); + + useEffect(() => { + onChange(input); + }, [input, onChange]); + + return ( + <div> + <Tabs value={tab} onChange={(_, t) => setTab(t)}> + <Tab label="Write" {...a11yProps(0)} /> + <Tab label="Preview" {...a11yProps(1)} /> + </Tabs> + <div className={classes.tabContent}> + <TabPanel value={tab} index={0}> + <TextField + fullWidth + label="Comment" + placeholder="Leave a comment" + className={classes.textarea} + multiline + value={input} + variant="filled" + rows="4" // TODO: rowsMin support + onChange={(e: any) => setInput(e.target.value)} + disabled={loading} + /> + </TabPanel> + <TabPanel value={tab} index={1} className={classes.preview}> + <Content markdown={input} /> + </TabPanel> + </div> + </div> + ); +} + +export default CommentInput; |