react-justified-layout-ts 1.1.2 → 1.1.3
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.
|
@@ -10,5 +10,5 @@ export interface TSJustifiedLayoutProps {
|
|
|
10
10
|
children: any[];
|
|
11
11
|
showWidows?: boolean;
|
|
12
12
|
}
|
|
13
|
-
declare
|
|
13
|
+
declare const TSJustifiedLayout: React.MemoExoticComponent<({ children, layoutItems, itemSpacing, rowSpacing, showWidows, targetRowHeight, targetRowHeightTolerance, width }: TSJustifiedLayoutProps) => React.JSX.Element>;
|
|
14
14
|
export { TSJustifiedLayout };
|
|
@@ -25,7 +25,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.TSJustifiedLayout = void 0;
|
|
27
27
|
const react_1 = __importStar(require("react"));
|
|
28
|
-
|
|
28
|
+
const TSJustifiedLayout = (0, react_1.memo)(({ children, layoutItems, itemSpacing = 10, rowSpacing = 10, showWidows = true, targetRowHeight = 320, targetRowHeightTolerance = .25, width }) => {
|
|
29
29
|
const minAspectRatio = width / targetRowHeight * (1 - targetRowHeightTolerance);
|
|
30
30
|
const maxAspectRatio = width / targetRowHeight * (1 + targetRowHeightTolerance);
|
|
31
31
|
/**
|
|
@@ -82,7 +82,6 @@ function TSJustifiedLayout({ children, layoutItems, itemSpacing = 10, rowSpacing
|
|
|
82
82
|
}
|
|
83
83
|
const rows = [];
|
|
84
84
|
let rowBuffer = [];
|
|
85
|
-
console.log(rows);
|
|
86
85
|
layoutItems.forEach((value) => {
|
|
87
86
|
const isItemSuccessfullyAdded = addItem(value);
|
|
88
87
|
if (!isItemSuccessfullyAdded) {
|
|
@@ -90,7 +89,6 @@ function TSJustifiedLayout({ children, layoutItems, itemSpacing = 10, rowSpacing
|
|
|
90
89
|
}
|
|
91
90
|
});
|
|
92
91
|
// Handle leftover content
|
|
93
|
-
console.log(rows);
|
|
94
92
|
if (showWidows) {
|
|
95
93
|
rows.push({ items: rowBuffer, height: rows.length === 0 ? targetRowHeight : rows[rows.length - 1].height });
|
|
96
94
|
}
|
|
@@ -101,15 +99,14 @@ function TSJustifiedLayout({ children, layoutItems, itemSpacing = 10, rowSpacing
|
|
|
101
99
|
*/
|
|
102
100
|
function renderChildren(isLast) {
|
|
103
101
|
childNodeCounter++;
|
|
104
|
-
return (0, react_1.cloneElement)(children[childNodeCounter], Object.assign(Object.assign({}, children[childNodeCounter].props), { style: Object.assign(Object.assign(Object.assign({}, children[childNodeCounter].props.style), { maxWidth:
|
|
102
|
+
return (0, react_1.cloneElement)(children[childNodeCounter], Object.assign(Object.assign({}, children[childNodeCounter].props), { style: Object.assign(Object.assign(Object.assign({}, children[childNodeCounter].props.style), { maxWidth: "100%" }), (isLast ? { maxHeight: "100%" } : {})) }));
|
|
105
103
|
}
|
|
106
104
|
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
107
|
-
react_1.default.createElement("div", { style: { width: "100%" } }),
|
|
108
105
|
react_1.default.createElement("div", { style: { width: "100%" } }, rows.map((value, index, array) => {
|
|
109
106
|
let isLastRow = index === array.length - 1 && showWidows;
|
|
110
107
|
return react_1.default.createElement("div", { style: Object.assign({ display: "flex", flexDirection: "row", gap: itemSpacing, marginBottom: rowSpacing }, (isLastRow ? { height: value.height } : {})) }, value.items.map((aspectRatio) => {
|
|
111
108
|
return react_1.default.createElement("div", { style: isLastRow ? { aspectRatio: aspectRatio } : { flex: aspectRatio } }, renderChildren(isLastRow));
|
|
112
109
|
}));
|
|
113
110
|
}))));
|
|
114
|
-
}
|
|
111
|
+
});
|
|
115
112
|
exports.TSJustifiedLayout = TSJustifiedLayout;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-justified-layout-ts",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.3",
|
|
4
4
|
"description": "A component based off Flickr's justified layout that is compatible with Typescript",
|
|
5
5
|
"main": "./dist/TSJustifiedLayout.js",
|
|
6
6
|
"types": "./dist/TSJustifiedLayout.d.ts",
|