@acrool/react-picker 1.1.4 → 2.0.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
@@ -27,7 +27,7 @@
27
27
  ## Features
28
28
 
29
29
  - Quickly create various Pickers such as Datepicker, timepicker, Select dropdown, etc.
30
- - Plug and unplug using `framer-motion`
30
+ - Plug and unplug using `motion` (`AnimatePresence` + the mini `animate`, Web Animations API)
31
31
  - 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)
32
32
  - The agent menu OnChange and value changes can be controlled freely and will be saved when the menu is closed.
33
33
 
@@ -207,6 +207,42 @@ return <DropdownRoot onClick={handleOnClick}>
207
207
  </DropdownRoot>;
208
208
  ```
209
209
 
210
+ ## Custom animation
211
+
212
+ Animations are played by the mini `animate` from `motion` (Web Animations API), and the menu is removed only after the exit animation has finished.
213
+ Use `motionProps` together with `isDisabledAutoPosition` to position and animate the menu yourself:
214
+
215
+ ```tsx
216
+ import {createPicker, IMotionOptions} from '@acrool/react-picker';
217
+
218
+ const slideInBottom: IMotionOptions = {
219
+ // static styles that are not animated
220
+ style: {position: 'fixed', bottom: 0, left: 0, right: 0},
221
+ // keyframes: a single value animates from the current state, an array is the full keyframe list
222
+ enter: {
223
+ keyframes: {transform: ['translateY(100%)', 'translateY(0%)'], opacity: [.9, 1]},
224
+ options: {duration: .3, ease: 'easeOut'},
225
+ },
226
+ exit: {
227
+ keyframes: {transform: 'translateY(100%)', opacity: .9},
228
+ options: {duration: .18, ease: 'easeOut'},
229
+ },
230
+ };
231
+
232
+ export default createPicker(Main, Dropdown, {
233
+ motionProps: slideInBottom,
234
+ isVisibleMask: true,
235
+ isDisabledAutoPosition: true,
236
+ });
237
+ ```
238
+
239
+ ### Migrating from 1.x
240
+
241
+ - `framer-motion` is replaced by `motion` (installed as a dependency, nothing to add on your side).
242
+ - `motionProps` no longer takes framer-motion `variants` / `transition`. Move the values of `variants.initial` that are not animated into `style`, and describe the animation with `enter` / `exit` as above. Write movement and scaling as `transform` strings.
243
+ - The package no longer bundles `react/jsx-runtime`, so it also renders under Preact (`preact/compat`).
244
+
245
+
210
246
  ## License
211
247
 
212
248
  MIT © [Acrool](https://github.com/acrool) & [Imagine](https://github.com/imagine10255)
@@ -1,3 +1,9 @@
1
- import { IMotionOptions } from '../types';
2
- export declare const maskMotionProps: IMotionOptions;
1
+ import { IMotionOptions, IPickerAnimation } from '../types';
2
+ /**
3
+ * 遮罩的動畫: 淡入、淡出
4
+ */
5
+ export declare const maskMotion: Record<'enter' | 'exit', IPickerAnimation>;
6
+ /**
7
+ * 選單 (自動定位) 的動畫: 淡入,離場時淡出並略為縮小
8
+ */
3
9
  export declare const pickerMotionProps: IMotionOptions;
@@ -0,0 +1,21 @@
1
+ import { RefObject } from 'react';
2
+ import { IMotionOptions } from '../types';
3
+ interface IArgs {
4
+ maskRef: RefObject<HTMLElement | null>;
5
+ mainRef: RefObject<HTMLElement | null>;
6
+ motionProps?: IMotionOptions;
7
+ }
8
+ /**
9
+ * 播放進場、離場動畫 (遮罩 + 主內容)
10
+ *
11
+ * 離場後才移除節點由 AnimatePresence + usePresence 處理 (需放在 AnimatePresence 內),
12
+ * 動畫由 motion mini (Web Animations API) 播放
13
+ *
14
+ * @param maskRef
15
+ * @param mainRef
16
+ * @param motionProps
17
+ */
18
+ declare const usePresenceMotion: ({ maskRef, mainRef, motionProps }: IArgs) => {
19
+ isPresent: boolean;
20
+ };
21
+ export default usePresenceMotion;
@@ -1,5 +1,5 @@
1
1
  import { RefObject } from 'react';
2
- import { EVertical, IPosition } from '../types';
2
+ import { EVertical, IPickerAnimation, IPosition } from '../types';
3
3
  /**
4
4
  * Get the closest scrollable parent of an element.
5
5
  * Caches results for performance.
@@ -13,3 +13,16 @@ export declare function getScrollParent(element: HTMLElement): HTMLElement | Win
13
13
  * @param setVertical 設定垂直(top/bottom, 讓選擇棄可以決定順序
14
14
  */
15
15
  export declare const updatePosition: (anchorRef: RefObject<HTMLElement | null>, pickerRef: RefObject<HTMLElement | null>, setVertical: (vertical: EVertical) => void, importantPosition?: IPosition) => void;
16
+ /**
17
+ * 是否不播放動畫
18
+ * - 環境不支援 Web Animations API (例如測試環境)
19
+ * - 使用者開啟「減少動態效果」
20
+ */
21
+ export declare const checkIsSkipMotion: () => boolean;
22
+ /**
23
+ * 不播放動畫時,直接套用進場動畫的最後一格
24
+ * (例如自訂動畫用 transform 定位,沒有套用版面會跑掉)
25
+ * @param el
26
+ * @param animation
27
+ */
28
+ export declare const applyFinalKeyframe: (el: HTMLElement, animation?: IPickerAnimation) => void;