Skip to content

Forms: Add theming support #362

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 369 commits into from
Apr 30, 2024
Merged

Conversation

kaushikrw
Copy link
Collaborator

@kaushikrw kaushikrw commented Mar 19, 2024

Summary of changes

  • Added theming support for the FeatureForm component that includes customizing the ColorScheme and Typography for most of the fields.
  • This theming support is built on top of Material3 to provide default values.
  • Added tests to ensure the color scheme and typography are being passed down and used by the appropriate field types.
  • Updates binary API

Details

It provides a way to customize the color scheme and typography using two classes.

  • FeatureFormColorScheme
    • EditableTextFieldColors
    • ReadOnlyTextFieldColors
    • GroupElementColors
    • RadioButtonFieldColors
  • FeatureFormTypoGraphy
    • EditableTextFieldTypography
    • ReadOnlyTextFieldTypography
    • GroupElementTypography
    • RadioButtonFieldTypography

These individual classes allow a user to fully customize the color and typography for all the fields independently.

These properties are passed down the compose tree using the LocalColorScheme and LocalLocalTypography composition local.

All these classes provide a createDefaults() factory method that can only be called from a Composable context. The createDefaults() method hydrates the individual properties of these classes from MaterialTheme. It also provides parameters with default values, so that any developer can quickly glance at what MaterialTheme values are being set as defaults.

Due to this design, the FeatureFormColorScheme and FeatureFormTypoGraphy can only be created from a Composable context, since it relies on MaterialTheme for default values. Hence, as a convenience, an object class DefaultThemeTokens is introduced which provides a default colorScheme and typography based on reasonable hardcoded values. These hardcoded defaults are adapted from the Material3.lightColorScheme and MaterialTheme.Typography.

Furthermore, the DefaultThemeTokens are also useful in providing a good default value for the LocalColorScheme and LocalLocalTypography composition local. This is particularly helpful for compose previews.

Soren Roth and others added 30 commits August 3, 2023 17:15
* added measure and placement constraints for the bottomsheetscaffold
* removed transparent top bar :(
…n support. fix some things that broke through merges

remove serialization dependency
… the date time picker state. add a call to dateTimePickerState.setSelection so that even though the state object is remembered, the selection is re-set on recompose.
@sorenoid sorenoid force-pushed the feature-branches/forms branch from 6cb93b7 to 10504ef Compare March 19, 2024 04:44
@kaushikrw kaushikrw force-pushed the kaushik/forms/theming branch from f7e68ed to f791558 Compare March 19, 2024 16:48
Base automatically changed from feature-branches/forms to v.next April 3, 2024 16:23
@kaushikrw kaushikrw changed the base branch from v.next to feature-branches/forms April 12, 2024 23:20
@kaushikrw kaushikrw marked this pull request as ready for review April 12, 2024 23:23
@kaushikrw kaushikrw requested a review from sorenoid April 12, 2024 23:23
Copy link
Collaborator

@sorenoid sorenoid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kaushikrw this looks great and fills a valuable need for FeatureForms. I have some very high level suggestions

  • provide a dark mode color palette that is applied automatically when in dark mode
  • add since tags to all public API
  • provide a simple theme for the FeatureForm itself in addition to the individual components of the form.
    • this theme could be used for the body of GroupElements as well, perhaps with different defaults.

// transform placeholder colors into text colors
val transformPlaceHolderColors = textIsEmpty && !placeHolderIsEmpty
val transformedFocusedTextColor = if (transformPlaceHolderColors) {
// if placeholder is visible, make it lighter than the actual input text color
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a nice addition to the TextField defaults. Was this based on an issue in the apollo backlog? I couldn't find one but I remember a mention of lightening placeholder text.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we ever created an issue, but this behavior also exists in the pre-custom theme system.

Comment on lines 89 to 92
colors = CardDefaults.cardColors(
containerColor = colors.headerColor
),
border = BorderStroke(GroupElementDefaults.borderThickness, colors.outlineColor)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that GroupElementColors.containerColor is also defined and used for the body of the card. I think it would make sense to call the headerColor containerColor so it matches the Card colors property name, and changing the current GroupElementColors.containerColor to bodyColor.

I think ultimately this points out that there is no overall FeatureFormColors and FeatureFormDefaults for the form container, just the elements contained in it. If there were, it would make sense to reuse it with a separate set of defaults for the card's body.

val TertiaryContainer = PaletteTokens.Tertiary90
}

private object PaletteTokens {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs to check isSystemInDarkTheme() and offer dark mode alternatives/

Copy link
Collaborator Author

@kaushikrw kaushikrw Apr 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this is needed. The DefaultThemeTokens only needs to provide default values for LocalColorScheme and LocalTypography. These defaults are only utilized in internal compose previews. During runtime the actual values are always taken from MaterialTheme based on current light/dark theme.

@kaushikrw
Copy link
Collaborator Author

@sorenoid I've updated this based on our new design standard and addressed some of the feedback. Please have another look!

@kaushikrw kaushikrw requested a review from sorenoid April 26, 2024 17:37
Copy link
Collaborator

@sorenoid sorenoid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@kaushikrw
Copy link
Collaborator Author

Thanks @sorenoid, merging.

@kaushikrw kaushikrw merged commit 198f938 into feature-branches/forms Apr 30, 2024
@kaushikrw kaushikrw deleted the kaushik/forms/theming branch April 30, 2024 20:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants