docs(ui): show icon tooltip on small devices (#6407)
This commit is contained in:
2
.changeset/green-geckos-pump.md
Normal file
2
.changeset/green-geckos-pump.md
Normal file
@@ -0,0 +1,2 @@
|
||||
---
|
||||
---
|
||||
@@ -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",
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user