forked from patternfly/patternfly-react
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(react-icons): Added Initial Icons Package (patternfly#453)
affects: @patternfly/react-icons, @patternfly/react-docs Added Icons package. ISSUES CLOSED: patternfly#442
- Loading branch information
1 parent
35bf096
commit fdbe746
Showing
37 changed files
with
677 additions
and
10 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import React from 'react'; | ||
import Content from '../../components/content'; | ||
import { Title } from '@patternfly/react-core'; | ||
import { iconMap } from '@patternfly/react-icons/icons'; | ||
import { css, StyleSheet } from '@patternfly/react-styles'; | ||
import styles from '@patternfly/patternfly-next/layouts/Grid/styles.css'; //eslint-disable-line | ||
import { | ||
global_spacer_md as spacerMd, | ||
global_FontSize_sm as labelFontSize | ||
} from '@patternfly/react-tokens'; | ||
|
||
const allIcons = Array.from(iconMap.entries()); | ||
|
||
const extraStyles = StyleSheet.create({ | ||
iconCell: { | ||
display: 'flex', | ||
flexDirection: 'column', | ||
alignItems: 'center', | ||
padding: spacerMd.var | ||
}, | ||
label: { | ||
textAlign: 'center', | ||
fontSize: labelFontSize.var | ||
} | ||
}); | ||
|
||
function Icons() { | ||
return ( | ||
<Content> | ||
<Title size="3xl" withMargins> | ||
Icons | ||
</Title> | ||
<div className={css(styles.grid)}> | ||
{allIcons.map(([id, Icon]) => ( | ||
<div | ||
key={id} | ||
className={css( | ||
styles.gridItem, | ||
styles.modifiers['2ColOnLg'], | ||
styles.modifiers['4ColOnMd'], | ||
styles.modifiers['6ColOnSm'], | ||
extraStyles.iconCell | ||
)} | ||
> | ||
<Icon size="xl" key={id} title={id} /> | ||
<div className={css(extraStyles.label)}>{id}</div> | ||
</div> | ||
))} | ||
</div> | ||
</Content> | ||
); | ||
} | ||
|
||
export default Icons; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# @patternfly/react-icons | ||
|
||
PatternFly 4 Icons as React Components. | ||
|
||
## Usage | ||
|
||
### Option 1 - Icon Component | ||
|
||
As a convenience `@patternfly/react-icons` exports an `Icon` component that can render any of the provided icons by providing it a name prop. This option does remove the ability for treeshaking so this should only be used in environments where that is not a concern. | ||
|
||
```jsx | ||
import React from 'react'; | ||
import { Icon } from '@patternfly/react-icons'; | ||
|
||
const closeIcon = <Icon name="times" />; | ||
``` | ||
|
||
For a list of the available icons please refer to the [PatternFly React Docs](https://patternfly-react.netlify.com/styles/icons) | ||
|
||
### Option 2 - Use icons directly. | ||
|
||
This is the best option use if you desire icons to be treeshaken. | ||
|
||
```jsx | ||
import React from 'react'; | ||
import { Times } from '@patternfly/react-icons'; | ||
|
||
const closeIcon = <Times />; | ||
``` | ||
|
||
## Adding Icons | ||
|
||
Icons for this package are generated from the `@fortawesome/free-solid-svg-icons` package. To add more to what is generated, modify the [icons.js](./build/icons.js) file in the build folder. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
const icons = require('./icons'); | ||
const path = require('path'); | ||
const nodePlop = require('node-plop'); | ||
|
||
const plop = nodePlop(path.resolve(__dirname, './generatorConfig.js')); | ||
const pascalCase = plop.getHelper('pascalCase'); | ||
const camelCase = plop.getHelper('camelCase'); | ||
|
||
const allIcons = icons.fontAwesome.map(getFontAwesomeIcon); | ||
|
||
plop | ||
.getGenerator('icons') | ||
.runActions({ icons: allIcons }) | ||
.catch(console.log); // eslint-disable-line | ||
|
||
function getFontAwesomeIcon(name) { | ||
const faIconName = camelCase(`fa-${name}`); | ||
const faIconDef = require(`@fortawesome/free-solid-svg-icons/${faIconName}`); // eslint-disable-line | ||
|
||
return { | ||
id: name, | ||
name: pascalCase(name), | ||
width: faIconDef.width, | ||
height: faIconDef.height, | ||
svgPath: faIconDef.svgPathData | ||
}; | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
const path = require('path'); | ||
|
||
const templatesDir = path.resolve(__dirname, './templates'); | ||
const srcDir = path.resolve(__dirname, '../src'); | ||
const iconsDir = path.join(srcDir, './icons'); | ||
|
||
module.exports = plop => { | ||
plop.setGenerator('icons', { | ||
prompts: [], | ||
actions(data) { | ||
const actions = []; | ||
data.icons.forEach(icon => { | ||
actions.push({ | ||
type: 'add', | ||
force: true, | ||
data: icon, | ||
path: path.join(iconsDir, './{{id}}.js'), | ||
templateFile: path.join(templatesDir, 'iconFile.hbs') | ||
}); | ||
|
||
actions.push({ | ||
type: 'add', | ||
force: true, | ||
data: icon, | ||
path: path.join(iconsDir, './{{id}}.d.ts'), | ||
templateFile: path.join(templatesDir, 'iconFileTS.hbs') | ||
}); | ||
}); | ||
|
||
actions.push({ | ||
type: 'add', | ||
force: true, | ||
path: path.join(iconsDir, './index.js'), | ||
templateFile: path.join(templatesDir, 'iconBarrelFile.hbs') | ||
}); | ||
|
||
actions.push({ | ||
type: 'add', | ||
force: true, | ||
path: path.join(iconsDir, './index.d.ts'), | ||
templateFile: path.join(templatesDir, 'iconBarrelFileTS.hbs') | ||
}); | ||
|
||
actions.push({ | ||
type: 'add', | ||
force: true, | ||
path: path.join(srcDir, './index.js'), | ||
templateFile: path.join(templatesDir, 'mainBarrelFile.hbs') | ||
}); | ||
|
||
actions.push({ | ||
type: 'add', | ||
force: true, | ||
path: path.join(srcDir, './index.d.ts'), | ||
templateFile: path.join(templatesDir, 'mainBarrelFileTS.hbs') | ||
}); | ||
|
||
return actions; | ||
} | ||
}); | ||
}; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
module.exports = { | ||
fontAwesome: [ | ||
'angle-double-left', | ||
'angle-double-right', | ||
'angle-down', | ||
'angle-left', | ||
'angle-right', | ||
'angle-up', | ||
'arrow-circle-down', | ||
'arrow-circle-up', | ||
'balance-scale', | ||
'ban', | ||
'bell', | ||
'bug', | ||
'caret-down', | ||
'caret-left', | ||
'caret-right', | ||
'caret-up', | ||
'check-circle', | ||
'check', | ||
'clipboard-check', | ||
'clock', | ||
'columns', | ||
'cube', | ||
'cubes', | ||
'ellipsis-v', | ||
'exclamation-circle', | ||
'exclamation-triangle', | ||
'external-link-alt', | ||
'external-link-square-alt', | ||
'filter', | ||
'flag', | ||
'folder-open', | ||
'folder', | ||
'hdd', | ||
'history', | ||
'info-circle', | ||
'key', | ||
'list', | ||
'lock-open', | ||
'lock', | ||
'map-marker', | ||
'memory', | ||
'minus', | ||
'pause-circle', | ||
'pencil-alt', | ||
'plus-circle', | ||
'plus-square', | ||
'plus', | ||
'print', | ||
'question-circle', | ||
'redo', | ||
'search', | ||
'sliders-h', | ||
'sort-alpha-down', | ||
'sort-alpha-up', | ||
'sort-numeric-down', | ||
'sort-numeric-up', | ||
'sort', | ||
'sync-alt', | ||
'table', | ||
'tachometer-alt', | ||
'th-large', | ||
'th', | ||
'thumbtack', | ||
'times-circle', | ||
'times', | ||
'trash', | ||
'user-friends', | ||
'user', | ||
'window-restore', | ||
'wrench' | ||
] | ||
}; |
Oops, something went wrong.