utils#getColorsString JavaScript Examples
The following examples show how to use
utils#getColorsString.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: colors-input.js From raster-playground with GNU General Public License v3.0 | 5 votes |
export default function ColorsInput() {
const [colors, onChangeColor] = useQueryParam(URL_COLORS, StringParam);
const [itemColorStatus, setItemColorStatus] = useState(null);
const colorsArray = getColorsArray(colors);
const changeItemColor = color => {
setItemColorStatus({ color: color.hex, key: itemColorStatus.key });
let tempColorsArray = colorsArray;
tempColorsArray[itemColorStatus.key] = color.hex;
onChangeColor(getColorsString(tempColorsArray), URL_UPDATE_PUSH);
};
const addColor = () => {
setItemColorStatus({ color: '#006698', key: colorsArray.length });
let tempColorsArray = colorsArray;
tempColorsArray.push('#006698');
onChangeColor(getColorsString(tempColorsArray), URL_UPDATE_PUSH);
};
return (
<>
<div className="color-row">
<p>Colors Palette</p>{' '}
<a
href="#add"
onClick={() => addColor()}
className="iconButton fa fa-lg fa-plus"
>
{' '}
</a>
</div>
<div className="color-input">
{colorsArray.map((color, key) => (
<Fragment key={color + key}>
<div
className="color-input-item"
style={
itemColorStatus && itemColorStatus.key === key
? { background: color, borderColor: 'black' }
: { background: color }
}
>
<div
className="color-input-item-close"
onClick={e => deleteColor(key, colorsArray, onChangeColor)}
>
<CloseSVG />
</div>
<div
className="color-input-item-overlay"
onClick={e => setItemColorStatus({ color, key })}
></div>
</div>
</Fragment>
))}
</div>
{itemColorStatus ? (
<div style={popover}>
<div
style={cover}
onClick={() => {
setItemColorStatus(false);
}}
/>
<ChromePicker
color={itemColorStatus.color}
onChange={changeItemColor}
/>
</div>
) : null}
</>
);
}
Example #2
Source File: colors-input.js From raster-playground with GNU General Public License v3.0 | 5 votes |
deleteColor = (key, colorsArray, onChangeColor) => {
let tempColorsArray = colorsArray;
if (key > -1) {
tempColorsArray.splice(key, 1);
onChangeColor(getColorsString(tempColorsArray), URL_UPDATE_PUSH);
}
}