refine-mantine 1.0.0-dev.2 → 1.0.0-dev.3
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 +12 -5
- package/dist/index.js +165 -108
- package/package.json +1 -1
- package/src/components/buttons/CloneButton.story.tsx +13 -1
- package/src/components/buttons/CloneButton.tsx +61 -47
- package/src/components/buttons/CreateButton.story.tsx +14 -2
- package/src/components/buttons/CreateButton.tsx +60 -46
- package/src/components/buttons/DeleteButton.story.tsx +13 -1
- package/src/components/buttons/DeleteButton.tsx +18 -0
- package/src/components/buttons/EditButton.story.tsx +14 -2
- package/src/components/buttons/EditButton.tsx +41 -25
- package/src/components/buttons/ListButton.story.tsx +14 -2
- package/src/components/buttons/ListButton.tsx +59 -45
- package/src/components/buttons/ShowButton.story.tsx +13 -1
- package/src/components/buttons/ShowButton.tsx +58 -41
- package/src/components/crud/List.story.tsx +11 -16
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { ActionIconProps,
|
|
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";
|
|
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";
|
|
5
|
-
import { RefineBreadcrumbProps, RefineCreateButtonProps, RefineCrudCreateProps, RefineCrudEditProps, RefineCrudListProps, RefineCrudShowProps, RefineDeleteButtonProps, RefineEditButtonProps, RefineListButtonProps, RefineRefreshButtonProps, RefineSaveButtonProps, RefineShowButtonProps } from "@refinedev/ui-types";
|
|
6
5
|
import React$1, { ReactNode } from "react";
|
|
6
|
+
import { RefineBreadcrumbProps, RefineCreateButtonProps, RefineCrudCreateProps, RefineCrudEditProps, RefineCrudListProps, RefineCrudShowProps, RefineDeleteButtonProps, RefineEditButtonProps, RefineListButtonProps, RefineRefreshButtonProps, RefineSaveButtonProps, RefineShowButtonProps } from "@refinedev/ui-types";
|
|
7
7
|
import { FormValidateInput, UseFormInput, UseFormReturnType as UseFormReturnType$2 } from "@mantine/form";
|
|
8
8
|
import { Column } from "@tanstack/table-core";
|
|
9
9
|
import { UseTableReturnType } from "@refinedev/react-table";
|
|
@@ -15,10 +15,11 @@ declare const Breadcrumb: React$1.FC<BreadcrumbProps>;
|
|
|
15
15
|
//#region src/components/buttons/CreateButton.d.ts
|
|
16
16
|
type CreateButtonProps = RefineCreateButtonProps<{
|
|
17
17
|
iconProps?: IconProps;
|
|
18
|
-
anchorProps?: AnchorProps;
|
|
19
18
|
actionIconProps?: ActionIconProps;
|
|
20
19
|
buttonProps?: ButtonProps;
|
|
21
20
|
disabled?: boolean;
|
|
21
|
+
menuItem?: boolean;
|
|
22
|
+
menuItemProps?: MenuItemProps;
|
|
22
23
|
}>;
|
|
23
24
|
declare const CreateButton: React$1.FC<CreateButtonProps>;
|
|
24
25
|
//#endregion
|
|
@@ -29,26 +30,30 @@ type DeleteButtonProps = RefineDeleteButtonProps<{
|
|
|
29
30
|
actionIconProps?: ActionIconProps;
|
|
30
31
|
buttonProps?: ButtonProps;
|
|
31
32
|
disabled?: boolean;
|
|
33
|
+
menuItem?: boolean;
|
|
34
|
+
menuItemProps?: MenuItemProps;
|
|
32
35
|
}>;
|
|
33
36
|
declare const DeleteButton: React$1.FC<DeleteButtonProps>;
|
|
34
37
|
//#endregion
|
|
35
38
|
//#region src/components/buttons/EditButton.d.ts
|
|
36
39
|
type EditButtonProps = RefineEditButtonProps<{
|
|
37
40
|
iconProps?: IconProps;
|
|
38
|
-
anchorProps?: AnchorProps;
|
|
39
41
|
actionIconProps?: ActionIconProps;
|
|
40
42
|
buttonProps?: ButtonProps;
|
|
41
43
|
disabled?: boolean;
|
|
44
|
+
menuItem?: boolean;
|
|
45
|
+
menuItemProps?: MenuItemProps;
|
|
42
46
|
}>;
|
|
43
47
|
declare const EditButton: React$1.FC<EditButtonProps>;
|
|
44
48
|
//#endregion
|
|
45
49
|
//#region src/components/buttons/ListButton.d.ts
|
|
46
50
|
type ListButtonProps = RefineListButtonProps<{
|
|
47
51
|
iconProps?: IconProps;
|
|
48
|
-
anchorProps?: AnchorProps;
|
|
49
52
|
actionIconProps?: ActionIconProps;
|
|
50
53
|
buttonProps?: ButtonProps;
|
|
51
54
|
disabled?: boolean;
|
|
55
|
+
menuItem?: boolean;
|
|
56
|
+
menuItemProps?: MenuItemProps;
|
|
52
57
|
}>;
|
|
53
58
|
declare const ListButton: React$1.FC<ListButtonProps>;
|
|
54
59
|
//#endregion
|
|
@@ -76,6 +81,8 @@ type ShowButtonProps = RefineShowButtonProps<{
|
|
|
76
81
|
actionIconProps?: ActionIconProps;
|
|
77
82
|
buttonProps?: ButtonProps;
|
|
78
83
|
disabled?: boolean;
|
|
84
|
+
menuItem?: boolean;
|
|
85
|
+
menuItemProps?: MenuItemProps;
|
|
79
86
|
}>;
|
|
80
87
|
declare const ShowButton: React$1.FC<ShowButtonProps>;
|
|
81
88
|
//#endregion
|
package/dist/index.js
CHANGED
|
@@ -2,9 +2,9 @@ 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
6
|
import { useDebouncedCallback, useDisclosure } from "@mantine/hooks";
|
|
6
7
|
import { RefinePageHeaderClassNames } from "@refinedev/ui-types";
|
|
7
|
-
import { useCallback, useEffect, useState } from "react";
|
|
8
8
|
import { flexRender } from "@tanstack/react-table";
|
|
9
9
|
import { isEmail, isNotEmpty, useForm as useForm$2 } from "@mantine/form";
|
|
10
10
|
import { hideNotification, showNotification, updateNotification } from "@mantine/notifications";
|
|
@@ -52,18 +52,16 @@ const Breadcrumb = ({ breadcrumbProps, showHome = true, hideIcons = false, meta,
|
|
|
52
52
|
|
|
53
53
|
//#endregion
|
|
54
54
|
//#region src/components/buttons/CreateButton.tsx
|
|
55
|
-
const CreateButton = ({ resource, hideText = false, accessControl, meta, children, iconProps,
|
|
55
|
+
const CreateButton = ({ resource, hideText = false, accessControl, meta, children, iconProps, actionIconProps, buttonProps, disabled: disabledFromProps, menuItem, menuItemProps, onClick }) => {
|
|
56
56
|
const { to, label, title, disabled: disabledFromHook, hidden, LinkComponent } = useCreateButton({
|
|
57
57
|
resource,
|
|
58
58
|
accessControl,
|
|
59
59
|
meta
|
|
60
60
|
});
|
|
61
|
-
if (hidden) return null;
|
|
62
61
|
const disabled = disabledFromProps || disabledFromHook;
|
|
63
|
-
|
|
62
|
+
const actionProps = {
|
|
64
63
|
component: LinkComponent,
|
|
65
|
-
|
|
66
|
-
onClick: (e) => {
|
|
64
|
+
onClick: useCallback((e) => {
|
|
67
65
|
if (disabled) {
|
|
68
66
|
e.preventDefault();
|
|
69
67
|
return;
|
|
@@ -72,36 +70,49 @@ const CreateButton = ({ resource, hideText = false, accessControl, meta, childre
|
|
|
72
70
|
e.preventDefault();
|
|
73
71
|
onClick(e);
|
|
74
72
|
}
|
|
75
|
-
},
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
leftSection: /* @__PURE__ */ jsx(IconSquarePlus, {
|
|
91
|
-
size: 18,
|
|
92
|
-
...iconProps
|
|
93
|
-
}),
|
|
94
|
-
title,
|
|
95
|
-
variant: "filled",
|
|
96
|
-
...buttonProps,
|
|
97
|
-
children: children ?? label
|
|
73
|
+
}, [disabled, onClick]),
|
|
74
|
+
to
|
|
75
|
+
};
|
|
76
|
+
if (hidden) return null;
|
|
77
|
+
return hideText ? /* @__PURE__ */ jsx(ActionIcon, {
|
|
78
|
+
title,
|
|
79
|
+
disabled,
|
|
80
|
+
"aria-label": label,
|
|
81
|
+
variant: "filled",
|
|
82
|
+
size: "md",
|
|
83
|
+
...actionProps,
|
|
84
|
+
...actionIconProps,
|
|
85
|
+
children: /* @__PURE__ */ jsx(IconSquarePlus, {
|
|
86
|
+
size: 18,
|
|
87
|
+
...iconProps
|
|
98
88
|
})
|
|
89
|
+
}) : menuItem ? /* @__PURE__ */ jsx(Menu.Item, {
|
|
90
|
+
disabled,
|
|
91
|
+
leftSection: /* @__PURE__ */ jsx(IconSquarePlus, {
|
|
92
|
+
size: 14,
|
|
93
|
+
...iconProps
|
|
94
|
+
}),
|
|
95
|
+
title,
|
|
96
|
+
...actionProps,
|
|
97
|
+
...menuItemProps,
|
|
98
|
+
children: children ?? label
|
|
99
|
+
}) : /* @__PURE__ */ jsx(Button, {
|
|
100
|
+
disabled,
|
|
101
|
+
leftSection: /* @__PURE__ */ jsx(IconSquarePlus, {
|
|
102
|
+
size: 18,
|
|
103
|
+
...iconProps
|
|
104
|
+
}),
|
|
105
|
+
title,
|
|
106
|
+
variant: "filled",
|
|
107
|
+
...actionProps,
|
|
108
|
+
...buttonProps,
|
|
109
|
+
children: children ?? label
|
|
99
110
|
});
|
|
100
111
|
};
|
|
101
112
|
|
|
102
113
|
//#endregion
|
|
103
114
|
//#region src/components/buttons/DeleteButton.tsx
|
|
104
|
-
const DeleteButton = ({ resource, recordItemId, mutationMode, invalidates, children, successNotification, errorNotification, hideText = false, accessControl, meta, dataProviderName, confirmTitle, confirmOkText, confirmCancelText, iconProps, popoverProps, actionIconProps, buttonProps, disabled: disabledFromProps, onSuccess }) => {
|
|
115
|
+
const DeleteButton = ({ resource, recordItemId, mutationMode, invalidates, children, successNotification, errorNotification, hideText = false, accessControl, meta, dataProviderName, confirmTitle, confirmOkText, confirmCancelText, iconProps, popoverProps, actionIconProps, buttonProps, disabled: disabledFromProps, menuItem, menuItemProps, onSuccess }) => {
|
|
105
116
|
const { title, label, hidden, disabled: disabledFromHook, loading, confirmTitle: defaultConfirmTitle, confirmOkLabel: defaultConfirmOkLabel, cancelLabel: defaultCancelLabel, onConfirm } = useDeleteButton({
|
|
106
117
|
resource,
|
|
107
118
|
id: recordItemId,
|
|
@@ -135,6 +146,18 @@ const DeleteButton = ({ resource, recordItemId, mutationMode, invalidates, child
|
|
|
135
146
|
size: 18,
|
|
136
147
|
...iconProps
|
|
137
148
|
})
|
|
149
|
+
}) : menuItem ? /* @__PURE__ */ jsx(Menu.Item, {
|
|
150
|
+
color: "red",
|
|
151
|
+
onClick: handlers.toggle,
|
|
152
|
+
disabled,
|
|
153
|
+
leftSection: /* @__PURE__ */ jsx(IconTrash, {
|
|
154
|
+
size: 14,
|
|
155
|
+
...iconProps
|
|
156
|
+
}),
|
|
157
|
+
title,
|
|
158
|
+
closeMenuOnClick: false,
|
|
159
|
+
...menuItemProps,
|
|
160
|
+
children: children ?? label
|
|
138
161
|
}) : /* @__PURE__ */ jsx(Button, {
|
|
139
162
|
color: "red",
|
|
140
163
|
variant: "outline",
|
|
@@ -174,19 +197,17 @@ const DeleteButton = ({ resource, recordItemId, mutationMode, invalidates, child
|
|
|
174
197
|
|
|
175
198
|
//#endregion
|
|
176
199
|
//#region src/components/buttons/EditButton.tsx
|
|
177
|
-
const EditButton = ({ resource, recordItemId, hideText = false, accessControl, meta, children, iconProps,
|
|
200
|
+
const EditButton = ({ resource, recordItemId, hideText = false, accessControl, meta, children, iconProps, actionIconProps, buttonProps, disabled: disabledFromProps, menuItem, menuItemProps, onClick }) => {
|
|
178
201
|
const { to, label, title, disabled: disabledFromHook, hidden, LinkComponent } = useEditButton({
|
|
179
202
|
resource,
|
|
180
203
|
id: recordItemId,
|
|
181
204
|
accessControl,
|
|
182
205
|
meta
|
|
183
206
|
});
|
|
184
|
-
if (hidden) return null;
|
|
185
207
|
const disabled = disabledFromProps || disabledFromHook;
|
|
186
|
-
|
|
208
|
+
const actionProps = {
|
|
187
209
|
component: LinkComponent,
|
|
188
|
-
|
|
189
|
-
onClick: (e) => {
|
|
210
|
+
onClick: useCallback((e) => {
|
|
190
211
|
if (disabled) {
|
|
191
212
|
e.preventDefault();
|
|
192
213
|
return;
|
|
@@ -195,46 +216,57 @@ const EditButton = ({ resource, recordItemId, hideText = false, accessControl, m
|
|
|
195
216
|
e.preventDefault();
|
|
196
217
|
onClick(e);
|
|
197
218
|
}
|
|
198
|
-
},
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
disabled,
|
|
213
|
-
leftSection: /* @__PURE__ */ jsx(IconPencil, {
|
|
214
|
-
size: 18,
|
|
215
|
-
...iconProps
|
|
216
|
-
}),
|
|
217
|
-
title,
|
|
218
|
-
...buttonProps,
|
|
219
|
-
children: children ?? label
|
|
219
|
+
}, [disabled, onClick]),
|
|
220
|
+
to
|
|
221
|
+
};
|
|
222
|
+
if (hidden) return null;
|
|
223
|
+
return hideText ? /* @__PURE__ */ jsx(ActionIcon, {
|
|
224
|
+
title,
|
|
225
|
+
disabled,
|
|
226
|
+
"aria-label": label,
|
|
227
|
+
variant: "default",
|
|
228
|
+
...actionProps,
|
|
229
|
+
...actionIconProps,
|
|
230
|
+
children: /* @__PURE__ */ jsx(IconPencil, {
|
|
231
|
+
size: 18,
|
|
232
|
+
...iconProps
|
|
220
233
|
})
|
|
234
|
+
}) : menuItem ? /* @__PURE__ */ jsx(Menu.Item, {
|
|
235
|
+
disabled,
|
|
236
|
+
leftSection: /* @__PURE__ */ jsx(IconPencil, {
|
|
237
|
+
size: 14,
|
|
238
|
+
...iconProps
|
|
239
|
+
}),
|
|
240
|
+
title,
|
|
241
|
+
...actionProps,
|
|
242
|
+
...menuItemProps,
|
|
243
|
+
children: children ?? label
|
|
244
|
+
}) : /* @__PURE__ */ jsx(Button, {
|
|
245
|
+
variant: "default",
|
|
246
|
+
disabled,
|
|
247
|
+
leftSection: /* @__PURE__ */ jsx(IconPencil, {
|
|
248
|
+
size: 18,
|
|
249
|
+
...iconProps
|
|
250
|
+
}),
|
|
251
|
+
title,
|
|
252
|
+
...actionProps,
|
|
253
|
+
...buttonProps,
|
|
254
|
+
children: children ?? label
|
|
221
255
|
});
|
|
222
256
|
};
|
|
223
257
|
|
|
224
258
|
//#endregion
|
|
225
259
|
//#region src/components/buttons/ListButton.tsx
|
|
226
|
-
const ListButton = ({ resource, hideText = false, accessControl, meta, children, iconProps, actionIconProps, buttonProps,
|
|
260
|
+
const ListButton = ({ resource, hideText = false, accessControl, meta, children, iconProps, actionIconProps, buttonProps, disabled: disabledFromProps, menuItem, menuItemProps, onClick }) => {
|
|
227
261
|
const { to, label, title, disabled: disabledFromHook, hidden, LinkComponent } = useListButton({
|
|
228
262
|
resource,
|
|
229
263
|
accessControl,
|
|
230
264
|
meta
|
|
231
265
|
});
|
|
232
|
-
if (hidden) return null;
|
|
233
266
|
const disabled = disabledFromProps || disabledFromHook;
|
|
234
|
-
|
|
267
|
+
const actionProps = {
|
|
235
268
|
component: LinkComponent,
|
|
236
|
-
|
|
237
|
-
onClick: (e) => {
|
|
269
|
+
onClick: useCallback((e) => {
|
|
238
270
|
if (disabled) {
|
|
239
271
|
e.preventDefault();
|
|
240
272
|
return;
|
|
@@ -243,28 +275,41 @@ const ListButton = ({ resource, hideText = false, accessControl, meta, children,
|
|
|
243
275
|
e.preventDefault();
|
|
244
276
|
onClick(e);
|
|
245
277
|
}
|
|
246
|
-
},
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
disabled,
|
|
260
|
-
leftSection: /* @__PURE__ */ jsx(IconList, {
|
|
261
|
-
size: 18,
|
|
262
|
-
...iconProps
|
|
263
|
-
}),
|
|
264
|
-
title,
|
|
265
|
-
...buttonProps,
|
|
266
|
-
children: children ?? label
|
|
278
|
+
}, [disabled, onClick]),
|
|
279
|
+
to
|
|
280
|
+
};
|
|
281
|
+
if (hidden) return null;
|
|
282
|
+
return hideText ? /* @__PURE__ */ jsx(ActionIcon, {
|
|
283
|
+
variant: "default",
|
|
284
|
+
disabled,
|
|
285
|
+
title,
|
|
286
|
+
...actionProps,
|
|
287
|
+
...actionIconProps,
|
|
288
|
+
children: /* @__PURE__ */ jsx(IconList, {
|
|
289
|
+
size: 18,
|
|
290
|
+
...iconProps
|
|
267
291
|
})
|
|
292
|
+
}) : menuItem ? /* @__PURE__ */ jsx(Menu.Item, {
|
|
293
|
+
disabled,
|
|
294
|
+
leftSection: /* @__PURE__ */ jsx(IconList, {
|
|
295
|
+
size: 14,
|
|
296
|
+
...iconProps
|
|
297
|
+
}),
|
|
298
|
+
title,
|
|
299
|
+
...actionProps,
|
|
300
|
+
...menuItemProps,
|
|
301
|
+
children: children ?? label
|
|
302
|
+
}) : /* @__PURE__ */ jsx(Button, {
|
|
303
|
+
variant: "default",
|
|
304
|
+
disabled,
|
|
305
|
+
leftSection: /* @__PURE__ */ jsx(IconList, {
|
|
306
|
+
size: 18,
|
|
307
|
+
...iconProps
|
|
308
|
+
}),
|
|
309
|
+
title,
|
|
310
|
+
...actionProps,
|
|
311
|
+
...buttonProps,
|
|
312
|
+
children: children ?? label
|
|
268
313
|
});
|
|
269
314
|
};
|
|
270
315
|
|
|
@@ -330,19 +375,17 @@ const SaveButton = ({ hideText = false, children, iconProps, actionIconProps, bu
|
|
|
330
375
|
|
|
331
376
|
//#endregion
|
|
332
377
|
//#region src/components/buttons/ShowButton.tsx
|
|
333
|
-
const ShowButton = ({ resource, recordItemId, hideText = false, accessControl, meta, children, iconProps, actionIconProps, buttonProps, disabled: disabledFromProps, onClick }) => {
|
|
378
|
+
const ShowButton = ({ resource, recordItemId, hideText = false, accessControl, meta, children, iconProps, actionIconProps, buttonProps, disabled: disabledFromProps, menuItem, menuItemProps, onClick }) => {
|
|
334
379
|
const { to, label, title, disabled: disabledFromHook, hidden, LinkComponent } = useShowButton({
|
|
335
380
|
resource,
|
|
336
381
|
id: recordItemId,
|
|
337
382
|
accessControl,
|
|
338
383
|
meta
|
|
339
384
|
});
|
|
340
|
-
if (hidden) return null;
|
|
341
385
|
const disabled = disabledFromProps || disabledFromHook;
|
|
342
|
-
|
|
386
|
+
const actionProps = {
|
|
343
387
|
component: LinkComponent,
|
|
344
|
-
|
|
345
|
-
onClick: (e) => {
|
|
388
|
+
onClick: useCallback((e) => {
|
|
346
389
|
if (disabled) {
|
|
347
390
|
e.preventDefault();
|
|
348
391
|
return;
|
|
@@ -351,27 +394,41 @@ const ShowButton = ({ resource, recordItemId, hideText = false, accessControl, m
|
|
|
351
394
|
e.preventDefault();
|
|
352
395
|
onClick(e);
|
|
353
396
|
}
|
|
354
|
-
},
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
leftSection: /* @__PURE__ */ jsx(IconEye, {
|
|
368
|
-
size: 18,
|
|
369
|
-
...iconProps
|
|
370
|
-
}),
|
|
371
|
-
title,
|
|
372
|
-
...buttonProps,
|
|
373
|
-
children: children ?? label
|
|
397
|
+
}, [disabled, onClick]),
|
|
398
|
+
to
|
|
399
|
+
};
|
|
400
|
+
if (hidden) return null;
|
|
401
|
+
return hideText ? /* @__PURE__ */ jsx(ActionIcon, {
|
|
402
|
+
variant: "default",
|
|
403
|
+
disabled,
|
|
404
|
+
title,
|
|
405
|
+
...actionProps,
|
|
406
|
+
...actionIconProps,
|
|
407
|
+
children: /* @__PURE__ */ jsx(IconEye, {
|
|
408
|
+
size: 18,
|
|
409
|
+
...iconProps
|
|
374
410
|
})
|
|
411
|
+
}) : menuItem ? /* @__PURE__ */ jsx(Menu.Item, {
|
|
412
|
+
disabled,
|
|
413
|
+
leftSection: /* @__PURE__ */ jsx(IconEye, {
|
|
414
|
+
size: 14,
|
|
415
|
+
...iconProps
|
|
416
|
+
}),
|
|
417
|
+
title,
|
|
418
|
+
...actionProps,
|
|
419
|
+
...menuItemProps,
|
|
420
|
+
children: children ?? label
|
|
421
|
+
}) : /* @__PURE__ */ jsx(Button, {
|
|
422
|
+
variant: "default",
|
|
423
|
+
disabled,
|
|
424
|
+
leftSection: /* @__PURE__ */ jsx(IconEye, {
|
|
425
|
+
size: 18,
|
|
426
|
+
...iconProps
|
|
427
|
+
}),
|
|
428
|
+
title,
|
|
429
|
+
...actionProps,
|
|
430
|
+
...buttonProps,
|
|
431
|
+
children: children ?? label
|
|
375
432
|
});
|
|
376
433
|
};
|
|
377
434
|
|
package/package.json
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { Stack } from "@mantine/core";
|
|
1
|
+
import { ActionIcon, Menu, Stack } from "@mantine/core";
|
|
2
2
|
import type { Meta } from "@storybook/react";
|
|
3
|
+
import { IconDots } from "@tabler/icons-react";
|
|
3
4
|
import { CloneButton } from "./CloneButton";
|
|
4
5
|
|
|
5
6
|
export default {
|
|
@@ -20,3 +21,14 @@ export const HideText = () =>
|
|
|
20
21
|
|
|
21
22
|
export const Disabled = () =>
|
|
22
23
|
<CloneButton disabled />;
|
|
24
|
+
|
|
25
|
+
export const MenuItem = () =>
|
|
26
|
+
<Menu shadow="md" width={200}>
|
|
27
|
+
<Menu.Target>
|
|
28
|
+
<ActionIcon variant="default"><IconDots size={16} /></ActionIcon>
|
|
29
|
+
</Menu.Target>
|
|
30
|
+
<Menu.Dropdown>
|
|
31
|
+
<Menu.Label>Clone Button</Menu.Label>
|
|
32
|
+
<CloneButton menuItem />
|
|
33
|
+
</Menu.Dropdown>
|
|
34
|
+
</Menu>;
|
|
@@ -1,21 +1,23 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ActionIcon,
|
|
3
3
|
type ActionIconProps,
|
|
4
|
-
Anchor,
|
|
5
|
-
type AnchorProps,
|
|
6
4
|
Button,
|
|
7
5
|
type ButtonProps,
|
|
6
|
+
Menu,
|
|
7
|
+
type MenuItemProps
|
|
8
8
|
} from "@mantine/core";
|
|
9
9
|
import { useCloneButton } from "@refinedev/core";
|
|
10
10
|
import type { RefineCloneButtonProps } from "@refinedev/ui-types";
|
|
11
|
-
import { type IconProps
|
|
11
|
+
import { IconLibraryPlus, type IconProps } from "@tabler/icons-react";
|
|
12
|
+
import { useCallback } from "react";
|
|
12
13
|
|
|
13
14
|
export type CloneButtonProps = RefineCloneButtonProps<{
|
|
14
15
|
iconProps?: IconProps;
|
|
15
|
-
anchorProps?: AnchorProps;
|
|
16
16
|
actionIconProps?: ActionIconProps;
|
|
17
17
|
buttonProps?: ButtonProps;
|
|
18
18
|
disabled?: boolean;
|
|
19
|
+
menuItem?: boolean;
|
|
20
|
+
menuItemProps?: MenuItemProps;
|
|
19
21
|
}>;
|
|
20
22
|
|
|
21
23
|
export const CloneButton: React.FC<CloneButtonProps> = ({
|
|
@@ -27,9 +29,10 @@ export const CloneButton: React.FC<CloneButtonProps> = ({
|
|
|
27
29
|
children,
|
|
28
30
|
iconProps,
|
|
29
31
|
actionIconProps,
|
|
30
|
-
anchorProps,
|
|
31
32
|
buttonProps,
|
|
32
33
|
disabled: disabledFromProps,
|
|
34
|
+
menuItem,
|
|
35
|
+
menuItemProps,
|
|
33
36
|
onClick,
|
|
34
37
|
}) => {
|
|
35
38
|
const { to, label, title, hidden, disabled: disabledFromHook, LinkComponent } = useCloneButton({
|
|
@@ -39,48 +42,59 @@ export const CloneButton: React.FC<CloneButtonProps> = ({
|
|
|
39
42
|
meta,
|
|
40
43
|
});
|
|
41
44
|
|
|
42
|
-
if (hidden) return null;
|
|
43
|
-
|
|
44
45
|
const disabled = disabledFromProps || disabledFromHook;
|
|
45
46
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
47
|
+
const handleClick = useCallback((e: React.PointerEvent<HTMLButtonElement>) => {
|
|
48
|
+
if (disabled) {
|
|
49
|
+
e.preventDefault();
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
if (onClick) {
|
|
53
|
+
e.preventDefault();
|
|
54
|
+
onClick(e);
|
|
55
|
+
}
|
|
56
|
+
}, [disabled, onClick]);
|
|
57
|
+
|
|
58
|
+
const actionProps = {
|
|
59
|
+
// biome-ignore lint/suspicious/noExplicitAny: that's fine
|
|
60
|
+
component: LinkComponent as any,
|
|
61
|
+
onClick: handleClick,
|
|
62
|
+
to,
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (hidden) return null;
|
|
66
|
+
|
|
67
|
+
return hideText ? (
|
|
68
|
+
<ActionIcon
|
|
69
|
+
variant="default"
|
|
70
|
+
disabled={disabled}
|
|
71
|
+
title={title}
|
|
72
|
+
aria-label={label}
|
|
73
|
+
{...actionProps}
|
|
74
|
+
{...actionIconProps}
|
|
75
|
+
>
|
|
76
|
+
<IconLibraryPlus size={18} {...iconProps} />
|
|
77
|
+
</ActionIcon>
|
|
78
|
+
) : menuItem ? (
|
|
79
|
+
<Menu.Item
|
|
80
|
+
disabled={disabled}
|
|
81
|
+
leftSection={<IconLibraryPlus size={14} {...iconProps} />}
|
|
82
|
+
title={title}
|
|
83
|
+
{...actionProps}
|
|
84
|
+
{...menuItemProps}
|
|
85
|
+
>
|
|
86
|
+
{children ?? label}
|
|
87
|
+
</Menu.Item>
|
|
88
|
+
) : (
|
|
89
|
+
<Button
|
|
90
|
+
variant="default"
|
|
91
|
+
disabled={disabled}
|
|
92
|
+
leftSection={<IconLibraryPlus size={18} {...iconProps} />}
|
|
93
|
+
title={title}
|
|
94
|
+
{...actionProps}
|
|
95
|
+
{...buttonProps}
|
|
96
|
+
>
|
|
97
|
+
{children ?? label}
|
|
98
|
+
</Button>
|
|
99
|
+
);
|
|
86
100
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { Stack } from "@mantine/core";
|
|
1
|
+
import { ActionIcon, Menu, Stack } from "@mantine/core";
|
|
2
2
|
import type { Meta } from "@storybook/react";
|
|
3
|
+
import { IconDots } from "@tabler/icons-react";
|
|
3
4
|
import { CreateButton } from "./CreateButton";
|
|
4
5
|
|
|
5
6
|
export default {
|
|
@@ -19,4 +20,15 @@ export const HideText = () =>
|
|
|
19
20
|
<CreateButton hideText />;
|
|
20
21
|
|
|
21
22
|
export const Disabled = () =>
|
|
22
|
-
<CreateButton disabled />;
|
|
23
|
+
<CreateButton disabled />;
|
|
24
|
+
|
|
25
|
+
export const MenuItem = () =>
|
|
26
|
+
<Menu shadow="md" width={200}>
|
|
27
|
+
<Menu.Target>
|
|
28
|
+
<ActionIcon variant="default"><IconDots size={16} /></ActionIcon>
|
|
29
|
+
</Menu.Target>
|
|
30
|
+
<Menu.Dropdown>
|
|
31
|
+
<Menu.Label>Create Button</Menu.Label>
|
|
32
|
+
<CreateButton menuItem />
|
|
33
|
+
</Menu.Dropdown>
|
|
34
|
+
</Menu>;
|