@oxyhq/bloom 0.15.0 → 0.16.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.
Files changed (208) hide show
  1. package/lib/commonjs/alert-dialog/AlertDialog.js +35 -27
  2. package/lib/commonjs/alert-dialog/AlertDialog.js.map +1 -1
  3. package/lib/commonjs/alert-dialog/index.js +1 -1
  4. package/lib/commonjs/alert-dialog/index.js.map +1 -1
  5. package/lib/commonjs/alert-dialog/index.web.js +1 -1
  6. package/lib/commonjs/alert-dialog/index.web.js.map +1 -1
  7. package/lib/commonjs/command/Command.js +27 -16
  8. package/lib/commonjs/command/Command.js.map +1 -1
  9. package/lib/commonjs/command/index.js +1 -1
  10. package/lib/commonjs/command/index.js.map +1 -1
  11. package/lib/commonjs/command/index.web.js +1 -1
  12. package/lib/commonjs/command/index.web.js.map +1 -1
  13. package/lib/commonjs/dialog/Dialog.js +39 -152
  14. package/lib/commonjs/dialog/Dialog.js.map +1 -1
  15. package/lib/commonjs/dialog/Dialog.web.js +61 -196
  16. package/lib/commonjs/dialog/Dialog.web.js.map +1 -1
  17. package/lib/commonjs/dialog/DialogBottomSheet.js +205 -0
  18. package/lib/commonjs/dialog/DialogBottomSheet.js.map +1 -0
  19. package/lib/commonjs/dialog/DialogContent.js +155 -0
  20. package/lib/commonjs/dialog/DialogContent.js.map +1 -0
  21. package/lib/commonjs/dialog/index.js +0 -13
  22. package/lib/commonjs/dialog/index.js.map +1 -1
  23. package/lib/commonjs/dialog/index.web.js +0 -19
  24. package/lib/commonjs/dialog/index.web.js.map +1 -1
  25. package/lib/commonjs/index.js +0 -29
  26. package/lib/commonjs/index.js.map +1 -1
  27. package/lib/commonjs/index.web.js +6 -35
  28. package/lib/commonjs/index.web.js.map +1 -1
  29. package/lib/module/alert-dialog/AlertDialog.js +35 -27
  30. package/lib/module/alert-dialog/AlertDialog.js.map +1 -1
  31. package/lib/module/alert-dialog/index.js +2 -2
  32. package/lib/module/alert-dialog/index.js.map +1 -1
  33. package/lib/module/alert-dialog/index.web.js +2 -2
  34. package/lib/module/alert-dialog/index.web.js.map +1 -1
  35. package/lib/module/command/Command.js +27 -16
  36. package/lib/module/command/Command.js.map +1 -1
  37. package/lib/module/command/index.js +2 -2
  38. package/lib/module/command/index.js.map +1 -1
  39. package/lib/module/command/index.web.js +2 -2
  40. package/lib/module/command/index.web.js.map +1 -1
  41. package/lib/module/dialog/Dialog.js +42 -155
  42. package/lib/module/dialog/Dialog.js.map +1 -1
  43. package/lib/module/dialog/Dialog.web.js +63 -198
  44. package/lib/module/dialog/Dialog.web.js.map +1 -1
  45. package/lib/module/dialog/DialogBottomSheet.js +200 -0
  46. package/lib/module/dialog/DialogBottomSheet.js.map +1 -0
  47. package/lib/module/dialog/DialogContent.js +148 -0
  48. package/lib/module/dialog/DialogContent.js.map +1 -0
  49. package/lib/module/dialog/index.js +0 -1
  50. package/lib/module/dialog/index.js.map +1 -1
  51. package/lib/module/dialog/index.web.js +0 -1
  52. package/lib/module/dialog/index.web.js.map +1 -1
  53. package/lib/module/index.js +1 -3
  54. package/lib/module/index.js.map +1 -1
  55. package/lib/module/index.web.js +1 -3
  56. package/lib/module/index.web.js.map +1 -1
  57. package/lib/typescript/commonjs/alert-dialog/AlertDialog.d.ts +13 -12
  58. package/lib/typescript/commonjs/alert-dialog/AlertDialog.d.ts.map +1 -1
  59. package/lib/typescript/commonjs/alert-dialog/index.d.ts.map +1 -1
  60. package/lib/typescript/commonjs/alert-dialog/index.web.d.ts.map +1 -1
  61. package/lib/typescript/commonjs/command/Command.d.ts +8 -8
  62. package/lib/typescript/commonjs/command/Command.d.ts.map +1 -1
  63. package/lib/typescript/commonjs/command/index.d.ts.map +1 -1
  64. package/lib/typescript/commonjs/command/index.web.d.ts.map +1 -1
  65. package/lib/typescript/commonjs/dialog/Dialog.d.ts +2 -3
  66. package/lib/typescript/commonjs/dialog/Dialog.d.ts.map +1 -1
  67. package/lib/typescript/commonjs/dialog/Dialog.web.d.ts +11 -8
  68. package/lib/typescript/commonjs/dialog/Dialog.web.d.ts.map +1 -1
  69. package/lib/typescript/commonjs/dialog/DialogBottomSheet.d.ts +29 -0
  70. package/lib/typescript/commonjs/dialog/DialogBottomSheet.d.ts.map +1 -0
  71. package/lib/typescript/commonjs/dialog/DialogContent.d.ts +32 -0
  72. package/lib/typescript/commonjs/dialog/DialogContent.d.ts.map +1 -0
  73. package/lib/typescript/commonjs/dialog/index.d.ts +0 -2
  74. package/lib/typescript/commonjs/dialog/index.d.ts.map +1 -1
  75. package/lib/typescript/commonjs/dialog/index.web.d.ts +0 -2
  76. package/lib/typescript/commonjs/dialog/index.web.d.ts.map +1 -1
  77. package/lib/typescript/commonjs/index.d.ts +2 -4
  78. package/lib/typescript/commonjs/index.d.ts.map +1 -1
  79. package/lib/typescript/commonjs/index.web.d.ts +2 -4
  80. package/lib/typescript/commonjs/index.web.d.ts.map +1 -1
  81. package/lib/typescript/module/alert-dialog/AlertDialog.d.ts +13 -12
  82. package/lib/typescript/module/alert-dialog/AlertDialog.d.ts.map +1 -1
  83. package/lib/typescript/module/alert-dialog/index.d.ts.map +1 -1
  84. package/lib/typescript/module/alert-dialog/index.web.d.ts.map +1 -1
  85. package/lib/typescript/module/command/Command.d.ts +8 -8
  86. package/lib/typescript/module/command/Command.d.ts.map +1 -1
  87. package/lib/typescript/module/command/index.d.ts.map +1 -1
  88. package/lib/typescript/module/command/index.web.d.ts.map +1 -1
  89. package/lib/typescript/module/dialog/Dialog.d.ts +2 -3
  90. package/lib/typescript/module/dialog/Dialog.d.ts.map +1 -1
  91. package/lib/typescript/module/dialog/Dialog.web.d.ts +11 -8
  92. package/lib/typescript/module/dialog/Dialog.web.d.ts.map +1 -1
  93. package/lib/typescript/module/dialog/DialogBottomSheet.d.ts +29 -0
  94. package/lib/typescript/module/dialog/DialogBottomSheet.d.ts.map +1 -0
  95. package/lib/typescript/module/dialog/DialogContent.d.ts +32 -0
  96. package/lib/typescript/module/dialog/DialogContent.d.ts.map +1 -0
  97. package/lib/typescript/module/dialog/index.d.ts +0 -2
  98. package/lib/typescript/module/dialog/index.d.ts.map +1 -1
  99. package/lib/typescript/module/dialog/index.web.d.ts +0 -2
  100. package/lib/typescript/module/dialog/index.web.d.ts.map +1 -1
  101. package/lib/typescript/module/index.d.ts +2 -4
  102. package/lib/typescript/module/index.d.ts.map +1 -1
  103. package/lib/typescript/module/index.web.d.ts +2 -4
  104. package/lib/typescript/module/index.web.d.ts.map +1 -1
  105. package/package.json +1 -18
  106. package/src/__tests__/AlertDialog.test.tsx +122 -0
  107. package/src/__tests__/BottomSheetGesture.test.tsx +135 -0
  108. package/src/__tests__/Command.test.tsx +107 -0
  109. package/src/__tests__/DialogBottomSheet.test.tsx +130 -0
  110. package/src/alert-dialog/AlertDialog.tsx +46 -36
  111. package/src/alert-dialog/index.ts +2 -2
  112. package/src/alert-dialog/index.web.ts +2 -2
  113. package/src/command/Command.tsx +30 -19
  114. package/src/command/index.ts +2 -2
  115. package/src/command/index.web.ts +2 -2
  116. package/src/dialog/Dialog.tsx +35 -168
  117. package/src/dialog/Dialog.web.tsx +52 -209
  118. package/src/dialog/DialogBottomSheet.tsx +235 -0
  119. package/src/dialog/DialogContent.tsx +157 -0
  120. package/src/dialog/index.ts +0 -2
  121. package/src/dialog/index.web.ts +0 -6
  122. package/src/index.ts +0 -11
  123. package/src/index.web.ts +0 -11
  124. package/lib/commonjs/dialog/CenteredDialog.js +0 -252
  125. package/lib/commonjs/dialog/CenteredDialog.js.map +0 -1
  126. package/lib/commonjs/dialog/CenteredDialog.web.js +0 -330
  127. package/lib/commonjs/dialog/CenteredDialog.web.js.map +0 -1
  128. package/lib/commonjs/dialog/centered-dialog-tokens.js +0 -62
  129. package/lib/commonjs/dialog/centered-dialog-tokens.js.map +0 -1
  130. package/lib/commonjs/dialog/centered-dialog-types.js +0 -6
  131. package/lib/commonjs/dialog/centered-dialog-types.js.map +0 -1
  132. package/lib/commonjs/responsive-sheet/ResponsiveSheet.js +0 -97
  133. package/lib/commonjs/responsive-sheet/ResponsiveSheet.js.map +0 -1
  134. package/lib/commonjs/responsive-sheet/ResponsiveSheet.web.js +0 -84
  135. package/lib/commonjs/responsive-sheet/ResponsiveSheet.web.js.map +0 -1
  136. package/lib/commonjs/responsive-sheet/index.js +0 -19
  137. package/lib/commonjs/responsive-sheet/index.js.map +0 -1
  138. package/lib/commonjs/responsive-sheet/index.web.js +0 -19
  139. package/lib/commonjs/responsive-sheet/index.web.js.map +0 -1
  140. package/lib/commonjs/responsive-sheet/types.js +0 -6
  141. package/lib/commonjs/responsive-sheet/types.js.map +0 -1
  142. package/lib/module/dialog/CenteredDialog.js +0 -246
  143. package/lib/module/dialog/CenteredDialog.js.map +0 -1
  144. package/lib/module/dialog/CenteredDialog.web.js +0 -324
  145. package/lib/module/dialog/CenteredDialog.web.js.map +0 -1
  146. package/lib/module/dialog/centered-dialog-tokens.js +0 -58
  147. package/lib/module/dialog/centered-dialog-tokens.js.map +0 -1
  148. package/lib/module/dialog/centered-dialog-types.js +0 -4
  149. package/lib/module/dialog/centered-dialog-types.js.map +0 -1
  150. package/lib/module/responsive-sheet/ResponsiveSheet.js +0 -90
  151. package/lib/module/responsive-sheet/ResponsiveSheet.js.map +0 -1
  152. package/lib/module/responsive-sheet/ResponsiveSheet.web.js +0 -77
  153. package/lib/module/responsive-sheet/ResponsiveSheet.web.js.map +0 -1
  154. package/lib/module/responsive-sheet/index.js +0 -4
  155. package/lib/module/responsive-sheet/index.js.map +0 -1
  156. package/lib/module/responsive-sheet/index.web.js +0 -12
  157. package/lib/module/responsive-sheet/index.web.js.map +0 -1
  158. package/lib/module/responsive-sheet/types.js +0 -4
  159. package/lib/module/responsive-sheet/types.js.map +0 -1
  160. package/lib/typescript/commonjs/dialog/CenteredDialog.d.ts +0 -22
  161. package/lib/typescript/commonjs/dialog/CenteredDialog.d.ts.map +0 -1
  162. package/lib/typescript/commonjs/dialog/CenteredDialog.web.d.ts +0 -31
  163. package/lib/typescript/commonjs/dialog/CenteredDialog.web.d.ts.map +0 -1
  164. package/lib/typescript/commonjs/dialog/centered-dialog-tokens.d.ts +0 -47
  165. package/lib/typescript/commonjs/dialog/centered-dialog-tokens.d.ts.map +0 -1
  166. package/lib/typescript/commonjs/dialog/centered-dialog-types.d.ts +0 -74
  167. package/lib/typescript/commonjs/dialog/centered-dialog-types.d.ts.map +0 -1
  168. package/lib/typescript/commonjs/responsive-sheet/ResponsiveSheet.d.ts +0 -22
  169. package/lib/typescript/commonjs/responsive-sheet/ResponsiveSheet.d.ts.map +0 -1
  170. package/lib/typescript/commonjs/responsive-sheet/ResponsiveSheet.web.d.ts +0 -16
  171. package/lib/typescript/commonjs/responsive-sheet/ResponsiveSheet.web.d.ts.map +0 -1
  172. package/lib/typescript/commonjs/responsive-sheet/index.d.ts +0 -3
  173. package/lib/typescript/commonjs/responsive-sheet/index.d.ts.map +0 -1
  174. package/lib/typescript/commonjs/responsive-sheet/index.web.d.ts +0 -3
  175. package/lib/typescript/commonjs/responsive-sheet/index.web.d.ts.map +0 -1
  176. package/lib/typescript/commonjs/responsive-sheet/types.d.ts +0 -58
  177. package/lib/typescript/commonjs/responsive-sheet/types.d.ts.map +0 -1
  178. package/lib/typescript/module/dialog/CenteredDialog.d.ts +0 -22
  179. package/lib/typescript/module/dialog/CenteredDialog.d.ts.map +0 -1
  180. package/lib/typescript/module/dialog/CenteredDialog.web.d.ts +0 -31
  181. package/lib/typescript/module/dialog/CenteredDialog.web.d.ts.map +0 -1
  182. package/lib/typescript/module/dialog/centered-dialog-tokens.d.ts +0 -47
  183. package/lib/typescript/module/dialog/centered-dialog-tokens.d.ts.map +0 -1
  184. package/lib/typescript/module/dialog/centered-dialog-types.d.ts +0 -74
  185. package/lib/typescript/module/dialog/centered-dialog-types.d.ts.map +0 -1
  186. package/lib/typescript/module/responsive-sheet/ResponsiveSheet.d.ts +0 -22
  187. package/lib/typescript/module/responsive-sheet/ResponsiveSheet.d.ts.map +0 -1
  188. package/lib/typescript/module/responsive-sheet/ResponsiveSheet.web.d.ts +0 -16
  189. package/lib/typescript/module/responsive-sheet/ResponsiveSheet.web.d.ts.map +0 -1
  190. package/lib/typescript/module/responsive-sheet/index.d.ts +0 -3
  191. package/lib/typescript/module/responsive-sheet/index.d.ts.map +0 -1
  192. package/lib/typescript/module/responsive-sheet/index.web.d.ts +0 -3
  193. package/lib/typescript/module/responsive-sheet/index.web.d.ts.map +0 -1
  194. package/lib/typescript/module/responsive-sheet/types.d.ts +0 -58
  195. package/lib/typescript/module/responsive-sheet/types.d.ts.map +0 -1
  196. package/src/__tests__/CenteredDialog.test.tsx +0 -108
  197. package/src/__tests__/ResponsiveSheet.test.tsx +0 -88
  198. package/src/dialog/CenteredDialog.stories.tsx +0 -125
  199. package/src/dialog/CenteredDialog.tsx +0 -305
  200. package/src/dialog/CenteredDialog.web.tsx +0 -374
  201. package/src/dialog/centered-dialog-tokens.ts +0 -68
  202. package/src/dialog/centered-dialog-types.ts +0 -74
  203. package/src/responsive-sheet/ResponsiveSheet.stories.tsx +0 -54
  204. package/src/responsive-sheet/ResponsiveSheet.tsx +0 -88
  205. package/src/responsive-sheet/ResponsiveSheet.web.tsx +0 -76
  206. package/src/responsive-sheet/index.ts +0 -6
  207. package/src/responsive-sheet/index.web.ts +0 -14
  208. package/src/responsive-sheet/types.ts +0 -60
