@v-c/slider 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/Handles/Handle.cjs +1 -0
- package/dist/Handles/Handle.d.ts +107 -0
- package/dist/Handles/Handle.js +203 -0
- package/dist/Handles/index.cjs +1 -0
- package/dist/Handles/index.d.ts +98 -0
- package/dist/Handles/index.js +117 -0
- package/dist/Marks/Mark.cjs +1 -0
- package/dist/Marks/Mark.d.ts +9 -0
- package/dist/Marks/Mark.js +39 -0
- package/dist/Marks/index.cjs +1 -0
- package/dist/Marks/index.d.ts +15 -0
- package/dist/Marks/index.js +31 -0
- package/dist/Slider.cjs +1 -0
- package/dist/Slider.d.ts +253 -0
- package/dist/Slider.js +343 -0
- package/dist/Steps/Dot.cjs +1 -0
- package/dist/Steps/Dot.d.ts +9 -0
- package/dist/Steps/Dot.js +38 -0
- package/dist/Steps/index.cjs +1 -0
- package/dist/Steps/index.d.ts +11 -0
- package/dist/Steps/index.js +41 -0
- package/dist/Tracks/Track.cjs +1 -0
- package/dist/Tracks/Track.d.ts +61 -0
- package/dist/Tracks/Track.js +82 -0
- package/dist/Tracks/index.cjs +1 -0
- package/dist/Tracks/index.d.ts +47 -0
- package/dist/Tracks/index.js +83 -0
- package/dist/context.cjs +1 -0
- package/dist/context.d.ts +51 -0
- package/dist/context.js +27 -0
- package/dist/hooks/useDrag.cjs +1 -0
- package/dist/hooks/useDrag.d.ts +11 -0
- package/dist/hooks/useDrag.js +88 -0
- package/dist/hooks/useOffset.cjs +1 -0
- package/dist/hooks/useOffset.d.ts +10 -0
- package/dist/hooks/useOffset.js +98 -0
- package/dist/hooks/useRange.cjs +1 -0
- package/dist/hooks/useRange.d.ts +8 -0
- package/dist/hooks/useRange.js +10 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +4 -0
- package/dist/interface.cjs +1 -0
- package/dist/interface.d.ts +7 -0
- package/dist/interface.js +1 -0
- package/dist/util.cjs +1 -0
- package/dist/util.d.ts +6 -0
- package/dist/util.js +29 -0
- package/docs/TooltipSlider.tsx +94 -0
- package/docs/assets/anim.less +63 -0
- package/docs/assets/bootstrap.less +163 -0
- package/docs/assets/index.less +337 -0
- package/docs/debug.vue +60 -0
- package/docs/editable.vue +59 -0
- package/docs/handle.vue +45 -0
- package/docs/marks.vue +85 -0
- package/docs/multiple.vue +54 -0
- package/docs/range.vue +211 -0
- package/docs/slider.stories.vue +45 -0
- package/docs/sliderDemo.vue +267 -0
- package/docs/vertical.vue +122 -0
- package/package.json +35 -0
- package/src/Handles/Handle.tsx +226 -0
- package/src/Handles/index.tsx +124 -0
- package/src/Marks/Mark.tsx +40 -0
- package/src/Marks/index.tsx +40 -0
- package/src/Slider.tsx +582 -0
- package/src/Steps/Dot.tsx +40 -0
- package/src/Steps/index.tsx +54 -0
- package/src/Tracks/Track.tsx +89 -0
- package/src/Tracks/index.tsx +92 -0
- package/src/context.ts +65 -0
- package/src/hooks/useDrag.ts +244 -0
- package/src/hooks/useOffset.ts +264 -0
- package/src/hooks/useRange.ts +24 -0
- package/src/index.ts +8 -0
- package/src/interface.ts +17 -0
- package/src/util.ts +41 -0
- package/vite.config.ts +18 -0
- package/vitest.config.ts +11 -0
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import type { CSSProperties, PropType, SlotsType } from 'vue'
|
|
2
|
+
import type { OnStartMove } from '../interface'
|
|
3
|
+
import { defineComponent, ref } from 'vue'
|
|
4
|
+
import { getIndex } from '../util'
|
|
5
|
+
import Handle from './Handle'
|
|
6
|
+
|
|
7
|
+
export interface HandlesRef {
|
|
8
|
+
focus: (index: number) => void
|
|
9
|
+
hideHelp: VoidFunction
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export default defineComponent({
|
|
13
|
+
name: 'Handles',
|
|
14
|
+
props: {
|
|
15
|
+
prefixCls: { type: String, required: true },
|
|
16
|
+
values: { type: Array, required: true },
|
|
17
|
+
handleStyle: { type: [Object, Array] as PropType<CSSProperties | CSSProperties[]> },
|
|
18
|
+
onStartMove: { type: Function as PropType<OnStartMove>, required: true },
|
|
19
|
+
onOffsetChange: { type: Function as PropType<(value: number | 'min' | 'max', valueIndex: number) => void>, required: true },
|
|
20
|
+
onFocus: { type: Function as PropType<(e: FocusEvent) => void> },
|
|
21
|
+
onBlur: { type: Function as PropType<(e: FocusEvent) => void> },
|
|
22
|
+
onDelete: { type: Function as PropType<(index: number) => void>, required: true },
|
|
23
|
+
handleRender: Function,
|
|
24
|
+
activeHandleRender: Function,
|
|
25
|
+
draggingIndex: { type: Number, default: -1 },
|
|
26
|
+
draggingDelete: { type: Boolean, default: false },
|
|
27
|
+
onChangeComplete: Function as PropType<() => void>,
|
|
28
|
+
},
|
|
29
|
+
emits: ['focus'],
|
|
30
|
+
slots: Object as SlotsType<{
|
|
31
|
+
activeHandleRender: any
|
|
32
|
+
handleRender: any
|
|
33
|
+
}>,
|
|
34
|
+
setup(props, { emit, expose }) {
|
|
35
|
+
const handlesRef = ref()
|
|
36
|
+
|
|
37
|
+
// =========================== Active ===========================
|
|
38
|
+
const activeVisible = ref(false)
|
|
39
|
+
const activeIndex = ref(-1)
|
|
40
|
+
|
|
41
|
+
const onActive = (index: number) => {
|
|
42
|
+
activeIndex.value = index
|
|
43
|
+
activeVisible.value = true
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const onHandleFocus = (e: FocusEvent, index: number) => {
|
|
47
|
+
onActive(index)
|
|
48
|
+
emit('focus', e)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const onHandleMouseEnter = (_e: MouseEvent, index: number) => {
|
|
52
|
+
onActive(index)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
expose({
|
|
56
|
+
focus: () => handlesRef.value?.focus(),
|
|
57
|
+
hideHelp: () => {
|
|
58
|
+
activeVisible.value = false
|
|
59
|
+
},
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
return () => {
|
|
63
|
+
const {
|
|
64
|
+
prefixCls,
|
|
65
|
+
onStartMove,
|
|
66
|
+
onOffsetChange,
|
|
67
|
+
values,
|
|
68
|
+
handleRender,
|
|
69
|
+
activeHandleRender,
|
|
70
|
+
draggingIndex,
|
|
71
|
+
draggingDelete,
|
|
72
|
+
onFocus,
|
|
73
|
+
handleStyle,
|
|
74
|
+
...restProps
|
|
75
|
+
} = props
|
|
76
|
+
|
|
77
|
+
// =========================== Render ===========================
|
|
78
|
+
// Handle Props
|
|
79
|
+
const handleProps = {
|
|
80
|
+
prefixCls,
|
|
81
|
+
onStartMove,
|
|
82
|
+
onOffsetChange,
|
|
83
|
+
render: handleRender,
|
|
84
|
+
onFocus: onHandleFocus,
|
|
85
|
+
onMouseenter: onHandleMouseEnter,
|
|
86
|
+
...restProps,
|
|
87
|
+
}
|
|
88
|
+
return (
|
|
89
|
+
<>
|
|
90
|
+
{values?.map((value: unknown, index: number) => {
|
|
91
|
+
const dragging = draggingIndex === index
|
|
92
|
+
return (
|
|
93
|
+
<Handle
|
|
94
|
+
ref={handlesRef.value}
|
|
95
|
+
dragging={dragging}
|
|
96
|
+
draggingDelete={dragging && draggingDelete}
|
|
97
|
+
style={getIndex(handleStyle, index)}
|
|
98
|
+
key={index}
|
|
99
|
+
value={value as number}
|
|
100
|
+
valueIndex={index}
|
|
101
|
+
{...handleProps}
|
|
102
|
+
/>
|
|
103
|
+
)
|
|
104
|
+
})}
|
|
105
|
+
|
|
106
|
+
{/* Used for render tooltip, this is not a real handle */}
|
|
107
|
+
{activeHandleRender && activeVisible.value && (
|
|
108
|
+
<Handle
|
|
109
|
+
key="a11y"
|
|
110
|
+
{...handleProps}
|
|
111
|
+
value={values[activeIndex.value] as number}
|
|
112
|
+
valueIndex={1}
|
|
113
|
+
dragging={draggingIndex !== -1}
|
|
114
|
+
draggingDelete={draggingDelete}
|
|
115
|
+
render={activeHandleRender}
|
|
116
|
+
style={{ pointerEvents: 'none' }}
|
|
117
|
+
aria-hidden
|
|
118
|
+
/>
|
|
119
|
+
)}
|
|
120
|
+
</>
|
|
121
|
+
)
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
})
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { CSSProperties, FunctionalComponent } from 'vue'
|
|
2
|
+
import classNames from 'classnames'
|
|
3
|
+
import { useInjectSlider } from '../context'
|
|
4
|
+
import { getDirectionStyle } from '../util'
|
|
5
|
+
|
|
6
|
+
export interface MarkProps {
|
|
7
|
+
prefixCls: string
|
|
8
|
+
value: number
|
|
9
|
+
style?: CSSProperties
|
|
10
|
+
onClick?: Function
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const Mark: FunctionalComponent<MarkProps> = (props, { attrs, slots, emit }) => {
|
|
14
|
+
const { prefixCls, value } = props
|
|
15
|
+
const { min, max, direction, includedStart, includedEnd, included } = useInjectSlider()
|
|
16
|
+
|
|
17
|
+
const textCls = `${prefixCls}-text`
|
|
18
|
+
|
|
19
|
+
// ============================ Offset ============================
|
|
20
|
+
const positionStyle = getDirectionStyle(direction.value, value, min.value, max.value)
|
|
21
|
+
|
|
22
|
+
return (
|
|
23
|
+
<span
|
|
24
|
+
class={classNames(textCls, {
|
|
25
|
+
[`${textCls}-active`]: included && includedStart <= value && value <= includedEnd,
|
|
26
|
+
})}
|
|
27
|
+
style={{ ...positionStyle, ...attrs.style as CSSProperties }}
|
|
28
|
+
onMousedown={(e: MouseEvent) => {
|
|
29
|
+
e.stopPropagation()
|
|
30
|
+
}}
|
|
31
|
+
onClick={() => {
|
|
32
|
+
emit('click', value)
|
|
33
|
+
}}
|
|
34
|
+
>
|
|
35
|
+
{slots.default?.()}
|
|
36
|
+
</span>
|
|
37
|
+
)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export default Mark
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { CSSProperties, FunctionalComponent } from 'vue'
|
|
2
|
+
import Mark from './Mark'
|
|
3
|
+
|
|
4
|
+
export interface MarkObj {
|
|
5
|
+
style?: CSSProperties
|
|
6
|
+
label?: any
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface InternalMarkObj extends MarkObj {
|
|
10
|
+
value: number
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface MarksProps {
|
|
14
|
+
prefixCls: string
|
|
15
|
+
marks?: InternalMarkObj[]
|
|
16
|
+
onClick?: (value: number) => void
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const Marks: FunctionalComponent<MarksProps> = (props, { emit }) => {
|
|
20
|
+
const { prefixCls, marks = [] } = props
|
|
21
|
+
|
|
22
|
+
const markPrefixCls = `${prefixCls}-mark`
|
|
23
|
+
|
|
24
|
+
// Not render mark if empty
|
|
25
|
+
if (!marks.length) {
|
|
26
|
+
return null
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return (
|
|
30
|
+
<div class={markPrefixCls}>
|
|
31
|
+
{marks.map(({ value, style, label }) => (
|
|
32
|
+
<Mark key={value} prefixCls={markPrefixCls} style={style} value={value} onClick={() => emit('click', value)}>
|
|
33
|
+
{label}
|
|
34
|
+
</Mark>
|
|
35
|
+
))}
|
|
36
|
+
</div>
|
|
37
|
+
)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export default Marks
|