Chor/bulk UI migration (#6367)
* Big bulk commit * Switch and settings toggle * Popover Kbar Timezones * Image Uploader * Fix core export * Meta * Swatch * Remove shell * Fix shell imports * Moved ShellSubHeading component to UI, to prevent recursive imports from shell component * Removed shell from ui ts config since shell doesnt have a dependency on shell anymore. Co-authored-by: Jeroen Reumkens <[email protected]> Co-authored-by: Omar López <[email protected]>
This commit is contained in:
62 files changed
+194
-157
No files matched your search
@@ -1,5 +1,5 @@
|
||||
import Meta from "../../v2/core/Meta";
|
||||
import { ShellSubHeading } from "../../v2/core/Shell";
|
||||
import { ShellSubHeading } from "../layout";
|
||||
import Meta from "../meta/Meta";
|
||||
import { SkeletonText } from "../skeleton";
|
||||
|
||||
export function SkeletonLoader({
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
import Link from "next/link";
|
||||
|
||||
import { classNames } from "@calcom/lib";
|
||||
|
||||
import { Badge, BadgeProps } from "..";
|
||||
import { Icon } from "../..";
|
||||
import { Divider } from "../divider";
|
||||
|
||||
type Action = { check: () => boolean; fn: () => void };
|
||||
export default function FormCard({
|
||||
children,
|
||||
label,
|
||||
deleteField,
|
||||
moveUp,
|
||||
moveDown,
|
||||
className,
|
||||
badge,
|
||||
...restProps
|
||||
}: {
|
||||
children: React.ReactNode;
|
||||
label?: React.ReactNode;
|
||||
deleteField?: Action | null;
|
||||
moveUp?: Action | null;
|
||||
moveDown?: Action | null;
|
||||
className?: string;
|
||||
badge?: { text: string; href?: string; variant: BadgeProps["variant"] } | null;
|
||||
} & JSX.IntrinsicElements["div"]) {
|
||||
className = classNames(
|
||||
className,
|
||||
"flex items-center group relative w-full rounded-md p-4 border border-gray-200"
|
||||
);
|
||||
|
||||
return (
|
||||
<div className={className} {...restProps}>
|
||||
<div>
|
||||
{moveUp?.check() ? (
|
||||
<button
|
||||
type="button"
|
||||
className="invisible absolute left-0 -ml-[13px] -mt-10 flex h-6 w-6 scale-0 items-center justify-center rounded-md border bg-white p-1 text-gray-400 transition-all hover:border-transparent hover:text-black hover:shadow group-hover:visible group-hover:scale-100 "
|
||||
onClick={() => moveUp?.fn()}>
|
||||
<Icon.FiArrowUp />
|
||||
</button>
|
||||
) : null}
|
||||
{moveDown?.check() ? (
|
||||
<button
|
||||
type="button"
|
||||
className="invisible absolute left-0 -ml-[13px] -mt-2 flex h-6 w-6 scale-0 items-center justify-center rounded-md border bg-white p-1 text-gray-400 transition-all hover:border-transparent hover:text-black hover:shadow group-hover:visible group-hover:scale-100"
|
||||
onClick={() => moveDown?.fn()}>
|
||||
<Icon.FiArrowDown />
|
||||
</button>
|
||||
) : null}
|
||||
</div>
|
||||
<div className="w-full">
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<span className="text-sm font-semibold leading-none">{label}</span>
|
||||
{badge && (
|
||||
<Badge className="ml-2" variant={badge.variant}>
|
||||
{badge.href ? <Link href={badge.href}>{badge.text}</Link> : badge.text}
|
||||
</Badge>
|
||||
)}
|
||||
</div>
|
||||
{deleteField?.check() ? (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
deleteField?.fn();
|
||||
}}
|
||||
color="secondary">
|
||||
<Icon.FiTrash className="h-4 w-4 text-gray-400" />
|
||||
</button>
|
||||
) : null}
|
||||
</div>
|
||||
<Divider className="mt-3 mb-6" />
|
||||
{children}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
export { default as Card } from "./Card";
|
||||
export type { BaseCardProps } from "./Card";
|
||||
export { StepCard } from "./StepCard";
|
||||
export { default as FormCard } from "./FormCard";
|
||||
@@ -0,0 +1,101 @@
|
||||
import { useCallback, useEffect, useRef, useState } from "react";
|
||||
import { HexColorInput, HexColorPicker } from "react-colorful";
|
||||
|
||||
import { fallBackHex, isValidHexCode } from "@calcom/lib/CustomBranding";
|
||||
|
||||
import { Swatch } from "../../..";
|
||||
|
||||
type Handler = (event: MouseEvent | Event) => void;
|
||||
function useEventListener<
|
||||
KW extends keyof WindowEventMap,
|
||||
KH extends keyof HTMLElementEventMap,
|
||||
T extends HTMLElement | void = void
|
||||
>(
|
||||
eventName: KW | KH,
|
||||
handler: (event: WindowEventMap[KW] | HTMLElementEventMap[KH] | Event) => void,
|
||||
element?: React.RefObject<T>
|
||||
) {
|
||||
// Create a ref that stores handler
|
||||
const savedHandler = useRef<typeof handler>();
|
||||
useEffect(() => {
|
||||
// Define the listening target
|
||||
const targetElement: T | Window = element?.current || window;
|
||||
if (!(targetElement && targetElement.addEventListener)) {
|
||||
return;
|
||||
}
|
||||
// Update saved handler if necessary
|
||||
if (savedHandler.current !== handler) {
|
||||
savedHandler.current = handler;
|
||||
}
|
||||
// Create event listener that calls handler function stored in ref
|
||||
const eventListener: typeof handler = (event) => {
|
||||
// eslint-disable-next-line no-extra-boolean-cast
|
||||
if (!!savedHandler?.current) {
|
||||
savedHandler.current(event);
|
||||
}
|
||||
};
|
||||
targetElement.addEventListener(eventName, eventListener);
|
||||
// Remove event listener on cleanup
|
||||
return () => {
|
||||
targetElement.removeEventListener(eventName, eventListener);
|
||||
};
|
||||
}, [eventName, element, handler]);
|
||||
}
|
||||
|
||||
function useOnClickOutside<T extends HTMLElement = HTMLElement>(
|
||||
ref: React.RefObject<T>,
|
||||
handler: Handler,
|
||||
mouseEvent: "mousedown" | "mouseup" = "mousedown"
|
||||
): void {
|
||||
useEventListener(mouseEvent, (event) => {
|
||||
const el = ref?.current;
|
||||
// Do nothing if clicking ref's element or descendent elements
|
||||
if (!el || el.contains(event.target as Node)) {
|
||||
return;
|
||||
}
|
||||
handler(event);
|
||||
});
|
||||
}
|
||||
export type ColorPickerProps = {
|
||||
defaultValue: string;
|
||||
onChange: (text: string) => void;
|
||||
};
|
||||
|
||||
const ColorPicker = (props: ColorPickerProps) => {
|
||||
const init = !isValidHexCode(props.defaultValue)
|
||||
? fallBackHex(props.defaultValue, false)
|
||||
: props.defaultValue;
|
||||
const [color, setColor] = useState(init);
|
||||
const [isOpen, toggle] = useState(false);
|
||||
const popover = useRef() as React.MutableRefObject<HTMLInputElement>;
|
||||
const close = useCallback(() => toggle(false), []);
|
||||
useOnClickOutside(popover, close);
|
||||
return (
|
||||
<div className="relative mt-1 flex items-center justify-center">
|
||||
<Swatch size="sm" backgroundColor={color} onClick={() => toggle(!isOpen)} />
|
||||
{isOpen && (
|
||||
<div className="popover" ref={popover}>
|
||||
<HexColorPicker
|
||||
className="!absolute !top-10 !left-0 !z-10 !h-32 !w-32"
|
||||
color={color}
|
||||
onChange={(val) => {
|
||||
setColor(val);
|
||||
props.onChange(val);
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
<HexColorInput
|
||||
className="block w-full border border-gray-300 px-3 py-2 ltr:ml-1 ltr:rounded-r-md rtl:mr-1 rtl:rounded-l-md sm:text-sm"
|
||||
color={color}
|
||||
onChange={(val) => {
|
||||
setColor(val);
|
||||
props.onChange(val);
|
||||
}}
|
||||
type="text"
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default ColorPicker;
|
||||
@@ -0,0 +1,147 @@
|
||||
import { CheckCircleIcon } from "@heroicons/react/outline";
|
||||
import * as DropdownMenuPrimitive from "@radix-ui/react-dropdown-menu";
|
||||
import Link from "next/link";
|
||||
import { ComponentProps, forwardRef } from "react";
|
||||
|
||||
import { classNames } from "@calcom/lib";
|
||||
import { SVGComponent } from "@calcom/types/SVGComponent";
|
||||
|
||||
export const Dropdown = DropdownMenuPrimitive.Root;
|
||||
|
||||
type DropdownMenuTriggerProps = ComponentProps<typeof DropdownMenuPrimitive["Trigger"]>;
|
||||
export const DropdownMenuTrigger = forwardRef<HTMLButtonElement, DropdownMenuTriggerProps>(
|
||||
({ className = "", ...props }, forwardedRef) => (
|
||||
<DropdownMenuPrimitive.Trigger
|
||||
{...props}
|
||||
className={
|
||||
props.asChild
|
||||
? classNames(className, "rounded-md ring-0")
|
||||
: `inline-flex items-center rounded-md bg-transparent px-3 py-2 text-sm font-medium text-gray-700 ring-0 hover:bg-gray-50 focus:bg-gray-100 group-hover:text-black ${className}`
|
||||
}
|
||||
ref={forwardedRef}
|
||||
/>
|
||||
)
|
||||
);
|
||||
DropdownMenuTrigger.displayName = "DropdownMenuTrigger";
|
||||
|
||||
export const DropdownMenuTriggerItem = DropdownMenuPrimitive.Trigger;
|
||||
|
||||
export const DropdownMenuPortal = DropdownMenuPrimitive.Portal;
|
||||
|
||||
type DropdownMenuContentProps = ComponentProps<typeof DropdownMenuPrimitive["Content"]>;
|
||||
export const DropdownMenuContent = forwardRef<HTMLDivElement, DropdownMenuContentProps>(
|
||||
({ children, sideOffset = 2, align = "end", ...props }, forwardedRef) => {
|
||||
return (
|
||||
<DropdownMenuPrimitive.Content
|
||||
align={align}
|
||||
{...props}
|
||||
sideOffset={sideOffset}
|
||||
className="shadow-dropdown w-50 relative z-10 origin-top-right rounded-md border border-gray-200 bg-white text-sm"
|
||||
ref={forwardedRef}>
|
||||
{children}
|
||||
</DropdownMenuPrimitive.Content>
|
||||
);
|
||||
}
|
||||
);
|
||||
DropdownMenuContent.displayName = "DropdownMenuContent";
|
||||
|
||||
type DropdownMenuLabelProps = ComponentProps<typeof DropdownMenuPrimitive["Label"]>;
|
||||
export const DropdownMenuLabel = (props: DropdownMenuLabelProps) => (
|
||||
<DropdownMenuPrimitive.Label {...props} className="px-3 py-2 text-neutral-500" />
|
||||
);
|
||||
|
||||
type DropdownMenuItemProps = ComponentProps<typeof DropdownMenuPrimitive["CheckboxItem"]>;
|
||||
export const DropdownMenuItem = forwardRef<HTMLDivElement, DropdownMenuItemProps>(
|
||||
({ className = "", ...props }, forwardedRef) => (
|
||||
<DropdownMenuPrimitive.Item
|
||||
className={`focus:ring-brand-800 text-sm text-gray-700 ring-inset first-of-type:rounded-t-[inherit] last-of-type:rounded-b-[inherit] hover:bg-gray-100 hover:text-gray-900 focus:outline-none focus:ring-1 ${className}`}
|
||||
{...props}
|
||||
ref={forwardedRef}
|
||||
/>
|
||||
)
|
||||
);
|
||||
DropdownMenuItem.displayName = "DropdownMenuItem";
|
||||
|
||||
export const DropdownMenuGroup = DropdownMenuPrimitive.Group;
|
||||
|
||||
type DropdownMenuCheckboxItemProps = ComponentProps<typeof DropdownMenuPrimitive["CheckboxItem"]>;
|
||||
export const DropdownMenuCheckboxItem = forwardRef<HTMLDivElement, DropdownMenuCheckboxItemProps>(
|
||||
({ children, ...props }, forwardedRef) => {
|
||||
return (
|
||||
<DropdownMenuPrimitive.CheckboxItem {...props} ref={forwardedRef}>
|
||||
{children}
|
||||
<DropdownMenuPrimitive.ItemIndicator>
|
||||
<CheckCircleIcon />
|
||||
</DropdownMenuPrimitive.ItemIndicator>
|
||||
</DropdownMenuPrimitive.CheckboxItem>
|
||||
);
|
||||
}
|
||||
);
|
||||
DropdownMenuCheckboxItem.displayName = "DropdownMenuCheckboxItem";
|
||||
|
||||
export const DropdownMenuRadioGroup = DropdownMenuPrimitive.RadioGroup;
|
||||
|
||||
type DropdownMenuRadioItemProps = ComponentProps<typeof DropdownMenuPrimitive["RadioItem"]>;
|
||||
export const DropdownMenuRadioItem = forwardRef<HTMLDivElement, DropdownMenuRadioItemProps>(
|
||||
({ children, ...props }, forwardedRef) => {
|
||||
return (
|
||||
<DropdownMenuPrimitive.RadioItem {...props} ref={forwardedRef}>
|
||||
{children}
|
||||
<DropdownMenuPrimitive.ItemIndicator>
|
||||
<CheckCircleIcon />
|
||||
</DropdownMenuPrimitive.ItemIndicator>
|
||||
</DropdownMenuPrimitive.RadioItem>
|
||||
);
|
||||
}
|
||||
);
|
||||
DropdownMenuRadioItem.displayName = "DropdownMenuRadioItem";
|
||||
|
||||
type DropdownItemProps = {
|
||||
children: React.ReactNode;
|
||||
color?: "destructive";
|
||||
StartIcon?: SVGComponent;
|
||||
EndIcon?: SVGComponent;
|
||||
href?: string;
|
||||
disabled?: boolean;
|
||||
} & ButtonOrLinkProps;
|
||||
|
||||
type ButtonOrLinkProps = ComponentProps<"button"> & ComponentProps<"a">;
|
||||
export function ButtonOrLink({ href, ...props }: ButtonOrLinkProps) {
|
||||
const isLink = typeof href !== "undefined";
|
||||
const ButtonOrLink = isLink ? "a" : "button";
|
||||
|
||||
const content = <ButtonOrLink {...props} />;
|
||||
|
||||
if (isLink) {
|
||||
return (
|
||||
<Link href={href} legacyBehavior>
|
||||
{content}
|
||||
</Link>
|
||||
);
|
||||
}
|
||||
|
||||
return content;
|
||||
}
|
||||
|
||||
export const DropdownItem = (props: DropdownItemProps) => {
|
||||
const { StartIcon, EndIcon } = props;
|
||||
|
||||
return (
|
||||
<ButtonOrLink
|
||||
{...props}
|
||||
className={classNames(
|
||||
"inline-flex w-full items-center px-3 py-2 text-gray-700 hover:text-gray-900",
|
||||
props.color === "destructive" ? "hover:bg-red-100 hover:text-red-700" : " hover:bg-gray-100"
|
||||
)}>
|
||||
<>
|
||||
{StartIcon && <StartIcon />}
|
||||
<div className="mx-2">{props.children}</div>
|
||||
{EndIcon && <EndIcon />}
|
||||
</>
|
||||
</ButtonOrLink>
|
||||
);
|
||||
};
|
||||
|
||||
export const DropdownMenuSeparator = DropdownMenuPrimitive.Separator;
|
||||
|
||||
export default Dropdown;
|
||||
@@ -0,0 +1,16 @@
|
||||
export {
|
||||
Dropdown,
|
||||
ButtonOrLink,
|
||||
DropdownItem,
|
||||
DropdownMenuCheckboxItem,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuGroup,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuLabel,
|
||||
DropdownMenuPortal,
|
||||
DropdownMenuRadioGroup,
|
||||
DropdownMenuRadioItem,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger,
|
||||
DropdownMenuTriggerItem,
|
||||
} from "./Dropdown";
|
||||
@@ -23,3 +23,23 @@ export type { ITimezone, ITimezoneOption } from "./timezone-select";
|
||||
export { DateRangePickerLazy as DateRangePicker } from "./date-range-picker";
|
||||
export { BooleanToggleGroup, BooleanToggleGroupField, ToggleGroup, ToggleGroupItem } from "./toggleGroup";
|
||||
export { DatePicker } from "./datepicker";
|
||||
export { FormStep, Steps, Stepper } from "./step";
|
||||
export { WizardForm } from "./wizard";
|
||||
export { default as ColorPicker } from "./color-picker/colorpicker";
|
||||
export {
|
||||
Dropdown,
|
||||
ButtonOrLink,
|
||||
DropdownItem,
|
||||
DropdownMenuCheckboxItem,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuGroup,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuLabel,
|
||||
DropdownMenuPortal,
|
||||
DropdownMenuRadioGroup,
|
||||
DropdownMenuRadioItem,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger,
|
||||
DropdownMenuTriggerItem,
|
||||
} from "./dropdown";
|
||||
export { SettingsToggle, Switch } from "./switch";
|
||||
@@ -0,0 +1,35 @@
|
||||
import React from "react";
|
||||
|
||||
import classNames from "@calcom/lib/classNames";
|
||||
|
||||
type Props = {
|
||||
steps: number;
|
||||
currentStep: number;
|
||||
};
|
||||
|
||||
// It might be worth passing this label string from outside the component so we can translate it?
|
||||
function FormStep({ currentStep, steps }: Props) {
|
||||
return (
|
||||
<div className="w-full">
|
||||
<p className="text-xs font-medium text-gray-400">
|
||||
Step {currentStep} of {steps}
|
||||
</p>
|
||||
<div className="flex flex-nowrap space-x-1">
|
||||
{[...Array(steps)].map((_, j) => {
|
||||
console.log({ j, currentStep });
|
||||
return (
|
||||
<div
|
||||
className={classNames(
|
||||
"h-1 w-full rounded-sm",
|
||||
currentStep - 1 >= j ? "bg-black" : "bg-gray-400"
|
||||
)}
|
||||
key={j}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default FormStep;
|
||||
@@ -0,0 +1,62 @@
|
||||
import Link from "next/link";
|
||||
|
||||
type DefaultStep = {
|
||||
title: string;
|
||||
};
|
||||
|
||||
function Stepper<T extends DefaultStep>(props: {
|
||||
href: string;
|
||||
step: number;
|
||||
steps: T[];
|
||||
disableSteps?: boolean;
|
||||
stepLabel?: (currentStep: number, totalSteps: number) => string;
|
||||
}) {
|
||||
const {
|
||||
href,
|
||||
steps,
|
||||
stepLabel = (currentStep, totalSteps) => `Step ${currentStep} of ${totalSteps}`,
|
||||
} = props;
|
||||
return (
|
||||
<>
|
||||
{steps.length > 1 && (
|
||||
<nav className="flex items-center justify-center" aria-label="Progress">
|
||||
<p className="text-sm font-medium">{stepLabel(props.step, steps.length)}</p>
|
||||
<ol role="list" className="ml-8 flex items-center space-x-5">
|
||||
{steps.map((mapStep, index) => (
|
||||
<li key={mapStep.title}>
|
||||
<Link
|
||||
href={props.disableSteps ? "#" : `${href}?step=${index + 1}`}
|
||||
shallow
|
||||
replace
|
||||
legacyBehavior>
|
||||
{index + 1 < props.step ? (
|
||||
<a className="block h-2.5 w-2.5 rounded-full bg-gray-600 hover:bg-gray-900">
|
||||
<span className="sr-only">{mapStep.title}</span>
|
||||
</a>
|
||||
) : index + 1 === props.step ? (
|
||||
<a className="relative flex items-center justify-center" aria-current="step">
|
||||
<span className="absolute flex h-5 w-5 p-px" aria-hidden="true">
|
||||
<span className="h-full w-full rounded-full bg-gray-200" />
|
||||
</span>
|
||||
<span
|
||||
className="relative block h-2.5 w-2.5 rounded-full bg-gray-600"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
<span className="sr-only">{mapStep.title}</span>
|
||||
</a>
|
||||
) : (
|
||||
<a className="block h-2.5 w-2.5 rounded-full bg-gray-200 hover:bg-gray-400">
|
||||
<span className="sr-only">{mapStep.title}</span>
|
||||
</a>
|
||||
)}
|
||||
</Link>
|
||||
</li>
|
||||
))}
|
||||
</ol>
|
||||
</nav>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export default Stepper;
|
||||
@@ -0,0 +1,37 @@
|
||||
import classNames from "@calcom/lib/classNames";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
|
||||
interface ISteps {
|
||||
maxSteps: number;
|
||||
currentStep: number;
|
||||
navigateToStep: (step: number) => void;
|
||||
}
|
||||
|
||||
const Steps = (props: ISteps) => {
|
||||
const { maxSteps, currentStep, navigateToStep } = props;
|
||||
const { t } = useLocale();
|
||||
return (
|
||||
<div className="mt-6 space-y-2">
|
||||
<p className="text-xs font-medium text-gray-500 dark:text-white">
|
||||
{t("current_step_of_total", { currentStep: currentStep + 1, maxSteps })}
|
||||
</p>
|
||||
<div className="flex w-full space-x-2 rtl:space-x-reverse">
|
||||
{new Array(maxSteps).fill(0).map((_s, index) => {
|
||||
return index <= currentStep ? (
|
||||
<div
|
||||
key={`step-${index}`}
|
||||
onClick={() => navigateToStep(index)}
|
||||
className={classNames(
|
||||
"h-1 w-full rounded-[1px] bg-black dark:bg-white",
|
||||
index < currentStep ? "cursor-pointer" : ""
|
||||
)}
|
||||
/>
|
||||
) : (
|
||||
<div key={`step-${index}`} className="h-1 w-full rounded-[1px] bg-black bg-opacity-25" />
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
export { Steps };
|
||||
@@ -0,0 +1,3 @@
|
||||
export { default as FormStep } from "./FormStep";
|
||||
export { Steps } from "./Steps";
|
||||
export { default as Stepper } from "./Stepper";
|
||||
@@ -0,0 +1,57 @@
|
||||
import { useAutoAnimate } from "@formkit/auto-animate/react";
|
||||
import { ReactNode } from "react";
|
||||
|
||||
import { Label } from "..";
|
||||
import Switch from "./Switch";
|
||||
|
||||
type Props = {
|
||||
children?: ReactNode;
|
||||
title: string;
|
||||
description?: string;
|
||||
checked: boolean;
|
||||
disabled?: boolean;
|
||||
onCheckedChange?: (checked: boolean) => void;
|
||||
"data-testid"?: string;
|
||||
};
|
||||
|
||||
function SettingsToggle({
|
||||
checked,
|
||||
onCheckedChange,
|
||||
description,
|
||||
title,
|
||||
children,
|
||||
disabled,
|
||||
...rest
|
||||
}: Props) {
|
||||
const [animateRef] = useAutoAnimate<HTMLDivElement>();
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="flex w-full flex-col space-y-4 lg:flex-row lg:space-y-0 lg:space-x-4">
|
||||
<fieldset className="block w-full flex-col sm:flex">
|
||||
<div className="flex space-x-3">
|
||||
<Switch
|
||||
data-testid={rest["data-testid"]}
|
||||
fitToHeight={true}
|
||||
checked={checked}
|
||||
onCheckedChange={onCheckedChange}
|
||||
disabled={disabled}
|
||||
/>
|
||||
|
||||
<div className="">
|
||||
<Label className="text-sm font-semibold leading-none text-black">{title}</Label>
|
||||
{description && <p className="-mt-2 text-sm leading-normal text-gray-600">{description}</p>}
|
||||
</div>
|
||||
</div>
|
||||
{children && (
|
||||
<div className="lg:ml-14" ref={animateRef}>
|
||||
{checked && <div className="mt-4">{children}</div>}
|
||||
</div>
|
||||
)}
|
||||
</fieldset>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export default SettingsToggle;
|
||||
@@ -0,0 +1,55 @@
|
||||
import { useId } from "@radix-ui/react-id";
|
||||
import * as Label from "@radix-ui/react-label";
|
||||
import * as PrimitiveSwitch from "@radix-ui/react-switch";
|
||||
import React from "react";
|
||||
|
||||
import classNames from "@calcom/lib/classNames";
|
||||
|
||||
const Switch = (
|
||||
props: React.ComponentProps<typeof PrimitiveSwitch.Root> & {
|
||||
label?: string;
|
||||
thumbProps?: {
|
||||
className?: string;
|
||||
};
|
||||
fitToHeight?: boolean;
|
||||
}
|
||||
) => {
|
||||
const { label, fitToHeight, ...primitiveProps } = props;
|
||||
const id = useId();
|
||||
|
||||
return (
|
||||
<div className={classNames("flex h-auto w-auto flex-row items-center", fitToHeight && "h-fit")}>
|
||||
<PrimitiveSwitch.Root
|
||||
className={classNames(
|
||||
props.checked ? "bg-gray-900" : "bg-gray-200",
|
||||
primitiveProps.disabled ? "cursor-not-allowed" : "hover:bg-gray-300",
|
||||
"focus:ring-brand-800 h-5 w-[34px] rounded-full shadow-none",
|
||||
props.className
|
||||
)}
|
||||
{...primitiveProps}>
|
||||
<PrimitiveSwitch.Thumb
|
||||
id={id}
|
||||
// Since we dont support global dark mode - we have to style dark mode components specifically on the instance for now
|
||||
// TODO: Remove once we support global dark mode
|
||||
className={classNames(
|
||||
"block h-[14px] w-[14px] rounded-full bg-white transition will-change-transform ltr:translate-x-[4px] rtl:-translate-x-[4px] ltr:[&[data-state='checked']]:translate-x-[17px] rtl:[&[data-state='checked']]:-translate-x-[17px]",
|
||||
props.checked && "shadow-inner",
|
||||
props.thumbProps?.className
|
||||
)}
|
||||
/>
|
||||
</PrimitiveSwitch.Root>
|
||||
{label && (
|
||||
<Label.Root
|
||||
htmlFor={id}
|
||||
className={classNames(
|
||||
"align-text-top text-sm font-medium text-gray-900 ltr:ml-3 rtl:mr-3 dark:text-white",
|
||||
primitiveProps.disabled ? "cursor-not-allowed opacity-25" : "cursor-pointer "
|
||||
)}>
|
||||
{label}
|
||||
</Label.Root>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default Switch;
|
||||
@@ -0,0 +1,2 @@
|
||||
export { default as SettingsToggle } from "./SettingsToggle";
|
||||
export { default as Switch } from "./Switch";
|
||||
@@ -0,0 +1,86 @@
|
||||
import { useRouter } from "next/router";
|
||||
import { ComponentProps } from "react";
|
||||
|
||||
import classNames from "@calcom/lib/classNames";
|
||||
|
||||
import { Button, Stepper } from "../../..";
|
||||
|
||||
type DefaultStep = {
|
||||
title: string;
|
||||
description: string;
|
||||
content: JSX.Element;
|
||||
enabled?: boolean;
|
||||
isLoading: boolean;
|
||||
};
|
||||
|
||||
function WizardForm<T extends DefaultStep>(props: {
|
||||
href: string;
|
||||
steps: T[];
|
||||
disableNavigation?: boolean;
|
||||
containerClassname?: string;
|
||||
prevLabel?: string;
|
||||
nextLabel?: string;
|
||||
finishLabel?: string;
|
||||
stepLabel?: ComponentProps<typeof Stepper>["stepLabel"];
|
||||
}) {
|
||||
const { href, steps, nextLabel = "Next", finishLabel = "Finish", prevLabel = "Back", stepLabel } = props;
|
||||
const router = useRouter();
|
||||
const step = parseInt((router.query.step as string) || "1");
|
||||
const currentStep = steps[step - 1];
|
||||
const setStep = (newStep: number) => {
|
||||
router.replace(`${href}?step=${newStep || 1}`, undefined, { shallow: true });
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="mx-auto mt-4 print:w-full">
|
||||
{/* eslint-disable-next-line @next/next/no-img-element */}
|
||||
<img className="mx-auto mb-8 h-8" src="https://cal.com/logo.svg" alt="Cal.com Logo" />
|
||||
<div
|
||||
className={classNames(
|
||||
"mb-8 divide-y divide-gray-200 overflow-hidden rounded-lg bg-white shadow print:divide-transparent print:shadow-transparent",
|
||||
props.containerClassname
|
||||
)}>
|
||||
<div className="px-4 py-5 sm:px-6">
|
||||
<h1 className="font-cal text-2xl text-gray-900">{currentStep.title}</h1>
|
||||
<p className="text-sm text-gray-500">{currentStep.description}</p>
|
||||
</div>
|
||||
|
||||
<div className="print:p-none max-w-3xl px-4 py-5 sm:p-6">{currentStep.content}</div>
|
||||
{!props.disableNavigation && (
|
||||
<>
|
||||
{currentStep.enabled !== false && (
|
||||
<div className="flex justify-end px-4 py-4 print:hidden sm:px-6">
|
||||
{step > 1 && (
|
||||
<Button
|
||||
color="secondary"
|
||||
onClick={() => {
|
||||
setStep(step - 1);
|
||||
}}>
|
||||
{prevLabel}
|
||||
</Button>
|
||||
)}
|
||||
|
||||
<Button
|
||||
tabIndex={0}
|
||||
loading={currentStep.isLoading}
|
||||
type="submit"
|
||||
color="primary"
|
||||
form={`wizard-step-${step}`}
|
||||
className="relative ml-2">
|
||||
{step < steps.length ? nextLabel : finishLabel}
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
{!props.disableNavigation && (
|
||||
<div className="print:hidden">
|
||||
<Stepper href={href} step={step} steps={steps} disableSteps stepLabel={stepLabel} />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default WizardForm;
|
||||
@@ -0,0 +1 @@
|
||||
export { default as WizardForm } from "./WizardForm";
|
||||
@@ -0,0 +1,282 @@
|
||||
import * as SliderPrimitive from "@radix-ui/react-slider";
|
||||
import { FormEvent, useCallback, useEffect, useState } from "react";
|
||||
import Cropper from "react-easy-crop";
|
||||
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
|
||||
import { Button, Dialog, DialogClose, DialogContent, DialogTrigger } from "../..";
|
||||
|
||||
type ReadAsMethod = "readAsText" | "readAsDataURL" | "readAsArrayBuffer" | "readAsBinaryString";
|
||||
|
||||
type UseFileReaderProps = {
|
||||
method: ReadAsMethod;
|
||||
onLoad?: (result: unknown) => void;
|
||||
};
|
||||
|
||||
type Area = {
|
||||
width: number;
|
||||
height: number;
|
||||
x: number;
|
||||
y: number;
|
||||
};
|
||||
|
||||
const MAX_IMAGE_SIZE = 512;
|
||||
|
||||
const useFileReader = (options: UseFileReaderProps) => {
|
||||
const { method = "readAsText", onLoad } = options;
|
||||
const [file, setFile] = useState<File | null>(null);
|
||||
const [loading, setLoading] = useState<boolean>(false);
|
||||
const [error, setError] = useState<DOMException | null>(null);
|
||||
const [result, setResult] = useState<string | ArrayBuffer | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (!file && result) {
|
||||
setResult(null);
|
||||
}
|
||||
}, [file, result]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!file) {
|
||||
return;
|
||||
}
|
||||
|
||||
const reader = new FileReader();
|
||||
reader.onloadstart = () => setLoading(true);
|
||||
reader.onloadend = () => setLoading(false);
|
||||
reader.onerror = () => setError(reader.error);
|
||||
|
||||
reader.onload = (e: ProgressEvent<FileReader>) => {
|
||||
setResult(e.target?.result ?? null);
|
||||
if (onLoad) {
|
||||
onLoad(e.target?.result ?? null);
|
||||
}
|
||||
};
|
||||
reader[method](file);
|
||||
}, [file, method, onLoad]);
|
||||
|
||||
return [{ result, error, file, loading }, setFile] as const;
|
||||
};
|
||||
|
||||
type ImageUploaderProps = {
|
||||
id: string;
|
||||
buttonMsg: string;
|
||||
handleAvatarChange: (imageSrc: string) => void;
|
||||
imageSrc?: string;
|
||||
target: string;
|
||||
};
|
||||
|
||||
interface FileEvent<T = Element> extends FormEvent<T> {
|
||||
target: EventTarget & T;
|
||||
}
|
||||
|
||||
// This is separate to prevent loading the component until file upload
|
||||
function CropContainer({
|
||||
onCropComplete,
|
||||
imageSrc,
|
||||
}: {
|
||||
imageSrc: string;
|
||||
onCropComplete: (croppedAreaPixels: Area) => void;
|
||||
}) {
|
||||
const { t } = useLocale();
|
||||
const [crop, setCrop] = useState({ x: 0, y: 0 });
|
||||
const [zoom, setZoom] = useState(1);
|
||||
|
||||
const handleZoomSliderChange = (value: number) => {
|
||||
value < 1 ? setZoom(1) : setZoom(value);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="crop-container h-40 max-h-40 w-40 rounded-full">
|
||||
<div className="relative h-40 w-40 rounded-full">
|
||||
<Cropper
|
||||
image={imageSrc}
|
||||
crop={crop}
|
||||
zoom={zoom}
|
||||
aspect={1}
|
||||
onCropChange={setCrop}
|
||||
onCropComplete={(croppedArea, croppedAreaPixels) => onCropComplete(croppedAreaPixels)}
|
||||
onZoomChange={setZoom}
|
||||
/>
|
||||
</div>
|
||||
<Slider
|
||||
value={zoom}
|
||||
min={1}
|
||||
max={3}
|
||||
step={0.1}
|
||||
label={t("slide_zoom_drag_instructions")}
|
||||
changeHandler={handleZoomSliderChange}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default function ImageUploader({
|
||||
target,
|
||||
id,
|
||||
buttonMsg,
|
||||
handleAvatarChange,
|
||||
...props
|
||||
}: ImageUploaderProps) {
|
||||
const { t } = useLocale();
|
||||
const [imageSrc, setImageSrc] = useState<string | null>(null);
|
||||
const [croppedAreaPixels, setCroppedAreaPixels] = useState<Area | null>(null);
|
||||
|
||||
const [{ result }, setFile] = useFileReader({
|
||||
method: "readAsDataURL",
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
if (props.imageSrc) setImageSrc(props.imageSrc);
|
||||
}, [props.imageSrc]);
|
||||
|
||||
const onInputFile = (e: FileEvent<HTMLInputElement>) => {
|
||||
if (!e.target.files?.length) {
|
||||
return;
|
||||
}
|
||||
setFile(e.target.files[0]);
|
||||
};
|
||||
|
||||
const showCroppedImage = useCallback(
|
||||
async (croppedAreaPixels: Area | null) => {
|
||||
try {
|
||||
if (!croppedAreaPixels) return;
|
||||
const croppedImage = await getCroppedImg(
|
||||
result as string /* result is always string when using readAsDataUrl */,
|
||||
croppedAreaPixels
|
||||
);
|
||||
setImageSrc(croppedImage);
|
||||
handleAvatarChange(croppedImage);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
},
|
||||
[result, handleAvatarChange]
|
||||
);
|
||||
|
||||
return (
|
||||
<Dialog
|
||||
onOpenChange={
|
||||
(opened) => !opened && setFile(null) // unset file on close
|
||||
}>
|
||||
<DialogTrigger asChild>
|
||||
<Button color="secondary" type="button" className="py-1 text-sm">
|
||||
{buttonMsg}
|
||||
</Button>
|
||||
</DialogTrigger>
|
||||
<DialogContent>
|
||||
<div className="mb-4 sm:flex sm:items-start">
|
||||
<div className="mt-3 text-center sm:mt-0 sm:text-left">
|
||||
<h3 className="font-cal text-lg leading-6 text-gray-900" id="modal-title">
|
||||
{t("upload_target", { target })}
|
||||
</h3>
|
||||
</div>
|
||||
</div>
|
||||
<div className="mb-4">
|
||||
<div className="cropper mt-6 flex flex-col items-center justify-center p-8">
|
||||
{!result && (
|
||||
<div className="flex h-20 max-h-20 w-20 items-center justify-start rounded-full bg-gray-50">
|
||||
{!imageSrc && (
|
||||
<p className="w-full text-center text-sm text-white sm:text-xs">
|
||||
{t("no_target", { target })}
|
||||
</p>
|
||||
)}
|
||||
{imageSrc && (
|
||||
// eslint-disable-next-line @next/next/no-img-element
|
||||
<img className="h-20 w-20 rounded-full" src={imageSrc} alt={target} />
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
{result && <CropContainer imageSrc={result as string} onCropComplete={setCroppedAreaPixels} />}
|
||||
<label className="mt-8 rounded-sm border border-gray-300 bg-white px-3 py-1 text-xs font-medium leading-4 text-gray-700 hover:bg-gray-50 hover:text-gray-900 focus:outline-none focus:ring-2 focus:ring-neutral-900 focus:ring-offset-1 dark:border-gray-800 dark:bg-transparent dark:text-white dark:hover:bg-gray-900">
|
||||
<input
|
||||
onInput={onInputFile}
|
||||
type="file"
|
||||
name={id}
|
||||
placeholder={t("upload_image")}
|
||||
className="pointer-events-none absolute mt-4 opacity-0"
|
||||
accept="image/*"
|
||||
/>
|
||||
{t("choose_a_file")}
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div className="mt-5 flex flex-row-reverse gap-x-2 sm:mt-4">
|
||||
<DialogClose onClick={() => showCroppedImage(croppedAreaPixels)}>{t("save")}</DialogClose>
|
||||
<DialogClose color="secondary">{t("cancel")}</DialogClose>
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
|
||||
const createImage = (url: string) =>
|
||||
new Promise<HTMLImageElement>((resolve, reject) => {
|
||||
const image = new Image();
|
||||
image.addEventListener("load", () => resolve(image));
|
||||
image.addEventListener("error", (error) => reject(error));
|
||||
image.setAttribute("crossOrigin", "anonymous"); // needed to avoid cross-origin issues on CodeSandbox
|
||||
image.src = url;
|
||||
});
|
||||
|
||||
async function getCroppedImg(imageSrc: string, pixelCrop: Area): Promise<string> {
|
||||
const image = await createImage(imageSrc);
|
||||
const canvas = document.createElement("canvas");
|
||||
const ctx = canvas.getContext("2d");
|
||||
if (!ctx) throw new Error("Context is null, this should never happen.");
|
||||
|
||||
const maxSize = Math.max(image.naturalWidth, image.naturalHeight);
|
||||
const resizeRatio = MAX_IMAGE_SIZE / maxSize < 1 ? Math.max(MAX_IMAGE_SIZE / maxSize, 0.75) : 1;
|
||||
// huh, what? - Having this turned off actually improves image quality as otherwise anti-aliasing is applied
|
||||
// this reduces the quality of the image overall because it anti-aliases the existing, copied image; blur results
|
||||
ctx.imageSmoothingEnabled = false;
|
||||
// pixelCrop is always 1:1 - width = height
|
||||
canvas.width = canvas.height = Math.min(maxSize * resizeRatio, pixelCrop.width);
|
||||
|
||||
ctx.drawImage(
|
||||
image,
|
||||
pixelCrop.x,
|
||||
pixelCrop.y,
|
||||
pixelCrop.width,
|
||||
pixelCrop.height,
|
||||
0,
|
||||
0,
|
||||
canvas.width,
|
||||
canvas.height
|
||||
);
|
||||
|
||||
// on very low ratios, the quality of the resize becomes awful. For this reason the resizeRatio is limited to 0.75
|
||||
if (resizeRatio <= 0.75) {
|
||||
// With a smaller image, thus improved ratio. Keep doing this until the resizeRatio > 0.75.
|
||||
return getCroppedImg(canvas.toDataURL("image/png"), {
|
||||
width: canvas.width,
|
||||
height: canvas.height,
|
||||
x: 0,
|
||||
y: 0,
|
||||
});
|
||||
}
|
||||
|
||||
return canvas.toDataURL("image/png");
|
||||
}
|
||||
|
||||
const Slider = ({
|
||||
value,
|
||||
label,
|
||||
changeHandler,
|
||||
...props
|
||||
}: Omit<SliderPrimitive.SliderProps, "value"> & {
|
||||
value: number;
|
||||
label: string;
|
||||
changeHandler: (value: number) => void;
|
||||
}) => (
|
||||
<SliderPrimitive.Root
|
||||
className="slider mt-2"
|
||||
value={[value]}
|
||||
aria-label={label}
|
||||
onValueChange={(value: number[]) => changeHandler(value[0] ?? value)}
|
||||
{...props}>
|
||||
<SliderPrimitive.Track className="slider-track">
|
||||
<SliderPrimitive.Range className="slider-range" />
|
||||
</SliderPrimitive.Track>
|
||||
<SliderPrimitive.Thumb className="slider-thumb" />
|
||||
</SliderPrimitive.Root>
|
||||
);
|
||||
@@ -0,0 +1 @@
|
||||
export { default as ImageUploader } from "./ImageUploader";
|
||||
@@ -35,6 +35,27 @@ export {
|
||||
ToggleGroup,
|
||||
ToggleGroupItem,
|
||||
getReactSelectProps,
|
||||
ColorPicker,
|
||||
FormStep,
|
||||
Dropdown,
|
||||
DropdownItem,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuLabel,
|
||||
DropdownMenuPortal,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger,
|
||||
DropdownMenuCheckboxItem,
|
||||
DropdownMenuRadioGroup,
|
||||
ButtonOrLink,
|
||||
DropdownMenuGroup,
|
||||
DropdownMenuRadioItem,
|
||||
DropdownMenuTriggerItem,
|
||||
Steps,
|
||||
WizardForm,
|
||||
SettingsToggle,
|
||||
Stepper,
|
||||
Switch,
|
||||
} from "./form";
|
||||
export type { ITimezone, ITimezoneOption } from "./form";
|
||||
export {
|
||||
@@ -49,7 +70,7 @@ export {
|
||||
} from "./apps";
|
||||
export { TopBanner } from "./top-banner";
|
||||
export type { TopBannerProps } from "./top-banner";
|
||||
export { AnimatedPopover } from "./popover/index";
|
||||
export { AnimatedPopover, MeetingTimeInTimezones } from "./popover";
|
||||
export { TableActions, DropdownActions } from "./table/TableActions";
|
||||
export type { ActionType } from "./table/TableActions";
|
||||
export { Icon } from "./icon";
|
||||
@@ -63,10 +84,17 @@ export { EmptyScreen } from "./empty-screen";
|
||||
export { List, ListItem, ListItemText, ListItemTitle, ListLinkItem } from "./list";
|
||||
export type { ListItemProps, ListProps } from "./list";
|
||||
export { HeadSeo } from "./head-seo";
|
||||
export { Skeleton, SkeletonAvatar, SkeletonButton, SkeletonContainer, SkeletonText } from "./skeleton";
|
||||
export {
|
||||
Skeleton,
|
||||
SkeletonAvatar,
|
||||
SkeletonButton,
|
||||
SkeletonContainer,
|
||||
SkeletonText,
|
||||
Loader,
|
||||
} from "./skeleton";
|
||||
export { HorizontalTabs, HorizontalTabItem, VerticalTabs, VerticalTabItem } from "./navigation";
|
||||
export type { HorizontalTabItemProps, NavTabProps, VerticalTabItemProps } from "./navigation";
|
||||
export { Card, StepCard } from "./card";
|
||||
export { Card, StepCard, FormCard } from "./card";
|
||||
export type { BaseCardProps } from "./card";
|
||||
export { Tooltip } from "./tooltip";
|
||||
export { Editor, AddVariablesDropdown } from "./editor";
|
||||
@@ -81,3 +109,6 @@ export {
|
||||
} from "./dialog";
|
||||
export type { DialogProps, ConfirmationDialogContentProps } from "./dialog";
|
||||
export { showToast } from "./toast"; // We don't export the toast components as they are only used in local storybook file
|
||||
export { Meta, MetaProvider, useMeta } from "./meta";
|
||||
export { Swatch } from "./swatch";
|
||||
export { ShellSubHeading } from "./layout";
|
||||
@@ -0,0 +1,22 @@
|
||||
import { ReactNode } from "react";
|
||||
|
||||
import { classNames } from "@calcom/lib";
|
||||
|
||||
export function ShellSubHeading(props: {
|
||||
title: ReactNode;
|
||||
subtitle?: ReactNode;
|
||||
actions?: ReactNode;
|
||||
className?: string;
|
||||
}) {
|
||||
return (
|
||||
<header className={classNames("mb-3 block justify-between sm:flex", props.className)}>
|
||||
<div>
|
||||
<h2 className="flex content-center items-center space-x-2 text-base font-bold leading-6 text-gray-900 rtl:space-x-reverse">
|
||||
{props.title}
|
||||
</h2>
|
||||
{props.subtitle && <p className="text-sm text-neutral-500 ltr:mr-4">{props.subtitle}</p>}
|
||||
</div>
|
||||
{props.actions && <div className="mt-2 flex-shrink-0 sm:mt-0">{props.actions}</div>}
|
||||
</header>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export { ShellSubHeading } from "./ShellSubHeading";
|
||||
@@ -0,0 +1,64 @@
|
||||
import Head from "next/head";
|
||||
import React, { createContext, useContext, useState, useEffect } from "react";
|
||||
|
||||
import { APP_NAME } from "@calcom/lib/constants";
|
||||
|
||||
type MetaType = {
|
||||
title: string;
|
||||
description: string;
|
||||
backButton?: boolean;
|
||||
CTA?: React.ReactNode;
|
||||
};
|
||||
|
||||
const initialMeta: MetaType = {
|
||||
title: "",
|
||||
description: "",
|
||||
backButton: false,
|
||||
CTA: null,
|
||||
};
|
||||
|
||||
const MetaContext = createContext({
|
||||
meta: initialMeta,
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
||||
setMeta: (newMeta: Partial<MetaType>) => {},
|
||||
});
|
||||
|
||||
export function useMeta() {
|
||||
return useContext(MetaContext);
|
||||
}
|
||||
|
||||
export function MetaProvider({ children }: { children: React.ReactNode }) {
|
||||
const [value, setValue] = useState(initialMeta);
|
||||
const setMeta = (newMeta: Partial<MetaType>) => {
|
||||
setValue((v) => ({ ...v, ...newMeta }));
|
||||
};
|
||||
|
||||
return <MetaContext.Provider value={{ meta: value, setMeta }}>{children}</MetaContext.Provider>;
|
||||
}
|
||||
|
||||
/**
|
||||
* The purpose of this component is to simplify title and description handling.
|
||||
* Similarly to `next/head`'s `Head` component this allow us to update the metadata for a page
|
||||
* from any children, also exposes the metadata via the `useMeta` hook in case we need them
|
||||
* elsewhere (ie. on a Heading, Title, Subtitle, etc.)
|
||||
* @example <Meta title="Password" description="Manage settings for your account passwords" />
|
||||
*/
|
||||
export default function Meta({ title, description, backButton, CTA }: MetaType) {
|
||||
const { setMeta, meta } = useMeta();
|
||||
|
||||
/* @TODO: maybe find a way to have this data on first render to prevent flicker */
|
||||
useEffect(() => {
|
||||
if (meta.title !== title || meta.description !== description || meta.CTA !== CTA) {
|
||||
setMeta({ title, description, backButton, CTA });
|
||||
}
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [title, description, backButton, CTA]);
|
||||
|
||||
const title_ = `${title} | ${APP_NAME}`;
|
||||
return (
|
||||
<Head>
|
||||
<title>{title_}</title>
|
||||
<meta name="description" content={description} />
|
||||
</Head>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export { default as Meta, MetaProvider, useMeta } from "./Meta";
|
||||
File renamed without changes.
@@ -0,0 +1,94 @@
|
||||
import * as Popover from "@radix-ui/react-popover";
|
||||
|
||||
import {
|
||||
formatTime,
|
||||
isNextDayInTimezone,
|
||||
isPreviousDayInTimezone,
|
||||
sortByTimezone,
|
||||
} from "@calcom/lib/date-fns";
|
||||
|
||||
import { Icon } from "../icon";
|
||||
import { Attendee } from ".prisma/client";
|
||||
|
||||
interface MeetingTimeInTimezonesProps {
|
||||
attendees: Attendee[];
|
||||
userTimezone?: string;
|
||||
timeFormat?: number | null;
|
||||
startTime: string;
|
||||
endTime: string;
|
||||
}
|
||||
|
||||
const MeetingTimeInTimezones = ({
|
||||
attendees,
|
||||
userTimezone,
|
||||
timeFormat,
|
||||
startTime,
|
||||
endTime,
|
||||
}: MeetingTimeInTimezonesProps) => {
|
||||
if (!userTimezone || !attendees.length) return null;
|
||||
|
||||
const attendeeTimezones = attendees.map((attendee) => attendee.timeZone);
|
||||
const uniqueTimezones = [userTimezone, ...attendeeTimezones].filter(
|
||||
(value, index, self) => self.indexOf(value) === index
|
||||
);
|
||||
|
||||
// Convert times to time in timezone, and then sort from earliest to latest time in timezone.
|
||||
const times = uniqueTimezones
|
||||
.map((timezone) => {
|
||||
const isPreviousDay = isPreviousDayInTimezone(startTime, userTimezone, timezone);
|
||||
const isNextDay = isNextDayInTimezone(startTime, userTimezone, timezone);
|
||||
return {
|
||||
startTime: formatTime(startTime, timeFormat, timezone),
|
||||
endTime: formatTime(endTime, timeFormat, timezone),
|
||||
timezone,
|
||||
isPreviousDay,
|
||||
isNextDay,
|
||||
};
|
||||
})
|
||||
.sort((timeA, timeB) => sortByTimezone(timeA.timezone, timeB.timezone));
|
||||
|
||||
// We don't show the popover if there's only one timezone.
|
||||
if (times.length === 1) return null;
|
||||
|
||||
return (
|
||||
<Popover.Root>
|
||||
<Popover.Trigger
|
||||
onClick={preventBubbling}
|
||||
className="popover-button invisible ml-2 inline-flex h-5 w-5 items-center justify-center rounded-sm text-gray-900 transition-colors hover:bg-gray-200 focus:bg-gray-200 group-hover:visible">
|
||||
<Icon.FiGlobe />
|
||||
</Popover.Trigger>
|
||||
<Popover.Portal>
|
||||
<Popover.Content
|
||||
onClick={preventBubbling}
|
||||
side="top"
|
||||
className="popover-content slideInBottom border-5 bg-brand-500 rounded-md border-gray-200 p-3 text-sm text-white shadow-sm">
|
||||
{times.map((time) => (
|
||||
<span className="mt-2 block first:mt-0" key={time.timezone}>
|
||||
<span className="inline-flex align-baseline">
|
||||
{time.startTime} - {time.endTime}
|
||||
{(time.isNextDay || time.isPreviousDay) && (
|
||||
<span className="text-medium ml-2 inline-flex h-5 w-5 items-center justify-center rounded-full bg-gray-700 text-[10px]">
|
||||
{time.isNextDay ? "+1" : "-1"}
|
||||
</span>
|
||||
)}
|
||||
</span>
|
||||
<br />
|
||||
<span className="text-gray-400">{time.timezone}</span>
|
||||
</span>
|
||||
))}
|
||||
</Popover.Content>
|
||||
</Popover.Portal>
|
||||
</Popover.Root>
|
||||
);
|
||||
};
|
||||
|
||||
MeetingTimeInTimezones.displayName = "MeetingTimeInTimezones";
|
||||
|
||||
// Prevents propagation so the click on eg booking overview won't
|
||||
// bubble to the row of the table, causing a navigation to the
|
||||
// detaill page.
|
||||
const preventBubbling = (event: React.MouseEvent) => {
|
||||
event.stopPropagation();
|
||||
};
|
||||
|
||||
export default MeetingTimeInTimezones;
|
||||
@@ -0,0 +1,2 @@
|
||||
export { AnimatedPopover } from "./AnimatedPopover";
|
||||
export { default as MeetingTimeInTimezones } from "./MeetingTimeInTimezones";
|
||||
@@ -0,0 +1,10 @@
|
||||
/**
|
||||
* @deprecated Use custom Skeletons instead
|
||||
**/
|
||||
export default function Loader() {
|
||||
return (
|
||||
<div className="loader border-brand dark:border-darkmodebrand">
|
||||
<span className="loader-inner bg-brand dark:bg-darkmodebrand" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -94,3 +94,4 @@ const SkeletonContainer: React.FC<SkeletonContainer> = ({ children, as, classNam
|
||||
};
|
||||
|
||||
export { Skeleton, SkeletonAvatar, SkeletonText, SkeletonButton, SkeletonContainer };
|
||||
export { default as Loader } from "./Loader";
|
||||
@@ -0,0 +1,27 @@
|
||||
import classNames from "@calcom/lib/classNames";
|
||||
|
||||
export type SwatchProps = {
|
||||
size?: "base" | "sm" | "lg";
|
||||
backgroundColor: string;
|
||||
onClick: () => void;
|
||||
};
|
||||
|
||||
const Swatch = (props: SwatchProps) => {
|
||||
const { size, backgroundColor, onClick } = props;
|
||||
return (
|
||||
<div className="border-2 border-gray-200 p-1">
|
||||
<div
|
||||
onClick={onClick}
|
||||
style={{ backgroundColor }}
|
||||
className={classNames(
|
||||
"cursor-pointer",
|
||||
size === "sm" && "h-6 w-6 rounded-sm",
|
||||
size === "base" && "h-16 w-16 rounded-sm",
|
||||
size === "lg" && "h-24 w-24 rounded-sm"
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default Swatch;
|
||||
@@ -0,0 +1 @@
|
||||
export { default as Swatch } from "./Swatch";
|
||||
Reference in new issue
Block a user