Skip to content

Commit 330a797

Browse files
author
Hector Arce De Las Heras
committed
Improve hook to add background and align to cell and header for Table component
1 parent af14e20 commit 330a797

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/components/table/hooks/useContent.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,13 @@ interface IUseContentResponse {
2323
dividerValue: () => null | TableDividerType | unknown;
2424
getExpandedAria: () => string | undefined;
2525
getValue: (headerValue: ITableHeader) => string | JSX.Element | DividerContent;
26-
getBackgroundColorCellValue: (headerValue: ITableHeader) => string | undefined;
26+
getCellTokenValue: ({
27+
headerValue,
28+
token,
29+
}: {
30+
headerValue: ITableHeader;
31+
token: string;
32+
}) => string | undefined;
2733
handleShowExpandedContent: (value: boolean) => void;
2834
hasExpandedContentRow: boolean;
2935
hasFooter: boolean;
@@ -91,14 +97,20 @@ export const useContent = (props: IUseContent): IUseContentResponse => {
9197
return (cellValue as ValueConfigType).value as string | JSX.Element;
9298
};
9399

94-
const getBackgroundColorCellValue = (headerValue: ITableHeader): string | undefined => {
100+
const getCellTokenValue = ({
101+
headerValue,
102+
token,
103+
}: {
104+
headerValue: ITableHeader;
105+
token: string;
106+
}): string | undefined => {
95107
const cellValue = props.value[headerValue.id]
96108
? (props.value[headerValue.id] as string | JSX.Element | ValueConfigType)
97109
: '-';
98110
if (React.isValidElement(cellValue) || typeof cellValue === 'string') {
99111
return;
100112
}
101-
return (cellValue as ValueConfigType).backgroundColor;
113+
return (cellValue as ValueConfigType)[token];
102114
};
103115

104116
const hasExpandedContentRow = !!Object.getOwnPropertyDescriptor(props.value, 'expandedContent');
@@ -111,7 +123,7 @@ export const useContent = (props: IUseContent): IUseContentResponse => {
111123
dividerValue,
112124
getExpandedAria,
113125
getValue,
114-
getBackgroundColorCellValue,
126+
getCellTokenValue,
115127
handleShowExpandedContent,
116128
hasExpandedContentRow,
117129
hasFooter,

0 commit comments

Comments
 (0)