Created new component "ZapSplitSlider"

This commit is contained in:
danidfra 2024-09-19 01:12:15 -03:00
parent 218a32821a
commit 3e36cc8078
1 changed files with 35 additions and 0 deletions

View File

@ -0,0 +1,35 @@
import clsx from 'clsx';
import React, { useState } from 'react';
import { Slider } from 'soapbox/components/ui';
const formattedWeight = (weight: number) =>{
return Number((weight * 100).toFixed());
};
interface IZapSplitSlider {
width?: string;
initialWeight: number;
onWeightChange: (newWeight: number) => void;
}
export const ZapSplitSlider: React.FC<IZapSplitSlider> = ({ initialWeight, onWeightChange, width = 'w-40' }) => {
const [value, setValue] = useState(initialWeight / 100);
const handleChange = (newValue: number) => {
setValue(newValue);
onWeightChange(Number((newValue * 100).toFixed()));
};
return (
<div className={clsx('flex flex-col', width)}>
{formattedWeight(value)}%
<Slider
value={value}
onChange={(v) => {
handleChange(v);
}}
/>
</div>
);
};