Skip to content

Commit 097afcb

Browse files
committed
Add Cycle themes
1 parent ba55e8e commit 097afcb

6 files changed

Lines changed: 110 additions & 18 deletions

File tree

desktop/src/app/components/common/react-container/react-container.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import * as ReactDOM from "react-dom";
1212
import {RootPane} from "@azure/bonito-ui/lib/components/layout";
1313
import { Subscription } from "rxjs";
1414
import { Theme, ThemeService } from "app/services";
15+
import { ThemeName } from "@azure/bonito-ui/lib/theme";
1516

1617
export const ReactWrapper: React.FC = props => {
1718
return React.createElement(RootPane, {theme: "explorerDark"}, props.children);
@@ -37,7 +38,7 @@ export class ReactContainerComponent<P> implements OnChanges, OnDestroy, AfterVi
3738

3839
private _subs: Subscription[] = [];
3940

40-
private _themeName: string = "explorerLight";
41+
private _themeName: ThemeName = "explorerLight";
4142

4243
private _themeService: ThemeService;
4344

packages/bonito-ui/src/components/layout/root-pane.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import * as React from "react";
2-
import { getTheme } from "../../theme";
2+
import { ThemeName, getTheme } from "../../theme";
33
import { ThemeProvider } from "@fluentui/react-theme-provider";
44
import { loadTheme } from "@fluentui/react/lib/Styling";
55

66
export interface RootPaneProps {
7-
theme?: string;
7+
theme?: ThemeName;
88
}
99

1010
const themeProviderStyles: React.CSSProperties = {
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { PartialAppTheme } from "./app-theme";
2+
3+
export const CycleThemeLight: PartialAppTheme = {
4+
semanticColors: {
5+
appHeaderBackground: "#0062b3",
6+
appHeaderText: "#ffffff",
7+
},
8+
};
9+
10+
export const CycleThemeDark: PartialAppTheme = {
11+
semanticColors: {
12+
appHeaderBackground: "#333842",
13+
appHeaderText: "#ffffff",
14+
},
15+
};
16+
17+
export const CycleThemeHighContrastLight: PartialAppTheme = {
18+
semanticColors: {
19+
appHeaderBackground: "#333333",
20+
appHeaderText: "#000000",
21+
},
22+
};
23+
24+
export const CycleThemeHighContrastDark: PartialAppTheme = {
25+
semanticColors: {
26+
appHeaderBackground: "#000000",
27+
appHeaderText: "#ffffff",
28+
},
29+
};

packages/bonito-ui/src/theme/theme-util.ts

Lines changed: 71 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ import {
1414
import { AppTheme } from "./app-theme";
1515
import { useTheme } from "@fluentui/react-theme-provider";
1616
import { getLogger } from "@azure/bonito-core";
17+
import {
18+
CycleThemeDark,
19+
CycleThemeHighContrastDark,
20+
CycleThemeHighContrastLight,
21+
CycleThemeLight,
22+
} from "./azure-theme";
1723

1824
export const BaseThemeLight = AzureThemeLight;
1925
export 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
*/
5157
export 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",

web/src/components/application.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { Main } from "./layout/main";
1616
import { Stack, IStackTokens } from "@fluentui/react/lib/Stack";
1717
import { PrimaryButton } from "@fluentui/react/lib/Button";
1818
import { translate } from "@azure/bonito-core";
19+
import { ThemeName } from "@azure/bonito-ui/lib/theme";
1920

2021
//DefaultButton
2122
const dropdownStyles: Partial<IDropdownStyles> = {
@@ -26,7 +27,7 @@ const dropdownStyles: Partial<IDropdownStyles> = {
2627
* Represents the entire application
2728
*/
2829
export const Application: React.FC = () => {
29-
const [theme, setTheme] = React.useState(defaultTheme);
30+
const [theme, setTheme] = React.useState<ThemeName>(defaultTheme);
3031

3132
const themeOptions = React.useMemo(() => {
3233
const options: IDropdownOption[] = [];
@@ -74,7 +75,7 @@ export const Application: React.FC = () => {
7475
onRenderLabel={() => <></>}
7576
onChange={(_, option) => {
7677
if (option) {
77-
setTheme(String(option.key));
78+
setTheme(option.key as ThemeName);
7879
}
7980
}}
8081
/>

web/src/components/layout/app-root.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import * as React from "react";
22
import { RootPane } from "@azure/bonito-ui/lib/components";
3+
import { ThemeName } from "@azure/bonito-ui/lib/theme";
4+
35
export interface RootProps {
4-
theme?: string;
6+
theme?: ThemeName;
57
}
68

79
export const AppRoot: React.FC<RootProps> = (props) => {

0 commit comments

Comments
 (0)