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

✨ DOP-4791 introduces new next/prev button #1156

Merged
merged 6 commits into from
Jul 9, 2024
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
113 changes: 76 additions & 37 deletions src/components/InternalPageNav.js
Original file line number Diff line number Diff line change
@@ -1,75 +1,114 @@
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`
padding-top: 2em;
const containerStyling = css`
padding-bottom: 2.5em;
Copy link
Collaborator

Choose a reason for hiding this comment

The 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

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mayaraman19 good question, let me get a confirmation from the design team.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mayaraman19 the PR has been updated.

width: 100%;
display: flex;
justify-content: space-between;
column-gap: ${theme.size.default};
margin-top: 88px;

@media ${theme.screenSize.upToSmall} {
flex-direction: column-reverse;
row-gap: 64px;
margin-top: 66px;
}

@media print {
display: none;
}
`;

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 nextPrevTextStyling = css`
${commonTextStyles}
font-weight: 500;
`;

const LinkContentContainer = styled.div`
const nextTextStyling = css`
text-align: end;
`;

const prevTextStyling = css`
text-align: start;
`;

const nextPrevTitleTextStyling = css`
${commonTextStyles}
color: ${palette.gray.base};
`;

const commonLinkContentContainerStyling = css`
align-items: center;
display: flex;
column-gap: ${theme.size.tiny};
column-gap: 14px;
`;

const nextLinkContainerStyling = css`
${commonLinkContentContainerStyling}
flex-direction: row-reverse;
`;

const prevLinkContainerStyling = css`
${commonLinkContentContainerStyling}
flex-direction: row;
`;

const NextPrevLink = ({ icon, direction, pageTitle }) => {
const isNext = direction?.toLowerCase() === 'next';
const isPrev = direction?.toLowerCase() === 'back';

return (
<div className={cx({ [nextLinkContainerStyling]: isNext, [prevLinkContainerStyling]: isPrev })}>
<Button size="large">
<Icon glyph={icon} />
</Button>
<div className={cx({ [nextTextStyling]: isNext }, { [prevTextStyling]: isPrev })}>
<Body className={cx(nextPrevTextStyling)}>{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(containerStyling)}>
{prevSlug && (
<React.Fragment>
<LinkContentContainer>
<span className={cx([arrowStyling])}>←&nbsp;</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])}>&nbsp;→</span>
</LinkContentContainer>
</React.Fragment>
<Link to={nextSlug} title="Next Section">
<NextPrevLink
icon={glyphs.ArrowRight.displayName}
direction="Next"
pageTitle={getPageTitle(nextSlug, slugTitleMapping)}
/>
</Link>
)}
</StyledContainer>
</div>
);
};

Expand Down
Loading
Loading