@acrool/react-picker 0.0.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/README.md +243 -0
- package/dist/MotionDrawer/MotionDrawer.d.ts +8 -0
- package/dist/MotionDrawer/index.d.ts +1 -0
- package/dist/PickerProvider.d.ts +16 -0
- package/dist/acrool-react-picker.es.js +5510 -0
- package/dist/compose/createPicker.d.ts +13 -0
- package/dist/index.d.ts +3 -0
- package/dist/listener/HotkeyListener/HotkeyListener.d.ts +10 -0
- package/dist/listener/HotkeyListener/index.d.ts +1 -0
- package/dist/listener/MousedownListener/MousedownListener.d.ts +10 -0
- package/dist/listener/MousedownListener/index.d.ts +1 -0
- package/dist/listener/PickerHideListener/PickerHideListener.d.ts +10 -0
- package/dist/listener/PickerHideListener/index.d.ts +1 -0
- package/dist/style.css +1 -0
- package/dist/types.d.ts +25 -0
- package/dist/utils.d.ts +5 -0
- package/package.json +92 -0
package/README.md
ADDED
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
# Acrool React Picker
|
|
2
|
+
|
|
3
|
+
<a href="https://acrool-react-picker.pages.dev/" title="Acrool React Picker - This is a picker function for React development loading picker">
|
|
4
|
+
<img src="https://raw.githubusercontent.com/acrool/acrool-react-picker/main/example/public/og.webp" alt="Acrool React Picker Logo"/>
|
|
5
|
+
</a>
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
8
|
+
This is a toast message function for React development notifications
|
|
9
|
+
</p>
|
|
10
|
+
|
|
11
|
+
<div align="center">
|
|
12
|
+
|
|
13
|
+
[](https://www.npmjs.com/package/@acrool/react-picker)
|
|
14
|
+
[](https://github.com/acrool/@acrool/react-picker/blob/main/LICENSE)
|
|
15
|
+
[](https://github.com/acrool/react-picker/blob/main/LICENSE)
|
|
16
|
+
|
|
17
|
+
[](https://www.npmjs.com/package/@acrool/react-picker)
|
|
18
|
+
[](https://www.npmjs.com/package/@acrool/react-picker)
|
|
19
|
+
|
|
20
|
+
</div>
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
## Features
|
|
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)
|
|
32
|
+
|
|
33
|
+
## Install
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
yarn add @acrool/react-picker
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Usage
|
|
40
|
+
|
|
41
|
+
add in your index.tsx
|
|
42
|
+
```tst
|
|
43
|
+
import "@acrool/react-picker/dist/index.css";
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
add in your App.tsx
|
|
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
|
+
|
|
51
|
+
```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
|
|
70
|
+
|
|
71
|
+
Add the lightbox to the display column list by throwing the Show method
|
|
72
|
+
|
|
73
|
+
***Defined Picker***
|
|
74
|
+
|
|
75
|
+
```tsx
|
|
76
|
+
import {animation, createPicker, IPickerOptions, usePicker} from '@acrool/react-picker';
|
|
77
|
+
|
|
78
|
+
const pickerProps: IPickerOptions = {
|
|
79
|
+
variants: animation.fadeInDown,
|
|
80
|
+
className: 'p-3'
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
interface IProps {
|
|
84
|
+
myVar: string
|
|
85
|
+
}
|
|
86
|
+
|
|
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
|
+
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
## B. Custom state picker component
|
|
123
|
+
|
|
124
|
+
The inside of the light box is controlled by its own state, which is displayed through rendering, such as using HashRouter.
|
|
125
|
+
|
|
126
|
+
***Defined Picker***
|
|
127
|
+
|
|
128
|
+
```tsx
|
|
129
|
+
import {animation, createStatePicker, IPickerOptions, usePicker} from '@acrool/react-picker';
|
|
130
|
+
import {useHashParams} from '@acrool/react-router-hash';
|
|
131
|
+
|
|
132
|
+
const pickerProps: IPickerOptions = {
|
|
133
|
+
variants: animation.fadeInDown,
|
|
134
|
+
className: 'p-3'
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
interface IProps {
|
|
138
|
+
myVar: string
|
|
139
|
+
}
|
|
140
|
+
|
|
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
|
+
);
|
|
160
|
+
|
|
161
|
+
export default PromotionHashPicker;
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
|
|
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.
|
|
168
|
+
|
|
169
|
+
```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
|
+
|
|
174
|
+
const history = createBrowserHistory({window});
|
|
175
|
+
|
|
176
|
+
const RouterSetting = () => {
|
|
177
|
+
return <Router>
|
|
178
|
+
|
|
179
|
+
<Routes>
|
|
180
|
+
<Route path="/" element={<Example/>} />
|
|
181
|
+
</Routes>
|
|
182
|
+
|
|
183
|
+
<HashRoutes>
|
|
184
|
+
<HashRoute path="promotion/:id" element={<PromotionHashPicker/>}/>
|
|
185
|
+
</HashRoutes>
|
|
186
|
+
|
|
187
|
+
{/* Add this */}
|
|
188
|
+
<PickerPortal/>
|
|
189
|
+
|
|
190
|
+
</Router>;
|
|
191
|
+
};
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
***Use Picker***
|
|
197
|
+
|
|
198
|
+
then in your page
|
|
199
|
+
|
|
200
|
+
```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>
|
|
209
|
+
}
|
|
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
|
+
|
|
229
|
+
|
|
230
|
+
There is also a example that you can play with it:
|
|
231
|
+
|
|
232
|
+
[](https://acrool-react-picker.pages.dev)
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
## License
|
|
236
|
+
|
|
237
|
+
MIT © [Acrool](https://github.com/acrool) & [Imagine](https://github.com/imagine10255)
|
|
238
|
+
|
|
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)
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { IPosition } from '../types';
|
|
3
|
+
interface IProps {
|
|
4
|
+
position: IPosition;
|
|
5
|
+
children: ReactNode;
|
|
6
|
+
}
|
|
7
|
+
declare const _default: import("react").ForwardRefExoticComponent<IProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
8
|
+
export default _default;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './MotionDrawer';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
interface IContextProps<T = any> {
|
|
3
|
+
hide: () => void;
|
|
4
|
+
show: () => void;
|
|
5
|
+
toggle: () => void;
|
|
6
|
+
isVisible: boolean;
|
|
7
|
+
inputFocus: () => void;
|
|
8
|
+
inputBlur: () => void;
|
|
9
|
+
isInputFocus: boolean;
|
|
10
|
+
value?: T;
|
|
11
|
+
onChange: (value: T) => void;
|
|
12
|
+
}
|
|
13
|
+
export declare const PickerProviderContext: React.Context<IContextProps<any>>;
|
|
14
|
+
export declare const PickerProviderConsumer: React.Consumer<IContextProps<any>>;
|
|
15
|
+
export declare const usePicker: () => IContextProps<any>;
|
|
16
|
+
export {};
|