Skip to content
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

[Epic] Lightweight Styling #854

Closed
kazo0 opened this issue Sep 23, 2022 · 7 comments
Closed

[Epic] Lightweight Styling #854

kazo0 opened this issue Sep 23, 2022 · 7 comments

Comments

@kazo0
Copy link
Collaborator

kazo0 commented Sep 23, 2022

Instead of having to override the ControlTemplate of any given Material/Cupertino style we should allow for Lightweight Styling

All styles should be refactored to reference resource keys that follow an accepted standard naming scheme.

All Default styles (those without a style-variant should follow the resource key naming coming from the matching Fluent themeresources

Proposed naming convention:
{?:style-variant}{control-name}{member}{?:visual-state}

Name Part Description
style-variant (Optional) Certain styles have multiple variants. Ex: For Button we have style variants such as: Outlined, Text, Filled
control-name Name of the control type (Button, TextBox, CheckBox, etc.)
member The property that this style should be assigned to (Foreground, Background, BorderBrush, etc.)
visual-state (Optional) Specifies which VisualState that this resource will be applied to (PointerOver, Checked, Disabled, etc.)

Ensure all color resources for the controls and their visual states follow the design specs from our Uno Material Figma file

Required Styles

EDIT: 2023-05-30

  1. We will be removing the {design} prefix for the lightweight styling keys since this will hinder us from creating design-agnostic aliases of these keys. Because of a limitation in the way resources are resolved: if you create an alias (B) for a resource key (A) and then override the value of A, the alias (B) will still retain the original value of A and will not be updated. Therefore, we cannot rely on aliasing the material-specific lightweight styling keys as design-agnostic ones and expect it to work if people were to override the material specific ones, or vice-versa.
  2. When creating lightweight style resource keys for a default style such as MaterialCheckBoxStyle, MaterialDatePickerStyle, etc (i.e. when there is no style-variant), we should be using the same key names as the ones coming from the Fluent resources as a base. We can go ahead and create additional lightweight resource keys, but we should at least be supporting the ones coming from Fluent. Example: the CheckBox style in Material should define the same resource keys that are defined here, as well as any additional keys that may be useful to have. Certain extra lightweight resource keys can be created that are specific to the Material template, and in those cases we would prefix those with "Material". Example:
@kazo0 kazo0 added the kind/enhancement New feature or request label Sep 23, 2022
@Xiaoy312
Copy link
Contributor

the proposed naming convention is expanded from the current style naming convention:
{design}{?:style-variant}{control-name}Style
{design}{?:style-variant}{control-name}{member}{?:visual-state}

eg:
MaterialFilledButtonStyle
MaterialFilledButtonBackground
MaterialFilledButtonBackgroundPressed

note: most styles are also aliased with a new key without the {design} prefix, so "MaterialFilledButtonStyle" can also referenced with "FilledButtonStyle" key.

@kazo0
Copy link
Collaborator Author

kazo0 commented Nov 26, 2022

Something to consider here, overriding these resources is going to be tricky. If my Button Style is referencing MaterialFilledButtonBackground, and I override MaterialFilledButtonBackground within my App.xaml, the aliased FilledButtonBackground resource will continue to resolve to the original value of MaterialFilledButtonBackground and not the overridden value. The same issue applies in the other direction. If I were to override FilledButtonBrush in my App.xaml, the MaterialFilledButtonBrush will not resolve to the new overridden value, only usages of the shared key, FilledButtonBrush, are affected by the override.

Right now, the Material styles contain a mishmash of resource references using both the Material specific keys but also the aliased "shared" keys.

Example:

<Setter Property="Foreground"
		Value="{StaticResource PrimaryBrush}" />
<Setter Property="BorderThickness"
		Value="{StaticResource MaterialOutlinedButtonBorderThickness}" />
<Setter Property="BorderBrush"
		Value="{StaticResource MaterialOutlinedButtonBorderBrush}" />

We need to figure out how we should be dealing with overrides. Should all Material styles only reference Material-specific resource keys? So, we'd use MaterialPrimaryBrush, MaterialOutlinedButtonBorderThickness, etc. In that case, we would provide aliases for these resources, but you would need to specifically override the resources using the Material prefix in order for the included styles to adapt properly. Overriding MaterialPrimaryBrush from Purple to Red will be reflected in the styles but any place that is directly referencing the aliased shared key of PrimaryBrush will still show Purple.

Otherwise, we get rid of the Material/Cupertino prefixes for resources, remove all the aliases, and they just get redefined in the Uno.Cupertino and Uno.Material libraries. There will have to be some special cases for resources that may be specific to one design system. In this case, we can reference PrimaryBrush, OutlinedButtonBorderThickness , etc. and those keys would also be the ones to override.

I feel like maintaining the design system prefixes are kind of pointless. Unless there are some resources that exist in only one design-system, then those can be specially documented usages with the Material/Cupertino prefix.

Problem with getting rid of the prefix is that it'll be a big breaking change for anyone that is currently using the Material prefixed keys. For the most part, people would most probably be using the shared aliases, but I'm assuming this'd need to be introduced as a new major version.

@francoistanguay @Xiaoy312 @jeromelaban thoughts?
@carldebilly this will for sure affect figma as well

@jeromelaban
Copy link
Member

Assuming current users don't override styles using Material-prefixed resources (which currently does not work with Uno), we could invert their definitions for the generic ones to be the original styles and the material prefixed ones to be the aliases.

We may also need to consider the scenario about the resolution in the gallery app, which contains both definitions simultaneously (if included at the app.xaml level), but may still resolve properly when using material-prefixed styles.

@kazo0
Copy link
Collaborator Author

kazo0 commented Nov 28, 2022

Yeah I've already inverted the font resources in my branch:

Typography.xaml

TypographyOverrides.xaml (should be called aliases, not overrides)

For the actual Styles themselves I don't think this is going to be an issue, it's more for the resources that the styles reference. Like for the Typography changes in the above links, I changed all usages of those resources within the styles to the non-prefixed/non-aliased ones.

So either,

  • Generic resource keys are the original definition and the styles reference the generic keys directly. So then overriding FilledButtonBackground will be reflected in the FilledButtonStyle. Or,
  • The styles reference only the aliased/prefixed resources and you would then need to specify the design system prefix when overriding. So in order for FilledButtonStyle to reflect the Background override, it needs to reference MaterialFilledButtonBackground

My feeling is people should not use prefixed resource keys within the app, same way they should be using the non-prefixed style keys. Only thing that messes things up are apps like Gallery where you need a way to directly reference the proper design system resources.

@kazo0
Copy link
Collaborator Author

kazo0 commented Nov 30, 2022

FYI for the issue of resource aliases not reflecting the overridden values, it seems that this is a known issue and pain point: microsoft/microsoft-ui-xaml#2913

@kazo0
Copy link
Collaborator Author

kazo0 commented Apr 14, 2023

Looking back on this, we should be going with the original design and allowing lightweight styling at a per-control level. Where we would be able to override something like a Brush in the Material style for NavigationViewItem called MaterialNavigationViewItemBackgroundSelected, rather than needing to locally override the PrimarySelectedBrush that this alias would be referencing.

Proposal updated and copied to the original post:

Proposed naming convention:
{design}{?:style-variant}{control-name}{member}{?:visual-state}

Name Part Description
design A prefix for the design system (Material, Cupertino, etc.)
style-variant (Optional) Certain styles have multiple variants. Ex: For Button we have style variants such as: Outlined, Text, Filled
control-name Name of the control type (Button, TextBox, CheckBox, etc.)
member The property that this style should be assigned to (Foreground, Background, BorderBrush, etc.)
visual-state (Optional) Specifies which VisualState that this resource will be applied to (PointerOver, Checked, Disabled, etc.)

@agneszitte
Copy link
Contributor

Closing this epic issue as the only left is #1063 which is already in progress

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants