Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(table): add logic to paint free rows #105

Merged
merged 3 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions src/components/Table/Table.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const Table = ({
showDefaultFooter,
showPagination,
total,
paintFreeRowsColor,
...props
}) => {
const columnsData = Array.isArray(columns) ? columns : [];
Expand Down Expand Up @@ -114,11 +115,16 @@ const Table = ({
)}
{!isLoading && data.length > 0 && buildRows(data, columnsData).map(row => (
<Tr key={row?.key} {...row?.containerStyle} data-testid={`row-${row?.key}`}>
{columnsData.map(header => (
<Td key={`${row.key}-${header.key}`} {...row.style} {...header.tdStyle} >
{row[header.key]}
</Td>
))}
{columnsData.map(header => {
const isEmpty = row[header.key] == null || row[header.key] === '';
const rowsStyle = isEmpty && paintFreeRowsColor !== undefined
? {backgroundColor: `${paintFreeRowsColor}`} : (row.style || '');
return (
<Td key={`${row.key}-${header.key}`} {...rowsStyle} {...header.tdStyle}>
{row[header.key]}
</Td>
);
})}
</Tr>
))}
</Tbody>
Expand All @@ -140,6 +146,7 @@ const Table = ({
};

Table.propTypes = {
paintFreeRowsColor: PropTypes.string,
arielerv marked this conversation as resolved.
Show resolved Hide resolved
caption: PropTypes.string,
columns: PropTypes.arrayOf(PropTypes.shape({})).isRequired,
data: PropTypes.arrayOf(PropTypes.shape({})),
Expand All @@ -164,14 +171,15 @@ Table.defaultProps = {
emptyMessage: 'No hay resultados',
isLoading: false,
name: 'table',
onSearch: () => {},
onSearch: () => { },
onSort: undefined,
paginationStyles: undefined,
params: undefined,
perPage: 0,
showDefaultFooter: true,
showPagination: true,
total: 0
total: 0,
paintFreeRowsColor: undefined
};

export default Table;
28 changes: 28 additions & 0 deletions src/theme/components/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,34 @@ const table = {
textAlign: 'left',
padding: '10px 20px'
}
},
fixedFirstColumn: {
fontSize: '16px',
arielerv marked this conversation as resolved.
Show resolved Hide resolved
height: '35px',
table: {
background: 'white',
borderRadius: '0 0 10px 10px'
},
tr: {
'& th:first-of-type': {
position: 'sticky',
left: '0',
backgroundColor: 'white'
},
'&:nth-of-type(even) td:first-of-type ': {
backgroundColor: 'brand.neutral50'
},
'&:nth-of-type(odd) td:first-of-type ': {
backgroundColor: 'white'
}
},

arielerv marked this conversation as resolved.
Show resolved Hide resolved
td: {
'&:first-of-type': {
position: 'sticky',
left: '0'
}
}
}
}
};
Expand Down
Loading