Skip to content
This repository has been archived by the owner on Mar 31, 2021. It is now read-only.

Commit

Permalink
Page Templates - Add Page.Content component (#79)
Browse files Browse the repository at this point in the history
* WIP

* WIP

* Update snaps
  • Loading branch information
jxom authored Apr 29, 2019
1 parent 00087c2 commit 2f8a400
Show file tree
Hide file tree
Showing 14 changed files with 800 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,15 @@ exports[`fluid renders correctly for a fluid container 1`] = `
.c0 {
width: 100%;
margin: 0 2rem;
padding-left: 2rem;
padding-right: 2rem;
}
@media (max-width:768px) {
.c0 {
padding-left: 1rem;
padding-right: 1rem;
}
}
<div
Expand Down Expand Up @@ -385,7 +393,8 @@ exports[`layout renders correctly for a layout container 1`] = `
@media (max-width:768px) {
.c0 {
margin: 0 1rem;
padding-left: 1rem;
padding-right: 1rem;
}
}
Expand Down
8 changes: 5 additions & 3 deletions packages/fannypack/src/Container/styled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,16 @@ export const Container = styled(Box)<ContainerProps>`
${props =>
props.isFluid &&
css`
margin: ${theme('fannypack.Container.fluidMargin')};
padding-left: ${theme('fannypack.Container.fluidMargin')};
padding-right: ${theme('fannypack.Container.fluidMargin')};
`};
${props =>
props.isLayout &&
(props.isLayout || props.isFluid) &&
css`
@media (max-width: ${theme('fannypack.layout.tabletBreakpoint')}px) {
margin: ${theme('fannypack.Container.tabletMargin')};
padding-left: ${theme('fannypack.Container.tabletMargin')};
padding-right: ${theme('fannypack.Container.tabletMargin')};
}
`};
Expand Down
58 changes: 58 additions & 0 deletions packages/fannypack/src/Page/PageContent.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import * as React from 'react';
import * as PropTypes from 'prop-types';
// @ts-ignore
import _get from 'lodash/get';

import { Box } from '../primitives';
import { withTheme } from '../styled';
import { ContainerProps, LocalContainerProps, containerPropTypes, containerDefaultProps } from '../Container/Container';
import { PageContent as _PageContent } from './styled';

export type LocalPageContentProps = LocalContainerProps & {
children: React.ReactNode;
theme?: Object;
wrapperProps?: Object;
};
export type PageContentProps = ContainerProps & LocalPageContentProps;

export const PageContent: React.FunctionComponent<LocalPageContentProps> = ({
breakpoint,
children,
isFluid,
isLayout,
theme,
wrapperProps,
...props
}) => (
<Box {...wrapperProps}>
<_PageContent
breakpoint={breakpoint}
isFluid={isFluid || !breakpoint}
isLayout={isLayout}
{...props}
{..._get(theme, 'fannypack.Page.PageContent.defaultProps', {})}
>
{children}
</_PageContent>
</Box>
);

export const PageContentPropTypes = {
...containerPropTypes,
children: PropTypes.node.isRequired,
theme: PropTypes.object,
wrapperProps: PropTypes.object
};
PageContent.propTypes = PageContentPropTypes;

export const PageContentDefaultProps = {
...containerDefaultProps,
breakpoint: 'tablet' as 'tablet',
isLayout: true,
theme: {},
wrapperProps: {}
};
PageContent.defaultProps = PageContentDefaultProps;

const C: React.FunctionComponent<PageContentProps> = withTheme(PageContent);
export default C;
23 changes: 23 additions & 0 deletions packages/fannypack/src/Page/__tests__/PageContent.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import * as React from 'react';
import render from '../../_utils/tests/render';
import PageContent from '../PageContent';

it('renders correctly for a basic PageContent', () => {
const { container } = render(<PageContent>test</PageContent>);
expect(container.firstChild).toMatchSnapshot();
});

it('renders correctly for a PageContent with breakpoint', () => {
const { container } = render(<PageContent breakpoint="desktop">test</PageContent>);
expect(container.firstChild).toMatchSnapshot();
});

it('renders correctly for a PageContent with a fluid container', () => {
const { container } = render(<PageContent isFluid>test</PageContent>);
expect(container.firstChild).toMatchSnapshot();
});

it('renders correctly for a PageContent with wrapper props', () => {
const { container } = render(<PageContent wrapperProps={{ backgroundColor: 'red' }}>test</PageContent>);
expect(container.firstChild).toMatchSnapshot();
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,231 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`renders correctly for a PageContent with a fluid container 1`] = `
.c0 {
margin: unset;
padding: unset;
border: unset;
background: unset;
font: unset;
font-family: inherit;
font-size: 100%;
box-sizing: border-box;
background-color: unset;
color: inherit;
}
.c0:focus:not(:focus-visible) {
outline: none;
}
.c2 {
width: 100%;
padding-left: 2rem;
padding-right: 2rem;
}
.c1 {
padding: 2rem 1rem;
padding-top: 1rem;
padding-bottom: 1rem;
}
@media (max-width:768px) {
.c2 {
padding-left: 1rem;
padding-right: 1rem;
}
}
@media (max-width:768px) {
.c1 {
padding-top: 1rem;
padding-bottom: 1rem;
}
}
<div
class="c0"
>
<div
class="c1 c2 c0"
>
test
</div>
</div>
`;

exports[`renders correctly for a PageContent with breakpoint 1`] = `
.c0 {
margin: unset;
padding: unset;
border: unset;
background: unset;
font: unset;
font-family: inherit;
font-size: 100%;
box-sizing: border-box;
background-color: unset;
color: inherit;
}
.c0:focus:not(:focus-visible) {
outline: none;
}
.c2 {
width: 100%;
max-width: 1440px;
margin-left: auto;
margin-right: auto;
}
.c2 {
max-width: 1024px;
}
.c1 {
padding: 2rem 1rem;
}
@media (max-width:768px) {
.c2 {
padding-left: 1rem;
padding-right: 1rem;
}
}
@media (max-width:768px) {
.c1 {
padding-top: 1rem;
padding-bottom: 1rem;
}
}
<div
class="c0"
>
<div
class="c1 c2 c0"
>
test
</div>
</div>
`;

exports[`renders correctly for a PageContent with wrapper props 1`] = `
.c0 {
margin: unset;
padding: unset;
border: unset;
background: unset;
font: unset;
font-family: inherit;
font-size: 100%;
box-sizing: border-box;
background-color: unset;
color: inherit;
}
.c0:focus:not(:focus-visible) {
outline: none;
}
.c2 {
width: 100%;
max-width: 1440px;
margin-left: auto;
margin-right: auto;
}
.c2 {
max-width: 768px;
}
.c1 {
padding: 2rem 1rem;
}
@media (max-width:768px) {
.c2 {
padding-left: 1rem;
padding-right: 1rem;
}
}
@media (max-width:768px) {
.c1 {
padding-top: 1rem;
padding-bottom: 1rem;
}
}
<div
class="c0"
style="background-color: red;"
>
<div
class="c1 c2 c0"
>
test
</div>
</div>
`;

exports[`renders correctly for a basic PageContent 1`] = `
.c0 {
margin: unset;
padding: unset;
border: unset;
background: unset;
font: unset;
font-family: inherit;
font-size: 100%;
box-sizing: border-box;
background-color: unset;
color: inherit;
}
.c0:focus:not(:focus-visible) {
outline: none;
}
.c2 {
width: 100%;
max-width: 1440px;
margin-left: auto;
margin-right: auto;
}
.c2 {
max-width: 768px;
}
.c1 {
padding: 2rem 1rem;
}
@media (max-width:768px) {
.c2 {
padding-left: 1rem;
padding-right: 1rem;
}
}
@media (max-width:768px) {
.c1 {
padding-top: 1rem;
padding-bottom: 1rem;
}
}
<div
class="c0"
>
<div
class="c1 c2 c0"
>
test
</div>
</div>
`;
6 changes: 6 additions & 0 deletions packages/fannypack/src/Page/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import PageContent from './PageContent';

export default { Content: PageContent };

export * from './PageContent';
export { default as PageContent } from './PageContent';
Loading

0 comments on commit 2f8a400

Please sign in to comment.