/*
* Copyright (C) 2026 Fluxer Contributors
*
* This file is part of Fluxer.
*
* Fluxer is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Fluxer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Fluxer. If not, see .
*/
import {clsx} from 'clsx';
import React from 'react';
import {MenuItem as AriaMenuItem} from 'react-aria-components';
import {Slider} from '../Slider';
import styles from './MenuItem.module.css';
interface MenuItemSliderProps {
label: string;
value: number;
minValue?: number;
maxValue?: number;
disabled?: boolean;
onChange?: (value: number) => void;
onFormat?: (value: number) => string;
}
export const MenuItemSlider = React.forwardRef(
({label, value, minValue = 0, maxValue = 100, disabled = false, onChange, onFormat}, forwardedRef) => {
const [localValue, setLocalValue] = React.useState(value);
React.useEffect(() => {
setLocalValue(value);
}, [value]);
const formattedValue = onFormat ? onFormat(localValue) : `${Math.round(localValue)}%`;
const handleValueChange = React.useCallback(
(newValue: number) => {
setLocalValue(newValue);
onChange?.(newValue);
},
[onChange],
);
const handleValueCommit = React.useCallback(
(newValue: number) => {
onChange?.(newValue);
},
[onChange],
);
const handleSliderInteraction = React.useCallback((e: React.SyntheticEvent) => {
e.stopPropagation();
e.preventDefault();
}, []);
return (
{/* biome-ignore lint/a11y/noStaticElementInteractions: interactive slider element */}