Skip to content

Commit c8ffb38

Browse files
authored
feat(framework): Add API to subscribe/unsubscribe for theme loaded (#2303)
1 parent ea0439a commit c8ffb38

File tree

4 files changed

+34
-2
lines changed

4 files changed

+34
-2
lines changed

packages/base/src/Theming.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
import { addCustomCSS } from "./theming/CustomStyle.js";
2+
import { attachThemeLoaded, detachThemeLoaded } from "./theming/ThemeLoaded.js";
23

3-
export { addCustomCSS }; // eslint-disable-line
4+
export { addCustomCSS, attachThemeLoaded, detachThemeLoaded };
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import EventProvider from "../EventProvider.js";
2+
3+
const eventProvider = new EventProvider();
4+
const THEME_LOADED = "themeLoaded";
5+
6+
const attachThemeLoaded = listener => {
7+
eventProvider.attachEvent(THEME_LOADED, listener);
8+
};
9+
10+
const detachThemeLoaded = listener => {
11+
eventProvider.detachEvent(THEME_LOADED, listener);
12+
};
13+
14+
const fireThemeLoaded = theme => {
15+
return eventProvider.fireEvent(THEME_LOADED, theme);
16+
};
17+
18+
export {
19+
attachThemeLoaded,
20+
detachThemeLoaded,
21+
fireThemeLoaded,
22+
};

packages/base/src/theming/applyTheme.js

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { getThemeProperties, getRegisteredPackages, isThemeRegistered } from "..
22
import createThemePropertiesStyleTag from "./createThemePropertiesStyleTag.js";
33
import getThemeDesignerTheme from "./getThemeDesignerTheme.js";
44
import { ponyfillNeeded, runPonyfill } from "./CSSVarsPonyfill.js";
5+
import { fireThemeLoaded } from "./ThemeLoaded.js";
56
import { getFeature } from "../FeaturesRegistry.js";
67

78
const BASE_THEME_PACKAGE = "@ui5/webcomponents-theme-base";
@@ -76,6 +77,8 @@ const applyTheme = async theme => {
7677
if (ponyfillNeeded()) {
7778
runPonyfill();
7879
}
80+
81+
fireThemeLoaded(theme);
7982
};
8083

8184
export default applyTheme;

packages/main/bundle.esm.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import { getAssetsPath, setAssetsPath } from "@ui5/webcomponents-base/dist/config/AssetsPath.js";
22
// setAssetsPath("/my-resources/");
33

4+
import { addCustomCSS, attachThemeLoaded, detachThemeLoaded } from "@ui5/webcomponents-base/dist/Theming";
5+
attachThemeLoaded(theme => {
6+
console.log("Theme load complete: ", theme);
7+
});
8+
49
// OpenUI5 integration
510
import "@ui5/webcomponents-base/dist/features/OpenUI5Support.js";
611

@@ -99,7 +104,6 @@ import { getFirstDayOfWeek } from "@ui5/webcomponents-base/dist/config/FormatSet
99104
import { getRegisteredNames as getIconNames } from "@ui5/webcomponents-base/dist/SVGIconRegistry.js";
100105
import applyDirection from "@ui5/webcomponents-base/dist/locale/applyDirection.js";
101106
import ResizeHandler from "@ui5/webcomponents-base/dist/delegate/ResizeHandler.js";
102-
import { addCustomCSS } from "@ui5/webcomponents-base/dist/Theming";
103107

104108
const testAssets = {
105109
configuration : {
@@ -119,6 +123,8 @@ const testAssets = {
119123
applyDirection,
120124
ResizeHandler,
121125
addCustomCSS,
126+
attachThemeLoaded,
127+
detachThemeLoaded,
122128
getIconNames,
123129
};
124130

0 commit comments

Comments
 (0)