mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-22 22:48:29 +08:00
05878dd300
* feat: slider support multiple & classNames * test: update snapshot * chore: fix lint
43 lines
940 B
TypeScript
43 lines
940 B
TypeScript
import React from 'react';
|
|
import { Slider } from 'antd';
|
|
|
|
function getGradientColor(percentage: number) {
|
|
const startColor = [135, 208, 104];
|
|
const endColor = [255, 204, 199];
|
|
|
|
const midColor = startColor.map((start, i) => {
|
|
const end = endColor[i];
|
|
const delta = end - start;
|
|
return (start + delta * percentage).toFixed(0);
|
|
});
|
|
|
|
return `rgb(${midColor.join(',')})`;
|
|
}
|
|
|
|
const App: React.FC = () => {
|
|
const [value, setValue] = React.useState([0, 10, 20]);
|
|
|
|
const start = value[0] / 100;
|
|
const end = value[value.length - 1] / 100;
|
|
|
|
return (
|
|
<Slider
|
|
range
|
|
defaultValue={value}
|
|
onChange={setValue}
|
|
styles={{
|
|
track: {
|
|
background: 'transparent',
|
|
},
|
|
tracks: {
|
|
background: `linear-gradient(to right, ${getGradientColor(start)} 0%, ${getGradientColor(
|
|
end,
|
|
)} 100%)`,
|
|
},
|
|
}}
|
|
/>
|
|
);
|
|
};
|
|
|
|
export default App;
|