Skip to content

Commit

Permalink
feat(Logo): use size prop, deprecate boolean types
Browse files Browse the repository at this point in the history
* fixes #264
  • Loading branch information
Andrew Hobson committed Jun 19, 2020
1 parent b8b45dc commit 84ef83e
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/components/Footer/Logo/Logo.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default {
parameters: {
info: `
Display logo image with optional heading. Used in USWDS 2.0 Footer component.
Source: https://designsystem.digital.gov/components/form-controls/#footer
`,
},
Expand All @@ -19,7 +19,7 @@ export default {
export const Slim = (): React.ReactElement => (
<div className="usa-footer__secondary-section">
<Logo
slim
size="slim"
image={
<img className="usa-footer__logo-img" src={logoImg} alt="Mock logo" />
}
Expand Down
26 changes: 26 additions & 0 deletions src/components/Footer/Logo/Logo.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React from 'react'
import { render } from '@testing-library/react'

jest.mock('../../../deprecation')
import { deprecationWarning } from '../../../deprecation'
import { Logo } from './Logo'

const heading = <h3 className="usa-footer__logo-heading">Swoosh Branding</h3>
Expand All @@ -27,4 +29,28 @@ describe('Logo component', () => {
const { getByText } = render(<Logo image={logoImage} heading={heading} />)
expect(getByText('Swoosh Branding')).toBeInTheDocument()
})

describe('renders with size prop', () => {
beforeEach(() => {
jest.clearAllMocks()
})

it.each([
['big', 'slim', '.mobile-lg\\:grid-col-6'],
['medium', 'slim', '.mobile-lg\\:grid-col-6'],
['slim', 'big', '.grid-gap-2'],
])(
'prefers size to deprecated %s',
(sizeString, deprecatedKey, expectedClass) => {
const size = sizeString as 'big' | 'medium' | 'slim'
const deprecatedProps: { [key: string]: boolean } = {}
deprecatedProps[`${deprecatedKey}`] = true
const { container } = render(
<Logo image={logoImage} size={size} {...deprecatedProps} />
)
expect(container.querySelector(expectedClass)).toBeInTheDocument()
expect(deprecationWarning).toHaveBeenCalledTimes(1)
}
)
})
})
33 changes: 29 additions & 4 deletions src/components/Footer/Logo/Logo.tsx
Original file line number Diff line number Diff line change
@@ -1,34 +1,59 @@
import React from 'react'
import classnames from 'classnames'
import { deprecationWarning } from '../../../deprecation'

type LogoProps = {
size?: 'big' | 'medium' | 'slim'
/**
* @deprecated since 1.6.0, use size
*/
big?: boolean
/**
* @deprecated since 1.6.0, use size
*/
medium?: boolean
/**
* @deprecated since 1.6.0, use size
*/
slim?: boolean
heading?: React.ReactNode
image: React.ReactNode
}

export const Logo = ({
size,
big,
medium,
slim,
heading,
image,
...elementAttributes
}: LogoProps & React.HtmlHTMLAttributes<HTMLElement>): React.ReactElement => {
if (big) {
deprecationWarning('FooterNav property big is deprecated. Use size')
}
if (medium) {
deprecationWarning('FooterNav property medium is deprecated. Use size')
}
if (slim) {
deprecationWarning('FooterNav property slim is deprecated. Use size')
}
const isBig = size ? size === 'big' : big
const isMedium = size ? size === 'medium' : medium
const isSlim = size ? size === 'slim' : slim

const containerClasses = classnames(
'usa-footer__logo grid-row',
{
'mobile-lg:grid-col-6 mobile-lg:grid-gap-2': big || medium,
'grid-gap-2': slim,
'mobile-lg:grid-col-6 mobile-lg:grid-gap-2': isBig || isMedium,
'grid-gap-2': isSlim,
},
elementAttributes.className
)

const columnClasses = classnames({
'mobile-lg:grid-col-auto': big || medium,
'grid-col-auto': slim,
'mobile-lg:grid-col-auto': isBig || isMedium,
'grid-col-auto': isSlim,
})

return (
Expand Down

0 comments on commit 84ef83e

Please sign in to comment.