-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
128 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
plugins/wiggle/src/LinearWiggleDisplay/components/SetColorDialog.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import React from 'react' | ||
import { makeStyles } from '@material-ui/core/styles' | ||
import { | ||
Dialog, | ||
DialogContent, | ||
DialogTitle, | ||
IconButton, | ||
Typography, | ||
Button, | ||
} from '@material-ui/core' | ||
import CloseIcon from '@material-ui/icons/Close' | ||
import { CompactPicker, Color, RGBColor } from 'react-color' | ||
|
||
const useStyles = makeStyles(theme => ({ | ||
root: {}, | ||
closeButton: { | ||
position: 'absolute', | ||
right: theme.spacing(1), | ||
top: theme.spacing(1), | ||
color: theme.palette.grey[500], | ||
}, | ||
})) | ||
|
||
// this is needed because passing a entire color object into the react-color | ||
// for alpha, can't pass in an rgba string for example | ||
function serializeColor(color: Color) { | ||
if (color instanceof Object) { | ||
const { r, g, b, a } = color as RGBColor | ||
return `rgb(${r},${g},${b},${a})` | ||
} | ||
return color | ||
} | ||
|
||
export default function SetColorDialog(props: { | ||
display: { | ||
color: number | ||
setColor: Function | ||
} | ||
handleClose: () => void | ||
}) { | ||
const classes = useStyles() | ||
const { display, handleClose } = props | ||
|
||
return ( | ||
<Dialog | ||
open | ||
onClose={handleClose} | ||
aria-labelledby="alert-dialog-title" | ||
aria-describedby="alert-dialog-description" | ||
> | ||
<DialogTitle id="alert-dialog-title"> | ||
Select a color | ||
<IconButton | ||
aria-label="close" | ||
className={classes.closeButton} | ||
onClick={handleClose} | ||
> | ||
<CloseIcon /> | ||
</IconButton> | ||
</DialogTitle> | ||
<DialogContent style={{ overflowX: 'hidden' }}> | ||
<div className={classes.root}> | ||
<CompactPicker | ||
onChange={event => { | ||
display.setColor(serializeColor(event.rgb)) | ||
}} | ||
/> | ||
<br /> | ||
<div style={{ margin: 20 }}> | ||
<Button | ||
onClick={() => { | ||
display.setColor(undefined) | ||
}} | ||
color="secondary" | ||
variant="contained" | ||
> | ||
Restore default from config | ||
</Button> | ||
<Button | ||
variant="contained" | ||
color="primary" | ||
type="submit" | ||
onClick={() => { | ||
handleClose() | ||
}} | ||
> | ||
Submit | ||
</Button> | ||
</div> | ||
</div> | ||
</DialogContent> | ||
</Dialog> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters