From d48a8fd227b3e94aa24bf1db10a63caefab57651 Mon Sep 17 00:00:00 2001 From: Polina Boneva <13227501+polibb@users.noreply.github.com> Date: Tue, 31 Jan 2023 11:39:15 +0200 Subject: [PATCH] PanelChrome: Styling issues (#62466) * all panel icons are 16x16 in size; allow ToolbarButton to have its icon size set from outside; * use TitleItem for streaming too, so that the style of focus-visible is the same * allow menu icon to be visible when panel is focused * remove some styling of title icons in panel header * panel alert notices are too big * PanelHeaderNotice: Fix styling issue with background and hover when feature toggle is not enable --------- Co-authored-by: Alexandra Vargas --- .../components/PanelChrome/PanelChrome.tsx | 23 ++++++++----------- .../PanelChrome/PanelDescription.tsx | 2 +- .../components/PanelChrome/PanelStatus.tsx | 1 + .../src/components/PanelChrome/TitleItem.tsx | 2 +- .../ToolbarButton/ToolbarButton.tsx | 10 +++++--- .../PanelHeader/PanelHeaderNotice.tsx | 8 ++++--- .../PanelHeader/PanelHeaderTitleItems.tsx | 5 ++-- .../dashboard/dashgrid/PanelLinks.tsx | 4 ++-- 8 files changed, 28 insertions(+), 27 deletions(-) diff --git a/packages/grafana-ui/src/components/PanelChrome/PanelChrome.tsx b/packages/grafana-ui/src/components/PanelChrome/PanelChrome.tsx index 5ea484bbf2b..df64acc0f88 100644 --- a/packages/grafana-ui/src/components/PanelChrome/PanelChrome.tsx +++ b/packages/grafana-ui/src/components/PanelChrome/PanelChrome.tsx @@ -13,6 +13,7 @@ import { Tooltip } from '../Tooltip'; import { PanelDescription } from './PanelDescription'; import { PanelStatus } from './PanelStatus'; +import { TitleItem } from './TitleItem'; /** * @internal @@ -101,11 +102,6 @@ export function PanelChrome({ cursor: dragClass ? 'move' : 'auto', }; - const itemStyles: CSSProperties = { - minHeight: headerHeight, - minWidth: headerHeight, - }; - const containerStyles: CSSProperties = { width, height }; const ariaLabel = title ? selectors.components.Panels.Panel.containerByTitle(title) : 'Panel'; @@ -133,11 +129,11 @@ export function PanelChrome({ )} {loadingState === LoadingState.Streaming && ( -
- - - -
+ + + + + )}
@@ -147,6 +143,7 @@ export function PanelChrome({ aria-label={`Menu for panel with ${title ? `title ${title}` : 'no title'}`} title="Menu" icon="ellipsis-v" + iconSize="md" narrow data-testid="panel-menu-button" className={cx(styles.menuItem, dragClassCancel, 'menu-icon')} @@ -224,7 +221,7 @@ const getStyles = (theme: GrafanaTheme2) => { flexDirection: 'column', flex: '1 1 0', - '&:focus-visible, &:hover': { + '&:focus-within, &:hover': { // only show menu icon on hover or focused panel '.menu-icon': { visibility: 'visible', @@ -265,6 +262,7 @@ const getStyles = (theme: GrafanaTheme2) => { title: css({ label: 'panel-title', marginBottom: 0, // override default h6 margin-bottom + paddingRight: theme.spacing(1), textOverflow: 'ellipsis', overflow: 'hidden', whiteSpace: 'nowrap', @@ -298,9 +296,6 @@ const getStyles = (theme: GrafanaTheme2) => { }), titleItems: css({ display: 'flex', - alignItems: 'center', - overflow: 'hidden', - padding: theme.spacing(1), }), }; }; diff --git a/packages/grafana-ui/src/components/PanelChrome/PanelDescription.tsx b/packages/grafana-ui/src/components/PanelChrome/PanelDescription.tsx index 4f7a74dc7e3..256a02ee884 100644 --- a/packages/grafana-ui/src/components/PanelChrome/PanelDescription.tsx +++ b/packages/grafana-ui/src/components/PanelChrome/PanelDescription.tsx @@ -28,7 +28,7 @@ export function PanelDescription({ description, className }: Props) { return description !== '' ? ( - + ) : null; diff --git a/packages/grafana-ui/src/components/PanelChrome/PanelStatus.tsx b/packages/grafana-ui/src/components/PanelChrome/PanelStatus.tsx index 15bbc4a3a08..55fd516f6ba 100644 --- a/packages/grafana-ui/src/components/PanelChrome/PanelStatus.tsx +++ b/packages/grafana-ui/src/components/PanelChrome/PanelStatus.tsx @@ -22,6 +22,7 @@ export function PanelStatus({ className, message, onClick, ariaLabel = 'status' onClick={onClick} variant={'destructive'} icon="exclamation-triangle" + iconSize="md" tooltip={message || ''} aria-label={ariaLabel} /> diff --git a/packages/grafana-ui/src/components/PanelChrome/TitleItem.tsx b/packages/grafana-ui/src/components/PanelChrome/TitleItem.tsx index b6d1d4fd8cd..f1880272890 100644 --- a/packages/grafana-ui/src/components/PanelChrome/TitleItem.tsx +++ b/packages/grafana-ui/src/components/PanelChrome/TitleItem.tsx @@ -55,7 +55,7 @@ const getStyles = (theme: GrafanaTheme2) => { border: 'none', borderRadius: `${theme.shape.borderRadius()}`, padding: `${theme.spacing(0, 1)}`, - height: `${theme.spacing(theme.components.height.md)}`, + height: `${theme.spacing(theme.components.panel.headerHeight)}`, display: 'flex', alignItems: 'center', justifyContent: 'center', diff --git a/packages/grafana-ui/src/components/ToolbarButton/ToolbarButton.tsx b/packages/grafana-ui/src/components/ToolbarButton/ToolbarButton.tsx index 6c286ff2dbe..a24289f01db 100644 --- a/packages/grafana-ui/src/components/ToolbarButton/ToolbarButton.tsx +++ b/packages/grafana-ui/src/components/ToolbarButton/ToolbarButton.tsx @@ -6,6 +6,7 @@ import { selectors } from '@grafana/e2e-selectors'; import { styleMixins, useStyles2 } from '../../themes'; import { getFocusStyles, getMouseFocusStyles } from '../../themes/mixins'; +import { IconSize } from '../../types/icon'; import { getPropertiesForVariant } from '../Button'; import { Icon } from '../Icon/Icon'; import { Tooltip } from '../Tooltip'; @@ -13,6 +14,8 @@ import { Tooltip } from '../Tooltip'; type CommonProps = { /** Icon name */ icon?: IconName | React.ReactNode; + /** Icon size */ + iconSize?: IconSize; /** Tooltip */ tooltip?: string; /** For image icons */ @@ -42,6 +45,7 @@ export const ToolbarButton = forwardRef( { tooltip, icon, + iconSize, className, children, imgSrc, @@ -83,7 +87,7 @@ export const ToolbarButton = forwardRef( aria-expanded={isOpen} {...rest} > - {renderIcon(icon)} + {renderIcon(icon, iconSize)} {imgSrc && {imgAlt} {children && !iconOnly &&
{children}
} {isOpen === false && } @@ -108,13 +112,13 @@ function getButtonAriaLabel(ariaLabel: string | undefined, tooltip: string | und return ariaLabel ? ariaLabel : tooltip ? selectors.components.PageToolbar.item(tooltip) : undefined; } -function renderIcon(icon: IconName | React.ReactNode) { +function renderIcon(icon: IconName | React.ReactNode, iconSize?: IconSize) { if (!icon) { return null; } if (isIconName(icon)) { - return ; + return ; } return icon; diff --git a/public/app/features/dashboard/dashgrid/PanelHeader/PanelHeaderNotice.tsx b/public/app/features/dashboard/dashgrid/PanelHeader/PanelHeaderNotice.tsx index a59680e1290..a1f45f92f1f 100644 --- a/public/app/features/dashboard/dashgrid/PanelHeader/PanelHeaderNotice.tsx +++ b/public/app/features/dashboard/dashgrid/PanelHeader/PanelHeaderNotice.tsx @@ -21,6 +21,7 @@ export const PanelHeaderNotice: FC = ({ notice, onClick }) => { onClick(e, notice.inspect!)} @@ -31,7 +32,7 @@ export const PanelHeaderNotice: FC = ({ notice, onClick }) => { if (notice.link) { return ( - + ); } @@ -39,7 +40,7 @@ export const PanelHeaderNotice: FC = ({ notice, onClick }) => { return ( - + ); @@ -47,12 +48,13 @@ export const PanelHeaderNotice: FC = ({ notice, onClick }) => { const getStyles = (theme: GrafanaTheme2) => ({ notice: css({ + background: 'inherit', border: 'none', borderRadius: theme.shape.borderRadius(), }), iconTooltip: css({ color: `${theme.colors.text.secondary}`, - backgroundColor: `${theme.colors.background.primary}`, + backgroundColor: 'inherit', cursor: 'auto', border: 'none', borderRadius: `${theme.shape.borderRadius()}`, diff --git a/public/app/features/dashboard/dashgrid/PanelHeader/PanelHeaderTitleItems.tsx b/public/app/features/dashboard/dashgrid/PanelHeader/PanelHeaderTitleItems.tsx index de802fc6fad..df92d69525e 100644 --- a/public/app/features/dashboard/dashgrid/PanelHeader/PanelHeaderTitleItems.tsx +++ b/public/app/features/dashboard/dashgrid/PanelHeader/PanelHeaderTitleItems.tsx @@ -30,7 +30,7 @@ export function PanelHeaderTitleItems(props: Props) { [styles.alerting]: alertState === AlertState.Alerting, })} > - + ); @@ -40,8 +40,7 @@ export function PanelHeaderTitleItems(props: Props) { {data.request && data.request.timeInfo && ( }> - - {data.request?.timeInfo} + {data.request?.timeInfo} )} diff --git a/public/app/features/dashboard/dashgrid/PanelLinks.tsx b/public/app/features/dashboard/dashgrid/PanelLinks.tsx index ae1e4444b5e..b56672787ed 100644 --- a/public/app/features/dashboard/dashgrid/PanelLinks.tsx +++ b/public/app/features/dashboard/dashgrid/PanelLinks.tsx @@ -32,13 +32,13 @@ export function PanelLinks({ panelLinks, onShowPanelLinks }: Props) { target={linkModel.target} title={linkModel.title} > - + ); } else { return ( - + ); }