@niibase/bottom-sheet-manager 1.1.0 → 1.3.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.
Files changed (63) hide show
  1. package/README.md +372 -38
  2. package/lib/commonjs/events.js +100 -15
  3. package/lib/commonjs/events.js.map +1 -1
  4. package/lib/commonjs/index.js +7 -0
  5. package/lib/commonjs/index.js.map +1 -1
  6. package/lib/commonjs/manager.js +107 -29
  7. package/lib/commonjs/manager.js.map +1 -1
  8. package/lib/commonjs/provider.js +69 -28
  9. package/lib/commonjs/provider.js.map +1 -1
  10. package/lib/commonjs/router/index.js +50 -21
  11. package/lib/commonjs/router/index.js.map +1 -1
  12. package/lib/commonjs/router/router.js +137 -12
  13. package/lib/commonjs/router/router.js.map +1 -1
  14. package/lib/commonjs/router/view.js +194 -84
  15. package/lib/commonjs/router/view.js.map +1 -1
  16. package/lib/commonjs/sheet.js +125 -76
  17. package/lib/commonjs/sheet.js.map +1 -1
  18. package/lib/module/events.js +100 -15
  19. package/lib/module/events.js.map +1 -1
  20. package/lib/module/index.js +1 -1
  21. package/lib/module/index.js.map +1 -1
  22. package/lib/module/manager.js +108 -29
  23. package/lib/module/manager.js.map +1 -1
  24. package/lib/module/provider.js +65 -25
  25. package/lib/module/provider.js.map +1 -1
  26. package/lib/module/router/index.js +34 -18
  27. package/lib/module/router/index.js.map +1 -1
  28. package/lib/module/router/router.js +135 -11
  29. package/lib/module/router/router.js.map +1 -1
  30. package/lib/module/router/view.js +194 -84
  31. package/lib/module/router/view.js.map +1 -1
  32. package/lib/module/sheet.js +127 -78
  33. package/lib/module/sheet.js.map +1 -1
  34. package/lib/typescript/events.d.ts +46 -12
  35. package/lib/typescript/events.d.ts.map +1 -1
  36. package/lib/typescript/index.d.ts +1 -1
  37. package/lib/typescript/index.d.ts.map +1 -1
  38. package/lib/typescript/manager.d.ts +57 -7
  39. package/lib/typescript/manager.d.ts.map +1 -1
  40. package/lib/typescript/provider.d.ts +22 -3
  41. package/lib/typescript/provider.d.ts.map +1 -1
  42. package/lib/typescript/router/index.d.ts +33 -17
  43. package/lib/typescript/router/index.d.ts.map +1 -1
  44. package/lib/typescript/router/router.d.ts +44 -5
  45. package/lib/typescript/router/router.d.ts.map +1 -1
  46. package/lib/typescript/router/types.d.ts +113 -17
  47. package/lib/typescript/router/types.d.ts.map +1 -1
  48. package/lib/typescript/router/view.d.ts +1 -1
  49. package/lib/typescript/router/view.d.ts.map +1 -1
  50. package/lib/typescript/sheet.d.ts.map +1 -1
  51. package/lib/typescript/types.d.ts +27 -12
  52. package/lib/typescript/types.d.ts.map +1 -1
  53. package/package.json +1 -1
  54. package/src/events.ts +118 -27
  55. package/src/index.ts +6 -5
  56. package/src/manager.ts +156 -33
  57. package/src/provider.tsx +98 -44
  58. package/src/router/index.tsx +38 -31
  59. package/src/router/router.ts +184 -15
  60. package/src/router/types.ts +119 -22
  61. package/src/router/view.tsx +252 -132
  62. package/src/sheet.tsx +176 -95
  63. package/src/types.ts +144 -129
package/src/types.ts CHANGED
@@ -11,143 +11,158 @@ export type SheetReturnValue<Id extends SheetIds> = Sheets[Id]["returnValue"];
11
11
  type AnimationConfigs = WithSpringConfig | WithTimingConfig;
12
12
 
13
13
  export interface SheetProps<Id extends SheetIds = SheetIds> {
14
- readonly id: SheetID<Id>;
15
- readonly payload: SheetPayload<Id>;
16
- readonly context: string;
14
+ readonly id: SheetID<Id>;
15
+ readonly payload: SheetPayload<Id>;
16
+ readonly context: string;
17
17
  }
18
18
 
