Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hidden columns #82

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions doc/app/components/home/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Section from '../section';
import Box from '../box';

import responsiveMD from './responsive';
import responsiveHideMD from './responsiveHide';
import fluidMD from './fluid';
import offsetMD from './offset';
import autoWidthMD from './auto-width';
Expand Down Expand Up @@ -44,6 +45,25 @@ const Home = () => (
<Markdown html = {responsiveMD} />
</Row>
</Section>
<Section title = "Hidden" description = "Set column size option to 0 to hide the contents of a column">
<h3><code>Medium and Large Only</code></h3>
<Row>
<Box type="row" xs={0} sm={0} md={2} lg={9} />
<Box type="row" xs={0} sm={0} md={2} lg={1} />
<Box type="row" xs={0} sm={0} md={4} lg={1} />
<Box type="row" xs={0} sm={0} md={4} lg={1} />
</Row>
<h3><code>XS and Small Only</code></h3>
<Row>
<Box type="row" xs={2} sm={1} md={0} lg={0} />
<Box type="row" xs={4} sm={1} md={0} lg={0} />
<Box type="row" xs={4} sm={9} md={0} lg={0} />
<Box type="row" xs={2} sm={1} md={0} lg={0} />
</Row>
<Row>
<Markdown html = {responsiveHideMD} />
</Row>
</Section>
<Section title = "Fluid" description = "Percent based width allow fluid resizing of columns and rows.">
<Row>
<Box type="row" xs={12} sm={3} md={2} lg={1} />
Expand Down
14 changes: 14 additions & 0 deletions doc/app/components/home/responsiveHide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
```jsx
<Row>
<Col xs={0} sm={0} md={2} lg={9} />
<Col xs={0} sm={0} md={2} lg={1} />
<Col xs={0} sm={0} md={4} lg={1} />
<Col xs={0} sm={0} md={4} lg={1} />
</Row>
<Row>
<Col xs={2} sm={1} md={0} lg={0} />
<Col xs={4} sm={1} md={0} lg={0} />
<Col xs={4} sm={9} md={0} lg={0} />
<Col xs={2} sm={1} md={0} lg={0} />
</Row>
```
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"expect": "^1.13.0",
"express": "^4.13.3",
"extract-text-webpack-plugin": "^0.8.2",
"flexboxgrid": "^6.3.0",
"flexboxgrid": "Zetoff/flexboxgrid#hidden-columns",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this temporary?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @silvenon yeah: this is temporary because it depends on this flexboxgrid branch kristoferjoseph/flexboxgrid#211

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see! Maybe this PR should wait then until there are news about that feature.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that'd be fine - hopefully @kristoferjoseph merges that PR soon

"isparta": "^4.0.0",
"jsdom": "^7.0.2",
"karma": "^0.13.3",
Expand Down
17 changes: 16 additions & 1 deletion src/components/Col.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ const classMap = {
lgOffset: 'col-lg-offset'
};

const hiddenMap = {
xs: 'hidden-xs',
sm: 'hidden-sm',
md: 'hidden-md',
lg: 'hidden-lg',
};

function getClassNames(props) {
const extraClasses = [];

Expand All @@ -43,7 +50,15 @@ function getClassNames(props) {

return Object.keys(props)
.filter(key => classMap[key])
.map(key => style[Number.isInteger(props[key]) ? (classMap[key] + '-' + props[key]) : classMap[key]])
.map(key => {
const colsAmount = props[key];
if ( Number.isInteger(colsAmount) && colsAmount === 0 ) {
return style[hiddenMap[key]];
} else if ( Number.isInteger(colsAmount) ) {
return style[`${classMap[key]}-${colsAmount}`];
}
return style[classMap[key]];
})
.concat(extraClasses)
.join(' ');
}
Expand Down
11 changes: 11 additions & 0 deletions test/components/Col.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@ describe('Col', () => {
expect(className).toContain(style['col-lg-4']);
});

it('Should hide elements when cols is 0', () => {
renderer.render(<Col xs={0} sm={0} md={0} lg={0} />);
const { type, props: { className } } = renderer.getRenderOutput();
expect(type).toBe('div');
expect(className).toContain('hidden-xs');
expect(className).toContain('hidden-sm');
expect(className).toContain('hidden-md');
expect(className).toContain('hidden-lg');
});


it('Should add "reverse" class if "reverse" property is true', () => {
renderer.render(<Col reverse/>);
expect(renderer.getRenderOutput().props.className).toContain(style.reverse);
Expand Down