@@ -1,305 +0,0 @@
1
- import React, { useMemo } from 'react';
2
- import {
3
- Modal,
4
- Pressable,
5
- ScrollView,
6
- StyleSheet,
7
- View,
8
- } from 'react-native';
9
-
10
- import { useInteractionState } from '../hooks/useInteractionState';
11
- import { TimesLarge_Stroke2_Corner0_Rounded as CloseIcon } from '../icons/Times';
12
- import { useTheme } from '../theme/use-theme';
13
- import { Text } from '../typography';
14
- import type { CenteredDialogProps } from './centered-dialog-types';
15
- import {
16
- CARD_RADIUS,
17
- DEFAULT_MAX_WIDTH,
18
- MAX_HEIGHT_FRACTION,
19
- resolveSpacing,
20
- VIEWPORT_GUTTER,
21
- } from './centered-dialog-tokens';
22
-
23
- const CLOSE_HIT_SLOP = { top: 8, bottom: 8, left: 8, right: 8 } as const;
24
-
25
- /** Stable testID for the dimmed backdrop. Overridden when a `testID` is set. */
26
- export const CENTERED_DIALOG_BACKDROP_TESTID = 'bloom-centered-dialog-backdrop';
27
-
28
- /**
29
- * @deprecated Use `<Dialog placement="center">` instead.
30
- *
31
- * Native variant of `<CenteredDialog>`.
32
- *
33
- * A controlled, centered modal: a transparent RN `Modal` (fade animation,
34
- * own native window) hosting a dimmed full-screen backdrop and a centered,
35
- * rounded card styled entirely from Bloom theme tokens.
36
- *
37
- * The backdrop is a sibling `Pressable` rendered BEHIND the card (absolute
38
- * filled), never a parent of it — so a tap on the card never bubbles to the
39
- * backdrop's close handler and the card never ends up nested inside the
40
- * backdrop's pressable on web.
41
- *
42
- * Dismissal: backdrop tap (when `dismissible`), the header close button, and
43
- * the Android hardware back button (`onRequestClose`) all call `onClose`.
44
- */
45
- export function CenteredDialog({
46
- visible,
47
- onClose,
48
- title,
49
- dismissible = true,
50
- maxWidth = DEFAULT_MAX_WIDTH,
51
- compact = true,
52
- showClose,
53
- children,
54
- footer,
55
- accessibilityLabel,
56
- closeAccessibilityLabel = 'Close dialog',
57
- backdropAccessibilityLabel = 'Dismiss dialog',
58
- cardStyle,
59
- contentStyle,
60
- testID,
61
- }: CenteredDialogProps) {
62
- const theme = useTheme();
63
- const backdropPress = useInteractionState();
64
-
65
- const spacing = useMemo(() => resolveSpacing(compact), [compact]);
66
- const resolvedShowClose = showClose ?? Boolean(title);
67
- const hasHeader = Boolean(title) || resolvedShowClose;
68
-
69
- const handleBackdropPress = dismissible ? onClose : undefined;
70
- // Android's hardware back must always be answerable; when the dialog is
71
- // non-dismissible we still need a handler (RN requires one for transparent
72
- // modals) — make it a no-op so back does nothing rather than crash.
73
- const handleRequestClose = dismissible ? onClose : noop;
74
-
75
- return (
76
- <Modal
77
- visible={visible}
78
- transparent
79
- animationType="fade"
80
- statusBarTranslucent
81
- onRequestClose={handleRequestClose}
82
- >
83
- <View style={[styles.root, { padding: VIEWPORT_GUTTER }]}>
84
- <Pressable
85
- testID={testID ? `${testID}-backdrop` : CENTERED_DIALOG_BACKDROP_TESTID}
86
- style={[
87
- styles.backdrop,
88
- { backgroundColor: theme.colors.overlay },
89
- backdropPress.state && styles.backdropPressed,
90
- ]}
91
- onPress={handleBackdropPress}
92
- onPressIn={backdropPress.onIn}
93
- onPressOut={backdropPress.onOut}
94
- disabled={!dismissible}
95
- accessibilityRole="button"
96
- accessibilityLabel={backdropAccessibilityLabel}
97
- />
98
-
99
- {/* RN's `Modal` already isolates its contents in a separate
100
- accessibility window, so an explicit `accessibilityViewIsModal`
101
- on the card is redundant here (and would mark the sibling
102
- backdrop inaccessible). The web fork uses `aria-modal` instead. */}
103
- <View
104
- testID={testID}
105
- accessibilityLabel={accessibilityLabel ?? title}
106
- style={[
107
- styles.card,
108
- {
109
- maxWidth,
110
- maxHeight: `${MAX_HEIGHT_FRACTION * 100}%`,
111
- backgroundColor: theme.colors.card,
112
- borderColor: theme.colors.border,
113
- shadowColor: theme.colors.shadow,
114
- },
115
- cardStyle,
116
- ]}
117
- >
118
- {hasHeader ? (
119
- <DialogHeader
120
- title={title}
121
- showClose={resolvedShowClose}
122
- padding={spacing.pad}
123
- gap={spacing.headerGap}
124
- closeAccessibilityLabel={closeAccessibilityLabel}
125
- onClose={onClose}
126
- />
127
- ) : null}
128
-
129
- <ScrollView
130
- style={styles.bodyScroll}
131
- contentContainerStyle={[
132
- {
133
- padding: spacing.pad,
134
- paddingTop: hasHeader ? spacing.headerGap : spacing.pad,
135
- gap: spacing.contentGap,
136
- },
137
- contentStyle,
138
- ]}
139
- showsVerticalScrollIndicator={false}
140
- keyboardShouldPersistTaps="handled"
141
- >
142
- {children}
143
- </ScrollView>
144
-
145
- {footer ? (
146
- <View
147
- style={[
148
- styles.footer,
149
- {
150
- padding: spacing.pad,
151
- paddingTop: spacing.footerGap,
152
- borderTopColor: theme.colors.borderLight,
153
- },
154
- ]}
155
- >
156
- {footer}
157
- </View>
158
- ) : null}
159
- </View>
160
- </View>
161
- </Modal>
162
- );
163
- }
164
-
165
- function DialogHeader({
166
- title,
167
- showClose,
168
- padding,
169
- gap,
170
- closeAccessibilityLabel,
171
- onClose,
172
- }: {
173
- title?: string;
174
- showClose: boolean;
175
- padding: number;
176
- gap: number;
177
- closeAccessibilityLabel: string;
178
- onClose: () => void;
179
- }) {
180
- const theme = useTheme();
181
-
182
- return (
183
- <View
184
- style={[
185
- styles.header,
186
- { paddingHorizontal: padding, paddingTop: padding, gap },
187
- ]}
188
- >
189
- {title ? (
190
- <Text
191
- accessibilityRole="header"
192
- numberOfLines={2}
193
- style={[styles.title, { color: theme.colors.text }]}
194
- >
195
- {title}
196
- </Text>
197
- ) : (
198
- <View style={styles.titleSpacer} />
199
- )}
200
- {showClose ? (
201
- <CloseButton
202
- accessibilityLabel={closeAccessibilityLabel}
203
- onPress={onClose}
204
- />
205
- ) : null}
206
- </View>
207
- );
208
- }
209
-
210
- function CloseButton({
211
- accessibilityLabel,
212
- onPress,
213
- }: {
214
- accessibilityLabel: string;
215
- onPress: () => void;
216
- }) {
217
- const theme = useTheme();
218
- const press = useInteractionState();
219
-
220
- return (
221
- <Pressable
222
- onPress={onPress}
223
- onPressIn={press.onIn}
224
- onPressOut={press.onOut}
225
- hitSlop={CLOSE_HIT_SLOP}
226
- accessibilityRole="button"
227
- accessibilityLabel={accessibilityLabel}
228
- style={[
229
- styles.closeButton,
230
- { backgroundColor: theme.colors.contrast50 },
231
- press.state && styles.closeButtonPressed,
232
- ]}
233
- >
234
- <CloseIcon size="sm" fill={theme.colors.textSecondary} />
235
- </Pressable>
236
- );
237
- }
238
-
239
- function noop(): void {
240
- /* non-dismissible: hardware back is intentionally inert */
241
- }
242
-
243
- const styles = StyleSheet.create({
244
- root: {
245
- flex: 1,
246
- alignItems: 'center',
247
- justifyContent: 'center',
248
- },
249
- backdrop: {
250
- // Spell out the absolute-fill rect (matches `Fill`'s canonical style)
251
- // rather than spreading the deprecated `StyleSheet.absoluteFillObject`,
252
- // which RN 0.83's generated types no longer surface on the `StyleSheet`
253
- // namespace and which downstream type-checks reject.
254
- position: 'absolute',
255
- top: 0,
256
- right: 0,
257
- bottom: 0,
258
- left: 0,
259
- },
260
- // A subtle deepening on press confirms the tap-to-dismiss affordance.
261
- backdropPressed: {
262
- opacity: 0.92,
263
- },
264
- card: {
265
- width: '100%',
266
- borderRadius: CARD_RADIUS,
267
- borderWidth: StyleSheet.hairlineWidth,
268
- overflow: 'hidden',
269
- shadowOpacity: 0.18,
270
- shadowRadius: 24,
271
- shadowOffset: { width: 0, height: 8 },
272
- elevation: 12,
273
- },
274
- header: {
275
- flexDirection: 'row',
276
- alignItems: 'flex-start',
277
- justifyContent: 'space-between',
278
- },
279
- title: {
280
- flex: 1,
281
- fontSize: 17,
282
- fontWeight: '700',
283
- lineHeight: 22,
284
- },
285
- titleSpacer: {
286
- flex: 1,
287
- },
288
- closeButton: {
289
- width: 28,
290
- height: 28,
291
- borderRadius: 14,
292
- alignItems: 'center',
293
- justifyContent: 'center',
294
- },
295
- closeButtonPressed: {
296
- opacity: 0.7,
297
- },
298
- bodyScroll: {
299
- flexGrow: 0,
300
- flexShrink: 1,
301
- },
302
- footer: {
303
- borderTopWidth: StyleSheet.hairlineWidth,
304
- },
305
- });
@@ -1,374 +0,0 @@
1
- import React, { useEffect, useMemo, useState } from 'react';
2
- import { Pressable, ScrollView, StyleSheet, View, type ViewStyle } from 'react-native';
3
- import { RemoveScrollBar } from 'react-remove-scroll-bar';
4
-
5
- import { useInteractionStates } from '../hooks/useInteractionState';
6
- import { TimesLarge_Stroke2_Corner0_Rounded as CloseIcon } from '../icons/Times';
7
- import { Portal } from '../portal/index.web';
8
- import { createOverlayZIndex } from '../styles/z-index';
9
- import { useTheme } from '../theme/use-theme';
10
- import { Text } from '../typography';
11
- import type { CenteredDialogProps } from './centered-dialog-types';
12
- import {
13
- CARD_RADIUS,
14
- DEFAULT_MAX_WIDTH,
15
- MAX_HEIGHT_FRACTION,
16
- resolveSpacing,
17
- VIEWPORT_GUTTER,
18
- } from './centered-dialog-tokens';
19
-
20
- const FADE_OUT_DURATION = 150;
21
- const CLOSE_HIT_SLOP = { top: 8, bottom: 8, left: 8, right: 8 } as const;
22
- const dialogZIndex = createOverlayZIndex();
23
-
24
- /** Stable testID for the dimmed backdrop. Overridden when a `testID` is set. */
25
- export const CENTERED_DIALOG_BACKDROP_TESTID = 'bloom-centered-dialog-backdrop';
26
-
27
- const stopPropagation = (e: { stopPropagation: () => void }) => e.stopPropagation();
28
-
29
- /**
30
- * @deprecated Use `<Dialog placement="center">` instead.
31
- *
32
- * Web variant of `<CenteredDialog>`.
33
- *
34
- * A centered modal card rendered into the Bloom Portal at the end of
35
- * `document.body`. Identical prop surface to native — `visible`, `onClose`,
36
- * `title`, `compact`, etc. — so call sites are platform agnostic.
37
- *
38
- * Differences from the native fork (necessary, not behavioural):
39
- * - Portal + `RemoveScrollBar` lock the underlying page while open.
40
- * - `Escape` dismisses (when `dismissible`).
41
- * - A `role="dialog"` panel with `aria-label`/`aria-modal` for a11y.
42
- * - A CSS fade/zoom keyframe matches the native modal's `fade` animation;
43
- * the keyframes are injected once (idempotent) into `<head>`.
44
- *
45
- * The backdrop is a sibling element BEHIND the card, and the card stops
46
- * click/press propagation so a tap on the card never dismisses.
47
- */
48
- export function CenteredDialog({
49
- visible,
50
- onClose,
51
- title,
52
- dismissible = true,
53
- maxWidth = DEFAULT_MAX_WIDTH,
54
- compact = true,
55
- showClose,
56
- children,
57
- footer,
58
- accessibilityLabel,
59
- closeAccessibilityLabel = 'Close dialog',
60
- backdropAccessibilityLabel = 'Dismiss dialog',
61
- cardStyle,
62
- contentStyle,
63
- testID,
64
- }: CenteredDialogProps) {
65
- const theme = useTheme();
66
- // `rendered` keeps the dialog mounted through its fade-out so a controlled
67
- // `visible` flip to `false` still plays an exit animation (matching the
68
- // native `Modal animationType="fade"`, which animates both directions).
69
- const [rendered, setRendered] = useState(visible);
70
- const isClosing = rendered && !visible;
71
-
72
- useKeyframes();
73
-
74
- // Mount immediately when opened; defer unmount until the exit animation
75
- // has played when closed.
76
- useEffect(() => {
77
- if (visible) {
78
- setRendered(true);
79
- return;
80
- }
81
- if (!rendered) return;
82
- const timer = setTimeout(() => setRendered(false), FADE_OUT_DURATION);
83
- return () => clearTimeout(timer);
84
- }, [visible, rendered]);
85
-
86
- // Escape-to-close while open. Scoped to the open lifetime so stacked
87
- // dialogs don't fight for the keydown — the top-most one wins via
88
- // document-level event order.
89
- useEffect(() => {
90
- if (!visible || !dismissible || typeof document === 'undefined') return;
91
- const handler = (e: KeyboardEvent) => {
92
- if (e.key === 'Escape') {
93
- e.stopPropagation();
94
- onClose();
95
- }
96
- };
97
- document.addEventListener('keydown', handler);
98
- return () => document.removeEventListener('keydown', handler);
99
- }, [visible, dismissible, onClose]);
100
-
101
- const spacing = useMemo(() => resolveSpacing(compact), [compact]);
102
- const resolvedShowClose = showClose ?? Boolean(title);
103
- const hasHeader = Boolean(title) || resolvedShowClose;
104
-
105
- if (!rendered) return null;
106
-
107
- // While closing, the backdrop must not re-trigger onClose (it's mid-exit).
108
- const handleBackdropPress = dismissible && !isClosing ? onClose : undefined;
109
-
110
- return (
111
- <Portal>
112
- <RemoveScrollBar />
113
- {/* `pointerEvents: 'auto'` opts back in from the Portal root's
114
- `pointer-events: none` (set so the idle portal doesn't intercept
115
- clicks on the underlying app). */}
116
- <View style={[styles.root, { padding: VIEWPORT_GUTTER }]}>
117
- <Pressable
118
- testID={testID ? `${testID}-backdrop` : CENTERED_DIALOG_BACKDROP_TESTID}
119
- onPress={handleBackdropPress}
120
- disabled={!dismissible}
121
- accessibilityRole="button"
122
- accessibilityLabel={backdropAccessibilityLabel}
123
- style={[
124
- styles.backdrop,
125
- { backgroundColor: theme.colors.overlay },
126
- backdropAnimation(isClosing),
127
- ]}
128
- />
129
-
130
- <View
131
- testID={testID}
132
- role="dialog"
133
- aria-modal
134
- aria-label={accessibilityLabel ?? title}
135
- onStartShouldSetResponder={returnsTrue}
136
- onResponderRelease={stopPropagation}
137
- {...({ onClick: stopPropagation } as Record<string, unknown>)}
138
- style={[
139
- styles.card,
140
- {
141
- maxWidth,
142
- maxHeight: `${MAX_HEIGHT_FRACTION * 100}%`,
143
- backgroundColor: theme.colors.card,
144
- borderColor: theme.colors.border,
145
- shadowColor: theme.colors.shadow,
146
- },
147
- cardAnimation(isClosing),
148
- cardStyle,
149
- ]}
150
- >
151
- {hasHeader ? (
152
- <DialogHeader
153
- title={title}
154
- showClose={resolvedShowClose}
155
- padding={spacing.pad}
156
- gap={spacing.headerGap}
157
- closeAccessibilityLabel={closeAccessibilityLabel}
158
- onClose={onClose}
159
- />
160
- ) : null}
161
-
162
- <ScrollView
163
- style={styles.bodyScroll}
164
- contentContainerStyle={[
165
- {
166
- padding: spacing.pad,
167
- paddingTop: hasHeader ? spacing.headerGap : spacing.pad,
168
- gap: spacing.contentGap,
169
- },
170
- contentStyle,
171
- ]}
172
- showsVerticalScrollIndicator={false}
173
- keyboardShouldPersistTaps="handled"
174
- >
175
- {children}
176
- </ScrollView>
177
-
178
- {footer ? (
179
- <View
180
- style={[
181
- styles.footer,
182
- {
183
- padding: spacing.pad,
184
- paddingTop: spacing.footerGap,
185
- borderTopColor: theme.colors.borderLight,
186
- },
187
- ]}
188
- >
189
- {footer}
190
- </View>
191
- ) : null}
192
- </View>
193
- </View>
194
- </Portal>
195
- );
196
- }
197
-
198
- function DialogHeader({
199
- title,
200
- showClose,
201
- padding,
202
- gap,
203
- closeAccessibilityLabel,
204
- onClose,
205
- }: {
206
- title?: string;
207
- showClose: boolean;
208
- padding: number;
209
- gap: number;
210
- closeAccessibilityLabel: string;
211
- onClose: () => void;
212
- }) {
213
- const theme = useTheme();
214
-
215
- return (
216
- <View
217
- style={[
218
- styles.header,
219
- { paddingHorizontal: padding, paddingTop: padding, gap },
220
- ]}
221
- >
222
- {title ? (
223
- <Text
224
- accessibilityRole="header"
225
- numberOfLines={2}
226
- style={[styles.title, { color: theme.colors.text }]}
227
- >
228
- {title}
229
- </Text>
230
- ) : (
231
- <View style={styles.titleSpacer} />
232
- )}
233
- {showClose ? (
234
- <CloseButton
235
- accessibilityLabel={closeAccessibilityLabel}
236
- onPress={onClose}
237
- />
238
- ) : null}
239
- </View>
240
- );
241
- }
242
-
243
- function CloseButton({
244
- accessibilityLabel,
245
- onPress,
246
- }: {
247
- accessibilityLabel: string;
248
- onPress: () => void;
249
- }) {
250
- const theme = useTheme();
251
- const { hovered, pressed, hoverHandlers, pressHandlers } = useInteractionStates();
252
-
253
- return (
254
- <Pressable
255
- onPress={onPress}
256
- {...hoverHandlers}
257
- {...pressHandlers}
258
- hitSlop={CLOSE_HIT_SLOP}
259
- accessibilityRole="button"
260
- accessibilityLabel={accessibilityLabel}
261
- style={[
262
- styles.closeButton,
263
- { backgroundColor: theme.colors.contrast50 },
264
- (hovered || pressed) && styles.closeButtonActive,
265
- ]}
266
- >
267
- <CloseIcon size="sm" fill={theme.colors.textSecondary} />
268
- </Pressable>
269
- );
270
- }
271
-
272
- const returnsTrue = () => true;
273
-
274
- function backdropAnimation(isClosing: boolean): ViewStyle {
275
- return isClosing
276
- ? ({ animation: `bloomCenteredDialogFadeOut ease-in ${FADE_OUT_DURATION}ms forwards` } as ViewStyle)
277
- : ({ animation: 'bloomCenteredDialogFadeIn ease-out 150ms' } as ViewStyle);
278
- }
279
-
280
- function cardAnimation(isClosing: boolean): ViewStyle {
281
- return isClosing
282
- ? ({ animation: `bloomCenteredDialogZoomOut ease-in ${FADE_OUT_DURATION}ms forwards` } as ViewStyle)
283
- : ({ animation: 'bloomCenteredDialogZoomIn cubic-bezier(0.16, 1, 0.3, 1) 200ms' } as ViewStyle);
284
- }
285
-
286
- const KEYFRAMES_ID = 'bloom-centered-dialog-keyframes';
287
-
288
- /**
289
- * CSS keyframes powering the web enter/exit animation. Injected once into
290
- * `<head>` on first mount (keyed by id so re-mounts and multiple dialogs
291
- * don't duplicate the rule). Mirrors the native modal's `fade` feel with a
292
- * subtle zoom on the card.
293
- */
294
- export const BLOOM_CENTERED_DIALOG_CSS = `
295
- @keyframes bloomCenteredDialogFadeIn { from { opacity: 0; } to { opacity: 1; } }
296
- @keyframes bloomCenteredDialogFadeOut { from { opacity: 1; } to { opacity: 0; } }
297
- @keyframes bloomCenteredDialogZoomIn { from { opacity: 0; transform: scale(0.96); } to { opacity: 1; transform: scale(1); } }
298
- @keyframes bloomCenteredDialogZoomOut { from { opacity: 1; transform: scale(1); } to { opacity: 0; transform: scale(0.96); } }
299
- `;
300
-
301
- function useKeyframes(): void {
302
- useEffect(() => {
303
- if (typeof document === 'undefined') return;
304
- if (document.getElementById(KEYFRAMES_ID)) return;
305
- const style = document.createElement('style');
306
- style.id = KEYFRAMES_ID;
307
- style.textContent = BLOOM_CENTERED_DIALOG_CSS;
308
- document.head.appendChild(style);
309
- }, []);
310
- }
311
-
312
- const styles = StyleSheet.create({
313
- root: {
314
- position: 'fixed' as 'absolute',
315
- top: 0,
316
- left: 0,
317
- right: 0,
318
- bottom: 0,
319
- zIndex: dialogZIndex.backdrop,
320
- alignItems: 'center',
321
- justifyContent: 'center',
322
- pointerEvents: 'auto',
323
- },
324
- backdrop: {
325
- position: 'fixed' as 'absolute',
326
- top: 0,
327
- left: 0,
328
- right: 0,
329
- bottom: 0,
330
- },
331
- card: {
332
- position: 'relative',
333
- width: '100%',
334
- borderRadius: CARD_RADIUS,
335
- borderWidth: 1,
336
- overflow: 'hidden',
337
- shadowOpacity: 0.18,
338
- shadowRadius: 24,
339
- shadowOffset: { width: 0, height: 8 },
340
- zIndex: dialogZIndex.surface,
341
- },
342
- header: {
343
- flexDirection: 'row',
344
- alignItems: 'flex-start',
345
- justifyContent: 'space-between',
346
- },
347
- title: {
348
- flex: 1,
349
- fontSize: 17,
350
- fontWeight: '700',
351
- lineHeight: 22,
352
- },
353
- titleSpacer: {
354
- flex: 1,
355
- },
356
- closeButton: {
357
- width: 28,
358
- height: 28,
359
- borderRadius: 14,
360
- alignItems: 'center',
361
- justifyContent: 'center',
362
- cursor: 'pointer',
363
- },
364
- closeButtonActive: {
365
- opacity: 0.7,
366
- },
367
- bodyScroll: {
368
- flexGrow: 0,
369
- flexShrink: 1,
370
- },
371
- footer: {
372
- borderTopWidth: 1,
373
- },
374
- });