@stokr/components-library 2.3.65-beta.7 → 2.3.65-beta.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -18,6 +18,31 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
18
18
  function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
19
19
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
20
20
  function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
21
+ // Interactive elements that should NOT trigger row click
22
+ const INTERACTIVE_ELEMENTS = ['button', 'a', 'input', 'select', 'textarea', 'label'];
23
+
24
+ // Check if an element or its parents are interactive
25
+ const isInteractiveElement = element => {
26
+ let current = element;
27
+ while (current && current.tagName !== 'TR') {
28
+ var _current$tagName, _current$getAttribute, _current, _current$dataset;
29
+ const tagName = (_current$tagName = current.tagName) === null || _current$tagName === void 0 ? void 0 : _current$tagName.toLowerCase();
30
+ if (INTERACTIVE_ELEMENTS.includes(tagName)) {
31
+ return true;
32
+ }
33
+ // Check for role="button" or other interactive roles
34
+ const role = (_current$getAttribute = (_current = current).getAttribute) === null || _current$getAttribute === void 0 ? void 0 : _current$getAttribute.call(_current, 'role');
35
+ if (role === 'button' || role === 'link') {
36
+ return true;
37
+ }
38
+ // Check for data-clickable attribute (escape hatch for custom interactive elements)
39
+ if (((_current$dataset = current.dataset) === null || _current$dataset === void 0 ? void 0 : _current$dataset.clickable) === 'true') {
40
+ return true;
41
+ }
42
+ current = current.parentElement;
43
+ }
44
+ return false;
45
+ };
21
46
  function ReactTable(props) {
22
47
  const {
23
48
  columns,
@@ -37,6 +62,19 @@ function ReactTable(props) {
37
62
  getRowDataCy,
38
63
  // Function to generate data-cy attribute: (rowData, rowIndex) => string
39
64
 
65
+ // Row click handler: (rowData, rowIndex, event) => void
66
+ // Will NOT trigger if clicking on buttons, links, inputs, etc.
67
+ onRowClick,
68
+ // Custom expanded content renderer: (row, toggleExpanded) => ReactNode
69
+ // If provided, this will be used instead of the sub-table
70
+ renderExpandedContent,
71
+ // Header click handler: (column, event) => void
72
+ // Called when a header cell is clicked (useful for sorting/filtering)
73
+ // Won't trigger if clicking on interactive elements inside header
74
+ onHeaderClick,
75
+ // Render custom header content: (column, defaultContent) => ReactNode
76
+ // Allows wrapping/replacing header content (e.g., add sort icons, dropdowns)
77
+ renderHeaderContent,
40
78
  //instead of passing the subData, we pass a function that will calculate the subData
41
79
  //subData must be part of the data array (an array or whatever)
42
80
  //calculateSubData is a function that receives the row and returns the subData
@@ -75,6 +113,17 @@ function ReactTable(props) {
75
113
  setInputPageSize(pageSize);
76
114
  }, [pageSize]);
77
115
 
116
+ // Handle row click with interactive element detection
117
+ const handleRowClick = (0, _react.useCallback)((row, rowIndex, event) => {
118
+ if (!onRowClick) return;
119
+
120
+ // Don't trigger if clicking on interactive elements
121
+ if (isInteractiveElement(event.target)) {
122
+ return;
123
+ }
124
+ onRowClick(row.original, rowIndex, event);
125
+ }, [onRowClick]);
126
+
78
127
  // Function to render cell content with hover support
79
128
  const renderCellContent = (cell, rowIndex, rowData) => {
80
129
  if (customRowHoverContent && hoveredRowIndex === rowIndex) {
@@ -85,21 +134,65 @@ function ReactTable(props) {
85
134
  }
86
135
  return cell.render('Cell');
87
136
  };
137
+
138
+ // Determine if row should have expand functionality
139
+ const shouldEnableExpand = withSubTable || renderExpandedContent;
140
+
141
+ // Handle header click with interactive element detection
142
+ const handleHeaderClick = (0, _react.useCallback)((column, event) => {
143
+ // Check for column-level click handler first
144
+ if (column.onHeaderClick) {
145
+ // Don't trigger if clicking on interactive elements
146
+ if (!isInteractiveElement(event.target)) {
147
+ column.onHeaderClick(column, event);
148
+ }
149
+ return;
150
+ }
151
+
152
+ // Fall back to global onHeaderClick
153
+ if (!onHeaderClick) return;
154
+
155
+ // Don't trigger if clicking on interactive elements inside header
156
+ if (isInteractiveElement(event.target)) {
157
+ return;
158
+ }
159
+ onHeaderClick(column, event);
160
+ }, [onHeaderClick]);
161
+
162
+ // Render header content with optional custom rendering
163
+ const renderHeader = column => {
164
+ const defaultContent = column.render('Header');
165
+
166
+ // If renderHeaderContent is provided, use it to wrap/modify the header
167
+ if (renderHeaderContent) {
168
+ return renderHeaderContent(column, defaultContent);
169
+ }
170
+ return defaultContent;
171
+ };
172
+
173
+ // Check if header should be clickable
174
+ const isHeaderClickable = column => {
175
+ return column.onHeaderClick || onHeaderClick;
176
+ };
88
177
  return /*#__PURE__*/_react.default.createElement(_Table.Styles, null, /*#__PURE__*/_react.default.createElement(_Table.TableWrap, {
89
178
  style: tableWrapStyles
90
179
  }, /*#__PURE__*/_react.default.createElement(_Table.StyledReactTable, _extends({}, getTableProps(), {
91
180
  customTableStyles: customTableStyles
92
181
  }), /*#__PURE__*/_react.default.createElement("thead", null, headerGroups.map(headerGroup => /*#__PURE__*/_react.default.createElement(_Table.StyledReactTable.Tr, headerGroup.getHeaderGroupProps(), headerGroup.headers.map(column => {
93
182
  const cellStyles = customThStyles ? customThStyles(column) : {};
183
+ const clickable = isHeaderClickable(column);
94
184
  return /*#__PURE__*/_react.default.createElement(_Table.StyledReactTable.Th, _extends({}, column.getHeaderProps({
95
185
  className: column.collapse ? 'collapse' : '',
96
- style: _objectSpread({}, cellStyles)
186
+ style: _objectSpread(_objectSpread({}, cellStyles), clickable ? {
187
+ cursor: 'pointer'
188
+ } : {})
97
189
  }), {
98
190
  blue: blue,
99
191
  width: column.width,
100
192
  minWidth: column.minWidth,
101
- maxWidth: column.maxWidth
102
- }), column.render('Header'));
193
+ maxWidth: column.maxWidth,
194
+ onClick: clickable ? e => handleHeaderClick(column, e) : undefined
195
+ }), renderHeader(column));
103
196
  })))), /*#__PURE__*/_react.default.createElement("tbody", getTableBodyProps(), page.map((row, i) => {
104
197
  prepareRow(row);
105
198
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, {
@@ -112,10 +205,17 @@ function ReactTable(props) {
112
205
  rowIndex: i,
113
206
  rowData: row.original,
114
207
  onMouseEnter: () => setHoveredRowIndex(i),
115
- onMouseLeave: () => setHoveredRowIndex(null)
208
+ onMouseLeave: () => setHoveredRowIndex(null),
209
+ onClick: e => handleRowClick(row, i, e),
210
+ style: onRowClick ? {
211
+ cursor: 'pointer'
212
+ } : undefined
116
213
  }), row.cells.map(cell => {
117
214
  const cellStyles = customTdStyles ? customTdStyles(i, row.original, cell.column) : {};
118
- return /*#__PURE__*/_react.default.createElement(_Table.StyledReactTable.Td, _extends({}, cell.row.getToggleRowExpandedProps(), {
215
+
216
+ // Only apply expand toggle props if expansion is enabled
217
+ const expandProps = shouldEnableExpand ? cell.row.getToggleRowExpandedProps() : {};
218
+ return /*#__PURE__*/_react.default.createElement(_Table.StyledReactTable.Td, _extends({}, expandProps, {
119
219
  title: ""
120
220
  }, cell.getCellProps({
121
221
  className: cell.column.collapse ? 'collapse' : '',
@@ -126,7 +226,12 @@ function ReactTable(props) {
126
226
  minWidth: cell.column.minWidth,
127
227
  maxWidth: cell.column.maxWidth
128
228
  }), renderCellContent(cell, i, row.original));
129
- })), withSubTable && row.isExpanded && /*#__PURE__*/_react.default.createElement(_Table.StyledReactTable.Tr, {
229
+ })), renderExpandedContent && row.isExpanded && /*#__PURE__*/_react.default.createElement(_Table.StyledReactTable.Tr, {
230
+ key: "".concat(row.id, "-expanded")
231
+ }, /*#__PURE__*/_react.default.createElement(_Table.StyledReactTable.Td, {
232
+ colSpan: visibleColumns.length,
233
+ subTable: true
234
+ }, renderExpandedContent(row, row.toggleRowExpanded))), withSubTable && !renderExpandedContent && row.isExpanded && /*#__PURE__*/_react.default.createElement(_Table.StyledReactTable.Tr, {
130
235
  key: "".concat(row.id, "-").concat(i)
131
236
  }, /*#__PURE__*/_react.default.createElement(_Table.StyledReactTable.Td, {
132
237
  colSpan: visibleColumns.length,
@@ -160,7 +265,18 @@ ReactTable.propTypes = {
160
265
  customRowHoverContent: _propTypes.default.func,
161
266
  customRowStyles: _propTypes.default.func,
162
267
  customTableStyles: _propTypes.default.func,
163
- getRowDataCy: _propTypes.default.func // (rowData, rowIndex) => string
268
+ tableWrapStyles: _propTypes.default.object,
269
+ customTdStyles: _propTypes.default.func,
270
+ customThStyles: _propTypes.default.func,
271
+ getRowDataCy: _propTypes.default.func,
272
+ // (rowData, rowIndex) => string
273
+ onRowClick: _propTypes.default.func,
274
+ // (rowData, rowIndex, event) => void
275
+ renderExpandedContent: _propTypes.default.func,
276
+ // (row, toggleExpanded) => ReactNode
277
+ onHeaderClick: _propTypes.default.func,
278
+ // (column, event) => void
279
+ renderHeaderContent: _propTypes.default.func // (column, defaultContent) => ReactNode
164
280
  };
165
281
  ReactTable.defaultProps = {
166
282
  blue: false,