react-justified-layout-ts 2.0.3 → 2.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -69,18 +69,28 @@ function TSJustifiedLayout({ children, layoutItems, itemSpacing = 10, rowSpacing
|
|
|
69
69
|
/**
|
|
70
70
|
* Clone the children element, and inject the height of the element as a prop
|
|
71
71
|
*/
|
|
72
|
-
function
|
|
72
|
+
function renderRowItem(aspectRatio, isSoloRow) {
|
|
73
73
|
childNodeCounter++;
|
|
74
|
-
return react_1.default.createElement("div", { style: Object.assign({ aspectRatio: aspectRatio, flex: aspectRatio }, containerStyle) }, children[childNodeCounter]);
|
|
74
|
+
return react_1.default.createElement("div", { style: Object.assign({ aspectRatio: aspectRatio, flex: isSoloRow ? 1 : aspectRatio }, containerStyle) }, children[childNodeCounter]);
|
|
75
75
|
}
|
|
76
|
-
|
|
76
|
+
// TODO Figure out how to eliminate the tiny gap between div and actual image height
|
|
77
|
+
// TODO Make bottom row respect length restrictions
|
|
78
|
+
return (react_1.default.createElement("div", { style: {
|
|
79
|
+
display: 'flex',
|
|
80
|
+
flexDirection: 'column',
|
|
81
|
+
gap: rowSpacing
|
|
82
|
+
} }, rows.map((value, index, array) => {
|
|
77
83
|
let isLastRow = index === array.length - 1 && showWidows;
|
|
84
|
+
let rowTotalAspectRatio = value.items.reduce((previousValue, currentValue) => previousValue + currentValue, 0);
|
|
85
|
+
const isLastRowWithinTolerance = isLastRow && rowTotalAspectRatio * targetRowHeight + (value.items.length - 1) * itemSpacing < minAspectRatio * targetRowHeight;
|
|
86
|
+
const fakeElementAspectRatio = (width - rowTotalAspectRatio - (value.items.length) * itemSpacing) / targetRowHeight;
|
|
78
87
|
return react_1.default.createElement("div", { className: 'justified-row', style: {
|
|
79
88
|
display: "flex",
|
|
80
89
|
flexDirection: "row",
|
|
81
90
|
gap: itemSpacing,
|
|
82
|
-
|
|
83
|
-
|
|
91
|
+
} },
|
|
92
|
+
value.items.map((aspectRatio) => renderRowItem(aspectRatio, value.items.length === 1)),
|
|
93
|
+
isLastRowWithinTolerance && react_1.default.createElement("div", { style: { aspectRatio: fakeElementAspectRatio, flex: fakeElementAspectRatio } }));
|
|
84
94
|
})));
|
|
85
95
|
}
|
|
86
96
|
exports.TSJustifiedLayout = TSJustifiedLayout;
|
|
@@ -19,6 +19,6 @@ const TSJustifiedLayout_1 = require("../components/TSJustifiedLayout");
|
|
|
19
19
|
const react_1 = __importDefault(require("react"));
|
|
20
20
|
const ConfiguredJustifiedLayout = (_a) => {
|
|
21
21
|
var { layoutItems, rowSpacing = 8, width = 1000, itemSpacing = 8, targetRowHeight = 320, targetRowHeightTolerance = 0.10, showWidows = true, children } = _a, props = __rest(_a, ["layoutItems", "rowSpacing", "width", "itemSpacing", "targetRowHeight", "targetRowHeightTolerance", "showWidows", "children"]);
|
|
22
|
-
return react_1.default.createElement(TSJustifiedLayout_1.TSJustifiedLayout, Object.assign({ layoutItems: layoutItems, width: width, itemSpacing: itemSpacing, targetRowHeight:
|
|
22
|
+
return react_1.default.createElement(TSJustifiedLayout_1.TSJustifiedLayout, Object.assign({ layoutItems: layoutItems, width: width, itemSpacing: itemSpacing, targetRowHeight: targetRowHeight, targetRowHeightTolerance: targetRowHeightTolerance, rowSpacing: rowSpacing, showWidows: showWidows }, props), children.map((child) => child));
|
|
23
23
|
};
|
|
24
24
|
exports.ConfiguredJustifiedLayout = ConfiguredJustifiedLayout;
|
package/package.json
CHANGED
|
@@ -97,29 +97,38 @@ function TSJustifiedLayout({
|
|
|
97
97
|
/**
|
|
98
98
|
* Clone the children element, and inject the height of the element as a prop
|
|
99
99
|
*/
|
|
100
|
-
function
|
|
100
|
+
function renderRowItem(aspectRatio: ElementDimensions, isSoloRow: boolean) {
|
|
101
101
|
childNodeCounter++;
|
|
102
102
|
return <div style={{
|
|
103
103
|
aspectRatio: aspectRatio,
|
|
104
|
-
flex: aspectRatio,
|
|
104
|
+
flex: isSoloRow ? 1 : aspectRatio,
|
|
105
105
|
...containerStyle
|
|
106
106
|
}}>
|
|
107
107
|
{children[childNodeCounter]}
|
|
108
108
|
</div>
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
+
// TODO Figure out how to eliminate the tiny gap between div and actual image height
|
|
112
|
+
// TODO Make bottom row respect length restrictions
|
|
111
113
|
return (
|
|
112
|
-
<div style={{
|
|
114
|
+
<div style={{
|
|
115
|
+
display: 'flex',
|
|
116
|
+
flexDirection: 'column',
|
|
117
|
+
gap: rowSpacing
|
|
118
|
+
}}>
|
|
113
119
|
{rows.map((value, index, array) => {
|
|
114
120
|
let isLastRow = index === array.length - 1 && showWidows;
|
|
121
|
+
let rowTotalAspectRatio = value.items.reduce((previousValue, currentValue) => previousValue + currentValue, 0);
|
|
122
|
+
const isLastRowWithinTolerance = isLastRow && rowTotalAspectRatio * targetRowHeight + (value.items.length - 1) * itemSpacing < minAspectRatio * targetRowHeight;
|
|
123
|
+
const fakeElementAspectRatio = (width - rowTotalAspectRatio - (value.items.length) * itemSpacing) / targetRowHeight
|
|
115
124
|
return <div className={'justified-row'} style={{
|
|
116
125
|
display: "flex",
|
|
117
126
|
flexDirection: "row",
|
|
118
127
|
gap: itemSpacing,
|
|
119
|
-
marginBottom: rowSpacing
|
|
120
128
|
}
|
|
121
129
|
}>
|
|
122
|
-
{value.items.map((aspectRatio) =>
|
|
130
|
+
{value.items.map((aspectRatio) => renderRowItem(aspectRatio, value.items.length === 1))}
|
|
131
|
+
{isLastRowWithinTolerance && <div style={{aspectRatio: fakeElementAspectRatio, flex: fakeElementAspectRatio}}></div>}
|
|
123
132
|
</div>
|
|
124
133
|
})}
|
|
125
134
|
</div>
|
|
@@ -16,7 +16,7 @@ export const ConfiguredJustifiedLayout = ({
|
|
|
16
16
|
return <TSJustifiedLayout layoutItems={layoutItems}
|
|
17
17
|
width={width}
|
|
18
18
|
itemSpacing={itemSpacing}
|
|
19
|
-
targetRowHeight={
|
|
19
|
+
targetRowHeight={targetRowHeight}
|
|
20
20
|
targetRowHeightTolerance={targetRowHeightTolerance}
|
|
21
21
|
rowSpacing={rowSpacing}
|
|
22
22
|
showWidows={showWidows} {...props}>
|