Skip to content

Commit

Permalink
React: fill is not a style property, it's a svg attribute.
Browse files Browse the repository at this point in the history
Added a default to currentColor but it's possibile to overwrite it via 'fill' prop

Updated react doc

Updates react test
  • Loading branch information
macno committed Apr 30, 2020
1 parent c54859b commit fe654ea
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 4 deletions.
18 changes: 18 additions & 0 deletions docs/content/packages/react.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,24 @@ export default () => (
```


### Fill
The `fill` prop takes a string value that can be used to color the icon.
Default value is `currentColor` which means it inherits parent's text color.

```js
// Example usage
import Octicon, {LogoGithub} from '@primer/octicons-react'

export default () => (
<h1>
<a href='https://github.com'>
<Octicon icon={LogoGithub} fill='#28284E' size='large' ariaLabel='GitHub'/>
</a>
</h1>
)
```


## Custom icons
Each of our icon components is really just a function that renders its SVG
`<path>`. To accommodate icons varying aspect ratios, the `Octicon` component
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ exports[`<Octicon> outputs <svg> 1`] = `
<svg
aria-hidden="true"
className="octicon"
fill="currentColor"
height={16}
role="img"
style={
Object {
"display": "inline-block",
"fill": "currentColor",
"userSelect": "none",
"verticalAlign": "text-bottom",
}
Expand Down
4 changes: 4 additions & 0 deletions lib/octicons_react/src/__tests__/octicon.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ describe('<Octicon>', () => {
expect(render(<TestOcticon verticalAlign="top" />).props.style.verticalAlign).toEqual('text-top')
})

it('respects the fill prop', () => {
expect(render(<TestOcticon fill="yellow" />).props.fill).toEqual('yellow')
})

describe('size props', () => {
it('respects size="small"', () => {
const rendered = render(<TestOcticon size="small" />)
Expand Down
3 changes: 2 additions & 1 deletion lib/octicons_react/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import {Icon} from './__generated__/icons'
type Size = 'small' | 'medium' | 'large'
export interface OcticonProps {
ariaLabel?: string
children?: React.ReactElement<any>
className?: string
children?: React.ReactElement<any>
fill?: string
height?: number
icon: Icon
size?: number | Size
Expand Down
7 changes: 5 additions & 2 deletions lib/octicons_react/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const alignMap = {
const defaultSize = [16, 16]

export default function Octicon(props) {
const {ariaLabel, children, className, height, icon: Icon, size, verticalAlign, width} = props
const {ariaLabel, children, className, height, icon: Icon, size, verticalAlign, width, fill} = props

const child = typeof Icon === 'function' ? <Icon /> : React.Children.only(children)

Expand All @@ -26,6 +26,7 @@ export default function Octicon(props) {
'aria-label': ariaLabel,
className,
height,
fill,
role: 'img',
viewBox: [0, 0, ...widthHeight].join(' ')
}
Expand All @@ -42,7 +43,6 @@ export default function Octicon(props) {

attrs.style = {
display: 'inline-block',
fill: 'currentColor',
userSelect: 'none',
verticalAlign: alignMap[verticalAlign] || verticalAlign
}
Expand All @@ -52,13 +52,16 @@ export default function Octicon(props) {

Octicon.defaultProps = {
className: 'octicon',
fill: 'currentColor',
size: 16,
verticalAlign: 'text-bottom'
}

Octicon.propTypes = {
ariaLabel: PropTypes.string,
children: PropTypes.element,
className: PropTypes.string,
fill: PropTypes.string,
height: PropTypes.number,
icon: PropTypes.func,
size: PropTypes.oneOfType([PropTypes.number, PropTypes.oneOf(Object.keys(sizeMap))]),
Expand Down

0 comments on commit fe654ea

Please sign in to comment.