@dxos/react-ui-masonry 0.9.1-main.c7dcc2e112 → 0.10.0
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 +22 -14
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +22 -14
- 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 +2 -2
- package/dist/types/src/Masonry.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +25 -26
- package/src/Masonry.stories.tsx +2 -2
- package/src/Masonry.tsx +41 -20
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/react-ui-masonry",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "A masonry component.",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -31,37 +31,36 @@
|
|
|
31
31
|
"@radix-ui/react-context": "1.1.1",
|
|
32
32
|
"@virtuoso.dev/masonry": "^1.4.2",
|
|
33
33
|
"react-resize-detector": "^11.0.1",
|
|
34
|
-
"@dxos/react-
|
|
35
|
-
"@dxos/react-
|
|
36
|
-
"@dxos/types": "0.
|
|
37
|
-
"@dxos/
|
|
34
|
+
"@dxos/react-hooks": "0.10.0",
|
|
35
|
+
"@dxos/react-ui-mosaic": "0.10.0",
|
|
36
|
+
"@dxos/ui-types": "0.10.0",
|
|
37
|
+
"@dxos/types": "0.10.0"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@types/react": "~19.2.
|
|
40
|
+
"@types/react": "~19.2.17",
|
|
41
41
|
"@types/react-dom": "~19.2.3",
|
|
42
|
-
"effect": "3.21.
|
|
43
|
-
"react": "~19.2.
|
|
44
|
-
"react-dom": "~19.2.
|
|
42
|
+
"effect": "3.21.4",
|
|
43
|
+
"react": "~19.2.7",
|
|
44
|
+
"react-dom": "~19.2.7",
|
|
45
45
|
"vite": "^8.0.16",
|
|
46
|
-
"@dxos/
|
|
47
|
-
"@dxos/
|
|
48
|
-
"@dxos/
|
|
49
|
-
"@dxos/react-
|
|
50
|
-
"@dxos/react-ui
|
|
51
|
-
"@dxos/
|
|
52
|
-
"@dxos/
|
|
53
|
-
"@dxos/
|
|
54
|
-
"@dxos/
|
|
55
|
-
"@dxos/
|
|
56
|
-
"@dxos/test-utils": "0.9.1-main.c7dcc2e112"
|
|
46
|
+
"@dxos/random": "0.10.0",
|
|
47
|
+
"@dxos/client": "0.10.0",
|
|
48
|
+
"@dxos/react-client": "0.10.0",
|
|
49
|
+
"@dxos/react-ui-form": "0.10.0",
|
|
50
|
+
"@dxos/react-ui": "0.10.0",
|
|
51
|
+
"@dxos/schema": "0.10.0",
|
|
52
|
+
"@dxos/storybook-utils": "0.10.0",
|
|
53
|
+
"@dxos/test-utils": "0.10.0",
|
|
54
|
+
"@dxos/ui-theme": "0.10.0",
|
|
55
|
+
"@dxos/echo": "0.10.0"
|
|
57
56
|
},
|
|
58
57
|
"peerDependencies": {
|
|
59
|
-
"effect": "3.21.
|
|
60
|
-
"react": "~19.2.
|
|
61
|
-
"react-dom": "~19.2.
|
|
62
|
-
"@dxos/
|
|
63
|
-
"@dxos/
|
|
64
|
-
"@dxos/ui-theme": "0.
|
|
58
|
+
"effect": "3.21.4",
|
|
59
|
+
"react": "~19.2.7",
|
|
60
|
+
"react-dom": "~19.2.7",
|
|
61
|
+
"@dxos/random": "0.10.0",
|
|
62
|
+
"@dxos/react-ui": "0.10.0",
|
|
63
|
+
"@dxos/ui-theme": "0.10.0"
|
|
65
64
|
},
|
|
66
65
|
"publishConfig": {
|
|
67
66
|
"access": "public"
|
package/src/Masonry.stories.tsx
CHANGED
|
@@ -27,7 +27,7 @@ const StoryItem = ({ data: { image, name, description } }: { data: Organization.
|
|
|
27
27
|
</Card.Header>
|
|
28
28
|
<Card.Poster alt={name!} {...(image ? { image } : { icon: 'ph--building-office--regular' })} />
|
|
29
29
|
{description && (
|
|
30
|
-
<Card.Row
|
|
30
|
+
<Card.Row classNames='px-2 pb-2'>
|
|
31
31
|
<Card.Text variant='description'>{description}</Card.Text>
|
|
32
32
|
</Card.Row>
|
|
33
33
|
)}
|
|
@@ -41,7 +41,7 @@ const DefaultStory = (props: MasonryRootProps) => {
|
|
|
41
41
|
|
|
42
42
|
return (
|
|
43
43
|
<Masonry.Root {...props} Tile={StoryItem}>
|
|
44
|
-
<Masonry.Content>
|
|
44
|
+
<Masonry.Content centered>
|
|
45
45
|
<Masonry.Viewport items={organizations} />
|
|
46
46
|
</Masonry.Content>
|
|
47
47
|
</Masonry.Root>
|
package/src/Masonry.tsx
CHANGED
|
@@ -5,8 +5,16 @@
|
|
|
5
5
|
import { useArrowNavigationGroup } from '@fluentui/react-tabster';
|
|
6
6
|
import { useComposedRefs } from '@radix-ui/react-compose-refs';
|
|
7
7
|
import { createContext } from '@radix-ui/react-context';
|
|
8
|
-
import { VirtuosoMasonry, type VirtuosoMasonryProps } from '@virtuoso.dev/masonry';
|
|
9
|
-
import React, {
|
|
8
|
+
import { VirtuosoMasonry as NaturalVirtuosoMasonry, type VirtuosoMasonryProps } from '@virtuoso.dev/masonry';
|
|
9
|
+
import React, {
|
|
10
|
+
type ComponentType,
|
|
11
|
+
type CSSProperties,
|
|
12
|
+
type JSX,
|
|
13
|
+
type PropsWithChildren,
|
|
14
|
+
type Ref,
|
|
15
|
+
useMemo,
|
|
16
|
+
useRef,
|
|
17
|
+
} from 'react';
|
|
10
18
|
import { useResizeDetector } from 'react-resize-detector';
|
|
11
19
|
|
|
12
20
|
import { ScrollArea, ScrollAreaRootProps, ThemedClassName, usePx } from '@dxos/react-ui';
|
|
@@ -81,19 +89,24 @@ MasonryRoot.displayName = 'Masonry.Root';
|
|
|
81
89
|
//
|
|
82
90
|
|
|
83
91
|
type MasonryContentProps = ThemedClassName<
|
|
84
|
-
PropsWithChildren<Pick<ScrollAreaRootProps, 'centered' | 'thin' | 'padding'>>
|
|
92
|
+
PropsWithChildren<Pick<ScrollAreaRootProps, 'scrollbars' | 'centered' | 'thin' | 'padding'>>
|
|
85
93
|
>;
|
|
86
94
|
|
|
87
95
|
const MasonryContentInner = composable<HTMLDivElement, MasonryContentProps>(
|
|
88
|
-
({ children, centered, thin = true, padding = true, ...props }, forwardedRef) => {
|
|
96
|
+
({ children, scrollbars, centered, thin = true, padding = true, ...props }, forwardedRef) => {
|
|
89
97
|
const rootRef = useRef<HTMLDivElement | null>(null);
|
|
90
98
|
const composedRef = useComposedRefs(rootRef, forwardedRef);
|
|
91
99
|
const { width = 0 } = useResizeDetector({ targetRef: rootRef });
|
|
92
100
|
|
|
93
|
-
// NOTE: Masonry currently doesn't support an external scroller.
|
|
94
|
-
// https://github.com/petyosi/react-virtuoso/issues/1305
|
|
95
101
|
return (
|
|
96
|
-
<ScrollArea.Root
|
|
102
|
+
<ScrollArea.Root
|
|
103
|
+
{...composableProps(props, { classNames: 'pt-trim-md' })}
|
|
104
|
+
scrollbars={scrollbars}
|
|
105
|
+
centered={centered}
|
|
106
|
+
thin={thin}
|
|
107
|
+
padding={padding}
|
|
108
|
+
ref={composedRef}
|
|
109
|
+
>
|
|
97
110
|
<MasonryContentProvider width={width}>{children}</MasonryContentProvider>
|
|
98
111
|
</ScrollArea.Root>
|
|
99
112
|
);
|
|
@@ -164,30 +177,38 @@ const MasonryViewportInner = composable<HTMLDivElement, MasonryViewportProps<any
|
|
|
164
177
|
return null;
|
|
165
178
|
}
|
|
166
179
|
|
|
180
|
+
// VirtuosoMasonry renders the scroller as a full-width flex row whose column children carry an
|
|
181
|
+
// inline `flexGrow: 1`. Capping each column at `maxColumnWidth` lets the columns grow to fill the
|
|
182
|
+
// row but stop at the natural card width; `justify-center` then distributes the remaining space as
|
|
183
|
+
// symmetric margins so the grid stays centered without the scroll container leaving the far edge.
|
|
167
184
|
return (
|
|
168
185
|
<ScrollArea.Viewport asChild>
|
|
169
|
-
<
|
|
186
|
+
<VirtuosoMasonry
|
|
187
|
+
{...composableProps(props, {
|
|
188
|
+
classNames: ['justify-center', '[&>div]:max-w-[var(--dx-masonry-column-max)]'],
|
|
189
|
+
style: { 'gap': `${gutter}rem`, '--dx-masonry-column-max': `${maxColumnWidth}rem` } as CSSProperties,
|
|
190
|
+
})}
|
|
170
191
|
{...arrowNavigationAttrs}
|
|
171
|
-
{...composableProps(props)}
|
|
172
|
-
ref={forwardedRef}
|
|
173
|
-
style={{ gap: `${gutter}rem` }}
|
|
174
|
-
data={items as any[]}
|
|
175
|
-
columnCount={columnCount}
|
|
176
192
|
ItemContent={TileAdapter}
|
|
193
|
+
columnCount={columnCount}
|
|
194
|
+
data={items as any[]}
|
|
195
|
+
// ref={forwardedRef}
|
|
177
196
|
/>
|
|
178
197
|
</ScrollArea.Viewport>
|
|
179
198
|
);
|
|
180
199
|
},
|
|
181
200
|
);
|
|
182
201
|
|
|
183
|
-
const ComposableVirtuosoMasonry = composable<HTMLDivElement, VirtuosoMasonryProps<any, any>>(
|
|
184
|
-
({ ...props }, _forwardedRef) => {
|
|
185
|
-
return <VirtuosoMasonry {...props} />;
|
|
186
|
-
},
|
|
187
|
-
);
|
|
188
|
-
|
|
189
202
|
MasonryViewportInner.displayName = 'Masonry.Viewport';
|
|
190
203
|
|
|
204
|
+
/**
|
|
205
|
+
* NOTE: Required in order for our Viewport to take over the scroll area.
|
|
206
|
+
* https://github.com/petyosi/react-virtuoso/issues/1305
|
|
207
|
+
*/
|
|
208
|
+
const VirtuosoMasonry = composable<HTMLDivElement, VirtuosoMasonryProps<any, any>>(({ ...props }, _forwardedRef) => {
|
|
209
|
+
return <NaturalVirtuosoMasonry {...props} />;
|
|
210
|
+
});
|
|
211
|
+
|
|
191
212
|
const MasonryViewport = MasonryViewportInner as <Item>(
|
|
192
213
|
props: MasonryViewportProps<Item> & {
|
|
193
214
|
ref?: Ref<HTMLDivElement | null>;
|
|
@@ -245,4 +266,4 @@ export const Masonry = {
|
|
|
245
266
|
Viewport: MasonryViewport,
|
|
246
267
|
};
|
|
247
268
|
|
|
248
|
-
export type {
|
|
269
|
+
export type { MasonryContentProps, MasonryRootProps, MasonryViewportProps };
|