refine-mantine 1.0.1 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +4 -2
- package/dist/index.js +38 -13
- package/package.json +1 -1
- package/src/components/buttons/DeleteButton.tsx +7 -4
- package/src/components/table/ColumnFilter.tsx +4 -0
- package/src/components/table/Table.story.tsx +0 -1
- package/src/components/table/Table.tsx +10 -3
- package/src/hooks/useEnter.ts +20 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ActionIconProps, AppShellFooterProps, AppShellHeaderProps, AppShellMainProps, AppShellNavbarConfiguration, AppShellNavbarProps, AppShellProps, AppShellSectionProps, BadgeProps, BoxProps, BreadcrumbsProps, ButtonProps, CardProps, GroupProps, LoadingOverlayProps, MenuItemProps, NotificationProps, PinInputProps, PopoverProps, ScrollAreaProps, StackProps, TextInputProps } from "@mantine/core";
|
|
1
|
+
import { ActionIconProps, AppShellFooterProps, AppShellHeaderProps, AppShellMainProps, AppShellNavbarConfiguration, AppShellNavbarProps, AppShellProps, AppShellSectionProps, BadgeProps, BoxProps, BreadcrumbsProps, ButtonProps, CardProps, GroupProps, LoadingOverlayProps, MenuItemProps, NotificationProps, PinInputProps, PopoverProps, ScrollAreaProps, StackProps, TableProps, TextInputProps } from "@mantine/core";
|
|
2
2
|
import { AuthProvider, AutoSaveIndicatorProps as AutoSaveIndicatorProps$1, BaseRecord, HttpError, LoginFormTypes, NotificationProvider, OAuthProvider, RegisterFormTypes, UseFormProps as UseFormProps$1, UseFormReturnType as UseFormReturnType$1, useMenu, useTranslate } from "@refinedev/core";
|
|
3
3
|
import { IconProps } from "@tabler/icons-react";
|
|
4
4
|
import * as react_jsx_runtime0 from "react/jsx-runtime";
|
|
@@ -153,9 +153,11 @@ declare const ColumnSorter: <T extends object>(p: {
|
|
|
153
153
|
//#endregion
|
|
154
154
|
//#region src/components/table/Table.d.ts
|
|
155
155
|
declare const Table: <TData extends BaseRecord = BaseRecord, TError extends HttpError = HttpError>({
|
|
156
|
-
props
|
|
156
|
+
props,
|
|
157
|
+
tableProps
|
|
157
158
|
}: {
|
|
158
159
|
props: UseTableReturnType<TData, TError>;
|
|
160
|
+
tableProps?: TableProps;
|
|
159
161
|
}) => react_jsx_runtime0.JSX.Element;
|
|
160
162
|
//#endregion
|
|
161
163
|
//#region src/components/notification/AutoSaveIndicator.d.ts
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import { ActionIcon, Anchor, AppShell, Avatar, Badge, Box, Breadcrumbs, Burger,
|
|
|
2
2
|
import { CanAccess, Link, flattenObjectKeys, matchResourceFromRoute, useBack, useBreadcrumb, useCreateButton, useDeleteButton, useEditButton, useForm as useForm$1, useGetIdentity, useGo, useLink, useListButton, useLogin, useLogout, useMenu, useMutationMode, useNavigation, useRefineContext, useRefineOptions, useRefreshButton, useRegister, useResourceParams, useSaveButton, useShowButton, useToPath, useTranslate, useTranslation, useUserFriendlyName, useWarnAboutChange } from "@refinedev/core";
|
|
3
3
|
import { IconArrowBackUp, IconArrowLeft, IconAt, IconCheck, IconChevronUp, IconCircleCheck, IconDeviceFloppy, IconDots, IconExclamationCircle, IconEye, IconFilter, IconHome, IconLanguage, IconList, IconLockPassword, IconLogout, IconMoon, IconPencil, IconRefresh, IconSelector, IconSquarePlus, IconSun, IconTrash, IconX } from "@tabler/icons-react";
|
|
4
4
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
-
import { useCallback, useEffect, useState } from "react";
|
|
5
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
6
6
|
import { useDebouncedCallback, useDisclosure } from "@mantine/hooks";
|
|
7
7
|
import { RefinePageHeaderClassNames } from "@refinedev/ui-types";
|
|
8
8
|
import { flexRender } from "@tanstack/react-table";
|
|
@@ -126,6 +126,10 @@ const DeleteButton = ({ resource, recordItemId, mutationMode, invalidates, child
|
|
|
126
126
|
onSuccess
|
|
127
127
|
});
|
|
128
128
|
const [opened, handlers] = useDisclosure(false);
|
|
129
|
+
const handleConfirm = useCallback(() => {
|
|
130
|
+
onConfirm();
|
|
131
|
+
handlers.close();
|
|
132
|
+
}, [onConfirm, handlers]);
|
|
129
133
|
if (hidden) return null;
|
|
130
134
|
const disabled = disabledFromProps || disabledFromHook;
|
|
131
135
|
return /* @__PURE__ */ jsxs(Popover, {
|
|
@@ -183,10 +187,7 @@ const DeleteButton = ({ resource, recordItemId, mutationMode, invalidates, child
|
|
|
183
187
|
children: confirmCancelText ?? defaultCancelLabel
|
|
184
188
|
}), /* @__PURE__ */ jsx(Button, {
|
|
185
189
|
color: "red",
|
|
186
|
-
onClick:
|
|
187
|
-
onConfirm();
|
|
188
|
-
handlers.close();
|
|
189
|
-
},
|
|
190
|
+
onClick: handleConfirm,
|
|
190
191
|
autoFocus: true,
|
|
191
192
|
size: "xs",
|
|
192
193
|
children: confirmOkText ?? defaultConfirmOkLabel
|
|
@@ -968,6 +969,22 @@ const Message = ({ message, description, undoLabel, undoableTime = 5, undoableTi
|
|
|
968
969
|
})
|
|
969
970
|
});
|
|
970
971
|
|
|
972
|
+
//#endregion
|
|
973
|
+
//#region src/hooks/useEnter.ts
|
|
974
|
+
const useEnter = (handler) => {
|
|
975
|
+
const ref = useRef(null);
|
|
976
|
+
useEffect(() => {
|
|
977
|
+
const el = ref?.current;
|
|
978
|
+
if (!el) return;
|
|
979
|
+
const onKeyDown = (event) => {
|
|
980
|
+
if (event.key === "Enter") handler();
|
|
981
|
+
};
|
|
982
|
+
el.addEventListener("keydown", onKeyDown);
|
|
983
|
+
return () => el.removeEventListener("keydown", onKeyDown);
|
|
984
|
+
}, [ref, handler]);
|
|
985
|
+
return ref;
|
|
986
|
+
};
|
|
987
|
+
|
|
971
988
|
//#endregion
|
|
972
989
|
//#region src/components/table/ColumnFilter.tsx
|
|
973
990
|
const ColumnFilter = (p) => {
|
|
@@ -993,6 +1010,7 @@ const ColumnFilter = (p) => {
|
|
|
993
1010
|
p.column.setFilterValue(filterOperator === "ina" ? [state.value] : state.value);
|
|
994
1011
|
close();
|
|
995
1012
|
};
|
|
1013
|
+
const confirmRef = useEnter(save);
|
|
996
1014
|
return /* @__PURE__ */ jsxs(Menu, {
|
|
997
1015
|
opened: !!state,
|
|
998
1016
|
position: "bottom",
|
|
@@ -1014,6 +1032,7 @@ const ColumnFilter = (p) => {
|
|
|
1014
1032
|
value: state?.value,
|
|
1015
1033
|
onChange: handleChange
|
|
1016
1034
|
}) : /* @__PURE__ */ jsx(TextInput, {
|
|
1035
|
+
ref: confirmRef,
|
|
1017
1036
|
autoComplete: "off",
|
|
1018
1037
|
value: state.value,
|
|
1019
1038
|
onChange: (e) => handleChange(e.target.value)
|
|
@@ -1058,19 +1077,25 @@ const ColumnSorter = (p) => {
|
|
|
1058
1077
|
|
|
1059
1078
|
//#endregion
|
|
1060
1079
|
//#region src/components/table/Table.tsx
|
|
1061
|
-
const Table = ({ props }) => /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Table$1.ScrollContainer, {
|
|
1080
|
+
const Table = ({ props, tableProps }) => /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Table$1.ScrollContainer, {
|
|
1062
1081
|
minWidth: 500,
|
|
1063
1082
|
children: /* @__PURE__ */ jsxs(Table$1, {
|
|
1064
1083
|
highlightOnHover: true,
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1084
|
+
...tableProps,
|
|
1085
|
+
children: [/* @__PURE__ */ jsx(Table$1.Thead, { children: props.reactTable.getHeaderGroups().map((headerGroup) => /* @__PURE__ */ jsx(Table$1.Tr, { children: headerGroup.headers.map((header) => /* @__PURE__ */ jsx(Table$1.Th, {
|
|
1086
|
+
colSpan: header.colSpan,
|
|
1087
|
+
rowSpan: header.rowSpan,
|
|
1088
|
+
style: { width: header.getSize() },
|
|
1089
|
+
children: !header.isPlaceholder && /* @__PURE__ */ jsxs(Group, {
|
|
1069
1090
|
gap: "xs",
|
|
1070
1091
|
wrap: "nowrap",
|
|
1071
|
-
children: [/* @__PURE__ */ jsx(
|
|
1072
|
-
|
|
1073
|
-
|
|
1092
|
+
children: [/* @__PURE__ */ jsx(Box, { children: flexRender(header.column.columnDef.header, header.getContext()) }), /* @__PURE__ */ jsxs(Group, {
|
|
1093
|
+
gap: "xs",
|
|
1094
|
+
wrap: "nowrap",
|
|
1095
|
+
children: [/* @__PURE__ */ jsx(ColumnSorter, { column: header.column }), /* @__PURE__ */ jsx(ColumnFilter, { column: header.column })]
|
|
1096
|
+
})]
|
|
1097
|
+
})
|
|
1098
|
+
}, header.id)) }, headerGroup.id)) }), /* @__PURE__ */ jsx(Table$1.Tbody, { children: props.reactTable.getRowModel().rows.map((row) => /* @__PURE__ */ jsx(Table$1.Tr, { children: row.getVisibleCells().map((cell) => /* @__PURE__ */ jsx(Table$1.Td, { children: flexRender(cell.column.columnDef.cell, cell.getContext()) }, cell.id)) }, row.id)) })]
|
|
1074
1099
|
})
|
|
1075
1100
|
}), /* @__PURE__ */ jsx(Group, {
|
|
1076
1101
|
justify: "flex-end",
|
package/package.json
CHANGED
|
@@ -15,6 +15,7 @@ import { useDeleteButton } from "@refinedev/core";
|
|
|
15
15
|
import type { RefineDeleteButtonProps } from "@refinedev/ui-types";
|
|
16
16
|
import { type IconProps, IconTrash } from "@tabler/icons-react";
|
|
17
17
|
import type React from "react";
|
|
18
|
+
import { useCallback } from "react";
|
|
18
19
|
|
|
19
20
|
export type DeleteButtonProps = RefineDeleteButtonProps<{
|
|
20
21
|
iconProps?: IconProps;
|
|
@@ -75,6 +76,11 @@ export const DeleteButton: React.FC<DeleteButtonProps> = ({
|
|
|
75
76
|
|
|
76
77
|
const [opened, handlers] = useDisclosure(false);
|
|
77
78
|
|
|
79
|
+
const handleConfirm = useCallback(() => {
|
|
80
|
+
onConfirm();
|
|
81
|
+
handlers.close();
|
|
82
|
+
}, [onConfirm, handlers]);
|
|
83
|
+
|
|
78
84
|
if (hidden) return null;
|
|
79
85
|
|
|
80
86
|
const disabled = disabledFromProps || disabledFromHook;
|
|
@@ -136,10 +142,7 @@ export const DeleteButton: React.FC<DeleteButtonProps> = ({
|
|
|
136
142
|
</Button>
|
|
137
143
|
<Button
|
|
138
144
|
color="red"
|
|
139
|
-
onClick={
|
|
140
|
-
onConfirm();
|
|
141
|
-
handlers.close();
|
|
142
|
-
}}
|
|
145
|
+
onClick={handleConfirm}
|
|
143
146
|
autoFocus
|
|
144
147
|
size="xs"
|
|
145
148
|
>
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { useEnter } from "@/hooks/useEnter";
|
|
1
2
|
import { ActionIcon, Group, Menu, Stack, TextInput } from "@mantine/core";
|
|
2
3
|
import type { CrudOperators } from "@refinedev/core";
|
|
3
4
|
import { IconCheck, IconFilter, IconX } from "@tabler/icons-react";
|
|
@@ -54,6 +55,8 @@ export const ColumnFilter = <T extends object>(p: { column: Column<T> }) => {
|
|
|
54
55
|
close();
|
|
55
56
|
};
|
|
56
57
|
|
|
58
|
+
const confirmRef = useEnter<HTMLInputElement>(save);
|
|
59
|
+
|
|
57
60
|
return (
|
|
58
61
|
<Menu
|
|
59
62
|
opened={!!state}
|
|
@@ -81,6 +84,7 @@ export const ColumnFilter = <T extends object>(p: { column: Column<T> }) => {
|
|
|
81
84
|
<FilterComponent value={state?.value} onChange={handleChange} />
|
|
82
85
|
) : (
|
|
83
86
|
<TextInput
|
|
87
|
+
ref={confirmRef}
|
|
84
88
|
autoComplete="off"
|
|
85
89
|
value={state.value}
|
|
86
90
|
onChange={(e) => handleChange(e.target.value)}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Box, Group, Table as MantineTable, Pagination } from "@mantine/core";
|
|
1
|
+
import { Box, Group, Table as MantineTable, Pagination, TableProps } from "@mantine/core";
|
|
2
2
|
import type { BaseRecord, HttpError } from "@refinedev/core";
|
|
3
3
|
import type { UseTableReturnType } from "@refinedev/react-table";
|
|
4
4
|
import { flexRender } from "@tanstack/react-table";
|
|
@@ -10,17 +10,24 @@ export const Table = <
|
|
|
10
10
|
TError extends HttpError = HttpError,
|
|
11
11
|
>({
|
|
12
12
|
props,
|
|
13
|
+
tableProps,
|
|
13
14
|
}: {
|
|
14
15
|
props: UseTableReturnType<TData, TError>;
|
|
16
|
+
tableProps?: TableProps;
|
|
15
17
|
}) => (
|
|
16
18
|
<>
|
|
17
19
|
<MantineTable.ScrollContainer minWidth={500}>
|
|
18
|
-
<MantineTable highlightOnHover>
|
|
20
|
+
<MantineTable highlightOnHover {...tableProps}>
|
|
19
21
|
<MantineTable.Thead>
|
|
20
22
|
{props.reactTable.getHeaderGroups().map((headerGroup) => (
|
|
21
23
|
<MantineTable.Tr key={headerGroup.id}>
|
|
22
24
|
{headerGroup.headers.map((header) => (
|
|
23
|
-
<MantineTable.Th
|
|
25
|
+
<MantineTable.Th
|
|
26
|
+
key={header.id}
|
|
27
|
+
colSpan={header.colSpan}
|
|
28
|
+
rowSpan={header.rowSpan}
|
|
29
|
+
style={{width: header.getSize()}}
|
|
30
|
+
>
|
|
24
31
|
{!header.isPlaceholder && (
|
|
25
32
|
<Group gap="xs" wrap="nowrap">
|
|
26
33
|
<Box>
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { useEffect, useRef } from 'react';
|
|
2
|
+
|
|
3
|
+
export const useEnter = <T extends HTMLElement>(handler: () => void) => {
|
|
4
|
+
const ref = useRef<T>(null);
|
|
5
|
+
|
|
6
|
+
useEffect(() => {
|
|
7
|
+
const el = ref?.current;
|
|
8
|
+
if (!el) return;
|
|
9
|
+
|
|
10
|
+
const onKeyDown = (event: KeyboardEvent) => {
|
|
11
|
+
if (event.key === 'Enter') handler();
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
el.addEventListener('keydown', onKeyDown);
|
|
15
|
+
|
|
16
|
+
return () => el.removeEventListener('keydown', onKeyDown);
|
|
17
|
+
}, [ref, handler]);
|
|
18
|
+
|
|
19
|
+
return ref;
|
|
20
|
+
}
|