@dxos/react-ui-masonry 0.8.4-main.ead640a → 0.8.4-main.fcfe5033a5
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/dist/lib/browser/index.mjs +95 -66
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +95 -66
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/Masonry.d.ts +31 -7
- package/dist/types/src/Masonry.d.ts.map +1 -1
- package/dist/types/src/Masonry.stories.d.ts +3 -0
- package/dist/types/src/Masonry.stories.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +36 -27
- package/src/Masonry.stories.tsx +32 -30
- package/src/Masonry.tsx +174 -113
package/package.json
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/react-ui-masonry",
|
|
3
|
-
"version": "0.8.4-main.
|
|
3
|
+
"version": "0.8.4-main.fcfe5033a5",
|
|
4
4
|
"description": "A masonry component.",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/dxos/dxos"
|
|
10
|
+
},
|
|
7
11
|
"license": "MIT",
|
|
8
12
|
"author": "DXOS.org",
|
|
9
|
-
"sideEffects":
|
|
13
|
+
"sideEffects": false,
|
|
10
14
|
"type": "module",
|
|
11
15
|
"exports": {
|
|
12
16
|
".": {
|
|
@@ -23,35 +27,40 @@
|
|
|
23
27
|
],
|
|
24
28
|
"dependencies": {
|
|
25
29
|
"@radix-ui/react-compose-refs": "1.1.1",
|
|
26
|
-
"
|
|
27
|
-
"@
|
|
30
|
+
"@radix-ui/react-context": "1.1.1",
|
|
31
|
+
"@virtuoso.dev/masonry": "^1.4.2",
|
|
32
|
+
"react-resize-detector": "^11.0.1",
|
|
33
|
+
"@dxos/react-hooks": "0.8.4-main.fcfe5033a5",
|
|
34
|
+
"@dxos/types": "0.8.4-main.fcfe5033a5",
|
|
35
|
+
"@dxos/react-ui-mosaic": "0.8.4-main.fcfe5033a5",
|
|
36
|
+
"@dxos/ui-types": "0.8.4-main.fcfe5033a5"
|
|
28
37
|
},
|
|
29
38
|
"devDependencies": {
|
|
30
|
-
"@types/react": "~19.2.
|
|
31
|
-
"@types/react-dom": "~19.2.
|
|
32
|
-
"effect": "3.
|
|
33
|
-
"react": "~19.2.
|
|
34
|
-
"react-dom": "~19.2.
|
|
35
|
-
"vite": "7.1.
|
|
36
|
-
"@dxos/
|
|
37
|
-
"@dxos/
|
|
38
|
-
"@dxos/
|
|
39
|
-
"@dxos/react-ui": "0.8.4-main.
|
|
40
|
-
"@dxos/react-
|
|
41
|
-
"@dxos/
|
|
42
|
-
"@dxos/
|
|
43
|
-
"@dxos/schema": "0.8.4-main.
|
|
44
|
-
"@dxos/
|
|
45
|
-
"@dxos/react-ui-
|
|
46
|
-
"@dxos/test-utils": "0.8.4-main.
|
|
39
|
+
"@types/react": "~19.2.7",
|
|
40
|
+
"@types/react-dom": "~19.2.3",
|
|
41
|
+
"effect": "3.20.0",
|
|
42
|
+
"react": "~19.2.3",
|
|
43
|
+
"react-dom": "~19.2.3",
|
|
44
|
+
"vite": "^7.1.11",
|
|
45
|
+
"@dxos/echo": "0.8.4-main.fcfe5033a5",
|
|
46
|
+
"@dxos/client": "0.8.4-main.fcfe5033a5",
|
|
47
|
+
"@dxos/random": "0.8.4-main.fcfe5033a5",
|
|
48
|
+
"@dxos/react-ui-form": "0.8.4-main.fcfe5033a5",
|
|
49
|
+
"@dxos/react-client": "0.8.4-main.fcfe5033a5",
|
|
50
|
+
"@dxos/react-ui": "0.8.4-main.fcfe5033a5",
|
|
51
|
+
"@dxos/storybook-utils": "0.8.4-main.fcfe5033a5",
|
|
52
|
+
"@dxos/schema": "0.8.4-main.fcfe5033a5",
|
|
53
|
+
"@dxos/ui-theme": "0.8.4-main.fcfe5033a5",
|
|
54
|
+
"@dxos/react-ui-stack": "0.8.4-main.fcfe5033a5",
|
|
55
|
+
"@dxos/test-utils": "0.8.4-main.fcfe5033a5"
|
|
47
56
|
},
|
|
48
57
|
"peerDependencies": {
|
|
49
|
-
"effect": "
|
|
50
|
-
"react": "
|
|
51
|
-
"react-dom": "
|
|
52
|
-
"@dxos/
|
|
53
|
-
"@dxos/
|
|
54
|
-
"@dxos/
|
|
58
|
+
"effect": "3.20.0",
|
|
59
|
+
"react": "~19.2.3",
|
|
60
|
+
"react-dom": "~19.2.3",
|
|
61
|
+
"@dxos/react-ui": "0.8.4-main.fcfe5033a5",
|
|
62
|
+
"@dxos/random": "0.8.4-main.fcfe5033a5",
|
|
63
|
+
"@dxos/ui-theme": "0.8.4-main.fcfe5033a5"
|
|
55
64
|
},
|
|
56
65
|
"publishConfig": {
|
|
57
66
|
"access": "public"
|
package/src/Masonry.stories.tsx
CHANGED
|
@@ -6,65 +6,67 @@ import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
|
6
6
|
import React from 'react';
|
|
7
7
|
|
|
8
8
|
import { Filter } from '@dxos/client/echo';
|
|
9
|
-
import {
|
|
9
|
+
import { random } from '@dxos/random';
|
|
10
10
|
import { useQuery } from '@dxos/react-client/echo';
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import { mx } from '@dxos/react-ui-theme';
|
|
15
|
-
import { DataType } from '@dxos/schema';
|
|
11
|
+
import { useClientStory, withClientProvider } from '@dxos/react-client/testing';
|
|
12
|
+
import { Card } from '@dxos/react-ui';
|
|
13
|
+
import { withLayout, withTheme } from '@dxos/react-ui/testing';
|
|
16
14
|
import { createObjectFactory } from '@dxos/schema/testing';
|
|
15
|
+
import { Organization } from '@dxos/types';
|
|
17
16
|
|
|
18
|
-
import { Masonry } from './Masonry';
|
|
17
|
+
import { Masonry, MasonryRootProps } from './Masonry';
|
|
19
18
|
|
|
20
|
-
const StoryItem = ({ data: { image, name, description } }: { data:
|
|
19
|
+
const StoryItem = ({ data: { image, name, description } }: { data: Organization.Organization }) => {
|
|
21
20
|
return (
|
|
22
|
-
<Card.
|
|
21
|
+
<Card.Root>
|
|
22
|
+
<Card.Toolbar>
|
|
23
|
+
<Card.Icon icon='ph--building-office--regular' />
|
|
24
|
+
<Card.Title>{name}</Card.Title>
|
|
25
|
+
</Card.Toolbar>
|
|
23
26
|
<Card.Poster alt={name!} {...(image ? { image } : { icon: 'ph--building-office--regular' })} />
|
|
24
|
-
|
|
25
|
-
<Card.
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
{description && (
|
|
28
|
+
<Card.Section classNames='px-2 pb-2'>
|
|
29
|
+
<Card.Text variant='description'>{description}</Card.Text>
|
|
30
|
+
</Card.Section>
|
|
31
|
+
)}
|
|
32
|
+
</Card.Root>
|
|
29
33
|
);
|
|
30
34
|
};
|
|
31
35
|
|
|
32
|
-
const DefaultStory = () => {
|
|
33
|
-
const { space } =
|
|
34
|
-
const organizations = useQuery(space, Filter.type(
|
|
36
|
+
const DefaultStory = (props: MasonryRootProps) => {
|
|
37
|
+
const { space } = useClientStory();
|
|
38
|
+
const organizations = useQuery(space?.db, Filter.type(Organization.Organization));
|
|
35
39
|
|
|
36
40
|
return (
|
|
37
|
-
<Masonry.Root
|
|
38
|
-
items={organizations}
|
|
39
|
-
|
|
40
|
-
classNames='is-full max-is-full bs-full max-bs-full overflow-y-auto p-4'
|
|
41
|
-
/>
|
|
41
|
+
<Masonry.Root {...props} Tile={StoryItem}>
|
|
42
|
+
<Masonry.Content items={organizations} />
|
|
43
|
+
</Masonry.Root>
|
|
42
44
|
);
|
|
43
45
|
};
|
|
44
46
|
|
|
45
47
|
const meta = {
|
|
46
48
|
title: 'ui/react-ui-masonry/Masonry',
|
|
49
|
+
render: DefaultStory,
|
|
47
50
|
decorators: [
|
|
48
|
-
withTheme,
|
|
51
|
+
withTheme(),
|
|
52
|
+
withLayout({ layout: 'fullscreen' }),
|
|
49
53
|
withClientProvider({
|
|
50
|
-
types: [
|
|
54
|
+
types: [Organization.Organization],
|
|
51
55
|
createIdentity: true,
|
|
52
56
|
createSpace: true,
|
|
53
57
|
onCreateSpace: async ({ space }) => {
|
|
54
|
-
const factory = createObjectFactory(space.db,
|
|
55
|
-
await factory([{ type:
|
|
58
|
+
const factory = createObjectFactory(space.db, random as any);
|
|
59
|
+
await factory([{ type: Organization.Organization, count: 36 }]);
|
|
56
60
|
},
|
|
57
61
|
}),
|
|
58
62
|
],
|
|
59
63
|
parameters: {
|
|
60
64
|
layout: 'fullscreen',
|
|
61
65
|
},
|
|
62
|
-
} satisfies Meta
|
|
66
|
+
} satisfies Meta;
|
|
63
67
|
|
|
64
68
|
export default meta;
|
|
65
69
|
|
|
66
70
|
type Story = StoryObj<typeof meta>;
|
|
67
71
|
|
|
68
|
-
export const Default: Story = {
|
|
69
|
-
render: DefaultStory,
|
|
70
|
-
};
|
|
72
|
+
export const Default: Story = {};
|
package/src/Masonry.tsx
CHANGED
|
@@ -3,128 +3,189 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { useComposedRefs } from '@radix-ui/react-compose-refs';
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
} from '
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
| 'height'
|
|
32
|
-
| 'scrollTop'
|
|
33
|
-
| 'isScrolling'
|
|
34
|
-
| 'resizeObserver'
|
|
35
|
-
| 'positioner'
|
|
36
|
-
| 'as'
|
|
37
|
-
| 'id'
|
|
38
|
-
| 'itemAs'
|
|
39
|
-
| 'itemStyle'
|
|
40
|
-
| 'className'
|
|
41
|
-
| 'style'
|
|
42
|
-
| 'role'
|
|
43
|
-
| 'tabIndex'
|
|
44
|
-
| 'containerRef'
|
|
45
|
-
> & { intrinsicHeight?: boolean };
|
|
46
|
-
|
|
47
|
-
const usePxProps = (remProps: Omit<UsePositionerOptions, 'width' | 'columnCount' | 'maxColumnCount'>) => {
|
|
48
|
-
const remInPx = usePx(1);
|
|
49
|
-
return useMemo(() => {
|
|
50
|
-
return Object.fromEntries(
|
|
51
|
-
Object.entries(remProps)
|
|
52
|
-
.filter(([_, value]) => Number.isFinite(value))
|
|
53
|
-
.map(([key, value]) => {
|
|
54
|
-
return [key, value * remInPx];
|
|
55
|
-
}),
|
|
56
|
-
);
|
|
57
|
-
}, [remProps, remInPx]);
|
|
6
|
+
import { createContext } from '@radix-ui/react-context';
|
|
7
|
+
import { VirtuosoMasonry, type VirtuosoMasonryProps } from '@virtuoso.dev/masonry';
|
|
8
|
+
import React, { type ComponentType, type JSX, type PropsWithChildren, type Ref, useMemo, useRef } from 'react';
|
|
9
|
+
import { useResizeDetector } from 'react-resize-detector';
|
|
10
|
+
|
|
11
|
+
import { ScrollArea, ScrollAreaRootProps, ThemedClassName, usePx } from '@dxos/react-ui';
|
|
12
|
+
import { cardMaxInlineSize, cardMinInlineSize, composable, composableProps, scrollbar } from '@dxos/ui-theme';
|
|
13
|
+
|
|
14
|
+
//
|
|
15
|
+
// Context
|
|
16
|
+
//
|
|
17
|
+
|
|
18
|
+
type MasonryContextValue = {
|
|
19
|
+
/** Render component for each masonry item. */
|
|
20
|
+
Tile: ComponentType<{ data: any; index: number }>;
|
|
21
|
+
/** Override auto-calculated column count. */
|
|
22
|
+
columns: number | undefined;
|
|
23
|
+
/** Upper bound on number of columns. */
|
|
24
|
+
maxColumns: number | undefined;
|
|
25
|
+
/** Minimum column width in rem. */
|
|
26
|
+
minColumnWidth: number;
|
|
27
|
+
/** Maximum column width in rem. */
|
|
28
|
+
maxColumnWidth: number;
|
|
29
|
+
/** Space between columns and rows in rem. */
|
|
30
|
+
gutter: number;
|
|
58
31
|
};
|
|
59
32
|
|
|
60
|
-
const
|
|
33
|
+
const MASONRY_NAME = 'Masonry';
|
|
34
|
+
|
|
35
|
+
const [MasonryProvider, useMasonryContext] = createContext<MasonryContextValue>(MASONRY_NAME);
|
|
36
|
+
|
|
37
|
+
//
|
|
38
|
+
// Root
|
|
39
|
+
//
|
|
40
|
+
|
|
41
|
+
type MasonryRootProps = PropsWithChildren<Partial<MasonryContextValue>>;
|
|
42
|
+
|
|
43
|
+
const MasonryRoot = ({
|
|
44
|
+
children,
|
|
45
|
+
Tile,
|
|
46
|
+
columns = undefined,
|
|
47
|
+
maxColumns = undefined,
|
|
48
|
+
minColumnWidth = cardMinInlineSize,
|
|
49
|
+
maxColumnWidth = cardMaxInlineSize,
|
|
50
|
+
gutter = 0.75,
|
|
51
|
+
}: MasonryRootProps) => (
|
|
52
|
+
<MasonryProvider
|
|
53
|
+
Tile={Tile!}
|
|
54
|
+
columns={columns}
|
|
55
|
+
maxColumns={maxColumns}
|
|
56
|
+
minColumnWidth={minColumnWidth}
|
|
57
|
+
maxColumnWidth={maxColumnWidth}
|
|
58
|
+
gutter={gutter}
|
|
59
|
+
>
|
|
60
|
+
{children}
|
|
61
|
+
</MasonryProvider>
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
MasonryRoot.displayName = 'Masonry.Root';
|
|
65
|
+
|
|
66
|
+
//
|
|
67
|
+
// Content
|
|
68
|
+
//
|
|
69
|
+
|
|
70
|
+
type MasonryContentProps<Item> = ThemedClassName<
|
|
61
71
|
{
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
classNames,
|
|
75
|
-
intrinsicHeight,
|
|
76
|
-
...props
|
|
77
|
-
}: MasonryRootProps<Item>,
|
|
78
|
-
forwardedRef: ForwardedRef<HTMLDivElement>,
|
|
79
|
-
) => {
|
|
80
|
-
const rootRef = useRef<HTMLDivElement | null>(null);
|
|
81
|
-
const ref = useComposedRefs(rootRef, forwardedRef);
|
|
82
|
-
const { width, height } = useSize(rootRef);
|
|
83
|
-
const { scrollTop, isScrolling } = useScroller(rootRef);
|
|
84
|
-
const remProps = useMemo(
|
|
85
|
-
() => ({ columnWidth, maxColumnWidth, columnGutter, rowGutter }),
|
|
86
|
-
[columnWidth, maxColumnWidth, columnGutter, rowGutter],
|
|
87
|
-
);
|
|
88
|
-
const pxProps = usePxProps(remProps);
|
|
89
|
-
const positionerProps = useMemo(
|
|
90
|
-
() => ({
|
|
91
|
-
width,
|
|
92
|
-
columnCount,
|
|
93
|
-
maxColumnCount,
|
|
94
|
-
...pxProps,
|
|
95
|
-
}),
|
|
96
|
-
[width, pxProps, columnCount, maxColumnCount],
|
|
97
|
-
);
|
|
98
|
-
const positioner = usePositioner(positionerProps, [positionerProps]);
|
|
99
|
-
const resizeObserver = useResizeObserver(positioner);
|
|
100
|
-
const children = useMasonry({
|
|
101
|
-
height: intrinsicHeight ? Infinity : height,
|
|
102
|
-
scrollTop,
|
|
103
|
-
isScrolling,
|
|
104
|
-
resizeObserver,
|
|
105
|
-
positioner,
|
|
106
|
-
items,
|
|
107
|
-
itemHeightEstimate,
|
|
108
|
-
itemKey,
|
|
109
|
-
overscanBy,
|
|
110
|
-
render,
|
|
111
|
-
onRender,
|
|
112
|
-
});
|
|
113
|
-
return (
|
|
114
|
-
<div className={mx(classNames)} {...props} ref={ref}>
|
|
115
|
-
{children}
|
|
116
|
-
</div>
|
|
117
|
-
);
|
|
118
|
-
};
|
|
72
|
+
/** Items to render in the masonry grid. */
|
|
73
|
+
items: Item[];
|
|
74
|
+
/** Extract a stable key from an item, aligned with react-ui-mosaic's getId. */
|
|
75
|
+
getId?: (data: Item) => string;
|
|
76
|
+
} & Pick<ScrollAreaRootProps, 'centered' | 'thin' | 'padding'>
|
|
77
|
+
>;
|
|
78
|
+
|
|
79
|
+
const MasonryContentInner = composable<HTMLDivElement, MasonryContentProps<any>>(
|
|
80
|
+
({ items, getId, centered, thin = true, padding = true, ...props }, forwardedRef) => {
|
|
81
|
+
const rootRef = useRef<HTMLDivElement | null>(null);
|
|
82
|
+
const composedRef = useComposedRefs(rootRef, forwardedRef);
|
|
83
|
+
const { width = 0 } = useResizeDetector({ targetRef: rootRef });
|
|
119
84
|
|
|
120
|
-
const
|
|
121
|
-
|
|
85
|
+
const { Tile, columns, maxColumns, minColumnWidth, maxColumnWidth, gutter } = useMasonryContext('Masonry.Content');
|
|
86
|
+
const columnCount = useColumnCount(
|
|
87
|
+
width - (scrollbar.thin.size + scrollbar.thin.padding),
|
|
88
|
+
columns,
|
|
89
|
+
maxColumns,
|
|
90
|
+
minColumnWidth,
|
|
91
|
+
maxColumnWidth,
|
|
92
|
+
gutter,
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
const TileAdapter = useMemo(() => {
|
|
96
|
+
const Adapter = ({ data, index }: { data: any; index: number }) => {
|
|
97
|
+
return (
|
|
98
|
+
<div role='listitem' style={{ paddingBottom: `${gutter}rem` }}>
|
|
99
|
+
<Tile index={index} data={data} />
|
|
100
|
+
</div>
|
|
101
|
+
);
|
|
102
|
+
};
|
|
103
|
+
Adapter.displayName = 'Masonry.TileAdapter';
|
|
104
|
+
return Adapter;
|
|
105
|
+
}, [Tile, gutter]);
|
|
106
|
+
|
|
107
|
+
// NOTE: Masonry currently doesn't support an external scroller.
|
|
108
|
+
// https://github.com/petyosi/react-virtuoso/issues/1305
|
|
109
|
+
return (
|
|
110
|
+
<ScrollArea.Root {...composableProps(props)} centered={centered} thin={thin} padding={padding} ref={composedRef}>
|
|
111
|
+
{width > 0 && (
|
|
112
|
+
<ScrollArea.Viewport asChild>
|
|
113
|
+
<ComposableVirtuosoMasonry
|
|
114
|
+
style={{ gap: `${gutter}rem` }}
|
|
115
|
+
data={items}
|
|
116
|
+
columnCount={columnCount}
|
|
117
|
+
ItemContent={TileAdapter}
|
|
118
|
+
/>
|
|
119
|
+
</ScrollArea.Viewport>
|
|
120
|
+
)}
|
|
121
|
+
</ScrollArea.Root>
|
|
122
|
+
);
|
|
123
|
+
},
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
const ComposableVirtuosoMasonry = composable<HTMLDivElement, VirtuosoMasonryProps<any, any>>(
|
|
127
|
+
({ ...props }, _forwardedRef) => {
|
|
128
|
+
return <VirtuosoMasonry {...props} />;
|
|
129
|
+
},
|
|
130
|
+
);
|
|
131
|
+
|
|
132
|
+
MasonryContentInner.displayName = 'Masonry.Content';
|
|
133
|
+
|
|
134
|
+
const MasonryContent = MasonryContentInner as <Item>(
|
|
135
|
+
props: MasonryContentProps<Item> & {
|
|
122
136
|
ref?: Ref<HTMLDivElement | null>;
|
|
123
137
|
},
|
|
124
138
|
) => JSX.Element;
|
|
125
139
|
|
|
140
|
+
/** Compute column count from container width and column constraints. */
|
|
141
|
+
const useColumnCount = (
|
|
142
|
+
width: number,
|
|
143
|
+
columns: number | undefined,
|
|
144
|
+
maxColumns: number | undefined,
|
|
145
|
+
minColumnWidth: number,
|
|
146
|
+
maxColumnWidth: number,
|
|
147
|
+
gutter: number,
|
|
148
|
+
) => {
|
|
149
|
+
const remInPx = usePx(1);
|
|
150
|
+
return useMemo(() => {
|
|
151
|
+
if (columns != null) {
|
|
152
|
+
return columns;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const minColumnWidthPx = minColumnWidth * remInPx;
|
|
156
|
+
const maxColumnWidthPx = maxColumnWidth * remInPx;
|
|
157
|
+
const gutterPx = gutter * remInPx;
|
|
158
|
+
|
|
159
|
+
if (width <= 0 || minColumnWidthPx <= 0) {
|
|
160
|
+
return 1;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// Each tile has paddingRight: gutter, so every slot (including the last) occupies
|
|
164
|
+
// (colWidth + gutterPx). The container therefore fits floor(containerWidth / (colWidth + gutterPx)) columns.
|
|
165
|
+
let cols = Math.floor(width / (minColumnWidthPx + gutterPx));
|
|
166
|
+
if (maxColumnWidthPx > 0) {
|
|
167
|
+
const effectiveColWidth = width / cols - gutterPx;
|
|
168
|
+
if (effectiveColWidth > maxColumnWidthPx) {
|
|
169
|
+
// Try to add columns to keep cards below maxColumnWidth, but never violate minColumnWidth.
|
|
170
|
+
const maxCols = Math.ceil(width / (maxColumnWidthPx + gutterPx));
|
|
171
|
+
if (width / maxCols - gutterPx >= minColumnWidthPx) {
|
|
172
|
+
cols = maxCols;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
const clamped = maxColumns != null ? Math.min(cols, maxColumns) : cols;
|
|
178
|
+
return Math.max(1, clamped);
|
|
179
|
+
}, [remInPx, width, columns, maxColumns, minColumnWidth, maxColumnWidth, gutter]);
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
//
|
|
183
|
+
// Masonry
|
|
184
|
+
//
|
|
185
|
+
|
|
126
186
|
export const Masonry = {
|
|
127
187
|
Root: MasonryRoot,
|
|
188
|
+
Content: MasonryContent,
|
|
128
189
|
};
|
|
129
190
|
|
|
130
|
-
export type { MasonryRootProps };
|
|
191
|
+
export type { MasonryRootProps, MasonryContentProps };
|