Let Me Tink About It
Let Me Tink About It

Reputation: 16112

Polymer 1.x: Using Font Awesome with paper-icon-button

Is there a way to use an icon from the Font Awesome library as the icon inside a paper-icon-button?

Here is my jsBin.

http://jsbin.com/rahesepeho/2/edit?html,output
<!doctype html>
<head>
  <meta name="description" content="iron-data-table beta3">
  <meta charset="utf-8">
  <base href="https://polygit.org/components/">
  <script src="webcomponentsjs/webcomponents-lite.min.js"></script>
  <link href="polymer/polymer.html" rel="import">
  <link href="paper-icon-button/paper-icon-button.html" rel="import"> 
</head>
<body>
  <dom-module id="x-foo">
    <style>
      :host {
        font-family: arial, sans-serif;
      }
    </style>
    <template>
      <p>The below <code>paper-icon-button</code> uses an image from Github.</p>
      <paper-icon-button
        src="https://assets-cdn.github.com/images/modules/logos_page/Octocat.png"
        alt="octocat" title="octocat">
      </paper-icon-button>
      <p>How do I make the below <code>paper-icon-button</code> use an icon from <a href="http://fontawesome.io/icons/" target="_blank">Font Awesome</a>?</p>
      <paper-icon-button
        src="https://assets-cdn.github.com/images/modules/logos_page/Octocat.png"
        alt="octocat" title="octocat">
      </paper-icon-button>
    </template>
    <script>
      document.addEventListener('WebComponentsReady', function() {
        Polymer({
          is: 'x-foo'
        });
      });
    </script>
  </dom-module>
  <x-foo></x-foo>
</body>

Upvotes: 1

Views: 1223

Answers (3)

kelegorm
kelegorm

Reputation: 975

You can use this project! It's cool, bower package to use in polymer 1-2. Now it's last version of FA: 4.7. Here: https://github.com/vangware/fontawesome-iconset

Upvotes: 1

Osvaldo Maria
Osvaldo Maria

Reputation: 361

in my case, on polymer v1.8 i had to create a custom style element as described in this link , paste font-awesome css there and then add it to my element using

   <template>
     <style include="shared-styles">
     </style>
     <paper-button> <i class="fa fa-facebook fa-lg"></i></paper-button>
   ..............
   </template>

Upvotes: 0

Let Me Tink About It
Let Me Tink About It

Reputation: 16112

Per @Stefanvott on the Polymer Slack site:

There are at least two ways:

  1. Use the following custom element https://customelements.io/philya/font-awesome-polymer-icons/ (Didn't work for me.)
  2. Do this <paper-icon-button src="" class="fa fa-github-alt fa-lg"></paper-icon-button> per this jsBin. See below code.
Short version http://jsbin.com/hubonatopa/1/edit?html,output
paper-icon-button.fa {
    padding: .5em;
    height: 2em;
    width: 2em;
}
<paper-icon-button class="fa fa-github-alt fa-lg"></paper-icon-button>
Full version http://jsbin.com/hubonatopa/1/edit?html,output
<!doctype html>

<head>
  <meta name="description" content="iron-data-table beta3">
  <meta charset="utf-8">
  <base href="https://polygit.org/components/">
  <script src="webcomponentsjs/webcomponents-lite.min.js"></script>
  <link href="polymer/polymer.html" rel="import">
  <link href="paper-icon-button/paper-icon-button.html" rel="import">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.css"> </head>

<body>
  <dom-module id="x-foo">
    <style>
      :host {
        font-family: arial, sans-serif;
      }

      paper-icon-button.fa {
        padding: 10px;
        line-height: 1em;
        overflow: hidden;
      }
    </style> <template>
      <p>The below <code>paper-icon-button</code> uses an image from Github.</p>
      <paper-icon-button src="https://assets-cdn.github.com/images/modules/logos_page/Octocat.png" alt="octocat" title="octocat"></paper-icon-button>
      <p>How do I make the below <code>paper-icon-button</code> use an icon from <a href="http://fontawesome.io/icons/" target="_blank">Font Awesome</a>?</p>
      <paper-icon-button class="fa fa-github-alt fa-lg"></paper-icon-button>
    </template>
    <script>
      document.addEventListener('WebComponentsReady', function() {
        Polymer({
          is: 'x-foo'
        });
      });
    </script>
  </dom-module>
  <x-foo></x-foo>
</body>

Upvotes: 1

Related Questions