Skip to content

refactor(octicons_react): add support for className, use presentational attributes over inline styles #1037

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

Merged
merged 15 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/brown-buttons-search.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/octicons': minor
---

Update octicons-react to use presentational attributes over inline styles for base styles
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(`"6.29kB"`)
expect(`${bundleSize}kB`).toMatchInlineSnapshot(`"6.292kB"`)
})
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ exports[`An icon component matches snapshot 1`] = `
<svg
aria-hidden="true"
class="octicon octicon-alert"
display="inline-block"
fill="currentColor"
focusable="false"
height="16"
style="display: inline-block; user-select: none; vertical-align: text-bottom; overflow: visible;"
overflow="visible"
style="vertical-align: text-bottom;"
viewBox="0 0 16 16"
width="16"
>
Expand Down
2 changes: 1 addition & 1 deletion lib/octicons_react/src/__tests__/octicon.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe('An icon component', () => {

it('respects the className prop', () => {
const {container} = render(<AlertIcon className="foo" />)
expect(container.querySelector('svg')).toHaveAttribute('class', 'foo')
expect(container.querySelector('svg')).toHaveAttribute('class', 'octicon octicon-alert foo')
})

it('respects the fill prop', () => {
Expand Down
9 changes: 4 additions & 5 deletions lib/octicons_react/src/createIconComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function createIconComponent(name, defaultClassName, getSVGData) {
'aria-label': ariaLabel,
'aria-labelledby': arialabelledby,
tabIndex,
className = defaultClassName,
className = '',
fill = 'currentColor',
size = 16,
verticalAlign = 'text-bottom',
Expand Down Expand Up @@ -44,18 +44,17 @@ export function createIconComponent(name, defaultClassName, getSVGData) {
focusable={tabIndex >= 0 ? 'true' : 'false'}
aria-label={ariaLabel}
aria-labelledby={arialabelledby}
className={className}
className={`${defaultClassName} ${className}`.trim()}
role={role}
viewBox={`0 0 ${naturalWidth} ${naturalHeight}`}
width={width}
height={height}
fill={fill}
id={id}
display="inline-block"
overflow="visible"
style={{
display: 'inline-block',
userSelect: 'none',
verticalAlign,
overflow: 'visible',
...style
}}
>
Expand Down
1 change: 1 addition & 0 deletions lib/octicons_react/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export interface OcticonProps extends React.ComponentPropsWithoutRef<'svg'> {
fill?: string
icon?: Icon | React.ReactNode
size?: number | Size
/** @deprecated use v-align utilities instead */
verticalAlign?: 'middle' | 'text-bottom' | 'text-top' | 'top' | 'unset'
}

Expand Down
Loading