diff --git a/libs/ui-toolkit/src/components/slider/leverage-slider.stories.tsx b/libs/ui-toolkit/src/components/slider/leverage-slider.stories.tsx new file mode 100644 index 000000000..198658214 --- /dev/null +++ b/libs/ui-toolkit/src/components/slider/leverage-slider.stories.tsx @@ -0,0 +1,36 @@ +import type { Story, Meta } from '@storybook/react'; +import { LeverageSlider } from './leverage-slider'; +import { useState } from 'react'; + +export default { + component: LeverageSlider, + title: 'LeverageSlider', +} as Meta; + +const Template: Story = ({ value: val, min, max, ...args }) => { + const [value, setValue] = useState(val); + + const onValueChange = (val: [number]) => { + setValue(val); + }; + + return ( + <> + +
{value}
+ + ); +}; + +export const Default = Template.bind({}); + +Default.args = { + max: 100, + step: 0.1, + value: [100], +}; diff --git a/libs/ui-toolkit/src/components/slider/leverage-slider.tsx b/libs/ui-toolkit/src/components/slider/leverage-slider.tsx new file mode 100644 index 000000000..91ec29747 --- /dev/null +++ b/libs/ui-toolkit/src/components/slider/leverage-slider.tsx @@ -0,0 +1,58 @@ +import * as SliderPrimitive from '@radix-ui/react-slider'; +import type { SliderProps } from '@radix-ui/react-slider'; +import classNames from 'classnames'; + +export const LeverageSlider = ( + props: Omit & Required> +) => { + const step = [2, 5, 10, 20, 25].find((step) => props.max / step <= 6); + const min = 1; + const value = props.value?.[0] || props.defaultValue?.[0]; + return ( + + + + + {step && + new Array(Math.floor(props.max / step) + 1) + .fill(null) + .map((v, i) => { + const labelValue = step * i || 1; + const higherThanValue = value && labelValue > value; + return ( + + + {labelValue}x + + ); + })} + + + + + + + + ); +};