@@ -14,6 +14,12 @@ import {
1414import { AppTheme } from "./app-theme" ;
1515import { useTheme } from "@fluentui/react-theme-provider" ;
1616import { getLogger } from "@azure/bonito-core" ;
17+ import {
18+ CycleThemeDark ,
19+ CycleThemeHighContrastDark ,
20+ CycleThemeHighContrastLight ,
21+ CycleThemeLight ,
22+ } from "./azure-theme" ;
1723
1824export const BaseThemeLight = AzureThemeLight ;
1925export const BaseThemeDark = AzureThemeDark ;
@@ -49,7 +55,7 @@ export interface ThemeInfo extends ThemeMapEntry {
4955 * @returns A list of objects which contain metadata on each theme
5056 */
5157export function listThemes ( ) : ThemeInfo [ ] {
52- const sortedNames = Object . keys ( _themeMap ) . sort ( ) ;
58+ const sortedNames = Object . keys ( _themeMap ) . sort ( ) as ThemeName [ ] ;
5359 const themes : ThemeInfo [ ] = [ ] ;
5460 for ( const n of sortedNames ) {
5561 const entry = _themeMap [ n ] ;
@@ -62,18 +68,25 @@ export function listThemes(): ThemeInfo[] {
6268 return themes ;
6369}
6470
71+ export type ThemeName = keyof typeof _themeMap ;
72+
6573/**
6674 * Gets a theme by name
6775 *
6876 * @returns A FluentUI theme
6977 */
70- export function getTheme ( themeName : string ) : ThemeInfo {
71- let mapInfo = _themeMap [ themeName ] ;
72- if ( ! mapInfo ) {
73- getLogger ( "getTheme" ) . error (
74- `Unable to load theme ${ themeName } : Falling back to default`
75- ) ;
78+ export function getTheme ( themeName : ThemeName | "default" ) : ThemeInfo {
79+ let mapInfo ;
80+ if ( themeName === "default" ) {
7681 mapInfo = _themeMap [ defaultTheme ] ;
82+ } else {
83+ mapInfo = _themeMap [ themeName ] ;
84+ if ( ! mapInfo ) {
85+ getLogger ( "getTheme" ) . error (
86+ `Unable to load theme ${ themeName } : Falling back to default`
87+ ) ;
88+ mapInfo = _themeMap [ defaultTheme ] ;
89+ }
7790 }
7891 return {
7992 name : themeName ,
@@ -87,9 +100,55 @@ interface ThemeMapEntry {
87100 get : ( ) => AppTheme ;
88101}
89102
90- const _themeMap : Record < string , ThemeMapEntry > = {
103+ const _themeMap = {
104+ cycleLight : {
105+ label : "Cycle Light" ,
106+ get : ( ) => {
107+ return _getThemeLazy ( "cycleLight" , BaseThemeLight , ( baseTheme ) => {
108+ return mergeThemes ( baseTheme , CycleThemeLight ) as AppTheme ;
109+ } ) ;
110+ } ,
111+ } ,
112+ cycleDark : {
113+ label : "Cycle Dark" ,
114+ get : ( ) => {
115+ return _getThemeLazy ( "cycleDark" , BaseThemeDark , ( baseTheme ) => {
116+ return mergeThemes ( baseTheme , CycleThemeDark ) as AppTheme ;
117+ } ) ;
118+ } ,
119+ } ,
120+ cycleHighContrastLight : {
121+ label : "Cycle High Contrast (Light)" ,
122+ get : ( ) => {
123+ return _getThemeLazy (
124+ "cycleHighContrastLight" ,
125+ BaseThemeHighContrastLight ,
126+ ( baseTheme ) => {
127+ return mergeThemes (
128+ baseTheme ,
129+ CycleThemeHighContrastLight
130+ ) as AppTheme ;
131+ }
132+ ) ;
133+ } ,
134+ } ,
135+ cycleHighContrastDark : {
136+ label : "Cycle High Contrast (Dark)" ,
137+ get : ( ) => {
138+ return _getThemeLazy (
139+ "cycleHighContrastDark" ,
140+ BaseThemeHighContrastDark ,
141+ ( baseTheme ) => {
142+ return mergeThemes (
143+ baseTheme ,
144+ CycleThemeHighContrastDark
145+ ) as AppTheme ;
146+ }
147+ ) ;
148+ } ,
149+ } ,
91150 explorerLight : {
92- label : "Light" ,
151+ label : "Explorer Light" ,
93152 get : ( ) => {
94153 return _getThemeLazy (
95154 "explorerLight" ,
@@ -104,15 +163,15 @@ const _themeMap: Record<string, ThemeMapEntry> = {
104163 } ,
105164 } ,
106165 explorerDark : {
107- label : "Dark" ,
166+ label : "Explorer Dark" ,
108167 get : ( ) => {
109168 return _getThemeLazy ( "explorerDark" , BaseThemeDark , ( baseTheme ) => {
110169 return mergeThemes ( baseTheme , ExplorerThemeDark ) as AppTheme ;
111170 } ) ;
112171 } ,
113172 } ,
114173 explorerHighContrastLight : {
115- label : "High Contrast (Light)" ,
174+ label : "Explorer High Contrast (Light)" ,
116175 get : ( ) => {
117176 return _getThemeLazy (
118177 "explorerHighContrastLight" ,
@@ -127,7 +186,7 @@ const _themeMap: Record<string, ThemeMapEntry> = {
127186 } ,
128187 } ,
129188 explorerHighContrastDark : {
130- label : "High Contrast (Dark)" ,
189+ label : "Explorer High Contrast (Dark)" ,
131190 get : ( ) => {
132191 return _getThemeLazy (
133192 "explorerHighContrastDark" ,
0 commit comments