Skip to content

Instantly share code, notes, and snippets.

@ajcrites
Last active March 18, 2019 19:01
Show Gist options
  • Save ajcrites/a660f9602e2151d543abf51a6965fd30 to your computer and use it in GitHub Desktop.
Save ajcrites/a660f9602e2151d543abf51a6965fd30 to your computer and use it in GitHub Desktop.
import React from 'react';
export const HexInput = ({ hex, setHex }) => {
const onChange = ({ target: { value } }) => {
setHex(value);
};
return (
<label>
Hex:
<input value={hex} onChange={onChange} />
</label>
);
};
import React from 'react';
export const RgbaInput = ({ rgba, setRgba }) => {
const onChange = idx => ({ target: { value } }) => {
const newRgba = [...rgba];
newRgba[idx] = value;
setRgba(newRgba);
};
return (
<label>
RGB(A):
<input value={rgba[0]} onChange={onChange(0)} />
<input value={rgba[1]} onChange={onChange(1)} />
<input value={rgba[2]} onChange={onChange(2)} />
<input value={rgba[3]} onChange={onChange(3)} />
</label>
);
}
@@ -9,8 +9,8 @@ export const ColorToolApp = () => {
return (
<main>
- <HexInput />
- <RgbaInput />
+ <HexInput hex={hex} setHex={setHex} />
+ <RgbaInput rgba={rgba} setRgba={setRgba} />
</main>
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment