UNPKG

cjd-parkball

Version:

> 中后台业务组件库,中后台就像公园,进入需要买门票(登录),所以以 Parkball(公园球) 命名,公园内必定捕获!作为一个组件库,提供使用方法文档,方便开发者的调用

70 lines (56 loc) 1.33 kB
--- category: 2 title: 带 icon 的滑块 title_en: Slider with icon --- zh-CN 滑块左右可以设置图标来表达业务含义。 en-US You can add an icon beside the slider to make it meaningful. ````jsx import { Slider, Icon } from 'parkball'; class IconSlider extends React.Component { state = { value: 0, } handleChange = (value) => { this.setState({ value }); } render() { const { max, min } = this.props; const { value } = this.state; const mid = ((max - min) / 2).toFixed(5); const preColor = value >= mid ? '' : 'rgba(0, 0, 0, .45)'; const nextColor = value >= mid ? 'rgba(0, 0, 0, .45)' : ''; return ( <div className="icon-wrapper"> <Icon style={{ color: preColor }} type="frown-o" /> <Slider {...this.props} onChange={this.handleChange} value={value} /> <Icon style={{ color: nextColor }} type="smile-o" /> </div> ); } } ReactDOM.render(<IconSlider min={0} max={20} />, mountNode); ```` ````css .icon-wrapper { position: relative; padding: 0px 30px; } .icon-wrapper .anticon { position: absolute; top: -2px; width: 16px; height: 16px; line-height: 1; font-size: 16px; color: rgba(0, 0, 0, .25); } .icon-wrapper .anticon:first-child { left: 0; } .icon-wrapper .anticon:last-child { right: 0; } ````