chore: fix table of contents option on mobile
This commit is contained in:
@@ -103,6 +103,7 @@ type Options = {
|
|||||||
side: PopoverSide
|
side: PopoverSide
|
||||||
disableMobileFullscreenTakeover?: boolean
|
disableMobileFullscreenTakeover?: boolean
|
||||||
disableApplyingMobileWidth?: boolean
|
disableApplyingMobileWidth?: boolean
|
||||||
|
disableFlip?: boolean
|
||||||
maxHeightFunction?: (calculatedMaxHeight: number) => number | 'none'
|
maxHeightFunction?: (calculatedMaxHeight: number) => number | 'none'
|
||||||
offset?: number
|
offset?: number
|
||||||
}
|
}
|
||||||
@@ -115,6 +116,7 @@ export const getPositionedPopoverStyles = ({
|
|||||||
side,
|
side,
|
||||||
disableMobileFullscreenTakeover,
|
disableMobileFullscreenTakeover,
|
||||||
disableApplyingMobileWidth,
|
disableApplyingMobileWidth,
|
||||||
|
disableFlip,
|
||||||
maxHeightFunction,
|
maxHeightFunction,
|
||||||
offset,
|
offset,
|
||||||
}: Options): PopoverCSSProperties | null => {
|
}: Options): PopoverCSSProperties | null => {
|
||||||
@@ -135,7 +137,7 @@ export const getPositionedPopoverStyles = ({
|
|||||||
|
|
||||||
const sideWithLessOverflows = preferredSideRectCollisions[side] ? oppositeSide : side
|
const sideWithLessOverflows = preferredSideRectCollisions[side] ? oppositeSide : side
|
||||||
const finalAlignment = getNonCollidingAlignment({
|
const finalAlignment = getNonCollidingAlignment({
|
||||||
finalSide: sideWithLessOverflows,
|
finalSide: disableFlip ? side : sideWithLessOverflows,
|
||||||
preferredAlignment: align,
|
preferredAlignment: align,
|
||||||
collisions: preferredSideRectCollisions,
|
collisions: preferredSideRectCollisions,
|
||||||
popoverRect,
|
popoverRect,
|
||||||
@@ -145,7 +147,7 @@ export const getPositionedPopoverStyles = ({
|
|||||||
const finalPositionedRect = getPositionedPopoverRect(
|
const finalPositionedRect = getPositionedPopoverRect(
|
||||||
popoverRect,
|
popoverRect,
|
||||||
anchorRect,
|
anchorRect,
|
||||||
sideWithLessOverflows,
|
disableFlip ? side : sideWithLessOverflows,
|
||||||
finalAlignment,
|
finalAlignment,
|
||||||
offset,
|
offset,
|
||||||
)
|
)
|
||||||
@@ -153,7 +155,7 @@ export const getPositionedPopoverStyles = ({
|
|||||||
let maxHeight = getPopoverMaxHeight(
|
let maxHeight = getPopoverMaxHeight(
|
||||||
getAppRect(),
|
getAppRect(),
|
||||||
anchorRect,
|
anchorRect,
|
||||||
sideWithLessOverflows,
|
disableFlip ? side : sideWithLessOverflows,
|
||||||
finalAlignment,
|
finalAlignment,
|
||||||
disableMobileFullscreenTakeover,
|
disableMobileFullscreenTakeover,
|
||||||
)
|
)
|
||||||
@@ -164,7 +166,7 @@ export const getPositionedPopoverStyles = ({
|
|||||||
|
|
||||||
return getStylesFromRect({
|
return getStylesFromRect({
|
||||||
rect: finalPositionedRect,
|
rect: finalPositionedRect,
|
||||||
side: sideWithLessOverflows,
|
side: disableFlip ? side : sideWithLessOverflows,
|
||||||
align: finalAlignment,
|
align: finalAlignment,
|
||||||
disableMobileFullscreenTakeover,
|
disableMobileFullscreenTakeover,
|
||||||
disableApplyingMobileWidth,
|
disableApplyingMobileWidth,
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ const PositionedPopoverContent = ({
|
|||||||
togglePopover,
|
togglePopover,
|
||||||
disableClickOutside,
|
disableClickOutside,
|
||||||
disableMobileFullscreenTakeover,
|
disableMobileFullscreenTakeover,
|
||||||
|
disableFlip,
|
||||||
maxHeight,
|
maxHeight,
|
||||||
portal = true,
|
portal = true,
|
||||||
offset,
|
offset,
|
||||||
@@ -53,7 +54,8 @@ const PositionedPopoverContent = ({
|
|||||||
documentRect,
|
documentRect,
|
||||||
popoverRect: popoverRect ?? popoverElement?.getBoundingClientRect(),
|
popoverRect: popoverRect ?? popoverElement?.getBoundingClientRect(),
|
||||||
side,
|
side,
|
||||||
disableMobileFullscreenTakeover: disableMobileFullscreenTakeover,
|
disableMobileFullscreenTakeover,
|
||||||
|
disableFlip,
|
||||||
maxHeightFunction: maxHeight,
|
maxHeightFunction: maxHeight,
|
||||||
offset,
|
offset,
|
||||||
})
|
})
|
||||||
@@ -140,9 +142,9 @@ const PositionedPopoverContent = ({
|
|||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
className={classNames(
|
className={classNames(
|
||||||
'overflow-y-auto rounded border border-[--popover-border-color] bg-[--popover-background-color] [backdrop-filter:var(--popover-backdrop-filter)] shadow-main',
|
'overflow-y-auto rounded border border-[--popover-border-color] bg-[--popover-background-color] shadow-main [backdrop-filter:var(--popover-backdrop-filter)]',
|
||||||
!isDesktopScreen && !disableMobileFullscreenTakeover ? 'pb-safe-bottom pt-safe-top' : '',
|
!isDesktopScreen && !disableMobileFullscreenTakeover ? 'pb-safe-bottom pt-safe-top' : '',
|
||||||
'transition-[transform,opacity] motion-reduce:transition-opacity duration-75 [transform-origin:var(--transform-origin)]',
|
'transition-[transform,opacity] duration-75 [transform-origin:var(--transform-origin)] motion-reduce:transition-opacity',
|
||||||
styles ? 'scale-100 opacity-100' : 'scale-95 opacity-0',
|
styles ? 'scale-100 opacity-100' : 'scale-95 opacity-0',
|
||||||
className,
|
className,
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ type CommonPopoverProps = {
|
|||||||
maxHeight?: (calculatedMaxHeight: number) => number
|
maxHeight?: (calculatedMaxHeight: number) => number
|
||||||
togglePopover?: () => void
|
togglePopover?: () => void
|
||||||
disableMobileFullscreenTakeover?: boolean
|
disableMobileFullscreenTakeover?: boolean
|
||||||
|
disableFlip?: boolean
|
||||||
title: string
|
title: string
|
||||||
portal?: boolean
|
portal?: boolean
|
||||||
offset?: number
|
offset?: number
|
||||||
|
|||||||
@@ -675,6 +675,7 @@ const ToolbarPlugin = () => {
|
|||||||
align="center"
|
align="center"
|
||||||
className="py-1"
|
className="py-1"
|
||||||
disableMobileFullscreenTakeover
|
disableMobileFullscreenTakeover
|
||||||
|
disableFlip
|
||||||
>
|
>
|
||||||
<div className="mb-1.5 mt-1 px-3 text-sm font-semibold uppercase text-text">Table of Contents</div>
|
<div className="mb-1.5 mt-1 px-3 text-sm font-semibold uppercase text-text">Table of Contents</div>
|
||||||
<LexicalTableOfContents>
|
<LexicalTableOfContents>
|
||||||
@@ -690,14 +691,13 @@ const ToolbarPlugin = () => {
|
|||||||
key={key}
|
key={key}
|
||||||
className="overflow-hidden md:py-2"
|
className="overflow-hidden md:py-2"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setIsTOCOpen(false)
|
|
||||||
editor.getEditorState().read(() => {
|
editor.getEditorState().read(() => {
|
||||||
const domElement = editor.getElementByKey(key)
|
const domElement = editor.getElementByKey(key)
|
||||||
if (!domElement) {
|
if (!domElement) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const reducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches
|
domElement.scrollIntoView({ block: 'start' })
|
||||||
domElement.scrollIntoView({ behavior: reducedMotion ? 'auto' : 'smooth', block: 'nearest' })
|
setIsTOCOpen(false)
|
||||||
})
|
})
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
|||||||
Reference in New Issue
Block a user