Skip to content

feat(framework): Add API to subscribe/unsubscribe for theme loaded #2303

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/base/src/Theming.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { addCustomCSS } from "./theming/CustomStyle.js";
import { attachThemeLoaded, detachThemeLoaded } from "./theming/ThemeLoaded.js";

export { addCustomCSS }; // eslint-disable-line
export { addCustomCSS, attachThemeLoaded, detachThemeLoaded };
22 changes: 22 additions & 0 deletions packages/base/src/theming/ThemeLoaded.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import EventProvider from "../EventProvider.js";

const eventProvider = new EventProvider();
const THEME_LOADED = "themeLoaded";

const attachThemeLoaded = listener => {
eventProvider.attachEvent(THEME_LOADED, listener);
};

const detachThemeLoaded = listener => {
eventProvider.detachEvent(THEME_LOADED, listener);
};

const fireThemeLoaded = theme => {
return eventProvider.fireEvent(THEME_LOADED, theme);
};

export {
attachThemeLoaded,
detachThemeLoaded,
fireThemeLoaded,
};
3 changes: 3 additions & 0 deletions packages/base/src/theming/applyTheme.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { getThemeProperties, getRegisteredPackages, isThemeRegistered } from "..
import createThemePropertiesStyleTag from "./createThemePropertiesStyleTag.js";
import getThemeDesignerTheme from "./getThemeDesignerTheme.js";
import { ponyfillNeeded, runPonyfill } from "./CSSVarsPonyfill.js";
import { fireThemeLoaded } from "./ThemeLoaded.js";
import { getFeature } from "../FeaturesRegistry.js";

const BASE_THEME_PACKAGE = "@ui5/webcomponents-theme-base";
Expand Down Expand Up @@ -76,6 +77,8 @@ const applyTheme = async theme => {
if (ponyfillNeeded()) {
runPonyfill();
}

fireThemeLoaded(theme);
};

export default applyTheme;
8 changes: 7 additions & 1 deletion packages/main/bundle.esm.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { getAssetsPath, setAssetsPath } from "@ui5/webcomponents-base/dist/config/AssetsPath.js";
// setAssetsPath("/my-resources/");

import { addCustomCSS, attachThemeLoaded, detachThemeLoaded } from "@ui5/webcomponents-base/dist/Theming";
attachThemeLoaded(theme => {
console.log("Theme load complete: ", theme);
});

// OpenUI5 integration
import "@ui5/webcomponents-base/dist/features/OpenUI5Support.js";

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

const testAssets = {
configuration : {
Expand All @@ -119,6 +123,8 @@ const testAssets = {
applyDirection,
ResizeHandler,
addCustomCSS,
attachThemeLoaded,
detachThemeLoaded,
getIconNames,
};

Expand Down