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 May 1, 2023
1 parent 171155a commit 10b96d1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 34 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
46 changes: 14 additions & 32 deletions src/types/variants.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,16 @@
import type { CSSProperties } from './css'
import type { PinceauMediaQueries } from './theme'
import type { CSSProperties } from './css';

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

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 =
(BooleanVariant | EnumVariant | ClassVariant)
&
{
options?: VariantOptions
}

export interface Variants {
[key: string]: Variant
}
export type Variants<T> = T extends Record<string, any> ? Variant<T> : any;

0 comments on commit 10b96d1

Please sign in to comment.