fix: should pass prefixCls to Tooltip correctly, close: #123

This commit is contained in:
Benjy Cui
2016-07-25 14:09:05 +08:00
parent 926d5aeb91
commit d05761f396
2 changed files with 81 additions and 32 deletions
+31 -16
View File
@@ -23,34 +23,49 @@ export default class Handle extends React.Component {
}
render() {
const props = this.props;
const {className, tipTransitionName, tipFormatter, vertical, offset, value} = props;
const {dragging, noTip} = props;
const {
prefixCls,
className,
tipTransitionName,
tipFormatter,
vertical,
offset,
value,
dragging,
noTip,
} = this.props;
const style = vertical ? { bottom: offset + '%' } : { left: offset + '%' };
const handle = (<div className={className} style={style}
onMouseUp={this.showTooltip.bind(this)}
onMouseEnter={this.showTooltip.bind(this)}
onMouseLeave={this.hideTooltip.bind(this)}/>);
const handle = (
<div className={className} style={style}
onMouseUp={this.showTooltip.bind(this)}
onMouseEnter={this.showTooltip.bind(this)}
onMouseLeave={this.hideTooltip.bind(this)}
/>
);
if (noTip) {
return handle;
}
const isTooltipVisible = dragging || this.state.isTooltipVisible;
return (<Tooltip
prefixCls={className.replace('slider-handle', 'tooltip')}
placement="top"
visible={isTooltipVisible}
overlay={<span>{tipFormatter(value)}</span>}
delay={0}
transitionName={tipTransitionName}>
{handle}
</Tooltip>);
return (
<Tooltip
prefixCls={prefixCls.replace('slider', 'tooltip')}
placement="top"
visible={isTooltipVisible}
overlay={<span>{tipFormatter(value)}</span>}
delay={0}
transitionName={tipTransitionName}
>
{handle}
</Tooltip>
);
}
}
Handle.propTypes = {
prefixCls: React.PropTypes.string,
className: React.PropTypes.string,
vertical: React.PropTypes.bool,
offset: React.PropTypes.number,
+50 -16
View File
@@ -327,9 +327,26 @@ class Slider extends React.Component {
}
render() {
const {handle, upperBound, lowerBound} = this.state;
const {className, prefixCls, disabled, vertical, dots, included, range, step,
marks, max, min, tipTransitionName, tipFormatter, children} = this.props;
const {
handle,
upperBound,
lowerBound,
} = this.state;
const {
className,
prefixCls,
disabled,
vertical,
dots,
included,
range,
step,
marks,
max, min,
tipTransitionName,
tipFormatter,
children,
} = this.props;
const customHandle = this.props.handle;
@@ -350,15 +367,31 @@ class Slider extends React.Component {
const isNoTip = (step === null) || (tipFormatter === null);
const upper = cloneElement(customHandle, { className: upperClassName,
noTip: isNoTip, tipTransitionName: tipTransitionName, tipFormatter: tipFormatter,
vertical: vertical, offset: upperOffset, value: upperBound, dragging: handle === 'upperBound' });
const commonHandleProps = {
prefixCls,
noTip: isNoTip,
tipTransitionName,
tipFormatter,
vertical,
};
const upper = cloneElement(customHandle, {
...commonHandleProps,
className: upperClassName,
value: upperBound,
offset: upperOffset,
dragging: handle === 'upperBound',
});
let lower = null;
if (range) {
lower = cloneElement(customHandle, { className: lowerClassName,
noTip: isNoTip, tipTransitionName: tipTransitionName, tipFormatter: tipFormatter,
vertical: vertical, offset: lowerOffset, value: lowerBound, dragging: handle === 'lowerBound' });
lower = cloneElement(customHandle, {
...commonHandleProps,
className: lowerClassName,
value: lowerBound,
offset: lowerOffset,
dragging: handle === 'lowerBound',
});
}
const sliderClassName = classNames({
@@ -370,18 +403,19 @@ class Slider extends React.Component {
const isIncluded = included || range;
return (
<div ref="slider" className={sliderClassName}
onTouchStart={disabled ? noop : this.onTouchStart.bind(this)}
onMouseDown={disabled ? noop : this.onMouseDown.bind(this)}>
onTouchStart={disabled ? noop : this.onTouchStart.bind(this)}
onMouseDown={disabled ? noop : this.onMouseDown.bind(this)}
>
{upper}
{lower}
<Track className={prefixCls + '-track'} vertical = {vertical} included={isIncluded}
offset={lowerOffset} length={upperOffset - lowerOffset}/>
offset={lowerOffset} length={upperOffset - lowerOffset} />
<Steps prefixCls={prefixCls} vertical = {vertical} marks={marks} dots={dots} step={step}
included={isIncluded} lowerBound={lowerBound}
upperBound={upperBound} max={max} min={min}/>
included={isIncluded} lowerBound={lowerBound}
upperBound={upperBound} max={max} min={min} />
<Marks className={prefixCls + '-mark'} vertical = {vertical} marks={marks}
included={isIncluded} lowerBound={lowerBound}
upperBound={upperBound} max={max} min={min}/>
included={isIncluded} lowerBound={lowerBound}
upperBound={upperBound} max={max} min={min} />
{children}
</div>
);