From 20f19ddca63dca4d34b9fd62b4e0b4073fdcd2be Mon Sep 17 00:00:00 2001 From: Alexander Burobin Date: Tue, 1 Oct 2024 17:15:39 +0300 Subject: [PATCH] feat(ClipboardButton): delay tooltip's closing animation after copying (#1735) Co-authored-by: Aleksandr Burobin --- .../ClipboardButton/ClipboardButton.scss | 10 ++ .../ClipboardButton/ClipboardButton.tsx | 96 +++++++++++++++++-- src/components/ClipboardButton/i18n/en.json | 2 +- src/components/ClipboardButton/i18n/ru.json | 2 +- 4 files changed, 100 insertions(+), 10 deletions(-) create mode 100644 src/components/ClipboardButton/ClipboardButton.scss diff --git a/src/components/ClipboardButton/ClipboardButton.scss b/src/components/ClipboardButton/ClipboardButton.scss new file mode 100644 index 0000000000..8891345fc8 --- /dev/null +++ b/src/components/ClipboardButton/ClipboardButton.scss @@ -0,0 +1,10 @@ +@use '../variables'; + +$block: '.#{variables.$ns}clipboard-button'; + +#{$block} { + &__icon { + // prevent button icon from firing onMouseEnter/onFocus through parent button's handler + pointer-events: none; + } +} diff --git a/src/components/ClipboardButton/ClipboardButton.tsx b/src/components/ClipboardButton/ClipboardButton.tsx index 4d2c5acc7b..c30d42065e 100644 --- a/src/components/ClipboardButton/ClipboardButton.tsx +++ b/src/components/ClipboardButton/ClipboardButton.tsx @@ -7,17 +7,27 @@ import {Button} from '../Button'; import type {ButtonProps, ButtonSize} from '../Button'; import {ClipboardIcon} from '../ClipboardIcon'; import {CopyToClipboard} from '../CopyToClipboard'; -import type {CopyToClipboardProps, CopyToClipboardStatus} from '../CopyToClipboard/types'; +import type { + CopyToClipboardProps, + CopyToClipboardStatus, + OnCopyHandler, +} from '../CopyToClipboard/types'; +import {block} from '../utils/cn'; import i18n from './i18n'; +import './ClipboardButton.scss'; + +const b = block('clipboard-button'); + export interface ClipboardButtonProps extends Omit, - Omit {} + Omit {} interface ClipboardButtonComponentProps extends Omit { status: CopyToClipboardStatus; + closeDelay: number | undefined; /** Disable tooltip. Tooltip won't be shown */ hasTooltip?: boolean; /** Text shown before copy */ @@ -28,7 +38,8 @@ interface ClipboardButtonComponentProps iconPosition?: 'start' | 'end'; } -const DEFAULT_TIMEOUT = 1000; +const DEFAULT_TIMEOUT = 1200; +const TOOLTIP_ANIMATION = 200; const ButtonSizeToIconSize: Record = { xs: 12, @@ -49,19 +60,23 @@ const ClipboardButtonComponent = (props: ClipboardButtonComponentProps) => { extraProps = {}, children, iconPosition = 'start', + closeDelay, + onMouseEnter, + onFocus, ...rest } = props; const buttonIcon = ( - + ); return (