ComposableField

open class ComposableField(label: String, initialValue: ComposableFieldValue, val choices: List<ComposableFieldValue> = ComposableFieldValue.DefaultChoices) : ImmutablePreviewLabField<@Composable () -> Unit>

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

label

The display label for this field

initialValue

The initial ComposableFieldValue to display

choices

List of available ComposableFieldValue options to choose from

Constructors

Link copied to clipboard
constructor(label: String, initialValue: ComposableFieldValue, choices: List<ComposableFieldValue> = ComposableFieldValue.DefaultChoices)

Properties

Link copied to clipboard
Link copied to clipboard
open override val coroutineScope: CoroutineScope
Link copied to clipboard
open override val initialValue: @Composable () -> Unit

Default value for this field.

Link copied to clipboard
open override val label: String

The label for this field. This is not used in any of the program logic, but only for display purposes, so it is best to set it in a language that is easy for your team members to read.

Link copied to clipboard
open override var value: @Composable () -> Unit

Current value of this PreviewLabField.

Link copied to clipboard
open override val valueFlow: Flow<@Composable () -> Unit>

Functions

Link copied to clipboard
open override fun Content()

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.

Link copied to clipboard
fun <Value> PreviewLabField<Value>.DefaultFieldView(modifier: Modifier = Modifier, menuItems: List<PreviewLabField.ViewMenuItem<Value>> = ViewMenuItem.defaults<Value>(this), content: @Composable () -> Unit = { Content() })

Default UI implementation of me.tbsten.compose.preview.lab.PreviewLabField.View. Display a label and draw the content below it.

Link copied to clipboard
fun <Value> PreviewLabField<Value>.FieldLabelHeader(menuItems: List<PreviewLabField.ViewMenuItem<Value>> = ViewMenuItem.defaults<Value>(this))

Display the label of PreviewLabField.

Link copied to clipboard
fun <Value : Any> PreviewLabField<Value>.nullable(initialValue: Value? = this.initialValue): NullableField<Value>

Create a PreviewLabField that makes the receiver's PreviewLabField nullable.

Link copied to clipboard
open fun onCleared()
Link copied to clipboard
open fun serializer(): KSerializer<@Composable () -> Unit>?

Returns a KSerializer for this field's value type, or null if serialization is not supported.

Link copied to clipboard
open override fun testValues(): List<@Composable () -> Unit>

Returns a list of representative values for this field to be used in automated testing.

Link copied to clipboard
open fun valueCode(): String

Returns a Kotlin code string representing the current value of this field.

Link copied to clipboard

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.

Link copied to clipboard