Skip to content

Commit 472bafd

Browse files
committed
add module to FilterOptionsMenu
add module to ShowHideColumnsMenu remove isSubMenu from ShowHideColumnsMenu
1 parent 3596da7 commit 472bafd

5 files changed

+32
-48
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.symbol {
2+
font-size: var(--mantine-font-size-xl);
3+
text-align: center;
4+
width: 2ch;
5+
transform: translateY(-0.1em);
6+
}

packages/mantine-react-table/src/menus/MRT_FilterOptionMenu.tsx

+5-21
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Fragment, useMemo } from 'react';
2-
import { Flex, Menu } from '@mantine/core';
2+
import { Menu } from '@mantine/core';
33
import {
44
type MRT_FilterOption,
55
type MRT_Header,
@@ -8,6 +8,8 @@ import {
88
type MRT_TableInstance,
99
} from '../types';
1010

11+
import classes from './MRT_FilterOptionMenu.module.css';
12+
1113
export const mrtFilterOptions = (
1214
localization: MRT_Localization,
1315
): MRT_InternalFilterOption[] => [
@@ -246,28 +248,10 @@ export const MRT_FilterOptionMenu = <TData extends Record<string, any> = {}>({
246248
handleSelectFilterMode(option as MRT_FilterOption)
247249
}
248250
color={option === filterOption ? 'blue' : undefined}
249-
style={
250-
{
251-
// TODO: move to module
252-
// '& > .mantine-Menu-itemLabel': {
253-
// display: 'flex',
254-
// flexWrap: 'nowrap',
255-
// gap: '1ch',
256-
// },
257-
}
258-
}
259251
value={option}
252+
leftSection={<span className={classes.symbol}>{symbol}</span>}
260253
>
261-
<Flex
262-
style={{
263-
fontSize: '20px',
264-
transform: 'translateY(-2px)',
265-
width: '2ch',
266-
}}
267-
>
268-
{symbol}
269-
</Flex>
270-
<Flex align="center">{label}</Flex>
254+
{label}
271255
</Menu.Item>
272256
{divider && <Menu.Divider />}
273257
</Fragment>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.root {
2+
max-height: calc(80vh - 100px);
3+
overflow-y: auto;
4+
.content {
5+
padding: 8px;
6+
gap: 8px;
7+
justify-content: space-between;
8+
}
9+
}

packages/mantine-react-table/src/menus/MRT_ShowHideColumnsMenu.tsx

+9-19
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
1+
import clsx from 'clsx';
12
import { useMemo, useState } from 'react';
23
import { Button, Divider, Flex, Menu } from '@mantine/core';
4+
35
import { MRT_ShowHideColumnsMenuItems } from './MRT_ShowHideColumnsMenuItems';
46
import { getDefaultColumnOrderIds } from '../column.utils';
57
import { type MRT_Column, type MRT_TableInstance } from '../types';
68

9+
import classes from './MRT_ShowHideColumnsMenu.module.css';
10+
711
interface Props<TData extends Record<string, any> = {}> {
8-
isSubMenu?: boolean;
912
table: MRT_TableInstance<TData>;
1013
}
1114

1215
export const MRT_ShowHideColumnsMenu = <
1316
TData extends Record<string, any> = {},
1417
>({
15-
isSubMenu,
1618
table,
1719
}: Props<TData>) => {
1820
const {
@@ -70,20 +72,9 @@ export const MRT_ShowHideColumnsMenu = <
7072
);
7173

7274
return (
73-
<Menu.Dropdown
74-
style={{
75-
maxHeight: 'calc(80vh - 100px)',
76-
overflowY: 'auto',
77-
}}
78-
>
79-
<Flex
80-
style={{
81-
justifyContent: isSubMenu ? 'center' : 'space-between',
82-
padding: '8px',
83-
gap: '8px',
84-
}}
85-
>
86-
{!isSubMenu && enableHiding && (
75+
<Menu.Dropdown className={clsx('mrt-show-hide-columns-menu', classes.root)}>
76+
<Flex className={clsx(classes.content)}>
77+
{enableHiding && (
8778
<Button
8879
disabled={!getIsSomeColumnsVisible()}
8980
onClick={hideAllColumns}
@@ -92,7 +83,7 @@ export const MRT_ShowHideColumnsMenu = <
9283
{localization.hideAll}
9384
</Button>
9485
)}
95-
{!isSubMenu && enableColumnOrdering && (
86+
{enableColumnOrdering && (
9687
<Button
9788
onClick={() =>
9889
table.setColumnOrder(
@@ -104,7 +95,7 @@ export const MRT_ShowHideColumnsMenu = <
10495
{localization.resetOrder}
10596
</Button>
10697
)}
107-
{!isSubMenu && enablePinning && (
98+
{enablePinning && (
10899
<Button
109100
disabled={!getIsSomeColumnsPinned()}
110101
onClick={() => table.resetColumnPinning(true)}
@@ -129,7 +120,6 @@ export const MRT_ShowHideColumnsMenu = <
129120
allColumns={allColumns}
130121
column={column}
131122
hoveredColumn={hoveredColumn}
132-
isSubMenu={isSubMenu}
133123
key={`${index}-${column.id}`}
134124
setHoveredColumn={setHoveredColumn}
135125
table={table}

packages/mantine-react-table/src/menus/MRT_ShowHideColumnsMenuItems.tsx

+3-8
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ interface Props<TData extends Record<string, any> = {}> {
2626
allColumns: MRT_Column<TData>[];
2727
column: MRT_Column<TData>;
2828
hoveredColumn: MRT_Column<TData> | null;
29-
isSubMenu?: boolean;
3029
setHoveredColumn: Dispatch<SetStateAction<MRT_Column<TData> | null>>;
3130
table: MRT_TableInstance<TData>;
3231
}
@@ -38,7 +37,6 @@ export const MRT_ShowHideColumnsMenuItems = <
3837
hoveredColumn,
3938
setHoveredColumn,
4039
column,
41-
isSubMenu,
4240
table,
4341
}: Props<TData>) => {
4442
const theme = useMantineTheme();
@@ -112,8 +110,7 @@ export const MRT_ShowHideColumnsMenuItems = <
112110
)}
113111
>
114112
<Box className={classes.menu}>
115-
{!isSubMenu &&
116-
columnDefType !== 'group' &&
113+
{columnDefType !== 'group' &&
117114
enableColumnOrdering &&
118115
!allColumns.some(
119116
(col) => col.columnDef.columnDefType === 'group',
@@ -127,8 +124,7 @@ export const MRT_ShowHideColumnsMenuItems = <
127124
) : (
128125
<Box className={classes.grab} />
129126
))}
130-
{!isSubMenu &&
131-
enablePinning &&
127+
{enablePinning &&
132128
(column.getCanPin() ? (
133129
<MRT_ColumnPinningButtons column={column} table={table} />
134130
) : (
@@ -142,7 +138,7 @@ export const MRT_ShowHideColumnsMenuItems = <
142138
>
143139
<Switch
144140
checked={switchChecked}
145-
disabled={(isSubMenu && switchChecked) || !column.getCanHide()}
141+
disabled={!column.getCanHide()}
146142
label={columnDef.header}
147143
onChange={() => handleToggleColumnHidden(column)}
148144
className={classes.switch}
@@ -158,7 +154,6 @@ export const MRT_ShowHideColumnsMenuItems = <
158154
allColumns={allColumns}
159155
column={c}
160156
hoveredColumn={hoveredColumn}
161-
isSubMenu={isSubMenu}
162157
key={`${i}-${c.id}`}
163158
setHoveredColumn={setHoveredColumn}
164159
table={table}

0 commit comments

Comments
 (0)