Skip to content
Merged
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
68 changes: 0 additions & 68 deletions src/components/tooltip/Tooltip.js

This file was deleted.

86 changes: 86 additions & 0 deletions src/components/tooltip/Tooltip.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import React, { useState, useRef, useEffect, useCallback, useMemo } from 'react'

interface TooltipProps {
children: React.ReactElement
text: string
}

const Tooltip: React.FC<TooltipProps> = ({ children, text, ...props }) => {
const [show, setShow] = useState(false)
const [overflow, setOverflow] = useState(true)
const el = useRef<HTMLElement | null>(null)

const onResize = useCallback(() => {
if (
el.current &&
overflow !== (el.current.offsetWidth < el.current.scrollWidth)
) {
setOverflow(!overflow)
}
}, [overflow])

useEffect(() => {
window.addEventListener('resize', onResize)
onResize()

return () => {
window.removeEventListener('resize', onResize)
}
}, [onResize])

const onMouseOver = () => {
setShow(true)
}

const onMouseLeave = () => {
setShow(false)
}

const tooltipDisplayClass = useMemo(() => show && overflow ? 'db' : 'dn', [show, overflow])

return (
<div className='relative' {...props}>
<div
onMouseOver={onMouseOver}
onMouseLeave={onMouseLeave}
onFocus={onMouseOver}
onBlur={onMouseLeave}
className='overflow-hidden'
>
{React.Children.map(children, (c) =>
React.cloneElement(c, {
ref: (n: HTMLElement) => {
el.current = n
}
})
)}
</div>

<div
style={{
bottom: '-10px',
left: '50%',
transform: 'translate(-50%, 100%)',
wordWrap: 'break-word',
width: '100%'
}}
className={`white z-max bg-navy-muted br2 pa1 f6 absolute ${tooltipDisplayClass}`}
>
<span
style={{
width: '17px',
height: '17px',
transform: 'translate(-50%, -50%) rotate(45deg)',
borderRadius: '2px 0px 0px',
left: '50%',
zIndex: -1
}}
className='db bg-navy-muted absolute'
/>
{text}
</div>
</div>
)
}

export default Tooltip
2 changes: 1 addition & 1 deletion src/files/file/File.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { normalizeFiles, humanSize } from '../../lib/files.js'
import { useDrag, useDrop } from 'react-dnd'
// Components
import GlyphDots from '../../icons/GlyphDots.js'
import Tooltip from '../../components/tooltip/Tooltip.js'
import Tooltip from '../../components/tooltip/Tooltip.tsx'
import Checkbox from '../../components/checkbox/Checkbox.js'
import FileIcon from '../file-icon/FileIcon.js'
import { CID } from 'multiformats/cid'
Expand Down