|
|
@@ -1,6 +1,7 @@
|
|
|
import React, { FunctionComponent } from 'react';
|
|
|
import { find, upperFirst } from 'lodash';
|
|
|
-import { Color, ColorsPalete, ColorDefinition } from '../../utils/colorsPalette';
|
|
|
+import { Color, ColorsPalete, ColorDefinition, getColorForTheme } from '../../utils/colorsPalette';
|
|
|
+import { Themeable } from '../../types';
|
|
|
|
|
|
type ColorChangeHandler = (color: ColorDefinition) => void;
|
|
|
|
|
|
@@ -10,13 +11,15 @@ enum ColorSwatchVariant {
|
|
|
}
|
|
|
|
|
|
interface ColorSwatchProps extends React.DOMAttributes<HTMLDivElement> {
|
|
|
- color: ColorDefinition;
|
|
|
+ color: string;
|
|
|
+ label?: string;
|
|
|
variant?: ColorSwatchVariant;
|
|
|
isSelected?: boolean;
|
|
|
}
|
|
|
|
|
|
const ColorSwatch: FunctionComponent<ColorSwatchProps> = ({
|
|
|
color,
|
|
|
+ label,
|
|
|
variant = ColorSwatchVariant.Small,
|
|
|
isSelected,
|
|
|
...otherProps
|
|
|
@@ -27,10 +30,10 @@ const ColorSwatch: FunctionComponent<ColorSwatchProps> = ({
|
|
|
width: swatchSize,
|
|
|
height: swatchSize,
|
|
|
borderRadius: '50%',
|
|
|
- background: `${color.variants.dark}`,
|
|
|
+ background: `${color}`,
|
|
|
marginRight: isSmall ? '0px' : '8px',
|
|
|
- boxShadow: isSelected ? `inset 0 0 0 2px ${color.variants.dark}, inset 0 0 0 4px white` : 'none',
|
|
|
- cursor: isSelected ? 'default' : 'pointer'
|
|
|
+ boxShadow: isSelected ? `inset 0 0 0 2px ${color}, inset 0 0 0 4px white` : 'none',
|
|
|
+ cursor: isSelected ? 'default' : 'pointer',
|
|
|
};
|
|
|
|
|
|
return (
|
|
|
@@ -42,32 +45,35 @@ const ColorSwatch: FunctionComponent<ColorSwatchProps> = ({
|
|
|
{...otherProps}
|
|
|
>
|
|
|
<div style={swatchStyles} />
|
|
|
- {variant === ColorSwatchVariant.Large && <span>{upperFirst(color.hue)}</span>}
|
|
|
+ {variant === ColorSwatchVariant.Large && <span>{label}</span>}
|
|
|
</div>
|
|
|
);
|
|
|
};
|
|
|
|
|
|
-interface ColorsGroupProps {
|
|
|
+interface ColorsGroupProps extends Themeable {
|
|
|
colors: ColorDefinition[];
|
|
|
selectedColor?: Color;
|
|
|
onColorSelect: ColorChangeHandler;
|
|
|
key?: string;
|
|
|
}
|
|
|
+
|
|
|
const ColorsGroup: FunctionComponent<ColorsGroupProps> = ({
|
|
|
colors,
|
|
|
selectedColor,
|
|
|
onColorSelect,
|
|
|
+ theme,
|
|
|
...otherProps
|
|
|
}) => {
|
|
|
const primaryColor = find(colors, color => !!color.isPrimary);
|
|
|
|
|
|
return (
|
|
|
- <div {...otherProps} style={{ display: 'flex', flexDirection: 'column' }}>
|
|
|
+ <div {...otherProps} style={{ display: 'flex', flexDirection: 'column' }}>
|
|
|
{primaryColor && (
|
|
|
<ColorSwatch
|
|
|
isSelected={primaryColor.name === selectedColor}
|
|
|
variant={ColorSwatchVariant.Large}
|
|
|
- color={primaryColor}
|
|
|
+ color={getColorForTheme(primaryColor, theme)}
|
|
|
+ label={upperFirst(primaryColor.hue)}
|
|
|
onClick={() => onColorSelect(primaryColor)}
|
|
|
/>
|
|
|
)}
|
|
|
@@ -77,30 +83,39 @@ const ColorsGroup: FunctionComponent<ColorsGroupProps> = ({
|
|
|
marginTop: '8px',
|
|
|
}}
|
|
|
>
|
|
|
- {colors.map(color => !color.isPrimary && (
|
|
|
- <div key={color.name} style={{ marginRight: '4px' }}>
|
|
|
- <ColorSwatch
|
|
|
- isSelected={color.name === selectedColor}
|
|
|
- color={color}
|
|
|
- onClick={() => onColorSelect(color)}
|
|
|
- />
|
|
|
- </div>
|
|
|
- ))}
|
|
|
+ {colors.map(
|
|
|
+ color =>
|
|
|
+ !color.isPrimary && (
|
|
|
+ <div key={color.name} style={{ marginRight: '4px' }}>
|
|
|
+ <ColorSwatch
|
|
|
+ isSelected={color.name === selectedColor}
|
|
|
+ color={getColorForTheme(color, theme)}
|
|
|
+ onClick={() => onColorSelect(color)}
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+ )
|
|
|
+ )}
|
|
|
</div>
|
|
|
</div>
|
|
|
);
|
|
|
};
|
|
|
|
|
|
-interface NamedColorsPickerProps {
|
|
|
- selectedColor?: Color;
|
|
|
- onChange: ColorChangeHandler;
|
|
|
+interface NamedColorsPickerProps extends Themeable {
|
|
|
+ color?: Color;
|
|
|
+ onChange: (colorName: string) => void;
|
|
|
}
|
|
|
-const NamedColorsPicker = ({ selectedColor, onChange }: NamedColorsPickerProps) => {
|
|
|
- const swatches: JSX.Element[] = [];
|
|
|
|
|
|
+const NamedColorsPicker = ({ color, onChange, theme }: NamedColorsPickerProps) => {
|
|
|
+ const swatches: JSX.Element[] = [];
|
|
|
ColorsPalete.forEach((colors, hue) => {
|
|
|
swatches.push(
|
|
|
- <ColorsGroup key={hue} selectedColor={selectedColor} colors={colors} onColorSelect={onChange} />
|
|
|
+ <ColorsGroup
|
|
|
+ key={hue}
|
|
|
+ theme={theme}
|
|
|
+ selectedColor={color}
|
|
|
+ colors={colors}
|
|
|
+ onColorSelect={color => onChange(color.name)}
|
|
|
+ />
|
|
|
);
|
|
|
});
|
|
|
|