withHint
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)
}Return
A WithHintField wrapper that displays the base field with hint choices
Parameters
Vararg of pairs where first is the hint label and second is the value
Adds hint choices to a MutablePreviewLabField from a Map.
This is a convenience overload that accepts a Map instead of vararg pairs.
Usage
val sizeHints = mapOf("Small" to 12, "Medium" to 16, "Large" to 20)
@Preview
@Composable
fun TextPreview() = PreviewLab {
val fontSize: Int = fieldValue {
IntField(label = "Font Size", initialValue = 16)
.withHint(sizeHints)
}
Text("Sample Text", fontSize = fontSize.sp)
}Return
A WithHintField wrapper that displays the base field with hint choices
Parameters
Map of hint labels to their corresponding values
Adds a single action hint to a MutablePreviewLabField.
This is a convenience overload for adding a single action hint with trailing lambda syntax.
Usage
@Preview
@Composable
fun TextPreview() = PreviewLab {
val text: String = fieldValue {
StringField(label = "Text", initialValue = "hello")
.withHint("Uppercase") { value = value.uppercase() }
.withHint("Clear") { value = "" }
}
Text(text)
}Return
A WithHintField wrapper that displays the base field with the action hint
Parameters
The label to display for this hint
The action to execute when this hint is selected