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

Add Back Button For /product-details page #254

Merged
merged 7 commits into from
Mar 17, 2019
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
1 change: 0 additions & 1 deletion src/components/Layout/Layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ injectGlobal`
`;

const Viewport = styled(`div`)`
overflow-x: hidden;
width: 100%;
`;

Expand Down
56 changes: 56 additions & 0 deletions src/components/ProductDetails/BackButton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import React from 'react';
import { navigate } from 'gatsby';
import PropTypes from 'prop-types';
import styled from 'react-emotion';
import { MdArrowBack } from 'react-icons/md';

import { Button } from '../shared/Buttons';

import { spacing } from '../../utils/styles';

const BackLinkRoot = styled(`div`)`
background: linear-gradient(
to top,
rgba(255, 255, 255, 1) 0%,
rgba(255, 255, 255, 1) 76%,
rgba(255, 255, 255, 0.75) 76%,
rgba(255, 255, 255, 0.75) 82%,
rgba(255, 255, 255, 0.5) 82%,
rgba(255, 255, 255, 0.5) 88%,
rgba(255, 255, 255, 0.25) 88%,
rgba(255, 255, 255, 0.25) 94%,
rgba(255, 255, 255, 0) 94%,
rgba(255, 255, 255, 0) 100%
);
bottom: 0;
left: 0;
padding: ${spacing.xl}px ${spacing.md}px ${spacing.md}px 0;
position: sticky;
top: 38px;
width: 100%;
`;

const BackToProduct = styled(Button)`
width: auto;
`;

const goBack = () => {
const urlParams = new URLSearchParams(window.location.search);
const fromProduct = urlParams.has('fromProduct');
fromProduct ? history.back() : navigate('/');
};

const BackButton = ({ children, className }) => (
<BackLinkRoot className={className}>
<BackToProduct onClick={goBack}>
<MdArrowBack /> {children}
</BackToProduct>
</BackLinkRoot>
);

BackButton.propTypes = {
children: PropTypes.node.isRequired,
className: PropTypes.string
};

export default BackButton;
15 changes: 11 additions & 4 deletions src/components/ProductDetails/ProductDetails.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
import React from 'react';
import styled from 'react-emotion';
import SizeChartTable from './SizeChartTable';
import BackButton from './BackButton';

import {
Heading as BaseHeading,
TextContainer,
UnorderedList
} from '../shared/Typography';
import { colors, spacing, dimensions } from '../../utils/styles';
import { colors, spacing, dimensions, breakpoints } from '../../utils/styles';

const Heading = styled(BaseHeading)`
margin-bottom: -${spacing.sm}px;
`;

const ProductTextContainer = styled(TextContainer)`
padding: ${spacing.xl}px;
`;

const Section = styled(`section`)`
padding-top: calc(${dimensions.headerHeight} + ${spacing.sm}px);
`;
Expand Down Expand Up @@ -93,8 +99,9 @@ class ProductDetails extends React.Component {
const { units } = this.state;

return (
<TextContainer>
<ProductTextContainer>
<Heading>Product Details</Heading>
<BackButton>Back to Product</BackButton>
<Section id="size-chart">
<SectionHeading>Size Chart</SectionHeading>
<UnitSelector unit={units} setUnits={this.changeUnits} />
Expand All @@ -107,7 +114,7 @@ class ProductDetails extends React.Component {
</p>
</Section>
<Section id="materials-fit">
<SectionHeading>T-Shirt Materials & Fit</SectionHeading>
<SectionHeading>T-Shirt Materials &amp; Fit</SectionHeading>
<p>
To help you find the right size and fit, here are some additional
details about our t-shirts.
Expand Down Expand Up @@ -146,7 +153,7 @@ class ProductDetails extends React.Component {
but they require a little TLC.
</p>
</Section>
</TextContainer>
</ProductTextContainer>
);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/components/ProductPage/ProductForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,11 @@ class ProductForm extends Component {
{isOutOfStock ? <MdSentimentDissatisfied /> : <MdShoppingCart />}
</AddToCartButton>
<InfoLinks>
<Link to="/product-details#materials-fit">
<span>Materials & Fit</span>
<Link to="/product-details?fromProduct#materials-fit">
<span>Materials &amp; Fit</span>
</Link>
&nbsp; • &nbsp;
<Link to="/product-details#care-instructions">
<Link to="/product-details?fromProduct#care-instructions">
<span>Care instructions</span>
</Link>
</InfoLinks>
Expand Down