@baukit/navigation 0.7.2 → 0.7.4
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 +24 -1
- package/dist/index.d.ts +28 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +34 -0
- package/dist/index.js.map +1 -1
- package/dist/native.d.ts +13 -1
- package/dist/native.d.ts.map +1 -1
- package/dist/native.js +136 -37
- package/dist/native.js.map +1 -1
- package/dist/web.css +27 -1
- package/dist/web.css.d.ts +1 -0
- package/dist/web.d.ts.map +1 -1
- package/dist/web.js +44 -38
- package/dist/web.js.map +1 -1
- package/package.json +9 -5
- package/src/index.test.ts +259 -0
- package/src/index.ts +236 -0
- package/src/native.browser.test.tsx +183 -0
- package/src/native.test.tsx +948 -0
- package/src/native.tsx +1076 -0
- package/src/use-navigation-state.ts +34 -0
- package/src/web-css.d.ts +4 -0
- package/src/web.browser.test.tsx +477 -0
- package/src/web.css +257 -0
- package/src/web.css.d.ts +1 -0
- package/src/web.test.tsx +483 -0
- package/src/web.tsx +618 -0
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@ Tailwind code.
|
|
|
8
8
|
|
|
9
9
|
- `@baukit/navigation` contains the TypeScript model, validation, active-route
|
|
10
10
|
resolution, section rotation, disclosure reducer and layout selection. It has
|
|
11
|
-
no React import.
|
|
11
|
+
no React runtime import.
|
|
12
12
|
- `@baukit/navigation/web` contains `AppNavigation` and `SectionPicker` for DOM.
|
|
13
13
|
It never imports React Native, including through `a11y-core`.
|
|
14
14
|
- `@baukit/navigation/native` contains those components for React Native and
|
|
@@ -73,6 +73,11 @@ A profile accepts either `href` or a nonempty `menu`. Menu entries have unique
|
|
|
73
73
|
ids, labels and either `href` or synchronous `onSelect`. Link entries accept `matches(pathname)`. Only the most-specific matching path is selected in a menu. A product owns async
|
|
74
74
|
action errors. Start an async sign-out in `onSelect` and handle its rejection in
|
|
75
75
|
the product. `imageUrl` renders an avatar, with initials after an image failure.
|
|
76
|
+
`renderAvatar({ active, size })` replaces the image or initials with a product
|
|
77
|
+
glyph or frame on web and native. It receives the route selection state and the
|
|
78
|
+
28-unit avatar size. Return decorative content. The wrapper hides it from
|
|
79
|
+
assistive technology; the profile label and subtitle still name the button.
|
|
80
|
+
Web custom avatars have no default background or circular frame.
|
|
76
81
|
The profile stays last in the bar and at the bottom of the rail.
|
|
77
82
|
|
|
78
83
|
Active leaves use a muted accent background with an accent icon and bold label.
|
|
@@ -120,6 +125,14 @@ trigger and above the compact bottom bar. Long sections scroll inside that
|
|
|
120
125
|
space. It updates the limit when the viewport, content layout, or scroll
|
|
121
126
|
position changes.
|
|
122
127
|
|
|
128
|
+
For compact native content, `useNavigationBarHeight(bottomInset, theme)` reserves
|
|
129
|
+
space using the current font scale and the bar's typography and spacing. Pass the
|
|
130
|
+
same theme as `AppNavigation` when you customize it. The default height is 75 dp
|
|
131
|
+
before the bottom inset. `getNavigationBarHeight(fontScale, bottomInset, metrics)`
|
|
132
|
+
provides the same calculation without a hook. Its optional metrics are `spacing`,
|
|
133
|
+
`fontSize` and `lineHeight`. `NAVIGATION_DIMENSIONS.nativeBar` is the default native
|
|
134
|
+
height; `bar` remains the 64-pixel DOM height.
|
|
135
|
+
|
|
123
136
|
Keep route-heading focus in the product. Use
|
|
124
137
|
`createRouteFocusController` from `@baukit/a11y-core/web` for DOM route changes,
|
|
125
138
|
and the product's screen-transition adapter on native. Navigation does not know
|
|
@@ -136,3 +149,13 @@ Library and the React Native Jest preset, and checks the packed exports. Expo
|
|
|
136
149
|
is not needed for these tests. `pnpm test:browser` runs Playwright through
|
|
137
150
|
Vitest in Chromium and WebKit at 320, 1023 and 1024 pixels, with short and normal
|
|
138
151
|
heights. It checks geometry, 44-pixel targets, browser warnings and axe.
|
|
152
|
+
|
|
153
|
+
A profile can supply `subtitle` for a name or sync status. The expanded rail and
|
|
154
|
+
profile menu display it below the label. The profile button includes both lines
|
|
155
|
+
in its accessible label, including in collapsed and compact navigation.
|
|
156
|
+
|
|
157
|
+
Native `NavigationTheme.typography` can set `fontFamily`, `fontSize`,
|
|
158
|
+
`barFontSize`, `subtitleFontSize`, `fontWeight`, `activeFontWeight`, `lineHeight`
|
|
159
|
+
and `letterSpacing`. Sizes and line height use React Native units. Omitted fields
|
|
160
|
+
keep the default sizes and weights. The font family also applies to menu entries,
|
|
161
|
+
initials and section pickers, as the web navigation inherits its CSS font family.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
1
2
|
export interface NavigationSubItem<Icon = unknown> {
|
|
2
3
|
readonly id: string;
|
|
3
4
|
readonly label: string;
|
|
@@ -21,10 +22,16 @@ export type NavigationProfileMenuEntry = {
|
|
|
21
22
|
readonly onSelect: () => void;
|
|
22
23
|
readonly href?: never;
|
|
23
24
|
});
|
|
25
|
+
export interface NavigationAvatarState {
|
|
26
|
+
readonly active: boolean;
|
|
27
|
+
readonly size: number;
|
|
28
|
+
}
|
|
24
29
|
export type NavigationProfile = {
|
|
25
30
|
readonly label: string;
|
|
31
|
+
readonly subtitle?: string;
|
|
26
32
|
readonly initials: string;
|
|
27
33
|
readonly imageUrl?: string;
|
|
34
|
+
readonly renderAvatar?: (state: NavigationAvatarState) => ReactNode;
|
|
28
35
|
} & ({
|
|
29
36
|
readonly href: string;
|
|
30
37
|
readonly menu?: never;
|
|
@@ -32,14 +39,35 @@ export type NavigationProfile = {
|
|
|
32
39
|
readonly menu: readonly NavigationProfileMenuEntry[];
|
|
33
40
|
readonly href?: never;
|
|
34
41
|
});
|
|
42
|
+
export declare function getNavigationProfileLabel(profile: NavigationProfile): string;
|
|
35
43
|
export interface ActiveNavigation<Icon = unknown> {
|
|
36
44
|
readonly item: NavigationItem<Icon> | null;
|
|
37
45
|
readonly subItem: NavigationSubItem<Icon> | null;
|
|
38
46
|
}
|
|
47
|
+
export declare const NAVIGATION_BAR_DIMENSIONS: {
|
|
48
|
+
readonly avatar: 28;
|
|
49
|
+
readonly icon: 24;
|
|
50
|
+
readonly border: 1;
|
|
51
|
+
readonly targetBorder: 3;
|
|
52
|
+
readonly targetPadding: 8;
|
|
53
|
+
readonly labelFontSize: 11;
|
|
54
|
+
readonly labelLineHeight: 16;
|
|
55
|
+
readonly spacing: 8;
|
|
56
|
+
};
|
|
57
|
+
export interface NavigationBarMetrics {
|
|
58
|
+
readonly spacing?: number;
|
|
59
|
+
readonly fontSize?: number;
|
|
60
|
+
readonly lineHeight?: number;
|
|
61
|
+
}
|
|
62
|
+
export declare function getNavigationBarLineHeight(metrics?: NavigationBarMetrics): number;
|
|
63
|
+
export declare function getNavigationBarVisualHeight(fontScale?: number): number;
|
|
64
|
+
export declare function getNavigationBarHeight(fontScale?: number, bottomInset?: number, metrics?: NavigationBarMetrics): number;
|
|
39
65
|
export declare const NAVIGATION_DIMENSIONS: {
|
|
66
|
+
readonly avatar: 28;
|
|
40
67
|
readonly rail: 280;
|
|
41
68
|
readonly collapsedRail: 76;
|
|
42
69
|
readonly bar: 64;
|
|
70
|
+
readonly nativeBar: number;
|
|
43
71
|
readonly target: 44;
|
|
44
72
|
readonly androidTarget: 48;
|
|
45
73
|
};
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvC,MAAM,WAAW,iBAAiB,CAAC,IAAI,GAAG,OAAO;IAC/C,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC;IACrB,QAAQ,CAAC,OAAO,CAA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QAAQ,EAAE,MAAM,GACf,0BAA0B,GAAG,IAAI,CAKnC;AAED,wBAAgB,uBAAuB,CAAC,IAAI,EAC1C,KAAK,EAAE,SAAS,cAAc,CAAC,IAAI,CAAC,EAAE,EACtC,QAAQ,EAAE,MAAM,GACf,gBAAgB,CAAC,IAAI,CAAC,CAUxB;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAM9E;AAED,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;CACrC;AAED,MAAM,MAAM,gBAAgB,GACxB;IAAE,QAAQ,CAAC,IAAI,EAAE,eAAe,CAAC;IAAC,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAA;CAAE,GAC/D;IAAE,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAC;IAAC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,CAAA;CAAE,GACpF;IAAE,QAAQ,CAAC,IAAI,EAAE,eAAe,CAAC;IAAC,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAAC;AAEnE,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,eAAe,EACtB,MAAM,EAAE,gBAAgB,GACvB,eAAe,CAkBjB;AAED,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,SAAS,cAAc,EAAE,EAChC,OAAO,CAAC,EAAE,iBAAiB,GAC1B,IAAI,CAyBN"}
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,42 @@
|
|
|
1
1
|
import { getLayoutMode } from '@baukit/ui-tokens';
|
|
2
|
+
export function getNavigationProfileLabel(profile) {
|
|
3
|
+
return profile.subtitle === undefined || profile.subtitle.trim() === ''
|
|
4
|
+
? profile.label
|
|
5
|
+
: `${profile.label}, ${profile.subtitle}`;
|
|
6
|
+
}
|
|
7
|
+
export const NAVIGATION_BAR_DIMENSIONS = {
|
|
8
|
+
avatar: 28,
|
|
9
|
+
icon: 24,
|
|
10
|
+
border: 1,
|
|
11
|
+
targetBorder: 3,
|
|
12
|
+
targetPadding: 8,
|
|
13
|
+
labelFontSize: 11,
|
|
14
|
+
labelLineHeight: 16,
|
|
15
|
+
spacing: 8,
|
|
16
|
+
};
|
|
17
|
+
export function getNavigationBarLineHeight(metrics = {}) {
|
|
18
|
+
return (metrics.lineHeight ??
|
|
19
|
+
Math.ceil((metrics.fontSize ?? NAVIGATION_BAR_DIMENSIONS.labelFontSize) *
|
|
20
|
+
(NAVIGATION_BAR_DIMENSIONS.labelLineHeight / NAVIGATION_BAR_DIMENSIONS.labelFontSize)));
|
|
21
|
+
}
|
|
22
|
+
export function getNavigationBarVisualHeight(fontScale = 1) {
|
|
23
|
+
return Math.max(NAVIGATION_BAR_DIMENSIONS.avatar, NAVIGATION_BAR_DIMENSIONS.icon * Math.max(1, fontScale));
|
|
24
|
+
}
|
|
25
|
+
export function getNavigationBarHeight(fontScale = 1, bottomInset = 0, metrics = {}) {
|
|
26
|
+
const scale = Math.max(1, fontScale);
|
|
27
|
+
return (NAVIGATION_BAR_DIMENSIONS.border +
|
|
28
|
+
2 * (NAVIGATION_BAR_DIMENSIONS.targetBorder + NAVIGATION_BAR_DIMENSIONS.targetPadding) +
|
|
29
|
+
getNavigationBarVisualHeight(scale) +
|
|
30
|
+
(metrics.spacing ?? NAVIGATION_BAR_DIMENSIONS.spacing) +
|
|
31
|
+
getNavigationBarLineHeight(metrics) * scale +
|
|
32
|
+
bottomInset);
|
|
33
|
+
}
|
|
2
34
|
export const NAVIGATION_DIMENSIONS = {
|
|
35
|
+
avatar: NAVIGATION_BAR_DIMENSIONS.avatar,
|
|
3
36
|
rail: 280,
|
|
4
37
|
collapsedRail: 76,
|
|
5
38
|
bar: 64,
|
|
39
|
+
nativeBar: getNavigationBarHeight(),
|
|
6
40
|
target: 44,
|
|
7
41
|
androidTarget: 48,
|
|
8
42
|
};
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AA6ClD,MAAM,UAAU,yBAAyB,CAAC,OAA0B;IAClE,OAAO,OAAO,CAAC,QAAQ,KAAK,SAAS,IAAI,OAAO,CAAC,QAAQ,CAAC,IAAI,EAAE,KAAK,EAAE;QACrE,CAAC,CAAC,OAAO,CAAC,KAAK;QACf,CAAC,CAAC,GAAG,OAAO,CAAC,KAAK,KAAK,OAAO,CAAC,QAAQ,EAAE,CAAC;AAC9C,CAAC;AAOD,MAAM,CAAC,MAAM,yBAAyB,GAAG;IACvC,MAAM,EAAE,EAAE;IACV,IAAI,EAAE,EAAE;IACR,MAAM,EAAE,CAAC;IACT,YAAY,EAAE,CAAC;IACf,aAAa,EAAE,CAAC;IAChB,aAAa,EAAE,EAAE;IACjB,eAAe,EAAE,EAAE;IACnB,OAAO,EAAE,CAAC;CACF,CAAC;AAQX,MAAM,UAAU,0BAA0B,CAAC,UAAgC,EAAE;IAC3E,OAAO,CACL,OAAO,CAAC,UAAU;QAClB,IAAI,CAAC,IAAI,CACP,CAAC,OAAO,CAAC,QAAQ,IAAI,yBAAyB,CAAC,aAAa,CAAC;YAC3D,CAAC,yBAAyB,CAAC,eAAe,GAAG,yBAAyB,CAAC,aAAa,CAAC,CACxF,CACF,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,4BAA4B,CAAC,SAAS,GAAG,CAAC;IACxD,OAAO,IAAI,CAAC,GAAG,CACb,yBAAyB,CAAC,MAAM,EAChC,yBAAyB,CAAC,I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C;IACH,CAAC;AACH,CAAC"}
|
package/dist/native.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type ReactNode } from 'react';
|
|
2
|
-
import { type ViewStyle } from 'react-native';
|
|
2
|
+
import { type ViewStyle, type TextStyle } from 'react-native';
|
|
3
3
|
import { type NavigationItem, type NavigationProfile } from './index.js';
|
|
4
4
|
import { type CollapseProps } from './use-navigation-state.js';
|
|
5
5
|
export interface NavigationIconState {
|
|
@@ -7,6 +7,16 @@ export interface NavigationIconState {
|
|
|
7
7
|
readonly size: number;
|
|
8
8
|
}
|
|
9
9
|
export type NavigationIcon = (state: NavigationIconState) => ReactNode;
|
|
10
|
+
export interface NavigationTypography {
|
|
11
|
+
readonly fontFamily?: string;
|
|
12
|
+
readonly fontSize?: number;
|
|
13
|
+
readonly barFontSize?: number;
|
|
14
|
+
readonly subtitleFontSize?: number;
|
|
15
|
+
readonly fontWeight?: TextStyle['fontWeight'];
|
|
16
|
+
readonly activeFontWeight?: TextStyle['fontWeight'];
|
|
17
|
+
readonly lineHeight?: number;
|
|
18
|
+
readonly letterSpacing?: number;
|
|
19
|
+
}
|
|
10
20
|
export interface NavigationTheme {
|
|
11
21
|
readonly background: string;
|
|
12
22
|
readonly text: string;
|
|
@@ -18,6 +28,7 @@ export interface NavigationTheme {
|
|
|
18
28
|
readonly focus: string;
|
|
19
29
|
readonly radius: number;
|
|
20
30
|
readonly spacing: number;
|
|
31
|
+
readonly typography?: NavigationTypography;
|
|
21
32
|
}
|
|
22
33
|
export interface NavigationInsets {
|
|
23
34
|
readonly top?: number;
|
|
@@ -26,6 +37,7 @@ export interface NavigationInsets {
|
|
|
26
37
|
readonly right?: number;
|
|
27
38
|
}
|
|
28
39
|
export type Navigate = (href: string) => void;
|
|
40
|
+
export declare function useNavigationBarHeight(bottomInset?: number, theme?: NavigationTheme): number;
|
|
29
41
|
export interface AppNavigationProps extends CollapseProps {
|
|
30
42
|
readonly items: readonly NavigationItem<NavigationIcon>[];
|
|
31
43
|
readonly profile?: NavigationProfile;
|
package/dist/native.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"native.d.ts","sourceRoot":"","sources":["../src/native.tsx"],"names":[],"mappings":"AAAA,OAAO,EAQL,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AACf,OAAO,
|
|
1
|
+
{"version":3,"file":"native.d.ts","sourceRoot":"","sources":["../src/native.tsx"],"names":[],"mappings":"AAAA,OAAO,EAQL,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AACf,OAAO,EAeL,KAAK,SAAS,EACd,KAAK,SAAS,EACf,MAAM,cAAc,CAAC;AAYtB,OAAO,EAaL,KAAK,cAAc,EACnB,KAAK,iBAAiB,EAEvB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAsB,KAAK,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAEnF,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AACD,MAAM,MAAM,cAAc,GAAG,CAAC,KAAK,EAAE,mBAAmB,KAAK,SAAS,CAAC;AACvE,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IACnC,QAAQ,CAAC,UAAU,CAAC,EAAE,SAAS,CAAC,YAAY,CAAC,CAAC;IAC9C,QAAQ,CAAC,gBAAgB,CAAC,EAAE,SAAS,CAAC,YAAY,CAAC,CAAC;IACpD,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;CACjC;AAED,MAAM,WAAW,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AAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,CAAC,EAAE,gBAAgB,CAAC;IACnC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,KAAK,CAAC,EAAE,SAAS,CAAC;CAC5B;AACD,wBAAgB,aAAa,CAAC,KAAK,EAAE,kBAAkB,+BA6NtD;AAED,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAC,cAAc,CAAC,CAAC;IAC9C,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,UAAU,EAAE,QAAQ,CAAC;IAC9B,QAAQ,CAAC,KAAK,EAAE,eAAe,CAAC;CACjC;AACD,wBAAgB,aAAa,CAAC,EAC5B,IAAI,EACJ,QAAQ,EACR,UAAU,EACV,KAAK,EACL,UAAU,GACX,EAAE,kBAAkB,sCAiEpB"}
|
package/dist/native.js
CHANGED
|
@@ -3,8 +3,33 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
3
3
|
import { useEffect, useCallback, useLayoutEffect, useId, useRef, useState, } from 'react';
|
|
4
4
|
import { Image, Modal, Platform, Pressable, ScrollView, StyleSheet, Text, View, useWindowDimensions, } from 'react-native';
|
|
5
5
|
import { announce, asFocusTarget, hostElement, useAriaHiddenInert, useOverlayA11y, useReducedMotionPreference, useRovingMenu, } from '@baukit/a11y-core';
|
|
6
|
-
import { getNavigationLayout, NAVIGATION_DIMENSIONS, navigationMatches, nextSectionHref, resolveActiveNavigation, resolveActiveMenuEntry, validateNavigation, } from './index.js';
|
|
6
|
+
import { getNavigationLayout, getNavigationBarHeight, getNavigationBarVisualHeight, getNavigationBarLineHeight, NAVIGATION_BAR_DIMENSIONS, NAVIGATION_DIMENSIONS, navigationMatches, nextSectionHref, resolveActiveNavigation, resolveActiveMenuEntry, validateNavigation, } from './index.js';
|
|
7
7
|
import { useNavigationState } from './use-navigation-state.js';
|
|
8
|
+
function barMetrics(theme) {
|
|
9
|
+
return {
|
|
10
|
+
...(theme === undefined ? {} : { spacing: theme.spacing }),
|
|
11
|
+
...(theme?.typography?.barFontSize === undefined
|
|
12
|
+
? {}
|
|
13
|
+
: { fontSize: theme.typography.barFontSize }),
|
|
14
|
+
...(theme?.typography?.lineHeight === undefined
|
|
15
|
+
? {}
|
|
16
|
+
: { lineHeight: theme.typography.lineHeight }),
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
function textStyle(theme, selected = false, bar = false) {
|
|
20
|
+
const typography = theme.typography;
|
|
21
|
+
return {
|
|
22
|
+
fontFamily: typography?.fontFamily,
|
|
23
|
+
fontSize: bar
|
|
24
|
+
? (typography?.barFontSize ?? NAVIGATION_BAR_DIMENSIONS.labelFontSize)
|
|
25
|
+
: (typography?.fontSize ?? 14),
|
|
26
|
+
fontWeight: selected
|
|
27
|
+
? (typography?.activeFontWeight ?? '700')
|
|
28
|
+
: (typography?.fontWeight ?? '400'),
|
|
29
|
+
lineHeight: bar ? getNavigationBarLineHeight(barMetrics(theme)) : typography?.lineHeight,
|
|
30
|
+
letterSpacing: typography?.letterSpacing,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
8
33
|
function FocusablePressable({ theme, selected = false, unfocusedBorderColor, style, onFocus, onBlur, ...props }) {
|
|
9
34
|
const [focused, setFocused] = useState(false);
|
|
10
35
|
return (_jsx(Pressable, { ...props, onFocus: (event) => {
|
|
@@ -22,7 +47,7 @@ function FocusablePressable({ theme, selected = false, unfocusedBorderColor, sty
|
|
|
22
47
|
minWidth: Platform.OS === 'android'
|
|
23
48
|
? NAVIGATION_DIMENSIONS.androidTarget
|
|
24
49
|
: NAVIGATION_DIMENSIONS.target,
|
|
25
|
-
borderWidth:
|
|
50
|
+
borderWidth: NAVIGATION_BAR_DIMENSIONS.targetBorder,
|
|
26
51
|
borderColor: focused
|
|
27
52
|
? selected
|
|
28
53
|
? theme.activeText
|
|
@@ -52,14 +77,14 @@ function follow(href, event, onNavigate) {
|
|
|
52
77
|
event.preventDefault();
|
|
53
78
|
onNavigate(href);
|
|
54
79
|
}
|
|
55
|
-
function Target({ label, selected = false, ancestor = false, expanded, controls, menu, href, onPress, theme, bar = false, collapsed = false, children, roving, triggerRef, testID, }) {
|
|
80
|
+
function Target({ label, subtitle, selected = false, ancestor = false, expanded, controls, menu, href, onPress, theme, bar = false, collapsed = false, children, roving, triggerRef, testID, }) {
|
|
56
81
|
return (_jsxs(FocusablePressable, { theme: theme, selected: selected && !ancestor, dataSet: { active: selected ? (ancestor ? 'ancestor' : 'page') : 'false' }, ...roving, ...(href === undefined ? {} : webLink(href, selected)), ...(Platform.OS === 'web'
|
|
57
82
|
? {
|
|
58
83
|
title: collapsed ? label : undefined,
|
|
59
84
|
'aria-controls': controls,
|
|
60
85
|
'aria-haspopup': menu ? 'menu' : undefined,
|
|
61
86
|
}
|
|
62
|
-
: {}), accessibilityLabel: label, accessibilityRole: href === undefined ? 'button' : 'link', accessibilityState: { selected, ...(expanded === undefined ? {} : { expanded }) }, ref: (node) => {
|
|
87
|
+
: {}), accessibilityLabel: subtitle === undefined ? label : `${label}, ${subtitle}`, accessibilityRole: href === undefined ? 'button' : 'link', accessibilityState: { selected, ...(expanded === undefined ? {} : { expanded }) }, ref: (node) => {
|
|
63
88
|
roving?.ref(node);
|
|
64
89
|
if (triggerRef !== undefined)
|
|
65
90
|
triggerRef.current = node;
|
|
@@ -72,18 +97,21 @@ function Target({ label, selected = false, ancestor = false, expanded, controls,
|
|
|
72
97
|
gap: theme.spacing,
|
|
73
98
|
backgroundColor: selected && !ancestor ? theme.activeBackground : theme.background,
|
|
74
99
|
},
|
|
75
|
-
], children: [children, !collapsed ? (_jsx(Text, { numberOfLines: 1, style: {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
100
|
+
], children: [children, !collapsed ? (_jsxs(View, { style: styles.labelGroup, children: [_jsx(Text, { numberOfLines: 1, style: {
|
|
101
|
+
...textStyle(theme, selected && !ancestor, bar),
|
|
102
|
+
color: ancestor ? theme.ancestorText : selected ? theme.activeText : theme.text,
|
|
103
|
+
}, children: label }), !bar && subtitle !== undefined ? (_jsx(Text, { numberOfLines: 1, style: {
|
|
104
|
+
...textStyle(theme),
|
|
105
|
+
color: theme.muted,
|
|
106
|
+
fontSize: theme.typography?.subtitleFontSize ?? 12,
|
|
107
|
+
}, children: subtitle })) : null] })) : null] }));
|
|
80
108
|
}
|
|
81
|
-
function Decorative({ children }) {
|
|
82
|
-
return (_jsx(View, { accessible: false, accessibilityElementsHidden: true, importantForAccessibility: "no-hide-descendants", "aria-hidden": true, children: children }));
|
|
109
|
+
function Decorative({ children, style, }) {
|
|
110
|
+
return (_jsx(View, { style: style, accessible: false, accessibilityElementsHidden: true, importantForAccessibility: "no-hide-descendants", "aria-hidden": true, children: children }));
|
|
83
111
|
}
|
|
84
112
|
const MENU_WIDTH = 280;
|
|
85
113
|
const MENU_EDGE = 8;
|
|
86
|
-
function Menu({ renderBackground, entries, label, closeLabel, pathname, visible, onClose, onNavigate, triggerRef, theme, id, }) {
|
|
114
|
+
function Menu({ subtitle, renderBackground, entries, label, closeLabel, pathname, visible, onClose, onNavigate, triggerRef, theme, id, }) {
|
|
87
115
|
const activeEntry = resolveActiveMenuEntry(entries, pathname);
|
|
88
116
|
const containerRef = useRef(null);
|
|
89
117
|
const closeRef = useRef(null);
|
|
@@ -184,7 +212,7 @@ function Menu({ renderBackground, entries, label, closeLabel, pathname, visible,
|
|
|
184
212
|
}
|
|
185
213
|
if (Platform.OS === 'web' && event.nativeEvent.key === 'Tab')
|
|
186
214
|
closeAndRestore();
|
|
187
|
-
}, ref: containerRef, accessibilityViewIsModal: Platform.OS !== 'web', accessibilityLabel: label, role: "menu", nativeID: id, testID: "navigation-menu", style: [
|
|
215
|
+
}, ref: containerRef, accessibilityViewIsModal: Platform.OS !== 'web', accessibilityLabel: subtitle === undefined ? label : `${label}, ${subtitle}`, role: "menu", nativeID: id, testID: "navigation-menu", style: [
|
|
188
216
|
styles.menu,
|
|
189
217
|
{
|
|
190
218
|
backgroundColor: theme.background,
|
|
@@ -192,7 +220,11 @@ function Menu({ renderBackground, entries, label, closeLabel, pathname, visible,
|
|
|
192
220
|
borderRadius: theme.radius,
|
|
193
221
|
},
|
|
194
222
|
Platform.OS === 'web' && webPosition,
|
|
195
|
-
], dataSet: { motion }, children: [
|
|
223
|
+
], dataSet: { motion }, children: [subtitle === undefined ? null : (_jsx(Decorative, { children: _jsxs(View, { style: styles.menuProfile, children: [_jsx(Text, { numberOfLines: 1, style: { ...textStyle(theme), color: theme.text }, children: label }), _jsx(Text, { numberOfLines: 1, style: {
|
|
224
|
+
...textStyle(theme),
|
|
225
|
+
color: theme.muted,
|
|
226
|
+
fontSize: theme.typography?.subtitleFontSize ?? 12,
|
|
227
|
+
}, children: subtitle })] }) })), _jsx(ScrollView, { children: entries.map((entry, index) => (_createElement(FocusablePressable, { theme: theme, selected: entry === activeEntry, dataSet: { active: entry === activeEntry ? 'page' : 'false' }, ...roving.itemProps(index), key: entry.id, accessibilityRole: "menuitem", accessibilityLabel: entry.label, accessibilityState: {
|
|
196
228
|
disabled: entry.disabled === true,
|
|
197
229
|
selected: entry === activeEntry,
|
|
198
230
|
}, disabled: entry.disabled, ...(entry.href === undefined ? {} : webLink(entry.href, entry === activeEntry)), onPress: (event) => {
|
|
@@ -212,8 +244,8 @@ function Menu({ renderBackground, entries, label, closeLabel, pathname, visible,
|
|
|
212
244
|
] },
|
|
213
245
|
_jsx(Text, { style: {
|
|
214
246
|
color: entry === activeEntry ? theme.activeText : theme.text,
|
|
215
|
-
|
|
216
|
-
}, children: entry.label })))) }), _jsx(FocusablePressable, { theme: theme, ref: closeRef, accessibilityRole: "button", accessibilityLabel: closeLabel, onPress: closeAndRestore, style: styles.menuItem, children: _jsx(Text, { style: { color: theme.text }, children: closeLabel }) })] }));
|
|
247
|
+
...textStyle(theme, entry === activeEntry),
|
|
248
|
+
}, children: entry.label })))) }), _jsx(FocusablePressable, { theme: theme, ref: closeRef, accessibilityRole: "button", accessibilityLabel: closeLabel, onPress: closeAndRestore, style: styles.menuItem, children: _jsx(Text, { style: { ...textStyle(theme), color: theme.text }, children: closeLabel }) })] }));
|
|
217
249
|
return (_jsxs(_Fragment, { children: [renderBackground(backgroundProps), _jsx(Modal, { visible: visible, transparent: true, animationType: "none", onRequestClose: onClose, onShow: () => {
|
|
218
250
|
if (!visible)
|
|
219
251
|
return;
|
|
@@ -225,21 +257,76 @@ function Menu({ renderBackground, entries, label, closeLabel, pathname, visible,
|
|
|
225
257
|
setWebPresented(true);
|
|
226
258
|
}, children: _jsx(View, { style: styles.modal, children: menu }) })] }));
|
|
227
259
|
}
|
|
228
|
-
function
|
|
260
|
+
function compactVisualStyle(fontScale) {
|
|
261
|
+
return { height: getNavigationBarVisualHeight(fontScale), justifyContent: 'center' };
|
|
262
|
+
}
|
|
263
|
+
function Avatar({ profile, active, theme, style, }) {
|
|
229
264
|
const [failedUrl, setFailedUrl] = useState();
|
|
230
|
-
|
|
265
|
+
if (profile.renderAvatar !== undefined) {
|
|
266
|
+
return (_jsx(Decorative, { style: style, children: profile.renderAvatar({ active, size: NAVIGATION_DIMENSIONS.avatar }) }));
|
|
267
|
+
}
|
|
268
|
+
return (_jsx(Decorative, { style: style, children: profile.imageUrl !== undefined && failedUrl !== profile.imageUrl ? (_jsx(Image, { source: { uri: profile.imageUrl }, onError: () => {
|
|
269
|
+
setFailedUrl(profile.imageUrl);
|
|
270
|
+
}, style: styles.avatar })) : (_jsx(View, { style: [styles.avatar, { backgroundColor: theme.activeBackground }], children: _jsx(Text, { allowFontScaling: false, style: { ...textStyle(theme), color: theme.activeText }, children: profile.initials }) })) }));
|
|
271
|
+
}
|
|
272
|
+
function profileIsActive(profile, pathname) {
|
|
273
|
+
return profile.href !== undefined
|
|
231
274
|
? navigationMatches({ id: 'profile', label: profile.label, href: profile.href }, pathname)
|
|
232
275
|
: resolveActiveMenuEntry(profile.menu, pathname) !== null;
|
|
233
|
-
|
|
276
|
+
}
|
|
277
|
+
function Profile({ profile, open, onOpen, triggerRef, id, theme, bar, collapsed, pathname, onNavigate, roving, onLayout, }) {
|
|
278
|
+
const { fontScale } = useWindowDimensions();
|
|
279
|
+
const active = profileIsActive(profile, pathname);
|
|
280
|
+
return (_jsx(View, { style: bar ? styles.barSection : styles.profile, testID: "navigation-profile", onLayout: onLayout, children: _jsx(Target, { label: profile.label, subtitle: profile.subtitle, selected: active, theme: theme, bar: bar, collapsed: collapsed, roving: roving, triggerRef: triggerRef, ...(profile.href === undefined
|
|
234
281
|
? { expanded: open, controls: id, menu: true }
|
|
235
282
|
: { href: profile.href }), onPress: (event) => {
|
|
236
283
|
if (profile.href !== undefined)
|
|
237
284
|
follow(profile.href, event, onNavigate);
|
|
238
285
|
else
|
|
239
286
|
onOpen();
|
|
240
|
-
}, children: _jsx(
|
|
241
|
-
|
|
242
|
-
|
|
287
|
+
}, children: _jsx(Avatar, { profile: profile, active: active, theme: theme, style: bar ? compactVisualStyle(fontScale) : undefined }) }) }));
|
|
288
|
+
}
|
|
289
|
+
export function useNavigationBarHeight(bottomInset = 0, theme) {
|
|
290
|
+
const { fontScale } = useWindowDimensions();
|
|
291
|
+
return getNavigationBarHeight(fontScale, bottomInset, barMetrics(theme));
|
|
292
|
+
}
|
|
293
|
+
function useCompactBarScroll(selectedIndex) {
|
|
294
|
+
const ref = useRef(null);
|
|
295
|
+
const viewport = useRef(0);
|
|
296
|
+
const content = useRef(0);
|
|
297
|
+
const offset = useRef(0);
|
|
298
|
+
const frames = useRef(new Map());
|
|
299
|
+
const revealSelected = useCallback(() => {
|
|
300
|
+
const frame = frames.current.get(selectedIndex);
|
|
301
|
+
if (frame === undefined || viewport.current === 0 || content.current === 0)
|
|
302
|
+
return;
|
|
303
|
+
if (frame.x >= offset.current && frame.x + frame.width <= offset.current + viewport.current)
|
|
304
|
+
return;
|
|
305
|
+
const x = Math.max(0, Math.min(frame.x + (frame.width - viewport.current) / 2, content.current - viewport.current));
|
|
306
|
+
ref.current?.scrollTo({ x, animated: false });
|
|
307
|
+
offset.current = x;
|
|
308
|
+
}, [selectedIndex]);
|
|
309
|
+
useEffect(revealSelected, [revealSelected]);
|
|
310
|
+
return {
|
|
311
|
+
scrollProps: {
|
|
312
|
+
ref,
|
|
313
|
+
onLayout: (event) => {
|
|
314
|
+
viewport.current = event.nativeEvent.layout.width;
|
|
315
|
+
revealSelected();
|
|
316
|
+
},
|
|
317
|
+
onContentSizeChange: (width) => {
|
|
318
|
+
content.current = width;
|
|
319
|
+
revealSelected();
|
|
320
|
+
},
|
|
321
|
+
onScroll: (event) => {
|
|
322
|
+
offset.current = event.nativeEvent.contentOffset.x;
|
|
323
|
+
},
|
|
324
|
+
},
|
|
325
|
+
itemLayout: (index) => (event) => {
|
|
326
|
+
frames.current.set(index, event.nativeEvent.layout);
|
|
327
|
+
revealSelected();
|
|
328
|
+
},
|
|
329
|
+
};
|
|
243
330
|
}
|
|
244
331
|
export function AppNavigation(props) {
|
|
245
332
|
const { items, profile, pathname, onNavigate, theme, insets = {}, label, closeLabel, collapseLabel, expandLabel, } = props;
|
|
@@ -256,13 +343,18 @@ export function AppNavigation(props) {
|
|
|
256
343
|
const visible = items.flatMap((item) => !bar && !collapsed && state.openIds.includes(item.id)
|
|
257
344
|
? [item, ...(item.children ?? [])]
|
|
258
345
|
: [item]);
|
|
346
|
+
const activeId = visible.some((item) => item.id === state.active.subItem?.id)
|
|
347
|
+
? state.active.subItem?.id
|
|
348
|
+
: state.active.item?.id;
|
|
349
|
+
const profileActive = profile !== undefined && profileIsActive(profile, pathname);
|
|
350
|
+
const compactScroll = useCompactBarScroll(bar ? (profileActive ? items.length : items.findIndex((item) => item.id === activeId)) : -1);
|
|
259
351
|
const roving = useRovingMenu({
|
|
260
352
|
active: true,
|
|
261
353
|
options: [
|
|
262
354
|
...visible.map((item) => ({
|
|
263
|
-
selected: item.id ===
|
|
355
|
+
selected: item.id === activeId,
|
|
264
356
|
})),
|
|
265
|
-
...(profile === undefined ? [] : [{}]),
|
|
357
|
+
...(profile === undefined ? [] : [{ selected: profileActive }]),
|
|
266
358
|
],
|
|
267
359
|
});
|
|
268
360
|
const renderBackground = (backgroundProps = {}) => (_jsxs(View, { ...backgroundProps, role: "navigation", accessibilityLabel: label, testID: "primary-navigation", dataSet: { layout: bar ? 'bar' : 'rail', collapsed: String(collapsed) }, style: [
|
|
@@ -271,6 +363,11 @@ export function AppNavigation(props) {
|
|
|
271
363
|
backgroundColor: theme.background,
|
|
272
364
|
borderColor: theme.border,
|
|
273
365
|
paddingBottom: insets.bottom ?? 0,
|
|
366
|
+
...(bar
|
|
367
|
+
? {
|
|
368
|
+
minHeight: getNavigationBarHeight(dimensions.fontScale, insets.bottom, barMetrics(theme)),
|
|
369
|
+
}
|
|
370
|
+
: {}),
|
|
274
371
|
paddingLeft: insets.left ?? 0,
|
|
275
372
|
paddingRight: insets.right ?? 0,
|
|
276
373
|
},
|
|
@@ -281,19 +378,19 @@ export function AppNavigation(props) {
|
|
|
281
378
|
props.style,
|
|
282
379
|
], children: [!bar ? (_jsx(Target, { label: collapsed ? expandLabel : collapseLabel, expanded: !collapsed, collapsed: true, theme: theme, onPress: () => {
|
|
283
380
|
state.setCollapsed(!collapsed);
|
|
284
|
-
}, children: _jsx(Decorative, { children: _jsx(Text, { style: { color: theme.text }, children: collapsed ? '›' : '‹' }) }) })) : null, _jsxs(ScrollView, { horizontal: bar, scrollEnabled:
|
|
381
|
+
}, children: _jsx(Decorative, { children: _jsx(Text, { style: { ...textStyle(theme), color: theme.text }, children: collapsed ? '›' : '‹' }) }) })) : null, _jsxs(ScrollView, { ...(bar ? compactScroll.scrollProps : {}), testID: "navigation-items", horizontal: bar, scrollEnabled: true, showsHorizontalScrollIndicator: false, style: bar ? styles.barItems : styles.railItems, contentContainerStyle: bar ? styles.barContent : undefined, children: [items.map((item, index) => {
|
|
285
382
|
const active = state.active.item?.id === item.id;
|
|
286
383
|
const children = item.children ?? [];
|
|
287
384
|
const open = !collapsed && state.openIds.includes(item.id);
|
|
288
385
|
const href = bar && active ? nextSectionHref(item, pathname) : item.href;
|
|
289
|
-
return (_jsxs(View, { style: bar ? styles.barSection : undefined, testID: `navigation-section-${item.id}`, children: [_jsx(Target, { label: item.label, selected: active, ancestor: active && !bar && !collapsed && state.active.subItem !== null, theme: theme, bar: bar, collapsed: collapsed, roving: roving.itemProps(visible.indexOf(item)), ...(!bar && children.length > 0
|
|
386
|
+
return (_jsxs(View, { style: bar ? styles.barSection : undefined, testID: `navigation-section-${item.id}`, onLayout: bar ? compactScroll.itemLayout(index) : undefined, children: [_jsx(Target, { label: item.label, selected: active, ancestor: active && !bar && !collapsed && state.active.subItem !== null, theme: theme, bar: bar, collapsed: collapsed, roving: roving.itemProps(visible.indexOf(item)), ...(!bar && children.length > 0
|
|
290
387
|
? { expanded: open, controls: `${id}-${String(index)}` }
|
|
291
388
|
: { href }), onPress: (event) => {
|
|
292
389
|
if (!bar && children.length > 0)
|
|
293
390
|
state.toggleGroup(item.id);
|
|
294
391
|
else
|
|
295
392
|
follow(href, event, onNavigate);
|
|
296
|
-
}, children: _jsx(Decorative, { children: item.icon({ active, size:
|
|
393
|
+
}, children: _jsx(Decorative, { style: bar ? compactVisualStyle(dimensions.fontScale) : undefined, children: item.icon({ active, size: NAVIGATION_BAR_DIMENSIONS.icon }) }) }), !bar && open && children.length > 0 ? (_jsx(View, { nativeID: `${id}-${String(index)}`, role: "group", accessibilityLabel: item.label, style: [styles.children, { borderColor: theme.border }], children: children.map((child) => {
|
|
297
394
|
const selected = state.active.subItem?.id === child.id;
|
|
298
395
|
return (_jsx(Target, { label: child.label, selected: selected, href: child.href, theme: theme, roving: roving.itemProps(visible.indexOf(child)), onPress: (event) => {
|
|
299
396
|
follow(child.href, event, onNavigate);
|
|
@@ -301,12 +398,12 @@ export function AppNavigation(props) {
|
|
|
301
398
|
}) })) : null] }, item.id));
|
|
302
399
|
}), bar && profile !== undefined ? (_jsx(Profile, { profile: profile, open: profileOpen, onOpen: () => {
|
|
303
400
|
setProfileOpen(true);
|
|
304
|
-
}, triggerRef: profileTriggerRef, id: profileMenuId, theme: theme, bar: true, collapsed: false, pathname: pathname, onNavigate: onNavigate, roving: roving.itemProps(visible.length) })) : null] }), !bar && profile !== undefined ? (_jsx(Profile, { profile: profile, open: profileOpen, onOpen: () => {
|
|
401
|
+
}, triggerRef: profileTriggerRef, id: profileMenuId, theme: theme, bar: true, collapsed: false, pathname: pathname, onNavigate: onNavigate, roving: roving.itemProps(visible.length), onLayout: compactScroll.itemLayout(items.length) })) : null] }), !bar && profile !== undefined ? (_jsx(Profile, { profile: profile, open: profileOpen, onOpen: () => {
|
|
305
402
|
setProfileOpen(true);
|
|
306
403
|
}, triggerRef: profileTriggerRef, id: profileMenuId, theme: theme, bar: false, collapsed: collapsed, pathname: pathname, onNavigate: onNavigate, roving: roving.itemProps(visible.length) })) : null] }));
|
|
307
404
|
if (profile?.menu === undefined)
|
|
308
405
|
return renderBackground();
|
|
309
|
-
return (_jsx(Menu, { renderBackground: renderBackground, entries: profile.menu, closeLabel: closeLabel, pathname: pathname, visible: profileOpen, id: profileMenuId, label: profile.label, triggerRef: profileTriggerRef, theme: theme, onClose: () => {
|
|
406
|
+
return (_jsx(Menu, { renderBackground: renderBackground, entries: profile.menu, closeLabel: closeLabel, pathname: pathname, visible: profileOpen, id: profileMenuId, label: profile.label, subtitle: profile.subtitle, triggerRef: profileTriggerRef, theme: theme, onClose: () => {
|
|
310
407
|
setProfileOpen(false);
|
|
311
408
|
}, onNavigate: onNavigate }));
|
|
312
409
|
}
|
|
@@ -333,7 +430,7 @@ export function SectionPicker({ item, pathname, onNavigate, theme, closeLabel, }
|
|
|
333
430
|
borderRadius: theme.radius,
|
|
334
431
|
padding: theme.spacing,
|
|
335
432
|
},
|
|
336
|
-
], children: [_jsxs(View, { children: [_jsx(Text, { style: { color: theme.muted }, children: item.label }), _jsx(Text, { style: { color: theme.text }, children: active?.label })] }), _jsx(Decorative, { children: _jsx(Text, { style: { color: theme.text }, children: "\u2304" }) })] }) }));
|
|
433
|
+
], children: [_jsxs(View, { children: [_jsx(Text, { style: { ...textStyle(theme), color: theme.muted }, children: item.label }), _jsx(Text, { style: { ...textStyle(theme), color: theme.text }, children: active?.label })] }), _jsx(Decorative, { children: _jsx(Text, { style: { ...textStyle(theme), color: theme.text }, children: "\u2304" }) })] }) }));
|
|
337
434
|
return (_jsx(Menu, { renderBackground: renderBackground, entries: entries, closeLabel: closeLabel, pathname: pathname, label: item.label, visible: open, id: id, triggerRef: triggerRef, theme: theme, onClose: () => {
|
|
338
435
|
setOpen(false);
|
|
339
436
|
}, onNavigate: (href) => {
|
|
@@ -342,29 +439,31 @@ export function SectionPicker({ item, pathname, onNavigate, theme, closeLabel, }
|
|
|
342
439
|
} }));
|
|
343
440
|
}
|
|
344
441
|
const styles = StyleSheet.create({
|
|
442
|
+
labelGroup: { minWidth: 0, flexShrink: 1 },
|
|
443
|
+
menuProfile: { padding: 8 },
|
|
345
444
|
target: {
|
|
346
|
-
padding:
|
|
445
|
+
padding: NAVIGATION_BAR_DIMENSIONS.targetPadding,
|
|
347
446
|
},
|
|
348
447
|
railTarget: { flexDirection: 'row', alignItems: 'center' },
|
|
349
448
|
collapsedTarget: { justifyContent: 'center' },
|
|
350
449
|
barTarget: { flexDirection: 'column', alignItems: 'center', justifyContent: 'center', flex: 1 },
|
|
351
450
|
bar: {
|
|
352
451
|
flexDirection: 'row',
|
|
353
|
-
minHeight: NAVIGATION_DIMENSIONS.
|
|
354
|
-
borderTopWidth:
|
|
452
|
+
minHeight: NAVIGATION_DIMENSIONS.nativeBar,
|
|
453
|
+
borderTopWidth: NAVIGATION_BAR_DIMENSIONS.border,
|
|
355
454
|
width: '100%',
|
|
356
455
|
},
|
|
357
456
|
rail: { borderRightWidth: 1, height: '100%' },
|
|
358
457
|
railItems: { flex: 1 },
|
|
359
458
|
barItems: { width: '100%' },
|
|
360
|
-
barContent: { flexDirection: 'row', flexGrow: 1 },
|
|
459
|
+
barContent: { flexDirection: 'row', flexGrow: 1, minWidth: '100%' },
|
|
361
460
|
barSection: { flex: 1, minWidth: NAVIGATION_DIMENSIONS.target },
|
|
362
461
|
children: { marginLeft: 20, paddingLeft: 8, borderLeftWidth: 1 },
|
|
363
462
|
profile: { position: 'relative', marginTop: 'auto', paddingTop: 8, borderTopWidth: 1 },
|
|
364
463
|
avatar: {
|
|
365
|
-
width:
|
|
366
|
-
height:
|
|
367
|
-
borderRadius:
|
|
464
|
+
width: NAVIGATION_DIMENSIONS.avatar,
|
|
465
|
+
height: NAVIGATION_DIMENSIONS.avatar,
|
|
466
|
+
borderRadius: NAVIGATION_DIMENSIONS.avatar / 2,
|
|
368
467
|
alignItems: 'center',
|
|
369
468
|
justifyContent: 'center',
|
|
370
469
|
},
|