1 /*
2  * Copyright (C) 2022 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.credentialmanager.common.ui
18 
19 import androidx.compose.foundation.layout.wrapContentSize
20 import androidx.compose.material3.MaterialTheme
21 import androidx.compose.material3.Text
22 import androidx.compose.runtime.Composable
23 import androidx.compose.ui.Modifier
24 import androidx.compose.ui.graphics.Color
25 import androidx.compose.ui.text.TextLayoutResult
26 import androidx.compose.ui.text.style.TextAlign
27 import androidx.compose.ui.text.style.TextOverflow
28 import com.android.credentialmanager.ui.theme.LocalAndroidColorScheme
29 
30 /**
31  * The headline for a screen. E.g. "Create a passkey for X", "Choose a saved sign-in for X".
32  *
33  * Centered horizontally; headline-small typography; on-surface color.
34  */
35 @Composable
36 fun HeadlineText(text: String, modifier: Modifier = Modifier) {
37     Text(
38         modifier = modifier.wrapContentSize(),
39         text = text,
40         color = LocalAndroidColorScheme.current.colorOnSurface,
41         textAlign = TextAlign.Center,
42         style = MaterialTheme.typography.headlineSmall,
43     )
44 }
45 
46 /**
47  * Body-medium typography; on-surface-variant color.
48  */
49 @Composable
50 fun BodyMediumText(text: String, modifier: Modifier = Modifier) {
51     Text(
52         modifier = modifier.wrapContentSize(),
53         text = text,
54         color = LocalAndroidColorScheme.current.colorOnSurfaceVariant,
55         style = MaterialTheme.typography.bodyMedium,
56     )
57 }
58 
59 /**
60  * Body-small typography; on-surface-variant color.
61  */
62 @Composable
63 fun BodySmallText(
64     text: String,
65     modifier: Modifier = Modifier,
66     enforceOneLine: Boolean = false,
67     onTextLayout: (TextLayoutResult) -> Unit = {},
68 ) {
69     Text(
70         modifier = modifier.wrapContentSize(),
71         text = text,
72         color = LocalAndroidColorScheme.current.colorOnSurfaceVariant,
73         style = MaterialTheme.typography.bodySmall,
74         overflow = TextOverflow.Ellipsis,
75         maxLines = if (enforceOneLine) 1 else Int.MAX_VALUE,
76         onTextLayout = onTextLayout,
77     )
78 }
79 
80 /**
81  * Title-large typography; on-surface color.
82  */
83 @Composable
84 fun LargeTitleText(text: String, modifier: Modifier = Modifier) {
85     Text(
86         modifier = modifier.wrapContentSize(),
87         text = text,
88         color = LocalAndroidColorScheme.current.colorOnSurface,
89         style = MaterialTheme.typography.titleLarge,
90     )
91 }
92 
93 /**
94  * Title-small typography; on-surface color.
95  */
96 @Composable
97 fun SmallTitleText(
98     text: String,
99     modifier: Modifier = Modifier,
100     enforceOneLine: Boolean = false,
101     onTextLayout: (TextLayoutResult) -> Unit = {},
102 ) {
103     Text(
104         modifier = modifier.wrapContentSize(),
105         text = text,
106         color = LocalAndroidColorScheme.current.colorOnSurface,
107         style = MaterialTheme.typography.titleSmall,
108         overflow = TextOverflow.Ellipsis,
109         maxLines = if (enforceOneLine) 1 else Int.MAX_VALUE,
110         onTextLayout = onTextLayout,
111     )
112 }
113 
114 /**
115  * Title-small typography.
116  */
117 @Composable
118 fun SectionHeaderText(text: String, modifier: Modifier = Modifier, color: Color) {
119     Text(
120         modifier = modifier.wrapContentSize(),
121         text = text,
122         color = color,
123         style = MaterialTheme.typography.titleSmall,
124     )
125 }
126 
127 /**
128  * Body-medium typography; inverse-on-surface color.
129  */
130 @Composable
131 fun SnackbarContentText(text: String, modifier: Modifier = Modifier) {
132     Text(
133         modifier = modifier.wrapContentSize(),
134         text = text,
135         color = MaterialTheme.colorScheme.inverseOnSurface,
136         style = MaterialTheme.typography.bodyMedium,
137     )
138 }
139 
140 /**
141  * Label-large typography; inverse-primary color.
142  */
143 @Composable
144 fun SnackbarActionText(text: String, modifier: Modifier = Modifier) {
145     Text(
146         modifier = modifier.wrapContentSize(),
147         text = text,
148         color = MaterialTheme.colorScheme.inversePrimary,
149         style = MaterialTheme.typography.labelLarge,
150     )
151 }
152 
153 /**
154  * Label-large typography; on-surface-variant color; centered.
155  */
156 @Composable
157 fun LargeLabelTextOnSurfaceVariant(text: String, modifier: Modifier = Modifier) {
158     Text(
159         modifier = modifier.wrapContentSize(),
160         text = text,
161         textAlign = TextAlign.Center,
162         color = LocalAndroidColorScheme.current.colorOnSurfaceVariant,
163         style = MaterialTheme.typography.labelLarge,
164     )
165 }
166 
167 /**
168  * Label-large typography; color following parent spec; centered.
169  */
170 @Composable
171 fun LargeLabelText(text: String, modifier: Modifier = Modifier) {
172     Text(
173         modifier = modifier.wrapContentSize(),
174         text = text,
175         textAlign = TextAlign.Center,
176         style = MaterialTheme.typography.labelLarge,
177     )
178 }