2021-09-29 21:33:18 +00:00
|
|
|
import { DotsHorizontalIcon } from "@heroicons/react/solid";
|
2022-03-13 22:09:39 +00:00
|
|
|
import React, { FC } from "react";
|
2021-09-29 21:33:18 +00:00
|
|
|
|
2022-03-16 23:36:43 +00:00
|
|
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
|
|
|
import Button from "@calcom/ui/Button";
|
2022-03-16 19:55:18 +00:00
|
|
|
import Dropdown, { DropdownMenuTrigger, DropdownMenuContent, DropdownMenuItem } from "@calcom/ui/Dropdown";
|
|
|
|
|
2021-09-29 21:33:18 +00:00
|
|
|
import { SVGComponent } from "@lib/types/SVGComponent";
|
|
|
|
|
2021-10-12 13:11:33 +00:00
|
|
|
export type ActionType = {
|
2021-09-29 21:33:18 +00:00
|
|
|
id: string;
|
|
|
|
icon: SVGComponent;
|
|
|
|
label: string;
|
|
|
|
disabled?: boolean;
|
2021-09-30 10:46:39 +00:00
|
|
|
color?: "primary" | "secondary";
|
2021-09-29 21:33:18 +00:00
|
|
|
} & ({ href?: never; onClick: () => any } | { href: string; onClick?: never });
|
|
|
|
|
|
|
|
interface Props {
|
|
|
|
actions: ActionType[];
|
|
|
|
}
|
|
|
|
|
|
|
|
const TableActions: FC<Props> = ({ actions }) => {
|
2021-10-15 10:53:42 +00:00
|
|
|
const { t } = useLocale();
|
2021-09-29 21:33:18 +00:00
|
|
|
return (
|
|
|
|
<>
|
2022-02-09 00:05:13 +00:00
|
|
|
<div className="hidden space-x-2 rtl:space-x-reverse lg:block">
|
2021-09-29 21:33:18 +00:00
|
|
|
{actions.map((action) => (
|
|
|
|
<Button
|
|
|
|
key={action.id}
|
|
|
|
data-testid={action.id}
|
|
|
|
href={action.href}
|
|
|
|
onClick={action.onClick}
|
|
|
|
StartIcon={action.icon}
|
|
|
|
disabled={action.disabled}
|
2021-09-30 10:46:39 +00:00
|
|
|
color={action.color || "secondary"}>
|
2021-09-29 21:33:18 +00:00
|
|
|
{action.label}
|
|
|
|
</Button>
|
|
|
|
))}
|
|
|
|
</div>
|
2022-03-13 22:09:39 +00:00
|
|
|
<div className="inline-block text-left lg:hidden">
|
|
|
|
<Dropdown>
|
|
|
|
<DropdownMenuTrigger className="h-[38px] w-[38px] cursor-pointer rounded-sm border border-transparent text-neutral-500 hover:border-gray-300 hover:text-neutral-900">
|
|
|
|
<DotsHorizontalIcon className="h-5 w-5 group-hover:text-gray-800" />
|
|
|
|
</DropdownMenuTrigger>
|
|
|
|
<DropdownMenuContent portalled>
|
|
|
|
{actions.map((action) => (
|
|
|
|
<DropdownMenuItem key={action.id}>
|
|
|
|
<Button
|
|
|
|
type="button"
|
2022-03-16 19:55:18 +00:00
|
|
|
size="lg"
|
2022-03-13 22:09:39 +00:00
|
|
|
color="minimal"
|
2022-03-16 19:55:18 +00:00
|
|
|
className="w-full rounded-none font-normal"
|
2022-03-13 22:09:39 +00:00
|
|
|
href={action.href}
|
|
|
|
StartIcon={action.icon}
|
|
|
|
onClick={action.onClick}>
|
|
|
|
{action.label}
|
|
|
|
</Button>
|
|
|
|
</DropdownMenuItem>
|
|
|
|
))}
|
|
|
|
</DropdownMenuContent>
|
|
|
|
</Dropdown>
|
|
|
|
</div>
|
2021-09-29 21:33:18 +00:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default TableActions;
|