Skip to content

Commit bff6bf9

Browse files
authored
feat: Action button tooltips (#1706)
Added tooltip prop to action button components resolves #1705
1 parent b1bcd3a commit bff6bf9

4 files changed

Lines changed: 34 additions & 2 deletions

File tree

packages/components/src/actions/ConfirmActionButton.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export interface ConfirmActionButtonProps {
1212
| ReactElement<SpectrumLabelableProps>
1313
| ReactElement<SpectrumLabelableProps>[];
1414
isHidden?: boolean;
15+
tooltip?: string;
1516
onConfirm: () => void;
1617
}
1718

@@ -21,6 +22,7 @@ export function ConfirmActionButton({
2122
confirmationButtonLabel,
2223
isHidden,
2324
children,
25+
tooltip,
2426
onConfirm,
2527
}: ConfirmActionButtonProps): JSX.Element {
2628
const renderDialog = useCallback(
@@ -47,6 +49,7 @@ export function ConfirmActionButton({
4749
isHidden={isHidden}
4850
isQuiet
4951
height={ACTION_ICON_HEIGHT}
52+
tooltip={tooltip}
5053
>
5154
{renderDialog}
5255
</ActionButtonDialogTrigger>

packages/components/src/actions/IconActionButton.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,19 @@ import {
77
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
88
import type { IconProp } from '@fortawesome/fontawesome-svg-core';
99
import { ACTION_ICON_HEIGHT } from '@deephaven/utils';
10+
import { Tooltip } from '../popper';
1011

1112
export interface IconActionButtonProps
1213
extends Omit<SpectrumActionButtonProps, 'aria-label' | 'isQuiet' | 'height'> {
1314
icon: IconProp;
1415
label: string;
16+
tooltip?: string;
1517
}
1618

1719
export function IconActionButton({
1820
icon,
1921
label,
22+
tooltip,
2023
...props
2124
}: IconActionButtonProps): JSX.Element {
2225
return (
@@ -26,9 +29,14 @@ export function IconActionButton({
2629
isQuiet
2730
height={ACTION_ICON_HEIGHT}
2831
>
29-
<Icon>
32+
<Icon
33+
UNSAFE_className={
34+
tooltip == null ? undefined : 'action-button-icon-with-tooltip'
35+
}
36+
>
3037
<FontAwesomeIcon icon={icon} />
3138
</Icon>
39+
{tooltip == null ? null : <Tooltip>{tooltip}</Tooltip>}
3240
</ActionButton>
3341
);
3442
}

packages/components/src/dialogs/ActionButtonDialogTrigger.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ import type { SpectrumDialogClose } from '@react-types/dialog';
44
import type { StyleProps } from '@react-types/shared';
55
import type { IconDefinition } from '@fortawesome/fontawesome-common-types';
66
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
7+
import { Tooltip } from '../popper';
78

89
export interface ActionButtonDialogTriggerProps extends StyleProps {
910
icon: IconDefinition;
1011
isQuiet?: boolean;
1112
labelText?: string;
1213
ariaLabel?: string;
14+
tooltip?: string;
1315
children: SpectrumDialogClose | ReactElement;
1416
onOpenChange?: (isOpen: boolean) => void;
1517
}
@@ -24,8 +26,14 @@ export function ActionButtonDialogTrigger({
2426
labelText,
2527
children,
2628
onOpenChange,
29+
tooltip,
2730
...styleProps
2831
}: ActionButtonDialogTriggerProps): JSX.Element {
32+
const iconClassName =
33+
labelText == null && tooltip != null
34+
? 'action-button-icon-with-tooltip'
35+
: undefined;
36+
2937
return (
3038
<DialogTrigger type="popover" onOpenChange={onOpenChange}>
3139
<ActionButton
@@ -34,10 +42,11 @@ export function ActionButtonDialogTrigger({
3442
aria-label={ariaLabel ?? labelText}
3543
isQuiet={isQuiet}
3644
>
37-
<Icon>
45+
<Icon UNSAFE_className={iconClassName}>
3846
<FontAwesomeIcon icon={icon} />
3947
</Icon>
4048
{labelText == null ? null : <Text>{labelText}</Text>}
49+
{tooltip == null ? null : <Tooltip>{tooltip}</Tooltip>}
4150
</ActionButton>
4251
{children}
4352
</DialogTrigger>

packages/components/src/theme/theme-spectrum/theme-spectrum-overrides.css

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,15 @@ label[class^='spectrum-'] {
1616
*/
1717
--spectrum-alias-workflow-icon-size: var(--dh-svg-inline-icon-size);
1818
}
19+
20+
/**
21+
* Spectrum action button icons only include right padding if the the icon is
22+
* the only child. In cases where we add a <Tooltip>, we have to manually add
23+
* the right padding ourselves to keep the icon centered.
24+
*/
25+
.action-button-icon-with-tooltip {
26+
padding-right: var(
27+
--spectrum-actionbutton-icon-padding-x,
28+
var(--spectrum-global-dimension-size-85)
29+
);
30+
}

0 commit comments

Comments
 (0)