question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[theme] How to use collor-palette to configure theme | sass

See original GitHub issue

This is not really a bug but rather help request - hopefully there is a quick answer.

I would like to configure my theme using material color palette (which can be found in @material/theme/color-palette

I am able to access the colors like this

@use "@material/theme" as theme;
// or @use "@material/theme/color-palette" as theme;
body {
  background-color: theme.$red-500;
}

but then how to configure $primary or $secondary colors

@use "@material/theme" as theme;
@use "@material/theme" with (
  $primary: theme.$red-500,
  $secondary: theme.$pink-500,
);

This throws Error: This module was already loaded, so it can't be configured using "with".

I’ve also tried

@use "@material/theme" as theme;
theme.$primary: theme.$red-500;
@use "material-components-web"; // custom file importing single components

body {
  background-color: theme.$red-500;
}

And I do get background red but mdc components are not changed.

How can I set material $primary,$secondary or other colors using material color palette? Thanks for help!

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:2
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

9reactions
asyncLizcommented, Mar 17, 2020

Try this:

// Configure
@use "@material/theme/color-palette";
@use "@material/theme/variables" with (
  $primary: color-palette.$red-500
);

// Usage
@use "@material/theme";

body {
  background-color: theme.$primary;
}

I think this would be a documentation feature we should expand upon. Either explaining how to do it like above, or refactoring code to make it more feasible.

2reactions
asyncLizcommented, May 26, 2020

Move the import after the use. @import url() is a runtime CSS statement, not a Sass @import module.

@use "@material/typography" with (
  $font-family: unquote("Dosis")
);
@import url('https://fonts.googleapis.com/css2?family=Dosis&display=swap');

@include typography.core-styles;

This will transpile to the following CSS:

@import url("https://fonts.googleapis.com/css2?family=Dosis&display=swap");
.mdc-typography {
  -moz-osx-font-smoothing: grayscale;
  -webkit-font-smoothing: antialiased;
  font-family: Dosis;
  /* @alternate */
  font-family: var(--mdc-typography-font-family, Dosis);
}
/* additional styles */

I just tested and verified that it works. If you continue to have trouble though, feel free to open a new issue so we can keep this one focused on the theme color palette documentation problem.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Create a color theme mixin with Sass - YouTube
A look at the CUBE CSS methodology in action · Give your site a fantastic color scheme fast · Create a fun animated...
Read more >
Theme and Color Scheme — SASS Way - Medium
In the SCSS file, you need to define your themes and color schemes. Both themes and color schemes are arrays. You can add...
Read more >
Access Theme Color Values With Sass - Egghead.io
Manage the color palette used in your stylesheets by creating a map of variables and a function to access the values by key....
Read more >
Dealing with Color Schemes in Sass - SitePoint
Many websites have styles set up as color modules. This articles considers how Sass can be used to make color schemes DRY and...
Read more >
Switchable Color Schemes in SASS
1. Setting/changing inline CSS based on a configurable color code · 2. Setting/changing a SASS variable based on a class · 3. Using...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found