Skip to content

Scheduling infrastructure for absolutely everyone.

Few updates to V2 components (#3532)

sean-brydonb3bd8c1a5875
diff --git a/apps/storybook/stories/Cards.stories.tsx b/apps/storybook/stories/Cards.stories.tsx
new file mode 100644
index 00000000000..8faa78076af
--- /dev/null
+++ b/apps/storybook/stories/Cards.stories.tsx
@@ -0,0 +1,53 @@
+import { ComponentMeta } from "@storybook/react";
+
+import { BaseCardProps, Card } from "@calcom/ui/v2/Card";
+
+export default {
+ title: "Cards",
+ component: Card,
+} as ComponentMeta<typeof Card>;
+
+const profileProps: BaseCardProps[] = [
+ {
+ variant: "ProfileCard",
+ title: "Alex Fisher",
+ image:
+ "https://images.unsplash.com/photo-1472099645785-5658abf4ff4e?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=facearea&facepad=2&w=256&h=256&q=80",
+ description: "Co-founder at Attio. Book a meeting to discuss enterprise deals.",
+ },
+ {
+ variant: "ProfileCard",
+ title: "Julian Wan",
+ image:
+ "https://images.unsplash.com/photo-1570295999919-56ceb5ecca61?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1760&q=80",
+ description: "Co-founder at Attio. Book a meeting to discuss enterprise deals.",
+ },
+];
+
+export const Profile = () => {
+ return (
+ <div className="flex w-full space-x-2 bg-gray-200 p-4">
+ <Card {...profileProps[0]} />
+ <Card {...profileProps[1]} />
+ </div>
+ );
+};
+
+const appStoreProps: BaseCardProps = {
+ variant: "AppStore",
+ title: "Giphy",
+ image: "https://app.cal.com/api/app-store/giphy/icon.svg",
+ description: "Add GIFs to spice up your booking confirmations.",
+ actionButton: {
+ href: "#",
+ child: "View Details",
+ },
+};
+
+export const AppStore = () => {
+ return (
+ <div className="w-full bg-gray-200 p-4">
+ <Card {...appStoreProps} />
+ </div>
+ );
+};
diff --git a/apps/storybook/stories/HorizontalTab.stories.tsx b/apps/storybook/stories/HorizontalTab.stories.tsx
new file mode 100644
index 00000000000..784a2c7b671
--- /dev/null
+++ b/apps/storybook/stories/HorizontalTab.stories.tsx
@@ -0,0 +1,30 @@
+// Disabling until we figure out what is happening with the RouterMock.
+import { ComponentMeta } from "@storybook/react";
+
+import { HorizontalTabs } from "@calcom/ui/v2/navigation/tabs";
+import { HorizontalTabItemProps } from "@calcom/ui/v2/navigation/tabs/HorizontalTabItem";
+
+export default {
+ title: "Horizontal Tabs",
+ component: HorizontalTabs,
+} as ComponentMeta<typeof HorizontalTabs>;
+
+const HorizontalTabsPropsDefault: HorizontalTabItemProps[] = [
+ {
+ name: "Tab One",
+ href: "/tab-one",
+ },
+];
+
+export const Default = () => (
+ <div className="w-full p-4" style={{ backgroundColor: "#F9FAFB" }}>
+ <HorizontalTabs tabs={HorizontalTabsPropsDefault} />
+ </div>
+);
+
+Default.parameters = {
+ nextRouter: {
+ path: "/[page]",
+ asPath: "/profile",
+ },
+};
diff --git a/packages/lib/defaultAvatarImage.ts b/packages/lib/defaultAvatarImage.ts
index 2ef123d9801..94ca0e75b90 100644
--- a/packages/lib/defaultAvatarImage.ts
+++ b/packages/lib/defaultAvatarImage.ts
@@ -9,3 +9,10 @@ export const defaultAvatarSrc = function ({ email, md5 }: { md5?: string; email?
return `https://www.gravatar.com/avatar/${md5}?s=160&d=identicon&r=PG`;
};
+
+export function getPlaceholderAvatar(avatar: string | null | undefined, name: string | null) {
+ return avatar
+ ? avatar
+ : "https://eu.ui-avatars.com/api/?background=fff&color=f9f9f9&bold=true&background=000000&name=" +
+ encodeURIComponent(name || "");
+}
diff --git a/packages/ui/package.json b/packages/ui/package.json
index e5090935227..cc8b80cb258 100644
--- a/packages/ui/package.json
+++ b/packages/ui/package.json
@@ -22,6 +22,7 @@
"@calcom/config": "*",
"@calcom/lib": "*",
"@calcom/tsconfig": "*",
+ "@calcom/trpc": "*",
"@types/react": "18.0.9",
"@types/react-dom": "18.0.4",
"typescript": "^4.6.4"
diff --git a/packages/ui/v2/Breadcrumb.tsx b/packages/ui/v2/Breadcrumb.tsx
index 9a150612015..f156ab71492 100644
--- a/packages/ui/v2/Breadcrumb.tsx
+++ b/packages/ui/v2/Breadcrumb.tsx
@@ -23,8 +23,8 @@ export const Breadcrumb = ({ children }: BreadcrumbProps) => {
});
return (
- <nav className=" mx-8 mt-8 md:mx-16 lg:mx-32">
- <ol className="flex items-center space-x-4">{childrenSeperated}</ol>
+ <nav className="text-sm font-normal leading-5 text-gray-600">
+ <ol className="flex items-center space-x-2">{childrenSeperated}</ol>
</nav>
);
};
@@ -65,5 +65,5 @@ export const BreadcrumbContainer = () => {
};
});
setBreadcrumbs(allBreadcrumbs);
- }, []);
+ }, [router.asPath]);
};
diff --git a/packages/ui/v2/Card.tsx b/packages/ui/v2/Card.tsx
new file mode 100644
index 00000000000..8cc16bfb6aa
--- /dev/null
+++ b/packages/ui/v2/Card.tsx
@@ -0,0 +1,66 @@
+import { ReactNode } from "react";
+
+import classNames from "@calcom/lib/classNames";
+
+import Button from "./Button";
+
+export type BaseCardProps = {
+ image: string;
+ variant: keyof typeof cardTypeByVariant;
+ imageProps?: JSX.IntrinsicElements["img"];
+ title: string;
+ description: string;
+ containerProps?: JSX.IntrinsicElements["div"];
+ actionButton?: {
+ href: string;
+ child: ReactNode;
+ };
+};
+
+const cardTypeByVariant = {
+ AppStore: {
+ image: "w-10 h-auto",
+ card: "p-5 w-64",
+ },
+ ProfileCard: {
+ image: "w-9 h-auto rounded-full mb-4s",
+ card: "w-80 p-4",
+ actionButton: "",
+ },
+};
+
+export function Card({
+ image,
+ title,
+ description,
+ variant,
+ actionButton,
+ containerProps,
+ imageProps,
+}: BaseCardProps) {
+ return (
+ <div
+ className={classNames(
+ containerProps?.className,
+ cardTypeByVariant[variant].card,
+ "border-1 rounded-md border-gray-200 bg-white"
+ )}
+ {...containerProps}>
+ <img
+ src={image}
+ // Stops eslint complaining - not smart enough to realise it comes from ...imageProps
+ alt={imageProps?.alt}
+ className={classNames(imageProps?.className, cardTypeByVariant[variant].image, "mb-4")}
+ {...imageProps}
+ />
+ <span className="text-base font-bold leading-5 text-gray-900 ">{title}</span>
+ <p className="pt-1 text-sm font-normal leading-[18px] text-gray-500">{description}</p>
+ {variant === "AppStore" && (
+ <Button color="secondary" href={actionButton?.href} size="lg" className="mt-10 w-full">
+ {/* Force it to be centered as this usecase of a button is off - doesnt meet normal sizes */}
+ <div className="mx-auto">{actionButton?.child}</div>
+ </Button>
+ )}
+ </div>
+ );
+}
diff --git a/packages/ui/v2/index.tsx b/packages/ui/v2/index.tsx
index 754c71d0624..0a79e91f3de 100644
--- a/packages/ui/v2/index.tsx
+++ b/packages/ui/v2/index.tsx
@@ -18,5 +18,7 @@ export { default as Banner } from "./banner";
export { default as FormStep } from "./form/FormStep";
export { default as Avatar } from "./Avatar";
export { default as AvatarGroup } from "./AvatarGroup";
+export * from "./Card";
export * from "./form/radio-area/";
export * from "./navigation/tabs/";
+export * from "./list-items";
diff --git a/packages/ui/v2/navigation/tabs/HorizontalTabItem.tsx b/packages/ui/v2/navigation/tabs/HorizontalTabItem.tsx
new file mode 100644
index 00000000000..ccbae9aeb90
--- /dev/null
+++ b/packages/ui/v2/navigation/tabs/HorizontalTabItem.tsx
@@ -0,0 +1,64 @@
+import noop from "lodash/noop";
+import Link from "next/link";
+import { useRouter } from "next/router";
+import { MouseEventHandler } from "react";
+
+import classNames from "@calcom/lib/classNames";
+
+export type HorizontalTabItemProps = {
+ name: string;
+ disabled?: boolean;
+} & (
+ | {
+ /** If you want to change query param tabName as per current tab */
+ href: string;
+ tabName?: never;
+ }
+ | {
+ href?: never;
+ /** If you want to change the path as per current tab */
+ tabName: string;
+ }
+);
+
+const HorizontalTabItem = ({ name, href, tabName, ...props }: HorizontalTabItemProps) => {
+ const router = useRouter();
+ let newHref = "";
+ let isCurrent;
+ if (href) {
+ newHref = href;
+ isCurrent = router.asPath === href;
+ } else if (tabName) {
+ newHref = "";
+ isCurrent = router.query.tabName === tabName;
+ }
+
+ const onClick: MouseEventHandler = tabName
+ ? (e) => {
+ e.preventDefault();
+ router.push({
+ query: {
+ ...router.query,
+ tabName,
+ },
+ });
+ }
+ : noop;
+
+ return (
+ <Link key={name} href={props.disabled ? "#" : newHref}>
+ <a
+ onClick={onClick}
+ className={classNames(
+ isCurrent ? "bg-gray-200 text-gray-900" : " text-gray-600 hover:bg-gray-100 hover:text-gray-900",
+ "rounded-r-md py-[10px] px-4 text-sm font-medium leading-4",
+ props.disabled && "pointer-events-none !opacity-30"
+ )}
+ aria-current={isCurrent ? "page" : undefined}>
+ {name}
+ </a>
+ </Link>
+ );
+};
+
+export default HorizontalTabItem;
diff --git a/packages/ui/v2/navigation/tabs/HorizontalTabs.tsx b/packages/ui/v2/navigation/tabs/HorizontalTabs.tsx
new file mode 100644
index 00000000000..2b437cc8565
--- /dev/null
+++ b/packages/ui/v2/navigation/tabs/HorizontalTabs.tsx
@@ -0,0 +1,21 @@
+import { FC } from "react";
+
+import HorizontalTabItem, { HorizontalTabItemProps } from "./HorizontalTabItem";
+
+export interface NavTabProps {
+ tabs: HorizontalTabItemProps[];
+}
+
+const HorizontalTabs: FC<NavTabProps> = ({ tabs, ...props }) => {
+ return (
+ <>
+ <nav className="no-scrollbar flex space-y-1" aria-label="Tabs" {...props}>
+ {tabs.map((tab, idx) => (
+ <HorizontalTabItem {...tab} key={idx} />
+ ))}
+ </nav>
+ </>
+ );
+};
+
+export default HorizontalTabs;
diff --git a/packages/ui/v2/navigation/tabs/index.tsx b/packages/ui/v2/navigation/tabs/index.tsx
index 9466ca88c8a..8e755625375 100644
--- a/packages/ui/v2/navigation/tabs/index.tsx
+++ b/packages/ui/v2/navigation/tabs/index.tsx
@@ -1,2 +1,4 @@
export { default as VerticalTabItem } from "./VerticalTabItem";
export { default as VerticalTabs } from "./VerticalTabs";
+export { default as HorizontalTabItem } from "./HorizontalTabItem";
+export { default as HorizontalTabs } from "./HorizontalTabs";