refactor: event editor color picker (#1400)

* refactor: event editor color picker

* refactor: throttle and debounce function signature
This commit is contained in:
Shobhit Nagpal
2024-12-27 15:27:48 +05:30
committed by GitHub
parent 7f39d035fd
commit 6bbf8ce795
8 changed files with 111 additions and 14 deletions
@@ -1,4 +1,5 @@
import { HexAlphaColorPicker } from 'react-colorful';
import { ReactNode } from 'react';
import { HexAlphaColorPicker, HexColorInput } from 'react-colorful';
import { useController, UseControllerProps } from 'react-hook-form';
import { Popover, PopoverContent, PopoverTrigger } from '@chakra-ui/react';
import { ViewSettings } from 'ontime-types';
@@ -16,19 +17,24 @@ export function PopoverPickerRHF(props: UseControllerProps<ViewSettings>) {
interface PopoverPickerProps {
color: string;
icon?: ReactNode;
hasInput?: boolean;
onChange: (color: string) => void;
}
export default function PopoverPicker(props: PopoverPickerProps) {
const { color, onChange } = props;
const { color, icon, hasInput, onChange } = props;
return (
<Popover>
<PopoverTrigger>
<div className={style.swatch} style={{ backgroundColor: color }} />
<div className={style.swatch} style={{ backgroundColor: color }}>
{icon ?? null}
</div>
</PopoverTrigger>
<PopoverContent style={{ width: 'auto' }}>
<HexAlphaColorPicker color={color} onChange={onChange} />
{hasInput && <HexColorInput color={color} onChange={onChange} className={style.input} prefixed />}
</PopoverContent>
</Popover>
);