-
Notifications
You must be signed in to change notification settings - Fork 827
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
Creating an official octicons-react component #196
Closed
Closed
Changes from 3 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
542d2f6
First commit on a react-octicons component
jonrohan 2cb57f7
Renaming for npmjs
jonrohan b5a9afd
Updating sheild location
jonrohan 0cccc4f
remove clasee
jonrohan a0d68d5
building babel dist
jonrohan d7728f2
Outputting to build instead
jonrohan 36e3e4b
Setting up linting
jonrohan 581a4f2
github-lint?
jonrohan 60d21a7
1.1.0
jonrohan 9d94633
1.1.0
jonrohan 8f120ac
Be explicit so that it's not mixed up with index.scss
jonrohan 20170b6
Making the sizing stricter
jonrohan 11933d8
Large
jonrohan b41121c
Adding alignment options
jonrohan 0071790
Merge branch 'master' into react_octicons
jonrohan ba46dc4
Removing lint from test
jonrohan c72f20b
Renaming
jonrohan a8a7a07
Updating react package to build components
jonrohan 571e219
Revert package.json
jonrohan 1b30538
Cleaning lint
jonrohan d2e5c24
Don't need this in files
jonrohan f962884
Importing separately for all vs specific octicons
jonrohan f0b872f
Adding named.js to the package files
jonrohan 130110c
Merge branch 'master' into react_octicons
jonrohan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2018 GitHub Inc. | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,60 @@ | ||
# GitHub Octicons React Component | ||
|
||
[![npm version](https://img.shields.io/npm/v/%40github%2Focticons-react.svg)](https://www.npmjs.org/package/%40github%2Focticons-react) | ||
[![Build Status](https://travis-ci.org/primer/octicons.svg?branch=master)](https://travis-ci.org/primer/octicons) | ||
|
||
> A react component for installing octicons | ||
|
||
## Install | ||
|
||
``` | ||
$ npm install @github/octicons-react --save | ||
``` | ||
|
||
## Usage | ||
|
||
The entire library will be available when importing `@github/octicons-react`. Specifying the [icon you want to use][octicons], by supplying the `name=""` to the component. | ||
|
||
```js | ||
// Example usage | ||
import Octicon from "@github/octicons-react" | ||
|
||
const AlertIcon = <Octicon name="alert" /> | ||
``` | ||
|
||
##### ariaLabel | ||
|
||
You have the option to add accessibility information to the icon using `aria-label`. | ||
|
||
```js | ||
// Example usage | ||
import Octicon from "@github/octicons-react" | ||
|
||
const PlusIcon = <Octicon name="plus" ariaLabel="Add new item" /> | ||
``` | ||
|
||
|
||
##### width & height | ||
|
||
You can change the dimensions of the icon by setting `width` and/or `height`. We recommended you supply **only the height**, because this will then calculate the appropriate width based on the viewBox size. | ||
|
||
```js | ||
// Example usage | ||
import Octicon from "@github/octicons-react" | ||
|
||
const BiggestLogo = <Octicon name="logo-github" height="500" /> | ||
``` | ||
|
||
## License | ||
|
||
(c) GitHub, Inc. | ||
|
||
When using the GitHub logos, be sure to follow the [GitHub logo guidelines](https://github.com/logos). | ||
|
||
[MIT](./LICENSE) | ||
|
||
[octicons]: https://octicons.github.com/ | ||
[primer]: https://github.com/primer/primer | ||
[docs]: http://primercss.io/ | ||
[npm]: https://www.npmjs.com/ | ||
[install-npm]: https://docs.npmjs.com/getting-started/installing-node |
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,53 @@ | ||
import React from 'react' | ||
import octicons from 'octicons' | ||
|
||
export default class Octicon extends React.Component { | ||
|
||
prepareAttributes(octicon) { | ||
const {height, width, ariaLabel} = this.props | ||
|
||
const attr = octicon.options | ||
|
||
// If any of the width or height is passed in | ||
if(width || height) { | ||
attr["width"] = width ? width : (parseInt(height) * octicon.options["width"] / octicon.options["height"]) | ||
attr["height"] = height ? height : (parseInt(width) * octicon.options["height"] / octicon.options["width"]) | ||
} | ||
|
||
// If the user passed in aria-label | ||
if (ariaLabel) { | ||
attr["aria-label"] = ariaLabel | ||
attr["role"] = "img" | ||
|
||
// Un-hide the icon | ||
delete attr["aria-hidden"] | ||
} | ||
|
||
return attr | ||
} | ||
|
||
render() { | ||
const {name} = this.props | ||
const octicon = octicons[name] | ||
|
||
if (octicon) { | ||
const svgStyle = { | ||
display: "inline-block", | ||
fill: "currentColor", | ||
verticalAlign: "text-bottom", | ||
position: "relative", | ||
userSelect: "none" | ||
} | ||
|
||
return ( | ||
<svg | ||
{...this.prepareAttributes(octicon)} | ||
style={svgStyle} | ||
dangerouslySetInnerHTML={ {__html: octicon.path } }> | ||
</svg> | ||
) | ||
} else { | ||
throw new Error(`No such octicon: "${name}"!`) | ||
} | ||
} | ||
} |
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,38 @@ | ||
{ | ||
"name": "@github/octicons-react", | ||
"version": "1.1.0-alpha.542d2f63", | ||
"description": "A scalable set of icons handcrafted with <3 by GitHub.", | ||
"homepage": "https://octicons.github.com", | ||
"author": "GitHub Inc.", | ||
"license": "MIT", | ||
"main": "index.js", | ||
"repository": "https://github.com/primer/octicons.git", | ||
"bugs": { | ||
"url": "https://github.com/primer/octicons/issues" | ||
}, | ||
"keywords": [ | ||
"GitHub", | ||
"icons", | ||
"svg", | ||
"octicons", | ||
"react", | ||
"primer" | ||
], | ||
"babel": { | ||
"presets": [ | ||
"env", | ||
"react" | ||
] | ||
}, | ||
"peerDependencies": { | ||
"react": ">=16.2.0" | ||
}, | ||
"dependencies": { | ||
"octicons": "7.1.0", | ||
"react": "^16.2.0" | ||
}, | ||
"devDependencies": { | ||
"babel-preset-env": "^1.6.1", | ||
"babel-preset-react": "^6.24.1" | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think showing examples where you use the icons within another other component might be clearer, this is example is kind of making a component of a component 🙃
Here's a quick example:
Also, pretty sure we want to be using single quotes.