Skip to content

Commit 8bf99a0

Browse files
authored
Implemented row direction feature
* Added tests for utils\percentage * Redefined rendering and implemented row direction feature * Added story for row direction feature
1 parent f69ed10 commit 8bf99a0

31 files changed

+719
-139
lines changed

src/column/Column.tsx

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,8 @@ import ColumnSize from "./ColumnSize";
1111
import renderOffset from "./renderOffset";
1212
import renderOrder from "./renderOrder";
1313
import renderSize from "./renderSize";
14-
import {
15-
breakpoints,
16-
BreakpointValue,
17-
BreakpointValues,
18-
PropertyValue
19-
} from "../media";
20-
import { gutterWidth, styled, Theme } from "../theme";
14+
import { BreakpointValue, PropertyValue } from "../media";
15+
import { styled, Theme } from "../theme";
2116
import { render } from "../utils";
2217

2318
const Column = styled.div`
@@ -26,28 +21,18 @@ const Column = styled.div`
2621
min-height: 1px;
2722
2823
${(props: ColumnProperties) => {
29-
const breakpointsMap = breakpoints(props!.theme);
3024
const renderer = {
3125
offset: (value?: PropertyValue) => renderOffset(value as ColumnOffset),
3226
order: (value?: PropertyValue) => renderOrder(value as ColumnOrder),
3327
size: (value?: PropertyValue) => renderSize(value as ColumnSize)
3428
};
3529
const valueMap = {
36-
offset: props!.offset as BreakpointValues<ColumnOffset>,
37-
order: props!.order as BreakpointValues<ColumnOrder>,
38-
size: props!.size as BreakpointValues<ColumnSize>
30+
offset: props!.offset as BreakpointValue<ColumnOffset>,
31+
order: props!.order as BreakpointValue<ColumnOrder>,
32+
size: props!.size as BreakpointValue<ColumnSize>
3933
};
40-
const width = gutterWidth(props.theme);
4134
42-
return `
43-
padding-right: ${width}px;
44-
padding-left: ${width}px;
45-
46-
${render(valueMap, breakpointsMap, renderer)}
47-
${renderOffset(props!.offset as ColumnOffset)}
48-
${renderOrder(props!.order as ColumnOrder)}
49-
${renderSize(props!.size as ColumnSize)}
50-
`;
35+
return render(valueMap, renderer, props!.theme);
5136
}};
5237
`;
5338

src/column/ColumnOffset.story.tsx

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,6 @@ import { storiesOf } from "@storybook/react";
33
import { action } from "@storybook/addon-actions";
44

55
import { Column, Container, Row } from "..";
6-
import { ThemeProvider } from "../theme/StyledComponents";
7-
8-
const breakpoints = {
9-
phone: 0,
10-
tablet: 600,
11-
desktop: 800
12-
};
13-
14-
const containerWidth = {
15-
// do not specify phone here
16-
tablet: 560,
17-
desktop: 760
18-
};
196

207
storiesOf("ColumnOffset", module).add("default", () => (
218
<div>

src/column/__snapshots__/Column.test.tsx.snap

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ exports[`<Column /> should match the snapshot (no properties set) 1`] = `
55
position: relative;
66
width: 100%;
77
min-height: 1px;
8-
padding-right: 15px;
9-
padding-left: 15px;
108
}
119
1210
<div
@@ -19,8 +17,6 @@ exports[`<Column /> should match the snapshot (offset: { xs: 3, sm: 4, md: 8 })
1917
position: relative;
2018
width: 100%;
2119
min-height: 1px;
22-
padding-right: 15px;
23-
padding-left: 15px;
2420
margin-left: 25.000000%;
2521
}
2622
@@ -53,8 +49,6 @@ exports[`<Column /> should match the snapshot (offset: 3) 1`] = `
5349
position: relative;
5450
width: 100%;
5551
min-height: 1px;
56-
padding-right: 15px;
57-
padding-left: 15px;
5852
margin-left: 25.000000%;
5953
}
6054
@@ -69,8 +63,6 @@ exports[`<Column /> should match the snapshot (offset: 3, order: 3, size: 9) 1`]
6963
position: relative;
7064
width: 100%;
7165
min-height: 1px;
72-
padding-right: 15px;
73-
padding-left: 15px;
7466
margin-left: 25.000000%;
7567
-webkit-box-ordinal-group: 3;
7668
-ms-flex-order: 2;
@@ -98,8 +90,6 @@ exports[`<Column /> should match the snapshot (order: { xs: 'first', sm: 3, md:
9890
position: relative;
9991
width: 100%;
10092
min-height: 1px;
101-
padding-right: 15px;
102-
padding-left: 15px;
10393
-webkit-box-ordinal-group: 0;
10494
-ms-flex-order: -1;
10595
-webkit-order: -1;
@@ -144,8 +134,6 @@ exports[`<Column /> should match the snapshot (order: 5) 1`] = `
144134
position: relative;
145135
width: 100%;
146136
min-height: 1px;
147-
padding-right: 15px;
148-
padding-left: 15px;
149137
-webkit-box-ordinal-group: 5;
150138
-ms-flex-order: 4;
151139
-webkit-order: 4;
@@ -164,8 +152,6 @@ exports[`<Column /> should match the snapshot (size: 7) 1`] = `
164152
position: relative;
165153
width: 100%;
166154
min-height: 1px;
167-
padding-right: 15px;
168-
padding-left: 15px;
169155
-webkit-box-flex: 0;
170156
-ms-flex: 0 0 58.333333%;
171157
-webkit-flex: 0 0 58.333333%;
@@ -185,8 +171,6 @@ exports[`<Column /> should match the snapshot (size: { xs: 'auto', sm: 7, md: 'n
185171
position: relative;
186172
width: 100%;
187173
min-height: 1px;
188-
padding-right: 15px;
189-
padding-left: 15px;
190174
-ms-flex-preferred-size: 0;
191175
-webkit-flex-basis: 0;
192176
-ms-flex-preferred-size: 0;

src/column/renderOffset.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import ColumnOffset from "./ColumnOffset";
22
import { percentage } from "../utils";
33

4-
export default function renderOrder(offset?: ColumnOffset): string {
4+
export default (offset?: ColumnOffset): string => {
55
if (
66
offset != null &&
77
typeof offset === "number" &&
@@ -14,4 +14,4 @@ export default function renderOrder(offset?: ColumnOffset): string {
1414
}
1515

1616
return "";
17-
}
17+
};

src/column/renderOrder.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import ColumnOrder from "./ColumnOrder";
22

3-
export default function renderOrder(order?: ColumnOrder | 0 | 13): string {
3+
const renderOrder = (order?: ColumnOrder | 0 | 13): string => {
44
if (order != null && typeof order !== "object") {
55
if (order === "first") {
66
return renderOrder(0);
@@ -20,4 +20,6 @@ export default function renderOrder(order?: ColumnOrder | 0 | 13): string {
2020
}
2121

2222
return "";
23-
}
23+
};
24+
25+
export default renderOrder;

src/container/Container.tsx

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import "../utils/bootstrap";
66
import ContainerProperties from "./ContainerProperties";
77
import renderWidth from "./renderWidth";
88
import getWidth from "./width";
9-
import { breakpoints, PropertyValue } from "../media";
9+
import { PropertyValue } from "../media";
1010
import { gutterWidth, styled, Theme } from "../theme";
1111
import { render } from "../utils";
1212

@@ -19,24 +19,21 @@ const Container = styled.div`
1919
const width = gutterWidth(props.theme);
2020
2121
return `
22-
padding-right: ${width}px;
23-
padding-left: ${width}px;
24-
`;
22+
padding-right: ${width}px;
23+
padding-left: ${width}px;
24+
`;
2525
}} ${(props: ContainerProperties) => {
2626
if (props.fluid) {
2727
return "";
2828
} else {
29-
const breakpointsMap = breakpoints(props!.theme);
3029
const renderer = {
3130
width: (value?: PropertyValue) => renderWidth(value as number)
3231
};
3332
const valueMap = {
3433
width: getWidth(props)
3534
};
3635
37-
return `
38-
${render(valueMap, breakpointsMap, renderer)}
39-
`;
36+
return render(valueMap, renderer, props!.theme);
4037
}
4138
}};
4239
`;

src/container/width.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import defaultWidth from "./defaultWidth";
21
import ContainerProperties from "./ContainerProperties";
2+
import defaultWidth from "./defaultWidth";
33
import { BreakpointValues } from "../media";
44

55
export default (props?: ContainerProperties): BreakpointValues<number> => {

src/media/PropertyValue.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
type PropertyValue = boolean | number | string;
1+
type PropertyValue = boolean | number | string | undefined;
22

33
export default PropertyValue;

src/media/PropertyValuesMap.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import BreakpointValues from "./BreakpointValues";
1+
import BreakpointValue from "./BreakpointValue";
22
import PropertyValue from "./PropertyValue";
33

44
export default interface PropertyValuesMap {
5-
[key: string]: BreakpointValues<PropertyValue>;
5+
[key: string]: BreakpointValue<PropertyValue>;
66
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { defaultBreakpointKey } from ".";
2+
3+
describe("defaultBreakpointKey", () => {
4+
it("should return 'xs'", () => {
5+
// arrange
6+
const input = undefined;
7+
8+
// act
9+
const output = defaultBreakpointKey(input);
10+
11+
// assert
12+
expect(output).toBe("xs");
13+
});
14+
15+
it("should return 'small'", () => {
16+
// arrange
17+
const input = {
18+
breakpoints: {
19+
small: 0,
20+
big: 500
21+
}
22+
};
23+
24+
// act
25+
const output = defaultBreakpointKey(input);
26+
27+
// assert
28+
expect(output).toBe("small");
29+
});
30+
31+
it("should return null", () => {
32+
// arrange
33+
const input = {
34+
breakpoints: {
35+
small: 200,
36+
big: 500
37+
}
38+
};
39+
40+
// act
41+
const output = defaultBreakpointKey(input);
42+
43+
// assert
44+
expect(output).toBeNull();
45+
});
46+
});

0 commit comments

Comments
 (0)