-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #112 from Automattic/hamorillo/gravatar-theme
`gravatar-ui` - Implement GravatarTheme
- Loading branch information
Showing
5 changed files
with
150 additions
and
78 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
gravatar-ui/src/main/java/com/gravatar/ui/GravatarTheme.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.gravatar.ui | ||
|
||
import androidx.compose.material3.ColorScheme | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.Shapes | ||
import androidx.compose.material3.Typography | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.ProvidableCompositionLocal | ||
import androidx.compose.runtime.staticCompositionLocalOf | ||
|
||
/** | ||
* [GravatarTheme] is a composable that wraps the content of the application with the Gravatar theme. | ||
*/ | ||
@Composable | ||
public fun GravatarTheme(content: @Composable () -> Unit) { | ||
MaterialTheme( | ||
colorScheme = gravatarTheme.colorScheme, | ||
typography = gravatarTheme.typography, | ||
shapes = gravatarTheme.shapes, | ||
) { | ||
content() | ||
} | ||
} | ||
|
||
/** | ||
* [GravatarTheme] contains the colors, typography, and shapes to be used in the Gravatar UI components. | ||
* Those values follow the Gravatar style guide but can be customized by the user. | ||
* In order to customize the theme, the user can provide a custom [GravatarTheme] using [Composition Local](https://developer.android.com/develop/ui/compose/compositionlocal) | ||
* | ||
* [colorScheme] The color scheme to be used in the Gravatar UI components | ||
* [typography] The typography to be used in the Gravatar UI components | ||
* [shapes] The shapes to be used in the Gravatar UI components | ||
*/ | ||
public interface GravatarTheme { | ||
public val colorScheme: ColorScheme | ||
@Composable | ||
get() = MaterialTheme.colorScheme | ||
|
||
public val typography: Typography | ||
@Composable | ||
get() = MaterialTheme.typography | ||
|
||
public val shapes: Shapes | ||
@Composable | ||
get() = MaterialTheme.shapes | ||
} | ||
|
||
/** | ||
* [LocalGravatarTheme] is a CompositionLocal that provides the current [GravatarTheme]. | ||
*/ | ||
public val LocalGravatarTheme: ProvidableCompositionLocal<GravatarTheme> = | ||
staticCompositionLocalOf { object : GravatarTheme {} } | ||
|
||
/** The current [GravatarTheme]. */ | ||
public val gravatarTheme: GravatarTheme | ||
@Composable | ||
get() = LocalGravatarTheme.current |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters