withHint
fun <Value> MutablePreviewLabField<Value>.withHint(vararg choices: Pair<String, Value>): MutablePreviewLabField<Value>
Adds hint choices to a MutablePreviewLabField, allowing users to quickly select from predefined values.
Usage
// Adding hints to number fields (like font sizes)
@Preview
@Composable
fun TextPreview() = PreviewLab {
val fontSize: Int = fieldValue {
IntField(label = "Font Size", initialValue = 16)
.withHint(
"Small" to 12,
"Medium" to 16,
"Large" to 20,
"XLarge" to 24
)
}
Text("Sample Text", fontSize = fontSize.sp)
}
// Adding hints to string fields (like common usernames or URLs)
@Preview
@Composable
fun ProfilePreview() = PreviewLab {
val username: String = fieldValue {
StringField(label = "Username", initialValue = "")
.withHint(
"Alice" to "alice_wonder",
"Bob" to "bob_builder",
"Charlie" to "charlie_choco"
)
}
ProfileCard(username = username)
}
// Combining withHint with other field modifiers
@Preview
@Composable
fun ApiUrlPreview() = PreviewLab {
val apiUrl: String = fieldValue {
StringField(label = "API URL", initialValue = "https://api.example.com")
.withHint(
"Production" to "https://api.example.com",
"Staging" to "https://staging.api.example.com",
"Development" to "https://dev.api.example.com",
"Local" to "http://localhost:3000"
)
}
ApiClient(baseUrl = apiUrl)
}Content copied to clipboard
Return
A WithHintField wrapper that displays the base field with hint choices
Parameters
choices
Vararg of pairs where first is the hint label and second is the value