Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for EmberJS in docs #506

Open
oleoneto opened this issue Dec 1, 2018 · 2 comments
Open

Add support for EmberJS in docs #506

oleoneto opened this issue Dec 1, 2018 · 2 comments

Comments

@oleoneto
Copy link

oleoneto commented Dec 1, 2018

Getting Feather to work with Ember is quite simple. I think the README could be updated to include how to use icons with the framework.

Here are the steps I followed:

  1. Install Feather
npm install feather-icons --save
  1. Add CommonJS modules support
ember install ember-cli-cjs-transform
  1. Add reference to ember-cli-build.js
...
app.import('node_modules/feather-icons/dist/feather.js', {
    using: [
      { transformation: 'cjs', as: 'feather' } // <-- enables `import 'feather'` from anywhere in the application
    ]
});
  1. In my case, I call feather.replace() from within a component's javascript file:
// app/components/home.js
import Component from '@ember/component';
import feather from 'feather'; // <-- using the transform name

export default Component.extend({
  feather: feather, // <-- here

  didInsertElement() {
    this.feather.replace(); // <-- replaces all references to data-feather with the correct SVGs
  }
});
  1. In the corresponding component template file I simply add the data-feather tag to the elements I want to replace with an icon:
<!-- app/templates/components/home.hbs -->
<span data-feather="home"></span> Home

Done.

@brunoocasali
Copy link

Thanks for your guidance @oleoneto :)

I've adapted your idea to a modifier approach (it's my first actually haha):

// app/modifiers/render-feather-icons.js
import { modifier } from "ember-modifier";
import feather from "feather";

export default modifier(() => feather.replace());
<nav class="navbar" {{render-feather-icons}}>
  <div class="navbar-brand">
    <div class="navbar-item">
      <span class="icon is-big has-text-black">
        <i data-feather="award"></i>
      </span>
    </div>
  </div>
  ...

This way we could define the feather import just once and reuse it all over the place ;)

#emberrocks

@oleoneto
Copy link
Author

oleoneto commented Aug 7, 2020

@brunoocasali I quite like this approach!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants