diff --git a/components/vc-slider/demo/handle.jsx b/components/vc-slider/demo/handle.jsx index b2af8e3ff..c3bcb9e0a 100644 --- a/components/vc-slider/demo/handle.jsx +++ b/components/vc-slider/demo/handle.jsx @@ -19,7 +19,7 @@ export default { }, render () { const handle = (h, props) => { - const { value, dragging, index, refStr, ...restProps } = props + const { value, dragging, index, refStr, style, ...restProps } = props const handleProps = { props: { ...restProps, @@ -29,6 +29,7 @@ export default { refStr, }, key: index, + style, } return ( { + const handleRange = (h, { value, dragging, index, disabled, style, ...restProps }) => { const tipFormatter = value => `${value}%` - const handleStyle = [{}] const tipProps = {} const { @@ -57,10 +57,10 @@ export default { ...restTooltipProps } = tipProps let handleStyleWithIndex - if (Array.isArray(handleStyle)) { - handleStyleWithIndex = handleStyle[index] || handleStyle[0] + if (Array.isArray(style)) { + handleStyleWithIndex = style[index] || style[0] } else { - handleStyleWithIndex = handleStyle + handleStyleWithIndex = style } const tooltipProps = { diff --git a/components/vc-slider/demo/marks.jsx b/components/vc-slider/demo/marks.jsx new file mode 100644 index 000000000..bc1ce728b --- /dev/null +++ b/components/vc-slider/demo/marks.jsx @@ -0,0 +1,56 @@ +import Slider from '../index' +import '../assets/index.less' + +export default { + render () { + const style = { width: '400px', margin: '50px' } + const pStyle = { margin: '20px 0' } + const marks = { + '-10': '-10°C', + 0: 0°C, + 26: '26°C', + 37: '37°C', + 50: '50°C', + 100: { + style: { + color: 'red', + }, + label: 100°C, + }, + } + + function log (value) { + console.log(value); //eslint-disable-line + } + return ( +
+
+

Slider with marks, `step=null`

+ +
+
+

Slider with marks and steps

+ +
+ +
+

Slider with marks, `included=false`

+ +
+
+

Slider with marks and steps, `included=false`

+ +
+ +
+

Range with marks

+ +
+
+

Range with marks and steps

+ +
+
+ ) + }, +} diff --git a/components/vc-slider/demo/range.jsx b/components/vc-slider/demo/range.jsx new file mode 100644 index 000000000..ee2eed274 --- /dev/null +++ b/components/vc-slider/demo/range.jsx @@ -0,0 +1,209 @@ +import Slider from '../index' +import '../assets/index.less' +const { Range } = Slider +function log (value) { + console.log(value); //eslint-disable-line +} + +const CustomizedRange = { + data () { + return { + lowerBound: 20, + upperBound: 40, + value: [20, 40], + } + }, + methods: { + onLowerBoundChange (e) { + this.lowerBound = +e.target.value + }, + onUpperBoundChange (e) { + this.upperBound = +e.target.value + }, + onSliderChange (value) { + log(value) + this.value = value + }, + handleApply () { + this.value = [this.lowerBound, this.upperBound] + }, + }, + render () { + return ( +
+ + +
+ + +
+ +

+ +
+ ) + }, +} + +const DynamicBounds = { + data () { + return { + min: 0, + max: 100, + } + }, + methods: { + onSliderChange (value) { + log(value) + }, + onMinChange (e) { + this.min = +e.target.value || 0 + }, + onMaxChange (e) { + this.max = +e.target.value || 100 + }, + }, + render () { + return ( +
+ + +
+ + +

+ +
+ ) + }, +} + +const ControlledRange = { + data () { + return { + value: [20, 40, 60, 80], + } + }, + methods: { + handleChange (value) { + this.value = value + }, + }, + render () { + return + }, +} + +const ControlledRangeDisableAcross = { + props: { + pushable: [Number, Boolean], + }, + data () { + return { + value: [20, 40, 60, 80], + } + }, + methods: { + handleChange (value) { + this.value = value + }, + }, + render () { + const rangeRange = { + props: { + value: this.value, + allowCross: false, + ...this.$props, + }, + on: { + change: this.handleChange, + }, + } + return + }, +} + +const PureRenderRange = { + data () { + return { + foo: false, + } + }, + methods: { + handleChange (value) { + console.log(value) + this.foo = !this.foo + }, + }, + render () { + return + }, +} + +export default { + render () { + const style = { width: '400px', margin: '50px' } + const pStyle = { margin: '20px 0' } + + return ( +
+
+

Basic Range,`allowCross=false`

+ +
+
+

Basic Range,`step=20`

+ +
+
+

Basic Range,`step=20, dots`

+ +
+
+

Basic Range,disabled

+ +
+
+

Controlled Range

+ +
+
+

Controlled Range, not allow across

+ +
+
+

Controlled Range, not allow across, pushable=5

+ +
+
+

Multi Range

+ +
+
+

Multi Range with custom track and handle style

+ +
+
+

Customized Range

+ +
+
+

Range with dynamic `max` `min`

+ +
+
+

Range as child component

+ +
+
+ ) + }, +} diff --git a/components/vc-slider/demo/slider.jsx b/components/vc-slider/demo/slider.jsx new file mode 100644 index 000000000..4909ee292 --- /dev/null +++ b/components/vc-slider/demo/slider.jsx @@ -0,0 +1,223 @@ +import Slider from '../index' +import Tooltip from '../../vc-tooltip' +import '../assets/index.less' +import '../../vc-tooltip/assets/bootstrap.less' + +const { Handle } = Slider + +function log (value) { + console.log(value); //eslint-disable-line +} + +const CustomizedSlider = { + data () { + return { + value: 50, + } + }, + methods: { + onSliderChange (value) { + log(value) + this.value = value + }, + onAfterChange (value) { + log(value) + }, + }, + render () { + return + }, +} + +const DynamicBounds = { + data () { + return { + min: 0, + max: 100, + } + }, + methods: { + onSliderChange (value) { + log(value) + this.value = value + }, + onAfterChange (value) { + log(value) + }, + onMinChange (e) { + this.min = +e.target.value || 0 + }, + onMaxChange (e) { + this.max = +e.target.value || 100 + }, + }, + render () { + return ( +
+ + +
+ + +

+ +
+ ) + }, +} + +const SliderWithTooltip = { + data () { + return { + visibles: [], + } + }, + methods: { + handleTooltipVisibleChange (index, visible) { + this.visibles[index] = visible + this.visibles = { ...this.visibles } + }, + handleRange (h, { value, dragging, index, disabled, style, ...restProps }) { + const tipFormatter = value => `${value}%` + const tipProps = { overlayClassName: 'foo' } + + const { + prefixCls = 'rc-slider-tooltip', + overlay = tipFormatter(value), + placement = 'top', + visible = visible || false, + ...restTooltipProps } = tipProps + + let handleStyleWithIndex + if (Array.isArray(style)) { + handleStyleWithIndex = style[index] || style[0] + } else { + handleStyleWithIndex = style + } + + const tooltipProps = { + props: { + prefixCls, + overlay, + placement, + visible: (!disabled && (this.visibles[index] || dragging)) || visible, + ...restTooltipProps, + }, + key: index, + } + const handleProps = { + props: { + value, + ...restProps, + }, + on: { + mouseenter: () => this.handleTooltipVisibleChange(index, true), + mouseleave: () => this.handleTooltipVisibleChange(index, false), + change: log, + }, + style: { + ...handleStyleWithIndex, + }, + } + + return ( + + + + + ) + }, + }, + render () { + return + }, +} + +export default { + render () { + const style = { width: '400px', margin: '50px' } + const pStyle = { margin: '20px 0' } + + return ( +
+
+

Basic Slider

+ +
+
+

Basic Slider,`step=20`

+ +
+ +
+

Basic Slider,`step=20, dots`

+ +
+
+

Basic Slider,`step=20, dots, dotStyle={"{borderColor: 'orange'}"}, activeDotStyle={"{borderColor: 'yellow'}"}`

+ +
+
+

Slider with tooltip, with custom `tipFormatter`

+ +
+
+

Slider with custom handle and track style.(old api, will be deprecated)

+ +
+
+

Slider with custom handle and track style.(The recommended new api)

+ +
+
+

Basic Slider, disabled

+ +
+
+

Controlled Slider

+ +
+
+

Customized Slider

+ +
+
+

Slider with dynamic `min` `max`

+ +
+
+ ) + }, +} diff --git a/components/vc-slider/demo/vertical.jsx b/components/vc-slider/demo/vertical.jsx new file mode 100644 index 000000000..a244afaa0 --- /dev/null +++ b/components/vc-slider/demo/vertical.jsx @@ -0,0 +1,57 @@ +import Slider from '../index' +import '../assets/index.less' + +export default { + render () { + const style = { float: 'left', width: '160px', height: '400px', marginBottom: '160px', marginLeft: '50px' } + const parentStyle = { overflow: 'hidden' } + const pStyle = { margin: '20px 0' } + const marks = { + '-10': '-10°C', + 0: 0°C, + 26: '26°C', + 37: '37°C', + 50: '50°C', + 100: { + style: { + color: 'red', + }, + label: 100°C, + }, + } + + function log (value) { + console.log(value); //eslint-disable-line + } + return ( +
+
+

Slider with marks, `step=null`

+ +
+
+

Slider with marks and steps

+ +
+ +
+

Slider with marks, `included=false`

+ +
+
+

Slider with marks and steps, `included=false`

+ +
+ +
+

Range with marks

+ +
+
+

Range with marks and steps

+ +
+
+ ) + }, +} diff --git a/components/vc-slider/src/Handle.jsx b/components/vc-slider/src/Handle.jsx index b8386d59f..06c696300 100644 --- a/components/vc-slider/src/Handle.jsx +++ b/components/vc-slider/src/Handle.jsx @@ -102,7 +102,6 @@ export default { refStr, ...ariaProps, }, - style: elStyle, class: className, on: { blur: this.onBlur, @@ -115,6 +114,7 @@ export default { return (
) }, diff --git a/components/vc-slider/src/Range.jsx b/components/vc-slider/src/Range.jsx index 1d3c0797c..3af78d1bb 100644 --- a/components/vc-slider/src/Range.jsx +++ b/components/vc-slider/src/Range.jsx @@ -86,8 +86,8 @@ const Range = { const isNotControlled = !hasProp(this, 'value') if (isNotControlled) { this.setState(state) - } else if (state.handle !== undefined) { - this.setState({ sHandle: state.handle }) + } else if (state.sHandle !== undefined) { + this.setState({ sHandle: state.sHandle }) } const data = { ...this.$data, ...state } @@ -110,10 +110,9 @@ const Range = { const prevValue = bounds[this.prevMovedHandleIndex] if (value === prevValue) return - const nextBounds = [...bounds] nextBounds[this.prevMovedHandleIndex] = value - this.$emit('change', { bounds: nextBounds }) + this.onChange({ bounds: nextBounds }) }, onEnd () { this.setState({ sHandle: null }) diff --git a/components/vc-slider/src/common/createSlider.jsx b/components/vc-slider/src/common/createSlider.jsx index 23ca08b78..bfd73d133 100644 --- a/components/vc-slider/src/common/createSlider.jsx +++ b/components/vc-slider/src/common/createSlider.jsx @@ -43,7 +43,7 @@ export default function createSlider (Component) { max: 100, step: 1, marks: {}, - handle (h, { index, refStr, className, ...restProps }) { + handle (h, { index, refStr, className, style, ...restProps }) { delete restProps.dragging const handleProps = { props: { @@ -53,6 +53,7 @@ export default function createSlider (Component) { refStr, }, class: className, + style, key: index, } return @@ -67,6 +68,10 @@ export default function createSlider (Component) { dotStyle: {}, activeDotStyle: {}, }), + model: { + prop: 'value', + event: 'change', + }, data () { if (process.env.NODE_ENV !== 'production') { const { step, max, min } = this @@ -147,6 +152,7 @@ export default function createSlider (Component) { } }, onBlur (e) { + console.dir(e) this.onEnd(e) this.$emit('blur', e) },