@plexui/react-native 0.2.13 → 0.2.14

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.
@@ -1,5 +1,5 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import { Platform, View } from "react-native";
2
+ import { Platform, StyleSheet, View } from "react-native";
3
3
  import { useSafeAreaInsets } from "react-native-safe-area-context";
4
4
  import { SoftBottomVeil, SoftTopEdge } from "../../internal/BarBackdrop";
5
5
  import { useTheme } from "../../theme/ThemeProvider";
@@ -22,6 +22,11 @@ export function ScrollEdge({ edge = "top", scrolled = false, canvasColor, testID
22
22
  return null;
23
23
  return (_jsx(View, { pointerEvents: "none", testID: testID, style: [{ position: "absolute", top: 0, left: 0, right: 0, height: insets.top }, style], children: _jsx(SoftTopEdge, { fill: canvas, blur: Platform.OS === "web" ? 6 : 0 }) }));
24
24
  }
25
- // The safe area at that edge; the veil reaches 34 past it, into the screen
26
- return (_jsx(View, { pointerEvents: "none", testID: testID, style: [{ position: "absolute", left: 0, right: 0 }, top ? { top: 0, height: insets.top } : { bottom: 0, height: insets.bottom }, style], children: top ? _jsx(SoftBottomVeil, { fill: canvas, bottom: insets.top }) : _jsx(SoftBottomVeil, { fill: canvas, top: 0 }) }));
25
+ // The safe area at that edge, or the height the style gives the top edge (a bar's row of buttons under the status
26
+ // bar): the content is blurred in full down to it, and the veil and the blur ease out over the 34 past it
27
+ const height = StyleSheet.flatten(style)?.height;
28
+ const reach = top && typeof height === "number" ? height + FULL_BLUR_SHORTFALL : insets.top;
29
+ return (_jsx(View, { pointerEvents: "none", testID: testID, style: [{ position: "absolute", left: 0, right: 0 }, top ? { top: 0, height: insets.top } : { bottom: 0, height: insets.bottom }, style], children: top ? _jsx(SoftBottomVeil, { fill: canvas, bottom: reach }) : _jsx(SoftBottomVeil, { fill: canvas, top: 0 }) }));
27
30
  }
