WithHintField
A field wrapper that adds hint choices below the base field. Users can click on hint chips to quickly apply predefined values.
Usage
// Adding hints to number fields (like font sizes)
@Preview
@Composable
fun FontSizePreview() = PreviewLab {
val lineHeight: Int = fieldValue {
IntField(label = "Line Height", initialValue = 24)
.withHint(
"Compact" to 18,
"Normal" to 24,
"Relaxed" to 32
)
}
Text("Multi-line text example", lineHeight = lineHeight.sp)
}
// Adding hints to string fields (like common usernames or URLs)
@Preview
@Composable
fun EmailPreview() = PreviewLab {
val email: String = fieldValue {
StringField(label = "Email", initialValue = "user@example.com")
.withHint(
"Personal" to "john.doe@gmail.com",
"Work" to "john@company.com",
"Test" to "test@example.com"
)
}
EmailDisplay(email = email)
}
// Combining withHint with other field modifiers
@Preview
@Composable
fun PaddingPreview() = PreviewLab {
val padding: Int = fieldValue {
IntField(label = "Padding", initialValue = 16)
.withHint(
"None" to 0,
"Small" to 8,
"Medium" to 16,
"Large" to 24,
"XLarge" to 32
)
}
Box(Modifier.padding(padding.dp)) {
Text("Content with padding")
}
}Parameters
The type of value managed by the field
The underlying field to wrap with hints
Map of hint labels to their corresponding values
Functions
Composable, which displays the main UI for this Field. If you want to customize the UI, you can override this method in your PreviewLabField to customize the UI.
Default UI implementation of me.tbsten.compose.preview.lab.PreviewLabField.View. Display a label and draw the content below it.
Display the label of PreviewLabField.
Create a PreviewLabField that makes the receiver's PreviewLabField nullable.
Returns a KSerializer for this field's value type, or null if serialization is not supported.
Returns a list of representative values for this field to be used in automated testing.
Helper for UI of Fields that can be input with TextField.
Transforms a MutablePreviewLabField to work with a different value type.
Composable, which displays the entire UI for this Field. If you want to customize the UI, you can override this method in your PreviewLabField to customize the UI. However, in many cases where the UI is customized, overriding the content method is more appropriate.
Adds hint choices to a MutablePreviewLabField, allowing users to quickly select from predefined values.
Adds predefined color hints to a Color field for quick selection.
Wraps this field with a custom me.tbsten.compose.preview.lab.PreviewLabField.serializer implementation.
Wraps this field with a custom me.tbsten.compose.preview.lab.PreviewLabField.valueCode implementation.
Wraps this field with additional composable content.