--- order: 2 title: zh-CN: 带 icon 的滑块 en-US: Slider with icon --- ## zh-CN 滑块左右可以设置图标来表达业务含义。 ## en-US You can add an icon beside the slider to make it meaningful. ```tsx import { FrownOutlined, SmileOutlined } from '@ant-design/icons'; import { Slider } from 'antd'; import React, { useState } from 'react'; interface IconSliderProps { max: number; min: number; } const IconSlider: React.FC = props => { const { max, min } = props; const [value, setValue] = useState(0); const mid = Number(((max - min) / 2).toFixed(5)); const preColorCls = value >= mid ? '' : 'icon-wrapper-active'; const nextColorCls = value >= mid ? 'icon-wrapper-active' : ''; return (
); }; const App: React.FC = () => ; export default App; ``` ```css .icon-wrapper { position: relative; padding: 0px 30px; } .icon-wrapper .anticon { position: absolute; top: -2px; width: 16px; height: 16px; color: rgba(0, 0, 0, 0.25); font-size: 16px; line-height: 1; } .icon-wrapper .icon-wrapper-active { color: rgba(0, 0, 0, 0.45); } .icon-wrapper .anticon:first-child { left: 0; } .icon-wrapper .anticon:last-child { right: 0; } ```