Created
March 18, 2019 21:54
-
-
Save ajcrites/6de9f59028cb6438fececaa4d9672334 to your computer and use it in GitHub Desktop.
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
export const ColorInput = () => { | |
const { hex, setHex, setRgba } = useContext(ColorToolContext); | |
const input = useRef(null); | |
const [show, setShow] = useState(true); | |
useEffect(() => { | |
input.current.value = '!'; | |
// input[type=color] is not supported | |
if ('!' === input.current.value) { | |
setShow(false); | |
} | |
}); | |
const onChange = ({ target: { value } }) => { | |
setHex(value); | |
setRgba(value); | |
}; | |
return show ? ( | |
<label> | |
Color Picker: | |
<input type="color" ref={input} value={hex} onChange={onChange} /> | |
</label> | |
) : null; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment