Empty State
What a place shows while it has nothing to show: a list before its first item, a search that found nothing, a pane that waits for a document. It says what the place is for and what to do there, and gives the way to do it.
import com.pantrixui.components.container.emptystate.PantrixEmptyState
- Its parts. An
iconin a circle of the theme's neutral fill, atitle, adescriptionunder it in the callout's type, and anactionunder them all: the app's own button, which the app tags and whose press it hears. Only the title is needed. - Its place. It fills the width it is given and stands in the middle of it. In a wide room the title and the description run no wider than the style's
maxTextWidth, 360dp: a line that runs across a whole window is not read. - Platform. The circle is 64dp on Android and iOS, the icon 32dp and the room 24dp; on desktop and the web 48dp, 24dp and 16dp (
EmptyStateStyle). - Its own colours.
EmptyStateColorsgives the colours of the circle, the icon, the title and the description; what is not given stays the theme's. - Automation. With
tagKeythe empty state isEmptyState_<tagKey>; the action's button carries its own tag.
Examples
A list that is still empty
A list that has nothing yet: the icon says what the list holds, the title what is not there, and the description what will come there. A long description goes on to a second line at 360dp and stays centred.
PantrixEmptyState(
title = "Nothing opened yet",
description = "Paste a document or open a file; it is kept here, the last one opened first.",
icon = PantrixIcons.Folder,
tagKey = "recent"
)
A search that found nothing
A search that found nothing: the action takes the reader back to something to find. The button is the app's: the empty state puts it under the description, and the app gives its tag and hears its press. Here clearing the filter brings the orders back, and "Search again" shows the empty state again.
var query by rememberSaveable { mutableStateOf("red") }
if (query.isEmpty()) {
Column(verticalArrangement = Arrangement.spacedBy(8.dp)) {
listOf("Order 4821", "Order 4822", "Order 4823").forEach { order -> PantrixText(order) }
PantrixButton(
text = "Search again",
onClick = { query = "red" },
variant = ButtonVariant.Text,
tagKey = "search_again"
)
}
} else {
PantrixEmptyState(
title = "No orders match",
description = "\"$query\" is in no order. Try another word, or clear the filter.",
icon = PantrixIcons.Search,
action = {
PantrixButton(
text = "Clear the filter",
onClick = { query = "" },
variant = ButtonVariant.Outline,
tagKey = "clear_filter"
)
},
tagKey = "orders"
)
}
Inside a card, with its own style and colours
Inside a card, on the card's own fill: a smaller circle and less room (EmptyStateStyle), and the circle and the icon in the app's own colour (EmptyStateColors). The second card has a title alone: neither a circle nor a description is needed.
val own = ownColors()
PantrixCard(modifier = Modifier.fillMaxWidth(), variant = CardVariant.Filled) {
PantrixEmptyState(
title = "No notifications",
description = "Something new shows here when it comes.",
icon = PantrixIcons.Inbox,
style = EmptyStateStyle(iconContainerSize = 40.dp, iconSize = 20.dp, padding = 8.dp, iconGap = 8.dp),
colors = EmptyStateColors(iconContainer = own.container, icon = own.onContainer),
tagKey = "notifications"
)
}
PantrixCard(modifier = Modifier.fillMaxWidth(), variant = CardVariant.Filled) {
PantrixEmptyState(
title = "No messages",
colors = EmptyStateColors(title = PantrixTheme.colors.textSecondary),
tagKey = "messages"
)
}
API
title
What a place shows while it has nothing to show: a list before its first item, a search that found nothing, a pane that waits for a document. It says what the place is for and what to do there, and gives the way to do it.
| Parameter | Type | Default | What it is |
|---|---|---|---|
title | String | what the place has none of, or what it waits for: Nothing opened yet. | |
modifier | Modifier | Modifier | the empty state's modifier. It fills the width it is given. |
description | String? | null | what to do there, in a line or two, or null for the title alone. |
icon | ImageVector? | null | what the place holds when it is not empty, drawn in a circle over the title, or null for none. |
action | (@Composable () -> Unit)? | null | what is done about it, under the words: the app's own button, PantrixButton, which is tagged by the app. Null for none. |
style | EmptyStateStyle? | null | this call's own style: over every enclosing one and under the density. Only the fields it sets change, on every platform. |
colors | EmptyStateColors? | null | this empty state's own colours, where they are not the theme's: the ones set here, with the theme's for the rest. |
tagKey | String? | null | the empty state's automation key: it is EmptyState_<tagKey>. |
EmptyStateStyle
PantrixEmptyState's geometry: the circle its icon stands in, the room around what it holds and between its parts, and how wide its words run.
| Parameter | Type | Default | What it is |
|---|---|---|---|
iconSize | Dp | Dp.Unspecified | The icon's own size: 32dp on Android and iOS, 24dp on desktop and the web. |
iconContainerSize | Dp | Dp.Unspecified | The circle the icon stands in the middle of: 64dp on Android and iOS, 48dp on desktop and the web. |
padding | Dp | Dp.Unspecified | The room between the edge of what the empty state stands in and what it holds: 24dp on Android and iOS, 16dp on desktop and the web. |
iconGap | Dp | Dp.Unspecified | The room between the circle and the title: 16dp on Android and iOS, 12dp on desktop and the web. |
textGap | Dp | Dp.Unspecified | The room between the title and the description: 4dp. |
actionGap | Dp | Dp.Unspecified | The room between the words and the action under them: 16dp. |
maxTextWidth | Dp | Dp.Unspecified | How wide the title and the description run at the most, in the middle of a wide room: a line that runs across a whole window is not read. 360dp. |
EmptyStateColors
What PantrixEmptyState is painted with, where it is not the theme's: a colour that is set is used, and one that is left out stays the theme's.
| Parameter | Type | Default | What it is |
|---|---|---|---|
icon | Color | Color.Unspecified | The icon: the onContainer of the theme's neutral role. |
iconContainer | Color | Color.Unspecified | The circle behind the icon: the container of the theme's neutral role. |
title | Color | Color.Unspecified | The title: the theme's textPrimary. |
description | Color | Color.Unspecified | The description: the theme's textSecondary. |
Accessibility
- Screen reader. The title and the description are read as one, the action after them, as a button. The icon is not read: the title says what it shows.