Skip to content

Commit

Permalink
feat: flatten types
Browse files Browse the repository at this point in the history
  • Loading branch information
wagerfield committed Aug 7, 2023
1 parent a9cd56f commit a4336ce
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import { ClassValue } from "clsx"

// Class Types

export type { ClassValue }

export type ClassKey = "className"

export type ClassProps = Partial<Record<ClassKey, ClassValue>>

// Utility Types

export type Flatten<T> = T extends object ? {} & { [P in keyof T]: T[P] } : T

// Onno Class Types

export type OnnoClassValue = string | string[]
Expand All @@ -30,8 +36,8 @@ export type OnnoCompound<T extends OnnoVariants> = {

export interface OnnoConfig<T extends OnnoVariants> {
baseline?: OnnoClassValue
compound?: OnnoCompound<T>[]
defaults?: OnnoDefaults<T>
compound?: Flatten<OnnoCompound<T>>[]
defaults?: Flatten<OnnoDefaults<T>>
variants: T
}

Expand All @@ -40,7 +46,7 @@ export type OnnoOptions<T extends OnnoVariants> = OnnoDefaults<T> & ClassProps
// Onno Function Types

export type OnnoFunction<T extends OnnoVariants> = (
options?: OnnoOptions<T>,
options?: Flatten<OnnoOptions<T>>,
) => string

export type OnnoFactory = <T extends OnnoVariants>(
Expand All @@ -49,12 +55,14 @@ export type OnnoFactory = <T extends OnnoVariants>(

// Onno Prop Types

type OnnoVariantProps<F extends OnnoFunction<any>> = Omit<
export type OnnoVariantProps<F extends OnnoFunction<any>> = Omit<
Exclude<Parameters<F>[0], undefined>,
ClassKey
>

export type OnnoProps<
F extends OnnoFunction<any>,
K extends keyof OnnoVariantProps<F> = never,
> = OnnoVariantProps<F> & Required<Pick<OnnoVariantProps<F>, K>> & ClassProps
> = Flatten<
OnnoVariantProps<F> & Required<Pick<OnnoVariantProps<F>, K>> & ClassProps
>

0 comments on commit a4336ce

Please sign in to comment.