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

chore(Icons): make pathData async #8785

Merged
merged 5 commits into from
Apr 18, 2024
Merged

chore(Icons): make pathData async #8785

merged 5 commits into from
Apr 18, 2024

Conversation

vladitasev
Copy link
Contributor

@vladitasev vladitasev commented Apr 17, 2024

UI5 Web Components Icons have a niche feature - exporting the SVG path string (pathData). This however causes issues as getTheme() must be called to determine which path version to export, and getTheme() is unreliable before boot() is complete. Now, we instead export a getPathData async function, that when awaited, will provide the said pathData.

This is how an icon accept.js is generated now:

import { isLegacyThemeFamilyAsync } from "@ui5/webcomponents-base/dist/config/Theme.js";
import { pathData as pathDatav4, ltr, accData } from "./v4/accept.js";
import { pathData as pathDatav5 } from "./v5/accept.js";

const getPathData = async() => {
	return await isLegacyThemeFamilyAsync() ? pathDatav4 : pathDatav5;
};

export default "accept";
export { getPathData, ltr, accData };

Technical note: onThemeRegistered used to call getTheme before boot was complete (and OpenUI5Support may change the outcome).

BREAKING CHANGE: UI5 Web Components Icons now export getPathData (function) instead of pathData (string)

If you used icons like this:

import "@ui5/webcomponents-icons/dist/accept.js";

or like this:

import accept from "@ui5/webcomponents-icons/dist/accept.js";

there is no change and no adaptations are required.

In the rare case you imported pathData from icons, for example:

import { pathData, ltr, accData } from "@ui5/webcomponents-icons/dist/accept.js";
console.log(pathData); // String containing the SVG path

you must change your code to, for example:

import { getPathData, ltr, accData } from "@ui5/webcomponents-icons/dist/accept.js";
getPathData().then(pathData => {
  console.log(pathData); // String containing the SVG path
});

@vladitasev vladitasev merged commit 0549dc9 into main Apr 18, 2024
9 checks passed
@vladitasev vladitasev deleted the async-icons branch April 18, 2024 11:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants