Skip to content

Commit

Permalink
refactor: swatch picker and inline colour picker
Browse files Browse the repository at this point in the history
  • Loading branch information
Shobhit-Nagpal authored and cpvalente committed Jan 2, 2025
1 parent 1ba48c6 commit dbd5652
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion apps/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,4 @@
"vite-tsconfig-paths": "^4.3.1",
"vitest": "catalog:"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ interface SwatchPickerProps {
color: string;
isSelected?: boolean;
onChange: (name: string) => void;
alwaysDisplayColor?: boolean;
}

const getIconColor = (color: string, isSelected: boolean) => {
Expand All @@ -28,11 +29,11 @@ const getIconColor = (color: string, isSelected: boolean) => {
};

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 iconColor = getIconColor(color, isSelected ?? false);
const iconColor = getIconColor(color, (alwaysDisplayColor || isSelected) ?? false);

const debouncedOnChange = useCallback(
debounce((newValue: string) => {
Expand All @@ -41,10 +42,12 @@ export default function SwatchPicker(props: SwatchPickerProps) {
[onChange],
);

const displayColor = alwaysDisplayColor || isSelected ? color : '';

return (
<div className={classes}>
<PopoverPicker
color={isSelected ? color : ''}
color={displayColor}
onChange={debouncedOnChange}
icon={<IoEyedrop color={iconColor} />}
hasInput
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ export default function InlineColourPicker(props: InlineColourPickerProps) {

return (
<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} />
</div>
);
Expand Down

0 comments on commit dbd5652

Please sign in to comment.