1
+ import clsx from 'clsx' ;
1
2
import { useState , type MouseEvent } from 'react' ;
2
- import {
3
- ActionIcon ,
4
- Box ,
5
- Transition ,
6
- Tooltip ,
7
- Popover ,
8
- useMantineTheme ,
9
- } from '@mantine/core' ;
10
- import { MRT_TableHeadCellFilterContainer } from './MRT_TableHeadCellFilterContainer' ;
3
+ import { ActionIcon , Box , Popover , Tooltip , Transition } from '@mantine/core' ;
4
+
11
5
import { type MRT_Header , type MRT_TableInstance } from '../types' ;
12
- import { getPrimaryColor } from '../column.utils' ;
6
+ import { localizedFilterOption } from '../filterFns' ;
7
+ import { MRT_TableHeadCellFilterContainer } from './MRT_TableHeadCellFilterContainer' ;
8
+
13
9
import classes from './MRT_TableHeadCellFilterLabel.module.css' ;
14
10
15
11
interface Props < TData extends Record < string , any > = { } > {
@@ -35,8 +31,6 @@ export const MRT_TableHeadCellFilterLabel = <
35
31
const { column } = header ;
36
32
const { columnDef } = column ;
37
33
38
- const theme = useMantineTheme ( ) ;
39
-
40
34
const filterValue = column . getFilterValue ( ) ;
41
35
42
36
const [ popoverOpened , setPopoverOpened ] = useState ( false ) ;
@@ -61,13 +55,7 @@ export const MRT_TableHeadCellFilterLabel = <
61
55
. replace ( '{column}' , String ( columnDef . header ) )
62
56
. replace (
63
57
'{filterType}' ,
64
- // @ts -ignore
65
- localization [
66
- `filter${
67
- currentFilterOption ?. charAt ( 0 ) ?. toUpperCase ( ) +
68
- currentFilterOption ?. slice ( 1 )
69
- } `
70
- ] ,
58
+ localizedFilterOption ( localization , currentFilterOption ) ,
71
59
)
72
60
. replace (
73
61
'{filterValue}' ,
@@ -100,8 +88,8 @@ export const MRT_TableHeadCellFilterLabel = <
100
88
( ! ! column . getFilterValue ( ) ?. [ 0 ] || ! ! column . getFilterValue ( ) ?. [ 1 ] ) )
101
89
}
102
90
>
103
- { ( style ) => (
104
- < Box component = "span" style = { { ... style , flex : '0 0' } } >
91
+ { ( ) => (
92
+ < Box component = "span" >
105
93
< Popover . Target >
106
94
< Tooltip
107
95
disabled = { popoverOpened }
@@ -111,8 +99,13 @@ export const MRT_TableHeadCellFilterLabel = <
111
99
withinPortal
112
100
>
113
101
< ActionIcon
102
+ size = "sm"
114
103
variant = "transparent"
115
- color = { isFilterActive ? getPrimaryColor ( theme ) : 'gray' }
104
+ className = { clsx (
105
+ 'mrt-table-head-cell-filter-label-icon' ,
106
+ classes . root ,
107
+ isFilterActive && classes . active ,
108
+ ) }
116
109
onClick = { ( event : MouseEvent < HTMLButtonElement > ) => {
117
110
event . stopPropagation ( ) ;
118
111
if ( columnFilterDisplayMode === 'popover' ) {
@@ -121,15 +114,11 @@ export const MRT_TableHeadCellFilterLabel = <
121
114
setShowColumnFilters ( true ) ;
122
115
}
123
116
setTimeout ( ( ) => {
124
- filterInputRefs . current [ `${ column . id } -0` ] ?. focus ( ) ;
125
- filterInputRefs . current [ `${ column . id } -0` ] ?. select ( ) ;
117
+ const input = filterInputRefs . current [ `${ column . id } -0` ] ;
118
+ input ?. focus ( ) ;
119
+ input ?. select ( ) ;
126
120
} , 100 ) ;
127
121
} }
128
- size = "sm"
129
- className = { classes . MRT_TableHeadCellFilterLabelActionIcon }
130
- __vars = { {
131
- '--opacity' : isFilterActive ? '1' : '0.5' ,
132
- } }
133
122
>
134
123
< IconFilter />
135
124
</ ActionIcon >
0 commit comments