Skip to content

Commit 868e3f9

Browse files
authored
Merge pull request #8 from smakosh/fix/handle-all-cases
fix(Flex): handle rough edges
2 parents 8ed0f0a + 95fb7ec commit 868e3f9

File tree

5 files changed

+115
-83
lines changed

5 files changed

+115
-83
lines changed

example/example.ts

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,131 +1,131 @@
11
export default [
22
{
3-
"columns": 1
3+
columns: 1,
44
},
55
{
6-
"columns": 1
6+
columns: 1,
77
},
88
{
9-
"columns": 1
9+
columns: 1,
1010
},
1111
{
12-
"columns": 1
12+
columns: 1,
1313
},
1414
{
15-
"columns": 1
15+
columns: 1,
1616
},
1717
{
18-
"columns": 1
18+
columns: 1,
1919
},
2020
{
21-
"columns": 1
21+
columns: 1,
2222
},
2323
{
24-
"columns": 1
24+
columns: 1,
2525
},
2626
{
27-
"columns": 1
27+
columns: 1,
2828
},
2929
{
30-
"columns": 1
30+
columns: 1,
3131
},
3232
{
33-
"columns": 1
33+
columns: 1,
3434
},
3535
{
36-
"columns": 1
36+
columns: 1,
3737
},
3838
{
39-
"columns": 2
39+
columns: 2,
4040
},
4141
{
42-
"columns": 2
42+
columns: 2,
4343
},
4444
{
45-
"columns": 2
45+
columns: 2,
4646
},
4747
{
48-
"columns": 2
48+
columns: 2,
4949
},
5050
{
51-
"columns": 2
51+
columns: 2,
5252
},
5353
{
54-
"columns": 2
54+
columns: 2,
5555
},
5656
{
57-
"columns": 3
57+
columns: 3,
5858
},
5959
{
60-
"columns": 3
60+
columns: 3,
6161
},
6262
{
63-
"columns": 3
63+
columns: 3,
6464
},
6565
{
66-
"columns": 3
66+
columns: 3,
6767
},
6868
{
69-
"columns": 4
69+
columns: 4,
7070
},
7171
{
72-
"columns": 4
72+
columns: 4,
7373
},
7474
{
75-
"columns": 4
75+
columns: 4,
7676
},
7777
{
78-
"columns": 5
78+
columns: 5,
7979
},
8080
{
81-
"columns": 7
81+
columns: 7,
8282
},
8383
{
84-
"columns": 6
84+
columns: 6,
8585
},
8686
{
87-
"columns": 6
87+
columns: 6,
8888
},
8989
{
90-
"columns": 4
90+
columns: 4,
9191
},
9292
{
93-
"columns": 8
93+
columns: 8,
9494
},
9595
{
96-
"columns": 3
96+
columns: 3,
9797
},
9898
{
99-
"columns": 9
99+
columns: 9,
100100
},
101101
{
102-
"columns": 2
102+
columns: 2,
103103
},
104104
{
105-
"columns": 10
105+
columns: 10,
106106
},
107107
{
108-
"columns": 1
108+
columns: 1,
109109
},
110110
{
111-
"columns": 11
111+
columns: 11,
112112
},
113113
{
114-
"columns": 12
114+
columns: 12,
115115
},
116116
{
117-
"columns": 4
117+
columns: 4,
118118
},
119119
{
120-
"columns": 4
120+
columns: 4,
121121
},
122122
{
123-
"columns": 4
123+
columns: 4,
124124
},
125125
{
126-
"columns": 4
126+
columns: 4,
127127
},
128128
{
129-
"columns": 4
130-
}
131-
]
129+
columns: 4,
130+
},
131+
];

example/index.tsx

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,43 @@
11
import 'react-app-polyfill/ie11';
22
import * as React from 'react';
33
import * as ReactDOM from 'react-dom';
4-
import { Flex, Item } from '../.'
5-
import myList from './example'
4+
import { Flex, Item } from '../.';
5+
import myList from './example';
66

