From ef043dbac2ad93405ecbe6a8ed0915bfb33870ec Mon Sep 17 00:00:00 2001 From: Josh Black Date: Fri, 6 Dec 2024 11:26:29 -0600 Subject: [PATCH 1/4] feat(octicons_react): update base icon component to include svg props --- lib/octicons_react/src/__tests__/octicon.js | 5 +++++ lib/octicons_react/src/createIconComponent.js | 8 ++++++-- lib/octicons_react/src/index.d.ts | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/octicons_react/src/__tests__/octicon.js b/lib/octicons_react/src/__tests__/octicon.js index c4a9493a7..56c195e76 100644 --- a/lib/octicons_react/src/__tests__/octicon.js +++ b/lib/octicons_react/src/__tests__/octicon.js @@ -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() + expect(container.firstElement).toHaveAttribute('data-testid', 'icon') + }) + describe('size props', () => { it('respects size="small"', () => { const {container} = render() diff --git a/lib/octicons_react/src/createIconComponent.js b/lib/octicons_react/src/createIconComponent.js index f895c43ec..f5469b5a5 100644 --- a/lib/octicons_react/src/createIconComponent.js +++ b/lib/octicons_react/src/createIconComponent.js @@ -21,7 +21,9 @@ export function createIconComponent(name, defaultClassName, getSVGData) { size = 16, verticalAlign = 'text-bottom', id, - title + title, + style, + ...rest }, forwardedRef ) => { @@ -36,6 +38,7 @@ export function createIconComponent(name, defaultClassName, getSVGData) { return ( = 0 ? 'true' : 'false'} @@ -52,7 +55,8 @@ export function createIconComponent(name, defaultClassName, getSVGData) { display: 'inline-block', userSelect: 'none', verticalAlign, - overflow: 'visible' + overflow: 'visible', + ...style }} > {title ? {title} : null} diff --git a/lib/octicons_react/src/index.d.ts b/lib/octicons_react/src/index.d.ts index 3b7302c5b..357d73528 100644 --- a/lib/octicons_react/src/index.d.ts +++ b/lib/octicons_react/src/index.d.ts @@ -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 From 955626d890319744da8d5d6268d76681178f6a27 Mon Sep 17 00:00:00 2001 From: Josh Black Date: Fri, 6 Dec 2024 11:26:57 -0600 Subject: [PATCH 2/4] chore: add changeset --- .changeset/nice-lamps-peel.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/nice-lamps-peel.md diff --git a/.changeset/nice-lamps-peel.md b/.changeset/nice-lamps-peel.md new file mode 100644 index 000000000..cda7fd482 --- /dev/null +++ b/.changeset/nice-lamps-peel.md @@ -0,0 +1,5 @@ +--- +'@primer/octicons': minor +--- + +Add support for SVG props to base icons From 3d5f21c5db82089fd874066b5a8b6e9c6e7f7f23 Mon Sep 17 00:00:00 2001 From: Josh Black Date: Mon, 9 Dec 2024 14:04:41 -0600 Subject: [PATCH 3/4] chore: add back in packageManager option --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 67f47dbc7..8a5fd9cd6 100644 --- a/package.json +++ b/package.json @@ -50,5 +50,6 @@ "github/no-then": 0, "eslint-comments/no-use": 0 } - } + }, + "packageManager": "yarn@1.22.1" } From bd81b345be28db2be4d3eeec5915358b995c5a1e Mon Sep 17 00:00:00 2001 From: Josh Black Date: Mon, 9 Dec 2024 14:06:40 -0600 Subject: [PATCH 4/4] test: update test to use firstChild --- lib/octicons_react/__tests__/tree-shaking.test.js | 2 +- lib/octicons_react/src/__tests__/octicon.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/octicons_react/__tests__/tree-shaking.test.js b/lib/octicons_react/__tests__/tree-shaking.test.js index a490c44bf..5ce93e15e 100644 --- a/lib/octicons_react/__tests__/tree-shaking.test.js +++ b/lib/octicons_react/__tests__/tree-shaking.test.js @@ -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"`) }) diff --git a/lib/octicons_react/src/__tests__/octicon.js b/lib/octicons_react/src/__tests__/octicon.js index 56c195e76..d21263e84 100644 --- a/lib/octicons_react/src/__tests__/octicon.js +++ b/lib/octicons_react/src/__tests__/octicon.js @@ -69,7 +69,7 @@ describe('An icon component', () => { it('supports additional props on the outermost element', () => { const {container} = render() - expect(container.firstElement).toHaveAttribute('data-testid', 'icon') + expect(container.firstChild).toHaveAttribute('data-testid', 'icon') }) describe('size props', () => {