|
| 1 | +// @flow |
| 2 | + |
| 3 | +import React, { useState, useMemo, useRef, useEffect } from "react" |
| 4 | +import { useLocalStorage } from "react-use" |
| 5 | +import { createPortal } from "react-dom" |
| 6 | +import IconButton from "@material-ui/core/IconButton" |
| 7 | +import BrushIcon from "@material-ui/icons/Brush" |
| 8 | +import ArrowForwardIcon from "@material-ui/icons/ArrowForward" |
| 9 | +import { styled } from "@material-ui/core/styles" |
| 10 | +import * as colors from "@material-ui/core/colors" |
| 11 | +import Button from "@material-ui/core/Button" |
| 12 | +import TextField from "@material-ui/core/TextField" |
| 13 | +import InputAdornment from "@material-ui/core/InputAdornment" |
| 14 | +import AddBoxTwoTone from "@material-ui/icons/AddBoxTwoTone" |
| 15 | +import ExitToAppIcon from "@material-ui/icons/ExitToApp" |
| 16 | +import CircularProgress from "@material-ui/core/CircularProgress" |
| 17 | +import HeaderPopupBox from "../HeaderPopupBox" |
| 18 | +import useEventCallback from "use-event-callback" |
| 19 | +import memoize from "lodash/memoize" |
| 20 | +import getBrushColorPalette from "../../utils/get-brush-color-palette.js" |
| 21 | + |
| 22 | +const Container = styled("div")({ position: "relative" }) |
| 23 | +const BrushCircle = styled("div")(({ color }) => ({ |
| 24 | + display: "inline", |
| 25 | + marginRight: 8, |
| 26 | + backgroundColor: color[700], |
| 27 | + width: 24, |
| 28 | + height: 24, |
| 29 | + borderRadius: 20, |
| 30 | +})) |
| 31 | + |
| 32 | +const OtherColorContainers = styled("div")({ |
| 33 | + paddingTop: 10, |
| 34 | + padding: 4, |
| 35 | + display: "flex", |
| 36 | + flexWrap: "wrap", |
| 37 | +}) |
| 38 | + |
| 39 | +const StyledIconButton = styled(IconButton)(({ iconColor, selected }) => ({ |
| 40 | + display: "flex", |
| 41 | + justifyContent: "center", |
| 42 | + alignItems: "center", |
| 43 | + backgroundColor: iconColor[700], |
| 44 | + border: selected ? `4px solid ${iconColor["A200"]}` : "4px solid #fff", |
| 45 | + boxSizing: "content-box", |
| 46 | + margin: 4, |
| 47 | + transition: "transform 200ms linear", |
| 48 | + "&:hover": { |
| 49 | + backgroundColor: iconColor[800], |
| 50 | + transform: "scale(1.2,1.2)", |
| 51 | + }, |
| 52 | + "&:active": { |
| 53 | + transition: "transform 100ms linear", |
| 54 | + transform: "scale(1.4,1.4)", |
| 55 | + }, |
| 56 | +})) |
| 57 | + |
| 58 | +const StyledButton = styled(Button)(({ selected, iconColor }) => ({ |
| 59 | + justifyContent: "flex-start", |
| 60 | + marginTop: 4, |
| 61 | + marginBottom: 4, |
| 62 | + paddingTop: 8, |
| 63 | + paddingBottom: 8, |
| 64 | + backgroundColor: selected ? iconColor[50] : "#fff", |
| 65 | + border: selected ? `2px solid ${iconColor[200]}` : "2px solid #fff", |
| 66 | + "&:hover": { |
| 67 | + backgroundColor: selected ? iconColor[100] : "none", |
| 68 | + }, |
| 69 | +})) |
| 70 | + |
| 71 | +export default ({ selectedBrush, onChangeSelectedBrush }) => { |
| 72 | + const [open, changeOpen] = useState(false) |
| 73 | + const handleClick = useEventCallback((color) => |
| 74 | + memoize(() => onChangeSelectedBrush(color)) |
| 75 | + ) |
| 76 | + |
| 77 | + return ( |
| 78 | + <Container |
| 79 | + onMouseEnter={() => changeOpen(true)} |
| 80 | + onMouseLeave={() => changeOpen(false)} |
| 81 | + > |
| 82 | + <IconButton> |
| 83 | + <BrushIcon |
| 84 | + style={{ color: getBrushColorPalette(selectedBrush)[800] }} |
| 85 | + /> |
| 86 | + </IconButton> |
| 87 | + <HeaderPopupBox open={open}> |
| 88 | + <h1>Sample Brushes</h1> |
| 89 | + <StyledButton |
| 90 | + selected={selectedBrush === "complete" || selectedBrush === "blue"} |
| 91 | + iconColor={colors.blue} |
| 92 | + fullWidth |
| 93 | + onClick={handleClick("complete")} |
| 94 | + > |
| 95 | + <BrushCircle color={colors.blue} /> |
| 96 | + Complete |
| 97 | + </StyledButton> |
| 98 | + <StyledButton |
| 99 | + selected={ |
| 100 | + selectedBrush === "review" || selectedBrush === "deepOrange" |
| 101 | + } |
| 102 | + iconColor={colors.deepOrange} |
| 103 | + fullWidth |
| 104 | + onClick={handleClick("review")} |
| 105 | + > |
| 106 | + <BrushCircle color={colors.deepOrange} /> |
| 107 | + Review |
| 108 | + </StyledButton> |
| 109 | + <OtherColorContainers> |
| 110 | + <StyledIconButton |
| 111 | + onClick={handleClick("green")} |
| 112 | + selected={selectedBrush === "green"} |
| 113 | + iconColor={colors.green} |
| 114 | + /> |
| 115 | + <StyledIconButton |
| 116 | + onClick={handleClick("purple")} |
| 117 | + selected={selectedBrush === "purple"} |
| 118 | + iconColor={colors.purple} |
| 119 | + /> |
| 120 | + <StyledIconButton |
| 121 | + onClick={handleClick("pink")} |
| 122 | + selected={selectedBrush === "pink"} |
| 123 | + iconColor={colors.pink} |
| 124 | + /> |
| 125 | + <StyledIconButton |
| 126 | + onClick={handleClick("cyan")} |
| 127 | + selected={selectedBrush === "cyan"} |
| 128 | + iconColor={colors.cyan} |
| 129 | + /> |
| 130 | + <StyledIconButton |
| 131 | + onClick={handleClick("orange")} |
| 132 | + selected={selectedBrush === "orange"} |
| 133 | + iconColor={colors.orange} |
| 134 | + /> |
| 135 | + <StyledIconButton |
| 136 | + onClick={handleClick("indigo")} |
| 137 | + selected={selectedBrush === "indigo"} |
| 138 | + iconColor={colors.indigo} |
| 139 | + /> |
| 140 | + </OtherColorContainers> |
| 141 | + </HeaderPopupBox> |
| 142 | + </Container> |
| 143 | + ) |
| 144 | +} |
0 commit comments