31
+ /** The veil's blur is full 6 short of the edge it is turned over at (12 to 40 into its 34): a given height adds them. */
32
+ const FULL_BLUR_SHORTFALL = 6;
@@ -73,10 +73,8 @@ function trackingFor(theme, style, mono) {
73
73
  // On the web, Chromium and Firefox on a Mac draw text with subpixel smoothing, 11–20% heavier than an iPhone draws the
74
74
  // same words; grayscale smoothing draws them within 1–2% of it
75
75
  const WEB_SMOOTHING = (Platform.OS === "web" ? { WebkitFontSmoothing: "antialiased", MozOsxFontSmoothing: "grayscale" } : {});
76
- // A mono face's weights: the web's 501–549 of a system face draw as a synthesized bold in Chromium, so Medium is 500
77
- const weightNumber = (weight) => (Platform.OS === "web"
78
- ? { regular: "400", medium: "500", semibold: "590", bold: "700" }
79
- : { regular: "400", medium: "500", semibold: "600", bold: "700" })[weight];
76
+ // A mono face's weights: a browser draws a weight its face lacks (510, 590) as a synthesized bold, so the named ones
77
+ const weightNumber = (weight) => ({ regular: "400", medium: "500", semibold: "600", bold: "700" }[weight]);
80
78
  /**
81
79
  * Text in the faces, sizes and colors of Plex UI. `variant` takes the platform's text styles (Body 17 on iOS, Body
82
80
  * Large 16 on Android); `size` the Plex UI scale. The tracking is the kit's Inter tracking at the size.
@@ -1,8 +1,38 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { Animated, Platform, StyleSheet, View } from "react-native";
3
- import { useTheme } from "../theme/ThemeProvider";
3
+ import { useTheme, useThemeOverrides } from "../theme/ThemeProvider";
4
4
  import { blurModule, liquidGlassModule } from "./optional";
5
5
  import { useReduceTransparency } from "./reduceTransparency";
6
+ /**
7
+ * In a browser the glass is a fill over a CSS blur, which shows far more of what is under it than iOS's own: a menu is
8
+ * almost opaque there, and a chip's label must read over any photo. So on the web the plain glass and the menu take
9
+ * these denser fills and blurs (each a token a theme may set; the shared web tokens stay as they are). A brand that
10
+ * sets the shared token itself keeps it.
11
+ */
12
+ const WEB_DENSE = {
13
+ "--mobile-glass-background": {
14
+ fill: "--mobile-glass-web-background",
15
+ light: "rgba(243, 243, 243, 0.8)",
16
+ dark: "rgba(28, 28, 30, 0.7)",
17
+ filter: "--mobile-glass-web-backdrop-filter",
18
+ blur: "blur(20px)",
19
+ },
20
+ // Pressed, a step deeper, as the shared tokens step from 55% to 75%
21
+ "--mobile-glass-background-active": {
22
+ fill: "--mobile-glass-web-background-active",
23
+ light: "rgba(232, 232, 232, 0.9)",
24
+ dark: "rgba(58, 58, 60, 0.8)",
25
+ filter: "--mobile-glass-web-backdrop-filter",
26
+ blur: "blur(20px)",
27
+ },
28
+ "--menu-mobile-background": {
29
+ fill: "--menu-mobile-web-background",
30
+ light: "rgba(255, 255, 255, 0.9)",
31
+ dark: "rgba(28, 28, 30, 0.9)",
32
+ filter: "--menu-mobile-web-backdrop-filter",
33
+ blur: "blur(30px)",
34
+ },
35
+ };
6
36
  /** The filter and the shadow of the glass surfaces of the phone layer, by their fill (mobile-materials.css, touch.css). */
7
37
  const SURFACES = {
8
38
  "--menu-mobile-background": { filter: "--menu-mobile-backdrop-filter", shadow: "--menu-shadow" },
@@ -24,6 +54,7 @@ const intensityOf = (radius) => Math.max(0, Math.min(100, Math.round(radius * 5)
24
54
  export function Glass({ radius = 0, elevation = "regular", tint, interactive, fillToken, filterToken, shadowToken, blur, style, children, ...rest }) {
25
55
  const theme = useTheme();
26
56
  const reduceTransparency = useReduceTransparency();
57
+ const overrides = useThemeOverrides();
27
58
  const shape = { borderRadius: radius, borderCurve: "continuous" };
28
59
  const surface = fillToken ? SURFACES[fillToken] : undefined;
29
60
  const shadow = theme.token(shadowToken ?? surface?.shadow ?? (elevation === "raised" ? "--mobile-glass-shadow-raised" : "--mobile-glass-shadow"));
@@ -34,10 +65,15 @@ export function Glass({ radius = 0, elevation = "regular", tint, interactive, fi
34
65
  const { GlassView } = native;
35
66
  return (_jsx(GlassView, { ...rest, glassEffectStyle: "regular", colorScheme: theme.scheme, tintColor: tint, isInteractive: interactive, style: [shape, style], children: children }));
36
67
  }
37
- const fill = tint ?? theme.color(fillToken ?? "--mobile-glass-background");
38
- const filterValue = theme.token(filterToken ?? surface?.filter ?? "--mobile-glass-backdrop-filter");
39
- const filter = blur != null ? `blur(${blur}px)` : typeof filterValue === "string" ? filterValue : "blur(12px)";
40
68
  const web = Platform.OS === "web";
69
+ const fillName = fillToken ?? "--mobile-glass-background";
70
+ const filterName = filterToken ?? surface?.filter ?? "--mobile-glass-backdrop-filter";
71
+ const dense = web && !theme.isAndroid ? WEB_DENSE[fillName] : undefined;
72
+ const denseFill = dense != null && tint == null && overrides?.[fillName] == null;
73
+ const denseFilter = dense != null && filterToken == null && overrides?.[filterName] == null;
74
+ const fill = tint ?? (denseFill ? theme.color(dense.fill, theme.scheme === "dark" ? dense.dark : dense.light) : theme.color(fillName));
75
+ const filterValue = denseFilter ? (theme.token(dense.filter) ?? dense.blur) : theme.token(filterName);
76
+ const filter = blur != null ? `blur(${blur}px)` : typeof filterValue === "string" ? filterValue : "blur(12px)";
41
77
  const module = web || Platform.OS !== "ios" ? null : blurModule();
42
78
  const opaque = reduceTransparency || (!web && module == null);
43
79
  if (web && !opaque) {
@@ -35,9 +35,12 @@ const ThemeSettingsContext = createContext(null);
35
35
  const WEIGHTS = Platform.OS === "web"
36
36
  ? { regular: "400", medium: "510", semibold: "590", bold: "700" }
37
37
  : { regular: "400", medium: "500", semibold: "600", bold: "700" };
38
- // The web's system font (react-native-web's own stack, no family set): Chromium draws 501–549 of it as a synthesized bold,
39
- // heavier than 590, so Medium is 500 there; 590 is SF's own Semibold, as an iPhone draws it
40
- const SYSTEM_WEIGHTS = Platform.OS === "web" ? { ...WEIGHTS, medium: "500" } : WEIGHTS;
38
+ // The web's system font (react-native-web's own stack, or a family that names the system's: -apple-system, system-ui):
39
+ // a browser has only its 500 and 600 there and draws 510 and 590 as a synthesized bold (Chromium, Safari on an iPhone:
40
+ // 590 heavier than 700), so Medium is 500 and Semibold 600
41
+ const SYSTEM_WEIGHTS = Platform.OS === "web" ? { ...WEIGHTS, medium: "500", semibold: "600" } : WEIGHTS;
42
+ /** Whether a font family starts with the system's face (`-apple-system, system-ui, sans-serif`), not an app's own. */
43
+ const isSystemFamily = (family) => /^\s*["']?(-apple-system|system-ui|BlinkMacSystemFont|ui-sans-serif|SF Pro|sans-serif)\b/i.test(family);
41
44
  /** The platform a ThemeProvider draws by default. */
42
45
  export function defaultPlatform() {
43
46
  return Platform.OS === "android" ? "android" : "ios";
@@ -93,12 +96,12 @@ function warnUnresolvedColors(brand, resolver) {
93
96
  function fontFor(fonts, weight) {
94
97
  const sans = fonts?.sans;
95
98
  if (typeof sans === "string")
96
- return { fontFamily: sans, fontWeight: WEIGHTS[weight] };
99
+ return { fontFamily: sans, fontWeight: (isSystemFamily(sans) ? SYSTEM_WEIGHTS : WEIGHTS)[weight] };
97
100
  const family = sans?.[weight] ?? (weight === "semibold" ? sans?.bold : undefined) ?? sans?.regular;
98
101
  // A family per weight carries its weight: a weight on top would be synthesized on Android
99
102
  if (family && sans?.[weight])
100
103
  return { fontFamily: family };
101
- return family ? { fontFamily: family, fontWeight: WEIGHTS[weight] } : { fontWeight: SYSTEM_WEIGHTS[weight] };
104
+ return family ? { fontFamily: family, fontWeight: (isSystemFamily(family) ? SYSTEM_WEIGHTS : WEIGHTS)[weight] } : { fontWeight: SYSTEM_WEIGHTS[weight] };
102
105
  }
103
106
  /** Builds a theme for a scheme and a platform (ThemeProvider does it for its children). */
104
107
  export function createTheme(options) {
@@ -241,6 +244,10 @@ function defaultTheme() {
241
244
  return fallbackTheme;
242
245
  }
243
246
  /** The theme of the nearest ThemeProvider (the light default of the device's platform without one). */
247
+ /** The tokens the brands of the providers around set (internal: a default that must yield to a brand's own). */
248
+ export function useThemeOverrides() {
249
+ return useContext(ThemeSettingsContext)?.overrides;
250
+ }
244
251
  export function useTheme() {
245
252
  return useContext(ThemeContext) ?? defaultTheme();
246
253
  }
@@ -77,4 +77,6 @@ export declare function createTheme(options: {
77
77
  */
78
78
  export declare function ThemeProvider({ scheme, platform, selectionColor, brand, fonts: fontsProp, viewportWidth, children }: ThemeProviderProps): import("react").JSX.Element;
79
79
  /** The theme of the nearest ThemeProvider (the light default of the device's platform without one). */
80
+ /** The tokens the brands of the providers around set (internal: a default that must yield to a brand's own). */
81
+ export declare function useThemeOverrides(): Readonly<Record<string, string>> | undefined;
80
82
  export declare function useTheme(): Theme;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plexui/react-native",
3
- "version": "0.2.13",
3
+ "version": "0.2.14",
4
4
  "description": "Plex UI components for React Native and Expo: iOS 26 and Material 3, on the shared @plexui/styles tokens",
5
5
  "license": "MIT",
6
6
  "homepage": "https://plexui.com",
@@ -1,4 +1,4 @@
1
- import { Platform, View, type StyleProp, type ViewStyle } from "react-native"
1
+ import { Platform, StyleSheet, View, type StyleProp, type ViewStyle } from "react-native"
2
2
  import { useSafeAreaInsets } from "react-native-safe-area-context"
3
3
  import { SoftBottomVeil, SoftTopEdge } from "../../internal/BarBackdrop"
4
4
  import { useTheme } from "../../theme/ThemeProvider"
@@ -35,14 +35,20 @@ export function ScrollEdge({ edge = "top", scrolled = false, canvasColor, testID
35
35
  </View>
36
36
  )
37
37
  }
38
- // The safe area at that edge; the veil reaches 34 past it, into the screen
38
+ // The safe area at that edge, or the height the style gives the top edge (a bar's row of buttons under the status
39
+ // bar): the content is blurred in full down to it, and the veil and the blur ease out over the 34 past it
40
+ const height = StyleSheet.flatten(style)?.height
41
+ const reach = top && typeof height === "number" ? height + FULL_BLUR_SHORTFALL : insets.top
39
42
  return (
40
43
  <View
41
44
  pointerEvents="none"
42
45
  testID={testID}
43
46
  style={[{ position: "absolute", left: 0, right: 0 }, top ? { top: 0, height: insets.top } : { bottom: 0, height: insets.bottom }, style]}
44
47
  >
45
- {top ? <SoftBottomVeil fill={canvas} bottom={insets.top} /> : <SoftBottomVeil fill={canvas} top={0} />}
48
+ {top ? <SoftBottomVeil fill={canvas} bottom={reach} /> : <SoftBottomVeil fill={canvas} top={0} />}
46
49
  </View>
47
50
  )
48
51
  }
52
+
53
+ /** The veil's blur is full 6 short of the edge it is turned over at (12 to 40 into its 34): a given height adds them. */
54
+ const FULL_BLUR_SHORTFALL = 6
@@ -113,11 +113,9 @@ function trackingFor(theme: Theme, style: StyleProp<TextStyle>, mono: boolean |
113
113
  // same words; grayscale smoothing draws them within 1–2% of it
114
114
  const WEB_SMOOTHING = (Platform.OS === "web" ? { WebkitFontSmoothing: "antialiased", MozOsxFontSmoothing: "grayscale" } : {}) as TextStyle
115
115
 
116
- // A mono face's weights: the web's 501–549 of a system face draw as a synthesized bold in Chromium, so Medium is 500
116
+ // A mono face's weights: a browser draws a weight its face lacks (510, 590) as a synthesized bold, so the named ones
117
117
  const weightNumber = (weight: FontWeightName) =>
118
- (Platform.OS === "web"
119
- ? { regular: "400", medium: "500", semibold: "590", bold: "700" } as Record<FontWeightName, string>
120
- : { regular: "400", medium: "500", semibold: "600", bold: "700" })[weight] as TextStyle["fontWeight"]
118
+ ({ regular: "400", medium: "500", semibold: "600", bold: "700" } as Record<FontWeightName, string>)[weight] as TextStyle["fontWeight"]
121
119
 
122
120
  /**
123
121
  * Text in the faces, sizes and colors of Plex UI. `variant` takes the platform's text styles (Body 17 on iOS, Body
@@ -1,5 +1,5 @@
1
1
  import { Animated, Platform, StyleSheet, View, type StyleProp, type ViewProps, type ViewStyle } from "react-native"
2
- import { useTheme } from "../theme/ThemeProvider"
2
+ import { useTheme, useThemeOverrides } from "../theme/ThemeProvider"
3
3
  import { blurModule, liquidGlassModule } from "./optional"
4
4
  import { useReduceTransparency } from "./reduceTransparency"
5
5
 
@@ -29,6 +29,37 @@ export type GlassProps = ViewProps & {
29
29
  style?: StyleProp<ViewStyle>
30
30
  }
31
31
 
32
+ /**
33
+ * In a browser the glass is a fill over a CSS blur, which shows far more of what is under it than iOS's own: a menu is
34
+ * almost opaque there, and a chip's label must read over any photo. So on the web the plain glass and the menu take
35
+ * these denser fills and blurs (each a token a theme may set; the shared web tokens stay as they are). A brand that
36
+ * sets the shared token itself keeps it.
37
+ */
38
+ const WEB_DENSE: Record<string, { fill: string; light: string; dark: string; filter: string; blur: string }> = {
39
+ "--mobile-glass-background": {
40
+ fill: "--mobile-glass-web-background",
41
+ light: "rgba(243, 243, 243, 0.8)",
42
+ dark: "rgba(28, 28, 30, 0.7)",
43
+ filter: "--mobile-glass-web-backdrop-filter",
44
+ blur: "blur(20px)",
45
+ },
46
+ // Pressed, a step deeper, as the shared tokens step from 55% to 75%
47
+ "--mobile-glass-background-active": {
48
+ fill: "--mobile-glass-web-background-active",
49
+ light: "rgba(232, 232, 232, 0.9)",
50
+ dark: "rgba(58, 58, 60, 0.8)",
51
+ filter: "--mobile-glass-web-backdrop-filter",
52
+ blur: "blur(20px)",
53
+ },
54
+ "--menu-mobile-background": {
55
+ fill: "--menu-mobile-web-background",
56
+ light: "rgba(255, 255, 255, 0.9)",
57
+ dark: "rgba(28, 28, 30, 0.9)",
58
+ filter: "--menu-mobile-web-backdrop-filter",
59
+ blur: "blur(30px)",
60
+ },
61
+ }
62
+
32
63
  /** The filter and the shadow of the glass surfaces of the phone layer, by their fill (mobile-materials.css, touch.css). */
33
64
  const SURFACES: Record<string, { filter: string; shadow: string }> = {
34
65
  "--menu-mobile-background": { filter: "--menu-mobile-backdrop-filter", shadow: "--menu-shadow" },
@@ -64,6 +95,7 @@ export function Glass({
64
95
  }: GlassProps) {
65
96
  const theme = useTheme()
66
97
  const reduceTransparency = useReduceTransparency()
98
+ const overrides = useThemeOverrides()
67
99
  const shape: ViewStyle = { borderRadius: radius, borderCurve: "continuous" }
68
100
  const surface = fillToken ? SURFACES[fillToken] : undefined
69
101
  const shadow = theme.token(shadowToken ?? surface?.shadow ?? (elevation === "raised" ? "--mobile-glass-shadow-raised" : "--mobile-glass-shadow"))
@@ -85,10 +117,15 @@ export function Glass({
85
117
  </GlassView>
86
118
  )
87
119
  }
88
- const fill = tint ?? theme.color(fillToken ?? "--mobile-glass-background")
89
- const filterValue = theme.token(filterToken ?? surface?.filter ?? "--mobile-glass-backdrop-filter")
90
- const filter = blur != null ? `blur(${blur}px)` : typeof filterValue === "string" ? filterValue : "blur(12px)"
91
120
  const web = Platform.OS === "web"
121
+ const fillName = fillToken ?? "--mobile-glass-background"
122
+ const filterName = filterToken ?? surface?.filter ?? "--mobile-glass-backdrop-filter"
123
+ const dense = web && !theme.isAndroid ? WEB_DENSE[fillName] : undefined
124
+ const denseFill = dense != null && tint == null && overrides?.[fillName] == null
125
+ const denseFilter = dense != null && filterToken == null && overrides?.[filterName] == null
126
+ const fill = tint ?? (denseFill ? theme.color(dense.fill, theme.scheme === "dark" ? dense.dark : dense.light) : theme.color(fillName))
127
+ const filterValue = denseFilter ? (theme.token(dense.filter) ?? dense.blur) : theme.token(filterName)
128
+ const filter = blur != null ? `blur(${blur}px)` : typeof filterValue === "string" ? filterValue : "blur(12px)"
92
129
  const module = web || Platform.OS !== "ios" ? null : blurModule()
93
130
  const opaque = reduceTransparency || (!web && module == null)
94
131
  if (web && !opaque) {
@@ -90,10 +90,14 @@ const WEIGHTS: Record<FontWeightName, TextStyle["fontWeight"]> =
90
90
  Platform.OS === "web"
91
91
  ? { regular: "400", medium: "510" as TextStyle["fontWeight"], semibold: "590" as TextStyle["fontWeight"], bold: "700" }
92
92
  : { regular: "400", medium: "500", semibold: "600", bold: "700" }
93
- // The web's system font (react-native-web's own stack, no family set): Chromium draws 501–549 of it as a synthesized bold,
94
- // heavier than 590, so Medium is 500 there; 590 is SF's own Semibold, as an iPhone draws it
93
+ // The web's system font (react-native-web's own stack, or a family that names the system's: -apple-system, system-ui):
94
+ // a browser has only its 500 and 600 there and draws 510 and 590 as a synthesized bold (Chromium, Safari on an iPhone:
95
+ // 590 heavier than 700), so Medium is 500 and Semibold 600
95
96
  const SYSTEM_WEIGHTS: Record<FontWeightName, TextStyle["fontWeight"]> =
96
- Platform.OS === "web" ? { ...WEIGHTS, medium: "500" } : WEIGHTS
97
+ Platform.OS === "web" ? { ...WEIGHTS, medium: "500", semibold: "600" } : WEIGHTS
98
+
99
+ /** Whether a font family starts with the system's face (`-apple-system, system-ui, sans-serif`), not an app's own. */
100
+ const isSystemFamily = (family: string) => /^\s*["']?(-apple-system|system-ui|BlinkMacSystemFont|ui-sans-serif|SF Pro|sans-serif)\b/i.test(family)
97
101
 
98
102
  /** The platform a ThemeProvider draws by default. */
99
103
  export function defaultPlatform(): PlatformStyle {
@@ -148,11 +152,11 @@ function warnUnresolvedColors(brand: BrandTheme | undefined, resolver: TokenReso
148
152
 
149
153
  function fontFor(fonts: FontFamilies | undefined, weight: FontWeightName) {
150
154
  const sans = fonts?.sans
151
- if (typeof sans === "string") return { fontFamily: sans, fontWeight: WEIGHTS[weight] }
155
+ if (typeof sans === "string") return { fontFamily: sans, fontWeight: (isSystemFamily(sans) ? SYSTEM_WEIGHTS : WEIGHTS)[weight] }
152
156
  const family = sans?.[weight] ?? (weight === "semibold" ? sans?.bold : undefined) ?? sans?.regular
153
157
  // A family per weight carries its weight: a weight on top would be synthesized on Android
154
158
  if (family && sans?.[weight]) return { fontFamily: family }
155
- return family ? { fontFamily: family, fontWeight: WEIGHTS[weight] } : { fontWeight: SYSTEM_WEIGHTS[weight] }
159
+ return family ? { fontFamily: family, fontWeight: (isSystemFamily(family) ? SYSTEM_WEIGHTS : WEIGHTS)[weight] } : { fontWeight: SYSTEM_WEIGHTS[weight] }
156
160
  }
157
161
 
158
162
  /** Builds a theme for a scheme and a platform (ThemeProvider does it for its children). */
@@ -319,6 +323,11 @@ function defaultTheme(): Theme {
319
323
  }
320
324
 
321
325
  /** The theme of the nearest ThemeProvider (the light default of the device's platform without one). */
326
+ /** The tokens the brands of the providers around set (internal: a default that must yield to a brand's own). */
327
+ export function useThemeOverrides(): Readonly<Record<string, string>> | undefined {
328
+ return useContext(ThemeSettingsContext)?.overrides
329
+ }
330
+
322
331
  export function useTheme(): Theme {
323
332
  return useContext(ThemeContext) ?? defaultTheme()
324
333
  }