react-justified-layout-ts 2.1.5 → 2.2.1
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.
- package/.storybook/main.ts +12 -13
- package/.storybook/preview.ts +11 -4
- package/README.md +44 -44
- package/dist/components/JustifiedGrid.js +10 -9
- package/dist/components/layout.css +3 -3
- package/dist/src/components/JustifiedGrid.d.ts +13 -0
- package/dist/src/components/JustifiedGrid.js +59 -0
- package/dist/src/components/TSJustifiedLayout.d.ts +18 -0
- package/dist/src/components/TSJustifiedLayout.js +99 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.js +7 -0
- package/dist/src/stories/ConfiguredJustifiedLayout.d.ts +3 -0
- package/dist/src/stories/ConfiguredJustifiedLayout.js +12 -0
- package/dist/src/stories/JustifiedLayout.stories.d.ts +13 -0
- package/dist/src/stories/JustifiedLayout.stories.js +202 -0
- package/dist/stories/JustifiedLayout.stories.d.ts +0 -1
- package/dist/stories/JustifiedLayout.stories.js +5 -6
- package/package.json +43 -49
- package/src/components/JustifiedGrid.d.ts +14 -0
- package/src/components/JustifiedGrid.d.ts.map +1 -0
- package/src/components/JustifiedGrid.js +63 -0
- package/src/components/JustifiedGrid.js.map +1 -0
- package/src/components/JustifiedGrid.tsx +79 -78
- package/src/components/TSJustifiedLayout.d.ts +19 -0
- package/src/components/TSJustifiedLayout.d.ts.map +1 -0
- package/src/components/TSJustifiedLayout.js +98 -0
- package/src/components/TSJustifiedLayout.js.map +1 -0
- package/src/components/TSJustifiedLayout.tsx +139 -139
- package/src/components/layout.css +3 -3
- package/src/declarations.d.ts +1 -0
- package/src/index.d.ts +4 -0
- package/src/index.d.ts.map +1 -0
- package/src/index.js +8 -0
- package/src/index.js.map +1 -0
- package/src/index.ts +3 -2
- package/src/stories/Configure.mdx +388 -364
- package/src/stories/ConfiguredJustifiedLayout.d.ts +3 -0
- package/src/stories/ConfiguredJustifiedLayout.d.ts.map +1 -0
- package/src/stories/ConfiguredJustifiedLayout.js +10 -0
- package/src/stories/ConfiguredJustifiedLayout.js.map +1 -0
- package/src/stories/ConfiguredJustifiedLayout.tsx +22 -22
- package/src/stories/JustifiedLayout.stories.d.ts +13 -0
- package/src/stories/JustifiedLayout.stories.d.ts.map +1 -0
- package/src/stories/JustifiedLayout.stories.js +197 -0
- package/src/stories/JustifiedLayout.stories.js.map +1 -0
- package/src/stories/JustifiedLayout.stories.tsx +204 -205
- package/src/stories/assets/accessibility.svg +1 -5
- package/src/stories/assets/discord.svg +1 -15
- package/src/stories/assets/github.svg +1 -3
- package/src/stories/assets/tutorials.svg +1 -12
- package/src/stories/assets/youtube.svg +1 -4
- package/tsconfig.json +44 -15
- package/LICENSE +0 -21
package/.storybook/main.ts
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
import type { StorybookConfig } from
|
|
1
|
+
import type { StorybookConfig } from '@storybook/react-vite';
|
|
2
2
|
|
|
3
3
|
const config: StorybookConfig = {
|
|
4
|
-
stories: [
|
|
5
|
-
|
|
6
|
-
"
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
"@storybook/addon-essentials",
|
|
4
|
+
"stories": [
|
|
5
|
+
"../src/**/*.mdx",
|
|
6
|
+
"../src/**/*.stories.@(js|jsx|mjs|ts|tsx)"
|
|
7
|
+
],
|
|
8
|
+
"addons": [
|
|
10
9
|
"@chromatic-com/storybook",
|
|
11
|
-
"@storybook/addon-
|
|
10
|
+
"@storybook/addon-vitest",
|
|
11
|
+
"@storybook/addon-a11y",
|
|
12
|
+
"@storybook/addon-docs",
|
|
13
|
+
"@storybook/addon-onboarding"
|
|
12
14
|
],
|
|
13
|
-
framework:
|
|
14
|
-
name: "@storybook/react-webpack5",
|
|
15
|
-
options: {},
|
|
16
|
-
},
|
|
15
|
+
"framework": "@storybook/react-vite"
|
|
17
16
|
};
|
|
18
|
-
export default config;
|
|
17
|
+
export default config;
|
package/.storybook/preview.ts
CHANGED
|
@@ -1,14 +1,21 @@
|
|
|
1
|
-
import type { Preview } from
|
|
1
|
+
import type { Preview } from '@storybook/react-vite'
|
|
2
2
|
|
|
3
3
|
const preview: Preview = {
|
|
4
4
|
parameters: {
|
|
5
5
|
controls: {
|
|
6
6
|
matchers: {
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
color: /(background|color)$/i,
|
|
8
|
+
date: /Date$/i,
|
|
9
9
|
},
|
|
10
10
|
},
|
|
11
|
+
|
|
12
|
+
a11y: {
|
|
13
|
+
// 'todo' - show a11y violations in the test UI only
|
|
14
|
+
// 'error' - fail CI on a11y violations
|
|
15
|
+
// 'off' - skip a11y checks entirely
|
|
16
|
+
test: 'todo'
|
|
17
|
+
}
|
|
11
18
|
},
|
|
12
19
|
};
|
|
13
20
|
|
|
14
|
-
export default preview;
|
|
21
|
+
export default preview;
|
package/README.md
CHANGED
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
A TypeScript component similar to Flickr's justified layout.
|
|
2
|
-
|
|
3
|
-
# Usage
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
Add the `TSJustifiedLayout` component to your code with the following props:
|
|
7
|
-
|
|
8
|
-
- `aspectRatioList: number[];` - An array of aspect ratios for the images you are adding to the grid
|
|
9
|
-
- `itemSpacing?: number;` - The amount of spacing between each image, in pixels. (Default: 10)
|
|
10
|
-
- `rowSpacing?: number;` - The amount of spacing between each row, in pixels. (Default: 10)
|
|
11
|
-
- `targetRowHeight?: number;` - The target row height for a row, in pixels. (Default: 320)
|
|
12
|
-
- `targetRowHeightTolerance?: number;` - The amount the row height could deviate from the target row height, as a percent. (Default: .25)
|
|
13
|
-
- `width: number;` - The width of the container. I would use something like `react-use-measure` if you're trying to make it dynamically take up the size of the parent container.
|
|
14
|
-
- `children: any[];` - The children elements that makes up the grid.
|
|
15
|
-
- `showWidows?: boolean;` - If the last row should be shown. (Default: true)
|
|
16
|
-
|
|
17
|
-
## Example Usage
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
```typescript jsx
|
|
21
|
-
<TSJustifiedLayout width={width}
|
|
22
|
-
aspectRatioList={imagesOnPage.map(value => ({
|
|
23
|
-
dimensions: value.aspectRatio || 1
|
|
24
|
-
}))}>
|
|
25
|
-
{imagesOnPage.map(value => <img
|
|
26
|
-
src={value.src}
|
|
27
|
-
alt={value.alt}
|
|
28
|
-
/>)}
|
|
29
|
-
</TSJustifiedLayout>
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
# Install
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
`npm i react-justified-layout-ts`
|
|
36
|
-
|
|
37
|
-
# Credits
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
The display logic for the layout and the math used to calculate the row height for each row is adapted from [Flickr's Justified Layout library](https://github.com/flickr/justified-layout).
|
|
41
|
-
|
|
42
|
-
# License
|
|
43
|
-
|
|
44
|
-
|
|
1
|
+
A TypeScript component similar to Flickr's justified layout.
|
|
2
|
+
|
|
3
|
+
# Usage
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
Add the `TSJustifiedLayout` component to your code with the following props:
|
|
7
|
+
|
|
8
|
+
- `aspectRatioList: number[];` - An array of aspect ratios for the images you are adding to the grid
|
|
9
|
+
- `itemSpacing?: number;` - The amount of spacing between each image, in pixels. (Default: 10)
|
|
10
|
+
- `rowSpacing?: number;` - The amount of spacing between each row, in pixels. (Default: 10)
|
|
11
|
+
- `targetRowHeight?: number;` - The target row height for a row, in pixels. (Default: 320)
|
|
12
|
+
- `targetRowHeightTolerance?: number;` - The amount the row height could deviate from the target row height, as a percent. (Default: .25)
|
|
13
|
+
- `width: number;` - The width of the container. I would use something like `react-use-measure` if you're trying to make it dynamically take up the size of the parent container.
|
|
14
|
+
- `children: any[];` - The children elements that makes up the grid.
|
|
15
|
+
- `showWidows?: boolean;` - If the last row should be shown. (Default: true)
|
|
16
|
+
|
|
17
|
+
## Example Usage
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
```typescript jsx
|
|
21
|
+
<TSJustifiedLayout width={width}
|
|
22
|
+
aspectRatioList={imagesOnPage.map(value => ({
|
|
23
|
+
dimensions: value.aspectRatio || 1
|
|
24
|
+
}))}>
|
|
25
|
+
{imagesOnPage.map(value => <img
|
|
26
|
+
src={value.src}
|
|
27
|
+
alt={value.alt}
|
|
28
|
+
/>)}
|
|
29
|
+
</TSJustifiedLayout>
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
# Install
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
`npm i react-justified-layout-ts`
|
|
36
|
+
|
|
37
|
+
# Credits
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
The display logic for the layout and the math used to calculate the row height for each row is adapted from [Flickr's Justified Layout library](https://github.com/flickr/justified-layout).
|
|
41
|
+
|
|
42
|
+
# License
|
|
43
|
+
|
|
44
|
+
|
|
45
45
|
Open Source Licensed under the MIT license.
|
|
@@ -42,17 +42,18 @@ function JustifiedGrid(props) {
|
|
|
42
42
|
const { targetRowHeightTolerance = .25, width, targetRowHeight = 320, itemSpacing = 8, rowSpacing = 8, children, containerStyle, aspectRatioList } = props;
|
|
43
43
|
const rows = getJustifiedGridRowConfiguration(width, targetRowHeightTolerance, aspectRatioList, targetRowHeight, itemSpacing);
|
|
44
44
|
let childNodeCounter = -1;
|
|
45
|
-
function renderRowItem(value, aspectRatio) {
|
|
46
|
-
childNodeCounter++;
|
|
47
|
-
return react_1.default.createElement("div", { style: Object.assign({ flex: value.length === 1 ? 1 : aspectRatio }, containerStyle) }, children[childNodeCounter]);
|
|
48
|
-
}
|
|
49
45
|
return (react_1.default.createElement("div", { style: {
|
|
50
46
|
display: 'flex',
|
|
51
47
|
flexDirection: 'column',
|
|
52
48
|
gap: rowSpacing
|
|
53
|
-
} }, rows.map(value =>
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
49
|
+
} }, rows.map((value) => {
|
|
50
|
+
return react_1.default.createElement("div", { className: 'justified-row', style: {
|
|
51
|
+
display: "flex",
|
|
52
|
+
flexDirection: "row",
|
|
53
|
+
gap: itemSpacing,
|
|
54
|
+
} }, value.map((aspectRatio) => {
|
|
55
|
+
childNodeCounter++;
|
|
56
|
+
return react_1.default.createElement("div", { style: Object.assign({ flex: value.length === 1 ? 1 : aspectRatio }, containerStyle) }, children[childNodeCounter]);
|
|
57
|
+
}));
|
|
58
|
+
})));
|
|
58
59
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
.justified-row img {
|
|
2
|
-
width: 100%;
|
|
3
|
-
display: block;
|
|
1
|
+
.justified-row img {
|
|
2
|
+
width: 100%;
|
|
3
|
+
display: block;
|
|
4
4
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import './layout.css';
|
|
3
|
+
export interface JustifiedGridProps {
|
|
4
|
+
aspectRatioList: number[];
|
|
5
|
+
itemSpacing?: number;
|
|
6
|
+
rowSpacing?: number;
|
|
7
|
+
targetRowHeight?: number;
|
|
8
|
+
targetRowHeightTolerance?: number;
|
|
9
|
+
width: number;
|
|
10
|
+
children: React.JSX.Element[];
|
|
11
|
+
containerStyle?: React.CSSProperties;
|
|
12
|
+
}
|
|
13
|
+
export declare function JustifiedGrid(props: Readonly<JustifiedGridProps>): React.JSX.Element;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.JustifiedGrid = JustifiedGrid;
|
|
7
|
+
const react_1 = __importDefault(require("react"));
|
|
8
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
9
|
+
require("./layout.css");
|
|
10
|
+
function getJustifiedGridRowConfiguration(width, targetRowHeightTolerance, aspectRatioList, targetRowHeight, itemSpacing) {
|
|
11
|
+
let buffer = [];
|
|
12
|
+
const rows = [];
|
|
13
|
+
// We assume that the row will have the specified height, which allows us to convert aspect ratios into widths
|
|
14
|
+
const minRowWidth = width * (1 / (1 + targetRowHeightTolerance));
|
|
15
|
+
const maxRowWidth = width * (1 / (1 - targetRowHeightTolerance));
|
|
16
|
+
aspectRatioList.forEach((aspectRatio, index) => {
|
|
17
|
+
let currentRowWidth = (lodash_1.default.sum(buffer) * targetRowHeight + aspectRatio * targetRowHeight + itemSpacing * (buffer.length));
|
|
18
|
+
// If the new item's width would cause it to fall between the tolerances for max widths, finish the row
|
|
19
|
+
// If the new item's width would cause it to exceed the tolerances for the row, add it to a new row
|
|
20
|
+
if (buffer.length === 0 || currentRowWidth < maxRowWidth) {
|
|
21
|
+
buffer.push(aspectRatio);
|
|
22
|
+
if (currentRowWidth > minRowWidth) {
|
|
23
|
+
rows.push(buffer);
|
|
24
|
+
buffer = [];
|
|
25
|
+
}
|
|
26
|
+
// If we're handling the last item, and it doesn't exceed the minimum tolerance for the row width, we add a "dummy" item to make the rest of the row now take up the whole width
|
|
27
|
+
else if (index === aspectRatioList.length - 1) {
|
|
28
|
+
buffer.push((width - lodash_1.default.sum(buffer) * targetRowHeight - itemSpacing * (buffer.length - 1)) / targetRowHeight);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
rows.push(buffer);
|
|
33
|
+
buffer = [aspectRatio];
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
if (buffer.length !== 0) {
|
|
37
|
+
rows.push(buffer);
|
|
38
|
+
}
|
|
39
|
+
return rows;
|
|
40
|
+
}
|
|
41
|
+
function JustifiedGrid(props) {
|
|
42
|
+
const { targetRowHeightTolerance = .25, width, targetRowHeight = 320, itemSpacing = 8, rowSpacing = 8, children, containerStyle, aspectRatioList } = props;
|
|
43
|
+
const rows = getJustifiedGridRowConfiguration(width, targetRowHeightTolerance, aspectRatioList, targetRowHeight, itemSpacing);
|
|
44
|
+
let childNodeCounter = -1;
|
|
45
|
+
return (react_1.default.createElement("div", { style: {
|
|
46
|
+
display: 'flex',
|
|
47
|
+
flexDirection: 'column',
|
|
48
|
+
gap: rowSpacing
|
|
49
|
+
} }, rows.map((value) => {
|
|
50
|
+
return react_1.default.createElement("div", { className: 'justified-row', style: {
|
|
51
|
+
display: "flex",
|
|
52
|
+
flexDirection: "row",
|
|
53
|
+
gap: itemSpacing,
|
|
54
|
+
} }, value.map((aspectRatio) => {
|
|
55
|
+
childNodeCounter++;
|
|
56
|
+
return react_1.default.createElement("div", { style: Object.assign({ flex: value.length === 1 ? 1 : aspectRatio }, containerStyle) }, children[childNodeCounter]);
|
|
57
|
+
}));
|
|
58
|
+
})));
|
|
59
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import './layout.css';
|
|
3
|
+
export interface TSJustifiedLayoutProps {
|
|
4
|
+
aspectRatioList: number[];
|
|
5
|
+
itemSpacing?: number;
|
|
6
|
+
rowSpacing?: number;
|
|
7
|
+
targetRowHeight?: number;
|
|
8
|
+
targetRowHeightTolerance?: number;
|
|
9
|
+
width: number;
|
|
10
|
+
children: React.JSX.Element[];
|
|
11
|
+
showWidows?: boolean;
|
|
12
|
+
containerStyle?: React.CSSProperties;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* @deprecated Use the new {@link JustifiedGrid} component instead as it has better handling for heights of widow rows and future work will be done there
|
|
16
|
+
*/
|
|
17
|
+
declare function TSJustifiedLayout({ children, aspectRatioList, itemSpacing, rowSpacing, showWidows, targetRowHeight, targetRowHeightTolerance, width, containerStyle }: Readonly<TSJustifiedLayoutProps>): React.JSX.Element;
|
|
18
|
+
export { TSJustifiedLayout, TSJustifiedLayout as JustifiedGrid };
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.TSJustifiedLayout = TSJustifiedLayout;
|
|
7
|
+
exports.JustifiedGrid = TSJustifiedLayout;
|
|
8
|
+
const react_1 = __importDefault(require("react"));
|
|
9
|
+
require("./layout.css");
|
|
10
|
+
/**
|
|
11
|
+
* @deprecated Use the new {@link JustifiedGrid} component instead as it has better handling for heights of widow rows and future work will be done there
|
|
12
|
+
*/
|
|
13
|
+
function TSJustifiedLayout({ children, aspectRatioList, itemSpacing = 10, rowSpacing = 10, showWidows = true, targetRowHeight = 320, targetRowHeightTolerance = .25, width, containerStyle }) {
|
|
14
|
+
const minAspectRatio = width / targetRowHeight * (1 - targetRowHeightTolerance);
|
|
15
|
+
const maxAspectRatio = width / targetRowHeight * (1 + targetRowHeightTolerance);
|
|
16
|
+
const rows = [];
|
|
17
|
+
let rowBuffer = [];
|
|
18
|
+
/**
|
|
19
|
+
* Attempts to add an item to the current row buffer
|
|
20
|
+
* @param value The new aspect ratio to be checked
|
|
21
|
+
* @return If the buffer can accept the new value
|
|
22
|
+
* */
|
|
23
|
+
function addItem(value) {
|
|
24
|
+
const newItems = rowBuffer.concat(value);
|
|
25
|
+
const newAspectRatio = newItems.reduce((previousValue, currentValue) => previousValue + currentValue, 0);
|
|
26
|
+
const rowWidthMinusSpacing = width - (newItems.length - 1) * itemSpacing;
|
|
27
|
+
const targetAspectRatio = rowWidthMinusSpacing / targetRowHeight;
|
|
28
|
+
// Row still has space
|
|
29
|
+
if (newAspectRatio < minAspectRatio) {
|
|
30
|
+
rowBuffer.push(value);
|
|
31
|
+
}
|
|
32
|
+
// Row ran out of space, and the new item is larger than the max aspect ratio for the row
|
|
33
|
+
else if (newAspectRatio > maxAspectRatio) {
|
|
34
|
+
// Always accept if it's just 1 item
|
|
35
|
+
if (rowBuffer.length === 0) {
|
|
36
|
+
rowBuffer.push(value);
|
|
37
|
+
rows.push({ items: rowBuffer, height: rowWidthMinusSpacing / newAspectRatio });
|
|
38
|
+
rowBuffer = [];
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
// Calculate width/aspect ratio for row before adding new item
|
|
42
|
+
const previousRowWidthWithoutSpacing = width - (rowBuffer.length - 1) * itemSpacing;
|
|
43
|
+
const previousAspectRatio = rowBuffer.reduce((previousValue, currentValue) => previousValue + currentValue, 0);
|
|
44
|
+
const previousTargetAspectRatio = previousRowWidthWithoutSpacing / targetRowHeight;
|
|
45
|
+
// 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
|
|
46
|
+
if (Math.abs(newAspectRatio - targetAspectRatio) > Math.abs(previousAspectRatio - previousTargetAspectRatio)) {
|
|
47
|
+
rows.push({ items: rowBuffer, height: previousRowWidthWithoutSpacing / previousAspectRatio });
|
|
48
|
+
rowBuffer = [value];
|
|
49
|
+
}
|
|
50
|
+
// If the new aspect ratio is closer to the target aspect ratio, then insert item and push row buffer
|
|
51
|
+
else {
|
|
52
|
+
rowBuffer.push(value);
|
|
53
|
+
rows.push({ items: rowBuffer, height: rowWidthMinusSpacing / newAspectRatio });
|
|
54
|
+
rowBuffer = [];
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
// New aspect ratio is within aspect ratio tolerance, so we finish off the row
|
|
60
|
+
rowBuffer.push(value);
|
|
61
|
+
rows.push({ items: rowBuffer, height: rowWidthMinusSpacing / newAspectRatio });
|
|
62
|
+
rowBuffer = [];
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
aspectRatioList.forEach((value) => {
|
|
66
|
+
addItem(value);
|
|
67
|
+
});
|
|
68
|
+
// Handle leftover content
|
|
69
|
+
if (showWidows && rowBuffer.length !== 0) {
|
|
70
|
+
rows.push({ items: rowBuffer, height: rows.length === 0 ? targetRowHeight : rows[rows.length - 1].height });
|
|
71
|
+
}
|
|
72
|
+
let childNodeCounter = -1;
|
|
73
|
+
/**
|
|
74
|
+
* Clone the children element, and inject the height of the element as a prop
|
|
75
|
+
*/
|
|
76
|
+
function renderRowItem(aspectRatio, isSoloRow, lastRowWithinTolerance, fakeElementAspectRatio) {
|
|
77
|
+
childNodeCounter++;
|
|
78
|
+
return react_1.default.createElement("div", { style: Object.assign({ flex: isSoloRow ? 1 : aspectRatio }, containerStyle) },
|
|
79
|
+
children[childNodeCounter],
|
|
80
|
+
lastRowWithinTolerance && react_1.default.createElement("div", { style: { flex: fakeElementAspectRatio } }));
|
|
81
|
+
}
|
|
82
|
+
// TODO Figure out how to eliminate the tiny gap between div and actual image height
|
|
83
|
+
// TODO Make bottom row respect length restrictions
|
|
84
|
+
return (react_1.default.createElement("div", { style: {
|
|
85
|
+
display: 'flex',
|
|
86
|
+
flexDirection: 'column',
|
|
87
|
+
gap: rowSpacing
|
|
88
|
+
} }, rows.map((value, index, array) => {
|
|
89
|
+
let isLastRow = index === array.length - 1 && showWidows;
|
|
90
|
+
let rowAspectRatioSum = value.items.reduce((previousValue, currentValue) => previousValue + currentValue, 0);
|
|
91
|
+
const isLastRowWithinTolerance = isLastRow && rowAspectRatioSum * value.height + (value.items.length - 1) * itemSpacing < minAspectRatio * value.height;
|
|
92
|
+
const fakeElementAspectRatio = (width - rowAspectRatioSum * value.height - (value.items.length - 1) * itemSpacing) / value.height;
|
|
93
|
+
return react_1.default.createElement("div", { className: 'justified-row', style: {
|
|
94
|
+
display: "flex",
|
|
95
|
+
flexDirection: "row",
|
|
96
|
+
gap: itemSpacing,
|
|
97
|
+
} }, value.items.map((aspectRatio) => renderRowItem(aspectRatio, value.items.length === 1, isLastRowWithinTolerance, fakeElementAspectRatio)));
|
|
98
|
+
})));
|
|
99
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.JustifiedGrid = exports.TSJustifiedLayout = void 0;
|
|
4
|
+
var TSJustifiedLayout_1 = require("./components/TSJustifiedLayout");
|
|
5
|
+
Object.defineProperty(exports, "TSJustifiedLayout", { enumerable: true, get: function () { return TSJustifiedLayout_1.TSJustifiedLayout; } });
|
|
6
|
+
var JustifiedGrid_1 = require("./components/JustifiedGrid");
|
|
7
|
+
Object.defineProperty(exports, "JustifiedGrid", { enumerable: true, get: function () { return JustifiedGrid_1.JustifiedGrid; } });
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { TSJustifiedLayoutProps } from "../components/TSJustifiedLayout";
|
|
2
|
+
import React from "react";
|
|
3
|
+
export declare const ConfiguredJustifiedLayout: ({ aspectRatioList, rowSpacing, width, itemSpacing, targetRowHeight, targetRowHeightTolerance, children }: TSJustifiedLayoutProps) => React.JSX.Element;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ConfiguredJustifiedLayout = void 0;
|
|
7
|
+
const react_1 = __importDefault(require("react"));
|
|
8
|
+
const JustifiedGrid_1 = require("../components/JustifiedGrid");
|
|
9
|
+
const ConfiguredJustifiedLayout = ({ aspectRatioList, rowSpacing = 8, width = 1000, itemSpacing = 8, targetRowHeight = 320, targetRowHeightTolerance = 0.10, children }) => {
|
|
10
|
+
return react_1.default.createElement(JustifiedGrid_1.JustifiedGrid, { aspectRatioList: aspectRatioList, width: width, itemSpacing: itemSpacing, targetRowHeight: targetRowHeight, targetRowHeightTolerance: targetRowHeightTolerance, rowSpacing: rowSpacing }, children.map((child) => child));
|
|
11
|
+
};
|
|
12
|
+
exports.ConfiguredJustifiedLayout = ConfiguredJustifiedLayout;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { StoryObj } from "@storybook/react";
|
|
2
|
+
import React from "react";
|
|
3
|
+
declare const meta: {
|
|
4
|
+
title: string;
|
|
5
|
+
component: ({ aspectRatioList, rowSpacing, width, itemSpacing, targetRowHeight, targetRowHeightTolerance, children }: import("../components/TSJustifiedLayout").TSJustifiedLayoutProps) => React.JSX.Element;
|
|
6
|
+
};
|
|
7
|
+
export default meta;
|
|
8
|
+
type Story = StoryObj<typeof meta>;
|
|
9
|
+
export declare const Primary: Story;
|
|
10
|
+
export declare const Secondary: Story;
|
|
11
|
+
export declare const Divs: Story;
|
|
12
|
+
export declare const Single: Story;
|
|
13
|
+
export declare const SingleWithDiv: Story;
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.SingleWithDiv = exports.Single = exports.Divs = exports.Secondary = exports.Primary = void 0;
|
|
7
|
+
const ConfiguredJustifiedLayout_1 = require("./ConfiguredJustifiedLayout");
|
|
8
|
+
const react_1 = __importDefault(require("react"));
|
|
9
|
+
const react_loading_skeleton_1 = __importDefault(require("react-loading-skeleton"));
|
|
10
|
+
const meta = {
|
|
11
|
+
title: 'JustifiedLayout/Basic',
|
|
12
|
+
component: ConfiguredJustifiedLayout_1.ConfiguredJustifiedLayout,
|
|
13
|
+
};
|
|
14
|
+
exports.default = meta;
|
|
15
|
+
const displayedImages = [
|
|
16
|
+
{
|
|
17
|
+
"title": "Outfit Sheet",
|
|
18
|
+
"artist": "@godbirdart",
|
|
19
|
+
"tags": [
|
|
20
|
+
"Vernal",
|
|
21
|
+
"Serotinal Circuitboard",
|
|
22
|
+
"Estival Checker",
|
|
23
|
+
"Autumnal Wavesniper",
|
|
24
|
+
"Hibernal Assassin",
|
|
25
|
+
"Rastaban Form",
|
|
26
|
+
"Knives",
|
|
27
|
+
"Techwear",
|
|
28
|
+
"Hoodie",
|
|
29
|
+
"Bodysuit",
|
|
30
|
+
"Featured"
|
|
31
|
+
],
|
|
32
|
+
"href": "https://x.com/FaintAlcor/status/1785179761309839456",
|
|
33
|
+
"published": "2024-04-30",
|
|
34
|
+
"aspectRatio": 2.35,
|
|
35
|
+
"thumbnailUrl": "https://alcorsiteartbucket.s3.amazonaws.com/600h/outfit_sheet.webp",
|
|
36
|
+
"webp": "https://alcorsiteartbucket.s3.amazonaws.com/webp/outfit_sheet.webp",
|
|
37
|
+
"src": "https://alcorsiteartbucket.s3.amazonaws.com/outfit_sheet.PNG"
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
"title": "Quick-Draw Stance",
|
|
41
|
+
"artist": "@RSN_07",
|
|
42
|
+
"tags": [
|
|
43
|
+
"Aquarius Form",
|
|
44
|
+
"Featured"
|
|
45
|
+
],
|
|
46
|
+
"href": "https://x.com/RSN_07/status/1775664237119217719?s=20",
|
|
47
|
+
"published": "2024-04-03",
|
|
48
|
+
"aspectRatio": 0.6328125,
|
|
49
|
+
"thumbnailUrl": "https://alcorsiteartbucket.s3.amazonaws.com/600h/quick_draw_stance.webp",
|
|
50
|
+
"webp": "https://alcorsiteartbucket.s3.amazonaws.com/webp/quick_draw_stance.webp",
|
|
51
|
+
"src": "https://alcorsiteartbucket.s3.amazonaws.com/quick_draw_stance.PNG"
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"title": "Evening Train",
|
|
55
|
+
"artist": "@greyy_arts",
|
|
56
|
+
"tags": [
|
|
57
|
+
"Estival Checker",
|
|
58
|
+
"Rastaban Form",
|
|
59
|
+
"Hoodie",
|
|
60
|
+
"Featured"
|
|
61
|
+
],
|
|
62
|
+
"href": "https://twitter.com/greyy_arts/status/1613748293531758593",
|
|
63
|
+
"published": "2023-01-12",
|
|
64
|
+
"thumbnailUrl": "https://alcorsiteartbucket.s3.amazonaws.com/600h/evening_train.webp",
|
|
65
|
+
"src": "https://alcorsiteartbucket.s3.amazonaws.com/evening_train.png",
|
|
66
|
+
"aspectRatio": 0.8203125,
|
|
67
|
+
"webp": "https://alcorsiteartbucket.s3.amazonaws.com/webp/evening_train.webp"
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
"src": "https://pbs.twimg.com/media/Fj2qZYRVEAAVyRC?format=jpg&name=large",
|
|
71
|
+
"title": "AICore Relaxing",
|
|
72
|
+
"href": "https://twitter.com/KuroPenguinEx/status/1602624683211227136/photo/1",
|
|
73
|
+
"artist": "@KuroPenguinEx",
|
|
74
|
+
"tags": [
|
|
75
|
+
"AICore Form",
|
|
76
|
+
"Thuban Form",
|
|
77
|
+
"Featured"
|
|
78
|
+
],
|
|
79
|
+
"published": "2022-12-13",
|
|
80
|
+
"aspectRatio": 1.3333333333333333
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
"title": "Sci-fi Mode: ON",
|
|
84
|
+
"href": "https://twitter.com/AxyUsagi/status/1543041029674344448?s=20&t=tlXwc5aegdXuQeLhgdUw-Q",
|
|
85
|
+
"artist": "@AxyUsagi",
|
|
86
|
+
"src": "https://pbs.twimg.com/media/FWn7dJ9XkAIHM5j?format=jpg&name=medium",
|
|
87
|
+
"tags": [
|
|
88
|
+
"Thuban Form",
|
|
89
|
+
"Knives",
|
|
90
|
+
"Hoodie",
|
|
91
|
+
"Techwear",
|
|
92
|
+
"Bodysuit",
|
|
93
|
+
"Featured"
|
|
94
|
+
],
|
|
95
|
+
"published": "2022-07-01",
|
|
96
|
+
"aspectRatio": 0.9166666666666666
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
"title": "Lance Hero",
|
|
100
|
+
"href": "https://twitter.com/eb_kemo/status/1521991097098305536?s=20&t=8fG0sc10hW-oJEyn8HzT3w",
|
|
101
|
+
"src": "https://pbs.twimg.com/media/FR8y1bnakAA0Pol?format=jpg&name=large",
|
|
102
|
+
"artist": "@eb_erh",
|
|
103
|
+
"tags": [
|
|
104
|
+
"Rastaban Form",
|
|
105
|
+
"Gungrir Suit",
|
|
106
|
+
"Lances",
|
|
107
|
+
"Superhero",
|
|
108
|
+
"Featured"
|
|
109
|
+
],
|
|
110
|
+
"published": "2022-05-04",
|
|
111
|
+
"aspectRatio": 0.85107421875
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
"src": "https://pbs.twimg.com/media/FnHp4nWaUAA-lgD?format=jpg&name=large",
|
|
115
|
+
"title": "Special Archery Training!",
|
|
116
|
+
"href": "https://twitter.com/Yamainu_ken/status/1617331411761115138?s=20",
|
|
117
|
+
"tags": [
|
|
118
|
+
"Superhero",
|
|
119
|
+
"Indra Suit",
|
|
120
|
+
"Bow",
|
|
121
|
+
"Bodysuit",
|
|
122
|
+
"Thuban Form",
|
|
123
|
+
"Featured"
|
|
124
|
+
],
|
|
125
|
+
"artist": "@Yamainu_ken",
|
|
126
|
+
"published": "2023-01-22",
|
|
127
|
+
"aspectRatio": 1.5442260442260443
|
|
128
|
+
}
|
|
129
|
+
];
|
|
130
|
+
// More on writing stories with args: https://storybook.js.org/docs/writing-stories/args
|
|
131
|
+
exports.Primary = {
|
|
132
|
+
name: "Complex Elements",
|
|
133
|
+
args: {
|
|
134
|
+
width: 1920,
|
|
135
|
+
showWidows: true,
|
|
136
|
+
targetRowHeight: undefined,
|
|
137
|
+
rowSpacing: undefined,
|
|
138
|
+
itemSpacing: undefined,
|
|
139
|
+
aspectRatioList: displayedImages.map(value => value.aspectRatio),
|
|
140
|
+
targetRowHeightTolerance: undefined,
|
|
141
|
+
children: displayedImages.map(value => {
|
|
142
|
+
var _a;
|
|
143
|
+
return react_1.default.createElement(react_1.default.Fragment, null,
|
|
144
|
+
react_1.default.createElement("div", { style: { top: 16, left: 16, position: "absolute" } }, "Testing"),
|
|
145
|
+
react_1.default.createElement("img", { src: (_a = value.webp) !== null && _a !== void 0 ? _a : value.src }));
|
|
146
|
+
}),
|
|
147
|
+
containerStyle: { position: 'relative' }
|
|
148
|
+
},
|
|
149
|
+
};
|
|
150
|
+
exports.Secondary = {
|
|
151
|
+
name: "Image Tag Elements",
|
|
152
|
+
args: {
|
|
153
|
+
width: 1920,
|
|
154
|
+
showWidows: true,
|
|
155
|
+
targetRowHeight: undefined,
|
|
156
|
+
rowSpacing: undefined,
|
|
157
|
+
itemSpacing: undefined,
|
|
158
|
+
aspectRatioList: displayedImages.slice(1, 5).map(value => value.aspectRatio),
|
|
159
|
+
targetRowHeightTolerance: undefined,
|
|
160
|
+
children: displayedImages.slice(1, 5).map(value => { var _a; return react_1.default.createElement("img", { src: (_a = value.webp) !== null && _a !== void 0 ? _a : value.src }); })
|
|
161
|
+
},
|
|
162
|
+
};
|
|
163
|
+
exports.Divs = {
|
|
164
|
+
name: "Divs Only",
|
|
165
|
+
args: {
|
|
166
|
+
width: 1920,
|
|
167
|
+
showWidows: true,
|
|
168
|
+
targetRowHeight: undefined,
|
|
169
|
+
rowSpacing: undefined,
|
|
170
|
+
itemSpacing: undefined,
|
|
171
|
+
aspectRatioList: displayedImages.slice(1, 5).map(value => value.aspectRatio),
|
|
172
|
+
targetRowHeightTolerance: undefined,
|
|
173
|
+
children: displayedImages.slice(1, 5).map(value => react_1.default.createElement(react_loading_skeleton_1.default, { style: { aspectRatio: value.aspectRatio } }))
|
|
174
|
+
},
|
|
175
|
+
};
|
|
176
|
+
exports.Single = {
|
|
177
|
+
name: "Single Elements",
|
|
178
|
+
args: {
|
|
179
|
+
children: [react_1.default.createElement("img", { src: 'https://alcorsiteartbucket.s3.amazonaws.com/webp/alcor_wow.webp' })],
|
|
180
|
+
width: 1920,
|
|
181
|
+
showWidows: true,
|
|
182
|
+
targetRowHeight: undefined,
|
|
183
|
+
rowSpacing: undefined,
|
|
184
|
+
itemSpacing: undefined,
|
|
185
|
+
targetRowHeightTolerance: undefined,
|
|
186
|
+
aspectRatioList: [1],
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
exports.SingleWithDiv = {
|
|
190
|
+
name: "Complex Single Element",
|
|
191
|
+
args: {
|
|
192
|
+
children: [react_1.default.createElement("div", null,
|
|
193
|
+
react_1.default.createElement("img", { src: 'https://alcorsiteartbucket.s3.amazonaws.com/webp/alcor_wow.webp' }))],
|
|
194
|
+
width: 1920,
|
|
195
|
+
showWidows: true,
|
|
196
|
+
targetRowHeight: undefined,
|
|
197
|
+
rowSpacing: undefined,
|
|
198
|
+
itemSpacing: undefined,
|
|
199
|
+
targetRowHeightTolerance: undefined,
|
|
200
|
+
aspectRatioList: [1],
|
|
201
|
+
}
|
|
202
|
+
};
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { StoryObj } from "@storybook/react";
|
|
2
2
|
import React from "react";
|
|
3
|
-
import 'react-loading-skeleton/dist/skeleton.css';
|
|
4
3
|
declare const meta: {
|
|
5
4
|
title: string;
|
|
6
5
|
component: ({ aspectRatioList, rowSpacing, width, itemSpacing, targetRowHeight, targetRowHeightTolerance, children }: import("../components/TSJustifiedLayout").TSJustifiedLayoutProps) => React.JSX.Element;
|