1 /*
2 * Copyright (C) 2024 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.components
18
19 import androidx.compose.foundation.layout.padding
20 import androidx.compose.foundation.layout.wrapContentSize
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 androidx.compose.ui.unit.dp
29 import androidx.wear.compose.material.MaterialTheme as WearMaterialTheme
30
31 @Composable
WearTitleTextnull32 fun WearTitleText(text: String, modifier: Modifier = Modifier) {
33 Text(
34 modifier = modifier.wrapContentSize(),
35 text = text,
36 color = WearMaterialTheme.colors.onSurface,
37 textAlign = TextAlign.Center,
38 style = WearMaterialTheme.typography.title3,
39 )
40 }
41
42 @Composable
WearDisplayNameTextnull43 fun WearDisplayNameText(text: String, modifier: Modifier = Modifier) {
44 Text(
45 modifier = modifier.wrapContentSize(),
46 text = text,
47 color = WearMaterialTheme.colors.onSurfaceVariant,
48 textAlign = TextAlign.Center,
49 overflow = TextOverflow.Ellipsis,
50 maxLines = 2,
51 style = WearMaterialTheme.typography.title2,
52 )
53 }
54
55 @Composable
WearUsernameTextnull56 fun WearUsernameText(
57 text: String,
58 textAlign: TextAlign = TextAlign.Center,
59 modifier: Modifier = Modifier,
60 onTextLayout: (TextLayoutResult) -> Unit = {},
61 ) {
62 Text(
63 modifier = modifier.padding(start = 8.dp, end = 8.dp).wrapContentSize(),
64 text = text,
65 color = WearMaterialTheme.colors.onSurfaceVariant,
66 style = WearMaterialTheme.typography.caption1,
67 overflow = TextOverflow.Ellipsis,
68 textAlign = textAlign,
69 maxLines = 2,
70 onTextLayout = onTextLayout,
71 )
72 }
73
74 // used for primary label in button
75 @Composable
WearButtonTextnull76 fun WearButtonText(
77 text: String,
78 textAlign: TextAlign,
79 maxLines: Int = 1,
80 modifier: Modifier = Modifier,
81 color: Color = WearMaterialTheme.colors.onSurface,
82 onTextLayout: (TextLayoutResult) -> Unit = {},
83 ) {
84 Text(
85 modifier = modifier.wrapContentSize(),
86 text = text,
87 color = color,
88 style = WearMaterialTheme.typography.button,
89 overflow = TextOverflow.Ellipsis,
90 textAlign = textAlign,
91 maxLines = maxLines,
92 onTextLayout = onTextLayout,
93 )
94 }
95
96 @Composable
WearSecondaryLabelnull97 fun WearSecondaryLabel(
98 text: String,
99 modifier: Modifier = Modifier,
100 onTextLayout: (TextLayoutResult) -> Unit = {},
101 ) {
102 Text(
103 modifier = modifier.wrapContentSize(),
104 text = text,
105 color = WearMaterialTheme.colors.onSurfaceVariant,
106 style = WearMaterialTheme.typography.caption1,
107 overflow = TextOverflow.Ellipsis,
108 textAlign = TextAlign.Start,
109 maxLines = 1,
110 onTextLayout = onTextLayout,
111 )
112 }
113