Skip to content
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

feat(Logo): use size prop, deprecate boolean types #268

Merged
merged 1 commit into from
Jun 24, 2020
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
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