Skip to content
This repository has been archived by the owner on Dec 13, 2020. It is now read-only.

Commit

Permalink
- handle widgetType Color in table cells #1603
Browse files Browse the repository at this point in the history
  • Loading branch information
siemiatj committed Apr 25, 2018
1 parent 5ede33e commit 56fbc2a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/components/table/TableCell.js
Expand Up @@ -8,6 +8,7 @@ import MasterWidget from '../widget/MasterWidget';
import {
AMOUNT_FIELD_TYPES,
AMOUNT_FIELD_FORMATS_BY_PRECISION,
SPECIAL_FIELD_TYPES,
DATE_FIELD_TYPES,
DATE_FIELD_FORMATS,
} from '../../constants/Constants';
Expand Down Expand Up @@ -40,6 +41,19 @@ class TableCell extends PureComponent {
}
};

static createSpecialField = (fieldType, fieldValue) => {
switch (fieldType) {
case 'Color': {
const style = {
backgroundColor: fieldValue,
};
return <span className="widget-color-display" style={style} />;
}
default:
return fieldValue;
}
};

static fieldValueToString = (
fieldValue,
fieldType = 'Text',
Expand Down Expand Up @@ -73,6 +87,8 @@ class TableCell extends PureComponent {
return TableCell.createDate(fieldValue, fieldType);
} else if (AMOUNT_FIELD_TYPES.includes(fieldType)) {
return TableCell.createAmount(fieldValue, precision);
} else if (SPECIAL_FIELD_TYPES.includes(fieldType)) {
return TableCell.createSpecialField(fieldType, fieldValue);
}
return fieldValue;
}
Expand Down Expand Up @@ -208,9 +224,13 @@ class TableCell extends PureComponent {
/>
) : (
<div
className="cell-text-wrapper"
className={classnames('cell-text-wrapper', {
[`${item.widgetType}-cell`]: item.widgetType,
})}
title={
item.widgetType === 'YesNo' || item.widgetType === 'Switch'
item.widgetType === 'YesNo' ||
item.widgetType === 'Switch' ||
item.widgetType === 'Color'
? ''
: tdValue
}
Expand Down
1 change: 1 addition & 0 deletions src/constants/Constants.js
Expand Up @@ -14,6 +14,7 @@ export const AMOUNT_FIELD_FORMATS_BY_PRECISION = [
'0,0.0000[0]',
'0,0.00000',
];
export const SPECIAL_FIELD_TYPES = ['Color'];
export const DATE_FIELD_TYPES = ['Date', 'DateTime', 'Time'];
export const DATE_FIELD_FORMATS = {
Date: 'l',
Expand Down

0 comments on commit 56fbc2a

Please sign in to comment.