ant-design/components/slider/demo/icon-slider.md

85 lines
1.6 KiB
Markdown
Raw Normal View History

2016-03-31 09:40:55 +08:00
---
order: 2
2016-09-22 10:09:22 +08:00
title:
zh-CN: 带 icon 的滑块
en-US: Slider with icon
2016-03-31 09:40:55 +08:00
---
2015-07-14 12:06:44 +08:00
## zh-CN
2015-07-16 16:48:06 +08:00
滑块左右可以设置图标来表达业务含义。
## en-US
You can add an icon beside the slider to make it meaningful.
```tsx
import React, { useState } from 'react';
use ant design icons 4.0 (#18217) * feat: use @ant-design/icons@4.0 * feat: use createFromIconfontCN to make site works * feat: update doc for Icon * feat: use icon in component Alert * feat: use icon in component Avatar * feat: use icon in component Breadcrumb * feat: use icon in component Button * feat: use icon in component Cascader * feat: use icon in component Collapse * feat: use icon in component Datepicker * feat: use icon in component Dropdown * feat: use icon in component Form * feat: use icon in component Input * feat: use icon in component InputNumber * feat: use icon in component Layout * feat: use icon in component Mention * feat: use icon in component Message * feat: use icon in component Modal * feat: use icon in component Notification * feat: use icon in component PageHeader * feat: use icon in component Pagination * feat: use icon in component Popconfirm * feat: use icon in component Progress * feat: use icon in component Rate * feat: use icon in component Result * feat: use icon in component Select * feat: use icon in component Step * feat: use icon in component Switch * feat: use icon in component Table * feat: use icon in component Tab * feat: use icon in component Tag * feat: handle rest component which using Icon * fix: remove unused vars * feat: use latest alpha ant design icons * fix: failed test in uploadlist.test.js * test: update snapshot for icons * doc: add Icon for site * doc: use @ant-design/icons in site * chore: use latest icons * fix: tslint issue * fix: test cases * fix: types for react * fix: lint rules for import orders * fix: use @ant-design/icons@4.0.0-alpha.5 to avoid insert css in server render * fix: eslint error in demo/**.md * inject antd icons * update snapshot * fix site * doc: update docs * fix: code snippets icon in site * feat: use latest @ant-design/icons * fix: icon props in message
2019-08-13 14:07:17 +08:00
import { Slider } from 'antd';
import { FrownOutlined, SmileOutlined } from '@ant-design/icons';
2015-07-14 12:06:44 +08:00
interface IconSliderProps {
max: number;
min: number;
}
2015-07-14 12:06:44 +08:00
const IconSlider: React.FC<IconSliderProps> = 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 (
<div className="icon-wrapper">
<FrownOutlined className={preColorCls} />
<Slider {...props} onChange={setValue} value={value} />
<SmileOutlined className={nextColorCls} />
</div>
);
};
const App: React.FC = () => <IconSlider min={0} max={20} />;
export default App;
2019-05-07 14:57:32 +08:00
```
2015-07-14 12:06:44 +08:00
2019-05-07 14:57:32 +08:00
```css
2016-11-21 16:37:04 +08:00
.icon-wrapper {
2015-07-14 12:06:44 +08:00
position: relative;
2015-11-14 14:09:08 +08:00
padding: 0px 30px;
2015-07-14 12:06:44 +08:00
}
2016-11-21 16:37:04 +08:00
.icon-wrapper .anticon {
2015-07-14 12:06:44 +08:00
position: absolute;
top: -2px;
2015-07-14 12:06:44 +08:00
width: 16px;
height: 16px;
2019-05-07 14:57:32 +08:00
color: rgba(0, 0, 0, 0.25);
font-size: 16px;
line-height: 1;
2015-07-14 12:06:44 +08:00
}
.icon-wrapper .icon-wrapper-active {
2020-02-19 13:20:43 +08:00
color: rgba(0, 0, 0, 0.45);
}
2016-11-21 16:37:04 +08:00
.icon-wrapper .anticon:first-child {
2015-07-14 12:06:44 +08:00
left: 0;
}
2016-04-07 12:04:06 +08:00
2016-11-21 16:37:04 +08:00
.icon-wrapper .anticon:last-child {
2015-07-14 12:06:44 +08:00
right: 0;
}
2019-05-07 14:57:32 +08:00
```
<style>
[data-theme="dark"] .icon-wrapper .anticon {
color: rgba(255, 255, 255, 0.25);
}
[data-theme="dark"] .icon-wrapper .icon-wrapper-active {
color: rgba(255, 255, 255, .45);
}
</style>