Created
July 29, 2016 04:59
-
-
Save Ripley6811/fd4abf6ff6240c4c31dc30b4ee8593d6 to your computer and use it in GitHub Desktop.
React component generator for Font Awesome icons
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
/** | |
* Creates a react element for a Font Awesome icon. | |
* | |
* ``` | |
* import FontAwesome from './FontAwesome'; | |
* var FA_SPINNING_COG = FontAwesome("cog", "fa-spin"); | |
* ``` | |
* | |
* @param {string} type Font Awesome class name (without "fa-"). | |
* @param {string} classNames = "" Additional string to append to `class`. | |
* @returns {object} React element that displays a Font Awesome icon. | |
*/ | |
export default function create(type, classNames = "") { | |
if (!type || typeof type !== 'string') throw "Type error"; | |
return React.createElement( "span", { | |
className: `fa fa-${type} ${classNames}`, | |
"aria-label": `Font Awesome ${type} icon` | |
}); | |
} | |
// Pre-set elements | |
export const FA_TRASH = create('trash'); | |
export const FA_DOWNLOAD = create('download'); | |
export const FA_CHEVRON_LEFT = create('chevron-left'); | |
export const FA_PLUS = create('plus'); | |
export const FA_MINUS = create('minus'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment