Angular Material: Difference between revisions
Created page with "[https://material.angular.io/ Angular Material] contains components for angular which follow material design. ==Getting Started== # Install Angular Material #: <pre>ng add @a..." |
|||
Line 5: | Line 5: | ||
#: <pre>ng add @angular/material</pre> | #: <pre>ng add @angular/material</pre> | ||
# Create a theme following [https://material.angular.io/guide/theming this guide]. | # Create a theme following [https://material.angular.io/guide/theming this guide]. | ||
==Components== | |||
See [https://material.angular.io/components/categories] for a list of components. | |||
To import a component, you use to add it to your <code>app.module.ts</code> file. | |||
{{ hidden | Example import | | |||
<syntaxhighlight lang="typescript"> | |||
import { MatSliderModule } from '@angular/material/slider'; | |||
@NgModule ({.... | |||
imports: [..., | |||
MatSliderModule, | |||
] | |||
}) | |||
</syntaxhighlight> | |||
==Themes== | ==Themes== |
Revision as of 15:20, 21 August 2020
Angular Material contains components for angular which follow material design.
Getting Started
- Install Angular Material
ng add @angular/material
- Create a theme following this guide.
Components
See [1] for a list of components.
To import a component, you use to add it to your app.module.ts
file.
{{ hidden | Example import |
import { MatSliderModule } from '@angular/material/slider';
@NgModule ({....
imports: [...,
MatSliderModule,
]
})
Themes
Theming Angular material is pretty simple but there is very little documentation on it.
First you need to create a theme scss file and add it to your styles array.
theme.scss
Theming Componenets
For each component you want to theme, you should create a mixin. This mixin will contain custom CSS rules for your component based on the global theme.
Next, in your main app theme file, import this mixin and pass in your global app theme:
theme.scss
Color Palettes
Get a color palette like this:
$config: mat-get-color-config($config-or-theme);
// Color Palettes
$primary: map-get($config, primary);
$accent: map-get($config, accent);
$warn: map-get($config, warn);
$foreground: map-get($config, foreground);
$background: map-get($config, background);
To get a specific color from a palette, use mat-color($palette, $key)
:
a {
color: mat-color($foreground, text);
}
# mat-color($primary, 50); is the lightest color
# mat-color($primary, 900); is the darkest color
# mat-color($primary, lighter); defaults to 100
# mat-color($primary); defaults to 500
# mat-color($primary, darker); defaults to 700
# mat-color($primary, '500-contrast'); gets contrast colors for text
Some keys for foreground include: base
, divider
, text
.
See _palette.scss for all available keys. See _theming.scss for a more in-depth understanding about theming.