@acrool/react-picker 0.0.2-alpha.7 → 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
@@ -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,11 @@
25
25
 
26
26
  ## Features
27
27
 
28
- - Supports queue picker list
29
- - Plug and unplug using `@acrool/react-portal` and `framer-motion`
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)
28
+ - Quickly create various Pickers such as Datepicker, timepicker, Select dropdown, etc.
29
+ - Plug and unplug using `framer-motion`
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.
32
+
32
33
 
33
34
  ## Install
34
35
 
@@ -45,199 +46,138 @@ import "@acrool/react-picker/dist/index.css";
45
46
 
46
47
  add in your App.tsx
47
48
 
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
49
 
51
50
  ```tsx
52
- import {PickerPortal} from "@acrool/react-picker";
53
-
54
- const App = () => {
55
- return (
56
- <div>
57
- <BaseUsed/>
58
- <PickerPortal/>
59
- </div>
60
- );
61
- };
62
- ```
63
-
64
- - Here are two ways to use it
65
- - [A. Custom picker component](#a-custom-picker-component)
66
- - [B. Custom state picker component](#b-custom-state-picker-component)
67
-
68
-
69
- ## A. Custom picker component
51
+ import {isEmpty} from '@acrool/js-utils/equal';
52
+ import clsx from 'clsx';
53
+ import React, {ForwardedRef} from 'react';
54
+ import styled, {css} from 'styled-components';
70
55
 
71
- Add the lightbox to the display column list by throwing the Show method
56
+ import NumberKeyboard from './NumberKeyboard';
57
+ import {createPicker, usePicker} from '@acrool/react-picker';
72
58
 
73
- ***Defined Picker***
74
59
 
75
- ```tsx
76
- import {animation, createPicker, IPickerOptions, usePicker} from '@acrool/react-picker';
77
60
 
78
- const pickerProps: IPickerOptions = {
79
- variants: animation.fadeInDown,
80
- className: 'p-3'
81
- };
82
61
 
83
- interface IProps {
84
- myVar: string
62
+ interface IProps extends FCProps {
63
+ value?: number
64
+ options?: number[]
65
+ onChange?: (value: number) => void
66
+ placeholder?: string
85
67
  }
86
68
 
87
- const PromotionPicker = createPicker(
88
- (args: IProps) => {
89
- const {hide} = usePicker();
90
-
91
- return <div>
92
- <div>Test2 content</div>
93
- <button type="button" onClick={hide}>X </button>
94
- </div>;
95
- }
96
- , pickerProps
97
- );
98
-
99
- export default PromotionPicker;
100
- ```
101
-
102
- ***Use Picker***
103
-
104
- then in your page
105
-
106
- ```tsx
107
- const ExamplePage = () => {
108
- return <div>
109
- <button type="button" onClick={() => PromotionPicker.show({myVar: 'Imageine'})}>Show Picker</button>
110
- </div>
111
- }
112
- ```
113
-
114
-
115
-
116
-
117
-
118
69
 
119
70
 
71
+ /**
72
+ * Select Number Keyboard
73
+ */
74
+ const SelectNumberKeyboard = ({
75
+ id,
76
+ placeholder = '0',
77
+ }: IProps, ref?: ForwardedRef<HTMLButtonElement>) => {
78
+ const Picker = usePicker();
79
+
80
+ /**
81
+ * Clean
82
+ */
83
+ const handleClear = (e: React.MouseEvent) => {
84
+ e.stopPropagation();
85
+ Picker.onChange(0);
86
+ };
87
+
88
+ const isPlaceholderValue = isEmpty(Picker.value);
89
+
90
+ return <SelectNumberKeyboardRoot
91
+ ref={ref}
92
+ type="button"
93
+ onMouseDown={Picker.toggle}
94
+ isFocus={Picker.isInputFocus}
95
+ onFocus={Picker.inputFocus}
96
+ >
97
+ <Text isPlaceholderValue={isPlaceholderValue}>
98
+ {isPlaceholderValue ? placeholder: Picker.value}
99
+ </Text>
100
+ </SelectNumberKeyboardRoot>;
101
+ };
120
102
 
121
103
 
122
- ## B. Custom state picker component
104
+ const Picker = (props: IProps) => {
105
+ const Picker = usePicker();
123
106
 
124
- The inside of the light box is controlled by its own state, which is displayed through rendering, such as using HashRouter.
107
+ const handleClickPicker = (addNumber: number) => {
108
+ let result = 0;
109
+ const currValue = Picker.value ?? 0;
110
+ if(addNumber >= 0){
111
+ result = currValue + addNumber;
112
+ }
113
+ Picker.onChange(result);
114
+ };
125
115
 
126
- ***Defined Picker***
116
+ return <NumberKeyboard
117
+ data={props.options}
118
+ onChange={handleClickPicker}
119
+ />;
120
+ };
127
121
 
128
- ```tsx
129
- import {animation, createStatePicker, IPickerOptions, usePicker} from '@acrool/react-picker';
130
- import {useHashParams} from '@acrool/react-router-hash';
122
+ export default createPicker(
123
+ SelectNumberKeyboard,
124
+ Picker
125
+ );
131
126
 
132
- const pickerProps: IPickerOptions = {
133
- variants: animation.fadeInDown,
134
- className: 'p-3'
135
- };
136
127
 
137
- interface IProps {
138
- myVar: string
139
- }
128
+ const SelectNumberKeyboardRoot = styled.button<{
129
+ isFocus?: boolean,
130
+ }>`
131
+ transition: box-shadow .15s ease-in-out;
140
132
 
141
- const PromotionHashPicker = createStatePicker(
142
- () => {
143
- const {hide} = usePicker();
144
- const navigate = useNavigate();
145
- const {id} = useHashParams<{id: string}>();
146
-
147
- const handleOnClose = () => {
148
- hide().then(() => {
149
- navigate({hash: undefined});
150
- })
151
- }
152
-
153
- return <div>
154
- <div>Test2 content</div>
155
- <button type="button" onClick={handleOnClose}>Close Picker</button>
156
- </div>;
157
- }
158
- , pickerProps
159
- );
133
+ ${props => props.isFocus && css`
134
+ box-shadow: 0 0 0 0.2rem rgb(0 123 255 / 25%);
135
+ `}
160
136
 
161
- export default PromotionHashPicker;
137
+ `;
162
138
  ```
163
139
 
164
140
 
165
- ***Defined Hash Route***
166
-
167
- > 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.
141
+ ## If you need to automatically infer types
168
142
 
169
143
  ```tsx
170
- import {HashRoute,HashRoutes} from '@acrool/react-router-hash';
171
- import {createBrowserHistory} from 'history';
172
- import {BrowserRouter as Router,Route, Routes} from 'react-router-dom';
173
144
 
174
- const history = createBrowserHistory({window});
145
+ export default createPicker(
146
+ SelectNumberKeyboard,
147
+ Picker
148
+ ) as <V extends any>(props: IProps<V>) => JSX.Element;
149
+ ```
175
150
 
176
- const RouterSetting = () => {
177
- return <Router>
178
151
 
179
- <Routes>
180
- <Route path="/" element={<Example/>} />
181
- </Routes>
152
+ There is also a example that you can play with it:
182
153
 
183
- <HashRoutes>
184
- <HashRoute path="promotion/:id" element={<PromotionHashPicker/>}/>
185
- </HashRoutes>
154
+ [![Play react-editext-example](https://raw.githubusercontent.com/acrool/acrool-react-picker/main/play-in-example-button.svg)](https://acrool-react-picker.pages.dev)
186
155
 
187
- {/* Add this */}
188
- <PickerPortal/>
189
156
 
190
- </Router>;
191
- };
192
- ```
157
+ ## Precautions
193
158
 
159
+ - The main control controls the opening and closing of the menu. You need to use `onMousedown` instead of `onClick`.
160
+ - The main control needs to use button to have the Tab focus function, where `react-hook-form` is very useful
161
+ - 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`.
194
162
 
195
163
 
196
- ***Use Picker***
164
+ ## Ref warning
197
165
 
198
- then in your page
166
+ `Warning: forwardRef render functions accept exactly two parameters: props and ref. Did you forget to use the ref parameter?`
199
167
 
200
168
  ```tsx
201
- import {useNavigate} from 'react-router-dom';
202
-
203
- const ExamplePage = () => {
204
- const navigate = useNavigate();
205
- return <div>
206
- <button type="button" onClick={() => navigate({hash: '/promotion/1'})}>Show Picker</button>
207
- <button type="button" onClick={() => navigate({hash: '/promotion/2'})}>Show Picker</button>
208
- </div>
169
+ interface IProps {
170
+ value: string,
171
+ onChange:(value: string) => void
209
172
  }
210
- ```
211
-
212
-
213
-
214
- - animation
215
- - fadeInDown: (default), ex Base picker style
216
- - zoomInDown
217
- - slideInLeft: ex Drawer slider
218
- - slideInRight: ex Drawer slider
219
- - slideInUp: ex Dropdown
220
- - custom (ref; https://www.framer.com/motion/animate-presence/#usage)
221
- ```tsx
222
- variants = {
223
- initial: {opacity: 0, y: -20, transition: {type:'spring'}},
224
- show: {opacity: 1, y: 0},
225
- exit: {opacity: 0, y: -40}
226
- }
227
- ```
228
-
173
+ const DateTimeField = (props: IProps) => {}
229
174
 
230
- There is also a example that you can play with it:
231
-
232
- [![Play react-editext-example](https://raw.githubusercontent.com/acrool/acrool-react-picker/main/play-in-example-button.svg)](https://acrool-react-picker.pages.dev)
175
+ // fix to
176
+ const DateTimeFieldAfter = (props: IProps, ref?: ForwardedRef<HTMLElement>) => {}
177
+ ```
233
178
 
234
179
 
235
180
  ## License
236
181
 
237
182
  MIT © [Acrool](https://github.com/acrool) & [Imagine](https://github.com/imagine10255)
238
183
 
239
-
240
- ## Refer to
241
-
242
- - [https://github.com/ebay/nice-picker-react](https://github.com/ebay/nice-picker-react)
243
- - [https://animate.style](https://animate.style)
@@ -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;