2022-08-26 00:11:41 +00:00
|
|
|
import Link from "next/link";
|
|
|
|
import { createElement } from "react";
|
|
|
|
|
|
|
|
import classNames from "@calcom/lib/classNames";
|
|
|
|
|
2022-09-13 14:14:27 +00:00
|
|
|
export type ListProps = {
|
|
|
|
roundContainer?: boolean;
|
2023-01-05 12:04:28 +00:00
|
|
|
// @TODO: Do we still need this? Coming from old v2 component. Prefer to delete it :)
|
|
|
|
noBorderTreatment?: boolean;
|
2022-09-13 14:14:27 +00:00
|
|
|
} & JSX.IntrinsicElements["ul"];
|
|
|
|
|
|
|
|
export function List(props: ListProps) {
|
2022-08-26 00:11:41 +00:00
|
|
|
return (
|
2022-09-13 14:14:27 +00:00
|
|
|
<ul
|
|
|
|
{...props}
|
|
|
|
className={classNames(
|
|
|
|
"-mx-4 rounded-sm sm:mx-0 sm:overflow-hidden ",
|
|
|
|
// Add rounded top and bottome if roundContainer is true
|
|
|
|
props.roundContainer && "[&>*:first-child]:rounded-t-md [&>*:last-child]:rounded-b-md ",
|
2023-01-19 15:02:01 +00:00
|
|
|
!props.noBorderTreatment && "divide-y divide-gray-200 rounded-md border border-l border-r ",
|
2022-09-13 14:14:27 +00:00
|
|
|
props.className
|
|
|
|
)}>
|
2022-08-26 00:11:41 +00:00
|
|
|
{props.children}
|
|
|
|
</ul>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-09-13 14:14:27 +00:00
|
|
|
export type ListItemProps = { expanded?: boolean; rounded?: boolean } & ({
|
|
|
|
href?: never;
|
|
|
|
} & JSX.IntrinsicElements["li"]);
|
2022-08-26 00:11:41 +00:00
|
|
|
|
|
|
|
export function ListItem(props: ListItemProps) {
|
2022-09-13 14:14:27 +00:00
|
|
|
const { href, expanded, rounded = true, ...passThroughProps } = props;
|
2022-08-26 00:11:41 +00:00
|
|
|
|
|
|
|
const elementType = href ? "a" : "li";
|
|
|
|
|
|
|
|
const element = createElement(
|
|
|
|
elementType,
|
|
|
|
{
|
|
|
|
...passThroughProps,
|
|
|
|
className: classNames(
|
2022-09-13 14:14:27 +00:00
|
|
|
"items-center bg-white min-w-0 flex-1 flex border-neutral-200 p-4 sm:mx-0 md:border md:p-4 xl:mt-0",
|
2022-08-26 00:11:41 +00:00
|
|
|
expanded ? "my-2 border" : "border -mb-px last:mb-0",
|
2022-09-13 14:14:27 +00:00
|
|
|
// Pass rounded false to not round the corners -> Usefull when used in list we can use roundedContainer to create the right design
|
|
|
|
rounded ? "rounded-md" : "rounded-none",
|
2022-08-26 00:11:41 +00:00
|
|
|
props.className,
|
|
|
|
(props.onClick || href) && "hover:bg-neutral-50"
|
|
|
|
),
|
|
|
|
},
|
|
|
|
props.children
|
|
|
|
);
|
|
|
|
|
|
|
|
return href ? (
|
2023-01-06 12:13:56 +00:00
|
|
|
<Link passHref href={href} legacyBehavior>
|
2022-08-26 00:11:41 +00:00
|
|
|
{element}
|
|
|
|
</Link>
|
|
|
|
) : (
|
|
|
|
element
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-01-05 12:04:28 +00:00
|
|
|
export type ListLinkItemProps = {
|
|
|
|
href: string;
|
|
|
|
heading: string;
|
|
|
|
subHeading: string;
|
|
|
|
disabled?: boolean;
|
|
|
|
actions?: JSX.Element;
|
|
|
|
} & JSX.IntrinsicElements["li"];
|
|
|
|
|
|
|
|
export function ListLinkItem(props: ListLinkItemProps) {
|
2023-03-09 12:14:17 +00:00
|
|
|
const { href, heading = "", children, disabled = false, actions = <div />, className = "" } = props;
|
2023-01-05 12:04:28 +00:00
|
|
|
let subHeading = props.subHeading;
|
|
|
|
if (!subHeading) {
|
|
|
|
subHeading = "";
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
<li
|
|
|
|
className={classNames(
|
|
|
|
"group flex w-full items-center justify-between p-5 hover:bg-neutral-50",
|
2023-03-09 12:14:17 +00:00
|
|
|
className,
|
2023-01-05 12:04:28 +00:00
|
|
|
disabled ? "hover:bg-white" : ""
|
|
|
|
)}>
|
2023-01-06 12:13:56 +00:00
|
|
|
<Link
|
|
|
|
passHref
|
|
|
|
href={href}
|
|
|
|
className={classNames(
|
|
|
|
"flex-grow truncate text-sm",
|
|
|
|
disabled ? "pointer-events-none cursor-not-allowed opacity-30" : ""
|
|
|
|
)}>
|
|
|
|
<h1 className="text-sm font-semibold leading-none">{heading}</h1>
|
|
|
|
<h2 className="min-h-4 mt-2 text-sm font-normal leading-none">
|
|
|
|
{subHeading.substring(0, 100)}
|
|
|
|
{subHeading.length > 100 && "..."}
|
|
|
|
</h2>
|
|
|
|
<div className="mt-2">{children}</div>
|
2023-01-05 12:04:28 +00:00
|
|
|
</Link>
|
|
|
|
{actions}
|
|
|
|
</li>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-08-26 00:11:41 +00:00
|
|
|
export function ListItemTitle<TComponent extends keyof JSX.IntrinsicElements = "span">(
|
|
|
|
props: JSX.IntrinsicElements[TComponent] & { component?: TComponent }
|
|
|
|
) {
|
|
|
|
const { component = "span", ...passThroughProps } = props;
|
|
|
|
|
|
|
|
return createElement(
|
|
|
|
component,
|
|
|
|
{
|
|
|
|
...passThroughProps,
|
2023-01-12 16:57:43 +00:00
|
|
|
className: classNames("text-sm font-medium text-gray-900 truncate", props.className),
|
2022-08-26 00:11:41 +00:00
|
|
|
},
|
|
|
|
props.children
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function ListItemText<TComponent extends keyof JSX.IntrinsicElements = "span">(
|
|
|
|
props: JSX.IntrinsicElements[TComponent] & { component?: TComponent }
|
|
|
|
) {
|
|
|
|
const { component = "span", ...passThroughProps } = props;
|
|
|
|
|
|
|
|
return createElement(
|
|
|
|
component,
|
|
|
|
{
|
|
|
|
...passThroughProps,
|
|
|
|
className: classNames("text-sm text-gray-500 truncate", props.className),
|
|
|
|
},
|
|
|
|
props.children
|
|
|
|
);
|
|
|
|
}
|