chore: upgrade ariakit

This commit is contained in:
Aman Harwara
2023-05-16 16:19:22 +05:30
parent 0c4d44fb00
commit 3b23312b62
12 changed files with 91 additions and 114 deletions

View File

@@ -1,6 +1,6 @@
import { classNames } from '@standardnotes/snjs'
import { ReactNode } from 'react'
import { Tooltip, TooltipAnchor, TooltipStoreProps, useTooltipStore } from '@ariakit/react'
import { Tooltip, TooltipAnchor, TooltipOptions, useTooltipStore } from '@ariakit/react'
import { Slot } from '@radix-ui/react-slot'
import { MutuallyExclusiveMediaQueryBreakpoints, useMediaQuery } from '@/Hooks/useMediaQuery'
import { getPositionedPopoverStyles } from '../Popover/GetPositionedPopoverStyles'
@@ -14,35 +14,9 @@ const StyledTooltip = ({
children: ReactNode
className?: string
label: string
} & Partial<TooltipStoreProps>) => {
} & Partial<TooltipOptions>) => {
const tooltip = useTooltipStore({
timeout: 350,
renderCallback(props) {
const { popoverElement, anchorElement } = props
const documentElement = document.querySelector('.main-ui-view')
if (!popoverElement || !anchorElement || !documentElement) {
return
}
const anchorRect = anchorElement.getBoundingClientRect()
const popoverRect = popoverElement.getBoundingClientRect()
const documentRect = documentElement.getBoundingClientRect()
const styles = getPositionedPopoverStyles({
align: 'center',
side: 'bottom',
anchorRect,
popoverRect,
documentRect,
disableMobileFullscreenTakeover: true,
offset: 6,
})
Object.assign(popoverElement.style, styles)
},
...props,
})
const isMobile = useMediaQuery(MutuallyExclusiveMediaQueryBreakpoints.sm)
@@ -61,6 +35,32 @@ const StyledTooltip = ({
'z-tooltip max-w-max rounded border border-border bg-contrast py-1.5 px-3 text-sm text-foreground shadow',
className,
)}
updatePosition={() => {
const { popoverElement, anchorElement } = tooltip.getState()
const documentElement = document.querySelector('.main-ui-view')
if (!popoverElement || !anchorElement || !documentElement) {
return
}
const anchorRect = anchorElement.getBoundingClientRect()
const popoverRect = popoverElement.getBoundingClientRect()
const documentRect = documentElement.getBoundingClientRect()
const styles = getPositionedPopoverStyles({
align: 'center',
side: 'bottom',
anchorRect,
popoverRect,
documentRect,
disableMobileFullscreenTakeover: true,
offset: 6,
})
Object.assign(popoverElement.style, styles)
}}
{...props}
>
{label}
</Tooltip>