如何在Hyperstack中使用FontAwsome图标?

时间:2019-04-11 05:10:55

标签: ruby-on-rails ruby reactjs isomorphic hyperstack

FontAwsome项目中通过Rails和ReactJS使用Hyperstack图标的最佳方法是,使用Yarn仅包含所需的图标吗?

1 个答案:

答案 0 :(得分:0)

这是最好的方法:

使用Yarn添加模块:

yarn add @fortawesome/fontawesome-svg-core
yarn add @fortawesome/free-solid-svg-icons
yarn add @fortawesome/react-fontawesome

将它们导入您的Webpacker软件包之一:

import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { library } from '@fortawesome/fontawesome-svg-core';
import { faAngleDown, faAngleUp, faCoffee } from '@fortawesome/free-solid-svg-icons';

library.add(faAngleDown, faAngleUp, faCoffee);
global.Fa = FontAwesomeIcon;

然后在组件中使用它们:

H1 { Fa(icon: 'coffee') } # to inherit your H1 style
Fa(icon: 'angle-down', size: 'xs) 
Fa(icon: 'angle-up', className: 'special') 

如果您经常使用某些图标,则可以向HyperComponent类添加帮助方法:

class HyperComponent
  include Hyperstack::Component
  include Hyperstack::State::Observable

  def icon_check
    Fa(icon: 'check', className: 'green-color', size: 'lg')
  end
end

就是这么简单!