Time Filled Text Field
A filled text field for a time of day: the time is typed in digits, or chosen from a time picker that a button at the box's end opens. It is PantrixTimeTextField in a filled box.
import com.pantrixui.components.date.timefilledtextfield.PantrixTimeFilledTextField
Examples
A meeting's start, on the quarter hour
A meeting's start, on the quarter hour: the picker's minutes come fifteen apart.
var start by remember { mutableStateOf<PantrixTime?>(null) }
val strings = PantrixTheme.strings
Column(verticalArrangement = Arrangement.spacedBy(PantrixTheme.spacing.sm)) {
PantrixTimeFilledTextField(
value = start,
onValueChange = { start = it },
label = "Meeting start",
minuteStep = QUARTER,
showClearButton = true,
tagKey = "meeting_start"
)
PantrixText(
text = start?.let { "Start: ${strings.time(it.hour, it.minute, is24Hour = true)}" }
?: "No time yet",
style = PantrixTheme.typography.body
)
}
private const val QUARTER = 15
Within working hours
A call within working hours: a time typed outside them is not taken, and the field says the two ends.
var call by remember { mutableStateOf<PantrixTime?>(null) }
PantrixTimeFilledTextField(
value = call,
onValueChange = { call = it },
label = "Call time",
supportingText = "Weekdays from 09:00 to 18:00",
minTime = PantrixTime(OPENS, 0),
maxTime = PantrixTime(CLOSES, 0),
tagKey = "call"
)
private const val OPENS = 9
private const val CLOSES = 18
A clock of twelve hours
A clock of twelve hours: the half of the day stands in the box beside the digits and turns at a press.
var alarm by remember { mutableStateOf<PantrixTime?>(PantrixTime(7, 30)) }
PantrixTimeFilledTextField(
value = alarm,
onValueChange = { alarm = it },
label = "Alarm",
is24Hour = false,
tagKey = "alarm"
)
Bound to a form
Bound to a form's field: with no time, "Save" shows the error and sends the focus to the field.
val form = rememberFormState()
val scope = rememberCoroutineScope()
val report = LocalExampleEvents.current
val start = form.field<PantrixTime?>("shift_start", initial = null, Rules.required("Enter the shift's start"))
PantrixTimeFilledTextField(
field = start,
modifier = Modifier.fillMaxWidth(),
form = form,
label = "Shift start",
minuteStep = QUARTER
)
PantrixButton(
text = "Save",
onClick = { scope.launch { form.submit { report("Saved") } } },
form = form,
tagKey = "save_shift"
)
private const val QUARTER = 15
On a state
On a state: state.time is the field's time, state.text the digits typed. Together they tell an empty field from a half-typed one. The button changes the state's time, and the field writes it in itself, by a clock of twelve hours with the half of the day.
val state = rememberTimeTextFieldState()
Column(verticalArrangement = Arrangement.spacedBy(PantrixTheme.spacing.sm)) {
PantrixTimeFilledTextField(
state = state,
label = "Reminder",
is24Hour = false,
tagKey = "reminder"
)
PantrixText(
text = when {
state.time != null -> "Time: ${state.time}"
state.text.isEmpty() -> "The field is empty"
else -> "Half typed: ${state.text}"
},
style = PantrixTheme.typography.body
)
PantrixButton(
text = "Write now",
onClick = { state.time = PantrixTime.now() },
variant = ButtonVariant.Outline,
tagKey = "write_now"
)
}
API
value
A filled text field for a time of day: the time is typed in digits, or chosen from a time picker that a button at the box's end opens. It is PantrixTimeTextField in a filled box.
| Parameter | Type | Default | What it is |
|---|---|---|---|
value | PantrixTime? | the time the field shows, or null. | |
onValueChange | (PantrixTime?) -> Unit | told the field's time each time the user changes it: a time, or null for none. | |
modifier | Modifier | Modifier | the modifier of the whole field: its label, its box and what is under it. |
enabled | Boolean | true | whether the field can be used. One that cannot takes no focus and opens no picker. |
readOnly | Boolean | false | whether the time can only be chosen from the picker, and not typed. |
label | String? | null | what the field is for, written above the box: the field's name for a screen reader, and its picker's. |
placeholder | String? | null | shown in the box while it is empty, in the place of the pattern the field shows by itself. |
supportingText | String? | null | help under the box. With error it is the message that says what to put right; without it, the field's own error takes its place while there is one. |
error | Boolean | false | whether the caller finds the time wrong, as a time already booked: the field is drawn in error, and supportingText is the message. |
leadingIcon | (@Composable () -> Unit)? | null | what stands before the text. A slot does not size what is put in it. |
showClearButton | Boolean | false | shows a button that empties the field, while it can be typed into and is not empty. |
minTime | PantrixTime? | null | the first time the field takes, or null for no first. Where it is after maxTime, the times run past midnight, as a night's do. |
maxTime | PantrixTime? | null | the last time the field takes, or null for no last. |
minuteStep | Int | 1 | how many minutes apart the picker's minutes are, 1 to 60. A minute typed between them is taken. |
is24Hour | Boolean | true | whether the field and its picker count the hours of a day, 00 to 23, or by a clock of twelve hours. |
presentation | DatePickerPresentation | DatePickerPresentation.Adaptive | what the picker opens in: by default a sheet in a narrow window and a popover under the box in a wider one, chosen as it opens; or always a popover, a sheet or a dialog. |
style | FilledTextFieldStyle? | null | this call's own style of the field: over every enclosing one and under the density. |
colors | FilledTextFieldColors? | null | this call's own colours of the field, in place of the theme's roles. |
pickerStyle | TimePickerStyle? | null | this call's own style of the picker. |
pickerColors | TimePickerColors? | null | this call's own colours of the picker. |
contentDescription | String? | null | what a screen reader says for the field where it has no label. |
tagKey | String? | null | the field's automation key: the field is TimeFilledTextField_<tagKey>, its button TimeFilledTextFieldClock_<tagKey>, its half of the day TimeFilledTextFieldPeriod_<tagKey>, its clear button TimeFilledTextFieldClear_<tagKey> and its picker TimePicker_<tagKey>. The field reports that the picker opened and that a value was chosen in it, and never the time. |
interactionSource | MutableInteractionSource? | null | the field's interactions, hoisted: its focus, its hover and its presses. |
state
A time field on a state its caller keeps, as PantrixTimeFilledTextField of a value is in every other way: the state's time is the field's time, setting it writes the time in, and its text tells a field that is half typed from an empty one.
| Parameter | Type | Default | What it is |
|---|---|---|---|
state | TimeTextFieldState | the digits typed and the time they make. Create it with rememberTimeTextFieldState(). | |
modifier | Modifier | Modifier | the modifier of the whole field: its label, its box and what is under it. |
enabled | Boolean | true | whether the field can be used. One that cannot takes no focus and opens no picker. |
readOnly | Boolean | false | whether the time can only be chosen from the picker, and not typed. |
label | String? | null | what the field is for, written above the box: the field's name for a screen reader, and its picker's. |
placeholder | String? | null | shown in the box while it is empty, in the place of the pattern the field shows by itself. |
supportingText | String? | null | help under the box. With error it is the message; without it, the field's own error takes its place while there is one. |
error | Boolean | false | whether the caller finds the time wrong: the field is drawn in error, and supportingText is the message. |
leadingIcon | (@Composable () -> Unit)? | null | what stands before the text. |
showClearButton | Boolean | false | shows a button that empties the field, while it can be typed into and is not empty. |
minTime | PantrixTime? | null | the first time the field takes, or null for no first; after maxTime, the times run past midnight. |
maxTime | PantrixTime? | null | the last time the field takes, or null for no last. |
minuteStep | Int | 1 | how many minutes apart the picker's minutes are, 1 to 60. |
is24Hour | Boolean | true | whether the field and its picker count the hours of a day, or by a clock of twelve hours. |
presentation | DatePickerPresentation | DatePickerPresentation.Adaptive | what the picker opens in: by default a sheet in a narrow window and a popover under the box in a wider one, chosen as it opens; or always a popover, a sheet or a dialog. |
style | FilledTextFieldStyle? | null | this call's own style of the field. |
colors | FilledTextFieldColors? | null | this call's own colours of the field. |
pickerStyle | TimePickerStyle? | null | this call's own style of the picker. |
pickerColors | TimePickerColors? | null | this call's own colours of the picker. |
contentDescription | String? | null | what a screen reader says for the field where it has no label. |
tagKey | String? | null | the field's automation key, as PantrixTimeFilledTextField of a value takes it. |
interactionSource | MutableInteractionSource? | null | the field's interactions, hoisted. |
field
A time field bound to a form's field: its time, its error and its name come from field.
| Parameter | Type | Default | What it is |
|---|---|---|---|
field | FormField<PantrixTime?> | the form's field the time field shows and changes. | |
modifier | Modifier | Modifier | the modifier of the whole field. |
form | FormState? | null | given, the keyboard's action key submits the form through the button registered with it. |
enabled | Boolean | true | whether the field can be used. |
readOnly | Boolean | false | whether the time can only be chosen from the picker. |
label | String? | null | what the field is for, written above the box. |
placeholder | String? | null | shown in the box while it is empty, in the place of the pattern. |
supportingText | String? | null | help under the box, while the field has no error to show there. |
leadingIcon | (@Composable () -> Unit)? | null | what stands before the text. |
showClearButton | Boolean | false | shows a button that empties the field, while it can be typed into and is not empty. |
minTime | PantrixTime? | null | the first time the field takes, or null for no first; after maxTime, the times run past midnight. |
maxTime | PantrixTime? | null | the last time the field takes, or null for no last. |
minuteStep | Int | 1 | how many minutes apart the picker's minutes are, 1 to 60. |
is24Hour | Boolean | true | whether the field and its picker count the hours of a day, or by a clock of twelve hours. |
presentation | DatePickerPresentation | DatePickerPresentation.Adaptive | what the picker opens in: by default a sheet in a narrow window and a popover under the box in a wider one, chosen as it opens; or always a popover, a sheet or a dialog. |
style | FilledTextFieldStyle? | null | this call's own style of the field. |
colors | FilledTextFieldColors? | null | this call's own colours of the field. |
pickerStyle | TimePickerStyle? | null | this call's own style of the picker. |
pickerColors | TimePickerColors? | null | this call's own colours of the picker. |
contentDescription | String? | null | what a screen reader says for the field where it has no label. |
interactionSource | MutableInteractionSource? | null | the field's interactions, hoisted. |
FilledTextFieldStyle
PantrixFilledTextField's box: its shape, how tall and how wide it is at the least, the room around what it holds, its icons and its outline.
| Parameter | Type | Default | What it is |
|---|---|---|---|
shape | ShapeSpec | ShapeSpec.Unspecified | The box's shape. A fully round one, ShapeRole.Full, is a pill only while the field holds one line: a field of several lines takes ShapeRole.Large instead, since a capsule's curve runs into the first line of its text. |
height | Dp | Dp.Unspecified | The least the box is tall. |
minWidth | Dp | Dp.Unspecified | The least the box is wide, which keeps an empty field from growing as the user types into it. |
horizontalPadding | Dp | Dp.Unspecified | The room between the box's edge and its label and text, where no icon is. |
verticalPadding | Dp | Dp.Unspecified | The room above the label's line and below the last line of the text. |
iconPadding | Dp | Dp.Unspecified | The room around an icon in its slot. |
iconSize | Dp | Dp.Unspecified | The size an icon in a slot should take. A slot does not size what is put in it. |
borderWidth | Dp | Dp.Unspecified | How thick the outline is that the box takes with the focus, in error and under a pointer. At rest it has none. |
textRole | TypeRole? | null | The role of the type scale the text is typed in, the label rests in and the placeholder is set in: the body's, 16sp, on Android and iOS, as Material 3 types a field, and the label's, 14sp, on the desktop and the web, as a page under a pointer does. |
FilledTextFieldColors
What PantrixFilledTextField is painted with, for a field that does not take the theme's: a colour that is set is used, and one that is left out stays the theme's role. A product gives the colours it changes and no others:
| Parameter | Type | Default | What it is |
|---|---|---|---|
container | Color | Color.Unspecified | The box's fill at rest. The theme's neutral container. |
focusedContainer | Color | Color.Unspecified | The box's fill under an outline: with the focus, and in error. The theme's surface. |
hoveredOutline | Color | Color.Unspecified | The outline under a pointer. The theme's borderHover. |
focusedOutline | Color | Color.Unspecified | The outline while the field has the focus. The theme's primary. |
error | Color | Color.Unspecified | What says the text is wrong: the outline, the message under the box, the caret, and the count once it is past its limit. The theme's danger. |
text | Color | Color.Unspecified | The typed text. The theme's textPrimary. |
label | Color | Color.Unspecified | The label, at rest in the text's place and on its own line above the text. The theme's textSecondary. |
placeholder | Color | Color.Unspecified | The placeholder. The theme's textSecondary. |
supportingText | Color | Color.Unspecified | The help under the box, and the count. The theme's textSecondary. |
icon | Color | Color.Unspecified | What an icon in a slot is drawn in unless it sets a tint of its own, and the clear button's cross. The theme's textSecondary. |
cursor | Color | Color.Unspecified | The caret, and with it the handles and the highlight of a selection. The theme's primary. |
scrollBar | Color | Color.Unspecified | The bar that shows how far the text of a box of several lines is scrolled. The theme's borderStrong: it is a mark on the box's fill, and a box's soft edge would not be seen there. |