@dxos/react-ui-masonry 0.8.4-main.406dc2a

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 ADDED
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "@dxos/react-ui-masonry",
3
+ "version": "0.8.4-main.406dc2a",
4
+ "description": "A masonry component.",
5
+ "homepage": "https://dxos.org",
6
+ "bugs": "https://github.com/dxos/dxos/issues",
7
+ "license": "MIT",
8
+ "author": "DXOS.org",
9
+ "sideEffects": true,
10
+ "type": "module",
11
+ "exports": {
12
+ ".": {
13
+ "source": "./src/index.ts",
14
+ "types": "./dist/types/src/index.d.ts",
15
+ "browser": "./dist/lib/browser/index.mjs",
16
+ "node": "./dist/lib/node-esm/index.mjs"
17
+ }
18
+ },
19
+ "types": "dist/types/src/index.d.ts",
20
+ "files": [
21
+ "dist",
22
+ "src"
23
+ ],
24
+ "dependencies": {
25
+ "@radix-ui/react-compose-refs": "1.1.1",
26
+ "masonic": "^4.1.0",
27
+ "@dxos/react-hooks": "0.8.4-main.406dc2a"
28
+ },
29
+ "devDependencies": {
30
+ "@types/react": "~19.2.2",
31
+ "@types/react-dom": "~19.2.1",
32
+ "effect": "3.18.3",
33
+ "react": "~19.2.0",
34
+ "react-dom": "~19.2.0",
35
+ "vite": "7.1.9",
36
+ "@dxos/echo": "0.8.4-main.406dc2a",
37
+ "@dxos/client": "0.8.4-main.406dc2a",
38
+ "@dxos/random": "0.8.4-main.406dc2a",
39
+ "@dxos/react-client": "0.8.4-main.406dc2a",
40
+ "@dxos/react-ui-form": "0.8.4-main.406dc2a",
41
+ "@dxos/react-ui-theme": "0.8.4-main.406dc2a",
42
+ "@dxos/react-ui-stack": "0.8.4-main.406dc2a",
43
+ "@dxos/storybook-utils": "0.8.4-main.406dc2a",
44
+ "@dxos/schema": "0.8.4-main.406dc2a",
45
+ "@dxos/react-ui": "0.8.4-main.406dc2a",
46
+ "@dxos/test-utils": "0.8.4-main.406dc2a"
47
+ },
48
+ "peerDependencies": {
49
+ "effect": "^3.13.3",
50
+ "react": "^19.0.0",
51
+ "react-dom": "^19.0.0",
52
+ "@dxos/random": "0.8.4-main.406dc2a",
53
+ "@dxos/react-ui": "0.8.4-main.406dc2a",
54
+ "@dxos/react-ui-theme": "0.8.4-main.406dc2a"
55
+ },
56
+ "publishConfig": {
57
+ "access": "public"
58
+ }
59
+ }
@@ -0,0 +1,70 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import { type Meta, type StoryObj } from '@storybook/react-vite';
6
+ import React from 'react';
7
+
8
+ import { Filter } from '@dxos/client/echo';
9
+ import { faker } from '@dxos/random';
10
+ import { useQuery } from '@dxos/react-client/echo';
11
+ import { useClientProvider, withClientProvider } from '@dxos/react-client/testing';
12
+ import { withTheme } from '@dxos/react-ui/testing';
13
+ import { Card, cardNoSpacing, cardSpacing } from '@dxos/react-ui-stack';
14
+ import { mx } from '@dxos/react-ui-theme';
15
+ import { DataType } from '@dxos/schema';
16
+ import { createObjectFactory } from '@dxos/schema/testing';
17
+
18
+ import { Masonry } from './Masonry';
19
+
20
+ const StoryItem = ({ data: { image, name, description } }: { data: DataType.Organization }) => {
21
+ return (
22
+ <Card.StaticRoot>
23
+ <Card.Poster alt={name!} {...(image ? { image } : { icon: 'ph--building-office--regular' })} />
24
+ <div role='none' className={mx('flex items-center gap-2', cardSpacing)}>
25
+ <Card.Heading classNames={cardNoSpacing}>{name}</Card.Heading>
26
+ </div>
27
+ {description && <Card.Text classNames='line-clamp-2'>{description}</Card.Text>}
28
+ </Card.StaticRoot>
29
+ );
30
+ };
31
+
32
+ const DefaultStory = () => {
33
+ const { space } = useClientProvider();
34
+ const organizations = useQuery(space, Filter.type(DataType.Organization));
35
+
36
+ return (
37
+ <Masonry.Root<DataType.Organization>
38
+ items={organizations}
39
+ render={StoryItem}
40
+ classNames='is-full max-is-full bs-full max-bs-full overflow-y-auto p-4'
41
+ />
42
+ );
43
+ };
44
+
45
+ const meta = {
46
+ title: 'ui/react-ui-masonry/Masonry',
47
+ decorators: [
48
+ withTheme,
49
+ withClientProvider({
50
+ types: [DataType.Organization],
51
+ createIdentity: true,
52
+ createSpace: true,
53
+ onCreateSpace: async ({ space }) => {
54
+ const factory = createObjectFactory(space.db, faker as any);
55
+ await factory([{ type: DataType.Organization, count: 36 }]);
56
+ },
57
+ }),
58
+ ],
59
+ parameters: {
60
+ layout: 'fullscreen',
61
+ },
62
+ } satisfies Meta<typeof Masonry>;
63
+
64
+ export default meta;
65
+
66
+ type Story = StoryObj<typeof meta>;
67
+
68
+ export const Default: Story = {
69
+ render: DefaultStory,
70
+ };
@@ -0,0 +1,130 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import { useComposedRefs } from '@radix-ui/react-compose-refs';
6
+ import {
7
+ type UseMasonryOptions,
8
+ type UsePositionerOptions,
9
+ useMasonry,
10
+ usePositioner,
11
+ useResizeObserver,
12
+ } from 'masonic';
13
+ import React, {
14
+ type ComponentPropsWithRef,
15
+ type ForwardedRef,
16
+ type JSX,
17
+ type Ref,
18
+ forwardRef,
19
+ useMemo,
20
+ useRef,
21
+ } from 'react';
22
+
23
+ import { useScroller, useSize } from '@dxos/react-hooks';
24
+ import { type ThemedClassName, usePx } from '@dxos/react-ui';
25
+ import { mx } from '@dxos/react-ui-theme';
26
+
27
+ type MasonryRootProps<Item> = ThemedClassName<ComponentPropsWithRef<'div'>> &
28
+ Omit<UsePositionerOptions, 'width'> &
29
+ Omit<
30
+ UseMasonryOptions<Item>,
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]);
58
+ };
59
+
60
+ const MasonryRootImpl = <Item,>(
61
+ {
62
+ columnCount,
63
+ maxColumnCount,
64
+ columnWidth = 18,
65
+ maxColumnWidth,
66
+ columnGutter = 1,
67
+ rowGutter,
68
+ items,
69
+ itemHeightEstimate = 256,
70
+ itemKey,
71
+ overscanBy = 6,
72
+ render,
73
+ onRender,
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
+ };
119
+
120
+ const MasonryRoot = forwardRef(MasonryRootImpl) as <Item>(
121
+ props: MasonryRootProps<Item> & {
122
+ ref?: Ref<HTMLDivElement | null>;
123
+ },
124
+ ) => JSX.Element;
125
+
126
+ export const Masonry = {
127
+ Root: MasonryRoot,
128
+ };
129
+
130
+ export type { MasonryRootProps };
package/src/index.ts ADDED
@@ -0,0 +1,5 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ export * from './Masonry';