Skip to content

Commit

Permalink
Merge pull request #301 from jpudysz/feature/get-theme
Browse files Browse the repository at this point in the history
feat: get theme by name
  • Loading branch information
jpudysz authored Oct 2, 2024
2 parents 4682e60 + e5026b8 commit 7b98bed
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/.astro/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"_variables": {
"lastUpdateCheck": 1725018017706
"lastUpdateCheck": 1727846556761
}
}
6 changes: 3 additions & 3 deletions docs/astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,12 @@ export default defineConfig({
},
{
label: 'Unistyles Registry',
link: '/reference/unistyles-registry/',
badge: 'Updated'
link: '/reference/unistyles-registry/'
},
{
label: 'Unistyles Runtime',
link: '/reference/unistyles-runtime/'
link: '/reference/unistyles-runtime/',
badge: 'Updated'
},
{
label: 'Content size category',
Expand Down
1 change: 1 addition & 0 deletions docs/src/content/docs/reference/unistyles-runtime.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ and use it anywhere in your code, even outside a component.
| <Badge label="2.8.0" />| fontScale | number | Font scale of the device |
| <Badge label="2.9.0" />| hairlineWidth | number | The thinnest width of the platform |
| <Badge label="2.9.0" />| rtl | boolean | Indicates if the device is in RTL mode |
| <Badge label="2.10.0" />| getTheme | (themeName?: string) => Theme | Get theme by name or current theme if not specified |

## Setters

Expand Down
13 changes: 13 additions & 0 deletions src/core/UnistylesRuntime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,19 @@ export class UnistylesRuntime {
return nearestPixel / pixelRatio
}

/**
* Get theme by name
* @param themeName - The name of the theme to get or current theme if not specified
* @returns - The theme
*/
public getTheme(themeName?: keyof UnistylesThemes) {
if (!themeName) {
return this.unistylesRegistry.getTheme(this.themeName)
}

return this.unistylesRegistry.getTheme(themeName)
}

/**
* Get the immersive mode (both status bar and navigation bar hidden (Android))
* @param isEnabled
Expand Down
8 changes: 8 additions & 0 deletions src/core/mocks/UnistylesMockedRuntime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,14 @@ export class UnistylesMockedRuntime {
return ScreenOrientation.Portrait
}

public getTheme = (themeName?: keyof UnistylesThemes) => {
if (!themeName) {
return this.unistylesRegistry.getTheme(this.themeName)
}

return this.unistylesRegistry.getTheme(themeName)
}

public setTheme = (name: keyof UnistylesThemes) => true
public updateTheme = (name: keyof UnistylesThemes, theme: UnistylesThemes[keyof UnistylesThemes]) => {}
public setAdaptiveThemes = (enabled: boolean) => {}
Expand Down

0 comments on commit 7b98bed

Please sign in to comment.