Skip to content

Commit cf5cb0d

Browse files
authored
remove last uses of style={{ that i can (#164)
1 parent b1d9b02 commit cf5cb0d

9 files changed

+59
-57
lines changed

packages/mantine-react-table/src/body/MRT_TableBodyRow.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { type DragEvent, memo, useRef } from 'react';
2-
import { TableTr } from '@mantine/core';
2+
import { Box, TableTr } from '@mantine/core';
33
import clsx from 'clsx';
44
import { Memo_MRT_TableBodyCell, MRT_TableBodyCell } from './MRT_TableBodyCell';
55
import { MRT_TableDetailPanel } from './MRT_TableDetailPanel';
@@ -102,7 +102,7 @@ export const MRT_TableBodyRow = <TData extends Record<string, any> = {}>({
102102
)}
103103
>
104104
{virtualPaddingLeft ? (
105-
<td style={{ display: 'flex', width: virtualPaddingLeft }} />
105+
<Box component="td" display="flex" w={virtualPaddingLeft} />
106106
) : null}
107107
{(virtualColumns ?? row.getVisibleCells()).map((cellOrVirtualCell) => {
108108
const cell = columnVirtualizer
@@ -140,7 +140,7 @@ export const MRT_TableBodyRow = <TData extends Record<string, any> = {}>({
140140
);
141141
})}
142142
{virtualPaddingRight ? (
143-
<td style={{ display: 'flex', width: virtualPaddingRight }} />
143+
<Box component="td" display="flex" w={virtualPaddingRight} />
144144
) : null}
145145
</TableTr>
146146
{renderDetailPanel && !row.getIsGrouped() && (

packages/mantine-react-table/src/filterFns.ts

+9
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
type RankingInfo,
55
} from '@tanstack/match-sorter-utils';
66
import { filterFns, type Row } from '@tanstack/react-table';
7+
import type { MRT_FilterOption, MRT_Localization } from './types';
78

89
const fuzzy = <TData extends Record<string, any> = {}>(
910
row: Row<TData>,
@@ -191,3 +192,11 @@ export const MRT_FilterFns = {
191192
notEquals,
192193
startsWith,
193194
};
195+
196+
export function localizedFilterOption(
197+
localization: MRT_Localization,
198+
option: MRT_FilterOption,
199+
) {
200+
const key = `filter${option[0].toUpperCase()}${option.slice(1)}`;
201+
return localization[key as keyof MRT_Localization] ?? '';
202+
}

packages/mantine-react-table/src/footer/MRT_TableFooterRow.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import clsx from 'clsx';
2-
import { TableTr } from '@mantine/core';
2+
import { Box, TableTr } from '@mantine/core';
33
import { MRT_TableFooterCell } from './MRT_TableFooterCell';
44
import {
55
type MRT_Header,
@@ -56,7 +56,7 @@ export const MRT_TableFooterRow = <TData extends Record<string, any> = {}>({
5656
{...tableRowProps}
5757
>
5858
{virtualPaddingLeft ? (
59-
<th style={{ display: 'flex', width: virtualPaddingLeft }} />
59+
<Box component="th" display="flex" w={virtualPaddingLeft} />
6060
) : null}
6161
{(virtualColumns ?? footerGroup.headers).map((footerOrVirtualFooter) => {
6262
const footer = virtualColumns
@@ -68,7 +68,7 @@ export const MRT_TableFooterRow = <TData extends Record<string, any> = {}>({
6868
);
6969
})}
7070
{virtualPaddingRight ? (
71-
<th style={{ display: 'flex', width: virtualPaddingRight }} />
71+
<Box component="th" display="flex" w={virtualPaddingRight} />
7272
) : null}
7373
</TableTr>
7474
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.filter-mode-label {
2+
white-space: nowrap;
3+
margin-top: 4px;
4+
font-size: 10px;
5+
}

packages/mantine-react-table/src/head/MRT_TableHeadCellFilterContainer.tsx

+5-9
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import { MRT_FilterCheckbox } from '../inputs/MRT_FilterCheckbox';
55
import { MRT_FilterOptionMenu } from '../menus/MRT_FilterOptionMenu';
66
import { type MRT_Header, type MRT_TableInstance } from '../types';
77
import { MRT_FilterRangeSlider } from '../inputs/MRT_FilterRangeSlider';
8+
import { localizedFilterOption } from '../filterFns';
9+
10+
import classes from './MRT_TableHeadCellFilterContainer.module.css';
811

912
interface Props<TData extends Record<string, any> = {}> {
1013
header: MRT_Header<TData>;
@@ -70,7 +73,6 @@ export const MRT_TableHeadCellFilterContainer = <
7073
variant="transparent"
7174
aria-label={localization.changeFilterMode}
7275
size="md"
73-
style={{ transform: 'translateY(-2px)' }}
7476
>
7577
<IconFilterCog />
7678
</ActionIcon>
@@ -92,18 +94,12 @@ export const MRT_TableHeadCellFilterContainer = <
9294
{showChangeModeButton ? (
9395
<Text
9496
component="label"
97+
className={classes['filter-mode-label']}
9598
c="dimmed"
96-
style={{ whiteSpace: 'nowrap', marginTop: '4px', fontSize: '10px' }}
9799
>
98100
{localization.filterMode.replace(
99101
'{filterType}',
100-
// @ts-ignore
101-
localization[
102-
`filter${
103-
currentFilterOption?.charAt(0)?.toUpperCase() +
104-
currentFilterOption?.slice(1)
105-
}`
106-
],
102+
localizedFilterOption(localization, currentFilterOption),
107103
)}
108104
</Text>
109105
) : null}

packages/mantine-react-table/src/head/MRT_TableHeadCellFilterLabel.module.css

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
1-
.MRT_TableHeadCellFilterLabelActionIcon {
2-
opacity: var(--opacity);
1+
.root {
2+
opacity: 0.5;
33
padding: 2px;
4+
color: gray;
5+
&.active {
6+
opacity: 1;
7+
color: var(--mantine-primary-color-filled);
8+
@mixin hover {
9+
color: var(--mantine-primary-color-filled-hover);
10+
}
11+
}
412
@mixin hover {
513
opacity: 1;
614
}

packages/mantine-react-table/src/head/MRT_TableHeadCellFilterLabel.tsx

+18-29
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
1+
import clsx from 'clsx';
12
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+
115
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+
139
import classes from './MRT_TableHeadCellFilterLabel.module.css';
1410

1511
interface Props<TData extends Record<string, any> = {}> {
@@ -35,8 +31,6 @@ export const MRT_TableHeadCellFilterLabel = <
3531
const { column } = header;
3632
const { columnDef } = column;
3733

38-
const theme = useMantineTheme();
39-
4034
const filterValue = column.getFilterValue();
4135

4236
const [popoverOpened, setPopoverOpened] = useState(false);
@@ -61,13 +55,7 @@ export const MRT_TableHeadCellFilterLabel = <
6155
.replace('{column}', String(columnDef.header))
6256
.replace(
6357
'{filterType}',
64-
// @ts-ignore
65-
localization[
66-
`filter${
67-
currentFilterOption?.charAt(0)?.toUpperCase() +
68-
currentFilterOption?.slice(1)
69-
}`
70-
],
58+
localizedFilterOption(localization, currentFilterOption),
7159
)
7260
.replace(
7361
'{filterValue}',
@@ -100,8 +88,8 @@ export const MRT_TableHeadCellFilterLabel = <
10088
(!!column.getFilterValue()?.[0] || !!column.getFilterValue()?.[1]))
10189
}
10290
>
103-
{(style) => (
104-
<Box component="span" style={{ ...style, flex: '0 0' }}>
91+
{() => (
92+
<Box component="span">
10593
<Popover.Target>
10694
<Tooltip
10795
disabled={popoverOpened}
@@ -111,8 +99,13 @@ export const MRT_TableHeadCellFilterLabel = <
11199
withinPortal
112100
>
113101
<ActionIcon
102+
size="sm"
114103
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+
)}
116109
onClick={(event: MouseEvent<HTMLButtonElement>) => {
117110
event.stopPropagation();
118111
if (columnFilterDisplayMode === 'popover') {
@@ -121,15 +114,11 @@ export const MRT_TableHeadCellFilterLabel = <
121114
setShowColumnFilters(true);
122115
}
123116
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();
126120
}, 100);
127121
}}
128-
size="sm"
129-
className={classes.MRT_TableHeadCellFilterLabelActionIcon}
130-
__vars={{
131-
'--opacity': isFilterActive ? '1' : '0.5',
132-
}}
133122
>
134123
<IconFilter />
135124
</ActionIcon>

packages/mantine-react-table/src/head/MRT_TableHeadRow.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { TableTr } from '@mantine/core';
1+
import { Box, TableTr } from '@mantine/core';
22
import clsx from 'clsx';
33
import { MRT_TableHeadCell } from './MRT_TableHeadCell';
44
import {
@@ -48,7 +48,7 @@ export const MRT_TableHeadRow = <TData extends Record<string, any> = {}>({
4848
)}
4949
>
5050
{virtualPaddingLeft ? (
51-
<th style={{ display: 'flex', width: virtualPaddingLeft }} />
51+
<Box component="th" display="flex" w={virtualPaddingLeft} />
5252
) : null}
5353
{(virtualColumns ?? headerGroup.headers).map((headerOrVirtualHeader) => {
5454
const header = virtualColumns
@@ -60,7 +60,7 @@ export const MRT_TableHeadRow = <TData extends Record<string, any> = {}>({
6060
);
6161
})}
6262
{virtualPaddingRight ? (
63-
<th style={{ display: 'flex', width: virtualPaddingRight }} />
63+
<Box component="th" display="flex" w={virtualPaddingRight} />
6464
) : null}
6565
</TableTr>
6666
);

packages/mantine-react-table/src/inputs/MRT_FilterTextInput.tsx

+3-8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import clsx from 'clsx';
12
import { type MouseEvent, useEffect, useMemo, useRef, useState } from 'react';
23
import {
34
ActionIcon,
@@ -10,11 +11,11 @@ import {
1011
Select,
1112
TextInput,
1213
} from '@mantine/core';
13-
import clsx from 'clsx';
1414
import { DateInput } from '@mantine/dates';
1515
import { useDebouncedValue } from '@mantine/hooks';
1616
import { type MRT_Header, type MRT_TableInstance } from '../types';
1717
import { parseFromValuesOrFunc } from '../column.utils';
18+
import { localizedFilterOption } from '../filterFns';
1819

1920
import classes from './MRT_FilterTextInput.module.css';
2021

@@ -108,13 +109,7 @@ export const MRT_FilterTextInput = <TData extends Record<string, any> = {}>({
108109

109110
const currentFilterOption = columnDef._filterFn;
110111
const filterChipLabel = ['empty', 'notEmpty'].includes(currentFilterOption)
111-
? //@ts-ignore
112-
localization[
113-
`filter${
114-
currentFilterOption?.charAt?.(0)?.toUpperCase() +
115-
currentFilterOption?.slice(1)
116-
}`
117-
]
112+
? localizedFilterOption(localization, currentFilterOption)
118113
: '';
119114
const filterPlaceholder = !isRangeFilter
120115
? textInputProps?.placeholder ??

0 commit comments

Comments
 (0)