Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

mobileThemeVariables.ts

41 lines1.4 KB

1import defaultThemeVariables from "../../generated-uniwind-default-theme-variables.json";
2import {
3 DEFAULT_MOBILE_THEME_ID,
4 getMobileThemeVariables,
5 themeColorWithAlpha,
6 type MobileThemeAppearance,
7 type MobileThemeId,
8 type MobileThemeVariables,
9} from "./mobileTheme";
10​
11const defaults = defaultThemeVariables as Readonly<
12 Record<MobileThemeAppearance, MobileThemeVariables>
13>;
14​
15/**
16 * Complete palette for native and third-party APIs that cannot consume a
17 * Uniwind className. The standard palette is generated from global.css; custom
18 * palettes share the same source that generates their registered CSS themes.
19 */
20export function getMobileThemeRuntimeVariables(
21 themeId: MobileThemeId,
22 appearance: MobileThemeAppearance,
23 platform: string,
24): MobileThemeVariables {
25 const usesDefaultPalette = themeId === DEFAULT_MOBILE_THEME_ID || themeId === "material-you";
26 const variables = usesDefaultPalette
27 ? defaults[appearance]
28 : getMobileThemeVariables(themeId, appearance);
29 if (platform !== "android") return variables;
30​
31 // Rounded panes share one opaque frame. The default dark drawer matches the
32 // settings body, so use its card tone to keep the rounded edge visible.
33 // System colors replace this with their own surfaceContainerHigh afterwards.
34 return {
35 ...variables,
36 "--color-header": themeColorWithAlpha(
37 variables[usesDefaultPalette ? "--color-card" : "--color-drawer"],
38 1,
39 ),
40 };