ComposableField
A field that allows selecting from predefined Composable content options.
Usage
// Basic usage with default choices
@Preview
@Composable
fun ContentPreview() = PreviewLab {
val content: @Composable () -> Unit = fieldValue {
ComposableField(
label = "Content",
initialValue = ComposableFieldValue.Red32X32
)
}
MyContainer(content = content)
}
// With custom choices
@Preview
@Composable
fun IconSlotPreview() = PreviewLab {
val icon: @Composable () -> Unit = fieldValue {
ComposableField(
label = "Icon",
initialValue = ComposableFieldValue.Empty,
choices = listOf(
ComposableFieldValue.Empty,
ComposableFieldValue("Home Icon") { Icon(Icons.Default.Home, null) },
ComposableFieldValue("Search Icon") { Icon(Icons.Default.Search, null) }
)
)
}
MyButton(icon = icon)
}
// With text content options
@Preview
@Composable
fun HeaderPreview() = PreviewLab {
val header: @Composable () -> Unit = fieldValue {
ComposableField(
label = "Header",
initialValue = ComposableFieldValue.HeadingText,
choices = listOf(
ComposableFieldValue.HeadingText,
ComposableFieldValue.SimpleText,
ComposableFieldValue.LongText
)
)
}
MyCard(header = header)
}Parameters
The display label for this field
The initial ComposableFieldValue to display
List of available ComposableFieldValue options to choose from
Constructors
Properties
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.
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.