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

Use parameter defaults instead of defaultProps #882

Merged
merged 6 commits into from Dec 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

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