2023-04-05 18:14:46 +00:00
|
|
|
import type { ReactElement, ReactNode } from "react";
|
|
|
|
import React from "react";
|
2022-11-04 15:40:46 +00:00
|
|
|
|
|
|
|
import { classNames } from "@calcom/lib";
|
|
|
|
|
|
|
|
export function VariantsTable({
|
|
|
|
children,
|
|
|
|
titles,
|
|
|
|
isDark,
|
|
|
|
columnMinWidth = 150,
|
|
|
|
}: {
|
|
|
|
children: ReactElement<RowProps> | ReactElement<RowProps>[];
|
|
|
|
titles: string[];
|
|
|
|
isDark?: boolean;
|
|
|
|
// Mainly useful on mobile, so components don't get squeesed
|
|
|
|
columnMinWidth?: number;
|
|
|
|
}) {
|
|
|
|
const columns = React.Children.toArray(children) as ReactElement<RowProps>[];
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
className={classNames(
|
|
|
|
isDark &&
|
2022-11-22 17:07:55 +00:00
|
|
|
"relative py-8 before:absolute before:left-0 before:top-0 before:block before:h-full before:w-screen before:bg-[#1C1C1C]"
|
2022-11-04 15:40:46 +00:00
|
|
|
)}>
|
|
|
|
<div className="z-1 relative mx-auto w-full max-w-[1200px] overflow-auto pr-8 pt-6">
|
|
|
|
<table>
|
|
|
|
<RowTitles titles={titles} />
|
|
|
|
{columns.map((column) => (
|
2023-06-22 22:25:37 +00:00
|
|
|
<tr className="p-2 pb-6 pr-6" key={column.props.variant}>
|
2022-11-04 15:40:46 +00:00
|
|
|
<th
|
2023-06-22 22:25:37 +00:00
|
|
|
className="p-2 pb-6 pr-6 text-left text-sm font-normal text-[#8F8F8F]"
|
2022-11-04 15:40:46 +00:00
|
|
|
key={column.props.variant}>
|
|
|
|
{column.props.variant}
|
|
|
|
</th>
|
|
|
|
{React.Children.count(column.props.children) &&
|
|
|
|
React.Children.map(column.props.children, (cell) => (
|
2023-06-22 22:25:37 +00:00
|
|
|
<td className="p-2 pb-6 pr-6" style={{ minWidth: `${columnMinWidth}px` }}>
|
2022-11-04 15:40:46 +00:00
|
|
|
{cell}
|
|
|
|
</td>
|
|
|
|
))}
|
|
|
|
</tr>
|
|
|
|
))}
|
|
|
|
</table>
|
|
|
|
</div>
|
|
|
|
{!isDark && (
|
2023-04-05 18:14:46 +00:00
|
|
|
<div data-mode="dark" className="dark">
|
2022-11-04 15:40:46 +00:00
|
|
|
<VariantsTable titles={titles} isDark columnMinWidth={columnMinWidth}>
|
|
|
|
{children}
|
|
|
|
</VariantsTable>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
interface RowProps {
|
|
|
|
variant: string;
|
|
|
|
children: ReactNode;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* There are two reasons we have this "empty" wrapper component:
|
|
|
|
* 1. In order to have an isolate group per variant, which we iterate through in the table component.
|
|
|
|
* 2. To have a way to pass the variant.
|
|
|
|
*/
|
|
|
|
export function VariantRow({ children }: RowProps) {
|
|
|
|
return <>{children}</>;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function RowTitles({ titles }: { titles: string[] }) {
|
|
|
|
return (
|
|
|
|
<tr>
|
2023-06-22 22:25:37 +00:00
|
|
|
<th className="p-2 pb-6 pr-6 text-left text-sm font-normal text-[#8F8F8F]" />
|
2022-11-04 15:40:46 +00:00
|
|
|
{titles.map((title) => (
|
2023-06-22 22:25:37 +00:00
|
|
|
<th className="p-2 pb-6 pr-6 text-left text-sm font-normal text-[#8F8F8F]" key={title}>
|
2022-11-04 15:40:46 +00:00
|
|
|
{title}
|
|
|
|
</th>
|
|
|
|
))}
|
|
|
|
</tr>
|
|
|
|
);
|
|
|
|
}
|