@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.
Files changed (81) hide show
  1. package/LICENSE +21 -0
  2. package/dist/Handles/Handle.cjs +1 -0
  3. package/dist/Handles/Handle.d.ts +107 -0
  4. package/dist/Handles/Handle.js +203 -0
  5. package/dist/Handles/index.cjs +1 -0
  6. package/dist/Handles/index.d.ts +98 -0
  7. package/dist/Handles/index.js +117 -0
  8. package/dist/Marks/Mark.cjs +1 -0
  9. package/dist/Marks/Mark.d.ts +9 -0
  10. package/dist/Marks/Mark.js +39 -0
  11. package/dist/Marks/index.cjs +1 -0
  12. package/dist/Marks/index.d.ts +15 -0
  13. package/dist/Marks/index.js +31 -0
  14. package/dist/Slider.cjs +1 -0
  15. package/dist/Slider.d.ts +253 -0
  16. package/dist/Slider.js +343 -0
  17. package/dist/Steps/Dot.cjs +1 -0
  18. package/dist/Steps/Dot.d.ts +9 -0
  19. package/dist/Steps/Dot.js +38 -0
  20. package/dist/Steps/index.cjs +1 -0
  21. package/dist/Steps/index.d.ts +11 -0
  22. package/dist/Steps/index.js +41 -0
  23. package/dist/Tracks/Track.cjs +1 -0
  24. package/dist/Tracks/Track.d.ts +61 -0
  25. package/dist/Tracks/Track.js +82 -0
  26. package/dist/Tracks/index.cjs +1 -0
  27. package/dist/Tracks/index.d.ts +47 -0
  28. package/dist/Tracks/index.js +83 -0
  29. package/dist/context.cjs +1 -0
  30. package/dist/context.d.ts +51 -0
  31. package/dist/context.js +27 -0
  32. package/dist/hooks/useDrag.cjs +1 -0
  33. package/dist/hooks/useDrag.d.ts +11 -0
  34. package/dist/hooks/useDrag.js +88 -0
  35. package/dist/hooks/useOffset.cjs +1 -0
  36. package/dist/hooks/useOffset.d.ts +10 -0
  37. package/dist/hooks/useOffset.js +98 -0
  38. package/dist/hooks/useRange.cjs +1 -0
  39. package/dist/hooks/useRange.d.ts +8 -0
  40. package/dist/hooks/useRange.js +10 -0
  41. package/dist/index.cjs +1 -0
  42. package/dist/index.d.ts +3 -0
  43. package/dist/index.js +4 -0
  44. package/dist/interface.cjs +1 -0
  45. package/dist/interface.d.ts +7 -0
  46. package/dist/interface.js +1 -0
  47. package/dist/util.cjs +1 -0
  48. package/dist/util.d.ts +6 -0
  49. package/dist/util.js +29 -0
  50. package/docs/TooltipSlider.tsx +94 -0
  51. package/docs/assets/anim.less +63 -0
  52. package/docs/assets/bootstrap.less +163 -0
  53. package/docs/assets/index.less +337 -0
  54. package/docs/debug.vue +60 -0
  55. package/docs/editable.vue +59 -0
  56. package/docs/handle.vue +45 -0
  57. package/docs/marks.vue +85 -0
  58. package/docs/multiple.vue +54 -0
  59. package/docs/range.vue +211 -0
  60. package/docs/slider.stories.vue +45 -0
  61. package/docs/sliderDemo.vue +267 -0
  62. package/docs/vertical.vue +122 -0
  63. package/package.json +35 -0
  64. package/src/Handles/Handle.tsx +226 -0
  65. package/src/Handles/index.tsx +124 -0
  66. package/src/Marks/Mark.tsx +40 -0
  67. package/src/Marks/index.tsx +40 -0
  68. package/src/Slider.tsx +582 -0
  69. package/src/Steps/Dot.tsx +40 -0
  70. package/src/Steps/index.tsx +54 -0
  71. package/src/Tracks/Track.tsx +89 -0
  72. package/src/Tracks/index.tsx +92 -0
  73. package/src/context.ts +65 -0
  74. package/src/hooks/useDrag.ts +244 -0
  75. package/src/hooks/useOffset.ts +264 -0
  76. package/src/hooks/useRange.ts +24 -0
  77. package/src/index.ts +8 -0
  78. package/src/interface.ts +17 -0
  79. package/src/util.ts +41 -0
  80. package/vite.config.ts +18 -0
  81. package/vitest.config.ts +11 -0
