Angular Material Integration with Analog
This tutorial will guide you through the process of integrating the Angular Material library within your Analog application.
Step 1: Installing the Angular Material library
To begin, you need to install the @angular/cdk and @angular/material packages. Depending on your preferred package manager, run one of the following commands:
- npm
- yarn
- pnpm
npm install @angular/cdk @angular/material
yarn add @angular/cdk @angular/material
pnpm install @angular/cdk @angular/material
Step 2: Configuring the Angular Material library
- Rename the file styles.csstostyles.scss.
- Set the inlineStylesExtensionproperty to'scss'in thevite.config.tsfile:
export default defineConfig(({ mode }) => {
  return {
    plugins: [
      analog({
        vite: {
          inlineStylesExtension: 'scss',
        },
      }),
    ],
  };
});
- Update the index.htmlfile to reference the SCSS file:
<head>
  <!-- other headers -->
  <link rel="stylesheet" href="/src/styles.scss" />
  <link rel="preconnect" href="https://fonts.gstatic.com" />
  <link
    href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500&display=swap"
    rel="stylesheet"
  />
  <link
    href="https://fonts.googleapis.com/icon?family=Material+Icons"
    rel="stylesheet"
  />
</head>
<body class="mat-typography">
  <!-- content -->
</body>
- Update the styles.scssfile to import the Angular Material styles and define your custom theme:
@use '@angular/material' as mat;
$theme: mat.define-theme(
  (
    color: (
      theme-type: light,
      primary: mat.$azure-palette,
      tertiary: mat.$blue-palette,
    ),
  )
);
body {
  @include mat.all-component-themes($theme);
  font-family: Roboto, 'Helvetica Neue', sans-serif;
  margin: 0;
  padding: 30px;
  height: 100%;
}
html {
  height: 100%;
}
@include mat.core();
@include mat.color-variants-backwards-compatibility($theme);