ant-design-vue/components/vc-slider/demo/slider.jsx

237 lines
6.0 KiB
Vue
Raw Normal View History

2019-01-12 03:33:27 +00:00
import Slider from '../index';
import Tooltip from '../../vc-tooltip';
import '../assets/index.less';
import '../../vc-tooltip/assets/bootstrap.less';
2018-03-29 06:32:43 +00:00
2019-01-12 03:33:27 +00:00
const { Handle } = Slider;
2018-03-29 06:32:43 +00:00
2019-01-12 03:33:27 +00:00
function log(value) {
2018-03-29 06:32:43 +00:00
console.log(value); //eslint-disable-line
}
const CustomizedSlider = {
2019-01-12 03:33:27 +00:00
data() {
2018-03-29 06:32:43 +00:00
return {
value: 50,
2019-01-12 03:33:27 +00:00
};
2018-03-29 06:32:43 +00:00
},
methods: {
2019-01-12 03:33:27 +00:00
onSliderChange(value) {
log(value);
this.value = value;
2018-03-29 06:32:43 +00:00
},
2019-01-12 03:33:27 +00:00
onAfterChange(value) {
log(value);
2018-03-29 06:32:43 +00:00
},
},
2019-01-12 03:33:27 +00:00
render() {
return (
<Slider
value={this.value}
onChange={this.onSliderChange}
onAfterChange={this.onAfterChange}
/>
);
2018-03-29 06:32:43 +00:00
},
2019-01-12 03:33:27 +00:00
};
2018-03-29 06:32:43 +00:00
const DynamicBounds = {
2019-01-12 03:33:27 +00:00
data() {
2018-03-29 06:32:43 +00:00
return {
min: 0,
max: 100,
2019-01-12 03:33:27 +00:00
};
2018-03-29 06:32:43 +00:00
},
methods: {
2019-01-12 03:33:27 +00:00
onSliderChange(value) {
log(value);
this.value = value;
2018-03-29 06:32:43 +00:00
},
2019-01-12 03:33:27 +00:00
onAfterChange(value) {
log(value);
2018-03-29 06:32:43 +00:00
},
2019-01-12 03:33:27 +00:00
onMinChange(e) {
this.min = +e.target.value || 0;
2018-03-29 06:32:43 +00:00
},
2019-01-12 03:33:27 +00:00
onMaxChange(e) {
this.max = +e.target.value || 100;
2018-03-29 06:32:43 +00:00
},
},
2019-01-12 03:33:27 +00:00
render() {
2018-03-29 06:32:43 +00:00
return (
<div>
<label>Min: </label>
2019-01-12 03:33:27 +00:00
<input type="number" value={this.min} onInput={this.onMinChange} />
2018-03-29 06:32:43 +00:00
<br />
<label>Max: </label>
2019-01-12 03:33:27 +00:00
<input type="number" value={this.max} onInput={this.onMaxChange} />
<br />
<br />
<Slider defaultValue={50} min={this.min} max={this.max} onChange={this.onSliderChange} />
2018-03-29 06:32:43 +00:00
</div>
2019-01-12 03:33:27 +00:00
);
2018-03-29 06:32:43 +00:00
},
2019-01-12 03:33:27 +00:00
};
2018-03-29 06:32:43 +00:00
const SliderWithTooltip = {
2019-01-12 03:33:27 +00:00
data() {
2018-03-29 06:32:43 +00:00
return {
visibles: [],
2019-01-12 03:33:27 +00:00
};
2018-03-29 06:32:43 +00:00
},
methods: {
2019-01-12 03:33:27 +00:00
handleTooltipVisibleChange(index, visible) {
this.visibles[index] = visible;
this.visibles = { ...this.visibles };
2018-03-29 06:32:43 +00:00
},
2019-01-12 03:33:27 +00:00
handleRange(h, { value, dragging, index, disabled, style, ...restProps }) {
const tipFormatter = value => `${value}%`;
const tipProps = { overlayClassName: 'foo' };
2018-03-29 06:32:43 +00:00
const {
prefixCls = 'rc-slider-tooltip',
overlay = tipFormatter(value),
placement = 'top',
visible = visible || false,
2019-01-12 03:33:27 +00:00
...restTooltipProps
} = tipProps;
2018-03-29 06:32:43 +00:00
2019-01-12 03:33:27 +00:00
let handleStyleWithIndex;
2018-03-29 06:32:43 +00:00
if (Array.isArray(style)) {
2019-01-12 03:33:27 +00:00
handleStyleWithIndex = style[index] || style[0];
2018-03-29 06:32:43 +00:00
} else {
2019-01-12 03:33:27 +00:00
handleStyleWithIndex = style;
2018-03-29 06:32:43 +00:00
}
const tooltipProps = {
props: {
prefixCls,
overlay,
placement,
visible: (!disabled && (this.visibles[index] || dragging)) || visible,
...restTooltipProps,
},
key: index,
2019-01-12 03:33:27 +00:00
};
2018-03-29 06:32:43 +00:00
const handleProps = {
props: {
value,
...restProps,
},
on: {
mouseenter: () => this.handleTooltipVisibleChange(index, true),
mouseleave: () => this.handleTooltipVisibleChange(index, false),
visibleChange: log,
2018-03-29 06:32:43 +00:00
},
style: {
...handleStyleWithIndex,
},
2019-01-12 03:33:27 +00:00
};
2018-03-29 06:32:43 +00:00
return (
2019-01-12 03:33:27 +00:00
<Tooltip {...tooltipProps}>
<Handle {...handleProps} />
2018-03-29 06:32:43 +00:00
</Tooltip>
2019-01-12 03:33:27 +00:00
);
2018-03-29 06:32:43 +00:00
},
},
2019-01-12 03:33:27 +00:00
render() {
return <Slider handle={this.handleRange} />;
2018-03-29 06:32:43 +00:00
},
2019-01-12 03:33:27 +00:00
};
2018-03-29 06:32:43 +00:00
export default {
2019-01-12 03:33:27 +00:00
render() {
const style = { width: '400px', margin: '50px' };
const pStyle = { margin: '20px 0' };
2018-03-29 06:32:43 +00:00
return (
<div>
<div style={style}>
<p style={pStyle}>Basic Slider</p>
<Slider onChange={log} />
</div>
<div style={style}>
<p style={pStyle}>Basic Slider`step=20`</p>
<Slider step={20} defaultValue={50} onBeforeChange={log} />
</div>
<div style={style}>
<p style={pStyle}>Basic Slider`step=20, dots`</p>
<Slider dots step={20} defaultValue={100} onAfterChange={log} />
</div>
<div style={style}>
2019-01-12 03:33:27 +00:00
<p style={pStyle}>
Basic Slider`step=20, dots, dotStyle={"{borderColor: 'orange'}"}, activeDotStyle=
{"{borderColor: 'yellow'}"}`
</p>
<Slider
dots
step={20}
defaultValue={100}
onAfterChange={log}
dotStyle={{ borderColor: 'orange' }}
activeDotStyle={{ borderColor: 'yellow' }}
/>
2018-03-29 06:32:43 +00:00
</div>
<div style={style}>
<p style={pStyle}>Slider with tooltip, with custom `tipFormatter`</p>
<SliderWithTooltip />
</div>
<div style={style}>
2019-01-12 03:33:27 +00:00
<p style={pStyle}>
Slider with custom handle and track style.<strong>(old api, will be deprecated)</strong>
</p>
2018-03-29 06:32:43 +00:00
<Slider
defaultValue={30}
maximumTrackStyle={{ backgroundColor: 'red', height: '10px' }}
minimumTrackStyle={{ backgroundColor: 'blue', height: '10px' }}
handleStyle={{
borderColor: 'blue',
height: '28px',
width: '28px',
marginLeft: '-14px',
marginTop: '-9px',
backgroundColor: 'black',
}}
/>
</div>
<div style={style}>
2019-01-12 03:33:27 +00:00
<p style={pStyle}>
Slider with custom handle and track style.<strong>(The recommended new api)</strong>
</p>
2018-03-29 06:32:43 +00:00
<Slider
defaultValue={30}
trackStyle={{ backgroundColor: 'blue', height: '10px' }}
handleStyle={{
borderColor: 'blue',
height: '28px',
width: '28px',
marginLeft: '-14px',
marginTop: '-9px',
backgroundColor: 'black',
}}
railStyle={{ backgroundColor: 'red', height: '10px' }}
/>
</div>
<div style={style}>
<p style={pStyle}>Basic Slider, disabled</p>
<Slider onChange={log} disabled />
</div>
<div style={style}>
<p style={pStyle}>Controlled Slider</p>
<Slider value={50} />
</div>
<div style={style}>
<p style={pStyle}>Customized Slider</p>
<CustomizedSlider />
</div>
<div style={style}>
<p style={pStyle}>Slider with dynamic `min` `max`</p>
<DynamicBounds />
</div>
</div>
2019-01-12 03:33:27 +00:00
);
2018-03-29 06:32:43 +00:00
},
2019-01-12 03:33:27 +00:00
};