Skip to content

Commit

Permalink
fix: collection spacing
Browse files Browse the repository at this point in the history
  • Loading branch information
alaycock committed Jan 13, 2025
1 parent 3991343 commit 9912c17
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
3 changes: 3 additions & 0 deletions packages/react-notion-x/src/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export interface NotionContext {
minTableOfContentsItems: number
linkTableTitleProperties: boolean
isLinkCollectionToUrlProperty: boolean
pageWidth: number

defaultPageIcon?: string | null
defaultPageCover?: string | null
Expand Down Expand Up @@ -63,6 +64,7 @@ export interface PartialNotionContext {
showCollectionViewDropdown?: boolean
linkTableTitleProperties?: boolean
isLinkCollectionToUrlProperty?: boolean
pageWidth?: number

showTableOfContents?: boolean
minTableOfContentsItems?: number
Expand Down Expand Up @@ -169,6 +171,7 @@ const defaultNotionContext: NotionContext = {
showCollectionViewDropdown: true,
linkTableTitleProperties: true,
isLinkCollectionToUrlProperty: false,
pageWidth: 708,

showTableOfContents: false,
minTableOfContentsItems: 3,
Expand Down
3 changes: 3 additions & 0 deletions packages/react-notion-x/src/renderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export function NotionRenderer({
linkTableTitleProperties,
isLinkCollectionToUrlProperty,
isImageZoomable = true,
pageWidth,
showTableOfContents,
minTableOfContentsItems,
defaultPageIcon,
Expand Down Expand Up @@ -59,6 +60,7 @@ export function NotionRenderer({
linkTableTitleProperties?: boolean
isLinkCollectionToUrlProperty?: boolean
isImageZoomable?: boolean
pageWidth?: number

showTableOfContents?: boolean
minTableOfContentsItems?: number
Expand Down Expand Up @@ -111,6 +113,7 @@ export function NotionRenderer({
showCollectionViewDropdown={showCollectionViewDropdown}
linkTableTitleProperties={linkTableTitleProperties}
isLinkCollectionToUrlProperty={isLinkCollectionToUrlProperty}
pageWidth={pageWidth}
showTableOfContents={showTableOfContents}
minTableOfContentsItems={minTableOfContentsItems}
defaultPageIcon={defaultPageIcon}
Expand Down
9 changes: 5 additions & 4 deletions packages/react-notion-x/src/third-party/collection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ function CollectionViewBlock({
block: types.CollectionViewBlock | types.CollectionViewPageBlock
className?: string
}) {
const { recordMap, showCollectionViewDropdown } = useNotionContext()
const { recordMap, pageWidth, showCollectionViewDropdown } =
useNotionContext()
const { view_ids: viewIds } = block
const collectionId = getBlockCollectionId(block, recordMap)!

Expand Down Expand Up @@ -139,15 +140,15 @@ function CollectionViewBlock({

const width = windowWidth
// TODO: customize for mobile?
const maxNotionBodyWidth = 708
const maxNotionBodyWidth = pageWidth
let notionBodyWidth = maxNotionBodyWidth

if (parentPage?.format?.page_full_width) {
notionBodyWidth = Math.trunc(width - 2 * Math.min(96, width * 0.08))
} else {
notionBodyWidth =
width < maxNotionBodyWidth
? Math.trunc(width - width * 0.02) // 2vw
? Math.trunc(width - width * 0.04) // 2vw for each side
: maxNotionBodyWidth
}

Expand All @@ -161,7 +162,7 @@ function CollectionViewBlock({
width,
padding
}
}, [windowWidth, parentPage, collectionView?.type, isMounted])
}, [windowWidth, parentPage, pageWidth, collectionView?.type, isMounted])

// console.log({
// width,
Expand Down
8 changes: 4 additions & 4 deletions packages/react-notion-x/src/third-party/react-use.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,16 @@ export const useWindowSize = (
initialHeight = Infinity
) => {
const [state, setState] = useRafState<{ width: number; height: number }>({
width: isBrowser ? window.innerWidth : initialWidth,
height: isBrowser ? window.innerHeight : initialHeight
width: isBrowser ? document.documentElement.clientWidth : initialWidth,
height: isBrowser ? document.documentElement.clientHeight : initialHeight
})

useEffect((): (() => void) | void => {
if (isBrowser) {
const handler = () => {
setState({
width: window.innerWidth,
height: window.innerHeight
width: document.documentElement.clientWidth,
height: document.documentElement.clientHeight
})
}

Expand Down

0 comments on commit 9912c17

Please sign in to comment.