Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Action button tooltips #1706

Merged
merged 2 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/components/src/actions/ConfirmActionButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export interface ConfirmActionButtonProps {
| ReactElement<SpectrumLabelableProps>
| ReactElement<SpectrumLabelableProps>[];
isHidden?: boolean;
tooltip?: string;
onConfirm: () => void;
}

Expand All @@ -21,6 +22,7 @@ export function ConfirmActionButton({
confirmationButtonLabel,
isHidden,
children,
tooltip,
onConfirm,
}: ConfirmActionButtonProps): JSX.Element {
const renderDialog = useCallback(
Expand All @@ -47,6 +49,7 @@ export function ConfirmActionButton({
isHidden={isHidden}
isQuiet
height={ACTION_ICON_HEIGHT}
tooltip={tooltip}
>
{renderDialog}
</ActionButtonDialogTrigger>
Expand Down
10 changes: 9 additions & 1 deletion packages/components/src/actions/IconActionButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<SpectrumActionButtonProps, 'aria-label' | 'isQuiet' | 'height'> {
icon: IconProp;
label: string;
tooltip?: string;
}

export function IconActionButton({
icon,
label,
tooltip,
...props
}: IconActionButtonProps): JSX.Element {
return (
Expand All @@ -26,9 +29,14 @@ export function IconActionButton({
isQuiet
height={ACTION_ICON_HEIGHT}
>
<Icon>
<Icon
UNSAFE_className={
tooltip == null ? undefined : 'action-button-icon-with-tooltip'
}
>
<FontAwesomeIcon icon={icon} />
</Icon>
{tooltip == null ? null : <Tooltip>{tooltip}</Tooltip>}
</ActionButton>
);
}
Expand Down
12 changes: 11 additions & 1 deletion packages/components/src/dialogs/ActionButtonDialogTrigger.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
/* eslint-disable camelcase */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary. In cases where we do need to go against eslint rules, should opt for disabling a single line only wherever possible.

Suggested change
/* eslint-disable camelcase */

import { ReactElement } from 'react';
import { ActionButton, DialogTrigger, Icon, Text } from '@adobe/react-spectrum';
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;
}
Expand All @@ -24,8 +27,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 (
<DialogTrigger type="popover" onOpenChange={onOpenChange}>
<ActionButton
Expand All @@ -34,10 +43,11 @@ export function ActionButtonDialogTrigger({
aria-label={ariaLabel ?? labelText}
isQuiet={isQuiet}
>
<Icon>
<Icon UNSAFE_className={iconClassName}>
<FontAwesomeIcon icon={icon} />
</Icon>
{labelText == null ? null : <Text>{labelText}</Text>}
{tooltip == null ? null : <Tooltip>{tooltip}</Tooltip>}
</ActionButton>
{children}
</DialogTrigger>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <Tooltip>, 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)
);
}
Loading