Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do i change the angular material md-primary button text color?

Basically i cant for the life of me figure out how to set the text color of the buttons using angular material and anything else using the md-primary background color.

The code i am using to create the theme is

var customPrimary = {
        '50': '#7de3cf',
        '100': '#69dec8',
        '200': '#54dac0',
        '300': '#3fd5b8',
        '400': '#2dceaf',
        '500': '#28b99d',
        '600': '#23a48b',
        '700': '#1f8f79',
        '800': '#1a7a68',
        '900': '#166556',
        'A100': '#92e8d7',
        'A200': '#a7ecdf',
        'A400': '#bcf1e7',
        'A700': '#115044'
    };
    $mdThemingProvider
        .definePalette('customPrimary',
        customPrimary);
    $mdThemingProvider.theme('buttons')
        .primaryPalette('customAccent');

However no matter what i try i can get the text colour to be #fff unless i use css and !important which i'd like to avoid, as it means overriding several selectors.

like image 891
JohnC Avatar asked Feb 07 '23 22:02

JohnC


1 Answers

From the docs:

angular.module('myApp', ['ngMaterial'])
.config(function($mdThemingProvider) {
  $mdThemingProvider.definePalette('amazingPaletteName', {
    '50': 'ffebee',
    ...
    'A700': 'd50000',
    'contrastDefaultColor': 'light',    // whether, by default, text (contrast)
                                        // on this palette should be dark or light
    'contrastDarkColors': ['50', '100', //hues which contrast should be 'dark' by default
     '200', '300', '400', 'A100'],
    'contrastLightColors': undefined    // could also specify this if default was 'dark'
  });
  $mdThemingProvider.theme('default')
    .primaryPalette('amazingPaletteName')
});

The important thing here is the contrastDarkColors/contrastLightColors. The "contrast" color is the text (or icon) color that shows up on buttons.

I'm guessing you'll want something like

'contrastDefaultColor': 'light',
'contrastDarkColors': ['50', '100', '200', '300', 'A100', 'A400']

Edit: if you for some reason wanted a color on a button, creating a class that has an !important is fine, e.g.

.md-button.cyan-text {
    color: cyan !important;
}

and

<md-button class="md-primary md-raised cyan-text">Hello world</md-button>
like image 166
Bryan K Avatar answered Feb 13 '23 06:02

Bryan K