@baukit/navigation 0.18.3 → 0.19.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/dist/index.d.ts.map +1 -1
- package/dist/index.js +19 -14
- package/dist/index.js.map +1 -1
- package/dist/native-menu.d.ts +22 -0
- package/dist/native-menu.d.ts.map +1 -0
- package/dist/native-menu.js +226 -0
- package/dist/native-menu.js.map +1 -0
- package/dist/native-primitives.d.ts +51 -0
- package/dist/native-primitives.d.ts.map +1 -0
- package/dist/native-primitives.js +125 -0
- package/dist/native-primitives.js.map +1 -0
- package/dist/native-profile.d.ts +34 -0
- package/dist/native-profile.d.ts.map +1 -0
- package/dist/native-profile.js +67 -0
- package/dist/native-profile.js.map +1 -0
- package/dist/native-section-picker.d.ts +14 -0
- package/dist/native-section-picker.d.ts.map +1 -0
- package/dist/native-section-picker.js +46 -0
- package/dist/native-section-picker.js.map +1 -0
- package/dist/native-styles.d.ts +106 -0
- package/dist/native-styles.d.ts.map +1 -0
- package/dist/native-styles.js +50 -0
- package/dist/native-styles.js.map +1 -0
- package/dist/native-theme.d.ts +49 -0
- package/dist/native-theme.d.ts.map +1 -0
- package/dist/native-theme.js +56 -0
- package/dist/native-theme.js.map +1 -0
- package/dist/native.d.ts +9 -52
- package/dist/native.d.ts.map +1 -1
- package/dist/native.js +148 -536
- package/dist/native.js.map +1 -1
- package/dist/use-navigation-state.d.ts +9 -8
- package/dist/use-navigation-state.d.ts.map +1 -1
- package/dist/use-navigation-state.js +3 -2
- package/dist/use-navigation-state.js.map +1 -1
- package/dist/web-link.d.ts +20 -0
- package/dist/web-link.d.ts.map +1 -0
- package/dist/web-link.js +23 -0
- package/dist/web-link.js.map +1 -0
- package/dist/web-menu.d.ts +19 -0
- package/dist/web-menu.d.ts.map +1 -0
- package/dist/web-menu.js +96 -0
- package/dist/web-menu.js.map +1 -0
- package/dist/web-profile.d.ts +16 -0
- package/dist/web-profile.d.ts.map +1 -0
- package/dist/web-profile.js +58 -0
- package/dist/web-profile.js.map +1 -0
- package/dist/web-section-picker.d.ts +13 -0
- package/dist/web-section-picker.d.ts.map +1 -0
- package/dist/web-section-picker.js +71 -0
- package/dist/web-section-picker.js.map +1 -0
- package/dist/web.d.ts +7 -25
- package/dist/web.d.ts.map +1 -1
- package/dist/web.js +113 -257
- package/dist/web.js.map +1 -1
- package/package.json +7 -7
- package/src/index.ts +22 -16
- package/src/native-menu.tsx +436 -0
- package/src/native-primitives.tsx +308 -0
- package/src/native-profile.tsx +153 -0
- package/src/native-section-picker.tsx +102 -0
- package/src/native-styles.ts +50 -0
- package/src/native-theme.ts +108 -0
- package/src/native.tsx +355 -1086
- package/src/use-navigation-state.ts +20 -5
- package/src/web-link.tsx +51 -0
- package/src/web-menu.tsx +220 -0
- package/src/web-profile.tsx +201 -0
- package/src/web-section-picker.tsx +128 -0
- package/src/web.tsx +256 -598
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import { Platform, type TextStyle, type ViewStyle } from 'react-native';
|
|
3
|
+
import {
|
|
4
|
+
getNavigationBarLineHeight,
|
|
5
|
+
NAVIGATION_BAR_DIMENSIONS,
|
|
6
|
+
type NavigationBarMetrics,
|
|
7
|
+
} from './index.js';
|
|
8
|
+
|
|
9
|
+
export interface NavigationIconState {
|
|
10
|
+
readonly active: boolean;
|
|
11
|
+
readonly size: number;
|
|
12
|
+
}
|
|
13
|
+
export type NavigationIcon = (state: NavigationIconState) => ReactNode;
|
|
14
|
+
export interface NavigationTypography {
|
|
15
|
+
readonly fontFamily?: string;
|
|
16
|
+
readonly activeFontFamily?: string;
|
|
17
|
+
readonly fontSize?: number;
|
|
18
|
+
readonly barFontSize?: number;
|
|
19
|
+
readonly subtitleFontSize?: number;
|
|
20
|
+
readonly fontWeight?: TextStyle['fontWeight'];
|
|
21
|
+
readonly activeFontWeight?: TextStyle['fontWeight'];
|
|
22
|
+
readonly lineHeight?: number;
|
|
23
|
+
readonly letterSpacing?: number;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface NavigationTheme {
|
|
27
|
+
readonly background: string;
|
|
28
|
+
readonly text: string;
|
|
29
|
+
readonly muted: string;
|
|
30
|
+
readonly danger: string;
|
|
31
|
+
readonly activeBackground: string;
|
|
32
|
+
readonly activeText: string;
|
|
33
|
+
readonly ancestorText: string;
|
|
34
|
+
readonly border: string;
|
|
35
|
+
readonly focus: string;
|
|
36
|
+
readonly radius: number;
|
|
37
|
+
readonly spacing: number;
|
|
38
|
+
readonly typography?: NavigationTypography;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface NavigationInsets {
|
|
42
|
+
readonly top?: number;
|
|
43
|
+
readonly bottom?: number;
|
|
44
|
+
readonly left?: number;
|
|
45
|
+
readonly right?: number;
|
|
46
|
+
}
|
|
47
|
+
export type Navigate = (href: string, options?: { readonly replace: boolean }) => void;
|
|
48
|
+
|
|
49
|
+
const DEFAULT_FONT_SIZE = 14;
|
|
50
|
+
const DEFAULT_SUBTITLE_FONT_SIZE = 12;
|
|
51
|
+
export const MENU_WIDTH = 280;
|
|
52
|
+
export const MENU_EDGE = 8;
|
|
53
|
+
|
|
54
|
+
export function barMetrics(theme?: NavigationTheme): NavigationBarMetrics {
|
|
55
|
+
return {
|
|
56
|
+
...(theme === undefined ? {} : { spacing: theme.spacing }),
|
|
57
|
+
...(theme?.typography?.barFontSize === undefined
|
|
58
|
+
? {}
|
|
59
|
+
: { fontSize: theme.typography.barFontSize }),
|
|
60
|
+
...(theme?.typography?.lineHeight === undefined
|
|
61
|
+
? {}
|
|
62
|
+
: { lineHeight: theme.typography.lineHeight }),
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function fontFamily(typography: NavigationTypography, selected: boolean): string | undefined {
|
|
67
|
+
return selected ? (typography.activeFontFamily ?? typography.fontFamily) : typography.fontFamily;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function fontSize(typography: NavigationTypography, bar: boolean): number {
|
|
71
|
+
return bar
|
|
72
|
+
? (typography.barFontSize ?? NAVIGATION_BAR_DIMENSIONS.labelFontSize)
|
|
73
|
+
: (typography.fontSize ?? DEFAULT_FONT_SIZE);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function fontWeight(typography: NavigationTypography, selected: boolean): TextStyle['fontWeight'] {
|
|
77
|
+
return selected ? (typography.activeFontWeight ?? '700') : (typography.fontWeight ?? '400');
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function textStyle(theme: NavigationTheme, selected = false, bar = false): TextStyle {
|
|
81
|
+
const typography = theme.typography ?? {};
|
|
82
|
+
return {
|
|
83
|
+
fontFamily: fontFamily(typography, selected),
|
|
84
|
+
fontSize: fontSize(typography, bar),
|
|
85
|
+
fontWeight: fontWeight(typography, selected),
|
|
86
|
+
lineHeight: bar ? getNavigationBarLineHeight(barMetrics(theme)) : typography.lineHeight,
|
|
87
|
+
letterSpacing: typography.letterSpacing,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export function subtitleTextStyle(theme: NavigationTheme): TextStyle {
|
|
92
|
+
return {
|
|
93
|
+
...textStyle(theme),
|
|
94
|
+
color: theme.muted,
|
|
95
|
+
fontSize: theme.typography?.subtitleFontSize ?? DEFAULT_SUBTITLE_FONT_SIZE,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export function menuModalPadding(insets: NavigationInsets = {}): ViewStyle {
|
|
100
|
+
const native = Platform.OS !== 'web';
|
|
101
|
+
const edge = (inset: number | undefined): number => MENU_EDGE + (native ? (inset ?? 0) : 0);
|
|
102
|
+
return {
|
|
103
|
+
paddingTop: edge(insets.top),
|
|
104
|
+
paddingBottom: edge(insets.bottom),
|
|
105
|
+
paddingLeft: edge(insets.left),
|
|
106
|
+
paddingRight: edge(insets.right),
|
|
107
|
+
};
|
|
108
|
+
}
|