2021-11-21 10:49:18 +00:00
|
|
|
import { Meta, Story } from '@storybook/react';
|
|
|
|
import { useEffect, useState } from 'react';
|
|
|
|
|
|
|
|
import { Slider, Props } from './Slider';
|
|
|
|
|
|
|
|
export default {
|
|
|
|
component: Slider,
|
|
|
|
title: 'Components/Form/Slider',
|
|
|
|
} as Meta;
|
|
|
|
|
2022-11-04 01:12:53 +00:00
|
|
|
function Template({
|
|
|
|
value,
|
|
|
|
min,
|
|
|
|
max,
|
|
|
|
step,
|
|
|
|
dataCy,
|
|
|
|
visibleTooltip,
|
|
|
|
}: JSX.IntrinsicAttributes & Props) {
|
2021-11-21 10:49:18 +00:00
|
|
|
const [sliderValue, setSliderValue] = useState(min);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
setSliderValue(value);
|
|
|
|
}, [value]);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Slider
|
|
|
|
min={min}
|
|
|
|
max={max}
|
|
|
|
step={step}
|
|
|
|
value={sliderValue}
|
2023-04-21 04:52:05 +00:00
|
|
|
onChange={(value) => {
|
|
|
|
if (Array.isArray(value)) {
|
|
|
|
setSliderValue(value[0]);
|
|
|
|
} else {
|
|
|
|
setSliderValue(value);
|
|
|
|
}
|
|
|
|
}}
|
2022-11-04 01:12:53 +00:00
|
|
|
dataCy={dataCy}
|
|
|
|
visibleTooltip={visibleTooltip}
|
2021-11-21 10:49:18 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export const Primary: Story<Props> = Template.bind({});
|
|
|
|
Primary.args = {
|
|
|
|
min: 0,
|
|
|
|
max: 100,
|
|
|
|
step: 1,
|
|
|
|
value: 5,
|
2022-11-04 01:12:53 +00:00
|
|
|
visibleTooltip: true,
|
|
|
|
dataCy: 'someView-coolSlider',
|
2021-11-21 10:49:18 +00:00
|
|
|
};
|