2019-01-12 11:33:27 +08:00
|
|
|
import PropTypes from '../_util/vue-types';
|
|
|
|
import BaseMixin from '../_util/BaseMixin';
|
2020-01-18 21:44:13 +08:00
|
|
|
import { getOptionProps, getListeners } from '../_util/props-util';
|
2019-01-12 11:33:27 +08:00
|
|
|
import VcSlider from '../vc-slider/src/Slider';
|
|
|
|
import VcRange from '../vc-slider/src/Range';
|
|
|
|
import VcHandle from '../vc-slider/src/Handle';
|
|
|
|
import Tooltip from '../tooltip';
|
2019-08-28 10:50:19 +08:00
|
|
|
import Base from '../base';
|
2019-09-18 20:03:13 +08:00
|
|
|
import { ConfigConsumerProps } from '../config-provider';
|
2020-03-07 19:45:13 +08:00
|
|
|
import abstractTooltipProps from '../tooltip/abstractTooltipProps';
|
2018-04-01 19:23:56 +08:00
|
|
|
|
|
|
|
// export interface SliderMarks {
|
|
|
|
// [key]: React.ReactNode | {
|
|
|
|
// style: React.CSSProperties,
|
|
|
|
// label: React.ReactNode,
|
|
|
|
// };
|
|
|
|
// }
|
|
|
|
// const SliderMarks = PropTypes.shape({
|
|
|
|
// style: PropTypes.object,
|
|
|
|
// label: PropTypes.any,
|
|
|
|
// }).loose
|
2020-03-07 19:45:13 +08:00
|
|
|
const tooltipProps = abstractTooltipProps();
|
2018-04-01 19:23:56 +08:00
|
|
|
export const SliderProps = () => ({
|
|
|
|
prefixCls: PropTypes.string,
|
|
|
|
tooltipPrefixCls: PropTypes.string,
|
|
|
|
range: PropTypes.bool,
|
2020-03-07 19:45:13 +08:00
|
|
|
reverse: PropTypes.bool,
|
2018-04-01 19:23:56 +08:00
|
|
|
min: PropTypes.number,
|
|
|
|
max: PropTypes.number,
|
|
|
|
step: PropTypes.oneOfType([PropTypes.number, PropTypes.any]),
|
|
|
|
marks: PropTypes.object,
|
|
|
|
dots: PropTypes.bool,
|
2019-01-12 11:33:27 +08:00
|
|
|
value: PropTypes.oneOfType([PropTypes.number, PropTypes.arrayOf(PropTypes.number)]),
|
|
|
|
defaultValue: PropTypes.oneOfType([PropTypes.number, PropTypes.arrayOf(PropTypes.number)]),
|
2018-04-01 19:23:56 +08:00
|
|
|
included: PropTypes.bool,
|
|
|
|
disabled: PropTypes.bool,
|
|
|
|
vertical: PropTypes.bool,
|
2019-01-12 11:33:27 +08:00
|
|
|
tipFormatter: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
2019-01-05 11:22:53 +08:00
|
|
|
tooltipVisible: PropTypes.bool,
|
2020-03-07 19:45:13 +08:00
|
|
|
tooltipPlacement: tooltipProps.placement,
|
|
|
|
getTooltipPopupContainer: PropTypes.func,
|
2019-01-12 11:33:27 +08:00
|
|
|
});
|
2018-04-01 19:23:56 +08:00
|
|
|
|
2018-09-19 13:21:57 +08:00
|
|
|
const Slider = {
|
2018-04-08 21:17:20 +08:00
|
|
|
name: 'ASlider',
|
2018-04-01 19:23:56 +08:00
|
|
|
model: {
|
|
|
|
prop: 'value',
|
|
|
|
event: 'change',
|
|
|
|
},
|
|
|
|
mixins: [BaseMixin],
|
2019-09-18 20:03:13 +08:00
|
|
|
inject: {
|
|
|
|
configProvider: { default: () => ConfigConsumerProps },
|
|
|
|
},
|
2018-04-01 19:23:56 +08:00
|
|
|
props: {
|
|
|
|
...SliderProps(),
|
2019-01-12 11:33:27 +08:00
|
|
|
tipFormatter: PropTypes.oneOfType([PropTypes.func, PropTypes.object]).def(value =>
|
|
|
|
value.toString(),
|
|
|
|
),
|
2018-04-01 19:23:56 +08:00
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
data() {
|
2018-04-01 19:23:56 +08:00
|
|
|
return {
|
|
|
|
visibles: {},
|
2019-01-12 11:33:27 +08:00
|
|
|
};
|
2018-04-01 19:23:56 +08:00
|
|
|
},
|
|
|
|
methods: {
|
2019-01-12 11:33:27 +08:00
|
|
|
toggleTooltipVisible(index, visible) {
|
2018-04-01 19:23:56 +08:00
|
|
|
this.setState(({ visibles }) => ({
|
|
|
|
visibles: {
|
|
|
|
...visibles,
|
|
|
|
[index]: visible,
|
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
}));
|
2018-04-01 19:23:56 +08:00
|
|
|
},
|
2020-03-07 19:45:13 +08:00
|
|
|
handleWithTooltip(
|
|
|
|
tooltipPrefixCls,
|
|
|
|
prefixCls,
|
|
|
|
{ value, dragging, index, directives, on, ...restProps },
|
|
|
|
) {
|
|
|
|
const {
|
|
|
|
tipFormatter,
|
|
|
|
tooltipVisible,
|
|
|
|
tooltipPlacement,
|
|
|
|
getTooltipPopupContainer,
|
|
|
|
} = this.$props;
|
2019-01-12 11:33:27 +08:00
|
|
|
const { visibles } = this;
|
|
|
|
const isTipFormatter = tipFormatter ? visibles[index] || dragging : false;
|
|
|
|
const visible = tooltipVisible || (tooltipVisible === undefined && isTipFormatter);
|
2018-04-01 19:23:56 +08:00
|
|
|
const tooltipProps = {
|
|
|
|
props: {
|
|
|
|
prefixCls: tooltipPrefixCls,
|
|
|
|
title: tipFormatter ? tipFormatter(value) : '',
|
|
|
|
visible,
|
2020-03-07 19:45:13 +08:00
|
|
|
placement: tooltipPlacement || 'top',
|
|
|
|
transitionName: 'zoom-down',
|
|
|
|
overlayClassName: `${prefixCls}-tooltip`,
|
|
|
|
getPopupContainer: getTooltipPopupContainer || (() => document.body),
|
2018-04-01 19:23:56 +08:00
|
|
|
},
|
|
|
|
key: index,
|
2019-01-12 11:33:27 +08:00
|
|
|
};
|
2018-04-01 19:23:56 +08:00
|
|
|
const handleProps = {
|
|
|
|
props: {
|
|
|
|
value,
|
|
|
|
...restProps,
|
|
|
|
},
|
2019-01-05 11:22:53 +08:00
|
|
|
directives,
|
2018-04-01 19:23:56 +08:00
|
|
|
on: {
|
2019-01-05 11:22:53 +08:00
|
|
|
...on,
|
2018-04-01 19:23:56 +08:00
|
|
|
mouseenter: () => this.toggleTooltipVisible(index, true),
|
|
|
|
mouseleave: () => this.toggleTooltipVisible(index, false),
|
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
};
|
2018-04-01 19:23:56 +08:00
|
|
|
return (
|
2019-01-12 11:33:27 +08:00
|
|
|
<Tooltip {...tooltipProps}>
|
|
|
|
<VcHandle {...handleProps} />
|
2018-04-01 19:23:56 +08:00
|
|
|
</Tooltip>
|
2019-01-12 11:33:27 +08:00
|
|
|
);
|
2018-04-01 19:23:56 +08:00
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
focus() {
|
|
|
|
this.$refs.sliderRef.focus();
|
2018-04-01 19:23:56 +08:00
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
blur() {
|
|
|
|
this.$refs.sliderRef.blur();
|
2018-04-01 19:23:56 +08:00
|
|
|
},
|
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
render() {
|
2019-09-18 20:03:13 +08:00
|
|
|
const {
|
|
|
|
range,
|
|
|
|
prefixCls: customizePrefixCls,
|
|
|
|
tooltipPrefixCls: customizeTooltipPrefixCls,
|
|
|
|
...restProps
|
|
|
|
} = getOptionProps(this);
|
|
|
|
const getPrefixCls = this.configProvider.getPrefixCls;
|
2019-09-20 19:19:59 +08:00
|
|
|
const prefixCls = getPrefixCls('slider', customizePrefixCls);
|
|
|
|
const tooltipPrefixCls = getPrefixCls('tooltip', customizeTooltipPrefixCls);
|
2020-01-18 21:44:13 +08:00
|
|
|
const listeners = getListeners(this);
|
2018-04-01 19:23:56 +08:00
|
|
|
if (range) {
|
|
|
|
const vcRangeProps = {
|
|
|
|
props: {
|
|
|
|
...restProps,
|
2019-09-18 20:03:13 +08:00
|
|
|
prefixCls,
|
|
|
|
tooltipPrefixCls,
|
2020-03-07 19:45:13 +08:00
|
|
|
handle: info => this.handleWithTooltip(tooltipPrefixCls, prefixCls, info),
|
2018-04-01 19:23:56 +08:00
|
|
|
},
|
|
|
|
ref: 'sliderRef',
|
2020-01-18 21:44:13 +08:00
|
|
|
on: listeners,
|
2019-01-12 11:33:27 +08:00
|
|
|
};
|
|
|
|
return <VcRange {...vcRangeProps} />;
|
2018-04-01 19:23:56 +08:00
|
|
|
}
|
|
|
|
const vcSliderProps = {
|
|
|
|
props: {
|
|
|
|
...restProps,
|
2019-09-18 20:03:13 +08:00
|
|
|
prefixCls,
|
|
|
|
tooltipPrefixCls,
|
2020-03-07 19:45:13 +08:00
|
|
|
handle: info => this.handleWithTooltip(tooltipPrefixCls, prefixCls, info),
|
2018-04-01 19:23:56 +08:00
|
|
|
},
|
|
|
|
ref: 'sliderRef',
|
2020-01-18 21:44:13 +08:00
|
|
|
on: listeners,
|
2019-01-12 11:33:27 +08:00
|
|
|
};
|
|
|
|
return <VcSlider {...vcSliderProps} />;
|
2018-04-01 19:23:56 +08:00
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
};
|
2018-09-19 13:21:57 +08:00
|
|
|
|
|
|
|
/* istanbul ignore next */
|
2019-01-12 11:33:27 +08:00
|
|
|
Slider.install = function(Vue) {
|
2019-08-28 10:50:19 +08:00
|
|
|
Vue.use(Base);
|
2019-01-12 11:33:27 +08:00
|
|
|
Vue.component(Slider.name, Slider);
|
|
|
|
};
|
2018-09-19 13:21:57 +08:00
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
export default Slider;
|