Skip to content

Commit 9912c17

Browse files
committed
fix: collection spacing
1 parent 3991343 commit 9912c17

File tree

4 files changed

+15
-8
lines changed

4 files changed

+15
-8
lines changed

packages/react-notion-x/src/context.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export interface NotionContext {
3535
minTableOfContentsItems: number
3636
linkTableTitleProperties: boolean
3737
isLinkCollectionToUrlProperty: boolean
38+
pageWidth: number
3839

3940
defaultPageIcon?: string | null
4041
defaultPageCover?: string | null
@@ -63,6 +64,7 @@ export interface PartialNotionContext {
6364
showCollectionViewDropdown?: boolean
6465
linkTableTitleProperties?: boolean
6566
isLinkCollectionToUrlProperty?: boolean
67+
pageWidth?: number
6668

6769
showTableOfContents?: boolean
6870
minTableOfContentsItems?: number
@@ -169,6 +171,7 @@ const defaultNotionContext: NotionContext = {
169171
showCollectionViewDropdown: true,
170172
linkTableTitleProperties: true,
171173
isLinkCollectionToUrlProperty: false,
174+
pageWidth: 708,
172175

173176
showTableOfContents: false,
174177
minTableOfContentsItems: 3,

packages/react-notion-x/src/renderer.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export function NotionRenderer({
2929
linkTableTitleProperties,
3030
isLinkCollectionToUrlProperty,
3131
isImageZoomable = true,
32+
pageWidth,
3233
showTableOfContents,
3334
minTableOfContentsItems,
3435
defaultPageIcon,
@@ -59,6 +60,7 @@ export function NotionRenderer({
5960
linkTableTitleProperties?: boolean
6061
isLinkCollectionToUrlProperty?: boolean
6162
isImageZoomable?: boolean
63+
pageWidth?: number
6264

6365
showTableOfContents?: boolean
6466
minTableOfContentsItems?: number
@@ -111,6 +113,7 @@ export function NotionRenderer({
111113
showCollectionViewDropdown={showCollectionViewDropdown}
112114
linkTableTitleProperties={linkTableTitleProperties}
113115
isLinkCollectionToUrlProperty={isLinkCollectionToUrlProperty}
116+
pageWidth={pageWidth}
114117
showTableOfContents={showTableOfContents}
115118
minTableOfContentsItems={minTableOfContentsItems}
116119
defaultPageIcon={defaultPageIcon}

packages/react-notion-x/src/third-party/collection.tsx

+5-4
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ function CollectionViewBlock({
8484
block: types.CollectionViewBlock | types.CollectionViewPageBlock
8585
className?: string
8686
}) {
87-
const { recordMap, showCollectionViewDropdown } = useNotionContext()
87+
const { recordMap, pageWidth, showCollectionViewDropdown } =
88+
useNotionContext()
8889
const { view_ids: viewIds } = block
8990
const collectionId = getBlockCollectionId(block, recordMap)!
9091

@@ -139,15 +140,15 @@ function CollectionViewBlock({
139140

140141
const width = windowWidth
141142
// TODO: customize for mobile?
142-
const maxNotionBodyWidth = 708
143+
const maxNotionBodyWidth = pageWidth
143144
let notionBodyWidth = maxNotionBodyWidth
144145

145146
if (parentPage?.format?.page_full_width) {
146147
notionBodyWidth = Math.trunc(width - 2 * Math.min(96, width * 0.08))
147148
} else {
148149
notionBodyWidth =
149150
width < maxNotionBodyWidth
150-
? Math.trunc(width - width * 0.02) // 2vw
151+
? Math.trunc(width - width * 0.04) // 2vw for each side
151152
: maxNotionBodyWidth
152153
}
153154

@@ -161,7 +162,7 @@ function CollectionViewBlock({
161162
width,
162163
padding
163164
}
164-
}, [windowWidth, parentPage, collectionView?.type, isMounted])
165+
}, [windowWidth, parentPage, pageWidth, collectionView?.type, isMounted])
165166

166167
// console.log({
167168
// width,

packages/react-notion-x/src/third-party/react-use.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,16 @@ export const useWindowSize = (
4545
initialHeight = Infinity
4646
) => {
4747
const [state, setState] = useRafState<{ width: number; height: number }>({
48-
width: isBrowser ? window.innerWidth : initialWidth,
49-
height: isBrowser ? window.innerHeight : initialHeight
48+
width: isBrowser ? document.documentElement.clientWidth : initialWidth,
49+
height: isBrowser ? document.documentElement.clientHeight : initialHeight
5050
})
5151

5252
useEffect((): (() => void) | void => {
5353
if (isBrowser) {
5454
const handler = () => {
5555
setState({
56-
width: window.innerWidth,
57-
height: window.innerHeight
56+
width: document.documentElement.clientWidth,
57+
height: document.documentElement.clientHeight
5858
})
5959
}
6060

0 commit comments

Comments
 (0)