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

Add hover handlers for TableWidget #907

Merged
merged 3 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Not released

- Support for `onRowMouseEnter` and `onRowMouseLeave` handlers for Table Widget [#907](https://github.com/CartoDB/carto-react/pull/907)

## 3.0.0

### 3.0.0-alpha.19 (2024-09-19)
Expand Down
22 changes: 20 additions & 2 deletions packages/react-ui/src/widgets/TableWidgetUI/TableWidgetUI.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ function TableWidgetUI({
rowsPerPageOptions,
onSetRowsPerPage,
onRowClick,
onRowMouseEnter,
onRowMouseLeave,
height,
dense,
isLoading,
Expand Down Expand Up @@ -126,7 +128,13 @@ function TableWidgetUI({
sortDirection={sortDirection}
onSort={handleSort}
/>
<TableBodyComponent columns={columns} rows={rows} onRowClick={onRowClick} />
<TableBodyComponent
columns={columns}
rows={rows}
onRowMouseEnter={onRowMouseEnter}
onRowMouseLeave={onRowMouseLeave}
onRowClick={onRowClick}
/>
</Table>
</TableContainer>
{pagination && (
Expand Down Expand Up @@ -182,7 +190,13 @@ function TableHeaderComponent({ columns, sorting, sortBy, sortDirection, onSort
);
}

function TableBodyComponent({ columns, rows, onRowClick }) {
function TableBodyComponent({
columns,
rows,
onRowMouseEnter,
onRowMouseLeave,
onRowClick
}) {
return (
<TableBody>
{rows.map((row, i) => {
Expand All @@ -192,6 +206,8 @@ function TableBodyComponent({ columns, rows, onRowClick }) {
<TableRowStyled
key={rowKey}
hover={!!onRowClick}
onMouseEnter={() => onRowMouseEnter && onRowMouseEnter(row)}
onMouseLeave={() => onRowMouseLeave && onRowMouseLeave(row)}
onClick={() => onRowClick && onRowClick(row)}
>
{columns.map(({ field, headerName, align, component, formatter }) => {
Expand Down Expand Up @@ -253,6 +269,8 @@ TableWidgetUI.propTypes = {
rowsPerPageOptions: PropTypes.array,
onSetRowsPerPage: PropTypes.func,
onRowClick: PropTypes.func,
onRowMouseEnter: PropTypes.func,
onRowMouseLeave: PropTypes.func,
height: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
dense: PropTypes.bool,
isLoading: PropTypes.bool,
Expand Down
8 changes: 8 additions & 0 deletions packages/react-widgets/src/widgets/TableWidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import { _FeatureFlags, _hasFeatureFlag } from '@carto/react-core';
* @param {string} props.dataSource - ID of the data source to get the data from.
* @param {Column[]} props.columns - List of data columns to display.
* @param {Column[]} props.hiddenColumnFields - List of data columns to be retrieved, but not displayed.
* @param {Function=} props.onRowMouseEnter - Function to handle on mouse enter events on rows.
* @param {Function=} props.onRowMouseLeave - Function to handle on mouse leave events on rows.
* @param {Function=} props.onRowClick - Function to handle on click events on rows.
* @param {Function=} [props.onError] - Function to handle error messages from the widget.
* @param {Function=} [props.onStateChange] - Callback to handle state updates of widgets
Expand Down Expand Up @@ -42,6 +44,8 @@ function TableWidget({
onError,
onStateChange,
onRowClick,
onRowMouseEnter,
onRowMouseLeave,
initialPageSize = 10,
onPageSizeChange,
global,
Expand Down Expand Up @@ -132,6 +136,8 @@ function TableWidget({
height={height}
dense={dense}
isLoading={isLoading}
onRowMouseEnter={onRowMouseEnter}
onRowMouseLeave={onRowMouseLeave}
onRowClick={onRowClick}
/>
)}
Expand Down Expand Up @@ -160,6 +166,8 @@ TableWidget.propTypes = {
height: PropTypes.string,
stableHeight: PropTypes.bool,
dense: PropTypes.bool,
onRowMouseEnter: PropTypes.func,
onRowMouseLeave: PropTypes.func,
searchText: PropTypes.string,
searchColumn: PropTypes.string,
// Internal state
Expand Down
Loading