19
19
  export interface SheetDefinition<Payload = never, ReturnValue = never> {
20
- payload: Payload;
21
- returnValue: ReturnValue;
20
+ payload: Payload;
21
+ returnValue: ReturnValue;
22
22
  }
23
23
 
24
+ /**
25
+ * Defines how sheets behave when a new sheet is opened.
26
+ *
27
+ * - `switch`: Closes current sheet and shows new one. Previous sheet is
28
+ * restored when new one closes.
29
+ *
30
+ * - `replace`: Closes current sheet and opens new one. Previous sheet is
31
+ * removed from stack (not restored on close).
32
+ *
33
+ * - `push`: (experimental) Stacks new sheet on top. Previous sheet remains visible underneath.
34
+ */
35
+ export type StackBehavior = "switch" | "replace" | "push";
36
+
24
37
  export interface BottomSheetInstance<Id extends SheetIds = SheetIds> {
25
- /**
26
- * Close the bottom sheet.
27
- * @param args
28
- */
29
- readonly close: (
30
- ...args: SheetReturnValue<Id> extends never
31
- ? [
32
- options?: {
33
- /**
34
- * Snap animation configs.
35
- */
36
- animationConfigs?: AnimationConfigs;
37
- },
38
- ]
39
- : [
40
- options: {
41
- /**
42
- * Return some data to the caller on closing the `BottomSheet`.
43
- */
44
- value: SheetReturnValue<Id>;
45
-
46
- /**
47
- * Snap animation configs.
48
- */
49
- animationConfigs?: AnimationConfigs;
50
- },
51
- ]
52
- ) => void;
53
-
54
- /**
55
- * Snap to the maximum provided point from `snapPoints`.
56
- * @param animationConfigs Snap animation configs.
57
- */
58
- readonly expand: (animationConfigs?: AnimationConfigs) => void;
59
-
60
- /**
61
- * Snap to the minimum provided point from `snapPoints`.
62
- * @param animationConfigs Snap animation configs.
63
- */
64
- readonly collapse: (animationConfigs?: AnimationConfigs) => void;
65
-
66
- /**
67
- * Snap to one of the provided points from `snapPoints`.
68
- * @param index Snap point index.
69
- * @param animationConfigs Snap animation configs.
70
- */
71
- readonly snapToIndex: (index: number, animationConfigs?: AnimationConfigs) => void;
72
-
73
- /**
74
- * Snap to a position out of provided `snapPoints`.
75
- * @param position Position in pixel or percentage.
76
- * @param animationConfigs Snap animation configs.
77
- */
78
- readonly snapToPosition: (
79
- position: string | number,
80
- animationConfigs?: AnimationConfigs,
81
- ) => void;
38
+ /**
39
+ * Close the bottom sheet.
40
+ * @param args
41
+ */
42
+ readonly close: (
43
+ ...args: SheetReturnValue<Id> extends never
44
+ ? [
45
+ options?: {
46
+ /**
47
+ * Snap animation configs.
48
+ */
49
+ animationConfigs?: AnimationConfigs;
50
+ },
51
+ ]
52
+ : [
53
+ options: {
54
+ /**
55
+ * Return some data to the caller on closing the `BottomSheet`.
56
+ */
57
+ value: SheetReturnValue<Id>;
58
+
59
+ /**
60
+ * Snap animation configs.
61
+ */
62
+ animationConfigs?: AnimationConfigs;
63
+ },
64
+ ]
65
+ ) => void;
66
+
67
+ /**
68
+ * Snap to the maximum provided point from `snapPoints`.
69
+ * @param animationConfigs Snap animation configs.
70
+ */
71
+ readonly expand: (animationConfigs?: AnimationConfigs) => void;
72
+
73
+ /**
74
+ * Snap to the minimum provided point from `snapPoints`.
75
+ * @param animationConfigs Snap animation configs.
76
+ */
77
+ readonly collapse: (animationConfigs?: AnimationConfigs) => void;
78
+
79
+ /**
80
+ * Snap to one of the provided points from `snapPoints`.
81
+ * @param index Snap point index.
82
+ * @param animationConfigs Snap animation configs.
83
+ */
84
+ readonly snapToIndex: (index: number, animationConfigs?: AnimationConfigs) => void;
85
+
86
+ /**
87
+ * Snap to a position out of provided `snapPoints`.
88
+ * @param position Position in pixel or percentage.
89
+ * @param animationConfigs Snap animation configs.
90
+ */
91
+ readonly snapToPosition: (
92
+ position: string | number,
93
+ animationConfigs?: AnimationConfigs,
94
+ ) => void;
82
95
  }
