mirror of https://github.com/grafana/grafana
ReactTable: adds color text to field options (#23427)
* Feature: adds text color field config * Refactor: created an extension point * Refactor: uses HOC for extension instead * Fix: fixes background styling from affecting cells without display.colorpull/23458/head
parent
d257e661cd
commit
d36397e7bd
@ -1,33 +0,0 @@ |
||||
import React, { CSSProperties, FC } from 'react'; |
||||
import { TableCellProps } from './types'; |
||||
import tinycolor from 'tinycolor2'; |
||||
import { formattedValueToString } from '@grafana/data'; |
||||
|
||||
export const BackgroundColoredCell: FC<TableCellProps> = props => { |
||||
const { cell, tableStyles, field } = props; |
||||
|
||||
if (!field.display) { |
||||
return null; |
||||
} |
||||
|
||||
const themeFactor = tableStyles.theme.isDark ? 1 : -0.7; |
||||
const displayValue = field.display(cell.value); |
||||
|
||||
const bgColor2 = tinycolor(displayValue.color) |
||||
.darken(10 * themeFactor) |
||||
.spin(5) |
||||
.toRgbString(); |
||||
|
||||
const styles: CSSProperties = { |
||||
background: `linear-gradient(120deg, ${bgColor2}, ${displayValue.color})`, |
||||
color: 'white', |
||||
height: tableStyles.cellHeight, |
||||
padding: tableStyles.cellPadding, |
||||
}; |
||||
|
||||
return ( |
||||
<div className={tableStyles.tableCell} style={styles}> |
||||
{formattedValueToString(displayValue)} |
||||
</div> |
||||
); |
||||
}; |
@ -0,0 +1,14 @@ |
||||
import { CellComponent, TableCellProps } from './types'; |
||||
import { TableStyles } from './styles'; |
||||
|
||||
export const withTableStyles = ( |
||||
CellComponent: CellComponent, |
||||
getExtendedStyles: (props: TableCellProps) => TableStyles |
||||
): CellComponent => { |
||||
function WithTableStyles(props: TableCellProps) { |
||||
return CellComponent({ ...props, tableStyles: getExtendedStyles(props) }); |
||||
} |
||||
|
||||
WithTableStyles.displayName = CellComponent.displayName || CellComponent.name; |
||||
return WithTableStyles; |
||||
}; |
Loading…
Reference in new issue