Giter Site home page Giter Site logo

md-component-theme's Introduction

Angular Material Component Theming

Angular Material doesn't currently provide a way to make custom components / directives themeable.

This service parses tokenized CSS to generate <style> tags based on the apps them which are added to the <head> section of the application.

Status

  • Code needs tidying
  • Proper tests need writing

Dependencies

Requires Angular and Angular Material

Installation

In your index.html file, include the component theming module.

<!-- module -->
<script type="text/javascript" src="../src/md-component-theme/theming.component.js"></script>

Include the material.core.theming.componentTheme module as a dependency in your application.

angular.module('myApp', ['ngMaterial', 'material.core.theming.componentTheme']);

Usage

$mdComponentTheme service has one function $mdComponentTheme.generateTheme(css). The generate theme function accepts CSS as a string not a file.

It's useful to compile your SCSS/CSS to a constant during your components/directives build.

The CSS string can contain tokens which will get replaced with the correct colors for the apps theme at runtime.

  • THEME_NAME e.g. md-button.md-THEME_NAME-theme
  • {{color}} e.g. background-color: '{{primary-color}}'

See the Angular Material ```*-theme.scss`` files for more examples.

Example

    angular
    .module('your.custom.component',['ngMaterial','material.core.theming.componentTheme'])
    .directive('customComponent', customComponentDirective)
    .constant("$CUSTOM_COMPONENT_THEME_CSS", "md-stepper.md-THEME_NAME-theme.md-primary md-step.active md-step-circle,md-stepper.md-THEME_NAME-theme.md-primary md-step.done md-step-circle{color:'{{primary-contrast}}';background-color:'{{primary-color}}'}...");

    function customComponentDirective($injector,$mdComponentTheme) {
        //Get component theme CSS
        var themeCss = $injector.get('$MD_STEPPER_THEME_CSS');
        // Parse CSS and add to HEAD with correct theme colors
        $mdComponentTheme.generateTheme(themeCss);

        /**
        Rest of your code
        */
    }

md-component-theme's People

Contributors

richshaw avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.