Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/static/js/2.b12a268b.chunk.js

Large diffs are not rendered by default.

89 changes: 70 additions & 19 deletions lib/elements/slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,21 @@ import React, { Component } from "react";
import PropTypes from "prop-types";
import styles from "./range.css.js";
import ReactDOM from "react-dom";

const TOOLTIP_PADDING = '25px';
const TOOLTIP_POSITION = {
TOP: 'top',
BOTTOM: 'bottom',
};

export default class Slider extends Component {
constructor(props) {
super(props);
let value = this.props.value
? this.props.value
: props.multiple
? [...props.settings.start]
: props.settings.start;
? [...props.settings.start]
: props.settings.start;
this.state = {
value: value,
position: props.multiple ? [] : 0,
Expand All @@ -29,8 +36,9 @@ export default class Slider extends Component {
window.addEventListener("mouseup", this.rangeMouseUp);
}

componentWillReceiveProps(nextProps) {
if (nextProps.value && nextProps.value !== this.state.value) {
UNSAFE_componentWillReceiveProps(nextProps) {
const isValueUnset = nextProps.value == null;
if (!isValueUnset && nextProps.value !== this.state.value) {
if (this.props.multiple) {
const different = this.isDifferentArrays(
nextProps.value,
Expand Down Expand Up @@ -221,7 +229,8 @@ export default class Slider extends Component {
}

this.setState({
mouseDown: true
mouseDown: true,
shouldDisplayTooltip: true,
});
let innerBoundingClientRect = ReactDOM.findDOMNode(
this.inner
Expand Down Expand Up @@ -272,7 +281,25 @@ export default class Slider extends Component {

rangeMouseUp() {
this.setState({
mouseDown: false
mouseDown: false,
shouldDisplayTooltip: false,
});
}

onMouseEnter() {
this.setState({
shouldDisplayTooltip: true,
});
}

onMouseLeave() {
// Continue showing the tooltip if the mouse is down
if (this.state.mouseDown) {
return;
}

this.setState({
shouldDisplayTooltip: false,
});
}

Expand Down Expand Up @@ -346,11 +373,11 @@ export default class Slider extends Component {
...{ width: this.state.position + this.state.offset + "px" },
...(this.props.multiple && this.state.position.length > 0
? {
left: this.state.position[0],
width:
left: this.state.position[0],
width:
this.state.position[this.state.numberOfThumbs - 1] -
this.state.position[0]
}
}
: {})
}}
/>
Expand All @@ -371,17 +398,38 @@ export default class Slider extends Component {
/>
))
) : (
<div
style={{
...styles.thumb,
...(this.props.style
? this.props.style.thumb
<React.Fragment>
{this.state.shouldDisplayTooltip && this.props.tooltip && <div
style={{
position: "absolute",
left: this.state.position + "px",
transform: "translateX(calc(-50% + 10px))",
top: 0,
}}
>
<div
style={{
transform: this.props.settings.tooltipPosition === TOOLTIP_POSITION.BOTTOM ?
'translateY(calc(50%))' : 'translateY(calc(-50% - 30px))'
}}
>
{ this.props.tooltip(this.state.value) }
</div>
</div>}
<div
onMouseEnter={() => this.onMouseEnter()}
onMouseLeave={() => this.onMouseLeave()}
style={{
...styles.thumb,
...(this.props.style
? this.props.style.thumb
: {}
: {}),
...{ left: this.state.position + "px" }
}}
/>
? this.props.style.thumb
: {}
: {}),
...{ left: this.state.position + "px" }
}}
/>
</React.Fragment>
)}
</div>
</div>
Expand All @@ -393,6 +441,7 @@ export default class Slider extends Component {
Slider.defaultProps = {
color: "red",
settings: {
tooltipPosition: 'top',
min: 0,
max: 10,
step: 1,
Expand All @@ -406,7 +455,9 @@ Slider.propTypes = {
discrete: PropTypes.bool,
inverted: PropTypes.bool,
multiple: PropTypes.bool,
tooltip: PropTypes.func,
settings: PropTypes.shape({
tooltipPosition: PropTypes.string,
min: PropTypes.number,
max: PropTypes.number,
step: PropTypes.number,
Expand Down
48 changes: 35 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-semantic-ui-range",
"version": "0.7.0",
"version": "0.8.1",
"description": "A Slider React Component for Semantic-UI",
"main": "build/index.js",
"scripts": {
Expand Down