react-justified-layout-ts 1.1.14 → 1.1.16

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,20 +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(() => renderChildren()));
103
- }))));
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
+ })));
104
104
  }
105
105
  exports.TSJustifiedLayout = TSJustifiedLayout;
@@ -0,0 +1,3 @@
1
+ .justified-row img {
2
+ height: 100%
3
+ }
@@ -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,44 +1,47 @@
1
- {
2
- "name": "react-justified-layout-ts",
3
- "version": "1.1.14",
4
- "description": "A component based off Flickr's justified layout that is compatible with Typescript",
5
- "main": "./dist/index.js",
6
- "types": "./dist/index.d.ts",
7
- "scripts": {
8
- "test": "echo \"Error: no test specified\" && exit 1",
9
- "typescript": "tsc",
10
- "storybook": "storybook dev -p 6006",
11
- "build-storybook": "storybook build"
12
- },
13
- "keywords": [],
14
- "author": "Alan19",
15
- "license": "MIT",
16
- "dependencies": {
17
- "@types/node": "^20.10.7",
18
- "react-use": "^17.5.0",
19
- "react-use-measure": "^2.1.1"
20
- },
21
- "devDependencies": {
22
- "@chromatic-com/storybook": "^1.5.0",
23
- "@storybook/addon-essentials": "^8.1.5",
24
- "@storybook/addon-interactions": "^8.1.5",
25
- "@storybook/addon-links": "^8.1.5",
26
- "@storybook/addon-onboarding": "^8.1.5",
27
- "@storybook/addon-webpack5-compiler-swc": "^1.0.3",
28
- "@storybook/blocks": "^8.1.5",
29
- "@storybook/react": "^8.1.5",
30
- "@storybook/react-webpack5": "^8.1.5",
31
- "@storybook/test": "^8.1.5",
32
- "@types/react": "^18.2.47",
33
- "react": "^18.2.0",
34
- "storybook": "^8.1.5",
35
- "typescript": "^5.3.3"
36
- },
37
- "peerDependencies": {
38
- "react": "^18.2.0"
39
- },
40
- "repository": {
41
- "type": "git",
42
- "url": "git+https://github.com/Alan19/react-justified-layout-ts.git"
43
- }
44
- }
1
+ {
2
+ "name": "react-justified-layout-ts",
3
+ "version": "1.1.16",
4
+ "description": "A component based off Flickr's justified layout that is compatible with Typescript",
5
+ "main": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
7
+ "exports": {},
8
+ "scripts": {
9
+ "test": "echo \"Error: no test specified\" && exit 1",
10
+ "typescript": "tsc && copyfiles -u 1 src/**/*.css dist/",
11
+ "storybook": "storybook dev -p 6006",
12
+ "build-storybook": "storybook build"
13
+ },
14
+ "keywords": [],
15
+ "author": "Alan19",
16
+ "license": "MIT",
17
+ "dependencies": {
18
+ "@types/node": "^20.10.7",
19
+ "react-use": "^17.5.0",
20
+ "react-use-measure": "^2.1.1"
21
+ },
22
+ "devDependencies": {
23
+ "@chromatic-com/storybook": "^1.5.0",
24
+ "@storybook/addon-essentials": "^8.1.5",
25
+ "@storybook/addon-interactions": "^8.1.5",
26
+ "@storybook/addon-links": "^8.1.5",
27
+ "@storybook/addon-onboarding": "^8.1.5",
28
+ "@storybook/addon-webpack5-compiler-swc": "^1.0.3",
29
+ "@storybook/blocks": "^8.1.5",
30
+ "@storybook/react": "^8.1.5",
31
+ "@storybook/react-webpack5": "^8.1.5",
32
+ "@storybook/test": "^8.1.5",
33
+ "@types/react": "^18.2.47",
34
+ "copyfiles": "^2.4.1",
35
+ "react": "^18.2.0",
36
+ "rimraf": "^5.0.7",
37
+ "storybook": "^8.1.5",
38
+ "typescript": "^5.3.3"
39
+ },
40
+ "peerDependencies": {
41
+ "react": "^18.2.0"
42
+ },
43
+ "repository": {
44
+ "type": "git",
45
+ "url": "git+https://github.com/Alan19/react-justified-layout-ts.git"
46
+ }
47
+ }
@@ -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,33 +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(() => renderChildren())}
118
- </div>
119
- })}
120
- </div>
121
- </>
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>
122
124
  );
123
125
  }
124
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,14 @@ 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"}}>
185
+ <div style={{top: 16, left: 16, position: "absolute"}}>Testing</div>
186
+ <img src={value.webp}/></div>)
184
187
  },
185
188
  };
186
189
 
187
190
  export const Secondary: Story = {
191
+ name: "Image Tag Elements",
188
192
  args: {
189
193
  width: 847,
190
194
  showWidows: true,
@@ -198,6 +202,7 @@ export const Secondary: Story = {
198
202
  }
199
203
 
200
204
  export const Single: Story = {
205
+ name: "Single Elements",
201
206
  args: {
202
207
  children: [<img src={'https://alcorsiteartbucket.s3.amazonaws.com/webp/alcor_wow.webp'} />],
203
208
  width: 847,
@@ -209,3 +214,17 @@ export const Single: Story = {
209
214
  layoutItems: [1],
210
215
  }
211
216
  }
217
+
218
+ export const SingleWithDiv: Story = {
219
+ name: "Complex Single Element",
220
+ args: {
221
+ children: [<div><img src={'https://alcorsiteartbucket.s3.amazonaws.com/webp/alcor_wow.webp'}/></div>],
222
+ width: 847,
223
+ showWidows: true,
224
+ targetRowHeight: undefined,
225
+ rowSpacing: undefined,
226
+ itemSpacing: undefined,
227
+ targetRowHeightTolerance: undefined,
228
+ layoutItems: [1],
229
+ }
230
+ }