|
| 1 | +import { Meta, Story } from '@storybook/react/types-6-0'; |
| 2 | +import React, { useState } from 'react'; |
| 3 | +import { Box } from 'rebass'; |
| 4 | +import RangeSlider, { Props } from './range-slider'; |
| 5 | +import Value from '../typography/value'; |
| 6 | +import Divider from '../divider'; |
| 7 | +import Labeling from '../typography/labeling'; |
| 8 | + |
| 9 | +export default { |
| 10 | + title: 'Quartz/RangeSlider', |
| 11 | + component: RangeSlider, |
| 12 | +} as Meta; |
| 13 | + |
| 14 | +export const DefaultSlider: Story<Pick<Props, 'label' | 'step' | 'range'>> = ( |
| 15 | + props, |
| 16 | +) => { |
| 17 | + const [value, setValue] = useState([2, 4]); |
| 18 | + |
| 19 | + return ( |
| 20 | + <Box width="700px"> |
| 21 | + <RangeSlider value={value} onChange={setValue} {...props} /> |
| 22 | + <Divider /> |
| 23 | + <Labeling>Current value:</Labeling> |
| 24 | + <Value>[{value.join(', ')}]</Value> |
| 25 | + </Box> |
| 26 | + ); |
| 27 | +}; |
| 28 | + |
| 29 | +DefaultSlider.args = { |
| 30 | + label: 'CPU cores', |
| 31 | + step: 1, |
| 32 | + range: [0, 10], |
| 33 | +}; |
| 34 | + |
| 35 | +export const WithCustomDisplayValue: Story< |
| 36 | + Pick<Props, 'label' | 'step' | 'range' | 'formatDisplayValue'> |
| 37 | +> = (props) => { |
| 38 | + const [value, setValue] = useState([128, 256]); |
| 39 | + |
| 40 | + return ( |
| 41 | + <Box width="700px"> |
| 42 | + <RangeSlider value={value} onChange={setValue} {...props} /> |
| 43 | + <Divider /> |
| 44 | + <Labeling>Current value:</Labeling> |
| 45 | + <Value>[{value.join(', ')}]</Value> |
| 46 | + </Box> |
| 47 | + ); |
| 48 | +}; |
| 49 | + |
| 50 | +WithCustomDisplayValue.args = { |
| 51 | + label: 'RAM', |
| 52 | + step: 128, |
| 53 | + range: [0, 1024], |
| 54 | + formatDisplayValue: (value) => `${value} MB`, |
| 55 | +}; |
0 commit comments