-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #460 from appearhere/feature/LFR-1690
LFR-1690 Add Grid Layout
- Loading branch information
Showing
7 changed files
with
143 additions
and
0 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,14 @@ | ||
.container { | ||
display: grid; | ||
height: auto; | ||
justify-items: center; | ||
align-items:center; | ||
} | ||
|
||
.item { | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
width: 100%; | ||
height: 100%; | ||
} |
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,44 @@ | ||
import React, { Component } from 'react'; | ||
import css from './GridLayout.css'; | ||
import PropTypes from 'prop-types'; | ||
import shortid from 'short-id'; | ||
|
||
export default class GridLayout extends Component { | ||
static propTypes = { | ||
children: PropTypes.oneOfType([ | ||
PropTypes.arrayOf(PropTypes.node), | ||
PropTypes.node | ||
]).isRequired, | ||
col: PropTypes.number, | ||
colGap: PropTypes.number, | ||
rowHeight: PropTypes.number, | ||
}; | ||
|
||
static defaultProps = { | ||
col: 4, | ||
colGap: 1, | ||
rowHeight: 10 | ||
}; | ||
|
||
|
||
render() { | ||
const { col, colGap, rowHeight, children } = this.props; | ||
|
||
return ( | ||
<div | ||
className={css.container} | ||
style={{ | ||
gridTemplateColumns: `repeat(${col}, minmax(0, 1fr))`, | ||
gridGap: `${colGap}rem`, | ||
gridAutoRows: `${rowHeight}rem`, | ||
}} | ||
> | ||
{children.map(item => ( | ||
<div key={shortid.generate()} className={css.item}> | ||
{item} | ||
</div> | ||
))} | ||
</div> | ||
); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
packages/core/src/components/GridLayout/GridLayout.test.js
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,16 @@ | ||
import React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import GridLayout from './GridLayout'; | ||
|
||
it('renders without crashing', () => { | ||
const div = document.createElement('div'); | ||
render( | ||
<GridLayout> | ||
<span>child</span> | ||
<span>child</span> | ||
</GridLayout>, | ||
div, | ||
); | ||
}); | ||
|
||
|
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 |
---|---|---|
|
@@ -49,6 +49,7 @@ export { | |
AutoComplete, | ||
FunnelInputField, | ||
GridFader, | ||
GridLayout, | ||
HeartBtn, | ||
Hero, | ||
SquareHero, | ||
|
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,66 @@ | ||
import React from 'react'; | ||
import { storiesOf } from '@storybook/react'; | ||
import { withKnobs, number } from '@storybook/addon-knobs'; | ||
|
||
import { GridLayout, Modifiers as m } from '@appearhere/bloom'; | ||
|
||
const stories = storiesOf('GridLayout', module); | ||
stories.addDecorator(withKnobs); | ||
|
||
stories.add('default', () => ( | ||
<GridLayout | ||
col={number('Columns', 3)} | ||
colGap={number('Column Gap (rem)', 1)} | ||
rowHeight={number('Row Height (rem)', 10)} | ||
> | ||
<div | ||
className={m.bgSuccess} | ||
style={{ | ||
width: '100%', | ||
height: '100%', | ||
display: 'inline-block', | ||
}} | ||
/> | ||
<div | ||
className={m.bgDanger} | ||
style={{ | ||
width: '100%', | ||
height: '100%', | ||
display: 'inline-block', | ||
}} | ||
/> | ||
<div | ||
className={m.bgPrimary} | ||
style={{ | ||
width: '100%', | ||
height: '100%', | ||
display: 'inline-block', | ||
}} | ||
/> | ||
<div | ||
className={m.bgSuccess} | ||
style={{ | ||
width: '100%', | ||
height: '100%', | ||
display: 'inline-block', | ||
}} | ||
/> | ||
<div | ||
className={m.bgDanger} | ||
style={{ | ||
width: '100%', | ||
height: '100%', | ||
display: 'inline-block', | ||
}} | ||
/> | ||
<div | ||
className={m.bgPrimary} | ||
style={{ | ||
width: '100%', | ||
height: '100%', | ||
display: 'inline-block', | ||
}} | ||
/> | ||
|
||
</GridLayout> | ||
)); |
ddb9215
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to following URLs: