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

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

Merged
merged 4 commits into from
Dec 9, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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": "yarn@1.22.1"
}
Loading