-
Notifications
You must be signed in to change notification settings - Fork 36
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
✨ DOP-4791 introduces new next/prev button #1156
Changes from 2 commits
af0011c
fffc22a
7d01445
4ad6405
4b86bfb
f8ffa64
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,15 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import styled from '@emotion/styled'; | ||
import Button from '@leafygreen-ui/button'; | ||
import { Body } from '@leafygreen-ui/typography'; | ||
import Icon, { glyphs } from '@leafygreen-ui/icon'; | ||
import { css, cx } from '@leafygreen-ui/emotion'; | ||
import { palette } from '@leafygreen-ui/palette'; | ||
import { useDarkMode } from '@leafygreen-ui/leafygreen-provider'; | ||
import { theme } from '../theme/docsTheme'; | ||
import { getPageTitle } from '../utils/get-page-title'; | ||
import Link from './Link'; | ||
|
||
const StyledContainer = styled.div` | ||
const styledContainer = css` | ||
padding-top: 2em; | ||
padding-bottom: 2.5em; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i noticed in the figma that we want the space between the bottom of the content and the top of the next/prev button to be 88px, although I'm not sure how strict that is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mayaraman19 good question, let me get a confirmation from the design team. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mayaraman19 the PR has been updated. |
||
width: 100%; | ||
|
@@ -21,55 +22,89 @@ const StyledContainer = styled.div` | |
} | ||
`; | ||
|
||
const arrowStyling = css` | ||
line-height: 28px; | ||
align-content: center; | ||
color: var(--arrow-color); | ||
const commonTextStyles = css` | ||
font-size: ${theme.fontSize.small}; | ||
line-height: 20px; | ||
`; | ||
|
||
const titleSpanStyling = css` | ||
line-height: 28px; | ||
--hover-text-decoration-color: var(--underline-color) !important; | ||
const commonNextPrevTextStyling = css` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. total nit: Can we name this without There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mmeigs, thank you for your feedback. I renamed it to be a less confusing. |
||
${commonTextStyles} | ||
font-weight: 500; | ||
`; | ||
|
||
const LinkContentContainer = styled.div` | ||
const nextTextStyling = css` | ||
${commonNextPrevTextStyling} | ||
text-align: end; | ||
`; | ||
|
||
const prevTextStyling = css` | ||
${commonNextPrevTextStyling} | ||
text-align: start; | ||
`; | ||
|
||
const nextPrevTitleTextStyling = css` | ||
${commonTextStyles} | ||
color: ${palette.gray.base}; | ||
`; | ||
|
||
const commonLinkContentContainer = css` | ||
align-items: center; | ||
display: flex; | ||
column-gap: ${theme.size.tiny}; | ||
column-gap: 14px; | ||
`; | ||
|
||
const nextLinkContainer = css` | ||
${commonLinkContentContainer} | ||
flex-direction: row-reverse; | ||
`; | ||
|
||
const prevLinkContainer = css` | ||
${commonLinkContentContainer} | ||
flex-direction: row; | ||
`; | ||
|
||
const NextPrevLink = ({ icon, direction, pageTitle }) => { | ||
const isNext = direction?.toLowerCase() === 'next'; | ||
const isPrev = direction?.toLowerCase() === 'back'; | ||
|
||
return ( | ||
<div className={cx({ [nextLinkContainer]: isNext, [prevLinkContainer]: isPrev })}> | ||
<Button size="large"> | ||
<Icon glyph={icon} /> | ||
</Button> | ||
<div> | ||
<Body className={cx({ [nextTextStyling]: isNext }, { [prevTextStyling]: isPrev })}>{direction}</Body> | ||
<Body className={cx(nextPrevTitleTextStyling)}>{pageTitle}</Body> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
const InternalPageNav = ({ slug, slugTitleMapping, toctreeOrder }) => { | ||
const { darkMode } = useDarkMode(); | ||
const slugIndex = toctreeOrder.indexOf(slug); | ||
const prevSlug = slugIndex > 0 ? toctreeOrder[slugIndex - 1] : null; | ||
const nextSlug = slugIndex < toctreeOrder.length - 1 ? toctreeOrder[slugIndex + 1] : null; | ||
return ( | ||
<StyledContainer | ||
style={{ | ||
'--arrow-color': darkMode ? palette.gray.light2 : palette.black, | ||
'--underline-color': darkMode ? palette.gray.dark1 : palette.gray.light2, | ||
}} | ||
> | ||
<div className={cx(styledContainer)}> | ||
{prevSlug && ( | ||
<React.Fragment> | ||
<LinkContentContainer> | ||
<span className={cx([arrowStyling])}>← </span> | ||
<Link className={cx(titleSpanStyling)} to={prevSlug} title="Previous Section"> | ||
{getPageTitle(prevSlug, slugTitleMapping)} | ||
</Link> | ||
</LinkContentContainer> | ||
</React.Fragment> | ||
<Link to={prevSlug} title="Previous Section"> | ||
<NextPrevLink | ||
icon={glyphs.ArrowLeft.displayName} | ||
direction="Back" | ||
pageTitle={getPageTitle(prevSlug, slugTitleMapping)} | ||
/> | ||
</Link> | ||
)} | ||
{nextSlug && ( | ||
<React.Fragment> | ||
<LinkContentContainer> | ||
<Link className={cx(titleSpanStyling)} to={nextSlug} title="Next Section"> | ||
{getPageTitle(nextSlug, slugTitleMapping)} | ||
</Link> | ||
<span className={cx([arrowStyling])}> →</span> | ||
</LinkContentContainer> | ||
</React.Fragment> | ||
<Link to={nextSlug} title="Next Section"> | ||
<NextPrevLink | ||
icon={glyphs.ArrowRight.displayName} | ||
direction="Next" | ||
pageTitle={getPageTitle(nextSlug, slugTitleMapping)} | ||
/> | ||
</Link> | ||
)} | ||
</StyledContainer> | ||
</div> | ||
); | ||
}; | ||
|
||
|
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.
Tiny nit: Can we name it differently because it's not actually using
styled
anymore? I've seen patterns where usingcss
would be named___styles
or___styling
or___style
.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.
@mmeigs, I opt for __styling to keep consistent with the other styles within this component.