-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(flexgrid): Add Row component with react-broadcast support / add …
…gutterless prop FlexGrid / fully unit-tested
- Loading branch information
1 parent
e9b498e
commit 03bb475
Showing
11 changed files
with
221 additions
and
39 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
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,25 @@ | ||
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
import { Subscriber } from 'react-broadcast' | ||
|
||
import { Row as ReactFlexboxGridRow } from 'react-flexbox-grid' | ||
|
||
import safeRest from '../../utils/safeRest' | ||
|
||
const Row = ({ children, ...rest }) => ( | ||
<Subscriber channel="gutterless"> | ||
{gutterless => { | ||
return ( | ||
<ReactFlexboxGridRow {...safeRest(rest)} style={gutterless}> | ||
{children} | ||
</ReactFlexboxGridRow> | ||
) | ||
}} | ||
</Subscriber> | ||
) | ||
|
||
Row.propTypes = { | ||
children: PropTypes.node.isRequired, | ||
} | ||
|
||
export default Row |
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 |
---|---|---|
@@ -1,45 +1,88 @@ | ||
import React from 'react' | ||
import { shallow } from 'enzyme' | ||
|
||
import { mount } from 'enzyme' | ||
import { Grid } from 'react-flexbox-grid' | ||
|
||
import Responsive from '../../Responsive/Responsive' | ||
import FlexGrid from '../FlexGrid' | ||
|
||
describe('FlexGrid', () => { | ||
const doShallow = (props = {}) => shallow(<FlexGrid {...props}>Some grid stuff</FlexGrid>) | ||
const doMount = (props = {}) => { | ||
const wrapper = mount(<FlexGrid {...props}>Some grid stuff</FlexGrid>) | ||
return wrapper.find('Grid') | ||
} | ||
|
||
const doMountWithChildren = (props = {}) => { | ||
const wrapper = mount( | ||
<FlexGrid {...props}> | ||
<Responsive id="responsive" minWidth="md"> | ||
{match => { | ||
return ( | ||
<FlexGrid.Col> | ||
<div>HALF: {match}</div> | ||
</FlexGrid.Col> | ||
) | ||
}} | ||
</Responsive> | ||
<FlexGrid.Row> | ||
<FlexGrid.Col>HALF</FlexGrid.Col> | ||
<FlexGrid.Col>HALF</FlexGrid.Col> | ||
</FlexGrid.Row> | ||
</FlexGrid> | ||
) | ||
|
||
// it('renders', () => { | ||
// const flexGrid = doShallow() | ||
return wrapper.find('Grid') | ||
} | ||
it('renders', () => { | ||
const flexGrid = doMount() | ||
|
||
// expect(flexGrid).toMatchSnapshot() | ||
// }) | ||
expect(flexGrid).toMatchSnapshot() | ||
}) | ||
|
||
it('renders a react-flexbox-grid Grid component', () => { | ||
const flexGrid = doShallow() | ||
const flexGrid = doMount() | ||
|
||
expect(flexGrid).toMatchSelector(Grid) | ||
}) | ||
|
||
it('is fluid by default', () => { | ||
const flexGrid = doShallow() | ||
const flexGrid = doMount() | ||
|
||
expect(flexGrid).toHaveProp('fluid', true) | ||
}) | ||
|
||
// it('passes additional attributes to the element', () => { | ||
// const flexGrid = doShallow({ id: 'the-id', 'data-some-attr': 'some value' }) | ||
it('should render all children related to Grid with no gutter', () => { | ||
const flexGrid = doMountWithChildren({ gutterless: true }) | ||
|
||
const gutterless = { padding: 0, margin: 0 } | ||
const getElementStyleProp = (target, idx) => flexGrid.find(target).get(idx).props.style | ||
|
||
const col1 = getElementStyleProp('Col', 1) | ||
const col2 = getElementStyleProp('Col', 3) | ||
const col3 = getElementStyleProp('Col', 5) | ||
const row = getElementStyleProp('Row', 1) | ||
const NonRelatedElement = flexGrid.find('Responsive') | ||
|
||
expect(col1).toEqual(gutterless) | ||
expect(col2).toEqual(gutterless) | ||
expect(col3).toEqual(gutterless) | ||
expect(row).toEqual(gutterless) | ||
expect(NonRelatedElement).not.toEqual(gutterless) | ||
}) | ||
|
||
it('passes additional attributes to the element', () => { | ||
const flexGrid = doMount({ id: 'the-id', 'data-some-attr': 'some value' }) | ||
|
||
// expect(flexGrid).toHaveProp('id', 'the-id') | ||
// expect(flexGrid).toHaveProp('data-some-attr', 'some value') | ||
// }) | ||
expect(flexGrid).toHaveProp('id', 'the-id') | ||
expect(flexGrid).toHaveProp('data-some-attr', 'some value') | ||
}) | ||
|
||
// it('does not allow custom CSS', () => { | ||
// const flexGrid = doShallow({ | ||
// className: 'my-custom-class', | ||
// style: { color: 'hotpink' }, | ||
// }) | ||
it('does not allow custom CSS', () => { | ||
const flexGrid = doMount({ | ||
className: 'my-custom-class', | ||
style: { color: 'hotpink' }, | ||
}) | ||
|
||
// expect(flexGrid).not.toHaveProp('className', 'my-custom-class') | ||
// expect(flexGrid).not.toHaveProp('style') | ||
// }) | ||
expect(flexGrid).not.toHaveProp('className', 'my-custom-class') | ||
expect(flexGrid).not.toHaveProp('style', { color: 'hotpink' }) | ||
}) | ||
}) |
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,45 @@ | ||
import React from 'react' | ||
import { mount } from 'enzyme' | ||
import { Row as ReactFlexboxGridRow } from 'react-flexbox-grid' | ||
|
||
import FlexGrid from '../FlexGrid' | ||
import Row from '../Row' | ||
|
||
describe('Col', () => { | ||
const doShallow = (props = {}) => { | ||
const wrapper = mount( | ||
<FlexGrid> | ||
<Row {...props}>Some content</Row>) | ||
</FlexGrid> | ||
) | ||
return wrapper.find(ReactFlexboxGridRow) | ||
} | ||
|
||
it('renders', () => { | ||
const col = doShallow() | ||
expect(col).toMatchSnapshot() | ||
}) | ||
|
||
it('renders a react-flexbox-grid Col component', () => { | ||
const row = doShallow() | ||
|
||
expect(row).toMatchSelector(ReactFlexboxGridRow) | ||
}) | ||
|
||
it('passes additional attributes to the react-flexbox-grid Col', () => { | ||
const col = doShallow({ id: 'the-id', 'data-some-attr': 'some value' }) | ||
|
||
expect(col).toHaveProp('id', 'the-id') | ||
expect(col).toHaveProp('data-some-attr', 'some value') | ||
}) | ||
|
||
it('does not allow custom CSS', () => { | ||
const col = doShallow({ | ||
className: 'my-custom-class', | ||
style: { color: 'hotpink' }, | ||
}) | ||
|
||
expect(col).not.toHaveProp('className', 'my-custom-class') | ||
expect(col).not.toHaveProp('style', { color: 'hotpink' }) | ||
}) | ||
}) |
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
13 changes: 13 additions & 0 deletions
13
src/components/FlexGrid/__tests__/__snapshots__/FlexGrid.spec.jsx.snap
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,13 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`FlexGrid renders 1`] = ` | ||
<Grid | ||
fluid={true} | ||
> | ||
<div | ||
className="container-fluid" | ||
> | ||
Some grid stuff | ||
</div> | ||
</Grid> | ||
`; |
11 changes: 11 additions & 0 deletions
11
src/components/FlexGrid/__tests__/__snapshots__/Row.spec.jsx.snap
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,11 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Col renders 1`] = ` | ||
<Row> | ||
<div | ||
className="row" | ||
> | ||
Some content | ||
</div> | ||
</Row> | ||
`; |
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