@component-hook/picker 0.1.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/README.md ADDED
@@ -0,0 +1,231 @@
1
+ # @component-hook/picker
2
+
3
+ Picker component with vue3 ([DEMO](https://tzuyi0817.github.io/component-hook/))
4
+
5
+ <p>
6
+ <a href="https://npm-stat.com/charts.html?package=@component-hook/picker">
7
+ <img src="https://img.shields.io/npm/dm/@component-hook/picker.svg" alt="npm"/>
8
+ </a>
9
+ <a href="https://www.npmjs.com/package/@component-hook/picker">
10
+ <img src="https://img.shields.io/npm/v/@component-hook/picker.svg" alt="npm"/>
11
+ </a>
12
+ </p>
13
+
14
+ ## Features
15
+
16
+ - Picker List
17
+ - Supports single-column and concatenated data
18
+ - Scroll wheel 3D effect
19
+ - Custom title, confirm and cancel text, class and color
20
+ - Custom wheel swipe Time
21
+ - Built-in date and time data
22
+ - Supports typescript
23
+
24
+ ## Getting started
25
+
26
+ ### Installation
27
+
28
+ First step is to install it using `yarn`、`npm` or `pnpm`:
29
+
30
+ ```bash
31
+ npm install @component-hook/picker
32
+
33
+ # or use yarn
34
+ yarn add @component-hook/picker
35
+
36
+ # or use pnpm
37
+ pnpm install @component-hook/picker
38
+ ```
39
+
40
+ ### Precautions
41
+
42
+ If you use Vite Tooling and report an error (TypeError: Cannot read properties of null (reading 'setupContext')):
43
+
44
+ ```bash
45
+ defineConfig({
46
+ ...
47
+ resolve: {
48
+ dedupe: ['vue'],
49
+ },
50
+ });
51
+ ```
52
+
53
+ ### Basic Using
54
+
55
+ ```vue
56
+ <script setup>
57
+ import { ref, computed, reactive } from 'vue';
58
+ import Picker from '@component-hook/picker';
59
+
60
+ const currentSelect = ref({});
61
+ const anchor = ref([0, 1, 2]);
62
+ const currentSingle = ref < LangType > {};
63
+ const anchorSingle = ref(1);
64
+ const currentDate = ref([2022, 7, 7]);
65
+ const currentTime = ref([]);
66
+ const isShowPicker = ref(false);
67
+ const isShowDate = ref(false);
68
+ const isShowTime = ref(false);
69
+ const singleData = [
70
+ { langType: 2, code: 'vi', original: 'Tiếng Việt' },
71
+ { langType: 0, code: 'en', original: 'English' },
72
+ { langType: 1, code: 'cn', original: '中文' },
73
+ ];
74
+ const dataList = ref([singleData, singleData, singleData]);
75
+
76
+ const options = reactive({
77
+ confirmColor: '#000',
78
+ cancelClass: 'test',
79
+ titleText: 'Title',
80
+ });
81
+
82
+ function confirm(value) {
83
+ currentSelect.value = value;
84
+ }
85
+
86
+ function cancel() {
87
+ console.log('cancel');
88
+ }
89
+
90
+ function toggle() {
91
+ isShowPicker.value = true;
92
+ }
93
+
94
+ function openSingle() {
95
+ isShowSingle.value = true;
96
+ }
97
+
98
+ function openDate() {
99
+ isShowDate.value = true;
100
+ }
101
+
102
+ function openTime() {
103
+ isShowTime.value = true;
104
+ }
105
+ </script>
106
+
107
+ <template>
108
+ <picker
109
+ v-model:isShowPicker="isShowPicker"
110
+ v-model:anchor="anchor"
111
+ :data="dataList"
112
+ :showKey="['original', 'original', 'original']"
113
+ :options="options"
114
+ :swipeTime="500"
115
+ @confirm="confirm"
116
+ @cancel="cancel"
117
+ />
118
+
119
+ <picker
120
+ v-model:isShowPicker="isShowSingle"
121
+ v-model:anchor="anchorSingle"
122
+ :data="singleData"
123
+ showKey="original"
124
+ :options="options"
125
+ @confirm="confirmSingle"
126
+ />
127
+
128
+ <picker
129
+ v-model:isShowPicker="isShowDate"
130
+ v-model:anchor="currentDate"
131
+ type="date"
132
+ :options="{ titleText: 'date selector' }"
133
+ />
134
+
135
+ <picker
136
+ v-model:isShowPicker="isShowTime"
137
+ v-model:anchor="currentTime"
138
+ type="time"
139
+ :options="{ titleText: 'time selector' }"
140
+ />
141
+
142
+ <button @click="toggle">toggle</button>
143
+ <button @click="openSingle">single</button>
144
+ <button @click="openDate">date</button>
145
+ <button @click="openTime">time</button>
146
+ </template>
147
+ ```
148
+
149
+ ### Props
150
+
151
+ <table width="100%">
152
+ <tr>
153
+ <th style="min-width:160px">Name</th>
154
+ <th>Required</th>
155
+ <th>Type</th>
156
+ <th>Description</th>
157
+ <th style="min-width:130px">Default</th>
158
+ </tr>
159
+ <tr>
160
+ <td>v-model:isShowPicker</td>
161
+ <td>true</td>
162
+ <td>Boolean</td>
163
+ <td>Control picker show</td>
164
+ <td></td>
165
+ </tr>
166
+ <tr>
167
+ <td>v-model:anchor</td>
168
+ <td>true</td>
169
+ <td>Number or Number[]</td>
170
+ <td>Picker current select index (single column for Number、 multiple columns for Array)</td>
171
+ <td>date: [2022, 7, 12] <br/> time: [10, 13, 20]</td>
172
+ </tr>
173
+ <tr>
174
+ <td>data</td>
175
+ <td>false</td>
176
+ <td>Array</td>
177
+ <td>Picker list [1, 2, 3] or [[1, 2, 3], [1, 2, 3]]</td>
178
+ <td></td>
179
+ </tr>
180
+ <tr>
181
+ <td>type</td>
182
+ <td>false</td>
183
+ <td>String</td>
184
+ <td>Built-in picker type, no need to pass in data (date, time)</td>
185
+ <td>date: current date <br/> time: current time</td>
186
+ </tr>
187
+ <tr>
188
+ <td>showKey</td>
189
+ <td>false</td>
190
+ <td>String or String[]</td>
191
+ <td>Wheel options name (object key)</td>
192
+ <td></td>
193
+ </tr>
194
+ <tr>
195
+ <td>swipeTime</td>
196
+ <td>false</td>
197
+ <td>Number</td>
198
+ <td>Wheel swipe Time</td>
199
+ <td>500</td>
200
+ </tr>
201
+ <tr>
202
+ <td>options</td>
203
+ <td>false</td>
204
+ <td>Object</td>
205
+ <td>Custom text, color and class</td>
206
+ <td>See below for details</td>
207
+ </tr>
208
+ </table>
209
+
210
+ #### options
211
+
212
+ ```object
213
+ {
214
+ cancelClass: '',
215
+ confirmClass: '',
216
+ titleClass: '',
217
+ cancelColor: '#999',
218
+ confirmColor: '#42b983',
219
+ titleColor: '',
220
+ cancelText: 'Cancel',
221
+ confirmText: 'Confirm',
222
+ titleText: '',
223
+ }
224
+ ```
225
+
226
+ ### Events
227
+
228
+ | Event | Description | Return Parameters |
229
+ | :------ | :------------------------------------------- | :---------------- |
230
+ | confirm | Triggered when the confirm button is clicked | Selected value |
231
+ | cancel | Triggered when the cancel button is clicked | None |
package/dist/index.css ADDED
@@ -0,0 +1 @@
1
+ .fade-enter-active[data-v-f4d0313e],.fade-leave-active[data-v-f4d0313e],.slide-enter-active[data-v-f4d0313e],.slide-leave-active[data-v-f4d0313e]{transition:all .3s ease}.fade-enter-from[data-v-f4d0313e],.fade-leave-to[data-v-f4d0313e]{opacity:0}.slide-enter-from[data-v-f4d0313e],.slide-leave-to[data-v-f4d0313e]{opacity:.5;transform:translate3d(0,270px,0)}.mask[data-v-f4d0313e]{position:fixed;top:0;right:0;bottom:0;left:0;z-index:9999;background:#0003}.picker[data-v-f4d0313e]{position:fixed;left:0;right:0;bottom:0;height:270px;z-index:10000;background:#fff;-webkit-user-select:none;user-select:none}.picker_title[data-v-f4d0313e]{position:relative;height:44px;color:#333}.picker_title[data-v-f4d0313e]:after{content:"";display:block;border-bottom:1px solid #ebebeb;left:0;right:0;transform:scaleY(.5)}.picker_title button[data-v-f4d0313e]{position:absolute;height:44px;line-height:44px;padding:0 12px;font-size:14px;border:none;background-color:transparent}.picker_title h4[data-v-f4d0313e]{margin:0;font-size:16px;font-weight:400;height:44px;line-height:44px;text-align:center}.picker_cancel[data-v-f4d0313e]{left:0;cursor:pointer;transition:all .3s}.picker_cancel[data-v-f4d0313e]:hover{filter:brightness(110%)}.picker_confirm[data-v-f4d0313e]{right:0;cursor:pointer;transition:all .3s}.picker_confirm[data-v-f4d0313e]:hover{filter:brightness(110%)}.picker_panel[data-v-f4d0313e]{position:relative;height:226px;padding:24px 12px;box-sizing:border-box}.picker_mask_top[data-v-f4d0313e],.picker_mask_bottom[data-v-f4d0313e]{position:absolute;left:0;right:0;height:72px;background:#fff;transform:translateZ(0);z-index:1;pointer-events:none}.picker_mask_top[data-v-f4d0313e]{top:24px;background:linear-gradient(to bottom,#ffffffe6,#ffffff80)}.picker_mask_top[data-v-f4d0313e]:after{content:"";display:block;position:absolute;left:0;right:0;bottom:0;border-bottom:1px solid #ebebeb;transform:scaleY(.5)}.picker_mask_bottom[data-v-f4d0313e]{bottom:24px;background:linear-gradient(to top,#ffffffe6,#ffffff80)}.picker_mask_bottom[data-v-f4d0313e]:before{content:"";display:block;position:absolute;left:0;right:0;top:0;border-bottom:1px solid #ebebeb;transform:scaleY(.5)}.picker_wheel[data-v-f4d0313e]{flex:1;overflow:hidden}.picker_wheel_wrapper[data-v-f4d0313e]{display:flex;align-items:stretch;height:100%}.picker_wheel_scroll[data-v-f4d0313e]{margin-top:72px;padding:0}.picker_wheel_item[data-v-f4d0313e]{height:34px;line-height:34px;font-size:17px;text-align:center;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:#333;cursor:pointer}
@@ -0,0 +1,106 @@
1
+ import { ComponentOptionsMixin } from 'vue';
2
+ import { DefineComponent } from 'vue';
3
+ import { ExtractPropTypes } from 'vue';
4
+ import { PropType } from 'vue';
5
+ import { PublicProps } from 'vue';
6
+
7
+ declare type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
8
+
9
+ declare type __VLS_Prettify<T> = {
10
+ [K in keyof T]: T[K];
11
+ } & {};
12
+
13
+ declare type __VLS_TypePropsToRuntimeProps<T> = {
14
+ [K in keyof T]-?: {} extends Pick<T, K> ? {
15
+ type: PropType<__VLS_NonUndefinedable<T[K]>>;
16
+ } : {
17
+ type: PropType<T[K]>;
18
+ required: true;
19
+ };
20
+ };
21
+
22
+ declare type __VLS_WithDefaults<P, D> = {
23
+ [K in keyof Pick<P, keyof P>]: K extends keyof D ? __VLS_Prettify<P[K] & {
24
+ default: D[K];
25
+ }> : P[K];
26
+ };
27
+
28
+ declare const _default: DefineComponent<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<Props>, {
29
+ data: () => never[];
30
+ isShowPicker: boolean;
31
+ options: () => {};
32
+ swipeTime: number;
33
+ type: string;
34
+ }>, {}, unknown, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {
35
+ "update:isShowPicker": (...args: any[]) => void;
36
+ "update:anchor": (...args: any[]) => void;
37
+ cancel: (...args: any[]) => void;
38
+ confirm: (...args: any[]) => void;
39
+ }, string, PublicProps, Readonly<ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<Props>, {
40
+ data: () => never[];
41
+ isShowPicker: boolean;
42
+ options: () => {};
43
+ swipeTime: number;
44
+ type: string;
45
+ }>>> & {
46
+ onCancel?: ((...args: any[]) => any) | undefined;
47
+ onConfirm?: ((...args: any[]) => any) | undefined;
48
+ "onUpdate:isShowPicker"?: ((...args: any[]) => any) | undefined;
49
+ "onUpdate:anchor"?: ((...args: any[]) => any) | undefined;
50
+ }, {
51
+ swipeTime: number;
52
+ options: Partial<PickerOptions>;
53
+ type: string;
54
+ data: PickData;
55
+ isShowPicker: boolean;
56
+ }, {}>;
57
+ export default _default;
58
+
59
+ declare type EmitKey = 'update:isShowPicker' | 'update:anchor' | 'cancel' | 'confirm';
60
+
61
+ export declare type NormalData = Record<PropertyKey, unknown> | string | number;
62
+
63
+ export declare type OriginData = Array<NormalData>;
64
+
65
+ export declare type PickData = OriginData | Array<OriginData>;
66
+
67
+ export declare type PickerEmit = (event: EmitKey, ...args: unknown[]) => void;
68
+
69
+ export declare interface PickerOptions {
70
+ cancelClass: string;
71
+ confirmClass: string;
72
+ titleClass: string;
73
+ cancelColor: string;
74
+ confirmColor: string;
75
+ titleColor: string;
76
+ cancelText: string;
77
+ confirmText: string;
78
+ titleText: string;
79
+ }
80
+
81
+ export declare interface PickerProps {
82
+ data: PickData;
83
+ isShowPicker: boolean;
84
+ anchor: number | Array<number>;
85
+ options?: Partial<PickerOptions>;
86
+ showKey?: string | Array<string>;
87
+ swipeTime?: number;
88
+ type: string;
89
+ }
90
+
91
+ export declare interface PickerSelectItems {
92
+ item: Array<NormalData>;
93
+ anchor: Array<number>;
94
+ }
95
+
96
+ declare interface Props {
97
+ data?: PickData;
98
+ isShowPicker: boolean;
99
+ options?: Partial<PickerOptions>;
100
+ anchor: number | Array<number>;
101
+ showKey?: string | Array<string>;
102
+ swipeTime?: number;
103
+ type?: string;
104
+ }
105
+
106
+ export { }