Files
calendar/packages/features/data-table/components/DataTableSelectionBar.tsx
T
Keith WilliamsandGitHub 78d06c6d01 refactor: Move classNames from @calcom/lib to @calcom/ui (#19674)
* refactor: Move classNames from @calcom/lib to @calcom/ui

* Import fix

* Removed extra import of classNames

* Removed tailwind-merge from @calcom/lib
2025-03-03 15:54:33 +00:00

72 lines
2.0 KiB
TypeScript

"use client";
import type { Table } from "@tanstack/react-table";
import { forwardRef } from "react";
import { createPortal } from "react-dom";
import { Button, Icon } from "@calcom/ui";
import type { IconName, ButtonProps } from "@calcom/ui";
import classNames from "@calcom/ui/classNames";
export type ActionItem<TData> =
| {
type: "action";
label: string;
onClick: () => void;
icon?: IconName;
needsXSelected?: number;
}
| {
type: "render";
render: (table: Table<TData>) => React.ReactNode;
needsXSelected?: number;
};
type ResponsiveButtonProps = {
className?: string;
icon: IconName;
onClick?: () => void;
children: string;
} & ButtonProps;
const ResponsiveButton = forwardRef<HTMLButtonElement, ResponsiveButtonProps>(
({ icon, onClick, children, ...rest }, ref) => {
return (
<Button ref={ref} onClick={onClick} title={children} {...rest}>
<Icon name={icon} size={18} className="sm:hidden" />
<Icon name={icon} size={16} className="mr-2 hidden shrink-0 sm:inline" />
<span className="sr-only shrink-0 md:not-sr-only">{children}</span>
</Button>
);
}
);
ResponsiveButton.displayName = "ResponsiveButton";
const Root = forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement> & { showSelectionCount?: boolean }
>(({ children, ...props }, ref) => {
const { className, style, ...rest } = props;
return createPortal(
<div
ref={ref}
className={classNames(
"bg-default text-emphasis shadow-outline-gray-rested fixed bottom-0 left-0 flex w-full items-center space-x-1 overflow-x-auto border px-2 py-2 sm:space-x-2 md:bottom-4 md:left-1/2 md:z-auto md:w-fit md:-translate-x-1/2 md:transform md:space-x-3 md:overflow-x-hidden md:rounded-lg md:px-4",
className
)}
style={{ ...style }}
{...rest}>
{children}
</div>,
document.body
);
});
Root.displayName = "Root";
export const DataTableSelectionBar = {
Root,
Button: ResponsiveButton,
};