Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to theme angular material component shapes?

Is there any way to theme component shapes in angular material? I know material design has a shape concept that allows you to create more rounded, less rounded or even cut corners for all small/medium/large components. Is there a way to implement that in angular material?

If not then what is the best way to customize a component globally in angular material? Say I want to remove the rounded corners on all <mat-button>'s?

like image 740
Canolyb1 Avatar asked Jul 15 '19 01:07

Canolyb1


1 Answers

The short answer is that Angular Material does not provide a straightforward way of doing this.

"Theming" in Angular Material is limited to color and typography. Shapes, spacing, sizes, borders, and so on are in a way "hard-coded." However, almost all of those things end up being CSS, and of course there's always a way to customize CSS. For example define some global style that does something like:

button.mat-button {
   border-radius: 0;
}

Then do that for every component and every property that you want to customize.

Note that it won't always be so straightforward because you'll need to know the internal DOM and class structure of all the components in order to apply the style where it needs to be. You'll also need to know all the component options and how they change the DOM and class structure. On top of that, some components dynamically inject style using ngStyle and that may be impossible to override.

Long story short - "redesigning" Angular Material is at best a lot of work, and more realistically not 100% achievable. If Angular Material isn't quite what you want, use something else.

like image 100
G. Tranter Avatar answered Oct 02 '22 14:10

G. Tranter