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

mixinColor: Allow custom colors #19134

Closed
tmburnell opened this issue Apr 21, 2020 · 3 comments
Closed

mixinColor: Allow custom colors #19134

tmburnell opened this issue Apr 21, 2020 · 3 comments
Labels
area: material/core feature This issue represents a new feature or feature request rather than a bug or bug fix

Comments

@tmburnell
Copy link

Feature Description

Add error as a valid ThemePalette
or better yet, provide a way to create custom Palette colors.

Use Case

Years ago I had the need to have a color="error" that was different than color="warn".
To accomplish this I have created scss library that creates all the css needed on all the material components to support the error color.
Here is an example of what I am talking about: https://stackblitz.com/edit/error-button-color

It works in stackblitz due to this bug: stackblitz/core#220
With Angular9 and this setting turned on (in the tsconfig.json):

"angularCompilerOptions": {
    "strictTemplates": true
}

it returns this error:

Type '"error"' is not assignable to type 'ThemePalettte'

A third option (that I have not figured out) is can you override the ThemePalettte type definition?

@tmburnell tmburnell added feature This issue represents a new feature or feature request rather than a bug or bug fix needs triage This issue needs to be triaged by the team labels Apr 21, 2020
@devversion
Copy link
Member

As per Material Design specification, there is only a primary, secondary and error palette. Obviously our palette is named warn through. Regardless of that though, there are only three supported themes as per spec, so I don't think we'll be able to add support for more.

We cannot add another option to ThemePalette as that would signify a breaking change, and we'd need to handle it in our theming system too.

Generally though, this is a great issue though! Please keep us updated when you find a way to achieve a fourth palette. It might be worth experimenting with TS declaration merging (though that might not play nicely w/ type checking)

@devversion devversion added area: material/core and removed needs triage This issue needs to be triaged by the team labels May 25, 2020
@tmburnell
Copy link
Author

tmburnell commented Jun 8, 2020

I may have got this to work (not fully tested).

import { ThemePalette as oldThemePalette } from '@angular/material/core';

export type ThemePalette = Partial<oldThemePalette | 'error'>;

If I make all my variables use my definition instead of materials.

The only issue i see is there is no clean way to do:

<button mat-button color="error"></button>

because it will by default use materials definition and not mine. (unless I can find a way to globally apply it.
---------------------------------------
my compiler was slow even my custom type was marked as errored

Type '"error" | "primary" | "accent" | "warn"' is not assignable to type 'ThemePalette'.

@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 Jul 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: material/core feature This issue represents a new feature or feature request rather than a bug or bug fix
Projects
None yet
Development

No branches or pull requests

2 participants