你如何在Hyperstack中使用FontAwesome图标?

问题描述 投票:0回答:1

在使用Rails和ReactJS的FontAwsome项目中使用Hyperstack图标的最佳方法是什么,使用Yarn只包含您需要的图标?

ruby-on-rails ruby reactjs isomorphic hyperstack
1个回答
1
投票

这是最好的方法:

使用纱线添加模块:

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

真的很简单!

© www.soinside.com 2019 - 2024. All rights reserved.