@component-hook/picker 0.1.0 → 0.1.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Tzuyi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @component-hook/picker
2
2
 
3
- Picker component with vue3 ([DEMO](https://tzuyi0817.github.io/component-hook/))
3
+ Picker component with vue3 ([DEMO](https://tzuyi0817.github.io/component-hook/#/picker))
4
4
 
5
5
  <p>
6
6
  <a href="https://npm-stat.com/charts.html?package=@component-hook/picker">
@@ -21,36 +21,19 @@ Picker component with vue3 ([DEMO](https://tzuyi0817.github.io/component-hook/))
21
21
  - Built-in date and time data
22
22
  - Supports typescript
23
23
 
24
- ## Getting started
25
-
26
- ### Installation
27
-
28
- First step is to install it using `yarn`、`npm` or `pnpm`:
24
+ ## Installation
29
25
 
30
26
  ```bash
31
- npm install @component-hook/picker
27
+ $ npm install @component-hook/picker
32
28
 
33
29
  # or use yarn
34
- yarn add @component-hook/picker
30
+ $ yarn add @component-hook/picker
35
31
 
36
32
  # 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
- });
33
+ $ pnpm install @component-hook/picker
51
34
  ```
52
35
 
53
- ### Basic Using
36
+ ## Basic Usage
54
37
 
55
38
  ```vue
56
39
  <script setup>
@@ -79,29 +62,13 @@ const options = reactive({
79
62
  titleText: 'Title',
80
63
  });
81
64
 
82
- function confirm(value) {
65
+ function onConfirm(value) {
83
66
  currentSelect.value = value;
84
67
  }
85
68
 
86
- function cancel() {
69
+ function onCancel() {
87
70
  console.log('cancel');
88
71
  }
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
72
  </script>
106
73
 
107
74
  <template>
@@ -112,8 +79,8 @@ function openTime() {
112
79
  :showKey="['original', 'original', 'original']"
113
80
  :options="options"
114
81
  :swipeTime="500"
115
- @confirm="confirm"
116
- @cancel="cancel"
82
+ @confirm="onConfirm"
83
+ @cancel="onCancel"
117
84
  />
118
85
 
119
86
  <picker
@@ -122,7 +89,6 @@ function openTime() {
122
89
  :data="singleData"
123
90
  showKey="original"
124
91
  :options="options"
125
- @confirm="confirmSingle"
126
92
  />
127
93
 
128
94
  <picker
@@ -138,78 +104,24 @@ function openTime() {
138
104
  type="time"
139
105
  :options="{ titleText: 'time selector' }"
140
106
  />
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
107
  </template>
147
108
  ```
148
109
 
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
110
+ ## Attributes
111
+
112
+ | Name | Required | Type | Description | Default |
113
+ | -------------------- | -------- | --------------------- | ----------------------------------------------------------------------------------- | --------------------- |
114
+ | v-model:isShowPicker | true | `boolean` | Control picker show | — |
115
+ | v-model:anchor | true | `number` / `number[]` | Picker current select index (single column for Number、 multiple columns for Array) | — |
116
+ | data | false | `array` | Picker list [1, 2, 3] or [[1, 2, 3], [1, 2, 3]] | — |
117
+ | type | false | `string` | Built-in picker type, no need to pass in data (date, time) | — |
118
+ | showKey | false | `string` / `string[]` | Wheel options name (object key) | — |
119
+ | swipeTime | false | `number` | Wheel swipe Time | 500 |
120
+ | options | false | `object` | Custom text, color and class | See below for details |
121
+
122
+ ## Options Attribute
123
+
124
+ ```javascript
213
125
  {
214
126
  cancelClass: '',
215
127
  confirmClass: '',
@@ -223,9 +135,9 @@ function openTime() {
223
135
  }
224
136
  ```
225
137
 
226
- ### Events
138
+ ## Events
227
139
 
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 |
140
+ | Event | Description | Type |
141
+ | :------ | :------------------------------------------- | :----------------------------- |
142
+ | confirm | Triggered when the confirm button is clicked | `Function () => selected item` |
143
+ | cancel | Triggered when the cancel button is clicked | `Function () => void` |
package/dist/index.css CHANGED
@@ -1 +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}
1
+ .fade-enter-active[data-v-78632b89],.fade-leave-active[data-v-78632b89],.slide-enter-active[data-v-78632b89],.slide-leave-active[data-v-78632b89]{transition:all .3s ease}.fade-enter-from[data-v-78632b89],.fade-leave-to[data-v-78632b89]{opacity:0}.slide-enter-from[data-v-78632b89],.slide-leave-to[data-v-78632b89]{opacity:.5;transform:translate3d(0,270px,0)}.mask[data-v-78632b89]{position:fixed;top:0;right:0;bottom:0;left:0;z-index:9999;background:#0003}.picker[data-v-78632b89]{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-78632b89]{position:relative;height:44px;color:#333}.picker_title[data-v-78632b89]:after{content:"";display:block;border-bottom:1px solid #ebebeb;left:0;right:0;transform:scaleY(.5)}.picker_title button[data-v-78632b89]{position:absolute;height:44px;line-height:44px;padding:0 12px;font-size:14px;border:none;background-color:transparent}.picker_title h4[data-v-78632b89]{margin:0;font-size:16px;font-weight:400;height:44px;line-height:44px;text-align:center}.picker_cancel[data-v-78632b89]{left:0;cursor:pointer;transition:all .3s}.picker_cancel[data-v-78632b89]:hover{filter:brightness(110%)}.picker_confirm[data-v-78632b89]{right:0;cursor:pointer;transition:all .3s}.picker_confirm[data-v-78632b89]:hover{filter:brightness(110%)}.picker_panel[data-v-78632b89]{position:relative;height:226px;padding:24px 12px;box-sizing:border-box}.picker_mask_top[data-v-78632b89],.picker_mask_bottom[data-v-78632b89]{position:absolute;left:0;right:0;height:72px;background:#fff;transform:translateZ(0);z-index:1;pointer-events:none}.picker_mask_top[data-v-78632b89]{top:24px;background:linear-gradient(to bottom,#ffffffe6,#ffffff80)}.picker_mask_top[data-v-78632b89]: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-78632b89]{bottom:24px;background:linear-gradient(to top,#ffffffe6,#ffffff80)}.picker_mask_bottom[data-v-78632b89]:before{content:"";display:block;position:absolute;left:0;right:0;top:0;border-bottom:1px solid #ebebeb;transform:scaleY(.5)}.picker_wheel[data-v-78632b89]{flex:1;overflow:hidden}.picker_wheel_wrapper[data-v-78632b89]{display:flex;align-items:stretch;height:100%}.picker_wheel_scroll[data-v-78632b89]{margin-top:72px;padding:0}.picker_wheel_item[data-v-78632b89]{height:34px;line-height:34px;font-size:17px;text-align:center;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:#333}
package/dist/index.d.ts CHANGED
@@ -50,7 +50,7 @@ onConfirm?: ((...args: any[]) => any) | undefined;
50
50
  }, {
51
51
  swipeTime: number;
52
52
  options: Partial<PickerOptions>;
53
- type: string;
53
+ type: PickerBuiltIn;
54
54
  data: PickData;
55
55
  isShowPicker: boolean;
56
56
  }, {}>;
@@ -64,6 +64,8 @@ export declare type OriginData = Array<NormalData>;
64
64
 
65
65
  export declare type PickData = OriginData | Array<OriginData>;
66
66
 
67
+ export declare type PickerBuiltIn = 'date' | 'time' | '';
68
+
67
69
  export declare type PickerEmit = (event: EmitKey, ...args: unknown[]) => void;
68
70
 
69
71
  export declare interface PickerOptions {
@@ -85,7 +87,7 @@ export declare interface PickerProps {
85
87
  options?: Partial<PickerOptions>;
86
88
  showKey?: string | Array<string>;
87
89
  swipeTime?: number;
88
- type: string;
90
+ type: PickerBuiltIn;
89
91
  }
90
92
 
91
93
  export declare interface PickerSelectItems {
@@ -100,7 +102,7 @@ declare interface Props {
100
102
  anchor: number | Array<number>;
101
103
  showKey?: string | Array<string>;
102
104
  swipeTime?: number;
103
- type?: string;
105
+ type?: PickerBuiltIn;
104
106
  }
105
107
 
106
108
  export { }