Dashboard: Adjust styles for very long titles (#52452)

This commit is contained in:
kay delaney
2022-07-25 17:03:37 +01:00
committed by GitHub
parent 33fc3a683b
commit 06012d51a9
4 changed files with 110 additions and 74 deletions

View File

@@ -15,6 +15,7 @@ import { IconButton } from '../IconButton/IconButton';
export interface Props { export interface Props {
pageIcon?: IconName; pageIcon?: IconName;
title?: string; title?: string;
section?: string;
parent?: string; parent?: string;
onGoBack?: () => void; onGoBack?: () => void;
titleHref?: string; titleHref?: string;
@@ -30,6 +31,7 @@ export interface Props {
export const PageToolbar: FC<Props> = React.memo( export const PageToolbar: FC<Props> = React.memo(
({ ({
title, title,
section,
parent, parent,
pageIcon, pageIcon,
onGoBack, onGoBack,
@@ -59,8 +61,22 @@ export const PageToolbar: FC<Props> = React.memo(
className className
); );
const leftItemChildren = leftItems?.map((child, index) => (
<div className={styles.leftActionItem} key={index}>
{child}
</div>
));
const titleEl = (
<>
<span className={styles.noLinkTitle}>{title}</span>
{section && <span className={styles.pre}> / {section}</span>}
</>
);
return ( return (
<nav className={mainStyle} aria-label={ariaLabel}> <nav className={mainStyle} aria-label={ariaLabel}>
<div className={styles.leftWrapper}>
{pageIcon && !onGoBack && ( {pageIcon && !onGoBack && (
<div className={styles.pageIcon}> <div className={styles.pageIcon}>
<Icon name={pageIcon} size="lg" aria-hidden /> <Icon name={pageIcon} size="lg" aria-hidden />
@@ -96,26 +112,26 @@ export const PageToolbar: FC<Props> = React.memo(
</> </>
)} )}
{title && titleHref && ( {title && (
<div className={styles.titleWrapper}>
<h1 className={styles.h1Styles}> <h1 className={styles.h1Styles}>
{titleHref ? (
<Link <Link
aria-label="Search dashboard by name" aria-label="Search dashboard by name"
className={cx(styles.titleText, styles.titleLink)} className={cx(styles.titleText, styles.titleLink)}
href={titleHref} href={titleHref}
> >
{title} {titleEl}
</Link> </Link>
</h1> ) : (
<div className={styles.titleText}>{titleEl}</div>
)} )}
{title && !titleHref && <h1 className={styles.titleText}>{title}</h1>} </h1>
</nav> {leftItemChildren}
{leftItems?.map((child, index) => ( </div>
<div className={styles.leftActionItem} key={index}> )}
{child} </nav>
</div> </div>
))}
<div className={styles.spacer} />
{React.Children.toArray(children) {React.Children.toArray(children)
.filter(Boolean) .filter(Boolean)
.map((child, index) => { .map((child, index) => {
@@ -136,21 +152,11 @@ const getStyles = (theme: GrafanaTheme2) => {
const { spacing, typography } = theme; const { spacing, typography } = theme;
const focusStyle = getFocusStyles(theme); const focusStyle = getFocusStyles(theme);
const titleStyles = css`
font-size: ${typography.size.lg};
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
margin: 0;
max-width: 240px;
border-radius: 2px;
@media ${styleMixins.mediaUp(theme.v1.breakpoints.xl)} {
max-width: unset;
}
`;
return { return {
pre: css`
white-space: pre;
`,
toolbar: css` toolbar: css`
align-items: center; align-items: center;
background: ${theme.colors.background.canvas}; background: ${theme.colors.background.canvas};
@@ -159,7 +165,9 @@ const getStyles = (theme: GrafanaTheme2) => {
justify-content: flex-end; justify-content: flex-end;
padding: ${theme.spacing(1.5, 2)}; padding: ${theme.spacing(1.5, 2)};
`, `,
spacer: css` leftWrapper: css`
display: flex;
flex-wrap: nowrap;
flex-grow: 1; flex-grow: 1;
`, `,
pageIcon: css` pageIcon: css`
@@ -170,24 +178,38 @@ const getStyles = (theme: GrafanaTheme2) => {
align-items: center; align-items: center;
} }
`, `,
noLinkTitle: css`
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
`,
titleWrapper: css` titleWrapper: css`
display: flex; display: flex;
align-items: center; flex-grow: 1;
min-width: 0; margin: 0;
overflow: hidden;
`, `,
navElement: css` navElement: css`
display: flex; display: flex;
flex-grow: 1;
align-items: center;
max-width: calc(100vw - 78px);
`, `,
h1Styles: css` h1Styles: css`
margin: 0; margin: 0;
line-height: inherit; line-height: inherit;
display: flex; width: 300px;
max-width: min-content;
flex-grow: 1;
`, `,
parentIcon: css` parentIcon: css`
margin-left: ${theme.spacing(0.5)}; margin-left: ${theme.spacing(0.5)};
`, `,
titleText: titleStyles, titleText: css`
display: flex;
font-size: ${typography.size.lg};
margin: 0;
border-radius: 2px;
`,
titleLink: css` titleLink: css`
&:focus-visible { &:focus-visible {
${focusStyle} ${focusStyle}

View File

@@ -42,7 +42,11 @@ describe('DashboardSettings', () => {
</Provider> </Provider>
); );
expect(screen.getByText('Foo / Settings')).toBeInTheDocument(); expect(
screen.getByText(
(_, el) => el?.tagName.toLowerCase() === 'h1' && /Foo\s*\/\s*Settings/.test(el?.textContent ?? '')
)
).toBeInTheDocument();
await userEvent.keyboard('{Escape}'); await userEvent.keyboard('{Escape}');

View File

@@ -163,7 +163,13 @@ export function DashboardSettings({ dashboard, editview }: Props) {
return ( return (
<FocusScope contain autoFocus> <FocusScope contain autoFocus>
<div className="dashboard-settings" ref={ref} {...overlayProps} {...dialogProps}> <div className="dashboard-settings" ref={ref} {...overlayProps} {...dialogProps}>
<PageToolbar title={`${dashboard.title} / Settings`} parent={folderTitle} onGoBack={onClose} /> <PageToolbar
className={styles.toolbar}
title={dashboard.title}
section="Settings"
parent={folderTitle}
onGoBack={onClose}
/>
<CustomScrollbar> <CustomScrollbar>
<div className={styles.scrollInner}> <div className={styles.scrollInner}>
<div className={styles.settingsWrapper}> <div className={styles.settingsWrapper}>
@@ -200,6 +206,10 @@ const getStyles = stylesFactory((theme: GrafanaTheme2) => ({
min-width: 100%; min-width: 100%;
display: flex; display: flex;
`, `,
toolbar: css`
width: 60vw;
min-width: min-content;
`,
settingsWrapper: css` settingsWrapper: css`
margin: ${theme.spacing(0, 2, 2)}; margin: ${theme.spacing(0, 2, 2)};
display: flex; display: flex;

View File

@@ -443,7 +443,7 @@ export class PanelEditorUnconnected extends PureComponent<Props> {
return ( return (
<div className={styles.wrapper} aria-label={selectors.components.PanelEditor.General.content}> <div className={styles.wrapper} aria-label={selectors.components.PanelEditor.General.content}>
<PageToolbar title={`${dashboard.title} / Edit Panel`} onGoBack={this.onGoBackToDashboard}> <PageToolbar title={dashboard.title} section="Edit Panel" onGoBack={this.onGoBackToDashboard}>
{this.renderEditorActions()} {this.renderEditorActions()}
</PageToolbar> </PageToolbar>
<div className={styles.verticalSplitPanesWrapper}> <div className={styles.verticalSplitPanesWrapper}>