Skip to content

Commit

Permalink
Update peer dependecy react version and the octicon func to use React…
Browse files Browse the repository at this point in the history
….forwardRef
  • Loading branch information
broccolinisoup committed May 3, 2023
1 parent 6c94e0e commit d74b2e6
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 37 deletions.
2 changes: 1 addition & 1 deletion lib/octicons_react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"typescript": "^4.8.3"
},
"peerDependencies": {
"react": ">=15"
"react": ">=16.3"
},
"engines": {
"node": ">=8"
Expand Down
78 changes: 42 additions & 36 deletions lib/octicons_react/src/createIconComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,43 +10,49 @@ export function createIconComponent(name, defaultClassName, getSVGData) {
const svgDataByHeight = getSVGData()
const heights = Object.keys(svgDataByHeight)

function Icon({
'aria-label': ariaLabel,
tabIndex,
className = defaultClassName,
fill = 'currentColor',
size = 16,
verticalAlign = 'text-bottom'
}) {
const height = sizeMap[size] || size
const naturalHeight = closestNaturalHeight(heights, height)
const naturalWidth = svgDataByHeight[naturalHeight].width
const width = height * (naturalWidth / naturalHeight)
const path = svgDataByHeight[naturalHeight].path
const Icon = React.forwardRef(
(
{
'aria-label': ariaLabel,
tabIndex,
className = defaultClassName,
fill = 'currentColor',
size = 16,
verticalAlign = 'text-bottom'
},
forwardedRef
) => {
const height = sizeMap[size] || size
const naturalHeight = closestNaturalHeight(heights, height)
const naturalWidth = svgDataByHeight[naturalHeight].width
const width = height * (naturalWidth / naturalHeight)
const path = svgDataByHeight[naturalHeight].path

return (
<svg
aria-hidden={ariaLabel ? 'false' : 'true'}
tabIndex={tabIndex}
focusable={tabIndex >= 0 ? 'true' : 'false'}
aria-label={ariaLabel}
role="img"
className={className}
viewBox={`0 0 ${naturalWidth} ${naturalHeight}`}
width={width}
height={height}
fill={fill}
style={{
display: 'inline-block',
userSelect: 'none',
verticalAlign,
overflow: 'visible'
}}
>
{path}
</svg>
)
}
return (
<svg
ref={forwardedRef}
aria-hidden={ariaLabel ? 'false' : 'true'}
tabIndex={tabIndex}
focusable={tabIndex >= 0 ? 'true' : 'false'}
aria-label={ariaLabel}
role="img"
className={className}
viewBox={`0 0 ${naturalWidth} ${naturalHeight}`}
width={width}
height={height}
fill={fill}
style={{
display: 'inline-block',
userSelect: 'none',
verticalAlign,
overflow: 'visible'
}}
>
{path}
</svg>
)
}
)

Icon.displayName = name

Expand Down

0 comments on commit d74b2e6

Please sign in to comment.