-
Notifications
You must be signed in to change notification settings - Fork 81
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
Add big footer #142
Merged
Merged
Add big footer #142
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
85f2fac
add: ExtendedNav in FooterNav
haworku ece71e0
add: SignupForm and implement in Footer
haworku 524663d
chore: cleanup stories formatting
haworku 7e26c83
Organize stories in subdirectories and add info
haworku a7c4948
Clean up stories tense and order
haworku File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
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
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 |
---|---|---|
@@ -1,36 +1,95 @@ | ||
import React from 'react' | ||
import classnames from 'classnames' | ||
|
||
type ExtendedNavLinks = [React.ReactNode[]] | ||
|
||
type FooterNavProps = { | ||
big?: boolean | ||
medium?: boolean | ||
slim?: boolean | ||
links: React.ReactNode[] | ||
/* | ||
Union type. Array of navigation links or multidimensional array of ExtendedNavLinks. | ||
ExtendedNavLinks are ordered sub arrays that will be displayed as columns, with the first element used as the section heading. | ||
ExtendedNavLinks can only be used with "big" prop size | ||
*/ | ||
links: React.ReactNode[] | ExtendedNavLinks | ||
} | ||
|
||
function isExtendedNavLinks( | ||
links: React.ReactNode[] | ExtendedNavLinks | ||
): links is ExtendedNavLinks { | ||
return (links as ExtendedNavLinks)[0].constructor === Array | ||
} | ||
|
||
export const FooterNav = ( | ||
props: FooterNavProps & React.HTMLAttributes<HTMLElement> | ||
): React.ReactElement => { | ||
const { medium, slim, links, ...elementAttributes } = props | ||
const { big, medium, slim, links, ...elementAttributes } = props | ||
|
||
const navClasses = classnames(`usa-footer__nav`, elementAttributes.className) | ||
const listItemClasses = classnames( | ||
'desktop:grid-col-auto usa-footer__primary-content', | ||
{ | ||
'mobile-lg:grid-col-4': medium, | ||
'mobile-lg:grid-col-4': big || medium, | ||
'mobile-lg:grid-col-6': slim, | ||
} | ||
) | ||
|
||
return ( | ||
<nav className={navClasses} aria-label="Footer navigation"> | ||
<ul className="grid-row grid-gap"> | ||
{links.map((link, i) => ( | ||
<li key={`navLink-${i}`} className={listItemClasses}> | ||
<nav | ||
{...elementAttributes} | ||
className="usa-footer__nav" | ||
aria-label="Footer navigation"> | ||
{big && isExtendedNavLinks(links) && <ExtendedNav nestedLinks={links} />} | ||
|
||
{!isExtendedNavLinks(links) && ( | ||
<ul className="grid-row grid-gap"> | ||
{links.map((link, i) => ( | ||
<li key={`navLink-${i}`} className={listItemClasses}> | ||
{link} | ||
</li> | ||
))} | ||
</ul> | ||
)} | ||
</nav> | ||
) | ||
} | ||
|
||
const Section = ({ | ||
links, | ||
}: { | ||
links: React.ReactNode[] | ||
}): React.ReactElement => { | ||
const primaryLinkOrHeading = links[0] | ||
const secondaryLinks = links.slice(1) | ||
|
||
return ( | ||
<section className="usa-footer__primary-content usa-footer__primary-content--collapsible"> | ||
<h4 className="usa-footer__primary-link">{primaryLinkOrHeading}</h4> | ||
<ul className="usa-list usa-list--unstyled"> | ||
{secondaryLinks.map((link, i) => ( | ||
<li key={`navLink-${i}`} className="usa-footer__secondary-link"> | ||
{link} | ||
</li> | ||
))} | ||
</ul> | ||
</nav> | ||
</section> | ||
) | ||
} | ||
|
||
const ExtendedNav = ({ | ||
nestedLinks, | ||
}: { | ||
nestedLinks: ExtendedNavLinks | ||
}): React.ReactElement => { | ||
return ( | ||
<div className="grid-row grid-gap-4"> | ||
{nestedLinks.map((links, i) => ( | ||
<div | ||
key={`linkSection-${i}`} | ||
className="mobile-lg:grid-col-6 desktop:grid-col-3"> | ||
<Section links={links} /> | ||
</div> | ||
))} | ||
</div> | ||
) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just as a heads up, I created a list component that could be used here too. It's not merged in yet though, so 🤷
https://github.com/trussworks/react-uswds/blob/61535c9510d4d528f02b09aaaa45de8ff0ebd789/src/components/header/List/List.stories.tsx