Skip to content

Commit

Permalink
fix(types): css() not giving correct suggestion, variants default opt…
Browse files Browse the repository at this point in the history
…ion not accepting correct value

Fix #85
  • Loading branch information
wypratama committed Apr 16, 2023
1 parent 171155a commit 771d178
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 31 deletions.
2 changes: 1 addition & 1 deletion src/runtime/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const plugin: Plugin = {
*/
function usePinceauRuntime(
props: any = {},
variants: Variants,
variants: Variants<typeof props>,
computedStyles: { [key: string]: ComputedRef },
) {
// Current component instance
Expand Down
2 changes: 1 addition & 1 deletion src/types/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export type CSSFunctionType<
UtilsProperties = PinceauUtils,
> =
{
variants?: Variants
variants?: Variants<ComponentProps>
}
&
{
Expand Down
41 changes: 12 additions & 29 deletions src/types/variants.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,17 @@
import type { CSSProperties } from './css'
import type { PinceauMediaQueries } from './theme'

export interface VariantOptions<T = string> {
type?: string
required?: boolean
default?: T | { [key in PinceauMediaQueries]?: T }
mediaPrefix?: boolean
}

export interface BooleanVariant {
true?: CSSProperties
false?: CSSProperties
[key: string]: CSSProperties
}

export interface EnumVariant {
[key: string]: CSSProperties
}

export interface ClassVariant {
[key: string]: string | (CSSProperties & { $class?: string })
export type Variant<T> = {
[K in keyof T]: {
[key: string]: string | (CSSProperties & { $class?: string })
} & {
options?: {
default?: T[K]
required?: boolean
mediaPrefix?: boolean
readonly type?: PropType<T[K]>
}
}
}

export type Variant =
(BooleanVariant | EnumVariant | ClassVariant)
&
{
options?: VariantOptions
}
export type Variants<T> = T extends Record<string, any> ? Variant<T> : any

export interface Variants {
[key: string]: Variant
}

0 comments on commit 771d178

Please sign in to comment.