Skip to content
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

feat(framework): add default values for language/theme #6738

Merged
merged 2 commits into from
Mar 20, 2023
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
13 changes: 12 additions & 1 deletion docs/2-advanced/01-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,12 @@ Example:
import { setTheme } from "@ui5/webcomponents-base/dist/config/Theme.js";
setTheme("sap_belize_hcb");
```


- To reset the theme to the default one:
```js
import { setTheme, getDefaultTheme } from "@ui5/webcomponents-base/dist/config/Theme.js";
setTheme(getDefaultTheme());
```

### language
<a name="language"></a>
Expand Down Expand Up @@ -88,6 +93,12 @@ import { setLanguage } from "@ui5/webcomponents-base/dist/config/Language.js";
setLanguage("fr");
```

- To reset the langauge to the default one:
```js
import { setLanguage, getDefaultLanguage } from "@ui5/webcomponents-base/dist/config/Language.js";
setLanguage(getDefaultLanguage());
```


### animationMode
<a name="animationMode"></a>
Expand Down
14 changes: 14 additions & 0 deletions packages/base/src/config/Language.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
} from "../InitialConfiguration.js";
import { fireLanguageChange } from "../locale/languageChange.js";
import { reRenderAllUI5Elements } from "../Render.js";
import { DEFAULT_LANGUAGE } from "../generated/AssetParameters.js";

let curLanguage: string | undefined;
let fetchDefaultLanguage: boolean;
Expand Down Expand Up @@ -39,6 +40,18 @@ const setLanguage = async (language: string): Promise<void> => {
await reRenderAllUI5Elements({ languageAware: true });
};

/**
* Returns the default languague.
*
* Note: Default language might be different than the configurated one.
*
* @public
* @returns {string}
*/
const getDefaultLanguage = (): string => {
return DEFAULT_LANGUAGE;
};

/**
* Defines if the default language, that is inlined, should be
* fetched over the network instead of using the inlined one.
Expand Down Expand Up @@ -67,6 +80,7 @@ const getFetchDefaultLanguage = (): boolean => {
export {
getLanguage,
setLanguage,
getDefaultLanguage,
setFetchDefaultLanguage,
getFetchDefaultLanguage,
};
14 changes: 14 additions & 0 deletions packages/base/src/config/Theme.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { getTheme as getConfiguredTheme } from "../InitialConfiguration.js";
import { reRenderAllUI5Elements } from "../Render.js";
import applyTheme from "../theming/applyTheme.js";
import { DEFAULT_THEME } from "../generated/AssetParameters.js";

let curTheme: string;

Expand Down Expand Up @@ -35,6 +36,18 @@ const setTheme = async (theme: string): Promise<void> => {
await reRenderAllUI5Elements({ themeAware: true });
};

/**
* Returns the default theme.
*
* Note: Default theme might be different than the configurated one.
*
* @public
* @returns {string}
*/
const getDefaultTheme = (): string => {
return DEFAULT_THEME;
};

/**
* Returns if the given theme name is the one currently applied.
* @private
Expand All @@ -61,4 +74,5 @@ export {
setTheme,
isTheme,
isThemeFamily,
getDefaultTheme,
};