@marktiderman/genesis-ui-native 2.0.3 → 2.2.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 +52 -0
- package/dist/{chunk-3LK5ZJ4M.js → chunk-2WCXMJL6.js} +2 -2
- package/dist/{chunk-3LK5ZJ4M.js.map → chunk-2WCXMJL6.js.map} +1 -1
- package/dist/{chunk-HNIEFTEL.js → chunk-F2TGDKOO.js} +2 -2
- package/dist/{chunk-HNIEFTEL.js.map → chunk-F2TGDKOO.js.map} +1 -1
- package/dist/{chunk-OMTXD7ND.js → chunk-FZTUSM56.js} +267 -93
- package/dist/chunk-FZTUSM56.js.map +1 -0
- package/dist/chunk-Z3AQYVUA.js +36 -0
- package/dist/chunk-Z3AQYVUA.js.map +1 -0
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.js +1 -1
- package/dist/data/index.js +1 -1
- package/dist/hooks/index.d.ts +12 -2
- package/dist/hooks/index.js +2 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +4 -4
- package/dist/layouts/index.d.ts +186 -13
- package/dist/layouts/index.js +2 -2
- package/package.json +6 -6
- package/src/components/__tests__/badge.test.tsx +1 -0
- package/src/components/textarea.tsx +1 -0
- package/src/hooks/__tests__/use-theme-roles.test.tsx +30 -0
- package/src/hooks/index.ts +1 -0
- package/src/hooks/use-theme-roles.ts +45 -0
- package/src/layouts/__tests__/apple-sign-in.test.tsx +97 -0
- package/src/layouts/__tests__/auth-screen.test.tsx +72 -0
- package/src/layouts/__tests__/auth.test.tsx +1 -0
- package/src/layouts/__tests__/keyboard-scroll.test.tsx +34 -0
- package/src/layouts/__tests__/nav-bar.test.tsx +1 -0
- package/src/layouts/__tests__/notifications-page-slots.test.tsx +23 -0
- package/src/layouts/__tests__/notifications-page.test.tsx +1 -0
- package/src/layouts/__tests__/screen-container.test.tsx +1 -0
- package/src/layouts/__tests__/settings-page-slots.test.tsx +41 -0
- package/src/layouts/__tests__/settings-page.test.tsx +1 -0
- package/src/layouts/__tests__/settings-sub-page.test.tsx +1 -0
- package/src/layouts/apple-sign-in.tsx +136 -0
- package/src/layouts/auth-screen.tsx +144 -0
- package/src/layouts/auth.tsx +41 -24
- package/src/layouts/index.ts +15 -1
- package/src/layouts/keyboard.tsx +39 -0
- package/src/layouts/notifications-page.tsx +63 -35
- package/src/layouts/screen-container.tsx +11 -3
- package/src/layouts/settings-page.tsx +122 -55
- package/src/layouts/settings-sub-page.tsx +21 -0
- package/dist/chunk-N4WHTQIO.js +0 -20
- package/dist/chunk-N4WHTQIO.js.map +0 -1
- package/dist/chunk-OMTXD7ND.js.map +0 -1
package/dist/layouts/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
|
-
import { ReactNode } from 'react';
|
|
2
|
+
import { ReactNode, ComponentType } from 'react';
|
|
3
|
+
import { ViewStyle } from 'react-native';
|
|
4
|
+
import { Slots, SlotPropsFor } from '@marktiderman/genesis-core/slots';
|
|
3
5
|
|
|
4
6
|
type SafeAreaEdge = "top" | "bottom" | "left" | "right";
|
|
5
7
|
type ScrollEdgeBehavior = "match" | "transparent" | "opaque";
|
|
@@ -31,6 +33,8 @@ interface ScreenContainerProps {
|
|
|
31
33
|
* Only used when `scroll` is true.
|
|
32
34
|
*/
|
|
33
35
|
keyboardShouldPersistTaps?: "always" | "never" | "handled";
|
|
36
|
+
/** Style on the root, e.g. a theme-role background color. */
|
|
37
|
+
style?: ViewStyle;
|
|
34
38
|
/** testID on the root container. */
|
|
35
39
|
testID?: string;
|
|
36
40
|
}
|
|
@@ -69,7 +73,7 @@ interface ScreenHeaderProps {
|
|
|
69
73
|
* return <><Stack.Screen options={opts} /><ScreenContainer>...</ScreenContainer></>;
|
|
70
74
|
*/
|
|
71
75
|
declare function composeHeaderOptions(props: ScreenHeaderProps): Record<string, unknown>;
|
|
72
|
-
declare function ScreenContainer({ children, scroll, safeAreaEdges, statusBar, themeMode, className, contentClassName, keyboardShouldPersistTaps, testID, }: ScreenContainerProps): react.JSX.Element;
|
|
76
|
+
declare function ScreenContainer({ children, scroll, safeAreaEdges, statusBar, themeMode, className, contentClassName, keyboardShouldPersistTaps, style, testID, }: ScreenContainerProps): react.JSX.Element;
|
|
73
77
|
|
|
74
78
|
interface NavBarSaveButtonProps {
|
|
75
79
|
/** Press handler. Disabled when not provided OR when `disabled`/`loading`. */
|
|
@@ -143,6 +147,32 @@ interface SettingsPageSection {
|
|
|
143
147
|
/** Rows in render order. */
|
|
144
148
|
rows: SettingsPageRow[];
|
|
145
149
|
}
|
|
150
|
+
/** A destructive-tone action in the footer, e.g. "Sign out". */
|
|
151
|
+
interface SettingsPageDangerousAction {
|
|
152
|
+
label: string;
|
|
153
|
+
onPress: () => void;
|
|
154
|
+
/** When true, renders with extra emphasis. Default `false`. */
|
|
155
|
+
emphasized?: boolean;
|
|
156
|
+
testID?: string;
|
|
157
|
+
}
|
|
158
|
+
/** The parts of a {@link SettingsPage} that `slots` and `slotProps` reach, with the props each receives. */
|
|
159
|
+
type SettingsPageSlotMap = {
|
|
160
|
+
sectionHeader: {
|
|
161
|
+
title: string;
|
|
162
|
+
testID: string;
|
|
163
|
+
};
|
|
164
|
+
row: SettingsPageRow & {
|
|
165
|
+
testID: string;
|
|
166
|
+
isLast: boolean;
|
|
167
|
+
};
|
|
168
|
+
footnote: {
|
|
169
|
+
text: string;
|
|
170
|
+
};
|
|
171
|
+
dangerousActions: {
|
|
172
|
+
actions: SettingsPageDangerousAction[];
|
|
173
|
+
testID: string;
|
|
174
|
+
};
|
|
175
|
+
};
|
|
146
176
|
interface SettingsPageProps extends ScreenHeaderProps {
|
|
147
177
|
/** Sectioned content. Order is preserved. */
|
|
148
178
|
sections: SettingsPageSection[];
|
|
@@ -150,13 +180,11 @@ interface SettingsPageProps extends ScreenHeaderProps {
|
|
|
150
180
|
* Optional dangerous-action row(s) shown after the last section in a
|
|
151
181
|
* destructive-tone footer. Typical: "Sign out", "Delete account".
|
|
152
182
|
*/
|
|
153
|
-
dangerousActions?:
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
testID?: string;
|
|
159
|
-
}[];
|
|
183
|
+
dangerousActions?: SettingsPageDangerousAction[];
|
|
184
|
+
/** Replace (a component) or drop (`null`) one part. */
|
|
185
|
+
slots?: Slots<SettingsPageSlotMap>;
|
|
186
|
+
/** More props for a default part, merged over what the layout passes. */
|
|
187
|
+
slotProps?: SlotPropsFor<SettingsPageSlotMap>;
|
|
160
188
|
/** Override root container styling. */
|
|
161
189
|
className?: string;
|
|
162
190
|
/** testID on the root container. Default `"settings-page"`. */
|
|
@@ -173,7 +201,7 @@ interface SettingsPageProps extends ScreenHeaderProps {
|
|
|
173
201
|
declare function getSettingsPageStackOptions(props: ScreenHeaderProps & {
|
|
174
202
|
headerTitle?: string;
|
|
175
203
|
}): Record<string, unknown>;
|
|
176
|
-
declare function SettingsPage({ sections, dangerousActions, className, testID, children, }: SettingsPageProps): react.JSX.Element;
|
|
204
|
+
declare function SettingsPage({ sections, dangerousActions, className, testID, children, slots, slotProps, }: SettingsPageProps): react.JSX.Element;
|
|
177
205
|
|
|
178
206
|
interface SettingsSubPageProps extends ScreenHeaderProps {
|
|
179
207
|
/** Form / detail body content. Pass any node tree. */
|
|
@@ -246,6 +274,20 @@ interface NotificationItem {
|
|
|
246
274
|
/** testID override. Falls back to `notifications-row-<id>`. */
|
|
247
275
|
testID?: string;
|
|
248
276
|
}
|
|
277
|
+
/** The parts of a {@link NotificationsPage} that `slots` and `slotProps` reach. */
|
|
278
|
+
type NotificationsPageSlotMap = {
|
|
279
|
+
sectionHeader: {
|
|
280
|
+
title: string;
|
|
281
|
+
};
|
|
282
|
+
row: NotificationItem & {
|
|
283
|
+
testID: string;
|
|
284
|
+
};
|
|
285
|
+
empty: {
|
|
286
|
+
title: string;
|
|
287
|
+
body: string;
|
|
288
|
+
testID: string;
|
|
289
|
+
};
|
|
290
|
+
};
|
|
249
291
|
interface NotificationsPageProps extends ScreenHeaderProps {
|
|
250
292
|
/** Notification items. Empty array → empty state. */
|
|
251
293
|
items: NotificationItem[];
|
|
@@ -255,8 +297,12 @@ interface NotificationsPageProps extends ScreenHeaderProps {
|
|
|
255
297
|
onRefresh?: () => void | Promise<void>;
|
|
256
298
|
/** Mark-all-read handler. When provided, exposes a header action. */
|
|
257
299
|
onMarkAllRead?: () => void;
|
|
258
|
-
/** Override the auto-rendered empty state. */
|
|
300
|
+
/** Override the auto-rendered empty state. Prefer `slots.empty`. */
|
|
259
301
|
emptyState?: ReactNode;
|
|
302
|
+
/** Replace (a component) or drop (`null`) one part. */
|
|
303
|
+
slots?: Slots<NotificationsPageSlotMap>;
|
|
304
|
+
/** More props for a default part, merged over what the layout passes. */
|
|
305
|
+
slotProps?: SlotPropsFor<NotificationsPageSlotMap>;
|
|
260
306
|
/** Optional override of the empty-state title. */
|
|
261
307
|
emptyTitle?: string;
|
|
262
308
|
/** Optional override of the empty-state body copy. */
|
|
@@ -280,7 +326,7 @@ declare function getNotificationsPageStackOptions(props: {
|
|
|
280
326
|
headerRight?: ScreenHeaderProps["headerRight"];
|
|
281
327
|
headerOptions?: ScreenHeaderProps["headerOptions"];
|
|
282
328
|
}): Record<string, unknown>;
|
|
283
|
-
declare function NotificationsPage({ items, refreshing, onRefresh, emptyState, emptyTitle, emptyBody, className, testID, }: NotificationsPageProps): react.JSX.Element;
|
|
329
|
+
declare function NotificationsPage({ items, refreshing, onRefresh, emptyState, emptyTitle, emptyBody, className, testID, slots, slotProps, }: NotificationsPageProps): react.JSX.Element;
|
|
284
330
|
|
|
285
331
|
interface AuthBrandingProps {
|
|
286
332
|
/** Brand mark (logo node). */
|
|
@@ -305,6 +351,15 @@ type SocialAuthProvider = {
|
|
|
305
351
|
onPress: () => void | Promise<void>;
|
|
306
352
|
/** When true, the button is disabled (e.g., loading). */
|
|
307
353
|
disabled?: boolean;
|
|
354
|
+
/**
|
|
355
|
+
* Draw the provider's own button instead of the default outline button,
|
|
356
|
+
* for a provider whose brand rules require theirs (Apple: see
|
|
357
|
+
* `appleProvider`). Receives the testID the default would use.
|
|
358
|
+
*/
|
|
359
|
+
render?: (props: {
|
|
360
|
+
testID: string;
|
|
361
|
+
disabled?: boolean;
|
|
362
|
+
}) => ReactNode;
|
|
308
363
|
};
|
|
309
364
|
interface SocialAuthRowProps {
|
|
310
365
|
providers: SocialAuthProvider[];
|
|
@@ -361,4 +416,122 @@ declare function ForgotPasswordLink({ onPress, label, testID, }: {
|
|
|
361
416
|
testID?: string;
|
|
362
417
|
}): react.JSX.Element;
|
|
363
418
|
|
|
364
|
-
|
|
419
|
+
/** The parts of an {@link AuthScreen} that `slots` and `slotProps` reach. */
|
|
420
|
+
type AuthScreenSlotMap = {
|
|
421
|
+
branding: AuthBrandingProps;
|
|
422
|
+
social: {
|
|
423
|
+
providers: SocialAuthProvider[];
|
|
424
|
+
testID: string;
|
|
425
|
+
};
|
|
426
|
+
form: AuthFormProps;
|
|
427
|
+
footer: {
|
|
428
|
+
children: ReactNode;
|
|
429
|
+
testID: string;
|
|
430
|
+
};
|
|
431
|
+
};
|
|
432
|
+
interface AuthScreenProps {
|
|
433
|
+
/** Logo, headline and subhead above everything else. */
|
|
434
|
+
branding?: AuthBrandingProps;
|
|
435
|
+
/**
|
|
436
|
+
* Sign-in providers (Apple, Google…). None: no social row. A `null` or
|
|
437
|
+
* `false` entry is skipped, so a platform-only provider such as
|
|
438
|
+
* `appleProvider(...)` (null off iOS) goes in the list as is.
|
|
439
|
+
*/
|
|
440
|
+
providers?: Array<SocialAuthProvider | null | false | undefined>;
|
|
441
|
+
/** The email form. */
|
|
442
|
+
form: AuthFormProps;
|
|
443
|
+
/** Adds a "Forgot password?" link below the fields (password mode only). */
|
|
444
|
+
onForgotPassword?: () => void;
|
|
445
|
+
/** Below the form: terms, a sign-up link. */
|
|
446
|
+
footer?: ReactNode;
|
|
447
|
+
/** Replace (a component) or drop (`null`) one part. */
|
|
448
|
+
slots?: Slots<AuthScreenSlotMap>;
|
|
449
|
+
/** More props for a default part, merged over what the screen passes. */
|
|
450
|
+
slotProps?: SlotPropsFor<AuthScreenSlotMap>;
|
|
451
|
+
/** testID on the root container. Default `"auth-screen"`. */
|
|
452
|
+
testID?: string;
|
|
453
|
+
}
|
|
454
|
+
declare function AuthScreen({ branding, providers: givenProviders, form, onForgotPassword, footer, slots, slotProps, testID, }: AuthScreenProps): react.JSX.Element;
|
|
455
|
+
|
|
456
|
+
/** The props Genesis passes to a keyboard-aware scroll view. */
|
|
457
|
+
interface KeyboardScrollProps {
|
|
458
|
+
children?: ReactNode;
|
|
459
|
+
testID?: string;
|
|
460
|
+
keyboardShouldPersistTaps?: "always" | "never" | "handled";
|
|
461
|
+
contentContainerStyle?: ViewStyle;
|
|
462
|
+
/** iOS: inset content under a translucent or large-title header, as `ScreenContainer` does. */
|
|
463
|
+
contentInsetAdjustmentBehavior?: "automatic" | "scrollableAxes" | "never" | "always";
|
|
464
|
+
/** Extra space between the focused input and the keyboard. */
|
|
465
|
+
bottomOffset?: number;
|
|
466
|
+
}
|
|
467
|
+
declare function KeyboardScrollProvider({ component, children }: {
|
|
468
|
+
component: ComponentType<KeyboardScrollProps>;
|
|
469
|
+
children: ReactNode;
|
|
470
|
+
}): react.FunctionComponentElement<react.ProviderProps<ComponentType<KeyboardScrollProps> | null>>;
|
|
471
|
+
/** The app's keyboard-aware scroll view, or null when none was provided. */
|
|
472
|
+
declare function useKeyboardScroll(): ComponentType<KeyboardScrollProps> | null;
|
|
473
|
+
|
|
474
|
+
/** The parts of `expo-apple-authentication` the button uses. Pass the module itself. */
|
|
475
|
+
interface AppleButtonModuleLike {
|
|
476
|
+
AppleAuthenticationButton: ComponentType<{
|
|
477
|
+
buttonType: number;
|
|
478
|
+
buttonStyle: number;
|
|
479
|
+
cornerRadius?: number;
|
|
480
|
+
onPress: () => void;
|
|
481
|
+
style?: ViewStyle;
|
|
482
|
+
testID?: string;
|
|
483
|
+
accessibilityState?: {
|
|
484
|
+
disabled?: boolean;
|
|
485
|
+
busy?: boolean;
|
|
486
|
+
};
|
|
487
|
+
}>;
|
|
488
|
+
AppleAuthenticationButtonType: {
|
|
489
|
+
SIGN_IN: number;
|
|
490
|
+
CONTINUE: number;
|
|
491
|
+
SIGN_UP: number;
|
|
492
|
+
};
|
|
493
|
+
AppleAuthenticationButtonStyle: {
|
|
494
|
+
BLACK: number;
|
|
495
|
+
WHITE: number;
|
|
496
|
+
WHITE_OUTLINE: number;
|
|
497
|
+
};
|
|
498
|
+
}
|
|
499
|
+
interface AppleSignInButtonProps {
|
|
500
|
+
/** `expo-apple-authentication`. */
|
|
501
|
+
apple: AppleButtonModuleLike;
|
|
502
|
+
/** Usually `() => signInWithApple(supabase, AppleAuthentication, { digest })` from `@marktiderman/genesis-supabase/native`. */
|
|
503
|
+
onPress: () => void | Promise<void>;
|
|
504
|
+
/** Apple's wording: "Sign in with Apple", "Continue with Apple" (default) or "Sign up with Apple". */
|
|
505
|
+
type?: "sign-in" | "continue" | "sign-up";
|
|
506
|
+
/** `"auto"` (default): black in light mode, white in dark, as Apple recommends. */
|
|
507
|
+
appearance?: "auto" | "black" | "white" | "white-outline";
|
|
508
|
+
/** Default 10, to sit with Genesis buttons. */
|
|
509
|
+
cornerRadius?: number;
|
|
510
|
+
/** Default 44, the recommended touch target (Apple's HIG minimum for this button is 30pt). */
|
|
511
|
+
height?: number;
|
|
512
|
+
/** Dims the button and ignores presses. It is also ignored on its own while an `onPress` promise is pending, so a second tap can't open a second sheet. */
|
|
513
|
+
disabled?: boolean;
|
|
514
|
+
testID?: string;
|
|
515
|
+
}
|
|
516
|
+
/** Apple's branded button, full width. Renders nothing off iOS. */
|
|
517
|
+
declare function AppleSignInButton({ apple, onPress, type, appearance, cornerRadius, height, disabled, testID, }: AppleSignInButtonProps): react.JSX.Element | null;
|
|
518
|
+
interface AppleProviderOptions extends Omit<AppleSignInButtonProps, "apple" | "testID"> {
|
|
519
|
+
/** `expo-apple-authentication`, or `undefined` where it isn't installed. */
|
|
520
|
+
apple: AppleButtonModuleLike | null | undefined;
|
|
521
|
+
/**
|
|
522
|
+
* The provider's `label`, used only by `AuthScreen`'s dev warning and a
|
|
523
|
+
* custom `social` slot. Apple's button draws and announces its own localized
|
|
524
|
+
* text. Default follows `type`: "Continue with Apple", "Sign in with Apple"
|
|
525
|
+
* or "Sign up with Apple".
|
|
526
|
+
*/
|
|
527
|
+
label?: string;
|
|
528
|
+
}
|
|
529
|
+
/**
|
|
530
|
+
* A `SocialAuthProvider` (id `"apple"`) that draws Apple's button, for
|
|
531
|
+
* `AuthScreen`'s `providers`. `null` off iOS or without the module.
|
|
532
|
+
*
|
|
533
|
+
* @stability Beta
|
|
534
|
+
*/
|
|
535
|
+
declare function appleProvider({ apple, label, ...button }: AppleProviderOptions): SocialAuthProvider | null;
|
|
536
|
+
|
|
537
|
+
export { type AppleButtonModuleLike, type AppleProviderOptions, AppleSignInButton, type AppleSignInButtonProps, AuthBranding, type AuthBrandingProps, AuthForm, type AuthFormProps, type AuthFormValues, AuthScreen, type AuthScreenProps, type AuthScreenSlotMap, ForgotPasswordLink, type KeyboardScrollProps, KeyboardScrollProvider, NavBarSaveButton, type NavBarSaveButtonProps, NavBarSearchBar, type NavBarSearchBarProps, NavBarTitle, type NavBarTitleProps, type NotificationItem, NotificationsPage, type NotificationsPageProps, type NotificationsPageSlotMap, type SafeAreaEdge, ScreenContainer, type ScreenContainerProps, type ScreenHeaderProps, type ScrollEdgeBehavior, SettingsPage, type SettingsPageDangerousAction, type SettingsPageProps, type SettingsPageRow, type SettingsPageSection, type SettingsPageSlotMap, SettingsSubPage, type SettingsSubPageProps, type SocialAuthProvider, SocialAuthRow, type SocialAuthRowProps, appleProvider, composeHeaderOptions, confirmDiscardChanges, getNotificationsPageStackOptions, getSettingsPageStackOptions, getSettingsSubPageStackOptions, useKeyboardScroll };
|
package/dist/layouts/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export { AuthBranding, AuthForm, ForgotPasswordLink, NavBarSaveButton, NavBarSearchBar, NavBarTitle, NotificationsPage, ScreenContainer, SettingsPage, SettingsSubPage, SocialAuthRow, composeHeaderOptions, confirmDiscardChanges, getNotificationsPageStackOptions, getSettingsPageStackOptions, getSettingsSubPageStackOptions } from '../chunk-
|
|
1
|
+
export { AppleSignInButton, AuthBranding, AuthForm, AuthScreen, ForgotPasswordLink, KeyboardScrollProvider, NavBarSaveButton, NavBarSearchBar, NavBarTitle, NotificationsPage, ScreenContainer, SettingsPage, SettingsSubPage, SocialAuthRow, appleProvider, composeHeaderOptions, confirmDiscardChanges, getNotificationsPageStackOptions, getSettingsPageStackOptions, getSettingsSubPageStackOptions, useKeyboardScroll } from '../chunk-FZTUSM56.js';
|
|
2
2
|
import '../chunk-ULS7I6ZS.js';
|
|
3
3
|
import '../chunk-5HRGIA6F.js';
|
|
4
|
-
import '../chunk-
|
|
4
|
+
import '../chunk-Z3AQYVUA.js';
|
|
5
5
|
import '../chunk-OHZD7KRO.js';
|
|
6
6
|
import '../chunk-DGUM43GV.js';
|
|
7
7
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@marktiderman/genesis-ui-native",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -63,8 +63,8 @@
|
|
|
63
63
|
"@gorhom/bottom-sheet": ">=5.0.0",
|
|
64
64
|
"@hookform/resolvers": "^3.0.0 || ^4.0.0 || ^5.0.0",
|
|
65
65
|
"@react-native-community/datetimepicker": ">=8.0.0",
|
|
66
|
-
"@marktiderman/genesis-core": "^1.
|
|
67
|
-
"@marktiderman/genesis-design-system": "^1.
|
|
66
|
+
"@marktiderman/genesis-core": "^1.7.0",
|
|
67
|
+
"@marktiderman/genesis-design-system": "^1.4.1",
|
|
68
68
|
"@tanstack/react-query": "^5.0.0",
|
|
69
69
|
"clsx": "^2.0.0",
|
|
70
70
|
"expo-haptics": ">=14.0.0",
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
"react-hook-form": "^7.0.0",
|
|
75
75
|
"react-native": ">=0.76.0",
|
|
76
76
|
"react-native-gesture-handler": ">=2.0.0",
|
|
77
|
-
"react-native-keyboard-controller": ">=1.
|
|
77
|
+
"react-native-keyboard-controller": ">=1.11.0",
|
|
78
78
|
"react-native-reanimated": ">=3.0.0",
|
|
79
79
|
"react-native-safe-area-context": ">=4.0.0",
|
|
80
80
|
"tailwind-merge": "^3.0.0",
|
|
@@ -109,13 +109,13 @@
|
|
|
109
109
|
"devDependencies": {
|
|
110
110
|
"@testing-library/react": "^16.3.2",
|
|
111
111
|
"@types/react": "^19.2.14",
|
|
112
|
-
"@vitest/coverage-v8": "^
|
|
112
|
+
"@vitest/coverage-v8": "^4.1.12",
|
|
113
113
|
"happy-dom": "^20.9.0",
|
|
114
114
|
"react": "^19.2.5",
|
|
115
115
|
"react-dom": "^19.2.5",
|
|
116
116
|
"tsup": "^8.3.0",
|
|
117
117
|
"typescript": "^5.9.3",
|
|
118
|
-
"vitest": "^
|
|
118
|
+
"vitest": "^4.1.12"
|
|
119
119
|
},
|
|
120
120
|
"scripts": {
|
|
121
121
|
"build": "tsup",
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { renderHook } from "@testing-library/react";
|
|
3
|
+
import { Platform } from "react-native";
|
|
4
|
+
import { useThemeRoles } from "../use-theme-roles";
|
|
5
|
+
|
|
6
|
+
describe("useThemeRoles", () => {
|
|
7
|
+
it("resolves neutral roles to iOS system colors and keeps the brand tint", () => {
|
|
8
|
+
const { result } = renderHook(() => useThemeRoles({ tint: "#123456" }));
|
|
9
|
+
expect(result.current.background).toEqual({ semantic: ["systemBackground"] });
|
|
10
|
+
expect(result.current.secondaryLabel).toEqual({ semantic: ["secondaryLabel"] });
|
|
11
|
+
expect(result.current.tint).toBe("#123456");
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it("uses Material You only on Android 12+ when asked", () => {
|
|
15
|
+
const os = Platform.OS;
|
|
16
|
+
const version = Platform.Version;
|
|
17
|
+
try {
|
|
18
|
+
Platform.OS = "android";
|
|
19
|
+
Platform.Version = 34;
|
|
20
|
+
const { result } = renderHook(() => useThemeRoles({ materialYou: true }));
|
|
21
|
+
expect(result.current.background).toEqual({ semantic: ["@android:color/system_neutral1_10"] });
|
|
22
|
+
Platform.Version = 30;
|
|
23
|
+
const { result: old } = renderHook(() => useThemeRoles({ materialYou: true }));
|
|
24
|
+
expect(typeof old.current.background).toBe("string");
|
|
25
|
+
} finally {
|
|
26
|
+
Platform.OS = os;
|
|
27
|
+
Platform.Version = version;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
});
|
package/src/hooks/index.ts
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
export { useReducedMotion } from "./use-reduced-motion";
|
|
10
10
|
export { useThemeMode, type ThemeMode } from "./use-theme-mode";
|
|
11
|
+
export { useThemeRoles, type ThemeRoleColors, type UseThemeRolesOptions } from "./use-theme-roles";
|
|
11
12
|
export {
|
|
12
13
|
BrandExtensionsProvider,
|
|
13
14
|
useGenesisExtension,
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useThemeRoles — the theme roles (background, label, separator, tint…) as
|
|
3
|
+
* colors for this platform and color scheme.
|
|
4
|
+
*
|
|
5
|
+
* On iOS every neutral role is a system color through `PlatformColor`, so a
|
|
6
|
+
* screen follows light and dark mode, increased contrast and accessibility
|
|
7
|
+
* settings like the system apps. On Android the roles are the Genesis tokens
|
|
8
|
+
* for the current scheme, or Material You colors on Android 12+ with
|
|
9
|
+
* `materialYou`. A brand sets `tint`.
|
|
10
|
+
*
|
|
11
|
+
* Use it for `style` props and anything Tailwind classes don't reach, such as
|
|
12
|
+
* navigation header and tab bar options.
|
|
13
|
+
*
|
|
14
|
+
* @stability Beta
|
|
15
|
+
*/
|
|
16
|
+
import { useMemo } from "react";
|
|
17
|
+
import { Platform, PlatformColor, type ColorValue } from "react-native";
|
|
18
|
+
import { resolveThemeRoles, type ThemeRole } from "@marktiderman/genesis-design-system";
|
|
19
|
+
import { useThemeMode } from "./use-theme-mode";
|
|
20
|
+
|
|
21
|
+
export type ThemeRoleColors = Record<ThemeRole, ColorValue>;
|
|
22
|
+
|
|
23
|
+
export interface UseThemeRolesOptions {
|
|
24
|
+
/** The brand's primary color. */
|
|
25
|
+
tint?: string;
|
|
26
|
+
/** On Android 12+, use Material You dynamic colors for the neutral roles (and the tint, unless `tint` is set). Ignored elsewhere. */
|
|
27
|
+
materialYou?: boolean;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function useThemeRoles(options: UseThemeRolesOptions = {}): ThemeRoleColors {
|
|
31
|
+
const scheme = useThemeMode();
|
|
32
|
+
const { tint, materialYou = false } = options;
|
|
33
|
+
const androidDynamic = materialYou && Platform.OS === "android" && Number(Platform.Version) >= 31;
|
|
34
|
+
return useMemo(
|
|
35
|
+
() =>
|
|
36
|
+
resolveThemeRoles<ColorValue>({
|
|
37
|
+
target: Platform.OS === "ios" ? "ios" : "android",
|
|
38
|
+
scheme,
|
|
39
|
+
platformColor: (name) => PlatformColor(name),
|
|
40
|
+
tint,
|
|
41
|
+
androidDynamic,
|
|
42
|
+
}),
|
|
43
|
+
[scheme, tint, androidDynamic],
|
|
44
|
+
);
|
|
45
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// @feat:account
|
|
2
|
+
import { act, fireEvent, render, screen } from "@testing-library/react";
|
|
3
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
4
|
+
import { Platform } from "react-native";
|
|
5
|
+
import { AuthScreen } from "../auth-screen";
|
|
6
|
+
import { appleProvider, AppleSignInButton, type AppleButtonModuleLike } from "../apple-sign-in";
|
|
7
|
+
|
|
8
|
+
function fakeApple() {
|
|
9
|
+
const seen: Array<{ buttonType: number; buttonStyle: number }> = [];
|
|
10
|
+
const apple: AppleButtonModuleLike = {
|
|
11
|
+
AppleAuthenticationButton: ({ buttonType, buttonStyle, onPress, testID, accessibilityState }) => {
|
|
12
|
+
seen.push({ buttonType, buttonStyle });
|
|
13
|
+
return (
|
|
14
|
+
<button type="button" data-testid={testID} aria-disabled={accessibilityState?.disabled ? "true" : "false"} onClick={onPress}>
|
|
15
|
+
apple-native-button
|
|
16
|
+
</button>
|
|
17
|
+
);
|
|
18
|
+
},
|
|
19
|
+
AppleAuthenticationButtonType: { SIGN_IN: 0, CONTINUE: 1, SIGN_UP: 2 },
|
|
20
|
+
AppleAuthenticationButtonStyle: { WHITE: 0, WHITE_OUTLINE: 1, BLACK: 2 },
|
|
21
|
+
};
|
|
22
|
+
return { apple, seen };
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const form = { onSubmit: vi.fn() };
|
|
26
|
+
const google = { id: "google", label: "Continue with Google", onPress: () => {} };
|
|
27
|
+
|
|
28
|
+
afterEach(() => {
|
|
29
|
+
Platform.OS = "ios";
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
describe("appleProvider", () => {
|
|
33
|
+
it("adds Apple's own button to AuthScreen in one line, on iOS", () => {
|
|
34
|
+
const { apple, seen } = fakeApple();
|
|
35
|
+
const onPress = vi.fn();
|
|
36
|
+
render(<AuthScreen form={form} providers={[appleProvider({ apple, onPress }), google]} />);
|
|
37
|
+
fireEvent.click(screen.getByTestId("auth-screen-social-apple"));
|
|
38
|
+
expect(onPress).toHaveBeenCalledTimes(1);
|
|
39
|
+
expect(screen.getByText("apple-native-button")).toBeTruthy();
|
|
40
|
+
expect(screen.getByText("Continue with Google")).toBeTruthy();
|
|
41
|
+
expect(seen[0]).toEqual({ buttonType: 1, buttonStyle: 2 });
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("is null off iOS or without the module, and AuthScreen skips it", () => {
|
|
45
|
+
const { apple } = fakeApple();
|
|
46
|
+
expect(appleProvider({ apple: undefined, onPress: () => {} })).toBeNull();
|
|
47
|
+
Platform.OS = "android";
|
|
48
|
+
const provider = appleProvider({ apple, onPress: () => {} });
|
|
49
|
+
expect(provider).toBeNull();
|
|
50
|
+
render(<AuthScreen form={form} providers={[provider, google]} />);
|
|
51
|
+
expect(screen.queryByText("apple-native-button")).toBeNull();
|
|
52
|
+
expect(screen.getByText("Continue with Google")).toBeTruthy();
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("keeps the dev warning when Apple is missing on iOS, and stays quiet when it's there", () => {
|
|
56
|
+
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
57
|
+
const { apple } = fakeApple();
|
|
58
|
+
const okta = { id: "okta", label: "Okta", onPress: () => {} };
|
|
59
|
+
render(<AuthScreen form={form} providers={[appleProvider({ apple, onPress: () => {} }), okta]} />);
|
|
60
|
+
expect(warn).not.toHaveBeenCalled();
|
|
61
|
+
render(<AuthScreen form={form} providers={[appleProvider({ apple: undefined, onPress: () => {} }), okta]} />);
|
|
62
|
+
expect(warn).toHaveBeenCalledTimes(1);
|
|
63
|
+
expect(warn.mock.calls[0]![0]).toContain("appleProvider");
|
|
64
|
+
warn.mockRestore();
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
describe("AppleSignInButton", () => {
|
|
69
|
+
it("maps Apple's wording and style, and ignores presses while disabled", () => {
|
|
70
|
+
const { apple, seen } = fakeApple();
|
|
71
|
+
const onPress = vi.fn();
|
|
72
|
+
render(<AppleSignInButton apple={apple} onPress={onPress} type="sign-up" appearance="white-outline" disabled />);
|
|
73
|
+
expect(seen[0]).toEqual({ buttonType: 2, buttonStyle: 1 });
|
|
74
|
+
fireEvent.click(screen.getByTestId("apple-sign-in"));
|
|
75
|
+
expect(onPress).not.toHaveBeenCalled();
|
|
76
|
+
expect(screen.getByTestId("apple-sign-in").getAttribute("aria-disabled")).toBe("true");
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it("ignores a second tap while the first sign-in is still open", async () => {
|
|
80
|
+
const { apple } = fakeApple();
|
|
81
|
+
let finish!: () => void;
|
|
82
|
+
const onPress = vi.fn(() => new Promise<void>((r) => (finish = r)));
|
|
83
|
+
render(<AppleSignInButton apple={apple} onPress={onPress} />);
|
|
84
|
+
const button = screen.getByTestId("apple-sign-in");
|
|
85
|
+
fireEvent.click(button);
|
|
86
|
+
fireEvent.click(button);
|
|
87
|
+
expect(onPress).toHaveBeenCalledTimes(1);
|
|
88
|
+
await act(async () => finish());
|
|
89
|
+
fireEvent.click(button);
|
|
90
|
+
expect(onPress).toHaveBeenCalledTimes(2);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it("labels the provider to match Apple's wording", () => {
|
|
94
|
+
const { apple } = fakeApple();
|
|
95
|
+
expect(appleProvider({ apple, onPress: () => {}, type: "sign-in" })?.label).toBe("Sign in with Apple");
|
|
96
|
+
});
|
|
97
|
+
});
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// @feat:native-components
|
|
2
|
+
import { fireEvent, render, screen } from "@testing-library/react";
|
|
3
|
+
import { describe, expect, it, vi } from "vitest";
|
|
4
|
+
import { Text } from "react-native";
|
|
5
|
+
import { AuthScreen, type AuthScreenSlotMap } from "../auth-screen";
|
|
6
|
+
|
|
7
|
+
const form = { onSubmit: vi.fn() };
|
|
8
|
+
|
|
9
|
+
describe("AuthScreen", () => {
|
|
10
|
+
it("assembles branding, providers, the form, forgot password and a footer", () => {
|
|
11
|
+
const onForgot = vi.fn();
|
|
12
|
+
render(
|
|
13
|
+
<AuthScreen
|
|
14
|
+
branding={{ headline: "Welcome back" }}
|
|
15
|
+
providers={[{ id: "apple", label: "Continue with Apple", onPress: () => {} }]}
|
|
16
|
+
form={form}
|
|
17
|
+
onForgotPassword={onForgot}
|
|
18
|
+
footer={<Text>Terms</Text>}
|
|
19
|
+
/>,
|
|
20
|
+
);
|
|
21
|
+
expect(screen.getByText("Welcome back")).toBeTruthy();
|
|
22
|
+
expect(screen.getByText("Continue with Apple")).toBeTruthy();
|
|
23
|
+
expect(screen.getByTestId("auth-screen-form")).toBeTruthy();
|
|
24
|
+
expect(screen.getByText("Terms")).toBeTruthy();
|
|
25
|
+
fireEvent.click(screen.getByTestId("auth-forgot-password"));
|
|
26
|
+
expect(onForgot).toHaveBeenCalled();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("leaves out what isn't given, and forgot password in magic-link mode", () => {
|
|
30
|
+
render(<AuthScreen form={{ ...form, mode: "magic-link" }} onForgotPassword={() => {}} />);
|
|
31
|
+
expect(screen.queryByTestId("auth-screen-social")).toBeNull();
|
|
32
|
+
expect(screen.queryByTestId("auth-forgot-password")).toBeNull();
|
|
33
|
+
expect(screen.getByTestId("auth-screen-form")).toBeTruthy();
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("replaces or drops a part through slots", () => {
|
|
37
|
+
const Social = ({ providers }: AuthScreenSlotMap["social"]) => <Text>{`${providers.length} custom`}</Text>;
|
|
38
|
+
render(
|
|
39
|
+
<AuthScreen
|
|
40
|
+
branding={{ headline: "Hi" }}
|
|
41
|
+
providers={[{ id: "g", label: "Google", onPress: () => {} }]}
|
|
42
|
+
form={form}
|
|
43
|
+
slots={{ social: Social, branding: null }}
|
|
44
|
+
/>,
|
|
45
|
+
);
|
|
46
|
+
expect(screen.getByText("1 custom")).toBeTruthy();
|
|
47
|
+
expect(screen.queryByText("Hi")).toBeNull();
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
describe("AuthScreen review fixes", () => {
|
|
52
|
+
it("moves focus to the password field when return is pressed on email", () => {
|
|
53
|
+
render(<AuthScreen form={form} />);
|
|
54
|
+
fireEvent.keyDown(screen.getByTestId("auth-screen-form-email"), { key: "Enter" });
|
|
55
|
+
expect(document.activeElement).toBe(screen.getByTestId("auth-screen-form-password"));
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("warns once on iOS when a third-party provider has no Sign in with Apple beside it", () => {
|
|
59
|
+
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
60
|
+
const github = [{ id: "github", label: "GitHub", onPress: () => {} }];
|
|
61
|
+
render(<AuthScreen form={form} providers={github} />);
|
|
62
|
+
render(<AuthScreen form={form} providers={github} />);
|
|
63
|
+
expect(warn).toHaveBeenCalledTimes(1);
|
|
64
|
+
expect(warn.mock.calls[0]![0]).toContain("4.8");
|
|
65
|
+
warn.mockRestore();
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it("stays above the keyboard", () => {
|
|
69
|
+
render(<AuthScreen form={form} />);
|
|
70
|
+
expect(screen.getByTestId("auth-screen-kav")).toBeTruthy();
|
|
71
|
+
});
|
|
72
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// @feat:native-layouts
|
|
2
|
+
import { render, screen } from "@testing-library/react";
|
|
3
|
+
import { describe, expect, it, vi } from "vitest";
|
|
4
|
+
import { View } from "react-native";
|
|
5
|
+
import { AuthScreen } from "../auth-screen";
|
|
6
|
+
import { SettingsSubPage } from "../settings-sub-page";
|
|
7
|
+
import { KeyboardScrollProvider, type KeyboardScrollProps } from "../keyboard";
|
|
8
|
+
|
|
9
|
+
const Aware = ({ children, testID }: KeyboardScrollProps) => <View testID={testID}>{children}</View>;
|
|
10
|
+
|
|
11
|
+
describe("KeyboardScrollProvider", () => {
|
|
12
|
+
it("puts AuthScreen in the app's keyboard-aware scroll view", () => {
|
|
13
|
+
render(
|
|
14
|
+
<KeyboardScrollProvider component={Aware}>
|
|
15
|
+
<AuthScreen form={{ onSubmit: vi.fn() }} />
|
|
16
|
+
</KeyboardScrollProvider>,
|
|
17
|
+
);
|
|
18
|
+
expect(screen.getByTestId("auth-screen-keyboard")).toBeTruthy();
|
|
19
|
+
expect(screen.queryByTestId("auth-screen-kav")).toBeNull();
|
|
20
|
+
expect(screen.getByTestId("auth-screen-form")).toBeTruthy();
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it("puts SettingsSubPage in it too, and falls back without a provider", () => {
|
|
24
|
+
const { unmount } = render(
|
|
25
|
+
<KeyboardScrollProvider component={Aware}>
|
|
26
|
+
<SettingsSubPage testID="sub">{null}</SettingsSubPage>
|
|
27
|
+
</KeyboardScrollProvider>,
|
|
28
|
+
);
|
|
29
|
+
expect(screen.getByTestId("sub-keyboard")).toBeTruthy();
|
|
30
|
+
unmount();
|
|
31
|
+
render(<SettingsSubPage testID="sub">{null}</SettingsSubPage>);
|
|
32
|
+
expect(screen.getByTestId("sub-kav")).toBeTruthy();
|
|
33
|
+
});
|
|
34
|
+
});
|