mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-21 15:09:10 +00:00
refactor: swatch picker and inline colour picker
This commit is contained in:
committed by
Carlos Valente
parent
1ba48c6a6f
commit
dbd56522f6
@@ -92,4 +92,4 @@
|
|||||||
"vite-tsconfig-paths": "^4.3.1",
|
"vite-tsconfig-paths": "^4.3.1",
|
||||||
"vitest": "catalog:"
|
"vitest": "catalog:"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ interface SwatchPickerProps {
|
|||||||
color: string;
|
color: string;
|
||||||
isSelected?: boolean;
|
isSelected?: boolean;
|
||||||
onChange: (name: string) => void;
|
onChange: (name: string) => void;
|
||||||
|
alwaysDisplayColor?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const getIconColor = (color: string, isSelected: boolean) => {
|
const getIconColor = (color: string, isSelected: boolean) => {
|
||||||
@@ -28,11 +29,11 @@ const getIconColor = (color: string, isSelected: boolean) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default function SwatchPicker(props: SwatchPickerProps) {
|
export default function SwatchPicker(props: SwatchPickerProps) {
|
||||||
const { color, onChange, isSelected } = props;
|
const { color, onChange, isSelected, alwaysDisplayColor } = props;
|
||||||
|
|
||||||
const classes = cx([style.swatch, isSelected ? style.selected : null, style.selectable]);
|
const classes = cx([style.swatch, isSelected ? style.selected : null, style.selectable]);
|
||||||
|
|
||||||
const iconColor = getIconColor(color, isSelected ?? false);
|
const iconColor = getIconColor(color, (alwaysDisplayColor || isSelected) ?? false);
|
||||||
|
|
||||||
const debouncedOnChange = useCallback(
|
const debouncedOnChange = useCallback(
|
||||||
debounce((newValue: string) => {
|
debounce((newValue: string) => {
|
||||||
@@ -41,10 +42,12 @@ export default function SwatchPicker(props: SwatchPickerProps) {
|
|||||||
[onChange],
|
[onChange],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const displayColor = alwaysDisplayColor || isSelected ? color : '';
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={classes}>
|
<div className={classes}>
|
||||||
<PopoverPicker
|
<PopoverPicker
|
||||||
color={isSelected ? color : ''}
|
color={displayColor}
|
||||||
onChange={debouncedOnChange}
|
onChange={debouncedOnChange}
|
||||||
icon={<IoEyedrop color={iconColor} />}
|
icon={<IoEyedrop color={iconColor} />}
|
||||||
hasInput
|
hasInput
|
||||||
|
|||||||
@@ -22,7 +22,8 @@ export default function InlineColourPicker(props: InlineColourPickerProps) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={style.inline}>
|
<div className={style.inline}>
|
||||||
<SwatchPicker color={colour} onChange={setColour} />
|
<SwatchPicker color={colour} onChange={setColour} alwaysDisplayColor />
|
||||||
|
<span>{colour}</span>
|
||||||
<input type='hidden' name={name} value={colour} />
|
<input type='hidden' name={name} value={colour} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user