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: header component #83 #102

Merged
merged 48 commits into from
May 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
908f543
Start work on header component
eamahanna Apr 22, 2020
9fd036c
Revise header structure
eamahanna Apr 22, 2020
8804604
Add secondary nav
eamahanna Apr 22, 2020
3b51e7e
Fix secondary nav
eamahanna Apr 22, 2020
22a2b57
Fix up header
eamahanna Apr 23, 2020
1e0c556
Fix test
eamahanna Apr 23, 2020
4eb09e4
Add changelog update
eamahanna Apr 23, 2020
7517c88
Add title component
eamahanna Apr 24, 2020
fc8312a
Fix title markup
eamahanna Apr 27, 2020
df2caf6
Refactor to have two types of drop down links
eamahanna Apr 27, 2020
4b6d1b4
Updates from PR review
eamahanna Apr 28, 2020
05df985
Keep it simple
eamahanna Apr 28, 2020
48f7e91
Fix props
eamahanna Apr 28, 2020
eed81e4
Fix div prop
eamahanna Apr 28, 2020
2bff179
Fix extended menu prop
eamahanna Apr 28, 2020
db7ffc2
Fix stories
eamahanna Apr 28, 2020
c6dcecc
Fix stories
eamahanna Apr 28, 2020
aa824e6
Add mobile functionality
eamahanna Apr 29, 2020
47901ed
Add list component
eamahanna Apr 29, 2020
caccb16
Add extended header
eamahanna Apr 29, 2020
b61ee71
Remove title prop
eamahanna Apr 29, 2020
86b0413
Merge in develop
eamahanna Apr 30, 2020
4c0efe4
Merge header branch
eamahanna May 1, 2020
ee10946
Merge pull request #105 from trussworks/em-title-component-#83
eamahanna May 1, 2020
cbaea66
Update props
eamahanna May 1, 2020
78f9953
Merge branch 'em-create-header-component-#83' of github.com:trusswork…
eamahanna May 1, 2020
ff7137a
Move title component
eamahanna May 1, 2020
84028bb
Merge branch 'develop' into em-create-header-component-#83
eamahanna May 1, 2020
babb09d
Update search input in header
eamahanna May 1, 2020
7ccd295
Change drop down menu props
eamahanna May 4, 2020
9c80a67
Refactor components
eamahanna May 5, 2020
30e37bd
Fix test
eamahanna May 5, 2020
61535c9
Update changelog
eamahanna May 5, 2020
990b4ba
Merge in develop
eamahanna May 6, 2020
f86ee97
Add storybook folders
eamahanna May 6, 2020
99d2449
Add tests
eamahanna May 6, 2020
09a8fad
Updates from PR review
eamahanna May 7, 2020
0882e53
PR Updates
eamahanna May 12, 2020
0240976
Update change log
eamahanna May 12, 2020
14d7612
Merge branch 'develop' into em-create-header-component-#83
eamahanna May 12, 2020
48c0e7b
Update links
eamahanna May 12, 2020
b4553d7
Update NavList props
eamahanna May 12, 2020
519c765
Add individual nav button components
eamahanna May 13, 2020
3ef7a1f
Add components to index exports
eamahanna May 13, 2020
e8eac06
Fix false
eamahanna May 13, 2020
3cc7a53
Add isCurrent
eamahanna May 13, 2020
56bd00a
Final PR updates
eamahanna May 18, 2020
9edf49e
feat: merge in develop
eamahanna May 18, 2020
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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

All notable changes to this project will be documented in this file. This file is generated automatically based on commit messages. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

## UNRELEASED
## [1.2.0] - 2020-04-30

- feat: Added components for the header and extended header (Header, NavList, MegaMenu, Menu, NavMenuButton, NavCloseButton, NavDropDownButton, PrimaryNav, Title, ExtendedNav)
- chore: Added yarn audit check to dangerfile (on package change)
- feat: Added search component
- feat: Added Grid, GridContainer components
Expand Down
2 changes: 1 addition & 1 deletion src/components/forms/Checkbox/Checkbox.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react'
import { Checkbox } from './Checkbox'

