-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(asCol): add asCol HOC
- Loading branch information
Showing
14 changed files
with
184 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Col should override defaults when passing margin prop 1`] = ` | ||
Object { | ||
"margin": 1, | ||
} | ||
`; | ||
|
||
exports[`Col should render a Grid with col margins ([0, 1.5, 3]) 1`] = ` | ||
Object { | ||
"className": "{\\"border\\":\\"0 transparent solid\\",\\"boxSizing\\":\\"border-box\\",\\"display\\":\\"flex\\",\\"flexFlow\\":\\"row wrap\\",\\"width\\":\\"100%\\"} {\\"flexGrow\\":1}", | ||
"style": Object { | ||
"borderBottomWidth": 24, | ||
"borderLeftWidth": 12, | ||
"borderRightWidth": 12, | ||
"borderTopWidth": 0, | ||
}, | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import React from 'react' | ||
import { mount } from 'enzyme' | ||
import log from '../log' | ||
import asCol from './index' | ||
|
||
describe('Col', () => { | ||
let wrapper | ||
const Col = asCol('div') | ||
|
||
it('should render a Grid with col margins ([0, 1.5, 3])', () => { | ||
wrapper = mount(<Col />) | ||
const gridProps = wrapper.find('div').props() | ||
expect(gridProps).toMatchSnapshot() | ||
}) | ||
|
||
it('should override defaults when passing margin prop', () => { | ||
wrapper = mount(<Col margin={1} />) | ||
const gridProps = wrapper.find('Grid').props() | ||
expect(gridProps).toMatchSnapshot() | ||
}) | ||
|
||
it('should render custom elements', () => { | ||
const StrongCol = asCol('strong') | ||
|
||
wrapper = mount(<StrongCol />) | ||
expect(wrapper.find('strong').length).toBe(1) | ||
}) | ||
|
||
fit('should not error when passed valid props', () => { | ||
spyOn(log, 'error') | ||
|
||
wrapper = mount(<Col margin={0} />) | ||
|
||
expect(log.error).not.toHaveBeenCalled() | ||
}) | ||
|
||
afterEach(() => { | ||
if (wrapper) { | ||
wrapper.unmount() | ||
} | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// @flow | ||
import * as React from 'react' | ||
import asGrid from '../asGrid' | ||
import type { OneResolution } from '../types' | ||
|
||
function mapProps(props): OneResolution { | ||
const defaultProps: OneResolution = { | ||
marginTop: 0, | ||
marginRight: 'gutter/2', | ||
marginBottom: 'verticalGutter', | ||
marginLeft: 'gutter/2', | ||
} | ||
|
||
return props.margin !== undefined | ||
? props | ||
: { | ||
...defaultProps, | ||
...props, | ||
} | ||
} | ||
|
||
export default function asCol(Component: React.ComponentType<*> | string) { | ||
return asGrid(Component, mapProps) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// @flow | ||
import * as React from 'react' | ||
import asCol from './asCol' | ||
import type { GridProps } from './types' | ||
|
||
export default (asCol('div'): React.ComponentType<GridProps>) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.