|
| 1 | +/* |
| 2 | + * Copyright 2025 Google Inc. All Rights Reserved. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
| 5 | + * in compliance with the License. You may obtain a copy of the License at |
| 6 | + * |
| 7 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | + * |
| 9 | + * Unless required by applicable law or agreed to in writing, software distributed under the |
| 10 | + * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either |
| 11 | + * express or implied. See the License for the specific language governing permissions and |
| 12 | + * limitations under the License. |
| 13 | + */ |
| 14 | + |
| 15 | +package com.firebase.ui.auth.compose.configuration.theme |
| 16 | + |
| 17 | +import androidx.compose.foundation.shape.RoundedCornerShape |
| 18 | +import androidx.compose.material3.ColorScheme |
| 19 | +import androidx.compose.material3.MaterialTheme |
| 20 | +import androidx.compose.material3.Shapes |
| 21 | +import androidx.compose.material3.Typography |
| 22 | +import androidx.compose.material3.lightColorScheme |
| 23 | +import androidx.compose.runtime.Composable |
| 24 | +import androidx.compose.ui.graphics.Color |
| 25 | +import androidx.compose.ui.graphics.Shape |
| 26 | +import androidx.compose.ui.unit.Dp |
| 27 | +import androidx.compose.ui.unit.dp |
| 28 | + |
| 29 | +/** |
| 30 | + * Theming configuration for the entire Auth UI. |
| 31 | + */ |
| 32 | +class AuthUITheme( |
| 33 | + /** |
| 34 | + * The color scheme to use. |
| 35 | + */ |
| 36 | + val colorScheme: ColorScheme, |
| 37 | + |
| 38 | + /** |
| 39 | + * The typography to use. |
| 40 | + */ |
| 41 | + val typography: Typography, |
| 42 | + |
| 43 | + /** |
| 44 | + * The shapes to use for UI elements. |
| 45 | + */ |
| 46 | + val shapes: Shapes, |
| 47 | + |
| 48 | + /** |
| 49 | + * A map of provider IDs to custom styling. |
| 50 | + */ |
| 51 | + val providerStyles: Map<String, ProviderStyle> = emptyMap() |
| 52 | +) { |
| 53 | + |
| 54 | + /** |
| 55 | + * A class nested within AuthUITheme that defines the visual appearance of a specific |
| 56 | + * provider button, allowing for per-provider branding and customization. |
| 57 | + */ |
| 58 | + class ProviderStyle( |
| 59 | + /** |
| 60 | + * The background color of the button. |
| 61 | + */ |
| 62 | + val backgroundColor: Color, |
| 63 | + |
| 64 | + /** |
| 65 | + * The color of the text label on the button. |
| 66 | + */ |
| 67 | + val contentColor: Color, |
| 68 | + |
| 69 | + /** |
| 70 | + * An optional tint color for the provider's icon. If null, |
| 71 | + * the icon's intrinsic color is used. |
| 72 | + */ |
| 73 | + var iconTint: Color? = null, |
| 74 | + |
| 75 | + /** |
| 76 | + * The shape of the button container. Defaults to RoundedCornerShape(4.dp). |
| 77 | + */ |
| 78 | + val shape: Shape = RoundedCornerShape(4.dp), |
| 79 | + |
| 80 | + /** |
| 81 | + * The shadow elevation for the button. Defaults to 2.dp. |
| 82 | + */ |
| 83 | + val elevation: Dp = 2.dp |
| 84 | + ) |
| 85 | + |
| 86 | + companion object { |
| 87 | + /** |
| 88 | + * A standard light theme with Material 3 defaults and |
| 89 | + * pre-configured provider styles. |
| 90 | + */ |
| 91 | + val Default = AuthUITheme( |
| 92 | + colorScheme = lightColorScheme( |
| 93 | + primary = Color(0xFFFFA611) |
| 94 | + ), |
| 95 | + typography = Typography(), |
| 96 | + shapes = Shapes(), |
| 97 | + providerStyles = ProviderStyleDefaults.default |
| 98 | + ) |
| 99 | + |
| 100 | + /** |
| 101 | + * Creates a theme inheriting the app's current Material |
| 102 | + * Theme settings. |
| 103 | + */ |
| 104 | + @Composable |
| 105 | + fun fromMaterialTheme( |
| 106 | + providerStyles: Map<String, ProviderStyle> = ProviderStyleDefaults.default |
| 107 | + ): AuthUITheme { |
| 108 | + return AuthUITheme( |
| 109 | + colorScheme = MaterialTheme.colorScheme, |
| 110 | + typography = MaterialTheme.typography, |
| 111 | + shapes = MaterialTheme.shapes, |
| 112 | + providerStyles = providerStyles |
| 113 | + ) |
| 114 | + } |
| 115 | + |
| 116 | + } |
| 117 | +} |
| 118 | + |
| 119 | +@Composable |
| 120 | +fun AuthUITheme( |
| 121 | + theme: AuthUITheme = AuthUITheme.Default, |
| 122 | + content: @Composable () -> Unit |
| 123 | +) { |
| 124 | + MaterialTheme( |
| 125 | + colorScheme = theme.colorScheme, |
| 126 | + typography = theme.typography, |
| 127 | + shapes = theme.shapes, |
| 128 | + content = content |
| 129 | + ) |
| 130 | +} |
0 commit comments