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

[v5] [icons] feat: make Icons.isValidIconName API public #6219

Merged
merged 2 commits into from
Jun 14, 2023
Merged
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
16 changes: 10 additions & 6 deletions packages/icons/src/iconLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@ export interface IconLoaderOptions {
loader?: "webpack-lazy-once" | "webpack-lazy" | "webpack-eager" | IconPathsLoader;
}

let defaultLoader: Required<IconLoaderOptions>["loader"] = "webpack-lazy-once";

/**
* Blueprint icons loader.
*/
export class Icons {
/** @internal */
public defaultLoader: Required<IconLoaderOptions>["loader"] = "webpack-lazy-once";

/** @internal */
public loadedIconPaths16: Map<IconName, IconPaths> = new Map();

Expand All @@ -49,7 +50,7 @@ export class Icons {
*/
public static setLoaderOptions(options: IconLoaderOptions) {
if (options.loader !== undefined) {
defaultLoader = options.loader;
singleton.defaultLoader = options.loader;
}
}

Expand Down Expand Up @@ -111,7 +112,7 @@ export class Icons {
return;
}

const { loader = defaultLoader } = options;
const { loader = singleton.defaultLoader } = options;

const loaderFn =
typeof loader == "function"
Expand All @@ -138,9 +139,12 @@ export class Icons {
}
}

private static isValidIconName(icon: IconName): boolean {
/**
* @returns true if the given string is a valid {@link IconName}
*/
public static isValidIconName(iconName: string): iconName is IconName {
const allIcons: IconName[] = Object.values(IconNames);
return allIcons.indexOf(icon) >= 0;
return allIcons.indexOf(iconName as IconName) >= 0;
}
}

Expand Down