Skip to content

Commit 6d12cd8

Browse files
authored
Forms: Add basic theming support (#339)
1 parent 609b640 commit 6d12cd8

File tree

4 files changed

+55
-25
lines changed

4 files changed

+55
-25
lines changed

toolkit/featureforms/README.md

+30
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,33 @@ FeatureForm(
9494
)
9595
```
9696
*Note* : Once the `validationErrorVisibility` is set to `Visible`, changing it back to `Automatic` will have no effect since all the fields have now gained focus to show any errors.
97+
98+
## Theming and Customization
99+
100+
`FeatureForm` uses the material3 theming system. The following `colors` and `typography` are used by the respective fields.
101+
102+
#### Text Fields
103+
- Outline color - `MaterialTheme.colorScheme.outline`
104+
- Label TextStyle - `MaterialTheme.typography.bodyMedium`
105+
- Input TextStyle - `MaterialTheme.typography.bodyLarge`
106+
- SupportingText TextStyle - `MaterialTheme.typography.bodySmall`
107+
- Error color - `MaterialTheme.colorScheme.error`
108+
109+
#### Radio Buttons
110+
- Outline color - `MaterialTheme.colorScheme.outline`
111+
- Label TextStyle - `MaterialTheme.typography.bodyMedium`
112+
- Options TextStyle - `MaterialTheme.typography.bodyLarge`
113+
- SupportingText TextStyle - `MaterialTheme.typography.bodySmall`
114+
- Error color - `MaterialTheme.colorScheme.error`
115+
116+
#### Group Elements
117+
- Outline Color - `MaterialTheme.colorScheme.outline`
118+
- Header Color - `MaterialTheme.colorScheme.SurfaceVariant`
119+
- Content background Color - `MaterialTheme.colorScheme.background`
120+
- Label TextStyle - `MaterialTheme.typography.bodyMedium`
121+
- Description TextStyle - `MaterialTheme.typography.bodySmall`
122+
123+
#### Read-Only Fields
124+
Alpha values for read only fields cannot be customized at this time.
125+
126+
More information on the material 3 specs [here](https://m3.material.io/components/text-fields/specs#e4964192-72ad-414f-85b4-4b4357abb83c)

toolkit/featureforms/src/main/java/com/arcgismaps/toolkit/featureforms/components/base/BaseTextField.kt

+14-8
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@ import androidx.compose.material.icons.rounded.Clear
3131
import androidx.compose.material.icons.rounded.TextFields
3232
import androidx.compose.material3.Icon
3333
import androidx.compose.material3.IconButton
34+
import androidx.compose.material3.LocalTextStyle
3435
import androidx.compose.material3.MaterialTheme
3536
import androidx.compose.material3.OutlinedTextField
3637
import androidx.compose.material3.Text
3738
import androidx.compose.runtime.Composable
39+
import androidx.compose.runtime.CompositionLocalProvider
3840
import androidx.compose.runtime.getValue
3941
import androidx.compose.runtime.mutableStateOf
4042
import androidx.compose.runtime.remember
@@ -190,12 +192,14 @@ internal fun BaseTextField(
190192
.semantics { contentDescription = "outlined text field" },
191193
enabled = true,
192194
readOnly = readOnly,
195+
textStyle = MaterialTheme.typography.bodyLarge,
193196
label = {
194197
Text(
195198
text = label,
196199
modifier = Modifier.semantics { contentDescription = "label" },
197200
overflow = TextOverflow.Ellipsis,
198-
maxLines = 1
201+
maxLines = 1,
202+
style = MaterialTheme.typography.bodySmall
199203
)
200204
},
201205
trailingIcon = trailingContent
@@ -209,13 +213,15 @@ internal fun BaseTextField(
209213
onDone = { focusManager.clearFocus() }
210214
),
211215
supportingText = {
212-
Column(
213-
modifier = Modifier
214-
.clickable {
215-
focusManager.clearFocus()
216-
}
217-
) {
218-
supportingText?.invoke(this)
216+
CompositionLocalProvider(LocalTextStyle provides MaterialTheme.typography.bodySmall) {
217+
Column(
218+
modifier = Modifier
219+
.clickable {
220+
focusManager.clearFocus()
221+
}
222+
) {
223+
supportingText?.invoke(this)
224+
}
219225
}
220226
},
221227
visualTransformation = visualTransformation,

toolkit/featureforms/src/main/java/com/arcgismaps/toolkit/featureforms/components/codedvalue/RadioButtonField.kt

+5-7
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import androidx.compose.foundation.selection.selectable
2626
import androidx.compose.foundation.selection.selectableGroup
2727
import androidx.compose.foundation.shape.RoundedCornerShape
2828
import androidx.compose.material3.LocalContentColor
29+
import androidx.compose.material3.LocalTextStyle
2930
import androidx.compose.material3.MaterialTheme
3031
import androidx.compose.material3.RadioButton
3132
import androidx.compose.material3.Text
@@ -101,8 +102,7 @@ private fun RadioButtonField(
101102
} else {
102103
label
103104
},
104-
style = MaterialTheme.typography.bodyMedium,
105-
color = colors.labelColor
105+
style = RadioButtonFieldDefaults.labelTextStyle,
106106
)
107107
Column(
108108
modifier = Modifier
@@ -114,7 +114,7 @@ private fun RadioButtonField(
114114
)
115115
) {
116116
CompositionLocalProvider(
117-
LocalContentColor provides colors.textColor
117+
LocalTextStyle provides RadioButtonFieldDefaults.textStyle
118118
) {
119119
options.forEach { (code, name) ->
120120
RadioButtonRow(
@@ -129,8 +129,7 @@ private fun RadioButtonField(
129129
if (description.isNotEmpty()) {
130130
Text(
131131
text = description,
132-
style = MaterialTheme.typography.bodySmall,
133-
color = colors.supportingTextColor
132+
style = RadioButtonFieldDefaults.supportingTextStyle
134133
)
135134
}
136135
}
@@ -164,8 +163,7 @@ private fun RadioButtonRow(
164163
enabled = enabled
165164
)
166165
Text(
167-
text = value,
168-
style = MaterialTheme.typography.bodyMedium
166+
text = value
169167
)
170168
}
171169
}

toolkit/featureforms/src/main/java/com/arcgismaps/toolkit/featureforms/components/codedvalue/RadioButtonFieldDefaults.kt

+6-10
Original file line numberDiff line numberDiff line change
@@ -16,36 +16,32 @@
1616

1717
package com.arcgismaps.toolkit.featureforms.components.codedvalue
1818

19-
import androidx.compose.material3.LocalContentColor
2019
import androidx.compose.material3.MaterialTheme
2120
import androidx.compose.runtime.Composable
2221
import androidx.compose.ui.graphics.Color
22+
import androidx.compose.ui.text.TextStyle
2323

2424
internal object RadioButtonFieldDefaults {
25+
26+
val textStyle : TextStyle @Composable get() = MaterialTheme.typography.bodyLarge
27+
val labelTextStyle : TextStyle @Composable get() = MaterialTheme.typography.bodyMedium
28+
val supportingTextStyle : TextStyle @Composable get() = MaterialTheme.typography.bodySmall
29+
2530
@Composable
2631
fun colors(): RadioButtonFieldColors = RadioButtonFieldColors(
27-
labelColor = MaterialTheme.colorScheme.onSurfaceVariant,
28-
supportingTextColor = MaterialTheme.colorScheme.onSurfaceVariant,
2932
errorColor = MaterialTheme.colorScheme.error,
3033
containerBorderColor = MaterialTheme.colorScheme.outline,
31-
textColor = LocalContentColor.current
3234
)
3335
}
3436

3537
/**
3638
* Color properties of a radio button field.
3739
*
38-
* @property labelColor The color used for the label of this radio button field.
39-
* @property supportingTextColor The color used for the supporting text of this radio button field.
4040
* @property errorColor The color used for the supporting text of this radio button field when the value is considered
4141
* invalid.
4242
* @property containerBorderColor The color used for the container border of this radio button field.
43-
* @property textColor The color used for the text of this radio button field options.
4443
*/
4544
internal data class RadioButtonFieldColors(
46-
val labelColor: Color,
47-
val supportingTextColor: Color,
4845
val errorColor: Color,
4946
val containerBorderColor: Color,
50-
val textColor: Color
5147
)

0 commit comments

Comments
 (0)