Skip to content

fix: table collection padding calculation #603

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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