docs(ui): show icon tooltip on small devices (#6407)

This commit is contained in:
Shahed Nasser
2024-02-26 09:31:36 +02:00
committed by GitHub
parent 3c5b020c5e
commit 3b18f399c1
3 changed files with 30 additions and 4 deletions

View File

@@ -0,0 +1,2 @@
---
---

View File

@@ -57,7 +57,7 @@ const SearchResults = ({ query = "" }: { query?: string }) => {
key={name}
className="flex h-full w-full items-center justify-center"
>
<CopyButton text={name} tooltipText={name}>
<CopyButton text={name} tooltipText={name} handleTouch>
<div
className={clsx(
"border-medusa-border-base",

View File

@@ -1,6 +1,6 @@
"use client"
import React from "react"
import React, { useState } from "react"
import clsx from "clsx"
import { Tooltip } from "@/components"
import { useCopy } from "../../hooks"
@@ -10,7 +10,12 @@ export type CopyButtonProps = {
buttonClassName?: string
tooltipClassName?: string
tooltipText?: string
onCopy?: (e: React.MouseEvent<HTMLSpanElement, MouseEvent>) => void
onCopy?: (
e:
| React.MouseEvent<HTMLSpanElement, MouseEvent>
| React.TouchEvent<HTMLSpanElement>
) => void
handleTouch?: boolean
} & Omit<React.HTMLAttributes<HTMLDivElement>, "onCopy">
export const CopyButton = ({
@@ -21,21 +26,40 @@ export const CopyButton = ({
children,
className,
onCopy,
handleTouch,
}: CopyButtonProps) => {
const { isCopied, handleCopy } = useCopy(text)
const [touchCount, setTouchCount] = useState(0)
return (
<Tooltip
text={isCopied ? `Copied!` : tooltipText}
tooltipClassName={tooltipClassName}
tooltipClassName={clsx(tooltipClassName, handleTouch && "!block")}
className={className}
>
<span
className={clsx("cursor-pointer", buttonClassName)}
onClick={(e) => {
if (touchCount > 0) {
// prevent the on-click event from triggering if a touch event occurred.
return
}
onCopy?.(e)
handleCopy()
}}
onTouchEnd={(e) => {
if (!handleTouch) {
return
}
if (touchCount === 0) {
setTouchCount(touchCount + 1)
} else {
onCopy?.(e)
handleCopy()
setTouchCount(0)
}
}}
>
{children}
</span>