@dxos/react-ui-masonry 0.9.0 → 0.9.1-staging.ee54ba693a

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/react-ui-masonry",
3
- "version": "0.9.0",
3
+ "version": "0.9.1-staging.ee54ba693a",
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-hooks": "0.9.0",
35
- "@dxos/types": "0.9.0",
36
- "@dxos/ui-types": "0.9.0",
37
- "@dxos/react-ui-mosaic": "0.9.0"
34
+ "@dxos/react-hooks": "0.9.1-staging.ee54ba693a",
35
+ "@dxos/types": "0.9.1-staging.ee54ba693a",
36
+ "@dxos/react-ui-mosaic": "0.9.1-staging.ee54ba693a",
37
+ "@dxos/ui-types": "0.9.1-staging.ee54ba693a"
38
38
  },
39
39
  "devDependencies": {
40
- "@types/react": "~19.2.7",
40
+ "@types/react": "~19.2.17",
41
41
  "@types/react-dom": "~19.2.3",
42
- "effect": "3.21.3",
43
- "react": "~19.2.3",
44
- "react-dom": "~19.2.3",
42
+ "effect": "3.21.4",
43
+ "react": "~19.2.7",
44
+ "react-dom": "~19.2.7",
45
45
  "vite": "^8.0.16",
46
- "@dxos/echo": "0.9.0",
47
- "@dxos/random": "0.9.0",
48
- "@dxos/react-ui": "0.9.0",
49
- "@dxos/react-client": "0.9.0",
50
- "@dxos/react-ui-stack": "0.9.0",
51
- "@dxos/storybook-utils": "0.9.0",
52
- "@dxos/schema": "0.9.0",
53
- "@dxos/ui-theme": "0.9.0",
54
- "@dxos/test-utils": "0.9.0",
55
- "@dxos/react-ui-form": "0.9.0",
56
- "@dxos/client": "0.9.0"
46
+ "@dxos/echo": "0.9.1-staging.ee54ba693a",
47
+ "@dxos/client": "0.9.1-staging.ee54ba693a",
48
+ "@dxos/random": "0.9.1-staging.ee54ba693a",
49
+ "@dxos/react-client": "0.9.1-staging.ee54ba693a",
50
+ "@dxos/react-ui": "0.9.1-staging.ee54ba693a",
51
+ "@dxos/react-ui-form": "0.9.1-staging.ee54ba693a",
52
+ "@dxos/schema": "0.9.1-staging.ee54ba693a",
53
+ "@dxos/storybook-utils": "0.9.1-staging.ee54ba693a",
54
+ "@dxos/ui-theme": "0.9.1-staging.ee54ba693a",
55
+ "@dxos/test-utils": "0.9.1-staging.ee54ba693a"
57
56
  },
58
57
  "peerDependencies": {
59
- "effect": "3.21.3",
60
- "react": "~19.2.3",
61
- "react-dom": "~19.2.3",
62
- "@dxos/random": "0.9.0",
63
- "@dxos/react-ui": "0.9.0",
64
- "@dxos/ui-theme": "0.9.0"
58
+ "effect": "3.21.4",
59
+ "react": "~19.2.7",
60
+ "react-dom": "~19.2.7",
61
+ "@dxos/react-ui": "0.9.1-staging.ee54ba693a",
62
+ "@dxos/ui-theme": "0.9.1-staging.ee54ba693a",
63
+ "@dxos/random": "0.9.1-staging.ee54ba693a"
65
64
  },
66
65
  "publishConfig": {
67
66
  "access": "public"
@@ -9,7 +9,7 @@ import { Filter } from '@dxos/echo';
9
9
  import { random } from '@dxos/random';
10
10
  import { useQuery } from '@dxos/react-client/echo';
11
11
  import { useClientStory, withClientProvider } from '@dxos/react-client/testing';
12
- import { Card } from '@dxos/react-ui';
12
+ import { Card, Icon } from '@dxos/react-ui';
13
13
  import { withLayout, withTheme } from '@dxos/react-ui/testing';
14
14
  import { createObjectFactory } from '@dxos/schema/testing';
15
15
  import { Organization } from '@dxos/types';
@@ -20,12 +20,14 @@ const StoryItem = ({ data: { image, name, description } }: { data: Organization.
20
20
  return (
21
21
  <Card.Root>
22
22
  <Card.Header>
23
- <Card.Icon icon='ph--building-office--regular' />
23
+ <Card.Block>
24
+ <Icon icon='ph--building-office--regular' />
25
+ </Card.Block>
24
26
  <Card.Title>{name}</Card.Title>
25
27
  </Card.Header>
26
28
  <Card.Poster alt={name!} {...(image ? { image } : { icon: 'ph--building-office--regular' })} />
27
29
  {description && (
28
- <Card.Row fullWidth classNames='px-2 pb-2'>
30
+ <Card.Row classNames='px-2 pb-2'>
29
31
  <Card.Text variant='description'>{description}</Card.Text>
30
32
  </Card.Row>
31
33
  )}
@@ -39,7 +41,7 @@ const DefaultStory = (props: MasonryRootProps) => {
39
41
 
40
42
  return (
41
43
  <Masonry.Root {...props} Tile={StoryItem}>
42
- <Masonry.Content>
44
+ <Masonry.Content centered>
43
45
  <Masonry.Viewport items={organizations} />
44
46
  </Masonry.Content>
45
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, { type ComponentType, type JSX, type PropsWithChildren, type Ref, useMemo, useRef } from '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 {...composableProps(props)} centered={centered} thin={thin} padding={padding} ref={composedRef}>
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
- <ComposableVirtuosoMasonry
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 { MasonryRootProps, MasonryContentProps, MasonryViewportProps };
269
+ export type { MasonryContentProps, MasonryRootProps, MasonryViewportProps };