bigbuffet-rw/app/soapbox/features/theme-editor/components/palette.tsx

42 lines
853 B
TypeScript
Raw Normal View History

2022-10-25 14:56:25 -07:00
import React from 'react';
import compareId from 'soapbox/compare_id';
import { HStack } from 'soapbox/components/ui';
import Color from './color';
2022-10-25 14:56:25 -07:00
interface ColorGroup {
[tint: string]: string,
}
interface IPalette {
palette: ColorGroup,
onChange: (palette: ColorGroup) => void,
2022-10-25 14:56:25 -07:00
}
/** Editable color palette. */
const Palette: React.FC<IPalette> = ({ palette, onChange }) => {
2022-10-25 14:56:25 -07:00
const tints = Object.keys(palette).sort(compareId);
const handleChange = (tint: string) => {
return (color: string) => {
onChange({
...palette,
[tint]: color,
});
};
};
2022-10-25 14:56:25 -07:00
return (
<HStack className='w-full h-8 rounded-md overflow-hidden'>
{tints.map(tint => (
<Color color={palette[tint]} onChange={handleChange(tint)} />
))}
2022-10-25 14:56:25 -07:00
</HStack>
);
};
export {
Palette as default,
ColorGroup,
};