@v-c/slider 1.0.3 → 1.0.5

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.
Files changed (76) hide show
  1. package/dist/Handles/Handle.cjs +191 -1
  2. package/dist/Handles/Handle.d.ts +4 -4
  3. package/dist/Handles/Handle.js +187 -204
  4. package/dist/Handles/index.cjs +108 -1
  5. package/dist/Handles/index.d.ts +1 -1
  6. package/dist/Handles/index.js +105 -120
  7. package/dist/Marks/Mark.cjs +51 -1
  8. package/dist/Marks/Mark.d.ts +2 -2
  9. package/dist/Marks/Mark.js +48 -39
  10. package/dist/Marks/index.cjs +39 -1
  11. package/dist/Marks/index.d.ts +2 -2
  12. package/dist/Marks/index.js +36 -32
  13. package/dist/Slider.cjs +557 -1
  14. package/dist/Slider.d.ts +53 -267
  15. package/dist/Slider.js +551 -352
  16. package/dist/Steps/Dot.cjs +52 -1
  17. package/dist/Steps/Dot.d.ts +2 -2
  18. package/dist/Steps/Dot.js +49 -38
  19. package/dist/Steps/index.cjs +64 -1
  20. package/dist/Steps/index.d.ts +2 -2
  21. package/dist/Steps/index.js +61 -41
  22. package/dist/Tracks/Track.cjs +74 -1
  23. package/dist/Tracks/Track.js +70 -81
  24. package/dist/Tracks/index.cjs +70 -1
  25. package/dist/Tracks/index.js +66 -82
  26. package/dist/_virtual/rolldown_runtime.cjs +21 -0
  27. package/dist/context.cjs +39 -1
  28. package/dist/context.d.ts +13 -7
  29. package/dist/context.js +29 -24
  30. package/dist/hooks/useDrag.cjs +160 -1
  31. package/dist/hooks/useDrag.d.ts +2 -2
  32. package/dist/hooks/useDrag.js +155 -86
  33. package/dist/hooks/useOffset.cjs +124 -1
  34. package/dist/hooks/useOffset.d.ts +2 -1
  35. package/dist/hooks/useOffset.js +122 -110
  36. package/dist/hooks/useRange.cjs +21 -1
  37. package/dist/hooks/useRange.js +18 -9
  38. package/dist/index.cjs +6 -1
  39. package/dist/index.d.ts +1 -0
  40. package/dist/index.js +4 -4
  41. package/dist/interface.cjs +0 -1
  42. package/dist/interface.js +0 -1
  43. package/dist/util.cjs +32 -1
  44. package/dist/util.js +27 -26
  45. package/package.json +18 -10
  46. package/docs/TooltipSlider.tsx +0 -94
  47. package/docs/assets/anim.less +0 -63
  48. package/docs/assets/bootstrap.less +0 -163
  49. package/docs/assets/index.less +0 -337
  50. package/docs/debug.vue +0 -59
  51. package/docs/editable.vue +0 -58
  52. package/docs/handle.vue +0 -51
  53. package/docs/marks.vue +0 -104
  54. package/docs/multiple.vue +0 -50
  55. package/docs/range.vue +0 -224
  56. package/docs/slider.stories.vue +0 -45
  57. package/docs/sliderDemo.vue +0 -283
  58. package/docs/vertical.vue +0 -135
  59. package/src/Handles/Handle.tsx +0 -232
  60. package/src/Handles/index.tsx +0 -132
  61. package/src/Marks/Mark.tsx +0 -40
  62. package/src/Marks/index.tsx +0 -40
  63. package/src/Slider.tsx +0 -602
  64. package/src/Steps/Dot.tsx +0 -40
  65. package/src/Steps/index.tsx +0 -54
  66. package/src/Tracks/Track.tsx +0 -89
  67. package/src/Tracks/index.tsx +0 -92
  68. package/src/context.ts +0 -65
  69. package/src/hooks/useDrag.ts +0 -243
  70. package/src/hooks/useOffset.ts +0 -272
  71. package/src/hooks/useRange.ts +0 -24
  72. package/src/index.ts +0 -8
  73. package/src/interface.ts +0 -17
  74. package/src/util.ts +0 -41
  75. package/vite.config.ts +0 -18
  76. package/vitest.config.ts +0 -11
