@acrool/react-picker 0.0.2 → 0.0.3-alpha.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Acrool
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
@@ -27,7 +27,8 @@
27
27
 
28
28
  - Quickly create various Pickers such as Datepicker, timepicker, Select dropdown, etc.
29
29
  - Plug and unplug using `framer-motion`
30
- - Quickly create light box effects and send them to the outside to avoid hierarchical problems
30
+ - Simulate the browser's native drop-down menu behavior (click outside to close, lose focus to close, open the menu when the keyboard is pressed or blank)
31
+ - The agent menu OnChange and value changes can be controlled freely and will be saved when the menu is closed.
31
32
 
32
33
 
33
34
  ## Install
@@ -59,11 +60,8 @@ import {createPicker, usePicker} from '@acrool/react-picker';
59
60
 
60
61
 
61
62
  interface IProps extends FCProps {
62
- title?: string
63
- name?: string
64
63
  value?: number
65
64
  options?: number[]
66
- disabled?: boolean
67
65
  onChange?: (value: number) => void
68
66
  placeholder?: string
69
67
  }
@@ -71,13 +69,7 @@ interface IProps extends FCProps {
71
69
 
72
70
 
73
71
  /**
74
- * 數字選擇器(含數字鍵盤)
75
- *
76
- * @param style
77
- * @param className
78
- * @param title 標題
79
- * @param disabled 是否禁用
80
- * @param ref
72
+ * Select Number Keyboard
81
73
  */
82
74
  const SelectNumberKeyboard = ({
83
75
  id,
@@ -86,7 +78,7 @@ const SelectNumberKeyboard = ({
86
78
  const Picker = usePicker();
87
79
 
88
80
  /**
89
- * 清除
81
+ * Clean
90
82
  */
91
83
  const handleClear = (e: React.MouseEvent) => {
92
84
  e.stopPropagation();
@@ -156,171 +148,6 @@ export default createPicker(
156
148
  ) as <V extends any>(props: IProps<V>) => JSX.Element;
157
149
  ```
158
150
 
159
- - Here are two ways to use it
160
- - [A. Custom picker component](#a-custom-picker-component)
161
- - [B. Custom state picker component](#b-custom-state-picker-component)
162
-
163
-
164
- ## A. Custom picker component
165
-
166
- Add the lightbox to the display column list by throwing the Show method
167
-
168
- ***Defined Picker***
169
-
170
- ```tsx
171
- import {animation, createPicker, IPickerOptions, usePicker} from '@acrool/react-picker';
172
-
173
- const pickerProps: IPickerOptions = {
174
- variants: animation.fadeInDown,
175
- className: 'p-3'
176
- };
177
-
178
- interface IProps {
179
- myVar: string
180
- }
181
-
182
- const PromotionPicker = createPicker(
183
- (args: IProps) => {
184
- const {hide} = usePicker();
185
-
186
- return <div>
187
- <div>Test2 content</div>
188
- <button type="button" onClick={hide}>X </button>
189
- </div>;
190
- }
191
- , pickerProps
192
- );
193
-
194
- export default PromotionPicker;
195
- ```
196
-
197
- ***Use Picker***
198
-
199
- then in your page
200
-
201
- ```tsx
202
- const ExamplePage = () => {
203
- return <div>
204
- <button type="button" onClick={() => PromotionPicker.show({myVar: 'Imageine'})}>Show Picker</button>
205
- </div>
206
- }
207
- ```
208
-
209
-
210
-
211
-
212
-
213
-
214
-
215
-
216
-
217
- ## B. Custom state picker component
218
-
219
- The inside of the light box is controlled by its own state, which is displayed through rendering, such as using HashRouter.
220
-
221
- ***Defined Picker***
222
-
223
- ```tsx
224
- import {animation, createStatePicker, IPickerOptions, usePicker} from '@acrool/react-picker';
225
- import {useHashParams} from '@acrool/react-router-hash';
226
-
227
- const pickerProps: IPickerOptions = {
228
- variants: animation.fadeInDown,
229
- className: 'p-3'
230
- };
231
-
232
- interface IProps {
233
- myVar: string
234
- }
235
-
236
- const PromotionHashPicker = createStatePicker(
237
- () => {
238
- const {hide} = usePicker();
239
- const navigate = useNavigate();
240
- const {id} = useHashParams<{id: string}>();
241
-
242
- const handleOnClose = () => {
243
- hide().then(() => {
244
- navigate({hash: undefined});
245
- })
246
- }
247
-
248
- return <div>
249
- <div>Test2 content</div>
250
- <button type="button" onClick={handleOnClose}>Close Picker</button>
251
- </div>;
252
- }
253
- , pickerProps
254
- );
255
-
256
- export default PromotionHashPicker;
257
- ```
258
-
259
-
260
- ***Defined Hash Route***
261
-
262
- > It should be noted that it must be within the scope of `Router Provider`. Another way is to place it in `Layout` and `Outlet` middle layer.
263
-
264
- ```tsx
265
- import {HashRoute,HashRoutes} from '@acrool/react-router-hash';
266
- import {createBrowserHistory} from 'history';
267
- import {BrowserRouter as Router,Route, Routes} from 'react-router-dom';
268
-
269
- const history = createBrowserHistory({window});
270
-
271
- const RouterSetting = () => {
272
- return <Router>
273
-
274
- <Routes>
275
- <Route path="/" element={<Example/>} />
276
- </Routes>
277
-
278
- <HashRoutes>
279
- <HashRoute path="promotion/:id" element={<PromotionHashPicker/>}/>
280
- </HashRoutes>
281
-
282
- {/* Add this */}
283
- <PickerPortal/>
284
-
285
- </Router>;
286
- };
287
- ```
288
-
289
-
290
-
291
- ***Use Picker***
292
-
293
- then in your page
294
-
295
- ```tsx
296
- import {useNavigate} from 'react-router-dom';
297
-
298
- const ExamplePage = () => {
299
- const navigate = useNavigate();
300
- return <div>
301
- <button type="button" onClick={() => navigate({hash: '/promotion/1'})}>Show Picker</button>
302
- <button type="button" onClick={() => navigate({hash: '/promotion/2'})}>Show Picker</button>
303
- </div>
304
- }
305
- ```
306
-
307
-
308
-
309
- - animation
310
- - fadeInDown: (default), ex Base picker style
311
- - zoomInDown
312
- - slideInLeft: ex Drawer slider
313
- - slideInRight: ex Drawer slider
314
- - slideInUp: ex Dropdown
315
- - custom (ref; https://www.framer.com/motion/animate-presence/#usage)
316
- ```tsx
317
- variants = {
318
- initial: {opacity: 0, y: -20, transition: {type:'spring'}},
319
- show: {opacity: 1, y: 0},
320
- exit: {opacity: 0, y: -40}
321
- }
322
- ```
323
-
324
151
 
325
152
  There is also a example that you can play with it:
326
153
 
@@ -1,8 +1,7 @@
1
- import { ReactNode } from 'react';
2
- import { IPosition } from '../types';
1
+ import { ReactNode, RefObject } from 'react';
3
2
  interface IProps {
4
- position: IPosition;
5
3
  children: ReactNode;
4
+ anchorRef: RefObject<HTMLDivElement>;
6
5
  }
7
6
  declare const _default: import("react").ForwardRefExoticComponent<IProps & import("react").RefAttributes<HTMLDivElement>>;
8
7
  export default _default;