@@ -8,6 +8,7 @@ import { Text } from "src/components/typography"
88import { IconButton } from "src/components/button"
99import Tooltip from "src/components/drops/tooltip"
1010import useToggle from "src/hooks/use-toggle"
11+ import { useTableContext } from "../features/provider"
1112
1213//TODO heights in Table.Cell and Table.HeadCell needs to change and not be direct.
1314// the problem is when we are applying column pin the second table has different sizes
@@ -28,7 +29,8 @@ const StyledHeaderCell = styled(Box)`
2829 padding: 4px 8px;
2930 border-bottom: 1px solid ${ getColor ( "borderSecondary" ) } ;
3031 &:not(:last-child) {
31- border-right: 1px solid ${ getColor ( "borderSecondary" ) } ;
32+ border-right: 1px solid
33+ ${ ( { background, theme } ) => getColor ( background || "borderSecondary" ) ( { theme } ) } ;
3234 }
3335`
3436
@@ -59,7 +61,7 @@ Table.HeadRow = forwardRef(({ children, ...props }, ref) => (
5961 </ StyledHeaderRow >
6062) )
6163
62- Table . Resizer = ( { onMouseDown, onTouchStart, deltaOffset, getIsResizing } ) => {
64+ Table . Resizer = ( { onMouseDown, onTouchStart, deltaOffset, getIsResizing, background } ) => {
6365 if ( ! onMouseDown ) return
6466 const resizingProps = getIsResizing ( ) ? { transform : `translateX(${ deltaOffset } px)` } : { }
6567
@@ -87,7 +89,7 @@ Table.Resizer = ({ onMouseDown, onTouchStart, deltaOffset, getIsResizing }) => {
8789 } }
8890 onMouseDown = { onMouseDown }
8991 onTouchStart = { onTouchStart }
90- background = "borderSecondary"
92+ background = { background || "borderSecondary" }
9193 position = "absolute"
9294 top = { 0 }
9395 right = { 0 }
@@ -99,9 +101,11 @@ Table.Resizer = ({ onMouseDown, onTouchStart, deltaOffset, getIsResizing }) => {
99101Table . HeadCell = forwardRef (
100102 (
101103 {
104+ id,
102105 children,
103106 align = "left" ,
104107 width,
108+ minWidth,
105109 tooltipText,
106110 filter,
107111 onMouseDown,
@@ -113,41 +117,48 @@ Table.HeadCell = forwardRef(
113117 ...props
114118 } ,
115119 ref
116- ) => (
117- < StyledHeaderCell
118- as = "th"
119- ref = { ref }
120- sx = { {
121- textAlign : align ,
122- fontSize : "14px" ,
123- height : "60px" ,
124- position : "sticky" ,
125- top : 0 ,
126- ...styles ,
127- ...headStyles ,
128- } }
129- width = { `${ width } px` }
130- { ...props }
131- >
132- < Flex >
133- { children }
134- < Box sx = { { marginLeft : "auto" } } position = "relative" top = { 0 } >
135- { tooltipText && (
136- < Tooltip align = "bottom" content = { tooltipText } >
137- < Icon color = "nodeBadgeColor" size = "small" name = "information" />
138- </ Tooltip >
139- ) }
140- </ Box >
141- </ Flex >
142- < Box sx = { { fontWeight : "normal" } } > { filter } </ Box >
143- < Table . Resizer
144- onMouseDown = { onMouseDown }
145- onTouchStart = { onTouchStart }
146- getIsResizing = { getIsResizing }
147- deltaOffset = { deltaOffset }
148- />
149- </ StyledHeaderCell >
150- )
120+ ) => {
121+ const { hoveredColumn, onHover } = useTableContext ( )
122+ const isHovering = id === hoveredColumn
123+
124+ return (
125+ < StyledHeaderCell
126+ as = "th"
127+ ref = { ref }
128+ sx = { {
129+ textAlign : align ,
130+ fontSize : "14px" ,
131+ height : "60px" ,
132+ ...styles ,
133+ ...headStyles ,
134+ } }
135+ width = { { min : `${ minWidth } px` , max : `${ width } px` } }
136+ onMouseEnter = { ( ) => onHover ( { row : null , column : id } ) }
137+ onMouseLeave = { ( ) => onHover ( ) }
138+ { ...props }
139+ background = { ! props . background && isHovering ? "borderSecondary" : props . background }
140+ >
141+ < Flex >
142+ { children }
143+ < Box position = "absolute" top = { 0.5 } right = { 0.5 } width = { 4 } height = { 4 } >
144+ { tooltipText && (
145+ < Tooltip align = "bottom" content = { tooltipText } >
146+ < Icon color = "nodeBadgeColor" size = "small" name = "information" />
147+ </ Tooltip >
148+ ) }
149+ </ Box >
150+ </ Flex >
151+ < Box sx = { { fontWeight : "normal" } } > { filter } </ Box >
152+ < Table . Resizer
153+ onMouseDown = { onMouseDown }
154+ onTouchStart = { onTouchStart }
155+ getIsResizing = { getIsResizing }
156+ deltaOffset = { deltaOffset }
157+ background = { props . background }
158+ />
159+ </ StyledHeaderCell >
160+ )
161+ }
151162)
152163
153164const sortingIcons = {
@@ -196,13 +207,13 @@ Table.SortingHeadCell = forwardRef(
196207 align = { align }
197208 ref = { ref }
198209 data-testid = { dataTestid }
199- maxWidth = { maxWidth }
200- width = { width }
210+ width = { width || maxWidth }
201211 minWidth = { minWidth }
202212 tooltipText = { tooltipText }
203213 headStyles = { headStyles }
204214 { ...props }
205215 filter = { filter }
216+ { ...( ! ! sortDirection && { background : "successBackground" } ) }
206217 >
207218 < Box
208219 onMouseEnter = { onMouseEnter }
@@ -212,14 +223,20 @@ Table.SortingHeadCell = forwardRef(
212223 cursor = "pointer"
213224 data-testid = { sortbyTestid }
214225 >
215- < Flex data-testid = "sorting-cell-children-sorting-arrows-wrapper" gap = { 1 } >
226+ < Flex
227+ position = "relative"
228+ data-testid = "sorting-cell-children-sorting-arrows-wrapper"
229+ gap = { 1 }
230+ >
216231 { children }
217- < Icon
218- height = "16px"
219- width = "16px"
220- color = { showHoveringIcon ? "textLite" : "text" }
221- name = { sortingIcons [ showHoveringIcon ? "indicator" : sortDirection ] ?? null }
222- />
232+ < Box position = "absolute" top = { 1 } right = { - 12 } >
233+ < Icon
234+ height = "16px"
235+ width = "16px"
236+ color = { showHoveringIcon ? "textLite" : "text" }
237+ name = { sortingIcons [ showHoveringIcon ? "indicator" : sortDirection ] ?? null }
238+ />
239+ </ Box >
223240 </ Flex >
224241 </ Box >
225242 </ Table . HeadCell >
@@ -245,6 +262,9 @@ Table.Cell = forwardRef(
245262 pinnedStyles = { } ,
246263 styles = { } ,
247264 width,
265+ isColumnHovering,
266+ isRowHovering,
267+ index,
248268 ...rest
249269 } ,
250270 ref
@@ -254,6 +274,7 @@ Table.Cell = forwardRef(
254274 if ( rest . stopPropagation ) e . stopPropagation ( )
255275 onClick ?. ( )
256276 }
277+
257278 return (
258279 < Box
259280 as = "td"
@@ -269,9 +290,21 @@ Table.Cell = forwardRef(
269290 ...pinnedStyles ,
270291 ...styles ,
271292 } }
272- width = { { max : `${ maxWidth } px` , base : ` ${ width } px`, min : `${ minWidth } px` } }
293+ width = { { max : `${ width || maxWidth } px` , min : `${ minWidth } px` } }
273294 overflow = "hidden"
274295 { ...rest }
296+ background = {
297+ ! rest . background && ( isColumnHovering || isRowHovering )
298+ ? "borderSecondary"
299+ : rest . background || ( index % 2 == 0 ? "mainBackground" : "tableRowBg" )
300+ }
301+ backgroundOpacity = {
302+ isColumnHovering && isRowHovering
303+ ? rest . backgroundOpacity
304+ ? rest . backgroundOpacity + 0.2
305+ : 1
306+ : rest . backgroundOpacity || 0.7
307+ }
275308 >
276309 { children }
277310 </ Box >
@@ -280,10 +313,7 @@ Table.Cell = forwardRef(
280313)
281314
282315Table . Row = forwardRef (
283- (
284- { children, onClick, disableClickRow, onMouseEnter, onMouseLeave, isHovering, ...props } ,
285- ref
286- ) => {
316+ ( { children, onClick, disableClickRow, onMouseEnter, onMouseLeave, ...props } , ref ) => {
287317 const isRowDisabledForClick = disableClickRow && disableClickRow ( )
288318 const handleClick = e => {
289319 if ( isRowDisabledForClick ) return
@@ -308,13 +338,11 @@ Table.Row = forwardRef(
308338 onMouseEnter = { handleMouseEnter }
309339 onMouseLeave = { handleMouseLeave }
310340 as = { StyledRow }
311- _hover = { isHovering && isRowClickable && { background : "borderSecondary" } }
312341 cursor = { cursor }
313342 isClickable = { ! ! onClick }
314343 onClick = { handleClick }
315344 ref = { ref }
316345 { ...props }
317- data-hover = { isHovering ? "" : undefined }
318346 >
319347 { children }
320348 </ Box >
0 commit comments