mirror of
https://github.com/wassname/slider.git
synced 2026-09-11 12:42:49 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6347b6d0c6 | ||
|
|
6a5573b6ca | ||
|
|
e030ba9f9d | ||
|
|
daaea139b9 | ||
|
|
2641880783 | ||
|
|
d6e81a692c | ||
|
|
0512ee6ee0 | ||
|
|
613a2ae213 | ||
|
|
2cb0dbce6f |
@@ -90,9 +90,9 @@ ReactDOM.render(<Rcslider />, container);
|
|||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>marks</td>
|
<td>marks</td>
|
||||||
<td>object {number: string}</td>
|
<td>object{number: string} or object{number: object{ style, label }}</td>
|
||||||
<td>{}</td>
|
<td>{}</td>
|
||||||
<td>Mark on the slider. The key determines the position, and the value determines what will show.</td>
|
<td>Mark 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.</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>step</td>
|
<td>step</td>
|
||||||
|
|||||||
+7
-2
@@ -7,11 +7,16 @@ const Slider = require('rc-slider');
|
|||||||
const style = {width: 400, margin: 50};
|
const style = {width: 400, margin: 50};
|
||||||
const marks = {
|
const marks = {
|
||||||
'-10': '-10°C',
|
'-10': '-10°C',
|
||||||
0: '0°C',
|
0: <strong>0°C</strong>,
|
||||||
26: '26°C',
|
26: '26°C',
|
||||||
37: '37°C',
|
37: '37°C',
|
||||||
50: '50°C',
|
50: '50°C',
|
||||||
100: '100°C',
|
100: {
|
||||||
|
style: {
|
||||||
|
color: 'red',
|
||||||
|
},
|
||||||
|
label: <strong>100°C</strong>,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
function log(value) {
|
function log(value) {
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "rc-slider",
|
"name": "rc-slider",
|
||||||
"version": "3.3.1",
|
"version": "3.5.0",
|
||||||
"description": "slider ui component for react",
|
"description": "slider ui component for react",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"react",
|
"react",
|
||||||
|
|||||||
+9
-3
@@ -8,7 +8,7 @@ const Marks = ({className, marks, included, upperBound, lowerBound, max, min}) =
|
|||||||
const markWidth = unit * 0.9;
|
const markWidth = unit * 0.9;
|
||||||
|
|
||||||
const range = max - min;
|
const range = max - min;
|
||||||
const elements = marksKeys.map(parseFloat).map((point) => {
|
const elements = marksKeys.map(parseFloat).sort((a, b) => a - b).map((point) => {
|
||||||
const isActived = (!included && point === upperBound) ||
|
const isActived = (!included && point === upperBound) ||
|
||||||
(included && point <= upperBound && point >= lowerBound);
|
(included && point <= upperBound && point >= lowerBound);
|
||||||
const markClassName = classNames({
|
const markClassName = classNames({
|
||||||
@@ -19,8 +19,14 @@ const Marks = ({className, marks, included, upperBound, lowerBound, max, min}) =
|
|||||||
const style = { width: markWidth + '%' };
|
const style = { width: markWidth + '%' };
|
||||||
style.left = (point - min) / range * 100 - markWidth / 2 + '%';
|
style.left = (point - min) / range * 100 - markWidth / 2 + '%';
|
||||||
|
|
||||||
return (<span className={markClassName} style={style} key={point}>
|
const markPoint = marks[point];
|
||||||
{marks[point]}
|
const markPointIsObject = typeof markPoint === 'object' &&
|
||||||
|
!React.isValidElement(markPoint);
|
||||||
|
const markLabel = markPointIsObject ? markPoint.label : markPoint;
|
||||||
|
const markStyle = markPointIsObject ?
|
||||||
|
{ ...style, ...markPoint.style } : style;
|
||||||
|
return (<span className={markClassName} style={markStyle} key={point}>
|
||||||
|
{markLabel}
|
||||||
</span>);
|
</span>);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
+10
-10
@@ -4,7 +4,7 @@ import classNames from 'classnames';
|
|||||||
import objectAssign from 'object-assign';
|
import objectAssign from 'object-assign';
|
||||||
import Track from './Track';
|
import Track from './Track';
|
||||||
import Handle from './Handle';
|
import Handle from './Handle';
|
||||||
import Dots from './Dots';
|
import Steps from './Steps';
|
||||||
import Marks from './Marks';
|
import Marks from './Marks';
|
||||||
|
|
||||||
function noop() {
|
function noop() {
|
||||||
@@ -34,7 +34,7 @@ class Slider extends React.Component {
|
|||||||
const {range, min, max} = props;
|
const {range, min, max} = props;
|
||||||
const initialValue = range ? [min, min] : min;
|
const initialValue = range ? [min, min] : min;
|
||||||
const defaultValue = ('defaultValue' in props ? props.defaultValue : initialValue);
|
const defaultValue = ('defaultValue' in props ? props.defaultValue : initialValue);
|
||||||
const value = ('value' in props ? props.value : defaultValue);
|
const value = (props.value !== undefined ? props.value : defaultValue);
|
||||||
|
|
||||||
let upperBound;
|
let upperBound;
|
||||||
let lowerBound;
|
let lowerBound;
|
||||||
@@ -81,11 +81,11 @@ class Slider extends React.Component {
|
|||||||
lowerBound: nextLowerBound,
|
lowerBound: nextLowerBound,
|
||||||
});
|
});
|
||||||
if (this.isValueOutOfBounds(upperBound, nextProps) ||
|
if (this.isValueOutOfBounds(upperBound, nextProps) ||
|
||||||
this.isValueOutOfBounds(lowerBound, nextProps)) {
|
this.isValueOutOfBounds(lowerBound, nextProps)) {
|
||||||
this.props.onChange([nextLowerBound, nextUpperBound]);
|
this.props.onChange([nextLowerBound, nextUpperBound]);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const value = 'value' in nextProps ? nextProps.value : upperBound;
|
const value = nextProps.value !== undefined ? nextProps.value : upperBound;
|
||||||
const nextValue = this.trimAlignValue(value, nextProps);
|
const nextValue = this.trimAlignValue(value, nextProps);
|
||||||
if (nextValue === upperBound && lowerBound === nextProps.min) return;
|
if (nextValue === upperBound && lowerBound === nextProps.min) return;
|
||||||
|
|
||||||
@@ -333,7 +333,7 @@ class Slider extends React.Component {
|
|||||||
render() {
|
render() {
|
||||||
const {handle, upperBound, lowerBound} = this.state;
|
const {handle, upperBound, lowerBound} = this.state;
|
||||||
const {className, prefixCls, disabled, dots, included, range, step,
|
const {className, prefixCls, disabled, dots, included, range, step,
|
||||||
marks, max, min, tipTransitionName, tipFormatter, children} = this.props;
|
marks, max, min, tipTransitionName, tipFormatter, children} = this.props;
|
||||||
|
|
||||||
const upperOffset = this.calcOffset(upperBound);
|
const upperOffset = this.calcOffset(upperBound);
|
||||||
const lowerOffset = this.calcOffset(lowerBound);
|
const lowerOffset = this.calcOffset(lowerBound);
|
||||||
@@ -343,13 +343,13 @@ class Slider extends React.Component {
|
|||||||
|
|
||||||
const upper = (<Handle className={handleClassName}
|
const upper = (<Handle className={handleClassName}
|
||||||
noTip={isNoTip} tipTransitionName={tipTransitionName} tipFormatter={tipFormatter}
|
noTip={isNoTip} tipTransitionName={tipTransitionName} tipFormatter={tipFormatter}
|
||||||
offset={upperOffset} value={upperBound} dragging={handle === 'upperBound'} />);
|
offset={upperOffset} value={upperBound} dragging={handle === 'upperBound'}/>);
|
||||||
|
|
||||||
let lower = null;
|
let lower = null;
|
||||||
if (range) {
|
if (range) {
|
||||||
lower = (<Handle className={handleClassName}
|
lower = (<Handle className={handleClassName}
|
||||||
noTip={isNoTip} tipTransitionName={tipTransitionName} tipFormatter={tipFormatter}
|
noTip={isNoTip} tipTransitionName={tipTransitionName} tipFormatter={tipFormatter}
|
||||||
offset={lowerOffset} value={lowerBound} dragging={handle === 'lowerBound'} />);
|
offset={lowerOffset} value={lowerBound} dragging={handle === 'lowerBound'}/>);
|
||||||
}
|
}
|
||||||
|
|
||||||
const sliderClassName = classNames({
|
const sliderClassName = classNames({
|
||||||
@@ -366,12 +366,12 @@ class Slider extends React.Component {
|
|||||||
{lower}
|
{lower}
|
||||||
<Track className={prefixCls + '-track'} included={isIncluded}
|
<Track className={prefixCls + '-track'} included={isIncluded}
|
||||||
offset={lowerOffset} length={upperOffset - lowerOffset}/>
|
offset={lowerOffset} length={upperOffset - lowerOffset}/>
|
||||||
<Dots prefixCls={prefixCls} marks={marks} dots={dots} step={step}
|
<Steps prefixCls={prefixCls} marks={marks} dots={dots} step={step}
|
||||||
included={isIncluded} lowerBound={lowerBound}
|
included={isIncluded} lowerBound={lowerBound}
|
||||||
upperBound={upperBound} max={max} min={min} />
|
upperBound={upperBound} max={max} min={min}/>
|
||||||
<Marks className={prefixCls + '-mark'} marks={marks}
|
<Marks className={prefixCls + '-mark'} marks={marks}
|
||||||
included={isIncluded} lowerBound={lowerBound}
|
included={isIncluded} lowerBound={lowerBound}
|
||||||
upperBound={upperBound} max={max} min={min} />
|
upperBound={upperBound} max={max} min={min}/>
|
||||||
{children}
|
{children}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -12,7 +12,8 @@ function calcPoints(marks, dots, step, min, max) {
|
|||||||
return points;
|
return points;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Dots = ({prefixCls, marks, dots, step, included, lowerBound, upperBound, max, min}) => {
|
const Steps = ({prefixCls, marks, dots, step, included,
|
||||||
|
lowerBound, upperBound, max, min}) => {
|
||||||
const range = max - min;
|
const range = max - min;
|
||||||
const elements = calcPoints(marks, dots, step, min, max).map((point) => {
|
const elements = calcPoints(marks, dots, step, min, max).map((point) => {
|
||||||
const offset = (point - min) / range * 100 + '%';
|
const offset = (point - min) / range * 100 + '%';
|
||||||
@@ -31,4 +32,4 @@ const Dots = ({prefixCls, marks, dots, step, included, lowerBound, upperBound, m
|
|||||||
return <div className={prefixCls + '-step'}>{elements}</div>;
|
return <div className={prefixCls + '-step'}>{elements}</div>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Dots;
|
export default Steps;
|
||||||
Reference in New Issue
Block a user