Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(types): css() not giving correct suggestion, variants default option not accepting correct value #87

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 3 additions & 118 deletions playground/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,119 +1,4 @@
{
"compilerOptions": {
"jsx": "preserve",
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "Node",
"skipLibCheck": true,
"strict": true,
"allowJs": true,
"noEmit": true,
"resolveJsonModule": true,
"allowSyntheticDefaultImports": true,
"types": [
"node"
],
"baseUrl": ".",
"paths": {
"~~": [
"."
],
"~~/*": [
"./*"
],
"@@": [
"."
],
"@@/*": [
"./*"
],
"~": [
"."
],
"~/*": [
"./*"
],
"@": [
"."
],
"@/*": [
"./*"
],
"assets": [
"assets"
],
"public": [
"public"
],
"public/*": [
"public/*"
],
"pinceau/runtime": [
"../src/runtime"
],
"pinceau": [
"../src/index"
],
"#app": [
"./node_modules/.pnpm/[email protected]/node_modules/nuxt/dist/app"
],
"#app/*": [
"./node_modules/.pnpm/[email protected]/node_modules/nuxt/dist/app/*"
],
"vue-demi": [
"./node_modules/.pnpm/[email protected]/node_modules/nuxt/dist/app/compat/vue-demi"
],
"#color-mode-options": [
"./.nuxt/color-mode-options"
],
"#nuxt-component-meta": [
"./.nuxt/component-meta.mjs"
],
"#nuxt-component-meta/types": [
"./.nuxt/component-meta.d.ts"
],
"#head": [
"./node_modules/.pnpm/[email protected]/node_modules/nuxt/dist/head/runtime"
],
"#head/*": [
"./node_modules/.pnpm/[email protected]/node_modules/nuxt/dist/head/runtime/*"
],
"#imports": [
"./.nuxt/imports"
],
"#build": [
"./.nuxt"
],
"#build/*": [
"./.nuxt/*"
],
"#pinceau/utils": [
"/Users/yaelguilloux/Code/sandbox/pinceau/playground/.nuxt/pinceau/utils.ts"
],
"#pinceau/theme": [
"/Users/yaelguilloux/Code/sandbox/pinceau/playground/.nuxt/pinceau/index.ts"
],
"#pinceau/schema": [
"/Users/yaelguilloux/Code/sandbox/pinceau/playground/.nuxt/pinceau/schema.ts"
],
"#pinceau/definitions": [
"/Users/yaelguilloux/Code/sandbox/pinceau/playground/.nuxt/pinceau/schema.ts"
],
"#components": [
"./.nuxt/components"
]
}
},
"include": [
"./.nuxt/nuxt.d.ts",
"../**/*"
],
"exclude": [
"./dist"
],
"vueCompilerOptions": {
"plugins": [
"../dist/volar.cjs"
]
}
}
// https://nuxt.com/docs/guide/concepts/typescript
"extends": "./.nuxt/tsconfig.json"
}
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
2 changes: 1 addition & 1 deletion src/types/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ export type PinceauTokensPaths = GeneratedPinceauPaths

export type PinceauUtils = GeneratedPinceauUtils

export type PinceauMediaQueries = 'dark' | 'light' | 'initial' | (keyof PinceauTheme['media'] extends string ? keyof PinceauTheme['media'] : never)
export type PinceauMediaQueries = 'dark' | 'light' | 'initial' | keyof Pick<PinceauTheme, 'media'>['media']
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;