commonMain.io.github.lyxnx.compose.pine.PineTheme.kt Maven / Gradle / Ivy
package io.github.lyxnx.compose.pine
import androidx.compose.foundation.LocalIndication
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material.ripple.rememberRipple
import androidx.compose.material3.LocalContentColor
import androidx.compose.material3.LocalTextStyle
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.ReadOnlyComposable
import androidx.compose.runtime.remember
/**
* The main Pine Theme object.
*
* From here, [colors][PineColors], [typography][PineTypography], [shadows][PineShadows], and [shapes][PineShapes] can be accessed.
*
* The colors will automatically update if dark mode is toggled
*/
public object PineTheme {
/**
* Pine theme colors
*/
public val colors: PineColors
@Composable
@ReadOnlyComposable
get() = LocalColors.current
/**
* Pine theme typography (text styles)
*/
public val typography: PineTypography
@Composable
@ReadOnlyComposable
get() = LocalTypography.current
/**
* Pine theme shadows
*/
public val shadows: PineShadows
@Composable
@ReadOnlyComposable
get() = LocalShadows.current
/**
* Pine theme shapes
*/
public val shapes: PineShapes
@Composable
@ReadOnlyComposable
get() = LocalShapes.current
}
/**
* The main entry point to the Pine theme
*
* Explicit values may be passed here if desired, or the standard Pine styles can be used.
*/
@Composable
public fun PineTheme(
isDarkTheme: Boolean = isSystemInDarkTheme(),
typography: PineTypography = PineTheme.typography,
shadows: PineShadows = PineTheme.shadows,
shapes: PineShapes = PineTheme.shapes,
content: @Composable () -> Unit
) {
val colors = remember(isDarkTheme) {
if (isDarkTheme) pineDarkColors() else pineLightColors()
}
PineTheme(
colors = colors,
typography = typography,
shadows = shadows,
shapes = shapes,
content = content
)
}
/**
* The main entry point to the Pine theme
*
* Explicit values may be passed here if desired, or the standard Pine styles can be used.
*
* [colors] must be given for this overload - use the all-optional overloaded PineTheme function for the standard Pine theme
*/
@Composable
public fun PineTheme(
colors: PineColors,
typography: PineTypography = PineTheme.typography,
shadows: PineShadows = PineTheme.shadows,
shapes: PineShapes = PineTheme.shapes,
content: @Composable () -> Unit
) {
/*
Override the M3 default text style
ProvideTextStyle does exactly this but we also want to provide content color too and ProvideContentColorTextStyle is
internal. Doing it like this is better than nesting CompositionLocal calls
*/
val mergedTextStyle = LocalTextStyle.current.merge(typography.bodyMedium)
val rippleIndication = rememberRipple()
CompositionLocalProvider(
LocalColors provides colors,
LocalTypography provides typography,
LocalShadows provides shadows,
LocalShapes provides shapes,
LocalContentColor provides colors.grey900,
LocalTextStyle provides mergedTextStyle,
LocalIndication provides rippleIndication,
content = content
)
}