CombinedField

open class CombinedField<Base, Value>(label: String, fields: List<MutablePreviewLabField<out Base>>, combine: (List<Base>) -> Value, split: (Value) -> List<Base>) : MutablePreviewLabField<Value>

A field that combines multiple sub-fields into a single composite value.

CombinedField allows creating complex field types by combining simpler field types. For example, combining multiple number fields to create a coordinate field, or combining color and size fields to create a styled element field.

Usage

// Custom data class with multiple fields
data class Padding(val horizontal: Dp, val vertical: Dp)

@Preview
@Composable
fun CustomFieldPreview() = PreviewLab {
val padding: Padding = fieldValue {
CombinedField(
label = "Padding",
fields = listOf(
DpField("Horizontal", 16.dp),
DpField("Vertical", 8.dp)
),
combine = { values -> Padding(values[0] as Dp, values[1] as Dp) },
split = { listOf(it.horizontal, it.vertical) }
)
}

Box(
modifier = Modifier
.background(Color.LightGray)
.padding(horizontal = padding.horizontal, vertical = padding.vertical)
) {
Text("Content with custom padding")
}
}

Parameters

Base

The base type of the individual sub-fields

Value

The composite value type created by combining the sub-fields

label

The display label for this combined field

fields

The list of sub-fields to combine

combine

Function to combine values from sub-fields into the composite value

split

Function to split a composite value back into individual sub-field values

Inheritors

Constructors

Link copied to clipboard
constructor(label: String, fields: List<MutablePreviewLabField<out Base>>, combine: (List<Base>) -> Value, split: (Value) -> List<Base>)

Properties

Link copied to clipboard
open override val coroutineScope: CoroutineScope
Link copied to clipboard
open override val initialValue: Value

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: Value

Current value of this PreviewLabField.

Link copied to clipboard
open override val valueFlow: Flow<Value>

Functions

Link copied to clipboard
open operator override fun component1(): Value
Link copied to clipboard
open operator override fun component2(): (Value) -> Unit
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<Value>?

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<Value>

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

Link copied to clipboard
fun <Value> MutablePreviewLabField<Value>.TextFieldContent(toString: (Value) -> String, toValue: (String) -> Result<Value>, modifier: Modifier = Modifier, prefix: @Composable () -> Unit? = null, suffix: @Composable () -> Unit? = null, placeholder: @Composable () -> Unit? = null)

Helper for UI of Fields that can be input with TextField.

Link copied to clipboard

Transforms a MutablePreviewLabField to work with a different value type.

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

Adds hint choices to a MutablePreviewLabField, allowing users to quickly select from predefined values.

Link copied to clipboard
fun MutablePreviewLabField<String>.withImageUrlHint(includeDummyImages: Boolean = true, includeInvalidImages: Boolean = true): MutablePreviewLabField<String>
Link copied to clipboard

Adds predefined color hints to a Color field for quick selection.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
fun <Value> MutablePreviewLabField<Value>.wrap(wrapRange: WrapRange = WrapRange.OnlyContent, content: @Composable (@Composable () -> Unit) -> Unit): WrapField<Value>

Wraps this field with additional composable content.