Skip to content

Commit 8caa48e

Browse files
authored
Added site wrap component (#36)
* Added site wrap component * Apply baseline text styles
1 parent 81a26c5 commit 8caa48e

File tree

8 files changed

+139
-2
lines changed

8 files changed

+139
-2
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import React from 'react'
2+
import PropTypes from 'prop-types'
3+
4+
import { BaseComponent } from '../tailwind'
5+
import { Footer } from '../footer'
6+
import { withTheme } from '../theme'
7+
8+
const Layout = ({ is, theme, children, ...rest }) => {
9+
let footer
10+
11+
React.Children.forEach(children, child => {
12+
const { type } = child
13+
if (type && (type === Footer || type.displayName === Footer.displayName)) {
14+
footer = child
15+
}
16+
})
17+
18+
return (
19+
<BaseComponent
20+
is={is}
21+
flex={[true, 'col']}
22+
minH="screen"
23+
leading="normal"
24+
font={theme.text.family.body}
25+
text={[theme.text.size.body[1], theme.textColors.body]}
26+
{...rest}
27+
>
28+
<div className="flex-auto flex-no-shrink">
29+
{React.Children.map(children, child => {
30+
if (child === footer) return false
31+
return child
32+
})}
33+
</div>
34+
<div className="flex-auto flex-no-shrink flex-no-grow">{footer}</div>
35+
</BaseComponent>
36+
)
37+
}
38+
39+
Layout.propTypes = {
40+
is: PropTypes.oneOfType([PropTypes.string, PropTypes.func, PropTypes.object]),
41+
theme: PropTypes.shape({}).isRequired,
42+
children: PropTypes.node,
43+
}
44+
45+
Layout.defaultProps = {
46+
is: 'div',
47+
children: undefined,
48+
}
49+
50+
export { Layout as component }
51+
export default withTheme(Layout)
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import React from 'react'
2+
import { shallow } from 'enzyme'
3+
4+
import { defaultTheme } from '../../theme'
5+
import { component as SiteWrap } from '../SiteWrap'
6+
import { Header } from '../../header'
7+
import { Footer } from '../../footer'
8+
9+
const setup = (testProps = {}) => {
10+
const props = Object.assign({ theme: defaultTheme }, testProps)
11+
12+
const wrapper = shallow(
13+
<SiteWrap {...props}>
14+
<Header>Header</Header>
15+
<p>Body</p>
16+
<Footer>Footer</Footer>
17+
</SiteWrap>,
18+
)
19+
20+
return {
21+
props,
22+
wrapper,
23+
}
24+
}
25+
26+
describe('SiteWrap', () => {
27+
it('renders matching snapshot', () => {
28+
const { wrapper } = setup()
29+
30+
expect(wrapper).toMatchSnapshot()
31+
})
32+
})
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`SiteWrap renders matching snapshot 1`] = `
4+
<BaseComponent
5+
flex={
6+
Array [
7+
true,
8+
"col",
9+
]
10+
}
11+
font="sans"
12+
is="div"
13+
leading="normal"
14+
minH="screen"
15+
text={
16+
Array [
17+
"base",
18+
"grey-darkest",
19+
]
20+
}
21+
>
22+
<div
23+
className="flex-auto flex-no-shrink"
24+
>
25+
<WithTheme(Header)
26+
key=".0"
27+
>
28+
Header
29+
</WithTheme(Header)>
30+
<p
31+
key=".1"
32+
>
33+
Body
34+
</p>
35+
</div>
36+
<div
37+
className="flex-auto flex-no-shrink flex-no-grow"
38+
>
39+
<WithTheme(Footer)>
40+
Footer
41+
</WithTheme(Footer)>
42+
</div>
43+
</BaseComponent>
44+
`;

src/components/siteWrap/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default as SiteWrap } from './SiteWrap'

src/components/siteWrap/readme.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
By default will fill the full screen size regardless of child content lenght to create a sticky footer. Also applies baseline body text styling.
2+
3+
```jsx
4+
<SiteWrap minH={0} h={64}>
5+
<p>Some short page content</p>
6+
<Footer>Footer pinned to the bottom of the screen</Footer>
7+
</SiteWrap>
8+
```

src/components/typography/Text.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const Text = ({
2626
font={[theme.text.family.body, bold && 'bold']}
2727
text={[
2828
theme.text.size.body[(lead ? theme.text.size.body.length : size) - 1],
29-
!brand && `text-${theme.textColors.body}`,
29+
!brand && theme.textColors.body,
3030
...getAsArray(text),
3131
]}
3232
m={isParagraph ? { b: theme.spacing.md } : undefined}

src/components/typography/__tests__/__snapshots__/Text.jsx.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ exports[`Text renders matching snapshot 1`] = `
1818
text={
1919
Array [
2020
"base",
21-
"text-grey-darkest",
21+
"grey-darkest",
2222
]
2323
}
2424
>

src/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export * from './components/grid'
88
export * from './components/header'
99
export * from './components/list'
1010
export * from './components/main'
11+
export * from './components/siteWrap'
1112
export * from './components/typography'
1213

1314
export * from './components/tailwind'

0 commit comments

Comments
 (0)