From bff6bf91b938bbba7f7649ac671d2e4447ea3439 Mon Sep 17 00:00:00 2001 From: Brian Ingles Date: Thu, 4 Jan 2024 15:59:46 -0600 Subject: [PATCH] feat: Action button tooltips (#1706) Added tooltip prop to action button components resolves #1705 --- .../components/src/actions/ConfirmActionButton.tsx | 3 +++ packages/components/src/actions/IconActionButton.tsx | 10 +++++++++- .../src/dialogs/ActionButtonDialogTrigger.tsx | 11 ++++++++++- .../theme-spectrum/theme-spectrum-overrides.css | 12 ++++++++++++ 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/packages/components/src/actions/ConfirmActionButton.tsx b/packages/components/src/actions/ConfirmActionButton.tsx index 5faf72f385..e0a246d505 100644 --- a/packages/components/src/actions/ConfirmActionButton.tsx +++ b/packages/components/src/actions/ConfirmActionButton.tsx @@ -12,6 +12,7 @@ export interface ConfirmActionButtonProps { | ReactElement | ReactElement[]; isHidden?: boolean; + tooltip?: string; onConfirm: () => void; } @@ -21,6 +22,7 @@ export function ConfirmActionButton({ confirmationButtonLabel, isHidden, children, + tooltip, onConfirm, }: ConfirmActionButtonProps): JSX.Element { const renderDialog = useCallback( @@ -47,6 +49,7 @@ export function ConfirmActionButton({ isHidden={isHidden} isQuiet height={ACTION_ICON_HEIGHT} + tooltip={tooltip} > {renderDialog} diff --git a/packages/components/src/actions/IconActionButton.tsx b/packages/components/src/actions/IconActionButton.tsx index 89701e369c..091cbabde5 100644 --- a/packages/components/src/actions/IconActionButton.tsx +++ b/packages/components/src/actions/IconActionButton.tsx @@ -7,16 +7,19 @@ import { import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import type { IconProp } from '@fortawesome/fontawesome-svg-core'; import { ACTION_ICON_HEIGHT } from '@deephaven/utils'; +import { Tooltip } from '../popper'; export interface IconActionButtonProps extends Omit { icon: IconProp; label: string; + tooltip?: string; } export function IconActionButton({ icon, label, + tooltip, ...props }: IconActionButtonProps): JSX.Element { return ( @@ -26,9 +29,14 @@ export function IconActionButton({ isQuiet height={ACTION_ICON_HEIGHT} > - + + {tooltip == null ? null : {tooltip}} ); } diff --git a/packages/components/src/dialogs/ActionButtonDialogTrigger.tsx b/packages/components/src/dialogs/ActionButtonDialogTrigger.tsx index 7a084b1806..51732a7230 100644 --- a/packages/components/src/dialogs/ActionButtonDialogTrigger.tsx +++ b/packages/components/src/dialogs/ActionButtonDialogTrigger.tsx @@ -4,12 +4,14 @@ import type { SpectrumDialogClose } from '@react-types/dialog'; import type { StyleProps } from '@react-types/shared'; import type { IconDefinition } from '@fortawesome/fontawesome-common-types'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; +import { Tooltip } from '../popper'; export interface ActionButtonDialogTriggerProps extends StyleProps { icon: IconDefinition; isQuiet?: boolean; labelText?: string; ariaLabel?: string; + tooltip?: string; children: SpectrumDialogClose | ReactElement; onOpenChange?: (isOpen: boolean) => void; } @@ -24,8 +26,14 @@ export function ActionButtonDialogTrigger({ labelText, children, onOpenChange, + tooltip, ...styleProps }: ActionButtonDialogTriggerProps): JSX.Element { + const iconClassName = + labelText == null && tooltip != null + ? 'action-button-icon-with-tooltip' + : undefined; + return ( - + {labelText == null ? null : {labelText}} + {tooltip == null ? null : {tooltip}} {children} diff --git a/packages/components/src/theme/theme-spectrum/theme-spectrum-overrides.css b/packages/components/src/theme/theme-spectrum/theme-spectrum-overrides.css index d0119fd51d..20ff5e7053 100644 --- a/packages/components/src/theme/theme-spectrum/theme-spectrum-overrides.css +++ b/packages/components/src/theme/theme-spectrum/theme-spectrum-overrides.css @@ -16,3 +16,15 @@ label[class^='spectrum-'] { */ --spectrum-alias-workflow-icon-size: var(--dh-svg-inline-icon-size); } + +/** + * Spectrum action button icons only include right padding if the the icon is + * the only child. In cases where we add a , we have to manually add + * the right padding ourselves to keep the icon centered. + */ +.action-button-icon-with-tooltip { + padding-right: var( + --spectrum-actionbutton-icon-padding-x, + var(--spectrum-global-dimension-size-85) + ); +}