Skip to content

Commit 607cd08

Browse files
nathpaivaaaronvanston
authored andcommitted
Create fixed column (#82)
* Add new documentation * Add new properties * Create new verifications to fixed a column * Creaet a story to fixed column * Remove sibling property * Update documentation
1 parent 4f620d6 commit 607cd08

File tree

8 files changed

+162
-19
lines changed

8 files changed

+162
-19
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ These are the **available** and **reserved** props that can be used on the `Col`
8383

8484
| Prop | Valid types | Valid values | Default value | Description |
8585
|:--------------|:------------------------------------------------------------|:----------------------------------------------------------------------------------------|:--------------|:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
86-
| `xs` | integer | `0`-`12`<br>(based on default columns)<br>`hidden`<br>`auto` | nill | Sets the width of the col based the column configuration (12 by default) for the XS breakpoint and up. |
87-
| `sm` | integer | `0`-`12`<br>(based on default columns)<br>`hidden`<br>`auto` | nill | Sets the width of the col based the column configuration (12 by default) for the SM breakpoint and up. |
88-
| `md` | integer | `0`-`12`<br>(based on default columns)<br>`hidden`<br>`auto` | nill | Sets the width of the col based the column configuration (12 by default) for the MD breakpoint and up. |
89-
| `lg` | integer | `0`-`12`<br>(based on default columns)<br>`hidden`<br>`auto` | nill | Sets the width of the col based the column configuration (12 by default) for the LG breakpoint and up. |
86+
| `xs` | integer/ string | `0`-`12`<br>(based on default columns)<br>`hidden`<br>`auto` <br> `'390px'` - `'calc=(100% - 390px)'` | nill | **Number:** Sets the width of the col based the column configuration (12 by default) for the XS breakpoint and up.<br> **String:** Set a width like string `xs="390px"` to fixed have a fixed colum, or create a calc `xs="calc(100% - 390px)"` base on sibling to have a responsive column. |
87+
| `sm` | integer/ string | `0`-`12`<br>(based on default columns)<br>`hidden`<br>`auto` <br> `'390px'` - `'calc=(100% - 390px)'` | nill | **Number:** Sets the width of the col based the column configuration (12 by default) for the SM breakpoint and up.<br> **String:** Set a width like string `sm="390px"` to fixed have a fixed colum, or create a calc `sm="calc(100% - 390px)"` base on sibling to have a responsive column. |
88+
| `md` | integer/ string | `0`-`12`<br>(based on default columns)<br>`hidden`<br>`auto` <br> `'390px'` - `'calc=(100% - 390px)'` | nill | **Number:** Sets the width of the col based the column configuration (12 by default) for the MD breakpoint and up.<br> **String:** Set a width like string `md="390px"` to fixed have a fixed colum, or create a calc `md="calc(100% - 390px)"` base on sibling to have a responsive column. |
89+
| `lg` | integer/ string | `0`-`12`<br>(based on default columns)<br>`hidden`<br>`auto` <br> `'390px'` - `'calc=(100% - 390px)'` | nill | **Number:** Sets the width of the col based the column configuration (12 by default) for the LG breakpoint and up.<br> **String:** Set a width like string `lg="390px"` to fixed have a fixed colum, or create a calc `lg="calc(100% - 390px)"` base on sibling to have a responsive column. |
9090
| `gutter` | integer, string,<br>[object](#responsive-api-using-objects) | `'1rem'`<br>`'12px'`<br>`4` | `'1rem'` | Sets the width of the gutter to be used between columns. For correct positioning you must set the same value (if custom) on the parent Row |
9191
| `order` | string,<br>[object](#responsive-api-using-objects) | `-1`<br>`0`<br>`1`<br>(etc) | `0` | By default, flex items are laid out in the source order. However, the order property controls the order in which they appear in the flex container. [Read more about order.](https://css-tricks.com/snippets/css/a-guide-to-flexbox/#article-header-id-9) |
9292
| `alignSelf` | string,<br>[object](#responsive-api-using-objects) | `'auto'`<br>`'flex‑start'`<br>`'flex‑end'`<br>`'center'`<br>`'baseline'`<br>`'stretch'` | `'auto'` | This allows the default alignment (or the one specified by align‑items) to be overridden for individual flex items. [Read more about align-self.](https://css-tricks.com/snippets/css/a-guide-to-flexbox/#article-header-id-14) |

src/components/Col/Col.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ const displayOptions = ['flex', 'inline-flex', 'block', 'none', 'inline-block'];
4242
export const alignSelfOptions = ['auto', 'flex-start', 'flex-end', 'center', 'baseline', 'stretch'];
4343

4444
Col.propTypes = {
45-
xs: PropTypes.oneOfType([PropTypes.number, PropTypes.oneOf(['hidden', 'auto'])]),
46-
sm: PropTypes.oneOfType([PropTypes.number, PropTypes.oneOf(['hidden', 'auto'])]),
47-
md: PropTypes.oneOfType([PropTypes.number, PropTypes.oneOf(['hidden', 'auto'])]),
48-
lg: PropTypes.oneOfType([PropTypes.number, PropTypes.oneOf(['hidden', 'auto'])]),
45+
xs: PropTypes.oneOfType([PropTypes.number, PropTypes.string, PropTypes.oneOf(['hidden', 'auto'])]),
46+
sm: PropTypes.oneOfType([PropTypes.number, PropTypes.string, PropTypes.oneOf(['hidden', 'auto'])]),
47+
md: PropTypes.oneOfType([PropTypes.number, PropTypes.string, PropTypes.oneOf(['hidden', 'auto'])]),
48+
lg: PropTypes.oneOfType([PropTypes.number, PropTypes.string, PropTypes.oneOf(['hidden', 'auto'])]),
4949

5050
gutter: PropTypes.oneOfType([
5151
PropTypes.number,

src/components/Col/Col.stories.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { storiesOf } from '@storybook/react';
55
import { withKnobs } from '@storybook/addon-knobs';
66
import withReadme from 'storybook-readme/with-readme';
77

8-
import { Col, Fluid, Responsive, AutoGrow } from './stories';
8+
import { Col, Fluid, Responsive, AutoGrow, Fixed } from './stories';
99
import README from './README.md';
1010

1111
storiesOf('Col', module)
@@ -14,4 +14,5 @@ storiesOf('Col', module)
1414
.add('Default', () => <Col />)
1515
.add('Fluid example', () => <Fluid />)
1616
.add('Responsive example', () => <Responsive />)
17-
.add('Auto grow example', () => <AutoGrow />);
17+
.add('Auto grow example', () => <AutoGrow />)
18+
.add('One fixed col', () => <Fixed />);

src/components/Col/README.md

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,18 @@ A component for creating a column containing other elements, within a grid syste
66

77
View detailed property information in [Col props](https://github.com/aaronvanston/react-flexa#col-props) within the react-flexa readme.
88

9-
- `xs`: Sets the width of the col based the column configuration (12 by default) for the XS breakpoint and up.
10-
- `sm`: Sets the width of the col based the column configuration (12 by default) for the SM breakpoint and up.
11-
- `md`: Sets the width of the col based the column configuration (12 by default) for the MD breakpoint and up.
12-
- `lg`: Sets the width of the col based the column configuration (12 by default) for the LG breakpoint and up.
9+
- `xs`:
10+
- **Number:** Sets the width of the col based the column configuration (12 by default) for the XS breakpoint and up.
11+
- **String:** Set a width like string `xs="390px"` to fixed have a fixed colum, or create a calc `xs="calc(100% - 390px)"` base on sibling to have a responsive column.
12+
- `sm`:
13+
- **Number:** Sets the width of the col based the column configuration (12 by default) for the SM breakpoint and up.
14+
- **String:** Set a width like string `sm="390px"` to fixed have a fixed colum, or create a calc `sm="calc(100% - 390px)"` base on sibling to have a responsive column.
15+
- `md`:
16+
- **Number:** Sets the width of the col based the column configuration (12 by default) for the MD breakpoint and up.
17+
- **String:** Set a width like string `md="390px"` to fixed have a fixed colum, or create a calc `md="calc(100% - 390px)"` base on sibling to have a responsive column.
18+
- `lg`:
19+
- **Number:** Sets the width of the col based the column configuration (12 by default) for the LG breakpoint and up.
20+
- **String:** Set a width like string `lg="390px"` to fixed have a fixed colum, or create a calc `lg="calc(100% - 390px)"` base on sibling to have a responsive column.
1321
- `gutter`: Sets the width of the gutter to be used between columns.
1422
- `order`: Controls the order in which they appear in the flex container.
1523
- `alignSelf`: Controls vertical alignment in the flex container.
@@ -45,4 +53,31 @@ export default () => (
4553
);
4654
```
4755

56+
### One fixed column
57+
58+
```js
59+
import React from 'react';
60+
import { Row, Col } from 'react-flexa';
61+
62+
export default () => (
63+
<Row>
64+
<Col xs={12} sm={6} md={6} lg="390px"></Col>
65+
<Col xs={12} sm={6} md={6} lg="calc(100% - 390px)"></Col>
66+
</Row>
67+
);
68+
```
69+
70+
```js
71+
import React from 'react';
72+
import { Row, Col } from 'react-flexa';
73+
74+
export default () => (
75+
<Row>
76+
<Col xs={12} sm={6} md={6} lg="390px"></Col>
77+
<Col xs={12} sm={6} md={6} lg="calc(80% - 390px)"></Col>
78+
<Col xs={12} sm={6} md={6} lg="20%"></Col>
79+
</Row>
80+
);
81+
```
82+
4883
Read more about react-flexa [responsive api using objects.](https://github.com/aaronvanston/react-flexa#responsive-api-using-objects)

src/components/Col/stories/Fixed.js

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import React from 'react';
2+
3+
import { Box, Title, Section } from '../../../../stories/components';
4+
import { Row, Col } from '../../';
5+
6+
export default () => (
7+
<div>
8+
<Section>
9+
<Title>One fixed column and other responsive</Title>
10+
<Row>
11+
<Col xs={12} sm={6} md={6} lg="390px">
12+
<Box>col 1</Box>
13+
</Col>
14+
15+
<Col xs={12} sm={6} md={6} lg="calc(80% - 390px)">
16+
<Box bgColor="#9c27b0">col 2</Box>
17+
</Col>
18+
19+
<Col xs={12} sm={6} md={6} lg="20%">
20+
<Box bgColor="#ff9800">col 3</Box>
21+
</Col>
22+
</Row>
23+
</Section>
24+
25+
<Section>
26+
<Title>One fixed column and responsive gutter</Title>
27+
<Row gutter={{ xs: 0, sm: 2, md: 4, lg: 8 }}>
28+
<Col xs={12} sm={6} md={6} lg="390px">
29+
<Box>col 1</Box>
30+
</Col>
31+
32+
<Col xs={12} sm={6} md={6} lg="calc(80% - 390px)">
33+
<Box bgColor="#9c27b0">col 2</Box>
34+
</Col>
35+
36+
<Col xs={12} sm={6} md={6} lg="20%">
37+
<Box bgColor="#ff9800">col 3</Box>
38+
</Col>
39+
</Row>
40+
</Section>
41+
42+
<Section>
43+
<Title>One fixed column and other responsive order</Title>
44+
<Row>
45+
<Col xs={12} sm={6} md={6} lg="390px" order={{ xs: 4, sm: 3, md: 2, lg: 1 }}>
46+
<Box>col 1</Box>
47+
</Col>
48+
49+
<Col xs={12} sm={6} md={6} lg="calc(80% - 390px)" order={1}>
50+
<Box bgColor="#9c27b0">col 2</Box>
51+
</Col>
52+
53+
<Col xs={12} sm={6} md={6} lg="20%">
54+
<Box bgColor="#ff9800">col 3</Box>
55+
</Col>
56+
</Row>
57+
</Section>
58+
59+
<Section>
60+
<Title>One fixed column and other responsive alignSelf</Title>
61+
<Row>
62+
<Col xs={12} sm={6} md={6} lg="390px">
63+
<Box height="5rem">col 1</Box>
64+
</Col>
65+
66+
<Col
67+
xs={12}
68+
sm={6}
69+
md={6}
70+
lg="calc(80% - 390px)"
71+
alignSelf={{ xs: 'flex-end', md: 'center', lg: 'flex-start' }}
72+
>
73+
<Box bgColor="#9c27b0">col 2</Box>
74+
</Col>
75+
76+
<Col xs={12} sm={6} md={6} lg="20%">
77+
<Box bgColor="#ff9800" height="5rem">col 3</Box>
78+
</Col>
79+
</Row>
80+
</Section>
81+
</div>
82+
);

src/components/Col/stories/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ export Col from './Col';
22
export Fluid from './Fluid';
33
export Responsive from './Responsive';
44
export AutoGrow from './AutoGrow';
5+
export Fixed from './Fixed';

src/helpers/columnWidth/columnWidth.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,22 @@ const columnWidth = (props, breakpoint) => {
3838

3939
const width = percentage(props, breakpoint);
4040

41-
return has(props, `${breakpoint}`) ? css`
42-
flex-basis: ${width}%;
43-
max-width: ${width}%;
44-
${display(props, breakpoint)}
45-
` : null;
41+
if (has(props, `${breakpoint}`) && typeof props[breakpoint] !== 'string') {
42+
return css`
43+
flex-basis: ${width}%;
44+
max-width: ${width}%;
45+
${display(props, breakpoint)}
46+
`;
47+
}
48+
49+
if (has(props, `${breakpoint}`) && typeof props[breakpoint] === 'string') {
50+
return css`
51+
width: ${props[breakpoint]};
52+
max-width: ${props[breakpoint]};
53+
flex-basis: initial;
54+
`;
55+
}
56+
57+
return null;
4658
};
4759
export default columnWidth;

src/helpers/columnWidth/columnWidth.spec.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,16 @@ describe('columnWidth', () => {
8888
const width = columnWidth(hiddenMockProps, 'md').join('');
8989
expect(width).toContain('display: none');
9090
});
91+
92+
test('should return a fixed column', () => {
93+
const hiddenMockProps = { xs: 12, sm: 5, md: 6, lg: '390px' };
94+
const width = columnWidth(hiddenMockProps, 'lg').join('');
95+
expect(width).toContain('max-width: 390px;');
96+
});
97+
98+
test('should return a fixed column with sibling responsive', () => {
99+
const hiddenMockProps = { xs: 12, sm: 5, md: 6, lg: 'calc(100% - 390px)' };
100+
const width = columnWidth(hiddenMockProps, 'lg').join('');
101+
expect(width).toContain('calc(100% - 390px);');
102+
});
91103
});

0 commit comments

Comments
 (0)