@acrool/react-picker 0.0.2-alpha.7 → 0.0.2

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,11 +1,11 @@
1
1
  # Acrool React Picker
2
2
 
3
- <a href="https://acrool-react-picker.pages.dev/" title="Acrool React Picker - This is a picker function for React development loading picker">
3
+ <a href="https://acrool-react-picker.pages.dev/" title="Acrool React Picker - This is a react method to quickly combine buttons with Picker">
4
4
  <img src="https://raw.githubusercontent.com/acrool/acrool-react-picker/main/example/public/og.webp" alt="Acrool React Picker Logo"/>
5
5
  </a>
6
6
 
7
7
  <p align="center">
8
- This is a toast message function for React development notifications
8
+ This is a react method to quickly combine buttons with Picker
9
9
  </p>
10
10
 
11
11
  <div align="center">
@@ -25,10 +25,10 @@
25
25
 
26
26
  ## Features
27
27
 
28
- - Supports queue picker list
29
- - Plug and unplug using `@acrool/react-portal` and `framer-motion`
28
+ - Quickly create various Pickers such as Datepicker, timepicker, Select dropdown, etc.
29
+ - Plug and unplug using `framer-motion`
30
30
  - Quickly create light box effects and send them to the outside to avoid hierarchical problems
31
- - Support [@acrool/react-router-hash](https://github.com/acrool/acrool-react-router-hash) lightbox (using createControlledPicker)
31
+
32
32
 
33
33
  ## Install
34
34
 
@@ -45,20 +45,115 @@ import "@acrool/react-picker/dist/index.css";
45
45
 
46
46
  add in your App.tsx
47
47
 
48
- > 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.
49
-
50
48
 
51
49
  ```tsx
52
- import {PickerPortal} from "@acrool/react-picker";
53
-
54
- const App = () => {
55
- return (
56
- <div>
57
- <BaseUsed/>
58
- <PickerPortal/>
59
- </div>
60
- );
50
+ import {isEmpty} from '@acrool/js-utils/equal';
51
+ import clsx from 'clsx';
52
+ import React, {ForwardedRef} from 'react';
53
+ import styled, {css} from 'styled-components';
54
+
55
+ import NumberKeyboard from './NumberKeyboard';
56
+ import {createPicker, usePicker} from '@acrool/react-picker';
57
+
58
+
59
+
60
+
61
+ interface IProps extends FCProps {
62
+ title?: string
63
+ name?: string
64
+ value?: number
65
+ options?: number[]
66
+ disabled?: boolean
67
+ onChange?: (value: number) => void
68
+ placeholder?: string
69
+ }
70
+
71
+
72
+
73
+ /**
74
+ * 數字選擇器(含數字鍵盤)
75
+ *
76
+ * @param style
77
+ * @param className
78
+ * @param title 標題
79
+ * @param disabled 是否禁用
80
+ * @param ref
81
+ */
82
+ const SelectNumberKeyboard = ({
83
+ id,
84
+ placeholder = '0',
85
+ }: IProps, ref?: ForwardedRef<HTMLButtonElement>) => {
86
+ const Picker = usePicker();
87
+
88
+ /**
89
+ * 清除
90
+ */
91
+ const handleClear = (e: React.MouseEvent) => {
92
+ e.stopPropagation();
93
+ Picker.onChange(0);
94
+ };
95
+
96
+ const isPlaceholderValue = isEmpty(Picker.value);
97
+
98
+ return <SelectNumberKeyboardRoot
99
+ ref={ref}
100
+ type="button"
101
+ onMouseDown={Picker.toggle}
102
+ isFocus={Picker.isInputFocus}
103
+ onFocus={Picker.inputFocus}
104
+ >
105
+ <Text isPlaceholderValue={isPlaceholderValue}>
106
+ {isPlaceholderValue ? placeholder: Picker.value}
107
+ </Text>
108
+ </SelectNumberKeyboardRoot>;
61
109
  };
110
+
111
+
112
+ const Picker = (props: IProps) => {
113
+ const Picker = usePicker();
114
+
115
+ const handleClickPicker = (addNumber: number) => {
116
+ let result = 0;
117
+ const currValue = Picker.value ?? 0;
118
+ if(addNumber >= 0){
119
+ result = currValue + addNumber;
120
+ }
121
+ Picker.onChange(result);
122
+ };
123
+
124
+ return <NumberKeyboard
125
+ data={props.options}
126
+ onChange={handleClickPicker}
127
+ />;
128
+ };
129
+
130
+ export default createPicker(
131
+ SelectNumberKeyboard,
132
+ Picker
133
+ );
134
+
135
+
136
+ const SelectNumberKeyboardRoot = styled.button<{
137
+ isFocus?: boolean,
138
+ }>`
139
+ transition: box-shadow .15s ease-in-out;
140
+
141
+ ${props => props.isFocus && css`
142
+ box-shadow: 0 0 0 0.2rem rgb(0 123 255 / 25%);
143
+ `}
144
+
145
+ `;
146
+ ```
147
+
148
+
149
+ ## If you need to automatically infer types
150
+
151
+ ```tsx
152
+
153
+ export default createPicker(
154
+ SelectNumberKeyboard,
155
+ Picker
156
+ ) as <V extends any>(props: IProps<V>) => JSX.Element;
62
157
  ```
63
158
 
64
159
  - Here are two ways to use it
@@ -232,12 +327,30 @@ There is also a example that you can play with it:
232
327
  [![Play react-editext-example](https://raw.githubusercontent.com/acrool/acrool-react-picker/main/play-in-example-button.svg)](https://acrool-react-picker.pages.dev)
233
328
 
234
329
 
235
- ## License
330
+ ## Precautions
331
+
332
+ - The main control controls the opening and closing of the menu. You need to use `onMousedown` instead of `onClick`.
333
+ - The main control needs to use button to have the Tab focus function, where `react-hook-form` is very useful
334
+ - The main control needs to use button. If you want to add a clear button in the inner layer, remember that it cannot be button, because `button > button` is an html structure error, and you need to use `onMousedown` instead of `onClick`.
236
335
 
237
- MIT © [Acrool](https://github.com/acrool) & [Imagine](https://github.com/imagine10255)
238
336
 
337
+ ## Ref warning
239
338
 
240
- ## Refer to
339
+ `Warning: forwardRef render functions accept exactly two parameters: props and ref. Did you forget to use the ref parameter?`
340
+
341
+ ```tsx
342
+ interface IProps {
343
+ value: string,
344
+ onChange:(value: string) => void
345
+ }
346
+ const DateTimeField = (props: IProps) => {}
347
+
348
+ // fix to
349
+ const DateTimeFieldAfter = (props: IProps, ref?: ForwardedRef<HTMLElement>) => {}
350
+ ```
351
+
352
+
353
+ ## License
354
+
355
+ MIT © [Acrool](https://github.com/acrool) & [Imagine](https://github.com/imagine10255)
241
356
 
242
- - [https://github.com/ebay/nice-picker-react](https://github.com/ebay/nice-picker-react)
243
- - [https://animate.style](https://animate.style)