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

remove last uses of style={{ that i can #164

Merged
merged 1 commit into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 3 additions & 3 deletions packages/mantine-react-table/src/body/MRT_TableBodyRow.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type DragEvent, memo, useRef } from 'react';
import { TableTr } from '@mantine/core';
import { Box, TableTr } from '@mantine/core';
import clsx from 'clsx';
import { Memo_MRT_TableBodyCell, MRT_TableBodyCell } from './MRT_TableBodyCell';
import { MRT_TableDetailPanel } from './MRT_TableDetailPanel';
Expand Down Expand Up @@ -102,7 +102,7 @@ export const MRT_TableBodyRow = <TData extends Record<string, any> = {}>({
)}
>
{virtualPaddingLeft ? (
<td style={{ display: 'flex', width: virtualPaddingLeft }} />
<Box component="td" display="flex" w={virtualPaddingLeft} />
) : null}
{(virtualColumns ?? row.getVisibleCells()).map((cellOrVirtualCell) => {
const cell = columnVirtualizer
Expand Down Expand Up @@ -140,7 +140,7 @@ export const MRT_TableBodyRow = <TData extends Record<string, any> = {}>({
);
})}
{virtualPaddingRight ? (
<td style={{ display: 'flex', width: virtualPaddingRight }} />
<Box component="td" display="flex" w={virtualPaddingRight} />
) : null}
</TableTr>
{renderDetailPanel && !row.getIsGrouped() && (
Expand Down
9 changes: 9 additions & 0 deletions packages/mantine-react-table/src/filterFns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
type RankingInfo,
} from '@tanstack/match-sorter-utils';
import { filterFns, type Row } from '@tanstack/react-table';
import type { MRT_FilterOption, MRT_Localization } from './types';

const fuzzy = <TData extends Record<string, any> = {}>(
row: Row<TData>,
Expand Down Expand Up @@ -191,3 +192,11 @@ export const MRT_FilterFns = {
notEquals,
startsWith,
};

export function localizedFilterOption(
localization: MRT_Localization,
option: MRT_FilterOption,
) {
const key = `filter${option[0].toUpperCase()}${option.slice(1)}`;
return localization[key as keyof MRT_Localization] ?? '';
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import clsx from 'clsx';
import { TableTr } from '@mantine/core';
import { Box, TableTr } from '@mantine/core';
import { MRT_TableFooterCell } from './MRT_TableFooterCell';
import {
type MRT_Header,
Expand Down Expand Up @@ -56,7 +56,7 @@ export const MRT_TableFooterRow = <TData extends Record<string, any> = {}>({
{...tableRowProps}
>
{virtualPaddingLeft ? (
<th style={{ display: 'flex', width: virtualPaddingLeft }} />
<Box component="th" display="flex" w={virtualPaddingLeft} />
) : null}
{(virtualColumns ?? footerGroup.headers).map((footerOrVirtualFooter) => {
const footer = virtualColumns
Expand All @@ -68,7 +68,7 @@ export const MRT_TableFooterRow = <TData extends Record<string, any> = {}>({
);
})}
{virtualPaddingRight ? (
<th style={{ display: 'flex', width: virtualPaddingRight }} />
<Box component="th" display="flex" w={virtualPaddingRight} />
) : null}
</TableTr>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.filter-mode-label {
white-space: nowrap;
margin-top: 4px;
font-size: 10px;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import { MRT_FilterCheckbox } from '../inputs/MRT_FilterCheckbox';
import { MRT_FilterOptionMenu } from '../menus/MRT_FilterOptionMenu';
import { type MRT_Header, type MRT_TableInstance } from '../types';
import { MRT_FilterRangeSlider } from '../inputs/MRT_FilterRangeSlider';
import { localizedFilterOption } from '../filterFns';

import classes from './MRT_TableHeadCellFilterContainer.module.css';

interface Props<TData extends Record<string, any> = {}> {
header: MRT_Header<TData>;
Expand Down Expand Up @@ -70,7 +73,6 @@ export const MRT_TableHeadCellFilterContainer = <
variant="transparent"
aria-label={localization.changeFilterMode}
size="md"
style={{ transform: 'translateY(-2px)' }}
>
<IconFilterCog />
</ActionIcon>
Expand All @@ -92,18 +94,12 @@ export const MRT_TableHeadCellFilterContainer = <
{showChangeModeButton ? (
<Text
component="label"
className={classes['filter-mode-label']}
c="dimmed"
style={{ whiteSpace: 'nowrap', marginTop: '4px', fontSize: '10px' }}
>
{localization.filterMode.replace(
'{filterType}',
// @ts-ignore
localization[
`filter${
currentFilterOption?.charAt(0)?.toUpperCase() +
currentFilterOption?.slice(1)
}`
],
localizedFilterOption(localization, currentFilterOption),
)}
</Text>
) : null}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
.MRT_TableHeadCellFilterLabelActionIcon {
opacity: var(--opacity);
.root {
opacity: 0.5;
padding: 2px;
color: gray;
&.active {
opacity: 1;
color: var(--mantine-primary-color-filled);
@mixin hover {
color: var(--mantine-primary-color-filled-hover);
}
}
@mixin hover {
opacity: 1;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import clsx from 'clsx';
import { useState, type MouseEvent } from 'react';
import {
ActionIcon,
Box,
Transition,
Tooltip,
Popover,
useMantineTheme,
} from '@mantine/core';
import { MRT_TableHeadCellFilterContainer } from './MRT_TableHeadCellFilterContainer';
import { ActionIcon, Box, Popover, Tooltip, Transition } from '@mantine/core';

import { type MRT_Header, type MRT_TableInstance } from '../types';
import { getPrimaryColor } from '../column.utils';
import { localizedFilterOption } from '../filterFns';
import { MRT_TableHeadCellFilterContainer } from './MRT_TableHeadCellFilterContainer';

import classes from './MRT_TableHeadCellFilterLabel.module.css';

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

const theme = useMantineTheme();

const filterValue = column.getFilterValue();

const [popoverOpened, setPopoverOpened] = useState(false);
Expand All @@ -61,13 +55,7 @@ export const MRT_TableHeadCellFilterLabel = <
.replace('{column}', String(columnDef.header))
.replace(
'{filterType}',
// @ts-ignore
localization[
`filter${
currentFilterOption?.charAt(0)?.toUpperCase() +
currentFilterOption?.slice(1)
}`
],
localizedFilterOption(localization, currentFilterOption),
)
.replace(
'{filterValue}',
Expand Down Expand Up @@ -100,8 +88,8 @@ export const MRT_TableHeadCellFilterLabel = <
(!!column.getFilterValue()?.[0] || !!column.getFilterValue()?.[1]))
}
>
{(style) => (
<Box component="span" style={{ ...style, flex: '0 0' }}>
{() => (
<Box component="span">
<Popover.Target>
<Tooltip
disabled={popoverOpened}
Expand All @@ -111,8 +99,13 @@ export const MRT_TableHeadCellFilterLabel = <
withinPortal
>
<ActionIcon
size="sm"
variant="transparent"
color={isFilterActive ? getPrimaryColor(theme) : 'gray'}
className={clsx(
'mrt-table-head-cell-filter-label-icon',
classes.root,
isFilterActive && classes.active,
)}
onClick={(event: MouseEvent<HTMLButtonElement>) => {
event.stopPropagation();
if (columnFilterDisplayMode === 'popover') {
Expand All @@ -121,15 +114,11 @@ export const MRT_TableHeadCellFilterLabel = <
setShowColumnFilters(true);
}
setTimeout(() => {
filterInputRefs.current[`${column.id}-0`]?.focus();
filterInputRefs.current[`${column.id}-0`]?.select();
const input = filterInputRefs.current[`${column.id}-0`];
input?.focus();
input?.select();
}, 100);
}}
size="sm"
className={classes.MRT_TableHeadCellFilterLabelActionIcon}
__vars={{
'--opacity': isFilterActive ? '1' : '0.5',
}}
>
<IconFilter />
</ActionIcon>
Expand Down
6 changes: 3 additions & 3 deletions packages/mantine-react-table/src/head/MRT_TableHeadRow.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TableTr } from '@mantine/core';
import { Box, TableTr } from '@mantine/core';
import clsx from 'clsx';
import { MRT_TableHeadCell } from './MRT_TableHeadCell';
import {
Expand Down Expand Up @@ -48,7 +48,7 @@ export const MRT_TableHeadRow = <TData extends Record<string, any> = {}>({
)}
>
{virtualPaddingLeft ? (
<th style={{ display: 'flex', width: virtualPaddingLeft }} />
<Box component="th" display="flex" w={virtualPaddingLeft} />
) : null}
{(virtualColumns ?? headerGroup.headers).map((headerOrVirtualHeader) => {
const header = virtualColumns
Expand All @@ -60,7 +60,7 @@ export const MRT_TableHeadRow = <TData extends Record<string, any> = {}>({
);
})}
{virtualPaddingRight ? (
<th style={{ display: 'flex', width: virtualPaddingRight }} />
<Box component="th" display="flex" w={virtualPaddingRight} />
) : null}
</TableTr>
);
Expand Down
11 changes: 3 additions & 8 deletions packages/mantine-react-table/src/inputs/MRT_FilterTextInput.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import clsx from 'clsx';
import { type MouseEvent, useEffect, useMemo, useRef, useState } from 'react';
import {
ActionIcon,
Expand All @@ -10,11 +11,11 @@ import {
Select,
TextInput,
} from '@mantine/core';
import clsx from 'clsx';
import { DateInput } from '@mantine/dates';
import { useDebouncedValue } from '@mantine/hooks';
import { type MRT_Header, type MRT_TableInstance } from '../types';
import { parseFromValuesOrFunc } from '../column.utils';
import { localizedFilterOption } from '../filterFns';

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

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

const currentFilterOption = columnDef._filterFn;
const filterChipLabel = ['empty', 'notEmpty'].includes(currentFilterOption)
? //@ts-ignore
localization[
`filter${
currentFilterOption?.charAt?.(0)?.toUpperCase() +
currentFilterOption?.slice(1)
}`
]
? localizedFilterOption(localization, currentFilterOption)
: '';
const filterPlaceholder = !isRangeFilter
? textInputProps?.placeholder ??
Expand Down
Loading