Skip to content

Commit

Permalink
chore(Logo): fix size prop in logo (#3673)
Browse files Browse the repository at this point in the history
The size prop was broken in earlier refactor to ts (#3611). This fix
makes it backwards compatible.

---------

Co-authored-by: Tobias Høegh <tobias@tujo.no>
  • Loading branch information
AadneRo and tujoworker authored Jun 7, 2024
1 parent 49f7a54 commit 375ab5d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
5 changes: 4 additions & 1 deletion packages/dnb-eufemia/src/components/logo/Logo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ function Logo(localProps: LogoProps) {
ratio, // eslint-disable-line
width,
inheritSize,
height,
height: heightProp,
brand: brandProp,
variant,
color,
Expand All @@ -111,6 +111,9 @@ function Logo(localProps: LogoProps) {
return 'dnb'
}, [brand, variant])

/** @deprecated Can remove this in v11 */
const height = parseFloat(size) > 0 ? size : heightProp

// Alt text for the logo does not need to be translated. DNB alt will be the same in english, and sbanken alt should always be in norwegian
const altText =
logoType === 'dnb' ? 'DNB Logo' : 'Sbanken - et konsept fra DNB logo'
Expand Down
16 changes: 12 additions & 4 deletions packages/dnb-eufemia/src/components/logo/__tests__/Logo.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,29 @@ describe('Logo component', () => {

it('should set correct class when inheritColor is set', () => {
render(<Logo inheritColor />)
expect(document.querySelector('.dnb-logo').classList).toContain(
expect(document.querySelector('.dnb-logo')).toHaveClass(
'dnb-logo--inherit-color'
)
})

it('should set correct class when size="inherit" is set', () => {
render(<Logo size="inherit" />)
expect(document.querySelector('.dnb-logo').classList).toContain(
expect(document.querySelector('.dnb-logo')).toHaveClass(
'dnb-logo--inherit-size'
)
})

it('should set height when size is number', () => {
render(<Logo size="48" />)
expect(document.querySelector('.dnb-logo svg')).toHaveAttribute(
'height',
'48'
)
})

it('should set correct class when inheritSize is true', () => {
render(<Logo inheritSize />)
expect(document.querySelector('.dnb-logo').classList).toContain(
expect(document.querySelector('.dnb-logo')).toHaveClass(
'dnb-logo--inherit-size'
)
})
Expand Down Expand Up @@ -80,7 +88,7 @@ describe('Logo component', () => {

it('should set custom class', () => {
render(<Logo className="custom-selector" />)
expect(document.querySelector('[role="img"]').classList).toContain(
expect(document.querySelector('[role="img"]')).toHaveClass(
'custom-selector'
)
})
Expand Down

0 comments on commit 375ab5d

Please sign in to comment.