mirror of
https://github.com/grafana/grafana.git
synced 2024-11-24 09:50:29 -06:00
TablePanel: Improve and align table styles with rest of Grafana
This commit is contained in:
parent
0e7c95a4d2
commit
1e28ee41cc
@ -21,7 +21,7 @@ export const HeaderRow = (props: HeaderRowProps) => {
|
||||
const tableStyles = useStyles2(getTableStyles);
|
||||
|
||||
return (
|
||||
<div role="rowgroup">
|
||||
<div role="rowgroup" className={tableStyles.headerRow}>
|
||||
{headerGroups.map((headerGroup: HeaderGroup) => {
|
||||
const { key, ...headerGroupProps } = headerGroup.getHeaderGroupProps();
|
||||
return (
|
||||
@ -62,9 +62,12 @@ function renderHeaderCell(column: any, tableStyles: TableStyles, showTypeIcons?:
|
||||
<Icon name={getFieldTypeIcon(field)} title={field?.type} size="sm" className={tableStyles.typeIcon} />
|
||||
)}
|
||||
<div>{column.render('Header')}</div>
|
||||
<div>
|
||||
{column.isSorted && (column.isSortedDesc ? <Icon name="arrow-down" /> : <Icon name="arrow-up" />)}
|
||||
</div>
|
||||
{column.isSorted &&
|
||||
(column.isSortedDesc ? (
|
||||
<Icon size="lg" name="arrow-down" className={tableStyles.sortIcon} />
|
||||
) : (
|
||||
<Icon name="arrow-up" size="lg" className={tableStyles.sortIcon} />
|
||||
))}
|
||||
</button>
|
||||
{column.canFilter && <Filter column={column} tableStyles={tableStyles} field={field} />}
|
||||
</>
|
||||
|
@ -150,7 +150,7 @@ export const Table = memo((props: Props) => {
|
||||
const variableSizeListScrollbarRef = useRef<HTMLDivElement>(null);
|
||||
const tableStyles = useStyles2(getTableStyles);
|
||||
const theme = useTheme2();
|
||||
const headerHeight = noHeader ? 0 : tableStyles.cellHeight;
|
||||
const headerHeight = noHeader ? 0 : tableStyles.rowHeight;
|
||||
const [footerItems, setFooterItems] = useState<FooterItem[] | undefined>(footerValues);
|
||||
const [expandedIndexes, setExpandedIndexes] = useState<Set<number>>(new Set());
|
||||
const prevExpandedIndexes = usePrevious(expandedIndexes);
|
||||
@ -288,7 +288,9 @@ export const Table = memo((props: Props) => {
|
||||
if (enablePagination) {
|
||||
listHeight -= tableStyles.cellHeight;
|
||||
}
|
||||
const pageSize = Math.round(listHeight / tableStyles.cellHeight) - 1;
|
||||
|
||||
const pageSize = Math.round(listHeight / tableStyles.rowHeight) - 1;
|
||||
|
||||
useEffect(() => {
|
||||
// Don't update the page size if it is less than 1
|
||||
if (pageSize <= 0) {
|
||||
|
@ -3,8 +3,7 @@ import { css, CSSObject } from '@emotion/css';
|
||||
import { GrafanaTheme2 } from '@grafana/data';
|
||||
|
||||
export const getTableStyles = (theme: GrafanaTheme2) => {
|
||||
const { colors } = theme;
|
||||
const headerBg = theme.colors.background.secondary;
|
||||
const footerBg = theme.colors.background.secondary;
|
||||
const borderColor = theme.colors.border.weak;
|
||||
const resizerColor = theme.colors.primary.border;
|
||||
const cellPadding = 6;
|
||||
@ -107,10 +106,9 @@ export const getTableStyles = (theme: GrafanaTheme2) => {
|
||||
`,
|
||||
thead: css`
|
||||
label: thead;
|
||||
height: ${cellHeight}px;
|
||||
height: ${rowHeight}px;
|
||||
overflow-y: auto;
|
||||
overflow-x: hidden;
|
||||
background: ${headerBg};
|
||||
position: relative;
|
||||
`,
|
||||
tfoot: css`
|
||||
@ -118,15 +116,17 @@ export const getTableStyles = (theme: GrafanaTheme2) => {
|
||||
height: ${cellHeight}px;
|
||||
overflow-y: auto;
|
||||
overflow-x: hidden;
|
||||
background: ${headerBg};
|
||||
background: ${footerBg};
|
||||
position: relative;
|
||||
`,
|
||||
headerRow: css`
|
||||
label: row;
|
||||
border-bottom: 1px solid ${borderColor};
|
||||
`,
|
||||
headerCell: css`
|
||||
padding: ${cellPadding}px;
|
||||
overflow: hidden;
|
||||
white-space: nowrap;
|
||||
color: ${colors.primary.text};
|
||||
border-right: 1px solid ${theme.colors.border.weak};
|
||||
display: flex;
|
||||
|
||||
&:last-child {
|
||||
@ -141,8 +141,15 @@ export const getTableStyles = (theme: GrafanaTheme2) => {
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
font-weight: ${theme.typography.fontWeightMedium};
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin-right: ${theme.spacing(0.5)};
|
||||
|
||||
&:hover {
|
||||
text-decoration: underline;
|
||||
color: ${theme.colors.text.link};
|
||||
}
|
||||
`,
|
||||
cellContainer: buildCellContainerStyle(undefined, undefined, true),
|
||||
cellContainerNoOverflow: buildCellContainerStyle(undefined, undefined, false),
|
||||
@ -152,6 +159,9 @@ export const getTableStyles = (theme: GrafanaTheme2) => {
|
||||
user-select: text;
|
||||
white-space: nowrap;
|
||||
`,
|
||||
sortIcon: css`
|
||||
margin-left: ${theme.spacing(0.5)};
|
||||
`,
|
||||
cellLink: css`
|
||||
cursor: pointer;
|
||||
overflow: hidden;
|
||||
@ -173,12 +183,10 @@ export const getTableStyles = (theme: GrafanaTheme2) => {
|
||||
`,
|
||||
paginationWrapper: css`
|
||||
display: flex;
|
||||
background: ${headerBg};
|
||||
height: ${cellHeight}px;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
border-top: 1px solid ${theme.colors.border.weak};
|
||||
li {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
@ -20,7 +20,6 @@ const footerCategory = 'Table footer';
|
||||
export const plugin = new PanelPlugin<PanelOptions, TableFieldOptions>(TablePanel)
|
||||
.setPanelChangeHandler(tablePanelChangedHandler)
|
||||
.setMigrationHandler(tableMigrationHandler)
|
||||
.setNoPadding()
|
||||
.useFieldConfig({
|
||||
useCustomConfig: (builder) => {
|
||||
builder
|
||||
|
Loading…
Reference in New Issue
Block a user