PeachTheme.kt

3.4 KB · raw

1package com.peachpasswords.ui.theme23import androidx.compose.material3.MaterialTheme4import androidx.compose.material3.darkColorScheme5import androidx.compose.material3.lightColorScheme6import androidx.compose.runtime.Composable7import androidx.compose.runtime.CompositionLocalProvider8import androidx.compose.runtime.compositionLocalOf9import androidx.compose.runtime.staticCompositionLocalOf10import androidx.compose.ui.graphics.Color11import androidx.compose.ui.text.TextStyle12import androidx.compose.ui.text.font.FontStyle13import androidx.compose.ui.text.font.FontWeight14import androidx.compose.ui.unit.sp1516/** Current accent color, available to any composable under [PeachTheme]. */17val LocalPeachAccent = compositionLocalOf { DEFAULT_ACCENT }1819/** When true, decorative/long-running animations should be skipped or shortened. */20val LocalReduceMotion = staticCompositionLocalOf { false }2122/** True when the active scheme is dark — some surfaces tune themselves off this. */23val LocalPeachDark = staticCompositionLocalOf { true }2425@Composable26fun PeachTheme(27    darkTheme: Boolean = true,28    accent: Color = DEFAULT_ACCENT,29    reduceMotion: Boolean = false,30    content: @Composable () -> Unit,31) {32    val colors = if (darkTheme) {33        darkColorScheme(34            primary = accent,35            onPrimary = PeachColors.Bg,36            secondary = PeachColors.SyncBusy,37            onSecondary = PeachColors.Bg,38            background = PeachColors.Bg,39            onBackground = PeachColors.T0,40            surface = PeachColors.S1,41            onSurface = PeachColors.T0,42            surfaceVariant = PeachColors.S2,43            onSurfaceVariant = PeachColors.T1,44            outline = PeachColors.T3,45            error = PeachColors.Breach,46            onError = PeachColors.Bg,47        )48    } else {49        lightColorScheme(50            primary = accent,51            onPrimary = PeachColorsLight.Bg,52            secondary = PeachColorsLight.TextLink,53            onSecondary = PeachColorsLight.Bg,54            background = PeachColorsLight.Bg,55            onBackground = PeachColorsLight.T0,56            surface = PeachColorsLight.S1,57            onSurface = PeachColorsLight.T0,58            surfaceVariant = PeachColorsLight.S2,59            onSurfaceVariant = PeachColorsLight.T1,60            outline = PeachColorsLight.BorderSubtle,61            error = PeachColorsLight.BreachText,62            onError = PeachColorsLight.Bg,63        )64    }6566    val typography = androidx.compose.material3.Typography(67        bodyLarge = TextStyle(68            fontFamily = PeachType.Body,69            fontSize = 16.sp,70            fontWeight = FontWeight.Normal,71        ),72        titleLarge = TextStyle(73            fontFamily = PeachType.Display,74            fontSize = 24.sp,75            fontStyle = FontStyle.Italic,76            fontWeight = FontWeight.Light,77        ),78        labelLarge = TextStyle(79            fontFamily = PeachType.Body,80            fontSize = 12.sp,81            fontWeight = FontWeight.Medium,82        ),83    )8485    val palette = if (darkTheme) peachDark(accent) else peachLight(accent)8687    CompositionLocalProvider(88        LocalPeachAccent provides accent,89        LocalReduceMotion provides reduceMotion,90        LocalPeachDark provides darkTheme,91        LocalPeachColors provides palette,92    ) {93        MaterialTheme(colorScheme = colors, typography = typography, content = content)94    }95}