fix(ui): Bump cva and minor type fixes (#5818)

**What**
- Bumps `class-variance-authority` to new beta version - `cva@beta`.
- Updates all usages of `cva` to new API.
- Clear up the naming of types in `usePrompt`

**Why**
- A bug in how `class-variance-authority` exported its types mean that we were relying on patching the package to ensure that the correct types made it into the build of our UI package. This was important to ensure intellisense for component variants, such as `<Button size="large" />`. Previously in the UI monorepo, having the patch was enough to ensure that the correct types made it into the build, but that was not the case after we moved the design system to the core repo. The issue with types is fixed in the `@1` version of `cva` which is currently in beta. I have pinpointed the version to the current beta version to ensure stability despite the package currently being in beta.
This commit is contained in:
Kasper Fabricius Kristensen
2023-12-07 21:13:44 +01:00
committed by GitHub
parent 85cda7ce37
commit 591ba2388d
21 changed files with 228 additions and 305 deletions

View File

@@ -1,71 +0,0 @@
diff --git a/dist/index.d.ts b/dist/index.d.ts
index 676e466a43ad8932cbb3131bb2c3dea687d47041..cbffdc5191bd8535468fdeaf68365845d15804ea 100644
--- a/dist/index.d.ts
+++ b/dist/index.d.ts
@@ -1,21 +1,55 @@
+import type * as CLSX from "clsx";
import clsx from "clsx";
-import type { ClassProp, ClassValue, OmitUndefined, StringToBoolean } from "./types";
-export type VariantProps<Component extends (...args: any) => any> = Omit<OmitUndefined<Parameters<Component>[0]>, "class" | "className">;
+
+type ClassPropKey = "class" | "className";
+type ClassValue = CLSX.ClassValue;
+type ClassProp =
+ | {
+ class: ClassValue;
+ className?: never;
+ }
+ | {
+ class?: never;
+ className: ClassValue;
+ }
+ | {
+ class?: never;
+ className?: never;
+ };
+type OmitUndefined<T> = T extends undefined ? never : T;
+type StringToBoolean<T> = T extends "true" | "false" ? boolean : T;
+
+export type VariantProps<Component extends (...args: any) => any> = Omit<
+ OmitUndefined<Parameters<Component>[0]>,
+ "class" | "className"
+>;
export type CxOptions = Parameters<typeof clsx>;
export type CxReturn = ReturnType<typeof clsx>;
export declare const cx: typeof clsx;
type ConfigSchema = Record<string, Record<string, ClassValue>>;
type ConfigVariants<T extends ConfigSchema> = {
- [Variant in keyof T]?: StringToBoolean<keyof T[Variant]> | null | undefined;
+ [Variant in keyof T]?: StringToBoolean<keyof T[Variant]> | null | undefined;
};
type ConfigVariantsMulti<T extends ConfigSchema> = {
- [Variant in keyof T]?: StringToBoolean<keyof T[Variant]> | StringToBoolean<keyof T[Variant]>[] | undefined;
+ [Variant in keyof T]?:
+ | StringToBoolean<keyof T[Variant]>
+ | StringToBoolean<keyof T[Variant]>[]
+ | undefined;
};
-type Config<T> = T extends ConfigSchema ? {
- variants?: T;
- defaultVariants?: ConfigVariants<T>;
- compoundVariants?: (T extends ConfigSchema ? (ConfigVariants<T> | ConfigVariantsMulti<T>) & ClassProp : ClassProp)[];
-} : never;
-type Props<T> = T extends ConfigSchema ? ConfigVariants<T> & ClassProp : ClassProp;
-export declare const cva: <T>(base?: ClassValue, config?: Config<T> | undefined) => (props?: Props<T> | undefined) => string;
+type Config<T> = T extends ConfigSchema
+ ? {
+ variants?: T;
+ defaultVariants?: ConfigVariants<T>;
+ compoundVariants?: (T extends ConfigSchema
+ ? (ConfigVariants<T> | ConfigVariantsMulti<T>) & ClassProp
+ : ClassProp)[];
+ }
+ : never;
+type Props<T> = T extends ConfigSchema
+ ? ConfigVariants<T> & ClassProp
+ : ClassProp;
+export declare const cva: <T>(
+ base?: ClassValue,
+ config?: Config<T> | undefined
+) => (props?: Props<T> | undefined) => string;
export {};