Skip to content

Commit f325691

Browse files
authored
Merge pull request #281 from devforth/add-single-theme-support
feat: add support for single theme configuration in AdminForth
2 parents 2826e56 + 37fd817 commit f325691

File tree

6 files changed

+39
-1
lines changed

6 files changed

+39
-1
lines changed

adminforth/documentation/docs/tutorial/03-Customization/01-branding.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,26 @@ const admin = new AdminForth({
9494
Here is how it looks:
9595
![AdminForth Themes](image-10.png)
9696

97+
## Single theme
98+
99+
If you want to enforce a consistent theme and disable the theme switcher, you can configure AdminForth to use only one theme variant.
100+
101+
```ts title='./index.ts'
102+
103+
const admin = new AdminForth({
104+
...
105+
customization: {
106+
//diff-add
107+
singleTheme: "light",
108+
styles: {
109+
...
110+
}
111+
}
112+
},
113+
...
114+
});
115+
```
116+
97117

98118
## Square vs rounded buttons?
99119

adminforth/modules/restApi.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ export default class AdminForthRestAPI implements IAdminForthRestAPI {
223223
everyPageBottom: this.adminforth.config.customization.globalInjections.everyPageBottom,
224224
},
225225
rememberMeDays: this.adminforth.config.auth.rememberMeDays,
226+
singleTheme: this.adminforth.config.customization.singleTheme,
226227
};
227228
},
228229
});
@@ -301,6 +302,7 @@ export default class AdminForthRestAPI implements IAdminForthRestAPI {
301302
loginPromptHTML: await tr(this.adminforth.config.auth.loginPromptHTML, 'system.loginPromptHTML'),
302303
loginPageInjections: this.adminforth.config.customization.loginPageInjections,
303304
rememberMeDays: this.adminforth.config.auth.rememberMeDays,
305+
singleTheme: this.adminforth.config.customization.singleTheme,
304306
}
305307

306308
const loggedInPart = {

adminforth/spa/src/App.vue

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
/>
2525

2626
<div class="flex items-center ms-3 ">
27-
<span
27+
<span
28+
v-if="!coreStore.config?.singleTheme"
2829
@click="toggleTheme" class="cursor-pointer flex items-center gap-1 block px-4 py-2 text-sm text-black hover:bg-lightHtml dark:text-darkSidebarTextHover dark:hover:bg-darkHtml dark:hover:text-darkSidebarTextActive" role="menuitem">
2930
<IconMoonSolid class="w-5 h-5 text-blue-300" v-if="coreStore.theme !== 'dark'" />
3031
<IconSunSolid class="w-5 h-5 text-yellow-300" v-else />
@@ -410,6 +411,14 @@ onBeforeMount(()=>{
410411
document.documentElement.classList.toggle('dark', theme.value === 'dark');
411412
})
412413
414+
watch(() => coreStore.config?.singleTheme, (singleTheme) => {
415+
if (singleTheme) {
416+
theme.value = singleTheme;
417+
window.localStorage.setItem('af__theme', singleTheme);
418+
document.documentElement.classList.toggle('dark', theme.value === 'dark');
419+
}
420+
}, { immediate: true })
421+
413422
414423
const ctaBadge: Ref<(AnnouncementBadgeResponse & { hash: string; }) | null> = computed(() => {
415424
const badge = coreStore.config?.announcementBadge;

adminforth/spa/src/spa_types/core.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export type ResourceColumns = {
2121

2222
export type CoreConfig = {
2323
brandName: string,
24+
singleTheme?: 'light' | 'dark',
2425
brandLogo: string,
2526
title: string,
2627
datesFormat: string,

adminforth/types/Back.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,11 @@ interface AdminForthInputConfigCustomization {
619619
*/
620620
brandName?: string,
621621

622+
/**
623+
* Whether to use single theme for the app
624+
*/
625+
singleTheme?: 'light' | 'dark',
626+
622627
/**
623628
* Whether to show brand name in sidebar
624629
* default is true

adminforth/types/Common.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,6 +1065,7 @@ export interface AdminForthConfigForFrontend {
10651065
rememberMeDays: number,
10661066
showBrandNameInSidebar: boolean,
10671067
brandLogo?: string,
1068+
singleTheme?: 'light' | 'dark',
10681069
datesFormat: string,
10691070
timeFormat: string,
10701071
auth: any,

0 commit comments

Comments
 (0)