use radix-ui tooltip

This commit is contained in:
Qing 2023-01-07 09:25:34 +08:00
parent a7240eedb5
commit a97f48220d
9 changed files with 26 additions and 82 deletions

View File

@ -14,7 +14,6 @@ const CoffeeIcon = () => {
<Button <Button
onClick={onClick} onClick={onClick}
toolTip="Buy me a coffee" toolTip="Buy me a coffee"
tooltipPosition="bottom"
style={{ border: 0 }} style={{ border: 0 }}
icon={<Coffee />} icon={<Coffee />}
/> />

View File

@ -59,7 +59,6 @@ import Croper from '../Croper/Croper'
import emitter, { import emitter, {
EVENT_PROMPT, EVENT_PROMPT,
EVENT_CUSTOM_MASK, EVENT_CUSTOM_MASK,
CustomMaskEventData,
EVENT_PAINT_BY_EXAMPLE, EVENT_PAINT_BY_EXAMPLE,
} from '../../event' } from '../../event'
import FileSelect from '../FileSelect/FileSelect' import FileSelect from '../FileSelect/FileSelect'
@ -1454,7 +1453,6 @@ export default function Editor() {
<div className="editor-toolkit-btns"> <div className="editor-toolkit-btns">
<Button <Button
toolTip="Interactive Segmentation" toolTip="Interactive Segmentation"
tooltipPosition="top"
icon={<CursorArrowRaysIcon />} icon={<CursorArrowRaysIcon />}
disabled={isInteractiveSeg || isInpainting || !isOriginalLoaded} disabled={isInteractiveSeg || isInpainting || !isOriginalLoaded}
onClick={() => { onClick={() => {
@ -1466,14 +1464,12 @@ export default function Editor() {
/> />
<Button <Button
toolTip="Reset Zoom & Pan" toolTip="Reset Zoom & Pan"
tooltipPosition="top"
icon={<ArrowsPointingOutIcon />} icon={<ArrowsPointingOutIcon />}
disabled={scale === minScale && panned === false} disabled={scale === minScale && panned === false}
onClick={resetZoom} onClick={resetZoom}
/> />
<Button <Button
toolTip="Undo" toolTip="Undo"
tooltipPosition="top"
icon={ icon={
<svg <svg
width="19" width="19"
@ -1493,7 +1489,6 @@ export default function Editor() {
/> />
<Button <Button
toolTip="Redo" toolTip="Redo"
tooltipPosition="top"
icon={ icon={
<svg <svg
width="19" width="19"
@ -1514,7 +1509,6 @@ export default function Editor() {
/> />
<Button <Button
toolTip="Show Original" toolTip="Show Original"
tooltipPosition="top"
icon={<EyeIcon />} icon={<EyeIcon />}
className={showOriginal ? 'eyeicon-active' : ''} className={showOriginal ? 'eyeicon-active' : ''}
onDown={ev => { onDown={ev => {
@ -1536,7 +1530,6 @@ export default function Editor() {
/> />
<Button <Button
toolTip="Save Image" toolTip="Save Image"
tooltipPosition="top"
icon={<ArrowDownTrayIcon />} icon={<ArrowDownTrayIcon />}
disabled={!renders.length} disabled={!renders.length}
onClick={download} onClick={download}
@ -1545,7 +1538,6 @@ export default function Editor() {
{settings.runInpaintingManually && !isSD && !isPaintByExample && ( {settings.runInpaintingManually && !isSD && !isPaintByExample && (
<Button <Button
toolTip="Run Inpainting" toolTip="Run Inpainting"
tooltipPosition="top"
icon={ icon={
<svg <svg
width="24" width="24"

View File

@ -201,7 +201,6 @@ export default function FileManager(props: Props) {
<Button <Button
icon={<BarsArrowDownIcon />} icon={<BarsArrowDownIcon />}
toolTip="Descending order" toolTip="Descending order"
tooltipPosition="bottom"
onClick={() => { onClick={() => {
setSortOrder(SortOrder.DESCENDING) setSortOrder(SortOrder.DESCENDING)
}} }}
@ -212,7 +211,6 @@ export default function FileManager(props: Props) {
<Button <Button
icon={<BarsArrowUpIcon />} icon={<BarsArrowUpIcon />}
toolTip="Ascending order" toolTip="Ascending order"
tooltipPosition="bottom"
onClick={() => { onClick={() => {
setSortOrder(SortOrder.ASCENDING) setSortOrder(SortOrder.ASCENDING)
}} }}

View File

@ -63,7 +63,6 @@ const Header = () => {
icon={<FolderIcon />} icon={<FolderIcon />}
style={{ border: 0 }} style={{ border: 0 }}
toolTip="Open File Manager" toolTip="Open File Manager"
tooltipPosition="bottom"
onClick={() => { onClick={() => {
setShowFileManager(true) setShowFileManager(true)
}} }}
@ -78,7 +77,6 @@ const Header = () => {
style={{ border: 0, gap: 0 }} style={{ border: 0, gap: 0 }}
disabled={isInpainting} disabled={isInpainting}
toolTip="Upload image" toolTip="Upload image"
tooltipPosition="bottom"
> >
<input <input
style={{ display: 'none' }} style={{ display: 'none' }}
@ -109,7 +107,6 @@ const Header = () => {
style={{ border: 0 }} style={{ border: 0 }}
disabled={isInpainting} disabled={isInpainting}
toolTip="Upload custom mask" toolTip="Upload custom mask"
tooltipPosition="bottom"
> >
<input <input
style={{ display: 'none' }} style={{ display: 'none' }}

View File

@ -15,7 +15,6 @@ const SettingIcon = () => {
<Button <Button
onClick={onClick} onClick={onClick}
toolTip="Settings" toolTip="Settings"
tooltipPosition="bottom"
style={{ border: 0 }} style={{ border: 0 }}
icon={ icon={
<svg <svg

View File

@ -22,7 +22,6 @@ const Shortcuts = () => {
<Button <Button
onClick={shortcutStateHandler} onClick={shortcutStateHandler}
toolTip="Hotkeys" toolTip="Hotkeys"
tooltipPosition="bottom"
disabled={shortcutVisibility} disabled={shortcutVisibility}
style={{ border: 0 }} style={{ border: 0 }}
icon={ icon={

View File

@ -36,7 +36,6 @@ const PESidePanel = () => {
<Button <Button
border border
toolTip="Upload example image" toolTip="Upload example image"
tooltipPosition="top"
icon={<UploadIcon />} icon={<UploadIcon />}
style={{ padding: '0.3rem', gap: 0 }} style={{ padding: '0.3rem', gap: 0 }}
> >

View File

@ -1,4 +1,5 @@
import React, { ReactNode } from 'react' import React, { ReactNode } from 'react'
import Tooltip from './Tooltip'
interface ButtonProps { interface ButtonProps {
border?: boolean border?: boolean
@ -7,7 +8,6 @@ interface ButtonProps {
className?: string className?: string
icon?: ReactNode icon?: ReactNode
toolTip?: string toolTip?: string
tooltipPosition?: string
onKeyDown?: () => void onKeyDown?: () => void
onClick?: () => void onClick?: () => void
onDown?: (ev: PointerEvent) => void onDown?: (ev: PointerEvent) => void
@ -23,7 +23,6 @@ const Button: React.FC<ButtonProps> = props => {
disabled, disabled,
icon, icon,
toolTip, toolTip,
tooltipPosition,
onKeyDown, onKeyDown,
onClick, onClick,
onDown, onDown,
@ -37,32 +36,31 @@ const Button: React.FC<ButtonProps> = props => {
} }
return ( return (
<div <Tooltip content={toolTip}>
role="button" <div
data-tooltip={toolTip} role="button"
style={style} style={style}
onKeyDown={onKeyDown} onKeyDown={onKeyDown}
onClick={blurOnClick} onClick={blurOnClick}
onPointerDown={(ev: React.PointerEvent<HTMLDivElement>) => { onPointerDown={(ev: React.PointerEvent<HTMLDivElement>) => {
onDown?.(ev.nativeEvent) onDown?.(ev.nativeEvent)
}} }}
onPointerUp={(ev: React.PointerEvent<HTMLDivElement>) => { onPointerUp={(ev: React.PointerEvent<HTMLDivElement>) => {
onUp?.(ev.nativeEvent) onUp?.(ev.nativeEvent)
}} }}
tabIndex={-1} tabIndex={-1}
className={[ className={[
'btn-primary', 'btn-primary',
children ? 'btn-primary-content' : '', children ? 'btn-primary-content' : '',
disabled === true ? 'btn-primary-disabled' : '', disabled === true ? 'btn-primary-disabled' : '',
toolTip ? 'info-tooltip' : '', className,
tooltipPosition ? `info-tooltip-${tooltipPosition}` : '', border ? `btn-border` : '',
className, ].join(' ')}
border ? `btn-border` : '', >
].join(' ')} {icon}
> {children ? <span>{children}</span> : null}
{icon} </div>
{children ? <span>{children}</span> : null} </Tooltip>
</div>
) )
} }

View File

@ -1,40 +1,3 @@
$tooltip-translate: 100%;
$tooltip-margin: 1.5rem;
.info-tooltip {
&:hover:before {
content: attr(data-tooltip);
position: absolute;
background-color: var(--tooltip-bg);
color: var(--tooltip-text-color);
padding: 0.5rem;
border-radius: 0.3rem;
z-index: 2;
opacity: 0;
animation-name: opacityReveal;
animation-duration: 0.2s;
animation-fill-mode: forwards;
animation-delay: 0.2s;
box-shadow: hsl(206 22% 7% / 35%) 0px 10px 38px -10px,
hsl(206 22% 7% / 20%) 0px 10px 20px -15px;
}
}
.info-tooltip-top {
&:hover:before {
transform: translateY(calc($tooltip-translate * -1));
margin-bottom: $tooltip-margin;
}
}
.info-tooltip-bottom {
&:hover:before {
transform: translateY($tooltip-translate);
margin-top: $tooltip-margin;
}
}
// radix-ui
.tooltip-trigger { .tooltip-trigger {
all: unset; all: unset;
display: flex; display: flex;