Chor/move table actions (#6157)
* Move table actions * Move table actions Co-authored-by: Peer Richelsen <[email protected]>
This commit is contained in:
1 parent
a076418989
commit
83b60de640
4 files changed
+14
-11
No files matched your search
@@ -29,3 +29,5 @@ export {
|
||||
} from "./form";
|
||||
export { TopBanner } from "./top-banner";
|
||||
export type { TopBannerProps } from "./top-banner";
|
||||
export { TableActions, DropdownActions } from "./table/TableActions";
|
||||
export type { ActionType } from "./table/TableActions";
|
||||
@@ -0,0 +1,101 @@
|
||||
import React, { FC } from "react";
|
||||
import { IconType } from "react-icons/lib";
|
||||
|
||||
import {
|
||||
Button,
|
||||
Dropdown,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuPortal,
|
||||
DropdownMenuTrigger,
|
||||
ButtonBaseProps,
|
||||
Icon,
|
||||
} from "@calcom/ui";
|
||||
|
||||
export type ActionType = {
|
||||
id: string;
|
||||
icon?: IconType;
|
||||
iconClassName?: string;
|
||||
label: string;
|
||||
disabled?: boolean;
|
||||
color?: ButtonBaseProps["color"];
|
||||
} & (
|
||||
| { href: string; onClick?: never; actions?: never }
|
||||
| { href?: never; onClick: (e: React.MouseEvent<HTMLElement, MouseEvent>) => void; actions?: never }
|
||||
| { actions?: ActionType[]; href?: never; onClick?: never }
|
||||
);
|
||||
|
||||
interface Props {
|
||||
actions: ActionType[];
|
||||
}
|
||||
|
||||
const defaultAction = (e: React.MouseEvent<HTMLElement, MouseEvent>) => {
|
||||
e.stopPropagation();
|
||||
};
|
||||
|
||||
export const DropdownActions = ({
|
||||
actions,
|
||||
actionTrigger,
|
||||
}: {
|
||||
actions: ActionType[];
|
||||
actionTrigger?: React.ReactNode;
|
||||
}) => {
|
||||
return (
|
||||
<Dropdown>
|
||||
{!actionTrigger ? (
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button type="button" color="secondary" size="icon" StartIcon={Icon.FiMoreHorizontal} />
|
||||
</DropdownMenuTrigger>
|
||||
) : (
|
||||
<DropdownMenuTrigger asChild>{actionTrigger}</DropdownMenuTrigger>
|
||||
)}
|
||||
<DropdownMenuPortal>
|
||||
<DropdownMenuContent>
|
||||
{actions.map((action) => (
|
||||
<DropdownMenuItem key={action.id}>
|
||||
<Button
|
||||
type="button"
|
||||
color={action.color || "minimal"}
|
||||
className="w-full rounded-none font-normal"
|
||||
href={action.href}
|
||||
StartIcon={action.icon}
|
||||
onClick={action.onClick || defaultAction}
|
||||
data-testid={action.id}>
|
||||
{action.label}
|
||||
</Button>
|
||||
</DropdownMenuItem>
|
||||
))}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenuPortal>
|
||||
</Dropdown>
|
||||
);
|
||||
};
|
||||
|
||||
export const TableActions: FC<Props> = ({ actions }) => {
|
||||
return (
|
||||
<>
|
||||
<div className="flex space-x-2 rtl:space-x-reverse">
|
||||
{actions.map((action) => {
|
||||
const button = (
|
||||
<Button
|
||||
className="whitespace-nowrap"
|
||||
key={action.id}
|
||||
data-testid={action.id}
|
||||
href={action.href}
|
||||
onClick={action.onClick || defaultAction}
|
||||
StartIcon={action.icon}
|
||||
{...(action?.actions ? { EndIcon: Icon.FiChevronDown } : null)}
|
||||
disabled={action.disabled}
|
||||
color={action.color || "secondary"}>
|
||||
{action.label}
|
||||
</Button>
|
||||
);
|
||||
if (!action.actions) {
|
||||
return button;
|
||||
}
|
||||
return <DropdownActions key={action.id} actions={action.actions} actionTrigger={button} />;
|
||||
})}
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
};
|
||||
@@ -27,7 +27,10 @@ export {
|
||||
Select,
|
||||
SelectField,
|
||||
SelectWithValidation,
|
||||
TableActions,
|
||||
DropdownActions,
|
||||
} from "./components";
|
||||
export type { ActionType } from "./components";
|
||||
export type { AvatarProps, BadgeProps, ButtonBaseProps, ButtonProps, TopBannerProps } from "./components";
|
||||
export { default as CheckboxField } from "./components/form/checkbox/Checkbox";
|
||||
/** ⬇️ TODO - Move these to components */
|
||||
|
||||
Reference in new issue
Block a user