@v-c/slider 1.0.2 → 1.0.4

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