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
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
import { ActionIcon, type ActionIconProps,
|
|
1
|
+
import { ActionIcon, type ActionIconProps, Button, type ButtonProps, Menu, type MenuItemProps } from "@mantine/core";
|
|
2
2
|
import { useCreateButton } from "@refinedev/core";
|
|
3
3
|
import type { RefineCreateButtonProps } from "@refinedev/ui-types";
|
|
4
4
|
import { type IconProps, IconSquarePlus } from "@tabler/icons-react";
|
|
5
5
|
import type React from "react";
|
|
6
|
+
import { useCallback } from "react";
|
|
6
7
|
|
|
7
8
|
export type CreateButtonProps = RefineCreateButtonProps<{
|
|
8
9
|
iconProps?: IconProps;
|
|
9
|
-
anchorProps?: AnchorProps;
|
|
10
10
|
actionIconProps?: ActionIconProps;
|
|
11
11
|
buttonProps?: ButtonProps;
|
|
12
12
|
disabled?: boolean;
|
|
13
|
+
menuItem?: boolean;
|
|
14
|
+
menuItemProps?: MenuItemProps;
|
|
13
15
|
}>;
|
|
14
16
|
|
|
15
17
|
export const CreateButton: React.FC<CreateButtonProps> = ({
|
|
@@ -19,10 +21,11 @@ export const CreateButton: React.FC<CreateButtonProps> = ({
|
|
|
19
21
|
meta,
|
|
20
22
|
children,
|
|
21
23
|
iconProps,
|
|
22
|
-
anchorProps,
|
|
23
24
|
actionIconProps,
|
|
24
25
|
buttonProps,
|
|
25
26
|
disabled: disabledFromProps,
|
|
27
|
+
menuItem,
|
|
28
|
+
menuItemProps,
|
|
26
29
|
onClick,
|
|
27
30
|
}) => {
|
|
28
31
|
const { to, label, title, disabled: disabledFromHook, hidden, LinkComponent } = useCreateButton(
|
|
@@ -33,49 +36,60 @@ export const CreateButton: React.FC<CreateButtonProps> = ({
|
|
|
33
36
|
},
|
|
34
37
|
);
|
|
35
38
|
|
|
36
|
-
if (hidden) return null;
|
|
37
|
-
|
|
38
39
|
const disabled = disabledFromProps || disabledFromHook;
|
|
39
40
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
-
|
|
41
|
+
const handleClick = useCallback((e: React.PointerEvent<HTMLButtonElement>) => {
|
|
42
|
+
if (disabled) {
|
|
43
|
+
e.preventDefault();
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
if (onClick) {
|
|
47
|
+
e.preventDefault();
|
|
48
|
+
onClick(e);
|
|
49
|
+
}
|
|
50
|
+
}, [disabled, onClick]);
|
|
51
|
+
|
|
52
|
+
const actionProps = {
|
|
53
|
+
// biome-ignore lint/suspicious/noExplicitAny: that's fine
|
|
54
|
+
component: LinkComponent as any,
|
|
55
|
+
onClick: handleClick,
|
|
56
|
+
to,
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (hidden) return null;
|
|
60
|
+
|
|
61
|
+
return hideText ? (
|
|
62
|
+
<ActionIcon
|
|
63
|
+
title={title}
|
|
64
|
+
disabled={disabled}
|
|
65
|
+
aria-label={label}
|
|
66
|
+
variant="filled"
|
|
67
|
+
size="md"
|
|
68
|
+
{...actionProps}
|
|
69
|
+
{...actionIconProps}
|
|
70
|
+
>
|
|
71
|
+
<IconSquarePlus size={18} {...iconProps} />
|
|
72
|
+
</ActionIcon>
|
|
73
|
+
) : menuItem ? (
|
|
74
|
+
<Menu.Item
|
|
75
|
+
disabled={disabled}
|
|
76
|
+
leftSection={<IconSquarePlus size={14} {...iconProps} />}
|
|
77
|
+
title={title}
|
|
78
|
+
{...actionProps}
|
|
79
|
+
{...menuItemProps}
|
|
80
|
+
>
|
|
81
|
+
{children ?? label}
|
|
82
|
+
</Menu.Item>
|
|
83
|
+
) : (
|
|
84
|
+
<Button
|
|
85
|
+
disabled={disabled}
|
|
86
|
+
leftSection={<IconSquarePlus size={18} {...iconProps} />}
|
|
87
|
+
title={title}
|
|
88
|
+
variant="filled"
|
|
89
|
+
{...actionProps}
|
|
90
|
+
{...buttonProps}
|
|
91
|
+
>
|
|
92
|
+
{children ?? label}
|
|
93
|
+
</Button>
|
|
94
|
+
);
|
|
81
95
|
};
|
|
@@ -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 { DeleteButton } from "./DeleteButton";
|
|
4
5
|
|
|
5
6
|
export default {
|
|
@@ -20,3 +21,14 @@ export const HideText = () =>
|
|
|
20
21
|
|
|
21
22
|
export const Disabled = () =>
|
|
22
23
|
<DeleteButton 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>Delete Button</Menu.Label>
|
|
32
|
+
<DeleteButton menuItem />
|
|
33
|
+
</Menu.Dropdown>
|
|
34
|
+
</Menu>;
|
|
@@ -4,6 +4,8 @@ import {
|
|
|
4
4
|
Button,
|
|
5
5
|
type ButtonProps,
|
|
6
6
|
Group,
|
|
7
|
+
Menu,
|
|
8
|
+
type MenuItemProps,
|
|
7
9
|
Popover,
|
|
8
10
|
type PopoverProps,
|
|
9
11
|
Text,
|
|
@@ -20,6 +22,8 @@ export type DeleteButtonProps = RefineDeleteButtonProps<{
|
|
|
20
22
|
actionIconProps?: ActionIconProps;
|
|
21
23
|
buttonProps?: ButtonProps;
|
|
22
24
|
disabled?: boolean;
|
|
25
|
+
menuItem?: boolean;
|
|
26
|
+
menuItemProps?: MenuItemProps;
|
|
23
27
|
}>;
|
|
24
28
|
|
|
25
29
|
export const DeleteButton: React.FC<DeleteButtonProps> = ({
|
|
@@ -42,6 +46,8 @@ export const DeleteButton: React.FC<DeleteButtonProps> = ({
|
|
|
42
46
|
actionIconProps,
|
|
43
47
|
buttonProps,
|
|
44
48
|
disabled: disabledFromProps,
|
|
49
|
+
menuItem,
|
|
50
|
+
menuItemProps,
|
|
45
51
|
onSuccess,
|
|
46
52
|
}) => {
|
|
47
53
|
const {
|
|
@@ -94,6 +100,18 @@ export const DeleteButton: React.FC<DeleteButtonProps> = ({
|
|
|
94
100
|
>
|
|
95
101
|
<IconTrash size={18} {...iconProps} />
|
|
96
102
|
</ActionIcon>
|
|
103
|
+
) : menuItem ? (
|
|
104
|
+
<Menu.Item
|
|
105
|
+
color="red"
|
|
106
|
+
onClick={handlers.toggle}
|
|
107
|
+
disabled={disabled}
|
|
108
|
+
leftSection={<IconTrash size={14} {...iconProps} />}
|
|
109
|
+
title={title}
|
|
110
|
+
closeMenuOnClick={false}
|
|
111
|
+
{...menuItemProps}
|
|
112
|
+
>
|
|
113
|
+
{children ?? label}
|
|
114
|
+
</Menu.Item>
|
|
97
115
|
) : (
|
|
98
116
|
<Button
|
|
99
117
|
color="red"
|
|
@@ -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 { EditButton } from "./EditButton";
|
|
4
5
|
|
|
5
6
|
export default {
|
|
@@ -19,4 +20,15 @@ export const HideText = () =>
|
|
|
19
20
|
<EditButton hideText />;
|
|
20
21
|
|
|
21
22
|
export const Disabled = () =>
|
|
22
|
-
<EditButton disabled />;
|
|
23
|
+
<EditButton 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>Edit Button</Menu.Label>
|
|
32
|
+
<EditButton menuItem />
|
|
33
|
+
</Menu.Dropdown>
|
|
34
|
+
</Menu>;
|
|
@@ -1,22 +1,24 @@
|
|
|
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 { useEditButton } from "@refinedev/core";
|
|
10
10
|
import type { RefineEditButtonProps } from "@refinedev/ui-types";
|
|
11
11
|
import { IconPencil, type IconProps } from "@tabler/icons-react";
|
|
12
12
|
import type React from "react";
|
|
13
|
+
import { useCallback } from "react";
|
|
13
14
|
|
|
14
15
|
export type EditButtonProps = RefineEditButtonProps<{
|
|
15
16
|
iconProps?: IconProps;
|
|
16
|
-
anchorProps?: AnchorProps;
|
|
17
17
|
actionIconProps?: ActionIconProps;
|
|
18
18
|
buttonProps?: ButtonProps;
|
|
19
19
|
disabled?: boolean;
|
|
20
|
+
menuItem?: boolean;
|
|
21
|
+
menuItemProps?: MenuItemProps;
|
|
20
22
|
}>;
|
|
21
23
|
|
|
22
24
|
export const EditButton: React.FC<EditButtonProps> = ({
|
|
@@ -27,10 +29,11 @@ export const EditButton: React.FC<EditButtonProps> = ({
|
|
|
27
29
|
meta,
|
|
28
30
|
children,
|
|
29
31
|
iconProps,
|
|
30
|
-
anchorProps,
|
|
31
32
|
actionIconProps,
|
|
32
33
|
buttonProps,
|
|
33
34
|
disabled: disabledFromProps,
|
|
35
|
+
menuItem,
|
|
36
|
+
menuItemProps,
|
|
34
37
|
onClick,
|
|
35
38
|
}) => {
|
|
36
39
|
const { to, label, title, disabled: disabledFromHook, hidden, LinkComponent } = useEditButton({
|
|
@@ -40,48 +43,61 @@ export const EditButton: React.FC<EditButtonProps> = ({
|
|
|
40
43
|
meta,
|
|
41
44
|
});
|
|
42
45
|
|
|
43
|
-
if (hidden) return null;
|
|
44
|
-
|
|
45
46
|
const disabled = disabledFromProps || disabledFromHook;
|
|
46
47
|
|
|
48
|
+
const handleClick = useCallback((e: React.PointerEvent<HTMLButtonElement>) => {
|
|
49
|
+
if (disabled) {
|
|
50
|
+
e.preventDefault();
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
if (onClick) {
|
|
54
|
+
e.preventDefault();
|
|
55
|
+
onClick(e);
|
|
56
|
+
}
|
|
57
|
+
}, [disabled, onClick]);
|
|
58
|
+
|
|
59
|
+
const actionProps = {
|
|
60
|
+
// biome-ignore lint/suspicious/noExplicitAny: that's fine
|
|
61
|
+
component: LinkComponent as any,
|
|
62
|
+
onClick: handleClick,
|
|
63
|
+
to,
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (hidden) return null;
|
|
67
|
+
|
|
47
68
|
return (
|
|
48
|
-
|
|
49
|
-
// biome-ignore lint/suspicious/noExplicitAny: refine tzpes are messed up
|
|
50
|
-
component={LinkComponent as any}
|
|
51
|
-
to={to}
|
|
52
|
-
onClick={(e: React.PointerEvent<HTMLButtonElement>) => {
|
|
53
|
-
if (disabled) {
|
|
54
|
-
e.preventDefault();
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
if (onClick) {
|
|
58
|
-
e.preventDefault();
|
|
59
|
-
onClick(e);
|
|
60
|
-
}
|
|
61
|
-
}}
|
|
62
|
-
{...anchorProps}
|
|
63
|
-
>
|
|
64
|
-
{hideText ? (
|
|
69
|
+
hideText ? (
|
|
65
70
|
<ActionIcon
|
|
66
71
|
title={title}
|
|
67
72
|
disabled={disabled}
|
|
68
73
|
aria-label={label}
|
|
69
74
|
variant="default"
|
|
75
|
+
{...actionProps}
|
|
70
76
|
{...actionIconProps}
|
|
71
77
|
>
|
|
72
78
|
<IconPencil size={18} {...iconProps} />
|
|
73
79
|
</ActionIcon>
|
|
80
|
+
) : menuItem ? (
|
|
81
|
+
<Menu.Item
|
|
82
|
+
disabled={disabled}
|
|
83
|
+
leftSection={<IconPencil size={14} {...iconProps} />}
|
|
84
|
+
title={title}
|
|
85
|
+
{...actionProps}
|
|
86
|
+
{...menuItemProps}
|
|
87
|
+
>
|
|
88
|
+
{children ?? label}
|
|
89
|
+
</Menu.Item>
|
|
74
90
|
) : (
|
|
75
91
|
<Button
|
|
76
92
|
variant="default"
|
|
77
93
|
disabled={disabled}
|
|
78
94
|
leftSection={<IconPencil size={18} {...iconProps} />}
|
|
79
95
|
title={title}
|
|
96
|
+
{...actionProps}
|
|
80
97
|
{...buttonProps}
|
|
81
98
|
>
|
|
82
99
|
{children ?? label}
|
|
83
100
|
</Button>
|
|
84
|
-
)
|
|
85
|
-
</Anchor>
|
|
101
|
+
)
|
|
86
102
|
);
|
|
87
103
|
};
|
|
@@ -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 { ListButton } from "./ListButton";
|
|
4
5
|
|
|
5
6
|
export default {
|
|
@@ -22,4 +23,15 @@ export const Disabled = () =>
|
|
|
22
23
|
<ListButton
|
|
23
24
|
resource="product"
|
|
24
25
|
disabled
|
|
25
|
-
/>;
|
|
26
|
+
/>;
|
|
27
|
+
|
|
28
|
+
export const MenuItem = () =>
|
|
29
|
+
<Menu shadow="md" width={200}>
|
|
30
|
+
<Menu.Target>
|
|
31
|
+
<ActionIcon variant="default"><IconDots size={16} /></ActionIcon>
|
|
32
|
+
</Menu.Target>
|
|
33
|
+
<Menu.Dropdown>
|
|
34
|
+
<Menu.Label>List Button</Menu.Label>
|
|
35
|
+
<ListButton menuItem>List</ListButton>
|
|
36
|
+
</Menu.Dropdown>
|
|
37
|
+
</Menu>;
|
|
@@ -1,22 +1,24 @@
|
|
|
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 { useListButton } from "@refinedev/core";
|
|
10
10
|
import type { RefineListButtonProps } from "@refinedev/ui-types";
|
|
11
11
|
import { IconList, type IconProps } from "@tabler/icons-react";
|
|
12
12
|
import type React from "react";
|
|
13
|
+
import { useCallback } from "react";
|
|
13
14
|
|
|
14
15
|
export type ListButtonProps = RefineListButtonProps<{
|
|
15
16
|
iconProps?: IconProps;
|
|
16
|
-
anchorProps?: AnchorProps;
|
|
17
17
|
actionIconProps?: ActionIconProps;
|
|
18
18
|
buttonProps?: ButtonProps;
|
|
19
19
|
disabled?: boolean;
|
|
20
|
+
menuItem?: boolean;
|
|
21
|
+
menuItemProps?: MenuItemProps;
|
|
20
22
|
}>;
|
|
21
23
|
|
|
22
24
|
export const ListButton: React.FC<ListButtonProps> = ({
|
|
@@ -28,8 +30,9 @@ export const ListButton: React.FC<ListButtonProps> = ({
|
|
|
28
30
|
iconProps,
|
|
29
31
|
actionIconProps,
|
|
30
32
|
buttonProps,
|
|
31
|
-
anchorProps,
|
|
32
33
|
disabled: disabledFromProps,
|
|
34
|
+
menuItem,
|
|
35
|
+
menuItemProps,
|
|
33
36
|
onClick,
|
|
34
37
|
}) => {
|
|
35
38
|
const {
|
|
@@ -45,47 +48,58 @@ export const ListButton: React.FC<ListButtonProps> = ({
|
|
|
45
48
|
meta,
|
|
46
49
|
});
|
|
47
50
|
|
|
48
|
-
if (hidden) return null;
|
|
49
|
-
|
|
50
51
|
const disabled = disabledFromProps || disabledFromHook;
|
|
51
52
|
|
|
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
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
53
|
+
const handleClick = useCallback((e: React.PointerEvent<HTMLButtonElement>) => {
|
|
54
|
+
if (disabled) {
|
|
55
|
+
e.preventDefault();
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
if (onClick) {
|
|
59
|
+
e.preventDefault();
|
|
60
|
+
onClick(e);
|
|
61
|
+
}
|
|
62
|
+
}, [disabled, onClick]);
|
|
63
|
+
|
|
64
|
+
const actionProps = {
|
|
65
|
+
// biome-ignore lint/suspicious/noExplicitAny: that's fine
|
|
66
|
+
component: LinkComponent as any,
|
|
67
|
+
onClick: handleClick,
|
|
68
|
+
to,
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (hidden) return null;
|
|
72
|
+
|
|
73
|
+
return hideText ? (
|
|
74
|
+
<ActionIcon
|
|
75
|
+
variant="default"
|
|
76
|
+
disabled={disabled}
|
|
77
|
+
title={title}
|
|
78
|
+
{...actionProps}
|
|
79
|
+
{...actionIconProps}
|
|
80
|
+
>
|
|
81
|
+
<IconList size={18} {...iconProps} />
|
|
82
|
+
</ActionIcon>
|
|
83
|
+
) : menuItem ? (
|
|
84
|
+
<Menu.Item
|
|
85
|
+
disabled={disabled}
|
|
86
|
+
leftSection={<IconList size={14} {...iconProps} />}
|
|
87
|
+
title={title}
|
|
88
|
+
{...actionProps}
|
|
89
|
+
{...menuItemProps}
|
|
90
|
+
>
|
|
91
|
+
{children ?? label}
|
|
92
|
+
</Menu.Item>
|
|
93
|
+
) : (
|
|
94
|
+
<Button
|
|
95
|
+
variant="default"
|
|
96
|
+
disabled={disabled}
|
|
97
|
+
leftSection={<IconList size={18} {...iconProps} />}
|
|
98
|
+
title={title}
|
|
99
|
+
{...actionProps}
|
|
100
|
+
{...buttonProps}
|
|
101
|
+
>
|
|
102
|
+
{children ?? label}
|
|
103
|
+
</Button>
|
|
104
|
+
);
|
|
91
105
|
};
|
|
@@ -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 { ShowButton } from "./ShowButton";
|
|
4
5
|
|
|
5
6
|
export default {
|
|
@@ -20,3 +21,14 @@ export const HideText = () =>
|
|
|
20
21
|
|
|
21
22
|
export const Disabled = () =>
|
|
22
23
|
<ShowButton 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>Show Button</Menu.Label>
|
|
32
|
+
<ShowButton menuItem />
|
|
33
|
+
</Menu.Dropdown>
|
|
34
|
+
</Menu>;
|
|
@@ -1,14 +1,17 @@
|
|
|
1
|
-
import { ActionIcon, type ActionIconProps,
|
|
1
|
+
import { ActionIcon, type ActionIconProps, Button, type ButtonProps, Menu, type MenuItemProps } from "@mantine/core";
|
|
2
2
|
import { useShowButton } from "@refinedev/core";
|
|
3
3
|
import type { RefineShowButtonProps } from "@refinedev/ui-types";
|
|
4
4
|
import { IconEye, type IconProps } from "@tabler/icons-react";
|
|
5
5
|
import type React from "react";
|
|
6
|
+
import { useCallback } from "react";
|
|
6
7
|
|
|
7
8
|
export type ShowButtonProps = RefineShowButtonProps<{
|
|
8
9
|
iconProps?: IconProps;
|
|
9
10
|
actionIconProps?: ActionIconProps;
|
|
10
11
|
buttonProps?: ButtonProps;
|
|
11
12
|
disabled?: boolean;
|
|
13
|
+
menuItem?: boolean;
|
|
14
|
+
menuItemProps?: MenuItemProps;
|
|
12
15
|
}>;
|
|
13
16
|
|
|
14
17
|
export const ShowButton: React.FC<ShowButtonProps> = ({
|
|
@@ -22,6 +25,8 @@ export const ShowButton: React.FC<ShowButtonProps> = ({
|
|
|
22
25
|
actionIconProps,
|
|
23
26
|
buttonProps,
|
|
24
27
|
disabled: disabledFromProps,
|
|
28
|
+
menuItem,
|
|
29
|
+
menuItemProps,
|
|
25
30
|
onClick,
|
|
26
31
|
}) => {
|
|
27
32
|
const {
|
|
@@ -38,46 +43,58 @@ export const ShowButton: React.FC<ShowButtonProps> = ({
|
|
|
38
43
|
meta,
|
|
39
44
|
});
|
|
40
45
|
|
|
41
|
-
if (hidden) return null;
|
|
42
|
-
|
|
43
46
|
const disabled = disabledFromProps || disabledFromHook;
|
|
44
47
|
|
|
45
|
-
|
|
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
|
-
|
|
48
|
+
const handleClick = useCallback((e: React.PointerEvent<HTMLButtonElement>) => {
|
|
49
|
+
if (disabled) {
|
|
50
|
+
e.preventDefault();
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
if (onClick) {
|
|
54
|
+
e.preventDefault();
|
|
55
|
+
onClick(e);
|
|
56
|
+
}
|
|
57
|
+
}, [disabled, onClick]);
|
|
58
|
+
|
|
59
|
+
const actionProps = {
|
|
60
|
+
// biome-ignore lint/suspicious/noExplicitAny: that's fine
|
|
61
|
+
component: LinkComponent as any,
|
|
62
|
+
onClick: handleClick,
|
|
63
|
+
to,
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (hidden) return null;
|
|
67
|
+
|
|
68
|
+
return hideText ? (
|
|
69
|
+
<ActionIcon
|
|
70
|
+
variant="default"
|
|
71
|
+
disabled={disabled}
|
|
72
|
+
title={title}
|
|
73
|
+
{...actionProps}
|
|
74
|
+
{...actionIconProps}
|
|
75
|
+
>
|
|
76
|
+
<IconEye size={18} {...iconProps} />
|
|
77
|
+
</ActionIcon>
|
|
78
|
+
) : menuItem ? (
|
|
79
|
+
<Menu.Item
|
|
80
|
+
disabled={disabled}
|
|
81
|
+
leftSection={<IconEye 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={<IconEye size={18} {...iconProps} />}
|
|
93
|
+
title={title}
|
|
94
|
+
{...actionProps}
|
|
95
|
+
{...buttonProps}
|
|
96
|
+
>
|
|
97
|
+
{children ?? label}
|
|
98
|
+
</Button>
|
|
99
|
+
);
|
|
83
100
|
};
|