Skip to content

Commit

Permalink
feat(octicons_react): update base icon component to include svg props (
Browse files Browse the repository at this point in the history
…#1047)

* feat(octicons_react): update base icon component to include svg props

* chore: add changeset

* chore: add back in packageManager option

* test: update test to use firstChild
  • Loading branch information
joshblack authored Dec 9, 2024
1 parent e01e42a commit 4819803
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/nice-lamps-peel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/octicons': minor
---

Add support for SVG props to base icons
2 changes: 1 addition & 1 deletion lib/octicons_react/__tests__/tree-shaking.test.js
Original file line number Diff line number Diff line change
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(`"3.563kB"`)
expect(`${bundleSize}kB`).toMatchInlineSnapshot(`"6.29kB"`)
})
5 changes: 5 additions & 0 deletions lib/octicons_react/src/__tests__/octicon.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ describe('An icon component', () => {
expect(container.querySelector('svg')).toHaveStyle({verticalAlign: 'middle'})
})

it('supports additional props on the outermost element', () => {
const {container} = render(<AlertIcon data-testid="icon" />)
expect(container.firstChild).toHaveAttribute('data-testid', 'icon')
})

describe('size props', () => {
it('respects size="small"', () => {
const {container} = render(<AlertIcon size="small" />)
Expand Down
8 changes: 6 additions & 2 deletions lib/octicons_react/src/createIconComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ export function createIconComponent(name, defaultClassName, getSVGData) {
size = 16,
verticalAlign = 'text-bottom',
id,
title
title,
style,
...rest
},
forwardedRef
) => {
Expand All @@ -36,6 +38,7 @@ export function createIconComponent(name, defaultClassName, getSVGData) {
return (
<svg
ref={forwardedRef}
{...rest}
aria-hidden={labelled ? undefined : 'true'}
tabIndex={tabIndex}
focusable={tabIndex >= 0 ? 'true' : 'false'}
Expand All @@ -52,7 +55,8 @@ export function createIconComponent(name, defaultClassName, getSVGData) {
display: 'inline-block',
userSelect: 'none',
verticalAlign,
overflow: 'visible'
overflow: 'visible',
...style
}}
>
{title ? <title>{title}</title> : null}
Expand Down
2 changes: 1 addition & 1 deletion lib/octicons_react/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {Icon} from './__generated__/icons.js'

type Size = 'small' | 'medium' | 'large'

export interface OcticonProps {
export interface OcticonProps extends React.ComponentPropsWithoutRef<'svg'> {
'aria-label'?: string
'aria-labelledby'?: string
tabIndex?: number
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,6 @@
"github/no-then": 0,
"eslint-comments/no-use": 0
}
}
},
"packageManager": "[email protected]"
}

0 comments on commit 4819803

Please sign in to comment.