0.2.2 • Published 5 years ago

mat-theme-util v0.2.2

Weekly downloads
9
License
MIT
Repository
github
Last release
5 years ago

Material Theme Util

This library is a interface for Angular Material UI Library and custom colors. The intended purpose it serves is to provide a dynamic solution for changing Angular Material theme colors on the fly and offer the ability to set the colors with any hex code.

This library should seamlessly integrate with most Angular Material applications - requiring very little (if any) modification on the Material Side.

Release Notes

v0.2

v0.2.2

  • Support for padding-unset
  • Removed logging

v0.2.1

  • More Effective regex for Hex codes
  • Dead code removal v0.2.0
  • New UI for ColorPicker/PalettePicker
  • Support for both a stringified and parsed JSON Theme object for the <mat-palette-picker> formControl value.

Pre-reqs

  • Angular CLI
  • Angular Material
  • A good understanding of both.

Integration

1. Install Material Theme Util package

2. Import the following packages in your AppModule

...
import { ThemeUtilModule, ThemeUtilService } from 'mat-theme-util';

@NgModule({
  imports: [
    ...
    ThemeUtilModule
  ],
  providers: [
    ThemeUtilService
  ]
  ...
})
export class AppModule { }

3. Choose the designated HTML Element that you want to contain the theme

...
<body #THEME_CONTAINER>
  ...
</body>

4. Import the following stylesheets

./styles.scss

@import "~@angular/material/theming";
@include mat-core();
@import "~mat-theme-util/theme-util";

No material theme should be imported, defined or set.

Usage

- Theme Initialization

app.component.ts

...
  primary = "#5F121F";
  accent = "#2F7F89";
  warn = "#ff0000";

  constructor(private themeUtil: ThemeUtilService) {
    this.themeUtil.initTheme(
      this.primary,
      this.accent,
      this.warn
    );
  }
...

- Setting Palette Colors

app.component.ts

...
  updatePrimary(hexCode: string) {
    this.themeUtil.setPrimaryPalette(hexCode);
    // this.themeUtil.setAccentPalette(hexCode);
    // this.themeUtil.setWarnPalette(hexCode);
  }
...

This code can be used in any component the ThemeUtilService is autowired

Additional Features

Color Extensions

classFunction
primary-bgSets background to the Primary Color, and the text as a contrast color
accent-bgSets background to the Accent Color, and the text as a contrast color
warn-bgSets background to the Warn Color, and the text as a contrast color
primary-colorSets text color to the Primary Color, and the background as a contrast color
accent-colorSets text color to the Accent Color, and the background as a contrast color
warn-colorSets text color to the Warn Color, and the background as a contrast color

These classes will stay up to date with the dynamic theming.

CSS Grids Framework

Responsive Layout

  • hide

    Preset layout class, setting the 'display' of the element to 'none'. Supports extensions

  • show

    Preset layout class, resetting the 'display' of the element. Supports extensions

  • col{XX}

    Preset layout class, with the 'XX' denoting the columns allocated for. (this can be nested)

    XXColumnsFunctionExtensions*
    111fr (> 100px)X
    221fr (> 100px)X
    331fr (> 100px)X
    441fr (> 50px)X
    551fr (> 50px)X
    661fr (> 40px)X
    -auto-fill*1fr (> 25px)
    -auto-fitany1fr (> 25px)
    aa2auto, autox
    a12auto, 1frx
    1a21fr, autox
    1-221fr, 2frx
    2-122fr, 1frx
    1-321fr, 3frx
    3-123fr, 1frx
    2-322fr, 3frx
    3-223fr, 2frx

* Extensions can be used for setting specific styles for different viewports

Extensions

ViewportMinMaxExample
-xs-600pxcol1-xs
-sm600px768pxcol1-sm
-md768px992pxcol1-md
-lg992px1200pxcol1-lg
-xl1200px-col1-xl

Other Extensions

*The following can only be used with col- classes

NameFunctionExample
-wideincreases col/row gapcol1-xs-wide

Margin

  • margin{1-6}

    Preset margin class, with the number denoting the 'rem'

  • vmargin{1-6}

    Preset vertical margin class, with the number denoting the 'rem'

  • hmargin{1-6}

    Preset horizontal margin class, with the number denoting the 'rem'

  • margin-unset

    Preset margin class, setting the margin to 'unset'

Padding

  • padding{1-6}

    Preset padding class, with the number denoting the 'rem'

  • vpadding{1-6}

    Preset vertical padding class, with the number denoting the 'rem'

  • hpadding{1-6}

    Preset horizontal padding class, with the number denoting the 'rem'

  • padding-unset

    Preset padding class, setting the padding to 'unset'



Package Versioning

  • Angular CLI: 8.1.3
  • Node: 12.6.

Inspired by:

0.2.2

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.7

5 years ago

0.1.6

5 years ago

0.1.5

5 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago