Skip to content
Merged
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
2 changes: 1 addition & 1 deletion bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/uniwind/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"circular:check": "dpdm --no-warning --no-tree -T --exit-code circular:1 'src/**/*.ts' 'src/**/*.tsx'",
"test:native": "jest --config jest.config.native.js",
"test:web": "jest --config jest.config.web.js",
"test:types": "tsc --project tests/type-test/tsconfig.json",
"test:e2e": "playwright test",
"release": "release-it"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/uniwind/src/hooks/useUniwind.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { UniwindListener } from '../core/listener'
import { ThemeName } from '../core/types'
import { StyleDependency } from '../types'

export const useUniwind = () => {
export const useUniwind = (): { theme: ThemeName; hasAdaptiveThemes: boolean } => {
const uniwindContext = useUniwindContext()
const [theme, setTheme] = useState(Uniwind.currentTheme)
const [hasAdaptiveThemes, setHasAdaptiveThemes] = useState(Uniwind.hasAdaptiveThemes)
Expand All @@ -26,7 +26,7 @@ export const useUniwind = () => {
}, [uniwindContext])

return {
theme: uniwindContext.scopedTheme ?? theme as ThemeName,
theme: uniwindContext.scopedTheme ?? theme,
hasAdaptiveThemes: uniwindContext.scopedTheme !== null ? false : hasAdaptiveThemes,
}
}
4 changes: 4 additions & 0 deletions packages/uniwind/tests/type-test/checks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export type Equal<A, B> = (<T>() => T extends A ? 1 : 2) extends (<T>() => T extends B ? 1 : 2) ? true
: false

export type Expect<T extends true> = Equal<T, true>
7 changes: 7 additions & 0 deletions packages/uniwind/tests/type-test/setup.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import 'uniwind'

declare module 'uniwind' {
export interface UniwindConfig {
themes: readonly ['light', 'dark', 'premium', 'custom']
}
}
30 changes: 30 additions & 0 deletions packages/uniwind/tests/type-test/theme.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import type { ComponentProps } from 'react'
import { ScopedTheme, type ThemeName, Uniwind, useUniwind } from 'uniwind'
import { type Equal, type Expect } from './checks'

type ExpectedThemeName = 'light' | 'dark' | 'premium' | 'custom'

// ThemeName exported from uniwind
type ThemeNameTest = Expect<Equal<ThemeName, ExpectedThemeName>>

// useUniwind.theme
type UseUniwindThemeResult = ReturnType<typeof useUniwind>['theme']
type UseUniwindTest = Expect<Equal<UseUniwindThemeResult, ExpectedThemeName>>

// Uniwind.currentTheme
type UniwindCurrentThemeTest = Expect<Equal<typeof Uniwind.currentTheme, ExpectedThemeName>>

// Uniwind.themes
type UniwindThemesTest = Expect<Equal<typeof Uniwind.themes, Array<ExpectedThemeName>>>

// Uniwind.setTheme
type UniwindSetThemeParameter = Parameters<typeof Uniwind.setTheme>[0]
type UniwindSetThemeTest = Expect<Equal<UniwindSetThemeParameter, ExpectedThemeName | 'system'>>

// Uniwind.updateCSSVariables
type UniwindUpdateCSSVariablesThemeParameter = Parameters<typeof Uniwind.updateCSSVariables>[0]
type UniwindUpdateCSSVariablesThemeTest = Expect<Equal<UniwindUpdateCSSVariablesThemeParameter, ExpectedThemeName>>

// ScopedTheme theme prop
type ScopedThemeThemeProp = ComponentProps<typeof ScopedTheme>['theme']
type ScopedThemeThemePropTest = Expect<Equal<ScopedThemeThemeProp, ExpectedThemeName>>
15 changes: 15 additions & 0 deletions packages/uniwind/tests/type-test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"noEmit": true,
"rootDir": ".",
"baseUrl": ".",
"paths": {
"uniwind": ["../../dist/module/index.d.ts"]
}
},
"include": [
"setup.d.ts",
"*.ts"
]
}
16 changes: 14 additions & 2 deletions turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,29 @@
"//#check:format": {},
"circular:check": {},
"precommit": {
"dependsOn": ["lint", "check:typescript", "circular:check", "test:native", "test:web", "//#check:format"]
"dependsOn": [
"lint",
"check:typescript",
"circular:check",
"test:native",
"test:web",
"test:types",
"//#check:format"
]
},
"test": {
"dependsOn": ["test:native", "test:web", "test:e2e"]
"dependsOn": ["test:native", "test:web", "test:types", "test:e2e"]
},
"test:native": {
"cache": false
},
"test:web": {
"cache": false
},
"test:types": {
"dependsOn": ["build"],
"cache": false
},
"test:e2e": {
"cache": false
}
Expand Down