9
9
<img alt =" Language Typescript " src =" https://img.shields.io/badge/language-Typescript-007acc.svg?style=flat-square " />
10
10
</p >
11
11
12
- iOS Style Scroll Picker Component for Vue 3. Support All Gestures of Mouse(also
13
- MouseWheel) and Touch.
12
+ Vue Scroll Picker is an iOS-style scroll picker component for Vue 3. It supports all gestures, including mouse and touch interactions, ensuring a smooth and intuitive user experience.
14
13
15
- If you are using vue 2, please refer to the
16
- [ v0.x branch] ( https://github.com/wan2land/vue-scroll-picker/tree/0.x-vue2 ) .
14
+ If you are using Vue 2, please refer to the [ v0.x branch] ( https://github.com/wan2land/vue-scroll-picker/tree/0.x-vue2 ) .
17
15
18
- [ See Example] ( http://vue-scroll-picker.dist.be ) ([ sources] ( ./example ) )
16
+ [ Live Demo] ( http://vue-scroll-picker.dist.be ) ([ source] ( ./example ) )
17
+
18
+ ## Features
19
+
20
+ - ** TypeScript Support** : Uses generics for strict type checking and improved developer experience.
21
+ - ** Native-like Behavior** : Mimics ` <select> ` element behavior for consistency.
22
+ - ** Lightweight & Performant** : Minimal dependencies with optimized rendering.
19
23
20
24
## Installation
21
25
22
26
``` bash
23
- npm i vue-scroll-picker
27
+ npm install vue-scroll-picker
24
28
```
25
29
26
30
## Usage
27
31
28
- ** Global Registration**
32
+ Vue Scroll Picker can be used both globally and locally in your Vue application. Below are examples of how to set it up.
33
+
34
+ ### Global Registration
35
+
36
+ To register Vue Scroll Picker globally in your Vue application, import it in your main file and apply it as a plugin:
29
37
30
38
[ Vue3 Global Registration Guide] ( https://v3.vuejs.org/guide/component-registration.html#global-registration )
31
39
@@ -40,56 +48,57 @@ const app = createApp(); /* */
40
48
app .use (VueScrollPicker); // export default is plugin
41
49
```
42
50
43
- ** Local Registration**
51
+ ### Local Registration
52
+
53
+ To use Vue Scroll Picker in a specific component, import it and register it locally:
44
54
45
55
[ Vue3 Local Registration Guide] ( https://v3.vuejs.org/guide/component-registration.html#local-registration )
46
56
47
57
``` vue
48
- <template>
49
- <VueScrollPicker :options="options" />
50
- </template>
51
- <script>
58
+ <script setup>
52
59
import { VueScrollPicker } from 'vue-scroll-picker'
53
60
54
- export default {
55
- components: {
56
- VueScrollPicker, // export VueScrollPicker is component
57
- },
58
- }
59
61
</script>
62
+ <template>
63
+ <VueScrollPicker :options="options" />
64
+ </template>
60
65
<style src="vue-scroll-picker/dist/style.css"></style>
61
66
```
62
67
63
68
## Options
64
69
65
70
### Props
66
71
67
- | Name | Type | Default | Example |
68
- | ----------------- | :------------------------------------------------ | ------------ | ----------------------------------------------------------------------------------------- |
69
- | modelValue | ` any ` | ` null ` | |
70
- | placeholder | ` string ` | ` null ` | |
71
- | empty | ` string ` | ` 'No Items' ` | |
72
- | options | ` string[] ` <br /> ` { name: string, value: any, disabled: boolean }[] ` | ` [] ` | ` ["10KG", "20KG", "30KG"] ` <br /> ` [{value: 10, name: "10KG"}, {value: 20, name: "20KG"}] ` |
73
- | dragSensitivity | ` number ` | ` 1.7 ` | |
74
- | touchSensitivity | ` number ` | ` 1.7 ` | |
75
- | scrollSensitivity | ` number ` | ` 1 ` | |
72
+ Vue Scroll Picker accepts several props to customize its behavior:
73
+
74
+ | Prop | Type | Default | Description |
75
+ | ------| ------| ---------| -------------|
76
+ | ` modelValue ` | ` string \| number \| boolean \| null ` | ` undefined ` | The selected value of the picker. |
77
+ | ` options ` | ` Array<{ name: string; value: any; disabled?: boolean }> ` | ` [] ` | The list of options displayed in the picker. |
78
+ | ` emptyText ` | ` string ` | ` 'No options available' ` | Text displayed when there are no options available. |
79
+ | ` dragSensitivity ` | ` number ` | ` 1.7 ` | Sensitivity of dragging interaction. |
80
+ | ` touchSensitivity ` | ` number ` | ` 1.7 ` | Sensitivity of touch interaction. |
81
+ | ` wheelSensitivity ` | ` number ` | ` 1 ` | Sensitivity of mouse wheel scrolling. |
76
82
77
83
### Events
78
84
79
- | Name | Type |
80
- | ----------------- | :------------------------------------ |
81
- | update: modelValue | ` (value: any) => void ` |
82
- | start | ` () => void ` |
83
- | move | ` (value: any) => void ` |
84
- | end | ` (value: any) => void ` |
85
- | cancel | ` () => void ` |
86
- | wheel | ` (value: any) => void ` |
87
- | click | ` (value: any, oldValue: any) => void ` |
85
+ Vue Scroll Picker emits several events to notify changes:
86
+
87
+ | Event | Payload | Description |
88
+ | -------| ---------| -------------|
89
+ | ` update:modelValue ` | ` string \| number \| boolean \| null ` | Fired when the selected value changes. |
90
+ | ` start ` | ` void ` | Fired when interaction starts. |
91
+ | ` move ` | ` string \| number \| boolean \| null ` | Fired when the selection moves. |
92
+ | ` end ` | ` string \| number \| boolean \| null ` | Fired when interaction ends. |
93
+ | ` cancel ` | ` void ` | Fired when interaction is canceled. |
94
+ | ` wheel ` | ` string \| number \| boolean \| null ` | Fired when using the mouse wheel. |
95
+ | ` click ` | ` string \| number \| boolean \| null ` | Fired when the picker is clicked. |
88
96
89
97
### Slots
90
98
91
- | Name | Prop | Default |
92
- | ----------- | :----------------------------------------- | ------------------- |
93
- | default | ` { option: { name: string, value: any } } ` | ` {{ option.name }} ` |
94
- | placeholder | ` { text: string } ` | ` {{ placeholder }} ` |
95
- | empty | ` { text: string } ` | ` No Items ` |
99
+ Vue Scroll Picker provides slots for custom rendering:
100
+
101
+ | Slot | Props | Description |
102
+ | ------| -------| -------------|
103
+ | ` default ` | ` { option: { name: string; value: any; disabled?: boolean } } ` | Custom rendering for each option. |
104
+ | ` empty ` | ` { text: string } ` | Custom rendering when no options are available. |
0 commit comments