mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* Search: Improving search look and feel * Fixed issue with tag filter beeing cramped and wrapping tags * Minor tag polish * fixed type
101 lines
2.5 KiB
TypeScript
101 lines
2.5 KiB
TypeScript
import React, { FC, useCallback } from 'react';
|
|
import { css, cx } from 'emotion';
|
|
import { GrafanaTheme } from '@grafana/data';
|
|
import { Icon, IconButton, IconName, stylesFactory, useTheme } from '@grafana/ui';
|
|
import { DashboardSection, OnToggleChecked } from '../types';
|
|
import { SearchCheckbox } from './SearchCheckbox';
|
|
|
|
interface SectionHeaderProps {
|
|
editable?: boolean;
|
|
onSectionClick: (section: DashboardSection) => void;
|
|
onToggleChecked?: OnToggleChecked;
|
|
section: DashboardSection;
|
|
}
|
|
|
|
export const SectionHeader: FC<SectionHeaderProps> = ({
|
|
section,
|
|
onSectionClick,
|
|
onToggleChecked,
|
|
editable = false,
|
|
}) => {
|
|
const theme = useTheme();
|
|
const styles = getSectionHeaderStyles(theme, section.selected, editable);
|
|
|
|
const onSectionExpand = () => {
|
|
onSectionClick(section);
|
|
};
|
|
|
|
const onSectionChecked = useCallback(
|
|
(e: React.MouseEvent) => {
|
|
e.preventDefault();
|
|
e.stopPropagation();
|
|
if (onToggleChecked) {
|
|
onToggleChecked(section);
|
|
}
|
|
},
|
|
[section]
|
|
);
|
|
|
|
return (
|
|
<div className={styles.wrapper} onClick={onSectionExpand}>
|
|
<SearchCheckbox editable={editable} checked={section.checked} onClick={onSectionChecked} />
|
|
|
|
<div className={styles.icon}>
|
|
<Icon name={section.icon as IconName} />
|
|
</div>
|
|
|
|
<span className={styles.text}>{section.title}</span>
|
|
{section.url && (
|
|
<a href={section.url} className={styles.link}>
|
|
<IconButton name="cog" className={styles.button} />
|
|
</a>
|
|
)}
|
|
<Icon name={section.expanded ? 'angle-down' : 'angle-right'} />
|
|
</div>
|
|
);
|
|
};
|
|
|
|
const getSectionHeaderStyles = stylesFactory((theme: GrafanaTheme, selected = false, editable: boolean) => {
|
|
const { sm } = theme.spacing;
|
|
return {
|
|
wrapper: cx(
|
|
css`
|
|
display: flex;
|
|
align-items: center;
|
|
font-size: ${theme.typography.size.base};
|
|
padding: 12px;
|
|
color: ${theme.colors.textWeak};
|
|
|
|
&:hover,
|
|
&.selected {
|
|
color: ${theme.colors.text};
|
|
}
|
|
|
|
&:hover {
|
|
a {
|
|
opacity: 1;
|
|
}
|
|
}
|
|
`,
|
|
'pointer',
|
|
{ selected }
|
|
),
|
|
icon: css`
|
|
padding: 0 ${sm} 0 ${editable ? 0 : sm};
|
|
`,
|
|
text: css`
|
|
flex-grow: 1;
|
|
line-height: 24px;
|
|
`,
|
|
link: css`
|
|
padding: 2px 10px 0;
|
|
color: ${theme.colors.textWeak};
|
|
opacity: 0;
|
|
transition: opacity 150ms ease-in-out;
|
|
`,
|
|
button: css`
|
|
margin-top: 3px;
|
|
`,
|
|
};
|
|
});
|