Skip to content

docs(material/theming): rewrite theming-your-components guide #22465

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 1 commit into from
Apr 14, 2021

Conversation

jelbourn
Copy link
Member

This change completely rewrites the theming-your-components guide to be
more complete, correct, and concise.

Summary of changes:

@jelbourn jelbourn added P2 The issue is important to a large percentage of users, with a workaround docs This issue is related to documentation merge safe target: major This PR is targeted for the next major release area: theming labels Apr 12, 2021
@google-cla google-cla bot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Apr 12, 2021
Copy link
Contributor

@mmalerba mmalerba left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@crisbeto crisbeto left a comment

Choose a reason for hiding this comment

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

LGTM

### Reading color values

To read color values from a theme, you can use the `get-color-config` Sass function. This function
returns a Sass map containing the theme's primary, accent, and warn palettes, as well as a flag
Copy link
Member

Choose a reason for hiding this comment

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

Should the palette names be wrapped in backticks?

Copy link
Member 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 so- we treat these as terms in the theming guide, but not explicitly as code symbols

```

### Step 3: Add a "theme" mixin
Copy link
Member

Choose a reason for hiding this comment

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

I think that "theme" should be in backticks, not quotes.

Copy link
Member Author

Choose a reason for hiding this comment

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

I removed the quotes

Copy link
Contributor

@twerske twerske left a comment

Choose a reason for hiding this comment

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

lgtm - a few comments/questions and a nit

}

@mixin theme($theme) {
$color-config: mat.get-color-config($theme);
Copy link
Contributor

Choose a reason for hiding this comment

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

You end up extracting the color-config and typography-config twice to check null in this structure, is that best practice?

Copy link
Member Author

Choose a reason for hiding this comment

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

It doesn't really matter, the cost is negligible

## 3. Include the theme mixin in your application
@mixin color($theme) {
// Get the color config from the theme.
$color-config: mat.get-color-config($theme);
Copy link
Contributor

Choose a reason for hiding this comment

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

No null checks shown here but then they're using in the theme mixin section, is that intentional?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, that mirrors the way our own mixins work- the typography and color mixins always emit, but the -theme mixin only emits if the configuration is defined.

Now that you've defined the carousel component's theme mixin, you can include this mixin along with
the the other theme mixins in your application.

```scss
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe define what file this goes in - should custom mixins also be top level in styles.scss (I assume yes?)

Copy link
Member Author

Choose a reason for hiding this comment

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

I considered this, but decided not to because this file can really be called anything. The CLI defaults to styles.scss (which isn't a great name IMO), but people can really call it anything. Inside Google, people often call this something like material-theme.scss. I think the theming guide is probably clear enough on this that I'm not super worried about it, but we can see if we get any feedback.

$color-config: mat.get-color-config($theme);
$primary-palette: map.get($color-config, 'primary');
$accent-palette: map.get($color-config, 'accent');
$warn-palette: map.get($color-config, 'warn');
Copy link
Contributor

Choose a reason for hiding this comment

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

I think (maybe no longer?) you can also get background and foreground so that you could style a raised carousel to have a background color like a 'card' etc? That seems useful to incorporate here for components that have background or foreground (especially with dark modes)

Copy link
Member Author

Choose a reason for hiding this comment

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

For the time being I want to leave the background palettes as a private implementation detail since we will likely need to change them in the not-too-distant future.

This change completely rewrites the theming-your-components guide to be
more complete, correct, and concise.

Summary of changes:
* Start document with some explanatory content before diving into
  step-by-step tutorial.
* Use new Sass `@use` API introduced in angular#22173
* Document (and expose) `get-color-config` and `get-typography-config`
@jelbourn jelbourn force-pushed the theme-your-components branch from d7690c5 to e182148 Compare April 13, 2021 18:21
@jelbourn jelbourn added the action: merge The PR is ready for merge by the caretaker label Apr 13, 2021
@mmalerba mmalerba merged commit b722fcf into angular:master Apr 14, 2021
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators May 15, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker area: theming cla: yes PR author has agreed to Google's Contributor License Agreement docs This issue is related to documentation P2 The issue is important to a large percentage of users, with a workaround target: major This PR is targeted for the next major release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants