Gathering detailed insights and metrics for @gem-mine/rc-slider
Gathering detailed insights and metrics for @gem-mine/rc-slider
Gathering detailed insights and metrics for @gem-mine/rc-slider
Gathering detailed insights and metrics for @gem-mine/rc-slider
npm install @gem-mine/rc-slider
Typescript
Module System
Min. Node Version
Node Version
NPM Version
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
3
32
基于 rc-slider 开发的 ui 组件:滚动条
IE 9+
1npm install @gem-mine/rc-slider --save
1# 默认开启服务器,地址为 :http://local:8000/ 2 3# 能在ie9+下浏览本站,修改代码后自动重新构建,且能在ie10+运行热更新,页面会自动刷新 4npm run start 5 6# 构建生产环境静态文件,用于发布文档 7npm run site
1.ant-input { 2 border: 1px solid red; 3}
1import '@gem-mine/rc-slider/lib/style/'; 2import 'rc-tooltip/assets/bootstrap.css'; 3import Tooltip from 'rc-tooltip'; 4import Slider from '@gem-mine/rc-slider'; 5 6const createSliderWithTooltip = Slider.createSliderWithTooltip; 7const Range = createSliderWithTooltip(Slider.Range); 8const Handle = Slider.Handle; 9 10const handle = (props) => { 11 const { value, dragging, index, ...restProps } = props; 12 return ( 13 <Tooltip 14 prefixCls="rc-slider-tooltip" 15 overlay={value} 16 visible={dragging} 17 placement="top" 18 key={index} 19 > 20 <Handle value={value} {...restProps} /> 21 </Tooltip> 22 ); 23}; 24 25const wrapperStyle = { width: 400, margin: 50 }; 26ReactDOM.render( 27 <div> 28 <div style={wrapperStyle}> 29 <p>Slider with custom handle</p> 30 <Slider min={0} max={20} defaultValue={3} handle={handle} /> 31 </div> 32 <div style={wrapperStyle}> 33 <p>Reversed Slider with custom handle</p> 34 <Slider min={0} max={20} reverse defaultValue={3} handle={handle} /> 35 </div> 36 <div style={wrapperStyle}> 37 <p>Slider with fixed values</p> 38 <Slider min={20} defaultValue={20} marks={{ 20: 20, 40: 40, 100: 100 }} step={null} /> 39 </div> 40 <div style={wrapperStyle}> 41 <p>Range with custom tooltip</p> 42 <Range min={0} max={20} defaultValue={[3, 10]} tipFormatter={value => `${value}%`} /> 43 </div> 44 </div>, 45 mountNode 46);
1import '@gem-mine/rc-slider/lib/style/'; 2import Slider from '@gem-mine/rc-slider'; 3 4const style = { width: 400, margin: 50 }; 5const marks = { 6 '-10': '-10°C', 7 0: <strong>0°C</strong>, 8 26: '26°C', 9 37: '37°C', 10 50: '50°C', 11 100: { 12 style: { 13 color: 'red', 14 }, 15 label: <strong>100°C</strong>, 16 }, 17}; 18 19function log(value) { 20 console.log(value); //eslint-disable-line 21} 22 23ReactDOM.render( 24 <div> 25 <div style={style}> 26 <p>Slider with marks, `step=null`</p> 27 <Slider min={-10} marks={marks} step={null} onChange={log} defaultValue={20} /> 28 </div> 29 <div style={style}> 30 <p>Slider with marks and steps</p> 31 <Slider dots min={-10} marks={marks} step={10} onChange={log} defaultValue={20} /> 32 </div> 33 34 <div style={style}> 35 <p>Slider with marks, `included=false`</p> 36 <Slider min={-10} marks={marks} included={false} defaultValue={20} /> 37 </div> 38 39 <div style={style}> 40 <p>Reversed Slider with marks and steps</p> 41 <Slider dots reverse min={-10} marks={marks} step={10} onChange={log} defaultValue={20} /> 42 </div> 43 44 <div style={style}> 45 <p>Slider with marks and steps, `included=false`</p> 46 <Slider min={-10} marks={marks} step={10} included={false} defaultValue={20} /> 47 </div> 48 49 <div style={style}> 50 <p>Range with marks</p> 51 <Slider.Range min={-10} marks={marks} onChange={log} defaultValue={[20, 25, 30, 40]} /> 52 </div> 53 <div style={style}> 54 <p>Range with marks and steps</p> 55 <Slider.Range min={-10} marks={marks} step={10} onChange={log} defaultValue={[20, 40]} /> 56 </div> 57 </div> 58 , mountNode);
1import '@gem-mine/rc-slider/lib/style/'; 2import Slider from '@gem-mine/rc-slider'; 3 4const Range = Slider.Range; 5 6const style = { width: 400, margin: 50 }; 7 8function log(value) { 9 console.log(value); //eslint-disable-line 10} 11 12class CustomizedRange extends React.Component { 13 constructor(props) { 14 super(props); 15 this.state = { 16 lowerBound: 20, 17 upperBound: 40, 18 value: [20, 40], 19 }; 20 } 21 onLowerBoundChange = (e) => { 22 this.setState({ lowerBound: +e.target.value }); 23 } 24 onUpperBoundChange = (e) => { 25 this.setState({ upperBound: +e.target.value }); 26 } 27 onSliderChange = (value) => { 28 log(value); 29 this.setState({ 30 value, 31 }); 32 } 33 handleApply = () => { 34 const { lowerBound, upperBound } = this.state; 35 this.setState({ value: [lowerBound, upperBound] }); 36 } 37 render() { 38 return ( 39 <div> 40 <label>LowerBound: </label> 41 <input type="number" value={this.state.lowerBound} onChange={this.onLowerBoundChange} /> 42 <br /> 43 <label>UpperBound: </label> 44 <input type="number" value={this.state.upperBound} onChange={this.onUpperBoundChange} /> 45 <br /> 46 <button onClick={this.handleApply}>Apply</button> 47 <br /><br /> 48 <Range allowCross={false} value={this.state.value} onChange={this.onSliderChange} /> 49 </div> 50 ); 51 } 52} 53 54class DynamicBounds extends React.Component { 55 constructor(props) { 56 super(props); 57 this.state = { 58 min: 0, 59 max: 100, 60 }; 61 } 62 onSliderChange = (value) => { 63 log(value); 64 } 65 onMinChange = (e) => { 66 this.setState({ 67 min: +e.target.value || 0, 68 }); 69 } 70 onMaxChange = (e) => { 71 this.setState({ 72 max: +e.target.value || 100, 73 }); 74 } 75 render() { 76 return ( 77 <div> 78 <label>Min: </label> 79 <input type="number" value={this.state.min} onChange={this.onMinChange} /> 80 <br /> 81 <label>Max: </label> 82 <input type="number" value={this.state.max} onChange={this.onMaxChange} /> 83 <br /><br /> 84 <Range defaultValue={[20, 50]} min={this.state.min} max={this.state.max} 85 onChange={this.onSliderChange} 86 /> 87 </div> 88 ); 89 } 90} 91 92class ControlledRange extends React.Component { 93 constructor(props) { 94 super(props); 95 this.state = { 96 value: [20, 40, 60, 80], 97 }; 98 } 99 handleChange = (value) => { 100 this.setState({ 101 value, 102 }); 103 } 104 render() { 105 return ( 106 <Range value={this.state.value} onChange={this.handleChange} /> 107 ); 108 } 109} 110 111class ControlledRangeDisableAcross extends React.Component { 112 constructor(props) { 113 super(props); 114 this.state = { 115 value: [20, 40, 60, 80], 116 }; 117 } 118 handleChange = (value) => { 119 this.setState({ 120 value, 121 }); 122 } 123 render() { 124 return ( 125 <Range 126 value={this.state.value} 127 onChange={this.handleChange} 128 allowCross={false} 129 {...this.props} 130 /> 131 ); 132 } 133} 134 135// https://github.com/react-component/slider/issues/226 136class PureRenderRange extends React.Component { 137 constructor(props) { 138 super(props); 139 this.state = { 140 foo: false, 141 }; 142 } 143 handleChange = (value) => { 144 console.log(value); 145 this.setState({ 146 foo: !this.state.foo, 147 }); 148 } 149 render() { 150 return ( 151 <Range defaultValue={[20, 40, 60, 80]} onChange={this.handleChange} allowCross={false} /> 152 ); 153 } 154} 155 156ReactDOM.render( 157 <div> 158 <div style={style}> 159 <p>Basic Range,`allowCross=false`</p> 160 <Range allowCross={false} defaultValue={[0, 20]} onChange={log} /> 161 </div> 162 <div style={style}> 163 <p>Basic reverse Range`</p> 164 <Range allowCross={false} defaultValue={[0, 20]} onChange={log} reverse /> 165 </div> 166 <div style={style}> 167 <p>Basic Range,`step=20` </p> 168 <Range step={20} defaultValue={[20, 20]} onBeforeChange={log} /> 169 </div> 170 <div style={style}> 171 <p>Basic Range,`step=20, dots` </p> 172 <Range dots step={20} defaultValue={[20, 40]} onAfterChange={log} /> 173 </div> 174 <div style={style}> 175 <p>Basic Range,disabled</p> 176 <Range allowCross={false} defaultValue={[0, 20]} onChange={log} disabled /> 177 </div> 178 <div style={style}> 179 <p>Controlled Range</p> 180 <ControlledRange /> 181 </div> 182 <div style={style}> 183 <p>Controlled Range, not allow across</p> 184 <ControlledRangeDisableAcross /> 185 </div> 186 <div style={style}> 187 <p>Controlled Range, not allow across, pushable=5</p> 188 <ControlledRangeDisableAcross pushable={5} /> 189 </div> 190 <div style={style}> 191 <p>Multi Range</p> 192 <Range count={3} defaultValue={[20, 40, 60, 80]} pushable /> 193 </div> 194 <div style={style}> 195 <p>Multi Range with custom track and handle style</p> 196 <Range count={3} defaultValue={[20, 40, 60, 80]} pushable 197 trackStyle={[{ backgroundColor: 'red' }, { backgroundColor: 'green' }]} 198 handleStyle={[{ backgroundColor: 'yellow' }, { backgroundColor: 'gray' }]} 199 railStyle={{ backgroundColor: 'black' }} 200 /> 201 </div> 202 <div style={style}> 203 <p>Customized Range</p> 204 <CustomizedRange /> 205 </div> 206 <div style={style}> 207 <p>Range with dynamic `max` `min`</p> 208 <DynamicBounds /> 209 </div> 210 <div style={style}> 211 <p>Range as child component</p> 212 <PureRenderRange /> 213 </div> 214 </div> 215 , mountNode);
1import '@gem-mine/rc-slider/lib/style/'; 2import Slider, { createSliderWithTooltip } from '@gem-mine/rc-slider'; 3 4const style = { width: 600, margin: 50 }; 5 6function log(value) { 7 console.log(value); //eslint-disable-line 8} 9 10 11function percentFormatter(v) { 12 return `${v} %`; 13} 14 15const SliderWithTooltip = createSliderWithTooltip(Slider); 16 17class NullableSlider extends React.Component { 18 constructor(props) { 19 super(props); 20 this.state = { 21 value: null, 22 }; 23 } 24 onSliderChange = (value) => { 25 log(value); 26 this.setState({ 27 value, 28 }); 29 }; 30 onAfterChange = (value) => { 31 console.log(value); //eslint-disable-line 32 }; 33 reset = () => { 34 console.log('reset value') // eslint-disable-line 35 this.setState({ value: null }); 36 }; 37 render() { 38 return ( 39 <div> 40 <Slider 41 value={this.state.value} 42 onChange={this.onSliderChange} 43 onAfterChange={this.onAfterChange} 44 /> 45 <button onClick={this.reset}>Reset</button> 46 </div> 47 ); 48 } 49} 50 51class CustomizedSlider extends React.Component { 52 constructor(props) { 53 super(props); 54 this.state = { 55 value: 50, 56 }; 57 } 58 onSliderChange = (value) => { 59 log(value); 60 this.setState({ 61 value, 62 }); 63 } 64 onAfterChange = (value) => { 65 console.log(value); //eslint-disable-line 66 } 67 render() { 68 return ( 69 <Slider value={this.state.value} 70 onChange={this.onSliderChange} onAfterChange={this.onAfterChange} 71 /> 72 ); 73 } 74} 75 76class DynamicBounds extends React.Component { 77 constructor(props) { 78 super(props); 79 this.state = { 80 min: 1, 81 max: 100, 82 step: 10, 83 value: 1, 84 }; 85 } 86 onSliderChange = (value) => { 87 log(value); 88 this.setState({value}); 89 } 90 onMinChange = (e) => { 91 this.setState({ 92 min: +e.target.value || 0, 93 }); 94 } 95 onMaxChange = (e) => { 96 this.setState({ 97 max: +e.target.value || 100, 98 }); 99 } 100 onStepChange = (e) => { 101 this.setState({ 102 step: +e.target.value || 1, 103 }); 104 } 105 render() { 106 const labelStyle = { minWidth: '60px', display: 'inline-block' }; 107 const inputStyle = { marginBottom: '10px'}; 108 return ( 109 <div> 110 <label style={labelStyle}>Min: </label> 111 <input type="number" value={this.state.min} onChange={this.onMinChange} style={inputStyle} /> 112 <br /> 113 <label style={labelStyle}>Max: </label> 114 <input type="number" value={this.state.max} onChange={this.onMaxChange} style={inputStyle} /> 115 <br /> 116 <label style={labelStyle}>Step: </label> 117 <input type="number" value={this.state.step} onChange={this.onStepChange} style={inputStyle} /> 118 <br /><br /> 119 <label style={labelStyle}>Value: </label><span>{this.state.value}</span> 120 <br /><br /> 121 <Slider value={this.state.value} min={this.state.min} max={this.state.max} step={this.state.step} 122 onChange={this.onSliderChange} 123 /> 124 </div> 125 ); 126 } 127} 128 129ReactDOM.render( 130 <div> 131 <div style={style}> 132 <p>Basic Slider</p> 133 <Slider onChange={log} /> 134 </div> 135 <div style={style}> 136 <p>Slider reverse</p> 137 <Slider onChange={log} reverse min={20} max={60}/> 138 </div> 139 <div style={style}> 140 <p>Basic Slider,`step=20`</p> 141 <Slider step={20} defaultValue={50} onBeforeChange={log} /> 142 </div> 143 <div style={style}> 144 <p>Basic Slider,`step=20, dots`</p> 145 <Slider dots step={20} defaultValue={100} onAfterChange={log} /> 146 </div> 147 <div style={style}> 148 <p>Basic Slider,`step=20, dots, dotStyle={"{borderColor: 'orange'}"}, activeDotStyle={"{borderColor: 'yellow'}"}`</p> 149 <Slider dots step={20} defaultValue={100} onAfterChange={log} dotStyle={{ borderColor: 'orange' }} activeDotStyle={{ borderColor: 'yellow' }} /> 150 </div> 151 <div style={style}> 152 <p>Slider with tooltip, with custom `tipFormatter`</p> 153 <SliderWithTooltip 154 tipFormatter={percentFormatter} 155 tipProps={{ overlayClassName: 'foo' }} 156 onChange={log} 157 /> 158 </div> 159 <div style={style}> 160 <p>Slider with custom handle and track style.<strong>(old api, will be deprecated)</strong></p> 161 <Slider 162 defaultValue={30} 163 railStyle={{ backgroundColor: 'red', height: 10 }} 164 trackStyle={{ backgroundColor: 'blue', height: 10 }} 165 handleStyle={{ 166 borderColor: 'blue', 167 height: 28, 168 width: 28, 169 marginLeft: -14, 170 marginTop: -9, 171 backgroundColor: 'black', 172 }} 173 /> 174 </div> 175 <div style={style}> 176 <p>Slider with custom handle and track style.<strong>(The recommended new api)</strong></p> 177 <Slider 178 defaultValue={30} 179 trackStyle={{ backgroundColor: 'blue', height: 10 }} 180 handleStyle={{ 181 borderColor: 'blue', 182 height: 28, 183 width: 28, 184 marginLeft: -14, 185 marginTop: -9, 186 backgroundColor: 'black', 187 }} 188 railStyle={{ backgroundColor: 'red', height: 10 }} 189 /> 190 </div> 191 <div style={style}> 192 <p>Basic Slider, disabled</p> 193 <Slider onChange={log} disabled /> 194 </div> 195 <div style={style}> 196 <p>Controlled Slider</p> 197 <Slider value={50} /> 198 </div> 199 <div style={style}> 200 <p>Customized Slider</p> 201 <CustomizedSlider /> 202 </div> 203 <div style={style}> 204 <p>Slider with null value and reset button</p> 205 <NullableSlider /> 206 </div> 207 <div style={style}> 208 <p>Slider with dynamic `min` `max` `step`</p> 209 <DynamicBounds /> 210 </div> 211 </div> 212 , mountNode); 213
1import '@gem-mine/rc-slider/lib/style/'; 2import Slider from '@gem-mine/rc-slider'; 3 4const style = { float: 'left', width: 160, height: 400, marginBottom: 160, marginLeft: 50 }; 5const parentStyle = { overflow: 'hidden' }; 6const pStyle = { marginBottom: 20 }; 7 8const marks = { 9 '-10': '-10°C', 10 0: <strong>0°C</strong>, 11 26: '26°C', 12 37: '37°C', 13 50: '50°C', 14 100: { 15 style: { 16 color: 'red', 17 }, 18 label: <strong>100°C</strong>, 19 }, 20}; 21 22function log(value) { 23 console.log(value); //eslint-disable-line 24} 25 26ReactDOM.render( 27 <div style={parentStyle}> 28 <div style={style}> 29 <p style={pStyle}>Slider with marks, `step=null`</p> 30 <Slider vertical min={-10} marks={marks} step={null} onChange={log} defaultValue={20} /> 31 </div> 32 <div style={style}> 33 <p>Reverse Slider with marks, `step=null`</p> 34 <Slider vertical min={-10} marks={marks} step={null} onChange={log} defaultValue={20} reverse /> 35 </div> 36 <div style={style}> 37 <p style={pStyle}>Slider with marks and steps</p> 38 <Slider vertical dots min={-10} marks={marks} step={10} onChange={log} defaultValue={20} /> 39 </div> 40 <div style={style}> 41 <p style={pStyle}>Slider with marks, `included=false`</p> 42 <Slider vertical min={-10} marks={marks} included={false} defaultValue={20} /> 43 </div> 44 <div style={style}> 45 <p style={pStyle}>Slider with marks and steps, `included=false`</p> 46 <Slider vertical min={-10} marks={marks} step={10} included={false} defaultValue={20} /> 47 </div> 48 <div style={style}> 49 <p style={pStyle}>Range with marks</p> 50 <Slider.Range vertical min={-10} marks={marks} onChange={log} defaultValue={[20, 40]} /> 51 </div> 52 <div style={style}> 53 <p style={pStyle}>Range with marks and steps</p> 54 <Slider.Range vertical min={-10} marks={marks} step={10} 55 onChange={log} defaultValue={[20, 40]} 56 /> 57 </div> 58 </div> 59 , mountNode);
An extension to make Slider or Range support Tooltip on handle.
const Slider = require('@gem-mine/rc-slider');
const createSliderWithTooltip = Slider.createSliderWithTooltip;
const Range = createSliderWithTooltip(Slider.Range);
After Range or Slider was wrapped by createSliderWithTooltip, it will have the following props:
Name | Type | Default | Description |
---|---|---|---|
tipFormatter | (value: number): React.ReactNode | value => value | A function to format tooltip's overlay |
tipProps | Object | { placement: 'top', prefixCls: 'rc-slider-tooltip', overlay: tipFormatter(value) } | A function to format tooltip's overlay |
The following APIs are shared by Slider and Range.
Name | Type | Default | Description |
---|---|---|---|
className | string | '' | Additional CSS class for the root DOM node |
min | number | 0 | The minimum value of the slider |
max | number | 100 | The maximum value of the slider |
marks | {number: string} or{number: { style, label }} | {} | Marks on the slider. The key determines the position, and the value determines what will show. If you want to set the style of a specific mark point, the value should be an object which contains style and label properties. |
step | number or null | 1 | Value to be added or subtracted on each step the slider makes. Must be greater than zero, and max - min should be evenly divisible by the step value. When marks is not an empty object, step can be set to null , to make marks as steps. |
vertical | boolean | false | If vertical is true , the slider will be vertical. |
handle | (props) => React.ReactNode | A handle generator which could be used to customized handle. | |
included | boolean | true | If the value is true , it means a continuous value interval, otherwise, it is a independent value. |
disabled | boolean | false | If true , handles can't be moved. |
dots | boolean | false | When the step value is greater than 1, you can set the dots to true if you want to render the slider with dots. |
onBeforeChange | Function | NOOP | onBeforeChange will be triggered when ontouchstart or onmousedown is triggered. |
onChange | Function | NOOP | onChange will be triggered while the value of Slider changing. |
onAfterChange | Function | NOOP | onAfterChange will be triggered when ontouchend or onmouseup is triggered. |
minimumTrackStyle | Object | please use trackStyle instead. (only used for slider, just for compatibility , will be deprecate at rc-slider@9.x ) | |
maximumTrackStyle | Object | please use railStyle instead (only used for slider, just for compatibility , will be deprecate at rc-slider@9.x ) | |
handleStyle | Array[Object] | Object | [{}] | The style used for handle. (both for slider( Object) and range( Array of Object), the array will be used for multi handle following element order ) |
trackStyle | Array[Object] | Object | [{}] | The style used for track. (both for slider( Object) and range( Array of Object), the array will be used for multi track following element order ) |
railStyle | Object | {} | The style used for the track base color. |
dotStyle | Object | {} | The style used for the dots. |
activeDotStyle | Object | {} | The style used for the active dots. |
reverse | boolean | false | If the value is true , it means the component is rendered reverse. |
Name | Type | Default | Description |
---|---|---|---|
defaultValue | number | 0 | Set initial value of slider. |
value | number | - | Set current value of slider. |
tabIndex | number | 0 | Set the tabIndex of the slider handle. |
Name | Type | Default | Description |
---|---|---|---|
defaultValue | number[] | [0, 0] | Set initial positions of handles. |
value | number[] | Set current positions of handles. | |
tabIndex | number[] | [0, 0] | Set the tabIndex of each handle. |
count | number | 1 | Determine how many ranges to render, and multiple handles will be rendered (number + 1). |
allowCross | boolean | true | allowCross could be set as true to allow those handles to cross. |
pushable | boolean or number | false | pushable could be set as true to allow pushing of surrounding handles when moving a handle. When set to a number, the number will be the minimum ensured distance between handles. Example: ![]() |
No vulnerabilities found.
No security vulnerabilities found.