Skip to content

Commit 4819803

Browse files
authored
feat(octicons_react): update base icon component to include svg props (#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
1 parent e01e42a commit 4819803

File tree

6 files changed

+20
-5
lines changed

6 files changed

+20
-5
lines changed

.changeset/nice-lamps-peel.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@primer/octicons': minor
3+
---
4+
5+
Add support for SVG props to base icons

lib/octicons_react/__tests__/tree-shaking.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,5 @@ test('tree shaking single export', async () => {
5050
})
5151

5252
const bundleSize = Buffer.byteLength(output[0].code.trim()) / 1000
53-
expect(`${bundleSize}kB`).toMatchInlineSnapshot(`"3.563kB"`)
53+
expect(`${bundleSize}kB`).toMatchInlineSnapshot(`"6.29kB"`)
5454
})

lib/octicons_react/src/__tests__/octicon.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ describe('An icon component', () => {
6767
expect(container.querySelector('svg')).toHaveStyle({verticalAlign: 'middle'})
6868
})
6969

70+
it('supports additional props on the outermost element', () => {
71+
const {container} = render(<AlertIcon data-testid="icon" />)
72+
expect(container.firstChild).toHaveAttribute('data-testid', 'icon')
73+
})
74+
7075
describe('size props', () => {
7176
it('respects size="small"', () => {
7277
const {container} = render(<AlertIcon size="small" />)

lib/octicons_react/src/createIconComponent.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ export function createIconComponent(name, defaultClassName, getSVGData) {
2121
size = 16,
2222
verticalAlign = 'text-bottom',
2323
id,
24-
title
24+
title,
25+
style,
26+
...rest
2527
},
2628
forwardedRef
2729
) => {
@@ -36,6 +38,7 @@ export function createIconComponent(name, defaultClassName, getSVGData) {
3638
return (
3739
<svg
3840
ref={forwardedRef}
41+
{...rest}
3942
aria-hidden={labelled ? undefined : 'true'}
4043
tabIndex={tabIndex}
4144
focusable={tabIndex >= 0 ? 'true' : 'false'}
@@ -52,7 +55,8 @@ export function createIconComponent(name, defaultClassName, getSVGData) {
5255
display: 'inline-block',
5356
userSelect: 'none',
5457
verticalAlign,
55-
overflow: 'visible'
58+
overflow: 'visible',
59+
...style
5660
}}
5761
>
5862
{title ? <title>{title}</title> : null}

lib/octicons_react/src/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {Icon} from './__generated__/icons.js'
66

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

9-
export interface OcticonProps {
9+
export interface OcticonProps extends React.ComponentPropsWithoutRef<'svg'> {
1010
'aria-label'?: string
1111
'aria-labelledby'?: string
1212
tabIndex?: number

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,6 @@
5050
"github/no-then": 0,
5151
"eslint-comments/no-use": 0
5252
}
53-
}
53+
},
54+
"packageManager": "[email protected]"
5455
}

0 commit comments

Comments
 (0)