@@ -1,232 +0,0 @@
1
- import type { CSSProperties, PropType } from 'vue'
2
- import type { OnStartMove, SliderClassNames, SliderStyles } from '../interface'
3
- import KeyCode from '@v-c/util/dist/KeyCode'
4
- import cls from 'classnames'
5
- import { defineComponent, ref } from 'vue'
6
- import { useInjectSlider } from '../context'
7
- import { getDirectionStyle, getIndex } from '../util'
8
-
9
- export interface RenderProps {
10
- index: number
11
- prefixCls: string
12
- value: number
13
- dragging: boolean
14
- draggingDelete: boolean
15
- node: any
16
- }
17
-
18
- export default defineComponent({
19
- name: 'Handle',
20
- props: {
21
- prefixCls: { type: String, required: true },
22
- value: { type: Number, required: true },
23
- valueIndex: { type: Number, required: true },
24
- dragging: { type: Boolean, default: false },
25
- draggingDelete: { type: Boolean, default: false },
26
- onStartMove: { type: Function as PropType<OnStartMove>, required: true },
27
- onDelete: { type: Function as PropType<(index: number) => void>, required: true },
28
- onOffsetChange: { type: Function as PropType<(value: number | 'min' | 'max', valueIndex: number) => void>, required: true },
29
- onFocus: { type: Function as PropType<(e: FocusEvent, index: number) => void>, required: true },
30
- onMouseenter: { type: Function as PropType<(e: MouseEvent, index: number) => void>, required: true },
31
- render: { type: Function as PropType<(v: RenderProps) => any> },
32
- onChangeComplete: Function as PropType<() => void>,
33
- mock: Boolean,
34
- classNames: Object as PropType<SliderClassNames>,
35
- styles: Object as PropType<SliderStyles>,
36
- },
37
- emits: ['focus', 'mouseenter', 'startMove', 'delete', 'offsetChange', 'changeComplete'],
38
- setup(props, { attrs, emit, expose }) {
39
- const {
40
- min,
41
- max,
42
- direction,
43
- disabled,
44
- keyboard,
45
- range,
46
- tabIndex,
47
- ariaLabelForHandle,
48
- ariaLabelledByForHandle,
49
- ariaRequired,
50
- ariaValueTextFormatterForHandle,
51
- } = useInjectSlider()
52
-
53
- const divProps = ref({})
54
- const handleClass = ref({})
55
- const handleStyle = ref({})
56
-
57
- // ============================ Events ============================
58
- const onInternalStartMove = (e: MouseEvent | TouchEvent) => {
59
- if (!disabled) {
60
- emit('startMove', e, props.valueIndex)
61
- }
62
- }
63
-
64
- const onInternalFocus = (e: FocusEvent) => {
65
- emit('focus', e, props.valueIndex)
66
- }
67
-
68
- const onInternalMouseEnter = (e: MouseEvent) => {
69
- emit('mouseenter', e, props.valueIndex)
70
- }
71
-
72
- // =========================== Keyboard ===========================
73
- const onKeyDown = (e: KeyboardEvent) => {
74
- if (!disabled && keyboard) {
75
- let offset: number | 'min' | 'max' | null = null
76
-
77
- // Change the value
78
- switch (e.which || e.keyCode) {
79
- case KeyCode.LEFT:
80
- offset = direction.value === 'ltr' || direction.value === 'btt' ? -1 : 1
81
- break
82
-
83
- case KeyCode.RIGHT:
84
- offset = direction.value === 'ltr' || direction.value === 'btt' ? 1 : -1
85
- break
86
-
87
- // Up is plus
88
- case KeyCode.UP:
89
- offset = direction.value !== 'ttb' ? 1 : -1
90
- break
91
-
92
- // Down is minus
93
- case KeyCode.DOWN:
94
- offset = direction.value !== 'ttb' ? -1 : 1
95
- break
96
-
97
- case KeyCode.HOME:
98
- offset = 'min'
99
- break
100
-
101
- case KeyCode.END:
102
- offset = 'max'
103
- break
104
-
105
- case KeyCode.PAGE_UP:
106
- offset = 2
107
- break
108
-
109
- case KeyCode.PAGE_DOWN:
110
- offset = -2
111
- break
112
-
113
- case KeyCode.BACKSPACE:
114
- case KeyCode.DELETE:
115
- emit('delete', e, props.valueIndex)
116
- break
117
- }
118
-
119
- if (offset !== null) {
120
- e.preventDefault()
121
- emit('offsetChange', offset, props.valueIndex)
122
- }
123
- }
124
- }
125
-
126
- const handleKeyUp = (e: KeyboardEvent) => {
127
- switch (e.which || e.keyCode) {
128
- case KeyCode.LEFT:
129
- case KeyCode.RIGHT:
130
- case KeyCode.UP:
131
- case KeyCode.DOWN:
132
- case KeyCode.HOME:
133
- case KeyCode.END:
134
- case KeyCode.PAGE_UP:
135
- case KeyCode.PAGE_DOWN:
136
- emit('changeComplete')
137
- break
138
- }
139
- }
140
- expose({
141
- focus: () => props.valueIndex,
142
- })
143
-
144
- return () => {
145
- const {
146
- prefixCls,
147
- value,
148
- valueIndex,
149
- onStartMove,
150
- onDelete,
151
- render,
152
- dragging,
153
- draggingDelete,
154
- onOffsetChange,
155
- onChangeComplete,
156
- onFocus,
157
- onMouseenter,
158
- styles,
159
- classNames,
160
- ...restProps
161
- } = props
162
- // ============================ Offset ============================
163
- const positionStyle = getDirectionStyle(direction.value, value, min.value, max.value)
164
- // ============================ Render ============================
165
-
166
- if (valueIndex !== null) {
167
- divProps.value = {
168
- 'tabindex': disabled ? null : getIndex(tabIndex, valueIndex),
169
- 'role': 'slider',
170
- 'aria-valuemin': min.value,
171
- 'aria-valuemax': max.value,
172
- 'aria-valuenow': value,
173
- 'aria-disabled': disabled,
174
- 'aria-label': getIndex(ariaLabelForHandle, valueIndex),
175
- 'aria-labelledby': getIndex(ariaLabelledByForHandle, valueIndex),
176
- 'aria-required': getIndex(ariaRequired, valueIndex),
177
- 'aria-valuetext': getIndex(ariaValueTextFormatterForHandle, valueIndex)?.(value),
178
- 'aria-orientation': direction.value === 'ltr' || direction.value === 'rtl' ? 'horizontal' : 'vertical',
179
- 'onMousedown': onInternalStartMove,
180
- 'onTouchstart': onInternalStartMove,
181
- 'onFocus': onInternalFocus,
182
- 'onMouseenter': onInternalMouseEnter,
183
- 'onKeydown': onKeyDown,
184
- 'onKeyup': handleKeyUp,
185
- ...restProps,
186
- }
187
- }
188
- else {
189
- divProps.value = {
190
- ...restProps,
191
- }
192
- }
193
- const handlePrefixCls = `${prefixCls}-handle`
194
- handleClass.value = cls(
195
- handlePrefixCls,
196
- {
197
- [`${handlePrefixCls}-${valueIndex + 1}`]: valueIndex !== null && range,
198
- [`${handlePrefixCls}-dragging`]: dragging,
199
- [`${handlePrefixCls}-dragging-delete`]: draggingDelete,
200
- },
201
- classNames?.handle,
202
- )
203
- handleStyle.value = {
204
- ...positionStyle,
205
- ...attrs.style as CSSProperties,
206
- ...styles?.handle,
207
- }
208
- const handleNode = (
209
- <div
210
- class={handleClass.value}
211
- style={handleStyle.value}
212
- {...divProps.value}
213
- />
214
- )
215
- // Customize
216
- if (render) {
217
- const renderProps = {
218
- index: valueIndex,
219
- prefixCls,
220
- value,
221
- dragging,
222
- draggingDelete,
223
- node: handleNode,
224
- }
225
-
226
- const RenderNode = () => render(renderProps)
227
- return <RenderNode />
228
- }
229
- return handleNode
230
- }
231
- },
232
- })
@@ -1,132 +0,0 @@
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 RenderProps {
8
- index: number
9
- prefixCls: string
10
- value: number
11
- dragging: boolean
12
- draggingDelete: boolean
13
- node: any
14
- }
15
- export interface HandlesRef {
16
- focus: (index: number) => void
17
- hideHelp: VoidFunction
18
- }
19
-
20
- export default defineComponent({
21
- name: 'Handles',
22
- props: {
23
- prefixCls: { type: String, required: true },
24
- values: { type: Array, required: true },
25
- handleStyle: { type: [Object, Array] as PropType<CSSProperties | CSSProperties[]> },
26
- onStartMove: { type: Function as PropType<OnStartMove>, required: true },
27
- onOffsetChange: { type: Function as PropType<(value: number | 'min' | 'max', valueIndex: number) => void>, required: true },
28
- onFocus: { type: Function as PropType<(e: FocusEvent) => void> },
29
- onBlur: { type: Function as PropType<(e: FocusEvent) => void> },
30
- onDelete: { type: Function as PropType<(index: number) => void>, required: true },
31
- handleRender: { type: Function as PropType<(props: RenderProps) => any> },
32
- activeHandleRender: { type: Function as PropType<(props: RenderProps) => any> },
33
- draggingIndex: { type: Number, default: -1 },
34
- draggingDelete: { type: Boolean, default: false },
35
- onChangeComplete: Function as PropType<() => void>,
36
- },
37
- emits: ['focus'],
38
- slots: Object as SlotsType<{
39
- activeHandleRender: any
40
- handleRender: any
41
- }>,
42
- setup(props, { emit, expose }) {
43
- const handlesRef = ref()
44
-
45
- // =========================== Active ===========================
46
- const activeVisible = ref(false)
47
- const activeIndex = ref(-1)
48
-
49
- const onActive = (index: number) => {
50
- activeIndex.value = index
51
- activeVisible.value = true
52
- }
53
-
54
- const onHandleFocus = (e: FocusEvent, index: number) => {
55
- onActive(index)
56
- emit('focus', e)
57
- }
58
-
59
- const onHandleMouseEnter = (_e: MouseEvent, index: number) => {
60
- onActive(index)
61
- }
62
-
63
- expose({
64
- focus: () => handlesRef.value?.focus(),
65
- hideHelp: () => {
66
- activeVisible.value = false
67
- },
68
- })
69
-
70
- return () => {
71
- const {
72
- prefixCls,
73
- onStartMove,
74
- onOffsetChange,
75
- values,
76
- handleRender,
77
- activeHandleRender,
78
- draggingIndex,
79
- draggingDelete,
80
- onFocus,
81
- handleStyle,
82
- ...restProps
83
- } = props
84
-
85
- // =========================== Render ===========================
86
- // Handle Props
87
- const handleProps = {
88
- prefixCls,
89
- onStartMove,
90
- onOffsetChange,
91
- render: handleRender,
92
- onFocus: onHandleFocus,
93
- onMouseenter: onHandleMouseEnter,
94
- ...restProps,
95
- }
96
- return (
97
- <>
98
- {values?.map((value: unknown, index: number) => {
99
- const dragging = draggingIndex === index
100
- return (
101
- <Handle
102
- ref={handlesRef.value}
103
- dragging={dragging}
104
- draggingDelete={dragging && draggingDelete}
105
- style={getIndex(handleStyle, index)}
106
- key={index}
107
- value={value as number}
108
- valueIndex={index}
109
- {...handleProps}
110
- />
111
- )
112
- })}
113
-
114
- {/* Used for render tooltip, this is not a real handle */}
115
- {activeHandleRender && activeVisible.value && (
116
- <Handle
117
- key="a11y"
118
- {...handleProps}
119
- value={values[activeIndex.value] as number}
120
- valueIndex={1}
121
- dragging={draggingIndex !== -1}
122
- draggingDelete={draggingDelete}
123
- render={activeHandleRender}
124
- style={{ pointerEvents: 'none' }}
125
- aria-hidden
126
- />
127
- )}
128
- </>
129
- )
130
- }
131
- },
132
- })
@@ -1,40 +0,0 @@
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
@@ -1,40 +0,0 @@
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, slots }) => {
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
- {slots.mark?.({ point: value, label }) || label}
34
- </Mark>
35
- ))}
36
- </div>
37
- )
38
- }
39
-
40
- export default Marks