77
const App = () => (
88
<div
9-
style={{
10-
maxWidth: 960,
11-
margin: "0 auto"
12-
}}
13-
>
14-
<h1>Example</h1>
15-
<Flex col={4}>
16-
{myList.map(({ columns }, i: number) => (
17-
<Item
18-
key={i}
19-
col={columns}
20-
colTablet={6}
21-
colMobile={12}
22-
gap={1}
23-
marginBottom={30}
24-
stretch
25-
>
26-
<div
27-
style={{
28-
textAlign: "center",
29-
width: "100%",
30-
border: "1px solid #eee",
31-
background: "#eee"
32-
}}
9+
style={{
10+
maxWidth: 960,
11+
margin: '0 auto',
12+
}}
13+
>
14+
<h1>Example</h1>
15+
<Flex col={4} total={myList.length}>
16+
{myList.map(({ columns }, i: number) => (
17+
<Item
18+
key={i}
19+
col={columns}
20+
colTablet={6}
21+
colMobile={12}
22+
gap={1}
23+
marginBottom={30}
24+
stretch
3325
>
34-
<h1>{columns}</h1>
35-
</div>
36-
</Item>
37-
))}
38-
</Flex>
39-
</div>
40-
)
26+
<div
27+
style={{
28+
textAlign: 'center',
29+
width: '100%',
30+
border: '1px solid #eee',
31+
background: '#eee',
32+
}}
33+
>
34+
<h1>{columns}</h1>
35+
</div>
36+
</Item>
37+
))}
38+
</Flex>
39+
<h2>Hello</h2>
40+
</div>
41+
);
4142

4243
ReactDOM.render(<App />, document.getElementById('root'));

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@
4141
"size-limit": [
4242
{
4343
"path": "dist/react-flex-ready.cjs.production.min.js",
44-
"limit": "10 KB"
44+
"limit": "16 KB"
4545
},
4646
{
4747
"path": "dist/react-flex-ready.esm.js",
48-
"limit": "10 KB"
48+
"limit": "16 KB"
4949
}
5050
],
5151
"devDependencies": {

src/Flex.ts renamed to src/Flex.tsx

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import * as React from 'react';
12
import styled from 'styled-components';
23
import { FlexProps } from './interfaces';
4+
import Item from './Item';
35

4-
const Flex = styled.div<FlexProps>`
6+
const StyledFlex = styled.div<Omit<FlexProps, 'total'>>`
57
display: flex;
68
justify-content: ${({ justifyContent }) => justifyContent || 'space-between'};
79
flex-wrap: wrap;
@@ -29,4 +31,34 @@ const Flex = styled.div<FlexProps>`
2931
}
3032
`;
3133

34+
const Flex: React.FC<FlexProps> = ({
35+
children,
36+
col,
37+
colTablet,
38+
colMobile,
39+
gap,
40+
gabTablet,
41+
gapMobile,
42+
align,
43+
justifyContent,
44+
className,
45+
style,
46+
}) => (
47+
<StyledFlex
48+
col={col}
49+
colTablet={colTablet}
50+
colMobile={colMobile}
51+
gap={gap}
52+
gabTablet={gabTablet}
53+
gapMobile={gapMobile}
54+
align={align}
55+
justifyContent={justifyContent}
56+
className={className}
57+
style={style}
58+
>
59+
{children}
60+
<Item col={col} colTablet={colTablet} colMobile={colMobile} />
61+
</StyledFlex>
62+
);
63+
3264
export default Flex;

src/interfaces.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export interface ItemProps extends HTMLAttributes<HTMLDivElement> {
1414
style?: object;
1515
}
1616

17-
export interface FlexProps extends HTMLAttributes<HTMLDivElement> {
17+
export interface FlexProps {
1818
gap?: number;
1919
gabTablet?: number;
2020
gapMobile?: number;
@@ -23,7 +23,6 @@ export interface FlexProps extends HTMLAttributes<HTMLDivElement> {
2323
col?: number;
2424
colTablet?: number;
2525
colMobile?: number;
26-
as?: string | Component;
2726
className?: string;
2827
style?: object;
2928
}

0 commit comments

Comments
 (0)