export default {
title: 'Checkbox',
title: 'Forms/Checkbox',
parameters: {
info: `
USWDS 2.0 Checkbox component
Expand Down
2 changes: 1 addition & 1 deletion src/components/forms/Dropdown/Dropdown.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Dropdown } from './Dropdown'
import { Label } from '../Label/Label'

export default {
title: 'Dropdown',
title: 'Forms/Dropdown',
parameters: {
info: `
USWDS 2.0 Dropdown component
Expand Down
2 changes: 1 addition & 1 deletion src/components/forms/ErrorMessage/ErrorMessage.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react'
import { ErrorMessage } from './ErrorMessage'

export default {
title: 'ErrorMessage',
title: 'Forms/ErrorMessage',
parameters: {
info: `
USWDS 2.0 ErrorMessage component
Expand Down
2 changes: 1 addition & 1 deletion src/components/forms/Fieldset/Fieldset.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Checkbox } from '../Checkbox/Checkbox'
import { Radio } from '../Radio/Radio'

export default {
title: 'Fieldset',
title: 'Forms/Fieldset',
parameters: {
info: `
USWDS 2.0 Fieldset component
Expand Down
2 changes: 1 addition & 1 deletion src/components/forms/Form/Form.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { TextInput } from '../TextInput/TextInput'
import { Textarea } from '../Textarea/Textarea'

export default {
title: 'Form',
title: 'Forms/Form',
parameters: {
info: `
USWDS 2.0 Form component
Expand Down
2 changes: 1 addition & 1 deletion src/components/forms/FormGroup/FormGroup.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { TextInput } from '../TextInput/TextInput'
import { ErrorMessage } from '../ErrorMessage/ErrorMessage'

export default {
title: 'FormGroup',
title: 'Forms/FormGroup',
parameters: {
info: `
USWDS 2.0 FormGroup component
Expand Down
2 changes: 1 addition & 1 deletion src/components/forms/Label/Label.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react'
import { Label } from './Label'

export default {
title: 'Label',
title: 'Forms/Label',
parameters: {
info: `
USWDS 2.0 Label component
Expand Down
2 changes: 1 addition & 1 deletion src/components/forms/Radio/Radio.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react'
import { Radio } from './Radio'

export default {
title: 'Radio',
title: 'Forms/Radio',
parameters: {
info: `
USWDS 2.0 Radio component
Expand Down
2 changes: 1 addition & 1 deletion src/components/forms/TextInput/TextInput.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react'
import { TextInput } from './TextInput'

export default {
title: 'TextInput',
title: 'Forms/TextInput',
parameters: {
info: `
USWDS 2.0 TextInput component
Expand Down
2 changes: 1 addition & 1 deletion src/components/forms/Textarea/Textarea.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react'
import { Textarea } from './Textarea'

export default {
title: 'Textarea',
title: 'Forms/Textarea',
parameters: {
info: `
USWDS 2.0 Textarea component
Expand Down
43 changes: 43 additions & 0 deletions src/components/header/ExtendedNav/ExtendedNav.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import React from 'react'
import { ExtendedNav } from './ExtendedNav'

export default {
title: 'Header/ExtendedNav',
parameters: {
info: `
USWDS 2.0 ExtendedNav component used within the Header component

Source: https://designsystem.digital.gov/components/header/
`,
},
}

const mockToggle = (): void => {
/* mock submit fn */
}

const testPrimaryItems = [
<a href="#linkOne" key="one" className="usa-nav__link">
<span>Simple link</span>
</a>,
<a href="#linkTwo" key="two" className="usa-nav__link">
<span>Simple link Two</span>
</a>,
]

const testSecondaryItems = [
<a href="#linkOne" key="one">
Simple link
</a>,
<a href="#linkTwo" key="two">
Simple link Two
</a>,
]

export const defaultExtendedNav = (): React.ReactElement => (
<ExtendedNav
onToggleMobileNav={mockToggle}
primaryItems={testPrimaryItems}
secondaryItems={testSecondaryItems}
/>
)
112 changes: 112 additions & 0 deletions src/components/header/ExtendedNav/ExtendedNav.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import React from 'react'
import { render, fireEvent } from '@testing-library/react'

import { ExtendedNav } from './ExtendedNav'

const testPrimaryItems = [
<a className="usa-current" href="#linkOne" key="one">
Simple link one
</a>,
<a href="#linkTwo" key="two">
Simple link two
</a>,
]

const testSecondaryItems = [
<a className="usa-current" href="#linkThree" key="three">
<span>Simple link three</span>
</a>,
<a href="#linkFour" key="four">
<span>Simple link four</span>
</a>,
]

const onToggleMobileNav = (): void => {
/* mock submit fn */
}

describe('ExtendedNav component', () => {
it('renders without errors', () => {
const { queryByRole } = render(
<ExtendedNav
onToggleMobileNav={onToggleMobileNav}
primaryItems={testPrimaryItems}
secondaryItems={testSecondaryItems}
/>
)
expect(queryByRole('navigation')).toBeInTheDocument()
})

it('renders primary items', () => {
const { getByText } = render(
<ExtendedNav
onToggleMobileNav={onToggleMobileNav}
primaryItems={testPrimaryItems}
secondaryItems={testSecondaryItems}
/>
)
expect(getByText('Simple link one')).toBeInTheDocument()
expect(getByText('Simple link two')).toBeInTheDocument()
})

it('renders secondary items', () => {
const { getByText } = render(
<ExtendedNav
onToggleMobileNav={onToggleMobileNav}
primaryItems={testPrimaryItems}
secondaryItems={testSecondaryItems}
/>
)
expect(getByText('Simple link three')).toBeInTheDocument()
expect(getByText('Simple link four')).toBeInTheDocument()
})

it('renders nav button', () => {
const { getByTestId } = render(
<ExtendedNav
onToggleMobileNav={onToggleMobileNav}
primaryItems={testPrimaryItems}
secondaryItems={testSecondaryItems}
/>
)
expect(getByTestId('navCloseButton')).toBeInTheDocument()
})

it('implements an onClick handler', () => {
const onToggleMobileNav = jest.fn()
const { getByTestId } = render(
<ExtendedNav
onToggleMobileNav={onToggleMobileNav}
primaryItems={testPrimaryItems}
secondaryItems={testSecondaryItems}
/>
)

fireEvent.click(getByTestId('navCloseButton'))
expect(onToggleMobileNav).toHaveBeenCalledTimes(1)
})

it('renders the is-visible class when mobileExpanded is true', () => {
const { container } = render(
<ExtendedNav
onToggleMobileNav={onToggleMobileNav}
primaryItems={testPrimaryItems}
secondaryItems={testSecondaryItems}
mobileExpanded={true}
/>
)
expect(container.querySelector('.is-visible')).toBeInTheDocument()
})

it('does not render the is-visible class when mobileExpanded is false', () => {
const { container } = render(
<ExtendedNav
onToggleMobileNav={onToggleMobileNav}
primaryItems={testPrimaryItems}
secondaryItems={testSecondaryItems}
mobileExpanded={false}
/>
)
expect(container.querySelector('.is-visible')).not.toBeInTheDocument()
})
})
51 changes: 51 additions & 0 deletions src/components/header/ExtendedNav/ExtendedNav.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import React from 'react'
import classnames from 'classnames'

import { NavCloseButton } from '../NavCloseButton/NavCloseButton'
import { NavList } from '../NavList/NavList'

type ExtendedNavProps = {
primaryItems: React.ReactNode[]
secondaryItems: React.ReactNode[]
onToggleMobileNav?: (
event: React.MouseEvent<HTMLButtonElement, MouseEvent>
) => void
mobileExpanded?: boolean
}

export const ExtendedNav = (
props: ExtendedNavProps & React.HTMLAttributes<HTMLElement>
): React.ReactElement => {
const {
primaryItems,
secondaryItems,
mobileExpanded = false,
children,
className,
onToggleMobileNav,
...navProps
} = props

const classes = classnames(
'usa-nav',
{
'is-visible': mobileExpanded,
},
className
)

return (
<nav className={classes} {...navProps}>
<div className="usa-nav__inner">
<NavCloseButton onClick={onToggleMobileNav} />
<NavList items={primaryItems} primary={true} />
<div className="usa-nav__secondary">
<NavList items={secondaryItems} secondary={true} />
{children}
</div>
</div>
</nav>
)
}

export default ExtendedNav
Loading