-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(RC-28267): Create LogoImage component
- Loading branch information
1 parent
4e7ff04
commit bfc1881
Showing
4 changed files
with
119 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import React from 'react' | ||
import { render, screen } from '../__test__/testing-library' | ||
import { LogoImage } from './LogoImage' | ||
|
||
describe('LogoImage', () => { | ||
it('renders with small size', () => { | ||
render(<LogoImage alt='Test Logo' size='small' src='test-image.jpg' />) | ||
const img = screen.getByAltText('Test Logo') | ||
expect(img).toBeInTheDocument() | ||
expect(img).toHaveStyleRule('max-height', '16px') | ||
expect(img).toHaveStyleRule('max-width', '60px') | ||
}) | ||
|
||
it('renders with medium size', () => { | ||
render(<LogoImage alt='Test Logo' size='medium' src='test-image.jpg' />) | ||
const img = screen.getByAltText('Test Logo') | ||
expect(img).toBeInTheDocument() | ||
expect(img).toHaveStyleRule('max-height', '28px') | ||
expect(img).toHaveStyleRule('max-width', '104px') | ||
}) | ||
|
||
it('applies common styles', () => { | ||
render(<LogoImage alt='Test Logo' size='small' src='test-image.jpg' />) | ||
const img = screen.getByAltText('Test Logo') | ||
expect(img).toHaveStyleRule('object-fit', 'contain') | ||
expect(img).toHaveStyleRule('margin', 'auto') | ||
}) | ||
|
||
it('passes src prop correctly', () => { | ||
render(<LogoImage alt='Test Logo' size='small' src='test-image.jpg' />) | ||
const img = screen.getByAltText('Test Logo') | ||
expect(img).toHaveAttribute('src', 'test-image.jpg') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import React from 'react' | ||
import { LogoImage } from './LogoImage' | ||
|
||
export default { | ||
title: 'LogoImage', | ||
component: LogoImage, | ||
argTypes: { | ||
size: { | ||
control: { | ||
type: 'select', | ||
options: ['small', 'medium'], | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
const Template = (args) => <LogoImage {...args} /> | ||
|
||
export const Small = Template.bind({}) | ||
Small.args = { | ||
size: 'small', | ||
src: 'https://s1qa.pclncdn.com/rc-static/v2/partner-logos/AV/AV.png?width=250&height=72&opto&fit=bounds', | ||
alt: 'Avis logo', | ||
} | ||
|
||
export const Medium = Template.bind({}) | ||
Medium.args = { | ||
size: 'medium', | ||
src: 'https://s1qa.pclncdn.com/rc-static/v2/partner-logos/AV/AV.png?width=250&height=72&opto&fit=bounds', | ||
alt: 'Avis logo', | ||
} | ||
|
||
export const MissingImage = Template.bind({}) | ||
MissingImage.args = { | ||
size: 'medium', | ||
src: 'non-existent-image.jpg', | ||
alt: 'Missing image', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import React from 'react' | ||
import styled, { css } from 'styled-components' | ||
import { Image } from '../Image/Image' | ||
|
||
const ImageWrapper = styled(Image)` | ||
${(props) => { | ||
switch (props.size) { | ||
case 'small': | ||
return css` | ||
max-height: 16px; | ||
max-width: 60px; | ||
` | ||
case 'medium': | ||
return css` | ||
max-height: 28px; | ||
max-width: 104px; | ||
` | ||
} | ||
}} | ||
object-fit: contain; | ||
margin: auto; | ||
` | ||
|
||
type Size = 'small' | 'medium' | ||
|
||
/** | ||
* @public | ||
*/ | ||
export type LogoImageProps = { | ||
alt: string | ||
size: Size | ||
src: string | ||
} | ||
|
||
/** | ||
* @public | ||
*/ | ||
export function LogoImage({ alt, size, src }: LogoImageProps) { | ||
return <ImageWrapper alt={alt} src={src} size={size} /> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters