fix: Do not self import @calcom/ui (#20050)

* fix: Do not self import @calcom/ui

* Make translations optional

* Fix mocking implementation of Button (never worked)

* Ensure other libraries can resolve AppListCard
This commit is contained in:
Alex van Andel authored and GitHub committed 2025-03-13 18:17:42 +00:00
1 parent b1ebefb854
commit be404436d7
28 files changed
+201 -124

No files matched your search

@@ -4,13 +4,18 @@ import { act } from "react-dom/test-utils";
import { vi } from "vitest";
import type { ButtonProps } from "../../button";
import { Button } from "../../button";
import ColorPicker from "./colorpicker";
vi.mock("@calcom/ui", async () => {
vi.mock("../../button/Button", async () => {
const ButtonMock = (await import("../../button/Button")).Button;
return {
Button: ({ tooltip, ...rest }: ButtonProps) => <ButtonMock {...rest}>{tooltip}</ButtonMock>,
};
});
vi.mock("../icon/Icon", async () => {
return {
Icon: () => <svg data-testid="dummy-icon" />,
Button: ({ tooltip, ...rest }: ButtonProps) => <Button {...rest}>{tooltip}</Button>,
};
});
@@ -5,9 +5,10 @@ import { useState } from "react";
import { HexColorInput, HexColorPicker } from "react-colorful";
import { fallBackHex, isValidHexCode } from "@calcom/lib/getBrandColours";
import { Button } from "@calcom/ui";
import cx from "@calcom/ui/classNames";
import { Button } from "../../button/Button";
export type ColorPickerProps = {
defaultValue: string;
onChange: (text: string) => void;
@@ -73,6 +74,7 @@ const ColorPicker = (props: ColorPickerProps) => {
target="_blank"
variant="icon"
rel="noreferrer"
aria-label="Reset to default"
StartIcon="rotate-ccw"
tooltip="Reset to default"
onClick={() => {
@@ -1,9 +1,9 @@
import * as Popover from "@radix-ui/react-popover";
import { format } from "date-fns";
import { Button } from "@calcom/ui";
import classNames from "@calcom/ui/classNames";
import { Button } from "../../button/Button";
import { Calendar } from "../date-range-picker/Calendar";
type Props = {
@@ -22,6 +22,11 @@ export function InputLeading(props: JSX.IntrinsicElements["div"]) {
);
}
type PasswordFieldTranslations = {
showPasswordText?: string;
hidePasswordText?: string;
};
export const PasswordField = forwardRef<HTMLInputElement, InputFieldProps>(function PasswordField(
props,
ref
+2 -1
View File
@@ -2,7 +2,8 @@ import type { VariantProps } from "class-variance-authority";
import type { inputStyles } from "./TextField";
export type InputFieldProps = {
export type InputFieldProps<Translations extends Record<string, string> = object> = {
translations?: Translations;
label?: React.ReactNode;
LockedIcon?: React.ReactNode;
hint?: string;
@@ -5,7 +5,7 @@ import * as React from "react";
import classNames from "@calcom/ui/classNames";
const Slider = React.forwardRef<
const RangeSlider = React.forwardRef<
React.ElementRef<typeof SliderPrimitive.Root>,
React.ComponentPropsWithoutRef<typeof SliderPrimitive.Root>
>(({ className, ...props }, ref) => (
@@ -20,6 +20,6 @@ const Slider = React.forwardRef<
<SliderPrimitive.Thumb className="border-subtle bg-brand-default ring-offset-background focus-visible:ring-ring block h-4 w-4 rounded-full border-2 border-[1px] transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50" />
</SliderPrimitive.Root>
));
Slider.displayName = SliderPrimitive.Root.displayName;
RangeSlider.displayName = SliderPrimitive.Root.displayName;
export { Slider };
export { RangeSlider };
@@ -3,13 +3,15 @@
import * as Popover from "@radix-ui/react-popover";
import { useState } from "react";
import { Badge, Button } from "@calcom/ui";
import { Badge } from "../../badge/Badge";
import { Button } from "../../button/Button";
import { inputStyles, TextField } from "../inputs/TextField";
import { Slider } from "./index";
import { RangeSlider } from "./RangeSlider";
interface RangeSliderPopoverProps {
triggerText: string;
resetBtnText?: string;
applyBtnText?: string;
value: number[];
onChange: (value: number[]) => void;
min: number;
@@ -22,6 +24,8 @@ interface RangeSliderPopoverProps {
}
export const RangeSliderPopover = ({
resetBtnText = "Reset",
applyBtnText = "Apply",
triggerText,
value,
onChange,
@@ -62,7 +66,13 @@ export const RangeSliderPopover = ({
align="start"
className="border-subtle shadow-dropdown bg-default z-50 mt-2 w-72 rounded-lg border-[1px] px-4 pb-3 pt-4 font-[family-name:var(--font-inter)]">
<div className="mb-4">
<Slider min={min} max={max} step={step} value={internalValue} onValueChange={setInternalValue} />
<RangeSlider
min={min}
max={max}
step={step}
value={internalValue}
onValueChange={setInternalValue}
/>
</div>
<div className="mb-4 flex items-center justify-between gap-2">
<TextField
@@ -105,10 +115,10 @@ export const RangeSliderPopover = ({
<hr className="border-subtle" />
<div className="mt-3 flex items-center justify-end gap-2 px-4">
<Button color="minimal" size="sm" onClick={handleReset}>
Reset
{resetBtnText}
</Button>
<Button color="secondary" size="sm" onClick={handleApply}>
Apply
{applyBtnText}
</Button>
</div>
</div>
@@ -1,9 +1,10 @@
import * as RadixToggleGroup from "@radix-ui/react-toggle-group";
import type { ReactNode } from "react";
import { Tooltip } from "@calcom/ui";
import classNames from "@calcom/ui/classNames";
import { Tooltip } from "../../tooltip/Tooltip";
interface ToggleGroupProps extends Omit<RadixToggleGroup.ToggleGroupSingleProps, "type"> {
options: {
value: string;