* WIP * Locked fields manager * Leftovers * Bad merge fix * Type import fix * Moving away from classes * Progress refactoring locked logic * Covering apps, webhooks and workflows * Supporting webhooks and workflows (TBT) * Restoring yarn.lock * Progress * Refactoring code, adding default values * Fixing CRUD for children * Connect app link and case-sensitive lib renaming * Translation missing * Locked indicators, empty screens, locations * Member card and hidden status + missing i18n * Missing existent children shown * Showing preview for already created children * Email notification almost in place * Making progress over notif email * Fixing nodemailer by mixed FE/BE mixup * Delete dialog * Adding tests * New test * Reverting unneeded change * Removed console.log * Tweaking email * Reverting not applicable webhook changes * Reverting dev email api * Fixing last changes due to tests * Changing user-evType relationship * Availability and slug replacement tweaks * Fixing event type delete * Sometimes slug is not there... * Removing old webhooks references Changed slug hint * Fixing types * Fixing hiding event types actions * Changing delete dialog text * Removing unneeded code * Applying feedback * Update yarn.lock * Making sure locked fields values are static * Applying feedback * Feedback + relying on children list, not users * Removing console.log * PR Feedback * Telemetry for slug replacement action * More unit tests * Relying on schedule and editor tweaks * Fixing conteiner classname * PR Feedback * PR Feedback * Updating unit tests * Moving stuff to ee, added feature flag * type fix * Including e2e * Reverting unneeded changes in EmptyScreen * Fixing some UI issues after merging tokens * Fixing missing disabled locked fields * Theme fixes + e2e potential fix * Fixing e2e * Fixing login relying on network * Tweaking e2e * Removing unneeded code --------- Co-authored-by: Peer Richelsen <[email protected]> Co-authored-by: zomars <[email protected]>
72 lines
2.2 KiB
TypeScript
72 lines
2.2 KiB
TypeScript
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 cx from "@calcom/lib/classNames";
|
|
|
|
import { Tooltip } from "../../tooltip";
|
|
|
|
const Wrapper = ({ children, tooltip }: { tooltip?: string; children: React.ReactNode }) => {
|
|
if (!tooltip) {
|
|
return <>{children}</>;
|
|
}
|
|
return <Tooltip content={tooltip}>{children}</Tooltip>;
|
|
};
|
|
const Switch = (
|
|
props: React.ComponentProps<typeof PrimitiveSwitch.Root> & {
|
|
label?: string;
|
|
fitToHeight?: boolean;
|
|
disabled?: boolean;
|
|
tooltip?: string;
|
|
classNames?: {
|
|
container?: string;
|
|
thumb?: string;
|
|
};
|
|
}
|
|
) => {
|
|
const { label, fitToHeight, classNames, ...primitiveProps } = props;
|
|
const id = useId();
|
|
|
|
return (
|
|
<Wrapper tooltip={props.tooltip}>
|
|
<div
|
|
className={cx(
|
|
"flex h-auto w-auto flex-row items-center",
|
|
fitToHeight && "h-fit",
|
|
classNames?.container
|
|
)}>
|
|
<PrimitiveSwitch.Root
|
|
className={cx(
|
|
props.checked || props.defaultChecked ? "bg-inverted" : "bg-emphasis",
|
|
primitiveProps.disabled && "cursor-not-allowed",
|
|
"focus:ring-brand-default h-5 w-[34px] rounded-full shadow-none",
|
|
props.className
|
|
)}
|
|
{...primitiveProps}>
|
|
<PrimitiveSwitch.Thumb
|
|
id={id}
|
|
className={cx(
|
|
"block h-[14px] w-[14px] rounded-full 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 || props.defaultChecked ? "bg-default shadow-inner" : "bg-inverted",
|
|
classNames?.thumb
|
|
)}
|
|
/>
|
|
</PrimitiveSwitch.Root>
|
|
{label && (
|
|
<Label.Root
|
|
htmlFor={id}
|
|
className={cx(
|
|
"text-emphasis ms-2 align-text-top text-sm font-medium",
|
|
primitiveProps.disabled ? "cursor-not-allowed opacity-25" : "cursor-pointer "
|
|
)}>
|
|
{label}
|
|
</Label.Root>
|
|
)}
|
|
</div>
|
|
</Wrapper>
|
|
);
|
|
};
|
|
|
|
export default Switch;
|