Skip to content
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

React: fill is not a style property, it's a svg attribute. #418

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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