Skip to content

Commit 79af6bf

Browse files
committed
update layout logic
1 parent 7107b6c commit 79af6bf

File tree

6 files changed

+24
-12
lines changed

6 files changed

+24
-12
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ const CardNumberBlock = () => (
285285
);
286286
const Main = () => (
287287
<RLM
288+
width="100%"
288289
verticalSpace={10}
289290
innerWidth={500}
290291
align="center"

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-layout-manager",
3-
"version": "0.1.8",
3+
"version": "0.1.9",
44
"description": "Layout manager not to give margins to components",
55
"homepage": "http://osamu38.github.io/react-layout-manager",
66
"bugs": {

src/demo/App.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ const CardNumberBlock = () => (
208208
);
209209
const Main = () => (
210210
<RLM
211+
width="100%"
211212
verticalSpace={10}
212213
innerWidth={500}
213214
align="center"

src/lib/components/LayoutManagerChild.jsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,17 @@ import {
1010
} from '../helpers/setStyles';
1111

1212
const LayoutManagerChild = styled.div`
13-
width: 100%;
14-
vertical-align: middle;
1513
&::after {
1614
display: block;
1715
clear: both;
1816
content: '';
1917
}
18+
${({ isVisible }) => setVisible(isVisible)}
2019
${({ horizontalSpace }) => setRightMargin(horizontalSpace)}
2120
${({ wrapVerticalSpace }) => setBottomMargin(wrapVerticalSpace)}
2221
${({ verticalSpace }) => setVerticalSpace(verticalSpace)}
2322
${({ childWidth }) => setWidth(childWidth)}
2423
${({ verticalAlign }) => setVerticalAlign(verticalAlign)}
25-
${({ isVisible }) => setVisible(isVisible)}
2624
${(props) => setResponsivePropertyToChild(props)}
2725
`;
2826

src/lib/components/LayoutManagerChildInner.jsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ import {
66
} from '../helpers/setStyles';
77

88
const LayoutManagerChildInner = styled.div`
9-
width: 100%;
10-
${({ innerWidth }) => setInnerWidth(innerWidth)}
119
${({ align }) => setAlign(align)}
10+
${({ innerWidth }) => setInnerWidth(innerWidth)}
1211
${(props) => setResponsivePropertyToChildInner(props)}
1312
`;
1413

src/lib/helpers/setStyles.js

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export function setBottomNegativeMargin(wrapVerticalSpace) {
5454
export function setWidth(childWidth) {
5555
return childWidth && `
5656
max-width: ${childWidth + getUnit(childWidth)};
57+
width: 100%;
5758
`;
5859
}
5960
export function setVerticalSpace(verticalSpace) {
@@ -62,20 +63,32 @@ export function setVerticalSpace(verticalSpace) {
6263
`;
6364
}
6465
export function setVerticalAlign(verticalAlign) {
65-
return checkApplyProperyValid(verticalAlign) && `
66+
return checkApplyProperyValid(verticalAlign) ? `
6667
vertical-align: ${verticalAlign + getUnit(verticalAlign)};
68+
` : `
69+
vertical-align: middle;
6770
`;
6871
}
6972
export function setInnerWidth(innerWidth) {
7073
return checkApplyProperyValid(innerWidth) && `
7174
max-width: ${innerWidth + getUnit(innerWidth)};
75+
width: 100%;
7276
`;
7377
}
7478
export function setAlign(align) {
75-
return align && align === 'center' ? `
76-
margin: 0 auto;
77-
` : `
79+
if (!align) {
80+
return `
81+
width: 100%;
82+
`;
83+
} else if (align === 'center') {
84+
return `
85+
margin: 0 auto;
86+
width: fit-content;
87+
`;
88+
}
89+
return `
7890
float: ${align};
91+
width: auto;
7992
`;
8093
}
8194
export function setResponsivePropertyToLayoutManager(props) {
@@ -117,12 +130,12 @@ export function setResponsivePropertyToChild(props) {
117130
);
118131
119132
return css`
133+
${setVisible(childProperty.isVisible)}
120134
${setRightMargin(childProperty.horizontalSpace)}
121135
${setBottomMargin(childProperty.wrapVerticalSpace)}
122136
${setVerticalSpace(childProperty.verticalSpace)}
123137
${setWidth(childProperty.childWidth)}
124138
${setVerticalAlign(childProperty.verticalAlign)}
125-
${setVisible(childProperty.isVisible)}
126139
`;
127140
})()}
128141
}
@@ -142,8 +155,8 @@ export function setResponsivePropertyToChildInner(props) {
142155
);
143156
144157
return css`
145-
${setInnerWidth(childInnerProperty.innerWidth)}
146158
${setAlign(childInnerProperty.align)}
159+
${setInnerWidth(childInnerProperty.innerWidth)}
147160
`;
148161
})()}
149162
}

0 commit comments

Comments
 (0)