feat(widgets/toggle): disable if going too fast

This commit is contained in:
Elian Doran 2025-12-10 20:32:58 +02:00
parent 483327c808
commit 36b1182565
No known key found for this signature in database

View File

@ -133,18 +133,25 @@ export function FormListItem({ className, icon, value, title, active, disabled,
);
}
export function FormListToggleableItem({ title, currentValue, onChange, ...props }: Omit<FormListItemOpts, "onClick" | "children"> & {
export function FormListToggleableItem({ title, currentValue, onChange, disabled, ...props }: Omit<FormListItemOpts, "onClick" | "children"> & {
title: string;
currentValue: boolean;
onChange(newValue: boolean): void;
onChange(newValue: boolean): void | Promise<void>;
}) {
const isWaiting = useRef(false);
return (
<FormListItem {...props} onClick={(e) => {
e.stopPropagation();
if (!props.disabled) {
onChange(!currentValue);
}
}}>
<FormListItem
{...props}
disabled={disabled}
onClick={async (e) => {
e.stopPropagation();
if (!disabled && !isWaiting.current) {
isWaiting.current = true;
await onChange(!currentValue);
isWaiting.current = false;
}
}}>
<FormToggle
switchOnName={title}
switchOffName={title}