83
96
 
84
97
  export type BottomSheetProps = Omit<
85
- RNBottomSheetProps,
86
- "children" | "onClose" | "animatedIndex" | "topInset"
98
+ RNBottomSheetProps,
99
+ "children" | "onClose"
87
100
  > & {
88
- /**
89
- * ID of the `BottomSheet`.
90
- */
91
- id?: SheetID<SheetIds>;
92
-
93
- /**
94
- * Content of the `BottomSheet`.
95
- */
96
- children: React.ReactNode;
97
-
98
- /**
99
- * When set to true, `BottomSheet` is closed when the hardware back button is pressed.
100
- * @default true
101
- */
102
- hardwareBackPressToClose?: boolean;
103
-
104
- /**
105
- * Callback when the sheet close.
106
- *
107
- * @type () => void;
108
- */
109
- onClose?: (data?: any) => void;
110
-
111
- /**
112
- * Event called before sheets is visible.
113
- * @param data Payload of the sheet if any.
114
- * @type () => void;
115
- */
116
- onBeforeShow?: (data?: any) => void;
117
-
118
- /**
119
- * Can click through the sheet to the underlying view.
120
- * @default false
121
- */
122
- clickThrough?: boolean;
123
-
124
- /**
125
- * Opacity of the sheet's overlay.
126
- * @default 0.45
127
- */
128
- opacity?: number;
129
-
130
- /**
131
- * Defines the stack behavior when modal mounts. (experimental)
132
- * @default "switch"
133
- */
134
- stackBehavior?: "push" | "replace" | "switch";
135
-
136
- /**
137
- * Whether the bottom sheet edge to edge.
138
- * @default false
139
- */
140
- fullScreen?: boolean;
141
-
142
- /**
143
- * Whether the bottom sheet is an iOS modal sheet type of animation.
144
- * @default false
145
- */
146
- iosModalSheetTypeOfAnimation?: boolean;
147
-
148
- className?: string;
149
- handleIndicatorClassName?: string;
150
- backgroundClassName?: string;
151
- containerClassName?: string;
152
- handleClassName?: string;
101
+ /**
102
+ * ID of the `BottomSheet`.
103
+ */
104
+ id?: SheetID<SheetIds>;
105
+
106
+ /**
107
+ * Content of the `BottomSheet`.
108
+ */
109
+ children: React.ReactNode;
110
+
111
+ /**
112
+ * When set to true, `BottomSheet` is closed when the hardware back button is pressed.
113
+ * @default true
114
+ */
115
+ hardwareBackPressToClose?: boolean;
116
+
117
+ /**
118
+ * Callback when the sheet close.
119
+ *
120
+ * @type () => any;
121
+ * @returns The data returned by the sheet to be returned when closed.
122
+ */
123
+ onClose?: (data?: unknown) => unknown;
124
+
125
+ /**
126
+ * Event called before sheets is visible.
127
+ * @param data Payload of the sheet if any.
128
+ * @type () => void;
129
+ */
130
+ onBeforeShow?: (data?: unknown) => void;
131
+
132
+ /**
133
+ * Can click through the sheet to the underlying view.
134
+ * @default false
135
+ */
136
+ clickThrough?: boolean;
137
+
138
+ /**
139
+ * Opacity of the sheet's overlay.
140
+ * @default 0.45
141
+ */
142
+ opacity?: number;
143
+
144
+ /**
145
+ * Defines the stack behavior when sheets are opened.
146
+ *
147
+ * - `switch`: (default) Dismisses the current sheet before showing the new one.
148
+ * - `replace`: Swaps the current sheet's content with smooth crossfade animation.
149
+ * - `push`: (experimental) Pushes new sheet on top, creating a navigable stack.
150
+ *
151
+ * @default "switch"
152
+ */
153
+ stackBehavior?: StackBehavior;
154
+
155
+ /**
156
+ * Whether the bottom sheet is an iOS 18 modal sheet type of animation.
157
+ * When enabled at snap point 90%, the content behind the sheet scales down and gets a
158
+ * border radius, similar to iOS 18 system sheets.
159
+ * @default false
160
+ */
161
+ iosModalSheetTypeOfAnimation?: boolean;
162
+
163
+ className?: string;
164
+ handleIndicatorClassName?: string;
165
+ backgroundClassName?: string;
166
+ containerClassName?: string;
167
+ handleClassName?: string;
153
168
  };