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.Hyphens
27 import androidx.compose.ui.text.style.TextAlign
28 import androidx.compose.ui.text.style.TextOverflow
29 import com.android.compose.theme.LocalAndroidColorScheme
30
31 /**
32 * The headline for a screen. E.g. "Create a passkey for X", "Choose a saved sign-in for X".
33 *
34 * Centered horizontally; headline-small typography; on-surface color.
35 */
36 @Composable
HeadlineTextnull37 fun HeadlineText(text: String, modifier: Modifier = Modifier) {
38 Text(
39 modifier = modifier.wrapContentSize(),
40 text = text,
41 color = LocalAndroidColorScheme.current.onSurface,
42 textAlign = TextAlign.Center,
43 style = MaterialTheme.typography.headlineSmall.copy(hyphens = Hyphens.Auto),
44 )
45 }
46
47 /**
48 * Body-medium typography; on-surface-variant color.
49 */
50 @Composable
BodyMediumTextnull51 fun BodyMediumText(text: String, modifier: Modifier = Modifier) {
52 Text(
53 modifier = modifier.wrapContentSize(),
54 text = text,
55 color = LocalAndroidColorScheme.current.onSurfaceVariant,
56 style = MaterialTheme.typography.bodyMedium.copy(hyphens = Hyphens.Auto),
57 )
58 }
59
60 /**
61 * Body-small typography; on-surface-variant color.
62 */
63 @Composable
BodySmallTextnull64 fun BodySmallText(
65 text: String,
66 modifier: Modifier = Modifier,
67 enforceOneLine: Boolean = false,
68 onTextLayout: (TextLayoutResult) -> Unit = {},
69 ) {
70 Text(
71 modifier = modifier.wrapContentSize(),
72 text = text,
73 color = LocalAndroidColorScheme.current.onSurfaceVariant,
74 style = MaterialTheme.typography.bodySmall.copy(hyphens = Hyphens.Auto),
75 overflow = TextOverflow.Ellipsis,
76 maxLines = if (enforceOneLine) 1 else Int.MAX_VALUE,
77 onTextLayout = onTextLayout,
78 )
79 }
80
81 /**
82 * Title-large typography; on-surface color.
83 */
84 @Composable
LargeTitleTextnull85 fun LargeTitleText(text: String, modifier: Modifier = Modifier) {
86 Text(
87 modifier = modifier.wrapContentSize(),
88 text = text,
89 color = LocalAndroidColorScheme.current.onSurface,
90 style = MaterialTheme.typography.titleLarge.copy(hyphens = Hyphens.Auto),
91 )
92 }
93
94 /**
95 * Title-small typography; on-surface color.
96 */
97 @Composable
SmallTitleTextnull98 fun SmallTitleText(
99 text: String,
100 modifier: Modifier = Modifier,
101 enforceOneLine: Boolean = false,
102 onTextLayout: (TextLayoutResult) -> Unit = {},
103 ) {
104 Text(
105 modifier = modifier.wrapContentSize(),
106 text = text,
107 color = LocalAndroidColorScheme.current.onSurface,
108 style = MaterialTheme.typography.titleSmall.copy(hyphens = Hyphens.Auto),
109 overflow = TextOverflow.Ellipsis,
110 maxLines = if (enforceOneLine) 1 else Int.MAX_VALUE,
111 onTextLayout = onTextLayout,
112 )
113 }
114
115 /**
116 * Title-small typography.
117 */
118 @Composable
SectionHeaderTextnull119 fun SectionHeaderText(text: String, modifier: Modifier = Modifier, color: Color) {
120 Text(
121 modifier = modifier.wrapContentSize(),
122 text = text,
123 color = color,
124 style = MaterialTheme.typography.titleSmall.copy(hyphens = Hyphens.Auto),
125 )
126 }
127
128 /**
129 * Body-medium typography; inverse-on-surface color.
130 */
131 @Composable
SnackbarContentTextnull132 fun SnackbarContentText(text: String, modifier: Modifier = Modifier) {
133 Text(
134 modifier = modifier.wrapContentSize(),
135 text = text,
136 color = MaterialTheme.colorScheme.inverseOnSurface,
137 style = MaterialTheme.typography.bodyMedium.copy(hyphens = Hyphens.Auto),
138 )
139 }
140
141 /**
142 * Label-large typography; inverse-primary color.
143 */
144 @Composable
SnackbarActionTextnull145 fun SnackbarActionText(text: String, modifier: Modifier = Modifier) {
146 Text(
147 modifier = modifier.wrapContentSize(),
148 text = text,
149 color = MaterialTheme.colorScheme.inversePrimary,
150 style = MaterialTheme.typography.labelLarge.copy(hyphens = Hyphens.Auto),
151 )
152 }
153
154 /**
155 * Label-large typography; on-surface-variant color; centered.
156 */
157 @Composable
LargeLabelTextOnSurfaceVariantnull158 fun LargeLabelTextOnSurfaceVariant(text: String, modifier: Modifier = Modifier) {
159 Text(
160 modifier = modifier.wrapContentSize(),
161 text = text,
162 textAlign = TextAlign.Center,
163 color = LocalAndroidColorScheme.current.onSurfaceVariant,
164 style = MaterialTheme.typography.labelLarge.copy(hyphens = Hyphens.Auto),
165 )
166 }
167
168 /**
169 * Label-large typography; color following parent spec; centered.
170 */
171 @Composable
LargeLabelTextnull172 fun LargeLabelText(text: String, modifier: Modifier = Modifier) {
173 Text(
174 modifier = modifier.wrapContentSize(),
175 text = text,
176 textAlign = TextAlign.Center,
177 style = MaterialTheme.typography.labelLarge.copy(hyphens = Hyphens.Auto),
178 )
179 }