refactor: slider to ts
parent
e1f979014d
commit
8a570fd653
|
@ -5,9 +5,9 @@ import Tooltip, { tooltipProps } from '../tooltip';
|
||||||
import raf from '../_util/raf';
|
import raf from '../_util/raf';
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
props: tooltipProps,
|
|
||||||
name: 'SliderTooltip',
|
name: 'SliderTooltip',
|
||||||
inheritAttrs: false,
|
inheritAttrs: false,
|
||||||
|
props: tooltipProps,
|
||||||
setup(props, { attrs, slots }) {
|
setup(props, { attrs, slots }) {
|
||||||
const innerRef = ref<any>(null);
|
const innerRef = ref<any>(null);
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,14 @@
|
||||||
import { computed, CSSProperties, ref, VNodeTypes } from 'vue';
|
import type { CSSProperties, VNodeTypes } from 'vue';
|
||||||
|
import { computed, ref } from 'vue';
|
||||||
import { defineComponent } from 'vue';
|
import { defineComponent } from 'vue';
|
||||||
import BaseMixin from '../_util/BaseMixin';
|
import BaseMixin from '../_util/BaseMixin';
|
||||||
import VcSlider from '../vc-slider/src/Slider';
|
import VcSlider from '../vc-slider/src/Slider';
|
||||||
import VcRange from '../vc-slider/src/Range';
|
import VcRange from '../vc-slider/src/Range';
|
||||||
import VcHandle from '../vc-slider/src/Handle';
|
import VcHandle from '../vc-slider/src/Handle';
|
||||||
import { VueNode, withInstall } from '../_util/type';
|
import type { VueNode } from '../_util/type';
|
||||||
import { PropType } from 'vue';
|
import { withInstall } from '../_util/type';
|
||||||
import { TooltipPlacement } from '../tooltip/Tooltip';
|
import type { PropType } from 'vue';
|
||||||
|
import type { TooltipPlacement } from '../tooltip/Tooltip';
|
||||||
import useConfigInject from '../_util/hooks/useConfigInject';
|
import useConfigInject from '../_util/hooks/useConfigInject';
|
||||||
import SliderTooltip from './SliderTooltip';
|
import SliderTooltip from './SliderTooltip';
|
||||||
import classNames from '../_util/classNames';
|
import classNames from '../_util/classNames';
|
||||||
|
@ -26,7 +28,6 @@ interface HandleGeneratorInfo {
|
||||||
value?: number;
|
value?: number;
|
||||||
dragging?: boolean;
|
dragging?: boolean;
|
||||||
index: number;
|
index: number;
|
||||||
rest?: any[];
|
|
||||||
}
|
}
|
||||||
interface SliderRange {
|
interface SliderRange {
|
||||||
draggableTrack?: boolean;
|
draggableTrack?: boolean;
|
||||||
|
@ -39,7 +40,7 @@ export type HandleGeneratorFn = (config: {
|
||||||
type Value = [number, number] | number;
|
type Value = [number, number] | number;
|
||||||
|
|
||||||
const defaultTipFormatter = (value: number) => (typeof value === 'number' ? value.toString() : '');
|
const defaultTipFormatter = (value: number) => (typeof value === 'number' ? value.toString() : '');
|
||||||
export const SliderProps = () => ({
|
export const sliderProps = () => ({
|
||||||
prefixCls: String,
|
prefixCls: String,
|
||||||
tooltipPrefixCls: String,
|
tooltipPrefixCls: String,
|
||||||
range: { type: [Boolean, Object] as PropType<boolean | SliderRange>, default: undefined },
|
range: { type: [Boolean, Object] as PropType<boolean | SliderRange>, default: undefined },
|
||||||
|
@ -77,7 +78,7 @@ const Slider = defineComponent({
|
||||||
mixins: [BaseMixin],
|
mixins: [BaseMixin],
|
||||||
inheritAttrs: false,
|
inheritAttrs: false,
|
||||||
props: {
|
props: {
|
||||||
...SliderProps(),
|
...sliderProps(),
|
||||||
},
|
},
|
||||||
emits: ['update:value', 'change', 'afterChange'],
|
emits: ['update:value', 'change', 'afterChange'],
|
||||||
slots: ['mark'],
|
slots: ['mark'],
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { computed, CSSProperties, defineComponent, ref } from 'vue';
|
import type { CSSProperties } from 'vue';
|
||||||
|
import { computed, defineComponent, ref } from 'vue';
|
||||||
import classNames from '../../_util/classNames';
|
import classNames from '../../_util/classNames';
|
||||||
import PropTypes from '../../_util/vue-types';
|
import PropTypes from '../../_util/vue-types';
|
||||||
import addEventListener from '../../vc-util/Dom/addEventListener';
|
import addEventListener from '../../vc-util/Dom/addEventListener';
|
||||||
|
@ -30,9 +31,9 @@ export default defineComponent({
|
||||||
clickFocused.value = true;
|
clickFocused.value = true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const handleBlur = () => {
|
const handleBlur = (e: FocusEvent) => {
|
||||||
clickFocused.value = false;
|
clickFocused.value = false;
|
||||||
emit('blur');
|
emit('blur', e);
|
||||||
};
|
};
|
||||||
const handleKeyDown = () => {
|
const handleKeyDown = () => {
|
||||||
clickFocused.value = false;
|
clickFocused.value = false;
|
||||||
|
@ -58,6 +59,7 @@ export default defineComponent({
|
||||||
focus,
|
focus,
|
||||||
blur,
|
blur,
|
||||||
clickFocus,
|
clickFocus,
|
||||||
|
ref: handle,
|
||||||
});
|
});
|
||||||
let onMouseUpListener = null;
|
let onMouseUpListener = null;
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
|
|
|
@ -7,7 +7,17 @@ import createSlider from './common/createSlider';
|
||||||
import * as utils from './utils';
|
import * as utils from './utils';
|
||||||
import initDefaultProps from '../../_util/props-util/initDefaultProps';
|
import initDefaultProps from '../../_util/props-util/initDefaultProps';
|
||||||
|
|
||||||
const trimAlignValue = ({ value, handle, bounds, props }) => {
|
const trimAlignValue = ({
|
||||||
|
value,
|
||||||
|
handle,
|
||||||
|
bounds,
|
||||||
|
props,
|
||||||
|
}: {
|
||||||
|
value: number;
|
||||||
|
handle: number;
|
||||||
|
bounds?: number[];
|
||||||
|
props: any;
|
||||||
|
}) => {
|
||||||
const { allowCross, pushable } = props;
|
const { allowCross, pushable } = props;
|
||||||
const thershold = Number(pushable);
|
const thershold = Number(pushable);
|
||||||
const valInRange = utils.ensureValueInRange(value, props);
|
const valInRange = utils.ensureValueInRange(value, props);
|
||||||
|
@ -332,7 +342,7 @@ const Range = {
|
||||||
|
|
||||||
pushSurroundingHandles(bounds, handle) {
|
pushSurroundingHandles(bounds, handle) {
|
||||||
const value = bounds[handle];
|
const value = bounds[handle];
|
||||||
let { pushable } = this;
|
const { pushable } = this;
|
||||||
const threshold = Number(pushable);
|
const threshold = Number(pushable);
|
||||||
|
|
||||||
let direction = 0;
|
let direction = 0;
|
||||||
|
|
|
@ -28,7 +28,7 @@ const Slider = defineComponent({
|
||||||
const defaultValue = this.defaultValue !== undefined ? this.defaultValue : this.min;
|
const defaultValue = this.defaultValue !== undefined ? this.defaultValue : this.min;
|
||||||
const value = this.value !== undefined ? this.value : defaultValue;
|
const value = this.value !== undefined ? this.value : defaultValue;
|
||||||
return {
|
return {
|
||||||
sValue: this.trimAlignValue(value),
|
sValue: (this as any).trimAlignValue(value),
|
||||||
dragging: false,
|
dragging: false,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { CSSProperties } from 'vue';
|
import type { CSSProperties } from 'vue';
|
||||||
import classNames from '../../../_util/classNames';
|
import classNames from '../../../_util/classNames';
|
||||||
import { VueNode } from '../../../_util/type';
|
import type { VueNode } from '../../../_util/type';
|
||||||
import warning from '../../../_util/warning';
|
import warning from '../../../_util/warning';
|
||||||
|
|
||||||
const calcPoints = (
|
const calcPoints = (
|
||||||
|
|
|
@ -66,7 +66,7 @@ export default function createSlider(Component) {
|
||||||
step && Math.floor(step) === step ? isPointDiffEven : true,
|
step && Math.floor(step) === step ? isPointDiffEven : true,
|
||||||
`Slider[max] - Slider[min] (${max - min}) should be a multiple of Slider[step] (${step})`,
|
`Slider[max] - Slider[min] (${max - min}) should be a multiple of Slider[step] (${step})`,
|
||||||
);
|
);
|
||||||
this.handlesRefs = {};
|
(this as any).handlesRefs = {};
|
||||||
return {};
|
return {};
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
|
|
|
@ -1,11 +1,8 @@
|
||||||
import keyCode from '../../_util/KeyCode';
|
import keyCode from '../../_util/KeyCode';
|
||||||
import { findDOMNode } from '../../_util/props-util';
|
|
||||||
|
|
||||||
export function isEventFromHandle(e: { target: HTMLElement }, handles) {
|
export function isEventFromHandle(e: { target: HTMLElement }, handles) {
|
||||||
try {
|
try {
|
||||||
return Object.keys(handles).some(
|
return Object.keys(handles).some(key => e.target === handles[key].ref);
|
||||||
key => e.target === findDOMNode(handles[key]) || e.target === handles[key],
|
|
||||||
);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue