feat: v2 embed (#4477)
* Add support for custom tabNameKey and use embedTabName as the key for embed to avoid conflict with event-types tabName property * Fix tests * Code cleanup * feat: v2 embed * fix: button black default, reuse horitzontalTabs v2 * fix: remove comment, remove linkProps from NavTabs v2 * fix: height: 98% to avoid overflow * fix: add embed to event type detail page * fix: add also tabNames embed-code embed-react * fix: add tabNames w empty divs * Update Embed component as per V2 Co-authored-by: Hariom Balhara <[email protected]> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> Co-authored-by: Agusti Fernandez Pardo <[email protected]> Co-authored-by: Alex van Andel <[email protected]>
This commit is contained in:
14 files changed
+857
-143
No files matched your search
@@ -21,7 +21,7 @@
|
||||
</head>
|
||||
<script type="module" src="./src/preview.ts"></script>
|
||||
<body>
|
||||
<div id="my-embed" style="width: 100%; height: 100%; overflow: scroll"></div>
|
||||
<div id="my-embed" style="width: 100%; height: 90%; overflow: scroll"></div>
|
||||
<script type="module">
|
||||
|
||||
</script>
|
||||
|
||||
@@ -252,10 +252,6 @@ export const methods = {
|
||||
ui: function style(uiConfig: UiConfig) {
|
||||
// TODO: Create automatic logger for all methods. Useful for debugging.
|
||||
log("Method: ui called", uiConfig);
|
||||
if (window.CalComPlan && window.CalComPlan !== "PRO") {
|
||||
log(`Upgrade to PRO for "ui" instruction to work`, window.CalComPlan);
|
||||
return;
|
||||
}
|
||||
const stylesConfig = uiConfig.styles;
|
||||
|
||||
// In case where parent gives instructions before CalComPlan is set.
|
||||
|
||||
@@ -276,8 +276,8 @@ export class Cal {
|
||||
hideButtonIcon = false,
|
||||
attributes,
|
||||
buttonPosition = "bottom-right",
|
||||
buttonColor = "rgb(255, 202, 0)",
|
||||
buttonTextColor = "rgb(20, 30, 47)",
|
||||
buttonColor = "rgb(0, 0, 0)",
|
||||
buttonTextColor = "rgb(255, 255, 255)",
|
||||
}: {
|
||||
calLink: string;
|
||||
buttonText?: string;
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import React, { ComponentProps } from "react";
|
||||
|
||||
import HorizontalTabs from "@calcom/ui/v2/core/navigation/tabs/HorizontalTabs";
|
||||
import type { VerticalTabItemProps } from "@calcom/ui/v2/core/navigation/tabs/VerticalTabItem";
|
||||
|
||||
import Shell from "../Shell";
|
||||
import { HorizontalTabItemProps } from "../navigation/tabs/HorizontalTabItem";
|
||||
|
||||
const tabs: VerticalTabItemProps[] = [
|
||||
const tabs: HorizontalTabItemProps[] = [
|
||||
{
|
||||
name: "app_store",
|
||||
href: "/apps",
|
||||
|
||||
@@ -45,10 +45,10 @@ export default function BookingLayout({
|
||||
<Shell {...rest}>
|
||||
<div className="flex flex-col sm:space-x-2 xl:flex-row">
|
||||
<div className="hidden xl:block">
|
||||
<VerticalTabs tabs={tabs} sticky />
|
||||
<VerticalTabs tabNameKey="tabName" tabs={tabs} sticky />
|
||||
</div>
|
||||
<div className="block xl:hidden">
|
||||
<HorizontalTabs tabs={tabs} />
|
||||
<HorizontalTabs tabNameKey="tabName" tabs={tabs} />
|
||||
</div>
|
||||
<main className="w-full max-w-6xl">{children}</main>
|
||||
</div>
|
||||
|
||||
@@ -6,34 +6,40 @@ import { MouseEventHandler } from "react";
|
||||
import classNames from "@calcom/lib/classNames";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
|
||||
export type HorizontalTabItemProps = {
|
||||
export type HorizontalTabItemProps<T extends string = "tabName"> = {
|
||||
name: string;
|
||||
disabled?: boolean;
|
||||
className?: string;
|
||||
} & (
|
||||
| {
|
||||
/** 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;
|
||||
}
|
||||
} & Partial<Record<T, string>>)
|
||||
);
|
||||
|
||||
const HorizontalTabItem = ({ name, href, tabName, ...props }: HorizontalTabItemProps) => {
|
||||
const HorizontalTabItem = function <T extends string>({
|
||||
name,
|
||||
href,
|
||||
tabNameKey,
|
||||
...props
|
||||
}: HorizontalTabItemProps<T> & {
|
||||
tabNameKey?: T;
|
||||
}) {
|
||||
const router = useRouter();
|
||||
const { t } = useLocale();
|
||||
let newHref = "";
|
||||
let isCurrent;
|
||||
const _tabNameKey = tabNameKey || "tabName";
|
||||
const tabName = props[tabNameKey as keyof typeof props];
|
||||
|
||||
if (href) {
|
||||
newHref = href;
|
||||
isCurrent = router.asPath === href;
|
||||
} else if (tabName) {
|
||||
newHref = "";
|
||||
isCurrent = router.query.tabName === tabName;
|
||||
isCurrent = router.query[_tabNameKey] === tabName;
|
||||
}
|
||||
|
||||
const onClick: MouseEventHandler = tabName
|
||||
@@ -42,7 +48,7 @@ const HorizontalTabItem = ({ name, href, tabName, ...props }: HorizontalTabItemP
|
||||
router.push({
|
||||
query: {
|
||||
...router.query,
|
||||
tabName,
|
||||
[_tabNameKey]: tabName,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import { FC } from "react";
|
||||
|
||||
import HorizontalTabItem, { HorizontalTabItemProps } from "./HorizontalTabItem";
|
||||
|
||||
export { HorizontalTabItem };
|
||||
|
||||
export interface NavTabProps {
|
||||
tabs: HorizontalTabItemProps[];
|
||||
export interface NavTabProps<T extends string> {
|
||||
tabs: HorizontalTabItemProps<T>[];
|
||||
tabNameKey?: T;
|
||||
}
|
||||
|
||||
const HorizontalTabs: FC<NavTabProps> = ({ tabs, ...props }) => {
|
||||
const HorizontalTabs = function <T extends string>({ tabs, tabNameKey, ...props }: NavTabProps<T>) {
|
||||
const _tabNameKey = tabNameKey || "tabName";
|
||||
return (
|
||||
<div className="-mx-6 mb-2 w-[calc(100%+40px)]">
|
||||
<nav
|
||||
@@ -16,7 +16,7 @@ const HorizontalTabs: FC<NavTabProps> = ({ tabs, ...props }) => {
|
||||
aria-label="Tabs"
|
||||
{...props}>
|
||||
{tabs.map((tab, idx) => (
|
||||
<HorizontalTabItem {...tab} key={idx} />
|
||||
<HorizontalTabItem tabNameKey={_tabNameKey} {...tab} key={idx} />
|
||||
))}
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import noop from "lodash/noop";
|
||||
import Link from "next/link";
|
||||
import { useRouter } from "next/router";
|
||||
import { FC, Fragment, MouseEventHandler } from "react";
|
||||
import { Fragment, MouseEventHandler } from "react";
|
||||
|
||||
// import { ChevronRight } from "react-feather";
|
||||
import classNames from "@calcom/lib/classNames";
|
||||
@@ -9,12 +9,12 @@ import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { SVGComponent } from "@calcom/types/SVGComponent";
|
||||
import { Icon } from "@calcom/ui/Icon";
|
||||
|
||||
export type VerticalTabItemProps = {
|
||||
export type VerticalTabItemProps<T extends string = "tabName"> = {
|
||||
name: string;
|
||||
info?: string;
|
||||
icon?: SVGComponent;
|
||||
disabled?: boolean;
|
||||
children?: VerticalTabItemProps[];
|
||||
children?: VerticalTabItemProps<T>[];
|
||||
textClassNames?: string;
|
||||
className?: string;
|
||||
isChild?: boolean;
|
||||
@@ -26,32 +26,34 @@ export type VerticalTabItemProps = {
|
||||
href: string;
|
||||
tabName?: never;
|
||||
}
|
||||
| {
|
||||
| ({
|
||||
href?: never;
|
||||
/** If you want to change the path as per current tab */
|
||||
tabName: string;
|
||||
}
|
||||
} & Partial<Record<T, string>>)
|
||||
);
|
||||
|
||||
const VerticalTabItem: FC<VerticalTabItemProps> = ({
|
||||
const VerticalTabItem = function <T extends string>({
|
||||
name,
|
||||
href,
|
||||
tabName,
|
||||
tabNameKey,
|
||||
info,
|
||||
isChild,
|
||||
disableChevron,
|
||||
...props
|
||||
}) => {
|
||||
}: VerticalTabItemProps<T> & {
|
||||
tabNameKey?: T;
|
||||
}) {
|
||||
const router = useRouter();
|
||||
const { t } = useLocale();
|
||||
let newHref = "";
|
||||
let isCurrent;
|
||||
const tabName = props[tabNameKey as keyof typeof props] as string;
|
||||
const _tabNameKey = tabNameKey || "tabName";
|
||||
if (href) {
|
||||
newHref = href;
|
||||
isCurrent = router.asPath === href;
|
||||
} else if (tabName) {
|
||||
newHref = "";
|
||||
isCurrent = router.query.tabName === tabName;
|
||||
isCurrent = router.query[_tabNameKey] === tabName;
|
||||
}
|
||||
|
||||
const onClick: MouseEventHandler = tabName
|
||||
@@ -60,7 +62,7 @@ const VerticalTabItem: FC<VerticalTabItemProps> = ({
|
||||
router.push({
|
||||
query: {
|
||||
...router.query,
|
||||
tabName,
|
||||
[_tabNameKey]: tabName,
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -83,6 +85,8 @@ const VerticalTabItem: FC<VerticalTabItemProps> = ({
|
||||
)}
|
||||
aria-current={isCurrent ? "page" : undefined}>
|
||||
{props.icon && (
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
//@ts-ignore
|
||||
<props.icon className="mr-[10px] h-[16px] w-[16px] self-start stroke-[2px] md:mt-0" />
|
||||
)}
|
||||
<div>
|
||||
@@ -101,7 +105,7 @@ const VerticalTabItem: FC<VerticalTabItemProps> = ({
|
||||
</a>
|
||||
</Link>
|
||||
{props.children?.map((child) => (
|
||||
<VerticalTabItem key={child.name} {...child} isChild />
|
||||
<VerticalTabItem tabNameKey={tabNameKey} key={child.name} {...child} isChild />
|
||||
))}
|
||||
</>
|
||||
)}
|
||||
|
||||
@@ -1,19 +1,26 @@
|
||||
import { FC } from "react";
|
||||
|
||||
import { classNames } from "@calcom/lib";
|
||||
|
||||
import VerticalTabItem, { VerticalTabItemProps } from "./VerticalTabItem";
|
||||
|
||||
export { VerticalTabItem };
|
||||
|
||||
export interface NavTabProps {
|
||||
tabs: VerticalTabItemProps[];
|
||||
export interface NavTabProps<T extends string> {
|
||||
tabs: VerticalTabItemProps<T>[];
|
||||
children?: React.ReactNode;
|
||||
className?: string;
|
||||
sticky?: boolean;
|
||||
tabNameKey?: T;
|
||||
}
|
||||
|
||||
const NavTabs: FC<NavTabProps> = ({ tabs, className = "", sticky, ...props }) => {
|
||||
const NavTabs = function <T extends string>({
|
||||
tabs,
|
||||
tabNameKey,
|
||||
className = "",
|
||||
sticky,
|
||||
...props
|
||||
}: NavTabProps<T>) {
|
||||
const _tabNameKey = tabNameKey || "tabName";
|
||||
|
||||
return (
|
||||
<nav
|
||||
className={classNames(
|
||||
@@ -26,7 +33,7 @@ const NavTabs: FC<NavTabProps> = ({ tabs, className = "", sticky, ...props }) =>
|
||||
{sticky && <div className="pt-6" />}
|
||||
{props.children}
|
||||
{tabs.map((tab, idx) => (
|
||||
<VerticalTabItem {...tab} key={idx} />
|
||||
<VerticalTabItem tabNameKey={_tabNameKey} {...tab} key={idx} />
|
||||
))}
|
||||
</nav>
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user