react-justified-layout-ts 1.0.2 → 1.0.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.
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
+
type ElementDimensions = number;
|
|
2
3
|
export interface TSJustifiedLayoutProps {
|
|
3
|
-
|
|
4
|
-
src: string;
|
|
5
|
-
dimensions: number;
|
|
6
|
-
}[];
|
|
4
|
+
layoutItems: ElementDimensions[];
|
|
7
5
|
itemSpacing?: number;
|
|
8
6
|
rowSpacing?: number;
|
|
9
7
|
targetRowHeight?: number;
|
|
@@ -12,5 +10,5 @@ export interface TSJustifiedLayoutProps {
|
|
|
12
10
|
children: any[];
|
|
13
11
|
showWidows?: boolean;
|
|
14
12
|
}
|
|
15
|
-
declare function TSJustifiedLayout({ children,
|
|
13
|
+
declare function TSJustifiedLayout({ children, layoutItems, itemSpacing, rowSpacing, showWidows, targetRowHeight, targetRowHeightTolerance, width }: TSJustifiedLayoutProps): React.JSX.Element;
|
|
16
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
|
-
function TSJustifiedLayout({ children,
|
|
28
|
+
function TSJustifiedLayout({ 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
|
/**
|
|
@@ -35,7 +35,7 @@ function TSJustifiedLayout({ children, images, itemSpacing = 10, rowSpacing = 10
|
|
|
35
35
|
* */
|
|
36
36
|
function addItem(value) {
|
|
37
37
|
const newItems = rowBuffer.concat(value);
|
|
38
|
-
const newAspectRatio = newItems.map(
|
|
38
|
+
const newAspectRatio = newItems.map(dimensions => dimensions).reduce((previousValue, currentValue) => previousValue + currentValue, 0);
|
|
39
39
|
const rowWidthWithoutSpacing = width - (newItems.length - 1) * itemSpacing;
|
|
40
40
|
const targetAspectRatio = rowWidthWithoutSpacing / targetRowHeight;
|
|
41
41
|
// Row still has space
|
|
@@ -55,7 +55,7 @@ function TSJustifiedLayout({ children, images, itemSpacing = 10, rowSpacing = 10
|
|
|
55
55
|
else {
|
|
56
56
|
// Calculate width/aspect ratio for row before adding new item
|
|
57
57
|
const previousRowWidthWithoutSpacing = width - (rowBuffer.length - 1) * itemSpacing;
|
|
58
|
-
const previousAspectRatio = rowBuffer.map(
|
|
58
|
+
const previousAspectRatio = rowBuffer.map(dimensions => dimensions).reduce((previousValue, currentValue) => previousValue + currentValue, 0);
|
|
59
59
|
const previousTargetAspectRatio = previousRowWidthWithoutSpacing / targetRowHeight;
|
|
60
60
|
// If the new aspect ratio is farther from the target after the insert, then push row buffer and insert new item into the next row
|
|
61
61
|
if (Math.abs(newAspectRatio - targetAspectRatio) > Math.abs(previousAspectRatio - previousTargetAspectRatio)) {
|
|
@@ -82,7 +82,7 @@ function TSJustifiedLayout({ children, images, itemSpacing = 10, rowSpacing = 10
|
|
|
82
82
|
}
|
|
83
83
|
const rows = [];
|
|
84
84
|
let rowBuffer = [];
|
|
85
|
-
|
|
85
|
+
layoutItems.forEach((value) => {
|
|
86
86
|
const isItemSuccessfullyAdded = addItem(value);
|
|
87
87
|
if (!isItemSuccessfullyAdded) {
|
|
88
88
|
addItem(value);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-justified-layout-ts",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.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",
|