package/docs/debug.vue ADDED
@@ -0,0 +1,60 @@
1
+ <script setup>
2
+ import { ref } from 'vue'
3
+ import Slider from '../src'
4
+
5
+ const disabled = ref(false)
6
+ const range = ref(false)
7
+ const reverse = ref(false)
8
+ const vertical = ref(false)
9
+ const data = ref()
10
+
11
+ function handleSliderChange(nextValues) {
12
+ console.log('Change:', nextValues)
13
+ data.value = nextValues
14
+ }
15
+
16
+ function handleSliderChangeComplete(v) {
17
+ console.log('AfterChange:', v)
18
+ }
19
+ </script>
20
+
21
+ <template>
22
+ <div>
23
+ <div>
24
+ <label>
25
+ <input v-model="disabled" type="checkbox">
26
+ Disabled
27
+ </label>
28
+ <label>
29
+ <input v-model="range" type="checkbox">
30
+ Range
31
+ </label>
32
+ <label>
33
+ <input v-model="reverse" type="checkbox">
34
+ Reverse
35
+ </label>
36
+ <label>
37
+ <input v-model="vertical" type="checkbox">
38
+ Vertical
39
+ </label>
40
+ </div>
41
+
42
+ <div style="height: 300px; width: 600px;">
43
+ <Slider
44
+ :disabled="disabled"
45
+ :value="data"
46
+ :step="0.01"
47
+ :default-value="0.81"
48
+ :min="0"
49
+ :max="1"
50
+ :vertical="vertical"
51
+ :reverse="reverse"
52
+ @change="handleSliderChange"
53
+ @change-complete="handleSliderChangeComplete"
54
+ />
55
+ </div>
56
+ </div>
57
+ </template>
58
+
59
+ <style scoped>
60
+ </style>
@@ -0,0 +1,59 @@
1
+ <script setup lang="ts">
2
+ import type { UnstableContextProps } from '../src/context'
3
+ import { ref } from 'vue'
4
+ import Slider from '../src'
5
+
6
+ const style = {
7
+ width: '400px',
8
+ margin: '50px',
9
+ }
10
+
11
+ const value = ref([0, 50, 80])
12
+
13
+ function onDragStart(info: Parameters<UnstableContextProps['onDragStart']>[0]) {
14
+ const { rawValues } = info
15
+ console.log('Start:', rawValues)
16
+ }
17
+
18
+ function onDragChange(info: Parameters<UnstableContextProps['onDragChange']>[0]) {
19
+ const { rawValues } = info
20
+ console.log('Move:', rawValues)
21
+ }
22
+
23
+ function handleChange(nextValue: number[]) {
24
+ console.error('Change:', nextValue)
25
+ value.value = nextValue
26
+ }
27
+
28
+ function handleChangeComplete(nextValue: number[]) {
29
+ console.log('Complete', nextValue)
30
+ }
31
+ </script>
32
+
33
+ <template>
34
+ <div>
35
+ <div :style="style">
36
+ <Slider
37
+ :range="{
38
+ editable: true,
39
+ minCount: 1,
40
+ maxCount: 4,
41
+ }"
42
+ :min="0"
43
+ :max="100"
44
+ :value="value"
45
+ :styles="{
46
+ rail: {
47
+ background: 'linear-gradient(to right, blue, red)',
48
+ },
49
+ track: {
50
+ background: 'orange',
51
+ },
52
+ }"
53
+ @change="handleChange"
54
+ @change-complete="handleChangeComplete"
55
+ />
56
+ </div>
57
+ <p>Here is a word that drag should not select it</p>
58
+ </div>
59
+ </template>
@@ -0,0 +1,45 @@
1
+ <script setup lang="ts">
2
+ import type { CSSProperties } from 'vue'
3
+ import Slider from '@v-c/slider'
4
+ import TooltipSlider, { HandleRender } from './TooltipSlider.tsx'
5
+
6
+ const wrapperStyle: CSSProperties = {
7
+ width: '400px',
8
+ margin: '50px',
9
+ }
10
+ </script>
11
+
12
+ <template>
13
+ <div>
14
+ <div :style="wrapperStyle">
15
+ <p>Slider with custom handle</p>
16
+ <Slider :min="0" :max="20" :default-value="3" :handle-render="HandleRender" />
17
+ </div>
18
+ <div :style="wrapperStyle">
19
+ <p>Reversed Slider with custom handle</p>
20
+ <Slider :min="0" :max="20" reverse :default-value="3" :handle-render="HandleRender"/>
21
+ </div>
22
+ <div :style="wrapperStyle">
23
+ <p>Slider with fixed values</p>
24
+ <Slider :min="20" :default-value="20" :marks="{ 20: 20, 40: 40, 100: 100 }" :step="null" />
25
+ </div>
26
+ <div :style="wrapperStyle">
27
+ <p>Range with custom tooltip</p>
28
+ <TooltipSlider
29
+ range
30
+ :min="0"
31
+ :max="20"
32
+ :default-value="[3, 10]"
33
+ :tip-formatter="(value) => (`${value}!`)"
34
+ />
35
+ </div>
36
+ <div :style="wrapperStyle">
37
+ <p>Keyboard events disabled</p>
38
+ <Slider :default-value="3" :keyboard="false" />
39
+ </div>
40
+ </div>
41
+ </template>
42
+
43
+ <style scoped>
44
+
45
+ </style>
package/docs/marks.vue ADDED
@@ -0,0 +1,85 @@
1
+ <script setup lang="ts">
2
+ import type { CSSProperties } from 'vue'
3
+ import Slider from '@v-c/slider'
4
+
5
+ const style: CSSProperties = {
6
+ width: '400px',
7
+ margin: '50px',
8
+ }
9
+
10
+ const marks = {
11
+ '-10': '-10°C',
12
+ '0': '0°C',
13
+ '26': '26°C',
14
+ '37': '37°C',
15
+ '50': '50°C',
16
+ '100': {
17
+ style: {
18
+ color: 'red',
19
+ },
20
+ label: '100°C',
21
+ },
22
+ }
23
+
24
+ function log(value) {
25
+ console.log(value); //eslint-disable-line
26
+ }
27
+ </script>
28
+
29
+ <template>
30
+ <div>
31
+ <div :style="style">
32
+ <p>Slider with marks, `step=null`</p>
33
+ <Slider
34
+ :min="-10"
35
+ :marks="marks"
36
+ :step="null"
37
+ :default-value="20"
38
+ @change="log"
39
+ @change-complete="(v) => console.log('AfterChange', v)"
40
+ />
41
+ </div>
42
+
43
+ <div :style="style">
44
+ <p>Range Slider with marks, `step=null`, pushable, draggableTrack</p>
45
+ <Slider
46
+ range
47
+ :min="-10"
48
+ :marks="marks"
49
+ :step="null"
50
+ :default-value="[-10, 0]"
51
+ :allow-cross="false"
52
+ pushable
53
+ @change="log"
54
+ @change-complete="(v) => console.log('AfterChange', v)"
55
+ />
56
+ </div>
57
+
58
+ <div :style="style">
59
+ <p>Slider with marks and steps</p>
60
+ <Slider dots :min="-10" :marks="marks" :step="10" :default-value="20" @change="log" />
61
+ </div>
62
+ <div :style="style">
63
+ <p>Reversed Slider with marks and steps</p>
64
+ <Slider dots reverse :min="-10" :marks="marks" :step="10" :default-value="20" @change="log" />
65
+ </div>
66
+
67
+ <div :style="style">
68
+ <p>Slider with marks, `included=false`</p>
69
+ <Slider :min="-10" :marks="marks" :included="false" :default-value="20" />
70
+ </div>
71
+ <div :style="style">
72
+ <p>Slider with marks and steps, `included=false`</p>
73
+ <Slider :min="-10" :marks="marks" :step="10" :included="false" :default-value="20" />
74
+ </div>
75
+
76
+ <div :style="style">
77
+ <p>Range with marks</p>
78
+ <Slider range :min="-10" :marks="marks" :default-value="[20, 25, 30, 40]" @change="log" />
79
+ </div>
80
+ <div :style="style">
81
+ <p>Range with marks and steps</p>
82
+ <Slider range :min="-10" :marks="marks" :step="10" :default-value="[20, 40]" @change="log" />
83
+ </div>
84
+ </div>
85
+ </template>
@@ -0,0 +1,54 @@
1
+ <script setup lang="ts">
2
+ import type { CSSProperties, VNode } from 'vue'
3
+ import Slider from '@v-c/slider'
4
+ import { h, ref } from 'vue'
5
+
6
+ const style: CSSProperties = {
7
+ width: '400px',
8
+ margin: '50px',
9
+ }
10
+
11
+ // const NodeWrapper = ({ children }: { children: React.ReactElement }) => {
12
+ // return <div>{React.cloneElement(children, {}, <div>TOOLTIP</div>)}</div>;
13
+ // };
14
+
15
+ function NodeWrapper(props: any): VNode {
16
+ return h('div', {}, [
17
+ h('slot', {}, { default: () => props.node }),
18
+ h('div', {}, 'TOOLTIP'),
19
+ ])
20
+ }
21
+ function activeHandleRender(props: any) {
22
+ return h(NodeWrapper, { ...props })
23
+ }
24
+ const state = ref([0, 50, 80])
25
+ </script>
26
+
27
+ <template>
28
+ <div>
29
+ <div :style="style">
30
+ <Slider
31
+ range
32
+ :min="0"
33
+ :max="100"
34
+ :value="state"
35
+ :styles="{
36
+ tracks: {
37
+ background: `linear-gradient(to right, blue, red)`,
38
+ },
39
+ track: {
40
+ background: 'transparent',
41
+ },
42
+ }"
43
+ :active-handle-render="activeHandleRender"
44
+ @change="(nextValue) => {
45
+ console.log('>>>', nextValue)
46
+ }"
47
+ />
48
+ </div>
49
+ </div>
50
+ </template>
51
+
52
+ <style scoped>
53
+
54
+ </style>
package/docs/range.vue ADDED
@@ -0,0 +1,211 @@
1
+ <script setup lang="ts">
2
+ import type { CSSProperties } from 'vue'
3
+ import Slider from '@v-c/slider'
4
+ import { reactive, ref } from 'vue'
5
+
6
+ const style: CSSProperties = {
7
+ width: '400px',
8
+ margin: '50px',
9
+ }
10
+
11
+ function log(value: unknown) {
12
+ console.log(value)
13
+ }
14
+
15
+ // CustomizedRange组件
16
+ const customizedRange = reactive({
17
+ lowerBound: 20,
18
+ upperBound: 40,
19
+ value: [20, 40],
20
+ })
21
+
22
+ function onLowerBoundChange(e: any) {
23
+ customizedRange.lowerBound = +e.target.value
24
+ }
25
+
26
+ function onUpperBoundChange(e: any) {
27
+ customizedRange.upperBound = +e.target.value
28
+ }
29
+
30
+ function onSliderChange(value: any) {
31
+ log(value)
32
+ customizedRange.value = value
33
+ }
34
+
35
+ function handleApply() {
36
+ const { lowerBound, upperBound } = customizedRange
37
+ customizedRange.value = [lowerBound, upperBound]
38
+ }
39
+
40
+ // DynamicBounds组件
41
+ const dynamicBounds = reactive({
42
+ min: 0,
43
+ max: 100,
44
+ })
45
+
46
+ function onDynamicSliderChange(value: unknown) {
47
+ log(value)
48
+ }
49
+
50
+ function onMinChange(e: any) {
51
+ dynamicBounds.min = +e.target.value || 0
52
+ }
53
+
54
+ function onMaxChange(e: any) {
55
+ dynamicBounds.max = +e.target.value || 100
56
+ }
57
+
58
+ // ControlledRange组件
59
+ const controlledRangeValue = ref([20, 40, 60, 80])
60
+
61
+ function handleControlledRangeChange(value: any) {
62
+ controlledRangeValue.value = value
63
+ }
64
+
65
+ // ControlledRangeDisableAcross组件
66
+ const controlledRangeDisableAcrossValue = ref([20, 40, 60, 80])
67
+
68
+ function handleControlledRangeDisableAcrossChange(value: any) {
69
+ controlledRangeDisableAcrossValue.value = value
70
+ }
71
+
72
+ // PureRenderRange组件
73
+ const pureRenderRangeFoo = ref(false)
74
+
75
+ function handlePureRenderRangeChange(value: any) {
76
+ console.log(value)
77
+ pureRenderRangeFoo.value = !pureRenderRangeFoo.value
78
+ }
79
+ </script>
80
+
81
+ <template>
82
+ <div>
83
+ <div :style="style">
84
+ <p>Basic Range,`allowCross=false`</p>
85
+ <Slider range :allow-cross="false" :default-value="[0, 20]" @change="log" />
86
+ </div>
87
+ <div :style="style">
88
+ <p>Basic reverse Range`</p>
89
+ <Slider range :allow-cross="false" :default-value="[0, 20]" reverse @change="log" />
90
+ </div>
91
+ <div :style="style">
92
+ <p>Basic Range,`step=20` </p>
93
+ <Slider range :step="20" :default-value="[20, 20]" @before-change="log" />
94
+ </div>
95
+ <div :style="style">
96
+ <p>Basic Range,`step=20, dots` </p>
97
+ <Slider range dots :step="20" :default-value="[20, 40]" @change-complete="log" />
98
+ </div>
99
+ <div :style="style">
100
+ <p>Basic Range,disabled</p>
101
+ <Slider range :allow-cross="false" :default-value="[0, 20]" disabled @change="log" />
102
+ </div>
103
+ <div :style="style">
104
+ <p>Controlled Range</p>
105
+ <Slider range :value="controlledRangeValue" @change="handleControlledRangeChange" />
106
+ </div>
107
+ <div :style="style">
108
+ <p>Controlled Range, not allow across</p>
109
+ <Slider
110
+ range
111
+ :value="controlledRangeDisableAcrossValue"
112
+ :allow-cross="false"
113
+ @change="handleControlledRangeDisableAcrossChange"
114
+ />
115
+ </div>
116
+ <div :style="style">
117
+ <p>Controlled Range, not allow across, pushable=5</p>
118
+ <Slider
119
+ range
120
+ :value="controlledRangeDisableAcrossValue"
121
+ :allow-cross="false"
122
+ :pushable="5"
123
+ @change="handleControlledRangeDisableAcrossChange"
124
+ />
125
+ </div>
126
+ <div :style="style">
127
+ <p>Multi Range, count=3 and pushable=true</p>
128
+ <Slider range :count="3" :default-value="[20, 40, 60, 80]" pushable />
129
+ </div>
130
+ <div :style="style">
131
+ <p>Multi Range with custom track and handle style and pushable</p>
132
+ <Slider
133
+ range
134
+ :count="3"
135
+ :default-value="[20, 40, 60, 80]"
136
+ pushable
137
+ :track-style="[{ backgroundColor: 'red' }, { backgroundColor: 'green' }]"
138
+ :handle-style="[{ backgroundColor: 'yellow' }, { backgroundColor: 'gray' }]"
139
+ :rail-style="{ backgroundColor: 'black' }"
140
+ />
141
+ </div>
142
+ <div :style="style">
143
+ <p>Customized Range</p>
144
+ <div>
145
+ <label>LowerBound: </label>
146
+ <input type="number" :value="customizedRange.lowerBound" @change="onLowerBoundChange">
147
+ <br>
148
+ <label>UpperBound: </label>
149
+ <input type="number" :value="customizedRange.upperBound" @change="onUpperBoundChange">
150
+ <br>
151
+ <button type="button" @click="handleApply">
152
+ Apply
153
+ </button>
154
+ <br>
155
+ <br>
156
+ <Slider range :allow-cross="false" :value="customizedRange.value" @change="onSliderChange" />
157
+ </div>
158
+ </div>
159
+ <div :style="style">
160
+ <p>Range with dynamic `max` `min`</p>
161
+ <div>
162
+ <label>Min: </label>
163
+ <input type="number" :value="dynamicBounds.min" @change="onMinChange">
164
+ <br>
165
+ <label>Max: </label>
166
+ <input type="number" :value="dynamicBounds.max" @change="onMaxChange">
167
+ <br>
168
+ <br>
169
+ <Slider
170
+ range
171
+ :default-value="[20, 50]"
172
+ :min="dynamicBounds.min"
173
+ :max="dynamicBounds.max"
174
+ @change="onDynamicSliderChange"
175
+ />
176
+ </div>
177
+ </div>
178
+ <div :style="style">
179
+ <p>Range as child component</p>
180
+ <Slider
181
+ range
182
+ :default-value="[20, 40, 60, 80]"
183
+ :allow-cross="false"
184
+ @change="handlePureRenderRangeChange"
185
+ />
186
+ </div>
187
+ <div :style="style">
188
+ <p>draggableTrack two points</p>
189
+ <Slider :range="{ draggableTrack: true }" :allow-cross="false" :default-value="[0, 40]" @change="log" />
190
+ </div>
191
+ <div :style="style">
192
+ <p>draggableTrack two points(reverse)</p>
193
+ <Slider
194
+ :range="{ draggableTrack: true }"
195
+ :allow-cross="false"
196
+ reverse
197
+ :default-value="[0, 40]"
198
+ @change="log"
199
+ />
200
+ </div>
201
+ <div :style="style">
202
+ <p>draggableTrack multiple points</p>
203
+ <Slider
204
+ :range="{ draggableTrack: true }"
205
+ :allow-cross="false"
206
+ :default-value="[0, 20, 30, 40, 50]"
207
+ @change="log"
208
+ />
209
+ </div>
210
+ </div>
211
+ </template>
@@ -0,0 +1,45 @@
1
+ <script setup lang="ts">
2
+ import Debug from './debug.vue'
3
+ import Editable from './editable.vue'
4
+ import Handle from './handle.vue'
5
+ import Marks from './marks.vue'
6
+ import Multiple from './multiple.vue'
7
+ import Range from './range.vue'
8
+ import SliderDemo from './sliderDemo.vue'
9
+ import Vertical from './vertical.vue'
10
+
11
+ import '../docs/assets/index.less'
12
+ </script>
13
+
14
+ <template>
15
+ <Story title="Slider">
16
+ <Variant title="debug">
17
+ <Debug />
18
+ </Variant>
19
+ <Variant title="Editable">
20
+ <Editable />
21
+ </Variant>
22
+ <Variant title="Handle">
23
+ <Handle />
24
+ </Variant>
25
+ <Variant title="Marks">
26
+ <Marks />
27
+ </Variant>
28
+ <Variant title="Multiple">
29
+ <Multiple />
30
+ </Variant>
31
+ <Variant title="Range">
32
+ <Range />
33
+ </Variant>
34
+ <Variant title="Slider">
35
+ <SliderDemo />
36
+ </Variant>
37
+ <Variant title="Vertical">
38
+ <Vertical />
39
+ </Variant>
40
+ </Story>
41
+ </template>
42
+
43
+ <style scoped>
44
+
45
+ </style>