Skip to content

Commit

Permalink
Use parameter defaults instead of defaultProps (#882)
Browse files Browse the repository at this point in the history
* Use parameter defaults instead of defaultProps

* changeset

* lint

* update bundle size in test

* update bundle size in test
  • Loading branch information
manuelpuyol committed Dec 21, 2022
1 parent 8a039a7 commit 503bafb
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/lazy-guests-call.md
@@ -0,0 +1,5 @@
---
'@primer/octicons': patch
---

Use parameter defaults instead of defaultProps
2 changes: 1 addition & 1 deletion lib/octicons_react/__tests__/tree-shaking.test.js
Expand Up @@ -50,5 +50,5 @@ test('tree shaking single export', async () => {
})

const bundleSize = Buffer.byteLength(output[0].code.trim()) / 1000
expect(`${bundleSize}kB`).toMatchInlineSnapshot(`"2.691kB"`)
expect(`${bundleSize}kB`).toMatchInlineSnapshot(`"2.826kB"`)
})
14 changes: 8 additions & 6 deletions lib/octicons_react/src/createIconComponent.js
Expand Up @@ -10,7 +10,14 @@ export function createIconComponent(name, defaultClassName, getSVGData) {
const svgDataByHeight = getSVGData()
const heights = Object.keys(svgDataByHeight)

function Icon({'aria-label': ariaLabel, tabIndex, className, fill = 'currentColor', size, verticalAlign}) {
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
Expand Down Expand Up @@ -42,11 +49,6 @@ export function createIconComponent(name, defaultClassName, getSVGData) {
}

Icon.displayName = name
Icon.defaultProps = {
className: defaultClassName,
size: 16,
verticalAlign: 'text-bottom'
}

return Icon
}
Expand Down

0 comments on commit 503bafb

Please sign in to comment.