material icon indicating copy to clipboard operation
material copied to clipboard

Material Icons on md-icon directive

Open edaquinta opened this issue 11 years ago • 15 comments

I have a question, sorry for my english btw, I found (http://google.github.io/material-design-icons/), a great icon set but didn't find a individual css class implementation for each icon, just Ligatures, so if I want to use the < md-icon > directive with the md-font-icon="menu" attribute I can't. Maybe there is a better way, I just didn't find it and create my own approach:

CSS .menu:after { content: "\E5D2" }

HTML < md-icon md-font-icon="menu" >< /md-icon >

so I define the icons I'll be using and that's it. make sense? If there is a better way let me know, and if no exist and your OK with mine, I can send you my CSS implementation, is that easy as include the material-icons web font from google and the new css with the individual definitions.

edaquinta avatar May 29 '15 17:05 edaquinta

Here are the general steps we used in our Font Icon Demo:

  1. Load the icon fonts desired
  2. Configure CSS with names to specify a content unicode
  3. Use your custom css name in md-font-icon=""

Loading the fonts

<style>
    @font-face {
      font-family:"icomoon";
      src:url("https://cdn.rawgit.com/angular/material/master/docs/app/fonts/icomoon.eot");
      font-weight:normal;
      font-style:normal;
    }
    @font-face {
      font-family: 'icomoon';
      src:url('https://rawgit.com/angular/material/master/docs/app/fonts/icomoon.eot?-cmq1um');
      src:url('https://cdn.rawgit.com/angular/material/master/docs/app/fonts/icomoon.eot?#iefix-cmq1um') format('embedded-opentype'),
      url('https://cdn.rawgit.com/angular/material/master/docs/app/fonts/icomoon.woff?-cmq1um') format('woff'),
      url('https://cdn.rawgit.com/angular/material/master/docs/app/fonts/icomoon.ttf?-cmq1um') format('truetype'),
      url('https://cdn.rawgit.com/angular/material/master/docs/app/fonts/icomoon.svg?-cmq1um#icomoon') format('svg');
      font-weight: normal;
      font-style: normal;
    }
  </style>

or using

<link href="https://fonts.googleapis.com/icon?family=Material+Icons"
      rel="stylesheet">

Specifying the CSS

Since our font-icon css names have an icon- prefix, we can easily specify the font-family in the css.

    [class^="icon-"]:before,
    [class*=" icon-"]:before {
      /** associate font-family with font icons names */
      font-family:"icomoon";
      display:inline-block;
      vertical-align:middle;
      line-height:1;
      font-weight:normal;
      font-style:normal;
      speak:none;
      text-decoration:inherit;
      text-transform:none;
      text-rendering:optimizeLegibility;
      -webkit-font-smoothing:antialiased;
      -moz-osx-font-smoothing:grayscale;
    }

    .icon-home:before {
        content: "\e900";
    }

And our css names - unique for each desired icon - are easy: .icon-home, etc.

Using <md-icon>

Simply set the md-font-icon attribute and any color: #xxx css to specify the fill color:

<md-icon md-font-icon="icon-home" />

ThomasBurleson avatar May 29 '15 19:05 ThomasBurleson

This is basically the same thing I'm doing, instead using icon-* I set the font family to all the md-icon:

md-icon > .md-font { font-family: 'Material Icons'; font-weight: normal; font-style: normal; font-size: 24px; /* Preferred icon size */ display: inline-block; width: 1em; height: 1em; line-height: 1; text-transform: none;

/* Support for all WebKit browsers. */
-webkit-font-smoothing: antialiased;
/* Support for Safari and Chrome. */
text-rendering: optimizeLegibility;

/* Support for Firefox. */
-moz-osx-font-smoothing: grayscale;

/* Support for IE. */
font-feature-settings: 'liga';

}

and then create the names with content unicode. So there isn't a CSS created with all the Material Icons individual icons right?

edaquinta avatar May 29 '15 20:05 edaquinta

I found this very confusing as well. Funny that the issue was JUST created. Angular material's md-icon makes it appear as if you get a large icon set, but in reality it appears you only get the 4 or 5 in the demo. Some sort of hook to the http://google.github.io/material-design-icons/ icons and how to hook them up would certainly be appreciated.

It seems silly to have to create css entries for each icon when all I need to use the icons in the material icon bundle is:

<i class="material-icons">face</i>

I should be able to just do:

<md-icon md-font-icon="face"></md-icon>

without having to do a css entry for "face"

dparish avatar May 29 '15 20:05 dparish

Yes, actually that's what I'm doing, making the hook for my personal use jejejeje. Just creating the CSS with the definition of every single icon in the css in order to be able to use it in the md-icon way. So in the future I just use < md-icon md-font-icon="face" >< /md-icon > cause I already define all ligatures as class names. make sense? Sorry for my english

edaquinta avatar May 29 '15 20:05 edaquinta

I'm surprised this doesn't work:

    <md-button class="md-fab" aria-label="FAB">
        <i class="material-icons">face</i>
    </md-button>

It won't show the icon even when it works by itself:

        <i class="material-icons">face</i>

dparish avatar May 29 '15 20:05 dparish

By the way, if you wanna use it in the easy way, just use my css (https://github.com/edaquinta/angular-material-icons). Regards

edaquinta avatar May 29 '15 21:05 edaquinta

@edaquinta https://www.google.com/design/icons/#ic_check_box google already provided this.😄

tianvan avatar May 29 '15 21:05 tianvan

No dude, this is where I took the unicode values but they don't provide a css with the class name, something required in md-icon directive, not the ligature. make sense?

edaquinta avatar May 29 '15 21:05 edaquinta

Here are the general steps we used in our Font Icon Demo:

  1. Load the icon fonts desired
  2. Configure CSS with names to specify a content unicode
  3. Use your custom css name in md-font-icon=""

Loading the fonts

<style>
    @font-face {
      font-family:"icomoon";
      src:url("https://cdn.rawgit.com/angular/material/master/docs/app/fonts/icomoon.eot");
      font-weight:normal;
      font-style:normal;
    }
    @font-face {
      font-family: 'icomoon';
      src:url('https://rawgit.com/angular/material/master/docs/app/fonts/icomoon.eot?-cmq1um');
      src:url('https://cdn.rawgit.com/angular/material/master/docs/app/fonts/icomoon.eot?#iefix-cmq1um') format('embedded-opentype'),
      url('https://cdn.rawgit.com/angular/material/master/docs/app/fonts/icomoon.woff?-cmq1um') format('woff'),
      url('https://cdn.rawgit.com/angular/material/master/docs/app/fonts/icomoon.ttf?-cmq1um') format('truetype'),
      url('https://cdn.rawgit.com/angular/material/master/docs/app/fonts/icomoon.svg?-cmq1um#icomoon') format('svg');
      font-weight: normal;
      font-style: normal;
    }
  </style>

or using

<link href="https://fonts.googleapis.com/icon?family=Material+Icons"
      rel="stylesheet">

Specifying the CSS

Since our font-icon css names have an icon- prefix, we can easily specify the font-family in the css.

    [class^="icon-"]:before,
    [class*=" icon-"]:before {
      /** associate font-family with font icons names */
      font-family:"icomoon";
      display:inline-block;
      vertical-align:middle;
      line-height:1;
      font-weight:normal;
      font-style:normal;
      speak:none;
      text-decoration:inherit;
      text-transform:none;
      text-rendering:optimizeLegibility;
      -webkit-font-smoothing:antialiased;
      -moz-osx-font-smoothing:grayscale;
    }

    .icon-home:before {
        content: "\e900";
    }

And our css names - unique for each desired icon - are easy: .icon-home, etc.

Using <md-icon>

Simply set the md-font-icon attribute and any color: #xxx css to specify the fill color:

<md-icon md-font-icon="icon-home" />

Support for Font-icons & Ligatures

We are currently enhancing md-icon to support font-icons libraries with ligatures:

<md-icon md-font-library="material-icons">face</md-icon>
<md-icon md-font-library="material-icons">&#xE87C;</md-icon>
<md-icon md-font-library="material-icons" class="md-light md-48">face</md-icon>

screen shot 2015-05-29 at 6 57 30 pm

This is a new feature that will be available in the 0.10 release.

These resources have details describing the above approach and more...

screen shot 2015-05-31 at 10 34 20 am

ThomasBurleson avatar May 29 '15 23:05 ThomasBurleson

Awesome!!! Thanks and keep the good work!!

edaquinta avatar May 29 '15 23:05 edaquinta

@ThomasBurleson can this be closed?

rschmukler avatar Jul 12 '15 20:07 rschmukler

For sure! I open the issue but is already addressed and works like a charm!

edaquinta avatar Jul 12 '15 20:07 edaquinta

Icons under md-button doesn't appear when I change the device view to Samsung Note 3 view. I change to device view on Chrome's inspector window. It is kind of random. For example, icons didn't work with Iphone 6 view few days ago. Now IPhone is OK but Samsung Note 3 is not. What is the problem? The icons are visible alone.

So this icon works: <md-icon md-font-set="material-icons"> face </md-icon>

But this icon doesn't:

<md-button class="md-fab" aria-label="Eat cake">
      <md-icon md-font-set="material-icons"> face </md-icon>
</md-button>

For now, I solved it by hosting fonts locally. The above problem persists when I include fonts as <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">

nurp avatar Jul 14 '15 22:07 nurp

This should be documented here: https://material.angularjs.org/latest/#/api/material.components.icon/service/$mdIcon

johannesjo avatar Jul 24 '15 17:07 johannesjo

Altering class attributes of font icons does not work, it will just produce the icons name:

<md-icon md-font-library="material-icons" class="md-light md-48">face</md-icon>

martinbrylski avatar Aug 31 '15 12:08 martinbrylski