forked from microsoft/fluentui-android
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Label.kt
42 lines (40 loc) · 1.71 KB
/
Label.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package com.microsoft.fluentui.tokenized.controls
import androidx.compose.foundation.text.BasicText
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.TextStyle
import com.microsoft.fluentui.theme.FluentTheme
import com.microsoft.fluentui.theme.token.ControlTokens
import com.microsoft.fluentui.theme.token.FluentAliasTokens.TypographyTokens
import com.microsoft.fluentui.theme.token.controlTokens.ColorStyle
import com.microsoft.fluentui.theme.token.controlTokens.LabelInfo
import com.microsoft.fluentui.theme.token.controlTokens.LabelTokens
/**
* A standard UI label consisting of a simple text.
* @param text Label text
* @param textStyle Text styling for the text. Default [TypographyTokens.Display]
* @param colorStyle Color styling for the text. Default [ColorStyle.Primary]
* @param modifier Optional modifier for Label
* @param labelTokens Option tokens for label styling
*/
@Composable
fun Label(
text: String,
textStyle: TypographyTokens = TypographyTokens.Display,
colorStyle: ColorStyle = ColorStyle.Primary,
modifier: Modifier = Modifier,
labelTokens: LabelTokens? = null
) {
val themeID =
FluentTheme.themeID //Adding This only for recomposition in case of Token Updates. Unused otherwise.
val tokens = labelTokens
?: FluentTheme.controlTokens.tokens[ControlTokens.ControlType.LabelControlType] as LabelTokens
val labelInfo = LabelInfo(textStyle, colorStyle)
val textStyle = tokens.typography(labelInfo = labelInfo)
val textColor = tokens.textColor(labelInfo = labelInfo)
BasicText(
modifier = modifier,
text = text,
style = textStyle.merge(TextStyle(color = textColor))
)
}