refine-mantine 1.0.0 → 1.1.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/README.md
CHANGED
|
@@ -5,6 +5,12 @@
|
|
|
5
5
|
This project provides ready-to-use [Mantine v8](https://mantine.dev/) UI components and utilities built for [Refine v5](https://refine.dev/) applications.
|
|
6
6
|
It aims to accelerate development by offering a collection of prebuilt components such as layouts, CRUD views, tables, buttons, and authentication screens, following both Refine and Mantine best practices.
|
|
7
7
|
|
|
8
|
+
### Setup
|
|
9
|
+
|
|
10
|
+
``` sh
|
|
11
|
+
npm i refine-mantine
|
|
12
|
+
```
|
|
13
|
+
|
|
8
14
|
### Features
|
|
9
15
|
|
|
10
16
|
* Prebuilt UI components for rapid Refine project development
|
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,13 +126,18 @@ 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, {
|
|
132
136
|
opened,
|
|
133
137
|
onChange: handlers.toggle,
|
|
134
138
|
withArrow: true,
|
|
135
|
-
withinPortal:
|
|
139
|
+
withinPortal: false,
|
|
140
|
+
withOverlay: true,
|
|
136
141
|
disabled,
|
|
137
142
|
...popoverProps,
|
|
138
143
|
children: [/* @__PURE__ */ jsx(Popover.Target, { children: hideText ? /* @__PURE__ */ jsx(ActionIcon, {
|
|
@@ -182,10 +187,7 @@ const DeleteButton = ({ resource, recordItemId, mutationMode, invalidates, child
|
|
|
182
187
|
children: confirmCancelText ?? defaultCancelLabel
|
|
183
188
|
}), /* @__PURE__ */ jsx(Button, {
|
|
184
189
|
color: "red",
|
|
185
|
-
onClick:
|
|
186
|
-
onConfirm();
|
|
187
|
-
handlers.close();
|
|
188
|
-
},
|
|
190
|
+
onClick: handleConfirm,
|
|
189
191
|
autoFocus: true,
|
|
190
192
|
size: "xs",
|
|
191
193
|
children: confirmOkText ?? defaultConfirmOkLabel
|
|
@@ -654,7 +656,6 @@ const List = (props) => {
|
|
|
654
656
|
const isCreateButtonVisible = canCreate ?? (!!resource?.create || createButtonPropsFromProps);
|
|
655
657
|
const breadcrumb = typeof breadcrumbFromProps === "undefined" ? globalBreadcrumb : breadcrumbFromProps;
|
|
656
658
|
const createButtonProps = isCreateButtonVisible ? {
|
|
657
|
-
size: "sm",
|
|
658
659
|
resource: identifier,
|
|
659
660
|
...createButtonPropsFromProps
|
|
660
661
|
} : void 0;
|
|
@@ -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)
|
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;
|
|
@@ -84,7 +90,8 @@ export const DeleteButton: React.FC<DeleteButtonProps> = ({
|
|
|
84
90
|
opened={opened}
|
|
85
91
|
onChange={handlers.toggle}
|
|
86
92
|
withArrow
|
|
87
|
-
withinPortal
|
|
93
|
+
withinPortal={false}
|
|
94
|
+
withOverlay
|
|
88
95
|
disabled={disabled}
|
|
89
96
|
{...popoverProps}
|
|
90
97
|
>
|
|
@@ -135,10 +142,7 @@ export const DeleteButton: React.FC<DeleteButtonProps> = ({
|
|
|
135
142
|
</Button>
|
|
136
143
|
<Button
|
|
137
144
|
color="red"
|
|
138
|
-
onClick={
|
|
139
|
-
onConfirm();
|
|
140
|
-
handlers.close();
|
|
141
|
-
}}
|
|
145
|
+
onClick={handleConfirm}
|
|
142
146
|
autoFocus
|
|
143
147
|
size="xs"
|
|
144
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)}
|
|
@@ -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
|
+
}
|