docs(ui): show icon tooltip on small devices (#6407)
This commit is contained in:
1 parent
3c5b020c5e
commit
3b18f399c1
3 files changed
+30
-4
No files matched your search
@@ -0,0 +1,2 @@
|
|||||||
|
---
|
||||||
|
---
|
||||||
@@ -57,7 +57,7 @@ const SearchResults = ({ query = "" }: { query?: string }) => {
|
|||||||
key={name}
|
key={name}
|
||||||
className="flex h-full w-full items-center justify-center"
|
className="flex h-full w-full items-center justify-center"
|
||||||
>
|
>
|
||||||
<CopyButton text={name} tooltipText={name}>
|
<CopyButton text={name} tooltipText={name} handleTouch>
|
||||||
<div
|
<div
|
||||||
className={clsx(
|
className={clsx(
|
||||||
"border-medusa-border-base",
|
"border-medusa-border-base",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
"use client"
|
"use client"
|
||||||
|
|
||||||
import React from "react"
|
import React, { useState } from "react"
|
||||||
import clsx from "clsx"
|
import clsx from "clsx"
|
||||||
import { Tooltip } from "@/components"
|
import { Tooltip } from "@/components"
|
||||||
import { useCopy } from "../../hooks"
|
import { useCopy } from "../../hooks"
|
||||||
@@ -10,7 +10,12 @@ export type CopyButtonProps = {
|
|||||||
buttonClassName?: string
|
buttonClassName?: string
|
||||||
tooltipClassName?: string
|
tooltipClassName?: string
|
||||||
tooltipText?: 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">
|
} & Omit<React.HTMLAttributes<HTMLDivElement>, "onCopy">
|
||||||
|
|
||||||
export const CopyButton = ({
|
export const CopyButton = ({
|
||||||
@@ -21,21 +26,40 @@ export const CopyButton = ({
|
|||||||
children,
|
children,
|
||||||
className,
|
className,
|
||||||
onCopy,
|
onCopy,
|
||||||
|
handleTouch,
|
||||||
}: CopyButtonProps) => {
|
}: CopyButtonProps) => {
|
||||||
const { isCopied, handleCopy } = useCopy(text)
|
const { isCopied, handleCopy } = useCopy(text)
|
||||||
|
const [touchCount, setTouchCount] = useState(0)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Tooltip
|
<Tooltip
|
||||||
text={isCopied ? `Copied!` : tooltipText}
|
text={isCopied ? `Copied!` : tooltipText}
|
||||||
tooltipClassName={tooltipClassName}
|
tooltipClassName={clsx(tooltipClassName, handleTouch && "!block")}
|
||||||
className={className}
|
className={className}
|
||||||
>
|
>
|
||||||
<span
|
<span
|
||||||
className={clsx("cursor-pointer", buttonClassName)}
|
className={clsx("cursor-pointer", buttonClassName)}
|
||||||
onClick={(e) => {
|
onClick={(e) => {
|
||||||
|
if (touchCount > 0) {
|
||||||
|
// prevent the on-click event from triggering if a touch event occurred.
|
||||||
|
return
|
||||||
|
}
|
||||||
onCopy?.(e)
|
onCopy?.(e)
|
||||||
handleCopy()
|
handleCopy()
|
||||||
}}
|
}}
|
||||||
|
onTouchEnd={(e) => {
|
||||||
|
if (!handleTouch) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (touchCount === 0) {
|
||||||
|
setTouchCount(touchCount + 1)
|
||||||
|
} else {
|
||||||
|
onCopy?.(e)
|
||||||
|
handleCopy()
|
||||||
|
setTouchCount(0)
|
||||||
|
}
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
</span>
|
</span>
|
||||||
|
|||||||
Reference in new issue
Block a user