@component-hook/picker 0.1.6 → 0.2.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # @component-hook/picker
2
2
 
3
- Picker component with vue3 ([DEMO](https://tzuyi0817.github.io/component-hook/#/component/picker))
3
+ Picker component with vue3 and react ([DEMO](https://tzuyi0817.github.io/component-hook/#/component/picker))
4
4
 
5
5
  <p>
6
6
  <a href="https://npm-stat.com/charts.html?package=@component-hook/picker">
@@ -33,12 +33,12 @@ $ yarn add @component-hook/picker
33
33
  $ pnpm install @component-hook/picker
34
34
  ```
35
35
 
36
- ## Basic Usage
36
+ ## Usage with Vue
37
37
 
38
38
  ```vue
39
39
  <script setup>
40
40
  import { ref, reactive } from 'vue';
41
- import Picker from '@component-hook/picker';
41
+ import Picker from '@component-hook/picker/vue';
42
42
 
43
43
  const currentSelect = ref({});
44
44
  const anchor = ref([0, 1, 2]);
@@ -107,17 +107,108 @@ function onCancel() {
107
107
  </template>
108
108
  ```
109
109
 
110
- ## Attributes
110
+ ## Usage with React
111
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 |
112
+ ```jsx
113
+ import { useState } from 'react';
114
+ import Picker from '@component-hook/picker/react';
115
+
116
+ const singleData = [
117
+ { langType: 2, code: 'vi', original: 'Tiếng Việt' },
118
+ { langType: 0, code: 'en', original: 'English' },
119
+ { langType: 1, code: 'cn', original: '中文' },
120
+ ];
121
+ const cascadeData = [singleData, singleData, singleData];
122
+
123
+ const options = {
124
+ confirmColor: '#000',
125
+ cancelClass: 'test',
126
+ titleText: 'Title',
127
+ };
128
+
129
+ function PickerExample() {
130
+ const [currentSelect, setCurrentSelect] = useState({});
131
+ const [anchor, setAnchor] = useState([0, 1, 2]);
132
+ const [anchorSingle, setAnchorSingle] = useState(0);
133
+ const [currentDate, setCurrentDate] = useState([2022, 7, 7]);
134
+ const [currentTime, setCurrentTime] = useState([]);
135
+ const [showPicker, setShowPicker] = useState(false);
136
+ const [showSingle, setShowSingle] = useState(false);
137
+ const [showDate, setShowDate] = useState(false);
138
+ const [showTime, setShowTime] = useState(false);
139
+
140
+ function onConfirm(value) {
141
+ setCurrentSelect(value);
142
+ }
143
+
144
+ return (
145
+ <>
146
+ <Picker
147
+ isShowPicker={showPicker}
148
+ data={cascadeData}
149
+ showKey={['original', 'original', 'original']}
150
+ options={{ titleText: 'cascade selector' }}
151
+ anchor={anchor}
152
+ onChangeAnchor={setAnchor}
153
+ onClose={() => setShowPicker(false)}
154
+ onConfirm={onConfirm}
155
+ onCancel={onCancel}
156
+ />
157
+
158
+ <Picker
159
+ data={singleData}
160
+ isShowPicker={showSingle}
161
+ anchor={anchorSingle}
162
+ showKey="original"
163
+ options={{ titleText: 'single selector' }}
164
+ onChangeAnchor={setAnchorSingle}
165
+ onClose={() => setShowSingle(false)}
166
+ />
167
+
168
+ <Picker
169
+ isShowPicker={showDate}
170
+ onClose={() => setShowDate(false)}
171
+ anchor={currentDate}
172
+ type="date"
173
+ options={{ titleText: 'date selector' }}
174
+ onChangeAnchor={setCurrentDate}
175
+ />
176
+
177
+ <Picker
178
+ isShowPicker={showTime}
179
+ onClose={() => setShowTime(false)}
180
+ anchor={currentTime}
181
+ type="time"
182
+ options={{ titleText: 'time selector' }}
183
+ onChangeAnchor={setCurrentTime}
184
+ />
185
+ </>
186
+ );
187
+ }
188
+
189
+ function onCancel() {
190
+ console.log('cancel');
191
+ }
192
+ ```
193
+
194
+ ## Attributes (Common)
195
+
196
+ | Name | Required | Type | Description | Default |
197
+ | ------------ | -------- | --------------------- | ------------------------------------------------------------------------------------------------------------ | --------------------- |
198
+ | isShowPicker | true | `boolean` | Control picker show (`vue` use `v-model`) | — |
199
+ | anchor | true | `number` / `number[]` | Picker current select index (single column for `number`、 multiple columns for `Array`, `vue` use `v-model`) | — |
200
+ | data | false | `array` | Picker list `[1, 2, 3]` or `[[1, 2, 3], [1, 2, 3]]` | — |
201
+ | type | false | `string` | Built-in picker type, no need to pass in data (date, time) | — |
202
+ | showKey | false | `string` / `string[]` | Wheel options name (object key) | — |
203
+ | swipeTime | false | `number` | Wheel swipe Time | 500 |
204
+ | options | false | `object` | Custom text, color and class | See below for details |
205
+
206
+ ## Attributes (React)
207
+
208
+ | Name | Required | Type | Description | Default |
209
+ | -------------- | -------- | ------------------------------------------------ | -------------------------------------------------- | ------- |
210
+ | onClose | true | `Function () => void` | close picker show (need to update state) | — |
211
+ | onChangeAnchor | true | `Function (anchor: number` / `number[]) => void` | update picker anchor (need to update anchor state) | — |
121
212
 
122
213
  ## Options Attribute
123
214
 
@@ -137,7 +228,7 @@ function onCancel() {
137
228
 
138
229
  ## Events
139
230
 
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` |
231
+ | Event | Description | Type |
232
+ | :--------------------------------- | :------------------------------------------- | :---------------------------------------- |
233
+ | confirm(`vue`), onConfirm(`react`) | Triggered when the confirm button is clicked | `Function (value: selected item) => void` |
234
+ | cancel(`vue`), onClose(`react`) | Triggered when the cancel button is clicked | `Function () => void` |
@@ -0,0 +1 @@
1
+ .mask{position:fixed;top:0;right:0;bottom:0;left:0;z-index:9999;background:#0003}.picker{position:fixed;left:0;right:0;bottom:0;height:270px;z-index:10000;background:#fff;-webkit-user-select:none;user-select:none}.picker_title{position:relative;height:44px;color:#333}.picker_title:after{content:"";display:block;border-bottom:1px solid #ebebeb;left:0;right:0;transform:scaleY(.5)}.picker_title button{position:absolute;height:44px;line-height:44px;padding:0 12px;font-size:14px;border:none;background-color:transparent}.picker_title h4{margin:0;font-size:16px;font-weight:400;height:44px;line-height:44px;text-align:center}.picker_cancel{left:0;cursor:pointer;transition:all .3s}.picker_cancel:hover{filter:brightness(110%)}.picker_confirm{right:0;cursor:pointer;transition:all .3s}.picker_confirm:hover{filter:brightness(110%)}.picker_panel{position:relative;height:226px;padding:24px 12px;box-sizing:border-box}.picker_mask_top,.picker_mask_bottom{position:absolute;left:0;right:0;height:72px;background:#fff;transform:translateZ(0);z-index:1;pointer-events:none}.picker_mask_top{top:24px;background:linear-gradient(to bottom,#ffffffe6,#ffffff80)}.picker_mask_top:after{content:"";display:block;position:absolute;left:0;right:0;bottom:0;border-bottom:1px solid #ebebeb;transform:scaleY(.5)}.picker_mask_bottom{bottom:24px;background:linear-gradient(to top,#ffffffe6,#ffffff80)}.picker_mask_bottom:before{content:"";display:block;position:absolute;left:0;right:0;top:0;border-bottom:1px solid #ebebeb;transform:scaleY(.5)}.picker_wheel{flex:1;overflow:hidden}.picker_wheel_wrapper{display:flex;align-items:stretch;height:100%}.picker_wheel_scroll{margin-top:72px;padding:0}.picker_wheel_item{height:34px;line-height:34px;font-size:17px;text-align:center;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:#333}.fade-enter{opacity:0}.fade-enter-active{opacity:1;transition:all .3s ease}.fade-exit-active{opacity:0;transition:all .3s ease}.slide-enter{opacity:.5;transform:translate3d(0,270px,0)}.slide-enter-active{transition:all .3s ease;opacity:1;transform:translateZ(0)}.slide-exit-active{transition:all .3s ease;opacity:.5;transform:translate3d(0,270px,0)}
@@ -0,0 +1,60 @@
1
+ import { JSX as JSX_2 } from 'react';
2
+
3
+ export declare type NormalData = Record<PropertyKey, unknown> | string | number;
4
+
5
+ export declare type OriginData = Array<NormalData>;
6
+
7
+ declare function Picker<T = NormalData, D = PickerAnchor>({ data, isShowPicker, options, anchor, showKey, swipeTime, type, onChangeAnchor, onClose, onCancel, onConfirm, }: PickerComponentProps<D> & PickerEmit<T, D>): JSX_2.Element;
8
+ export default Picker;
9
+
10
+ export declare type PickerAnchor = number | Array<number>;
11
+
12
+ export declare type PickerBuiltIn = 'date' | 'time' | '';
13
+
14
+ export declare interface PickerComponentProps<T = PickerAnchor> {
15
+ data?: PickerData;
16
+ isShowPicker: boolean;
17
+ options?: Partial<PickerOptions>;
18
+ anchor: T;
19
+ showKey?: string | Array<string>;
20
+ swipeTime?: number;
21
+ type?: PickerBuiltIn;
22
+ }
23
+
24
+ export declare type PickerData = OriginData | Array<OriginData>;
25
+
26
+ export declare interface PickerEmit<T = NormalData, D = PickerAnchor> {
27
+ onClose: () => void;
28
+ onChangeAnchor: (value: D) => void;
29
+ onCancel?: () => void;
30
+ onConfirm?: (value: T) => void;
31
+ }
32
+
33
+ export declare interface PickerOptions {
34
+ cancelClass: string;
35
+ confirmClass: string;
36
+ titleClass: string;
37
+ cancelColor: string;
38
+ confirmColor: string;
39
+ titleColor: string;
40
+ cancelText: string;
41
+ confirmText: string;
42
+ titleText: string;
43
+ }
44
+
45
+ export declare interface PickerProps<T = PickerAnchor> {
46
+ data: PickerData;
47
+ isShowPicker: boolean;
48
+ anchor: T;
49
+ options?: Partial<PickerOptions>;
50
+ showKey?: string | Array<string>;
51
+ swipeTime?: number;
52
+ type: PickerBuiltIn;
53
+ }
54
+
55
+ export declare interface PickerSelectItems<T = NormalData> {
56
+ item: Array<T>;
57
+ anchor: Array<number>;
58
+ }
59
+
60
+ export { }