Skip to content

Commit

Permalink
Make onValueChanged optional and add marks and valueLabelDisplay prop…
Browse files Browse the repository at this point in the history
…s to SliderInput

Signed-off-by: Ayoub LABIDI <[email protected]>
  • Loading branch information
ayolab committed Feb 10, 2025
1 parent 9266b59 commit e422a3b
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions src/components/inputs/reactHookForm/numbers/SliderInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,19 @@ import { identity } from '../utils/functions';

export interface SliderInputProps extends SliderProps {
name: string;
onValueChanged: (value: number | number[]) => void;
onValueChanged?: (value: number | number[]) => void;
}

export function SliderInput({ name, min, max, step, size = 'small', onValueChanged = identity }: SliderInputProps) {
export function SliderInput({
name,
min,
max,
step,
size = 'small',
marks,
valueLabelDisplay,
onValueChanged = identity,
}: SliderInputProps) {
const {
field: { onChange, value },
} = useController({ name });
Expand All @@ -25,9 +34,20 @@ export function SliderInput({ name, min, max, step, size = 'small', onValueChang
// eslint-disable-next-line @typescript-eslint/no-unused-vars
activeThumb: number
) => {
onValueChanged(newValue);
onValueChanged?.(newValue);
onChange(newValue);
};

return <Slider size={size} min={min} max={max} step={step} value={value} onChange={handleValueChange} />;
return (
<Slider
size={size}
min={min}
max={max}
step={step}
value={value}
onChange={handleValueChange}
marks={marks}
valueLabelDisplay={valueLabelDisplay}
/>
);
}

0 comments on commit e422a3b

Please sign in to comment.