react-justified-layout-ts 1.1.13 → 1.1.15

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,4 +1,5 @@
1
1
  import React from "react";
2
+ import './layout.css';
2
3
  type ElementDimensions = number;
3
4
  export interface TSJustifiedLayoutProps {
4
5
  layoutItems: ElementDimensions[];
@@ -25,6 +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
+ require("./layout.css");
28
29
  function TSJustifiedLayout({ children, layoutItems, itemSpacing = 10, rowSpacing = 10, showWidows = true, targetRowHeight = 320, targetRowHeightTolerance = .25, width }) {
29
30
  const minAspectRatio = width / targetRowHeight * (1 - targetRowHeightTolerance);
30
31
  const maxAspectRatio = width / targetRowHeight * (1 + targetRowHeightTolerance);
@@ -86,22 +87,19 @@ function TSJustifiedLayout({ children, layoutItems, itemSpacing = 10, rowSpacing
86
87
  /**
87
88
  * Clone the children element, and inject the height of the element as a prop
88
89
  */
89
- function renderChildren() {
90
+ function renderRow(aspectRatio, isLastRow) {
90
91
  childNodeCounter++;
91
- return (0, react_1.cloneElement)(children[childNodeCounter], Object.assign(Object.assign({}, children[childNodeCounter].props), { style: Object.assign(Object.assign({}, children[childNodeCounter].props.style), { maxWidth: '100%' }) }));
92
+ return (0, react_1.cloneElement)(children[childNodeCounter], Object.assign(Object.assign({}, children[childNodeCounter].props), { style: Object.assign(Object.assign(Object.assign(Object.assign({}, children[childNodeCounter].props.style), { aspectRatio: aspectRatio }), (isLastRow ? {} : { flex: aspectRatio })), { maxHeight: '100%' }) }));
92
93
  }
93
- return (react_1.default.createElement(react_1.default.Fragment, null,
94
- react_1.default.createElement("div", { style: { width: "100%" } }, rows.map((value, index, array) => {
95
- let isLastRow = index === array.length - 1 && showWidows;
96
- return react_1.default.createElement("div", { style: {
97
- display: "flex",
98
- flexDirection: "row",
99
- gap: itemSpacing,
100
- marginBottom: rowSpacing,
101
- aspectRatio: width / value.height
102
- } }, value.items.map((aspectRatio) => {
103
- return react_1.default.createElement("div", { style: isLastRow ? { aspectRatio: aspectRatio } : { flex: aspectRatio } }, renderChildren());
104
- }));
105
- }))));
94
+ return (react_1.default.createElement("div", { style: { width: "100%" } }, rows.map((value, index, array) => {
95
+ let isLastRow = index === array.length - 1 && showWidows;
96
+ return react_1.default.createElement("div", { className: 'justified-row', style: {
97
+ display: "flex",
98
+ flexDirection: "row",
99
+ gap: itemSpacing,
100
+ marginBottom: rowSpacing,
101
+ aspectRatio: width / value.height
102
+ } }, value.items.map((aspectRatio) => renderRow(aspectRatio, isLastRow)));
103
+ })));
106
104
  }
107
105
  exports.TSJustifiedLayout = TSJustifiedLayout;
@@ -9,3 +9,4 @@ type Story = StoryObj<typeof meta>;
9
9
  export declare const Primary: Story;
10
10
  export declare const Secondary: Story;
11
11
  export declare const Single: Story;
12
+ export declare const SingleWithDiv: Story;
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.Single = exports.Secondary = exports.Primary = void 0;
6
+ exports.SingleWithDiv = exports.Single = exports.Secondary = exports.Primary = void 0;
7
7
  const ConfiguredJustifiedLayout_1 = require("./ConfiguredJustifiedLayout");
8
8
  const react_1 = __importDefault(require("react"));
9
9
  const meta = {
@@ -172,6 +172,7 @@ const displayedImages = [
172
172
  ];
173
173
  // More on writing stories with args: https://storybook.js.org/docs/writing-stories/args
174
174
  exports.Primary = {
175
+ name: "Complex Elements",
175
176
  args: {
176
177
  width: 847,
177
178
  showWidows: true,
@@ -180,10 +181,13 @@ exports.Primary = {
180
181
  itemSpacing: undefined,
181
182
  layoutItems: displayedImages.map(value => value.aspectRatio),
182
183
  targetRowHeightTolerance: undefined,
183
- children: displayedImages.map(value => react_1.default.createElement("img", { src: value.webp }))
184
+ children: displayedImages.map(value => react_1.default.createElement("div", { style: { position: "relative" } },
185
+ react_1.default.createElement("div", { style: { top: 16, left: 16, position: "absolute" } }, "Testing"),
186
+ react_1.default.createElement("img", { src: value.webp })))
184
187
  },
185
188
  };
186
189
  exports.Secondary = {
190
+ name: "Image Tag Elements",
187
191
  args: {
188
192
  width: 847,
189
193
  showWidows: true,
@@ -196,6 +200,7 @@ exports.Secondary = {
196
200
  },
197
201
  };
198
202
  exports.Single = {
203
+ name: "Single Elements",
199
204
  args: {
200
205
  children: [react_1.default.createElement("img", { src: 'https://alcorsiteartbucket.s3.amazonaws.com/webp/alcor_wow.webp' })],
201
206
  width: 847,
@@ -207,3 +212,17 @@ exports.Single = {
207
212
  layoutItems: [1],
208
213
  }
209
214
  };
215
+ exports.SingleWithDiv = {
216
+ name: "Complex Single Element",
217
+ args: {
218
+ children: [react_1.default.createElement("div", null,
219
+ react_1.default.createElement("img", { src: 'https://alcorsiteartbucket.s3.amazonaws.com/webp/alcor_wow.webp' }))],
220
+ width: 847,
221
+ showWidows: true,
222
+ targetRowHeight: undefined,
223
+ rowSpacing: undefined,
224
+ itemSpacing: undefined,
225
+ targetRowHeightTolerance: undefined,
226
+ layoutItems: [1],
227
+ }
228
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-justified-layout-ts",
3
- "version": "1.1.13",
3
+ "version": "1.1.15",
4
4
  "description": "A component based off Flickr's justified layout that is compatible with Typescript",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -1,4 +1,5 @@
1
1
  import React, {cloneElement} from "react";
2
+ import './layout.css'
2
3
 
3
4
  type ElementDimensions = number;
4
5
 
@@ -92,37 +93,34 @@ function TSJustifiedLayout({
92
93
  /**
93
94
  * Clone the children element, and inject the height of the element as a prop
94
95
  */
95
- function renderChildren() {
96
+ function renderRow(aspectRatio: ElementDimensions, isLastRow: boolean) {
96
97
  childNodeCounter++;
97
98
  return cloneElement(children[childNodeCounter], {
98
99
  ...children[childNodeCounter].props, style: {
99
100
  ...children[childNodeCounter].props.style,
100
- maxWidth: '100%'
101
+ aspectRatio: aspectRatio,
102
+ ...(isLastRow ? {} : {flex: aspectRatio}),
103
+ maxHeight: '100%'
101
104
  }
102
105
  })
103
106
  }
104
107
 
105
108
  return (
106
- <>
107
- <div style={{width: "100%"}}>
108
- {rows.map((value, index, array) => {
109
- let isLastRow = index === array.length - 1 && showWidows;
110
- return <div style={{
111
- display: "flex",
112
- flexDirection: "row",
113
- gap: itemSpacing,
114
- marginBottom: rowSpacing,
115
- aspectRatio: width / value.height}
116
- }>
117
- {value.items.map((aspectRatio) => {
118
- return <div style={isLastRow ? {aspectRatio: aspectRatio} : {flex: aspectRatio}}>
119
- {renderChildren()}
120
- </div>;
121
- })}
122
- </div>
123
- })}
124
- </div>
125
- </>
109
+ <div style={{width: "100%"}}>
110
+ {rows.map((value, index, array) => {
111
+ let isLastRow = index === array.length - 1 && showWidows;
112
+ return <div className={'justified-row'} style={{
113
+ display: "flex",
114
+ flexDirection: "row",
115
+ gap: itemSpacing,
116
+ marginBottom: rowSpacing,
117
+ aspectRatio: width / value.height
118
+ }
119
+ }>
120
+ {value.items.map((aspectRatio) => renderRow(aspectRatio, isLastRow))}
121
+ </div>
122
+ })}
123
+ </div>
126
124
  );
127
125
  }
128
126
 
@@ -0,0 +1,3 @@
1
+ .justified-row img {
2
+ height: 100%
3
+ }
@@ -172,6 +172,7 @@ const displayedImages = [
172
172
 
173
173
  // More on writing stories with args: https://storybook.js.org/docs/writing-stories/args
174
174
  export const Primary: Story = {
175
+ name: "Complex Elements",
175
176
  args: {
176
177
  width: 847,
177
178
  showWidows: true,
@@ -180,11 +181,12 @@ export const Primary: Story = {
180
181
  itemSpacing: undefined,
181
182
  layoutItems: displayedImages.map(value => value.aspectRatio),
182
183
  targetRowHeightTolerance: undefined,
183
- children: displayedImages.map(value => <img src={value.webp} /> )
184
+ children: displayedImages.map(value => <div style={{position: "relative"}}><div style={{top: 16, left: 16, position: "absolute"}}>Testing</div><img src={value.webp} /></div> )
184
185
  },
185
186
  };
186
187
 
187
188
  export const Secondary: Story = {
189
+ name: "Image Tag Elements",
188
190
  args: {
189
191
  width: 847,
190
192
  showWidows: true,
@@ -198,6 +200,7 @@ export const Secondary: Story = {
198
200
  }
199
201
 
200
202
  export const Single: Story = {
203
+ name: "Single Elements",
201
204
  args: {
202
205
  children: [<img src={'https://alcorsiteartbucket.s3.amazonaws.com/webp/alcor_wow.webp'} />],
203
206
  width: 847,
@@ -209,3 +212,17 @@ export const Single: Story = {
209
212
  layoutItems: [1],
210
213
  }
211
214
  }
215
+
216
+ export const SingleWithDiv: Story = {
217
+ name: "Complex Single Element",
218
+ args: {
219
+ children: [<div><img src={'https://alcorsiteartbucket.s3.amazonaws.com/webp/alcor_wow.webp'} /></div>],
220
+ width: 847,
221
+ showWidows: true,
222
+ targetRowHeight: undefined,
223
+ rowSpacing: undefined,
224
+ itemSpacing: undefined,
225
+ targetRowHeightTolerance: undefined,
226
+ layoutItems: [1],
227
+ }
228
+ }