Skip to content

Commit 7402e69

Browse files
jonrohanlangermankjoshblack
authored
refactor(octicons_react): add support for className, use presentational attributes over inline styles (#1037)
* Concat className with default * join space * update snap * tests * Refactor className concatenation method * Set default value for className variable * Update snapshot size in tree-shaking test * Move to logical properties and deprecate verticalAlign * Fix verticalAlign style property formatting * test: update snapshots, add support for style * chore: update snapshots * chore: add changeset --------- Co-authored-by: Katie Langerman <18661030+langermank@users.noreply.github.com> Co-authored-by: Josh Black <joshblack@github.com>
1 parent 4819803 commit 7402e69

File tree

6 files changed

+15
-8
lines changed

6 files changed

+15
-8
lines changed

.changeset/brown-buttons-search.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+
Update octicons-react to use presentational attributes over inline styles for base styles

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(`"6.29kB"`)
53+
expect(`${bundleSize}kB`).toMatchInlineSnapshot(`"6.292kB"`)
5454
})

lib/octicons_react/src/__tests__/__snapshots__/octicon.js.snap

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ exports[`An icon component matches snapshot 1`] = `
44
<svg
55
aria-hidden="true"
66
class="octicon octicon-alert"
7+
display="inline-block"
78
fill="currentColor"
89
focusable="false"
910
height="16"
10-
style="display: inline-block; user-select: none; vertical-align: text-bottom; overflow: visible;"
11+
overflow="visible"
12+
style="vertical-align: text-bottom;"
1113
viewBox="0 0 16 16"
1214
width="16"
1315
>

lib/octicons_react/src/__tests__/octicon.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ describe('An icon component', () => {
5454

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

6060
it('respects the fill prop', () => {

lib/octicons_react/src/createIconComponent.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export function createIconComponent(name, defaultClassName, getSVGData) {
1616
'aria-label': ariaLabel,
1717
'aria-labelledby': arialabelledby,
1818
tabIndex,
19-
className = defaultClassName,
19+
className = '',
2020
fill = 'currentColor',
2121
size = 16,
2222
verticalAlign = 'text-bottom',
@@ -44,18 +44,17 @@ export function createIconComponent(name, defaultClassName, getSVGData) {
4444
focusable={tabIndex >= 0 ? 'true' : 'false'}
4545
aria-label={ariaLabel}
4646
aria-labelledby={arialabelledby}
47-
className={className}
47+
className={`${defaultClassName} ${className}`.trim()}
4848
role={role}
4949
viewBox={`0 0 ${naturalWidth} ${naturalHeight}`}
5050
width={width}
5151
height={height}
5252
fill={fill}
5353
id={id}
54+
display="inline-block"
55+
overflow="visible"
5456
style={{
55-
display: 'inline-block',
56-
userSelect: 'none',
5757
verticalAlign,
58-
overflow: 'visible',
5958
...style
6059
}}
6160
>

lib/octicons_react/src/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export interface OcticonProps extends React.ComponentPropsWithoutRef<'svg'> {
1717
fill?: string
1818
icon?: Icon | React.ReactNode
1919
size?: number | Size
20+
/** @deprecated use v-align utilities instead */
2021
verticalAlign?: 'middle' | 'text-bottom' | 'text-top' | 'top' | 'unset'
2122
}
2223

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy