@metamask-previews/design-system-react 0.28.0-preview.25db973 → 0.28.0-preview.ba3ace4e
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/BannerAlert/BannerAlert.cjs +1 -4
- package/dist/components/BannerAlert/BannerAlert.cjs.map +1 -1
- package/dist/components/BannerAlert/BannerAlert.constants.cjs +4 -7
- package/dist/components/BannerAlert/BannerAlert.constants.cjs.map +1 -1
- package/dist/components/BannerAlert/BannerAlert.constants.d.cts +1 -2
- package/dist/components/BannerAlert/BannerAlert.constants.d.cts.map +1 -1
- package/dist/components/BannerAlert/BannerAlert.constants.d.mts +1 -2
- package/dist/components/BannerAlert/BannerAlert.constants.d.mts.map +1 -1
- package/dist/components/BannerAlert/BannerAlert.constants.mjs +4 -7
- package/dist/components/BannerAlert/BannerAlert.constants.mjs.map +1 -1
- package/dist/components/BannerAlert/BannerAlert.d.cts.map +1 -1
- package/dist/components/BannerAlert/BannerAlert.d.mts.map +1 -1
- package/dist/components/BannerAlert/BannerAlert.mjs +2 -5
- package/dist/components/BannerAlert/BannerAlert.mjs.map +1 -1
- package/dist/components/BannerBase/BannerBase.cjs +5 -5
- package/dist/components/BannerBase/BannerBase.cjs.map +1 -1
- package/dist/components/BannerBase/BannerBase.d.cts.map +1 -1
- package/dist/components/BannerBase/BannerBase.d.mts.map +1 -1
- package/dist/components/BannerBase/BannerBase.mjs +6 -6
- package/dist/components/BannerBase/BannerBase.mjs.map +1 -1
- package/dist/components/ButtonIcon/ButtonIcon.constants.cjs +2 -0
- package/dist/components/ButtonIcon/ButtonIcon.constants.cjs.map +1 -1
- package/dist/components/ButtonIcon/ButtonIcon.constants.d.cts +2 -0
- package/dist/components/ButtonIcon/ButtonIcon.constants.d.cts.map +1 -1
- package/dist/components/ButtonIcon/ButtonIcon.constants.d.mts +2 -0
- package/dist/components/ButtonIcon/ButtonIcon.constants.d.mts.map +1 -1
- package/dist/components/ButtonIcon/ButtonIcon.constants.mjs +2 -0
- package/dist/components/ButtonIcon/ButtonIcon.constants.mjs.map +1 -1
- package/dist/components/Icon/Icon.cjs +30 -8
- package/dist/components/Icon/Icon.cjs.map +1 -1
- package/dist/components/Icon/Icon.d.cts.map +1 -1
- package/dist/components/Icon/Icon.d.mts.map +1 -1
- package/dist/components/Icon/Icon.mjs +8 -6
- package/dist/components/Icon/Icon.mjs.map +1 -1
- package/dist/components/Icon/Icon.registry.cjs +74 -0
- package/dist/components/Icon/Icon.registry.cjs.map +1 -0
- package/dist/components/Icon/Icon.registry.d.cts +46 -0
- package/dist/components/Icon/Icon.registry.d.cts.map +1 -0
- package/dist/components/Icon/Icon.registry.d.mts +46 -0
- package/dist/components/Icon/Icon.registry.d.mts.map +1 -0
- package/dist/components/Icon/Icon.registry.mjs +67 -0
- package/dist/components/Icon/Icon.registry.mjs.map +1 -0
- package/dist/components/Icon/icons/index.cjs +303 -587
- package/dist/components/Icon/icons/index.cjs.map +1 -1
- package/dist/components/Icon/icons/index.d.cts +14 -296
- package/dist/components/Icon/icons/index.d.cts.map +1 -1
- package/dist/components/Icon/icons/index.d.mts +14 -296
- package/dist/components/Icon/icons/index.d.mts.map +1 -1
- package/dist/components/Icon/icons/index.mjs +301 -583
- package/dist/components/Icon/icons/index.mjs.map +1 -1
- package/dist/components/Icon/index.cjs +3 -1
- package/dist/components/Icon/index.cjs.map +1 -1
- package/dist/components/Icon/index.d.cts +1 -0
- package/dist/components/Icon/index.d.cts.map +1 -1
- package/dist/components/Icon/index.d.mts +1 -0
- package/dist/components/Icon/index.d.mts.map +1 -1
- package/dist/components/Icon/index.mjs +1 -0
- package/dist/components/Icon/index.mjs.map +1 -1
- package/dist/components/index.cjs +3 -2
- package/dist/components/index.cjs.map +1 -1
- package/dist/components/index.d.cts +1 -1
- package/dist/components/index.d.cts.map +1 -1
- package/dist/components/index.d.mts +1 -1
- package/dist/components/index.d.mts.map +1 -1
- package/dist/components/index.mjs +1 -1
- package/dist/components/index.mjs.map +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isIconName = exports.preloadIcon = exports.getIconComponent = exports.getLazyIcon = exports.preloadIconsForTests = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const icons_1 = require("./icons/index.cjs");
|
|
6
|
+
Object.defineProperty(exports, "isIconName", { enumerable: true, get: function () { return icons_1.isIconName; } });
|
|
7
|
+
const lazyIconCache = new Map();
|
|
8
|
+
const testIconCache = new Map();
|
|
9
|
+
let testPreloadPromise;
|
|
10
|
+
/**
|
|
11
|
+
* Preloads all icon modules for the Jest test environment.
|
|
12
|
+
* Icons are cached as synchronous components so tests can query the DOM
|
|
13
|
+
* immediately without waiting for React.lazy resolution.
|
|
14
|
+
*
|
|
15
|
+
* @returns A promise that resolves when all icons are cached.
|
|
16
|
+
*/
|
|
17
|
+
function preloadIconsForTests() {
|
|
18
|
+
testPreloadPromise ?? (testPreloadPromise = Promise.all(Object.entries(icons_1.iconLoaders).map(async ([name, loader]) => {
|
|
19
|
+
const mod = await loader();
|
|
20
|
+
testIconCache.set(name, mod.default);
|
|
21
|
+
})).then(() => undefined));
|
|
22
|
+
return testPreloadPromise;
|
|
23
|
+
}
|
|
24
|
+
exports.preloadIconsForTests = preloadIconsForTests;
|
|
25
|
+
/**
|
|
26
|
+
* Returns a cached React.lazy wrapper for the given icon name.
|
|
27
|
+
* Each icon is loaded on demand via dynamic import, enabling per-icon
|
|
28
|
+
* code splitting instead of bundling all ~291 icons upfront.
|
|
29
|
+
*
|
|
30
|
+
* @param name - The icon name to resolve.
|
|
31
|
+
* @returns A lazy-loaded icon component.
|
|
32
|
+
*/
|
|
33
|
+
function getLazyIcon(name) {
|
|
34
|
+
let lazyIcon = lazyIconCache.get(name);
|
|
35
|
+
if (!lazyIcon) {
|
|
36
|
+
lazyIcon = (0, react_1.lazy)(icons_1.iconLoaders[name]);
|
|
37
|
+
lazyIconCache.set(name, lazyIcon);
|
|
38
|
+
}
|
|
39
|
+
return lazyIcon;
|
|
40
|
+
}
|
|
41
|
+
exports.getLazyIcon = getLazyIcon;
|
|
42
|
+
/**
|
|
43
|
+
* Resolves an icon component for rendering.
|
|
44
|
+
* Returns a synchronously cached component when present in the test preload
|
|
45
|
+
* cache (populated by preloadIconsForTests()). Otherwise returns a React.lazy
|
|
46
|
+
* wrapper for per-icon code splitting.
|
|
47
|
+
*
|
|
48
|
+
* @param name - The icon name to resolve.
|
|
49
|
+
* @param options - Optional resolver configuration.
|
|
50
|
+
* @param options.useTestCache - When false, skips the test preload cache.
|
|
51
|
+
* @returns The icon component to render.
|
|
52
|
+
*/
|
|
53
|
+
function getIconComponent(name, options) {
|
|
54
|
+
if (options?.useTestCache !== false) {
|
|
55
|
+
const cachedTestIcon = testIconCache.get(name);
|
|
56
|
+
if (cachedTestIcon) {
|
|
57
|
+
return cachedTestIcon;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return getLazyIcon(name);
|
|
61
|
+
}
|
|
62
|
+
exports.getIconComponent = getIconComponent;
|
|
63
|
+
/**
|
|
64
|
+
* Preloads an icon module so it is available synchronously on the next render.
|
|
65
|
+
* Useful for warming commonly used icons before they appear on screen.
|
|
66
|
+
*
|
|
67
|
+
* @param name - The icon name to preload.
|
|
68
|
+
* @returns A promise that resolves when the icon module has loaded.
|
|
69
|
+
*/
|
|
70
|
+
function preloadIcon(name) {
|
|
71
|
+
return icons_1.iconLoaders[name]().then(() => undefined);
|
|
72
|
+
}
|
|
73
|
+
exports.preloadIcon = preloadIcon;
|
|
74
|
+
//# sourceMappingURL=Icon.registry.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Icon.registry.cjs","sourceRoot":"","sources":["../../../src/components/Icon/Icon.registry.ts"],"names":[],"mappings":";;;AAEA,iCAA6B;AAG7B,6CAAkD;AA2FzC,2FA3Fa,kBAAU,OA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AbD,4CAaC;AAED;;;;;;GAMG;AACH,SAAgB,WAAW,CAAC,IAAc;IACxC,OAAO,mBAAW,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;AACnD,CAAC;AAFD,kCAEC","sourcesContent":["import type { IconName } from '@metamask-previews/design-system-shared';\nimport type { LazyExoticComponent } from 'react';\nimport { lazy } from 'react';\n\nimport type { IconComponentType } from './icons';\nimport { iconLoaders, isIconName } from './icons';\n\nconst lazyIconCache = new Map<\n IconName,\n LazyExoticComponent<IconComponentType>\n>();\n\nconst testIconCache = new Map<IconName, IconComponentType>();\n\nlet testPreloadPromise: Promise<void> | undefined;\n\n/**\n * Preloads all icon modules for the Jest test environment.\n * Icons are cached as synchronous components so tests can query the DOM\n * immediately without waiting for React.lazy resolution.\n *\n * @returns A promise that resolves when all icons are cached.\n */\nexport function preloadIconsForTests(): Promise<void> {\n testPreloadPromise ??= Promise.all(\n Object.entries(iconLoaders).map(async ([name, loader]) => {\n const mod = await loader();\n testIconCache.set(name as IconName, mod.default);\n }),\n ).then(() => undefined);\n\n return testPreloadPromise;\n}\n\n/**\n * Returns a cached React.lazy wrapper for the given icon name.\n * Each icon is loaded on demand via dynamic import, enabling per-icon\n * code splitting instead of bundling all ~291 icons upfront.\n *\n * @param name - The icon name to resolve.\n * @returns A lazy-loaded icon component.\n */\nexport function getLazyIcon(\n name: IconName,\n): LazyExoticComponent<IconComponentType> {\n let lazyIcon = lazyIconCache.get(name);\n\n if (!lazyIcon) {\n lazyIcon = lazy(iconLoaders[name]);\n lazyIconCache.set(name, lazyIcon);\n }\n\n return lazyIcon;\n}\n\ntype GetIconComponentOptions = {\n useTestCache?: boolean;\n};\n\n/**\n * Resolves an icon component for rendering.\n * Returns a synchronously cached component when present in the test preload\n * cache (populated by preloadIconsForTests()). Otherwise returns a React.lazy\n * wrapper for per-icon code splitting.\n *\n * @param name - The icon name to resolve.\n * @param options - Optional resolver configuration.\n * @param options.useTestCache - When false, skips the test preload cache.\n * @returns The icon component to render.\n */\nexport function getIconComponent(\n name: IconName,\n options?: GetIconComponentOptions,\n): IconComponentType | LazyExoticComponent<IconComponentType> {\n if (options?.useTestCache !== false) {\n const cachedTestIcon = testIconCache.get(name);\n\n if (cachedTestIcon) {\n return cachedTestIcon;\n }\n }\n\n return getLazyIcon(name);\n}\n\n/**\n * Preloads an icon module so it is available synchronously on the next render.\n * Useful for warming commonly used icons before they appear on screen.\n *\n * @param name - The icon name to preload.\n * @returns A promise that resolves when the icon module has loaded.\n */\nexport function preloadIcon(name: IconName): Promise<void> {\n return iconLoaders[name]().then(() => undefined);\n}\n\nexport { isIconName };\n"]}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { IconName } from "@metamask-previews/design-system-shared";
|
|
2
|
+
import type { LazyExoticComponent } from "react";
|
|
3
|
+
import type { IconComponentType } from "./icons/index.cjs";
|
|
4
|
+
import { isIconName } from "./icons/index.cjs";
|
|
5
|
+
/**
|
|
6
|
+
* Preloads all icon modules for the Jest test environment.
|
|
7
|
+
* Icons are cached as synchronous components so tests can query the DOM
|
|
8
|
+
* immediately without waiting for React.lazy resolution.
|
|
9
|
+
*
|
|
10
|
+
* @returns A promise that resolves when all icons are cached.
|
|
11
|
+
*/
|
|
12
|
+
export declare function preloadIconsForTests(): Promise<void>;
|
|
13
|
+
/**
|
|
14
|
+
* Returns a cached React.lazy wrapper for the given icon name.
|
|
15
|
+
* Each icon is loaded on demand via dynamic import, enabling per-icon
|
|
16
|
+
* code splitting instead of bundling all ~291 icons upfront.
|
|
17
|
+
*
|
|
18
|
+
* @param name - The icon name to resolve.
|
|
19
|
+
* @returns A lazy-loaded icon component.
|
|
20
|
+
*/
|
|
21
|
+
export declare function getLazyIcon(name: IconName): LazyExoticComponent<IconComponentType>;
|
|
22
|
+
type GetIconComponentOptions = {
|
|
23
|
+
useTestCache?: boolean;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Resolves an icon component for rendering.
|
|
27
|
+
* Returns a synchronously cached component when present in the test preload
|
|
28
|
+
* cache (populated by preloadIconsForTests()). Otherwise returns a React.lazy
|
|
29
|
+
* wrapper for per-icon code splitting.
|
|
30
|
+
*
|
|
31
|
+
* @param name - The icon name to resolve.
|
|
32
|
+
* @param options - Optional resolver configuration.
|
|
33
|
+
* @param options.useTestCache - When false, skips the test preload cache.
|
|
34
|
+
* @returns The icon component to render.
|
|
35
|
+
*/
|
|
36
|
+
export declare function getIconComponent(name: IconName, options?: GetIconComponentOptions): IconComponentType | LazyExoticComponent<IconComponentType>;
|
|
37
|
+
/**
|
|
38
|
+
* Preloads an icon module so it is available synchronously on the next render.
|
|
39
|
+
* Useful for warming commonly used icons before they appear on screen.
|
|
40
|
+
*
|
|
41
|
+
* @param name - The icon name to preload.
|
|
42
|
+
* @returns A promise that resolves when the icon module has loaded.
|
|
43
|
+
*/
|
|
44
|
+
export declare function preloadIcon(name: IconName): Promise<void>;
|
|
45
|
+
export { isIconName };
|
|
46
|
+
//# sourceMappingURL=Icon.registry.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Icon.registry.d.cts","sourceRoot":"","sources":["../../../src/components/Icon/Icon.registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,gDAAgD;AACxE,OAAO,KAAK,EAAE,mBAAmB,EAAE,cAAc;AAGjD,OAAO,KAAK,EAAE,iBAAiB,EAAE,0BAAgB;AACjD,OAAO,EAAe,UAAU,EAAE,0BAAgB;AAWlD;;;;;;GAMG;AACH,wBAAgB,oBAAoB,IAAI,OAAO,CAAC,IAAI,CAAC,CASpD;AAED;;;;;;;GAOG;AACH,wBAAgB,WAAW,CACzB,IAAI,EAAE,QAAQ,GACb,mBAAmB,CAAC,iBAAiB,CAAC,CASxC;AAED,KAAK,uBAAuB,GAAG;IAC7B,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB,CAAC;AAEF;;;;;;;;;;GAUG;AACH,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,QAAQ,EACd,OAAO,CAAC,EAAE,uBAAuB,GAChC,iBAAiB,GAAG,mBAAmB,CAAC,iBAAiB,CAAC,CAU5D;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAEzD;AAED,OAAO,EAAE,UAAU,EAAE,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { IconName } from "@metamask-previews/design-system-shared";
|
|
2
|
+
import type { LazyExoticComponent } from "react";
|
|
3
|
+
import type { IconComponentType } from "./icons/index.mjs";
|
|
4
|
+
import { isIconName } from "./icons/index.mjs";
|
|
5
|
+
/**
|
|
6
|
+
* Preloads all icon modules for the Jest test environment.
|
|
7
|
+
* Icons are cached as synchronous components so tests can query the DOM
|
|
8
|
+
* immediately without waiting for React.lazy resolution.
|
|
9
|
+
*
|
|
10
|
+
* @returns A promise that resolves when all icons are cached.
|
|
11
|
+
*/
|
|
12
|
+
export declare function preloadIconsForTests(): Promise<void>;
|
|
13
|
+
/**
|
|
14
|
+
* Returns a cached React.lazy wrapper for the given icon name.
|
|
15
|
+
* Each icon is loaded on demand via dynamic import, enabling per-icon
|
|
16
|
+
* code splitting instead of bundling all ~291 icons upfront.
|
|
17
|
+
*
|
|
18
|
+
* @param name - The icon name to resolve.
|
|
19
|
+
* @returns A lazy-loaded icon component.
|
|
20
|
+
*/
|
|
21
|
+
export declare function getLazyIcon(name: IconName): LazyExoticComponent<IconComponentType>;
|
|
22
|
+
type GetIconComponentOptions = {
|
|
23
|
+
useTestCache?: boolean;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Resolves an icon component for rendering.
|
|
27
|
+
* Returns a synchronously cached component when present in the test preload
|
|
28
|
+
* cache (populated by preloadIconsForTests()). Otherwise returns a React.lazy
|
|
29
|
+
* wrapper for per-icon code splitting.
|
|
30
|
+
*
|
|
31
|
+
* @param name - The icon name to resolve.
|
|
32
|
+
* @param options - Optional resolver configuration.
|
|
33
|
+
* @param options.useTestCache - When false, skips the test preload cache.
|
|
34
|
+
* @returns The icon component to render.
|
|
35
|
+
*/
|
|
36
|
+
export declare function getIconComponent(name: IconName, options?: GetIconComponentOptions): IconComponentType | LazyExoticComponent<IconComponentType>;
|
|
37
|
+
/**
|
|
38
|
+
* Preloads an icon module so it is available synchronously on the next render.
|
|
39
|
+
* Useful for warming commonly used icons before they appear on screen.
|
|
40
|
+
*
|
|
41
|
+
* @param name - The icon name to preload.
|
|
42
|
+
* @returns A promise that resolves when the icon module has loaded.
|
|
43
|
+
*/
|
|
44
|
+
export declare function preloadIcon(name: IconName): Promise<void>;
|
|
45
|
+
export { isIconName };
|
|
46
|
+
//# sourceMappingURL=Icon.registry.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Icon.registry.d.mts","sourceRoot":"","sources":["../../../src/components/Icon/Icon.registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,gDAAgD;AACxE,OAAO,KAAK,EAAE,mBAAmB,EAAE,cAAc;AAGjD,OAAO,KAAK,EAAE,iBAAiB,EAAE,0BAAgB;AACjD,OAAO,EAAe,UAAU,EAAE,0BAAgB;AAWlD;;;;;;GAMG;AACH,wBAAgB,oBAAoB,IAAI,OAAO,CAAC,IAAI,CAAC,CASpD;AAED;;;;;;;GAOG;AACH,wBAAgB,WAAW,CACzB,IAAI,EAAE,QAAQ,GACb,mBAAmB,CAAC,iBAAiB,CAAC,CASxC;AAED,KAAK,uBAAuB,GAAG;IAC7B,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB,CAAC;AAEF;;;;;;;;;;GAUG;AACH,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,QAAQ,EACd,OAAO,CAAC,EAAE,uBAAuB,GAChC,iBAAiB,GAAG,mBAAmB,CAAC,iBAAiB,CAAC,CAU5D;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAEzD;AAED,OAAO,EAAE,UAAU,EAAE,CAAC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { lazy } from "react";
|
|
2
|
+
import { iconLoaders, isIconName } from "./icons/index.mjs";
|
|
3
|
+
const lazyIconCache = new Map();
|
|
4
|
+
const testIconCache = new Map();
|
|
5
|
+
let testPreloadPromise;
|
|
6
|
+
/**
|
|
7
|
+
* Preloads all icon modules for the Jest test environment.
|
|
8
|
+
* Icons are cached as synchronous components so tests can query the DOM
|
|
9
|
+
* immediately without waiting for React.lazy resolution.
|
|
10
|
+
*
|
|
11
|
+
* @returns A promise that resolves when all icons are cached.
|
|
12
|
+
*/
|
|
13
|
+
export function preloadIconsForTests() {
|
|
14
|
+
testPreloadPromise ?? (testPreloadPromise = Promise.all(Object.entries(iconLoaders).map(async ([name, loader]) => {
|
|
15
|
+
const mod = await loader();
|
|
16
|
+
testIconCache.set(name, mod.default);
|
|
17
|
+
})).then(() => undefined));
|
|
18
|
+
return testPreloadPromise;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Returns a cached React.lazy wrapper for the given icon name.
|
|
22
|
+
* Each icon is loaded on demand via dynamic import, enabling per-icon
|
|
23
|
+
* code splitting instead of bundling all ~291 icons upfront.
|
|
24
|
+
*
|
|
25
|
+
* @param name - The icon name to resolve.
|
|
26
|
+
* @returns A lazy-loaded icon component.
|
|
27
|
+
*/
|
|
28
|
+
export function getLazyIcon(name) {
|
|
29
|
+
let lazyIcon = lazyIconCache.get(name);
|
|
30
|
+
if (!lazyIcon) {
|
|
31
|
+
lazyIcon = lazy(iconLoaders[name]);
|
|
32
|
+
lazyIconCache.set(name, lazyIcon);
|
|
33
|
+
}
|
|
34
|
+
return lazyIcon;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Resolves an icon component for rendering.
|
|
38
|
+
* Returns a synchronously cached component when present in the test preload
|
|
39
|
+
* cache (populated by preloadIconsForTests()). Otherwise returns a React.lazy
|
|
40
|
+
* wrapper for per-icon code splitting.
|
|
41
|
+
*
|
|
42
|
+
* @param name - The icon name to resolve.
|
|
43
|
+
* @param options - Optional resolver configuration.
|
|
44
|
+
* @param options.useTestCache - When false, skips the test preload cache.
|
|
45
|
+
* @returns The icon component to render.
|
|
46
|
+
*/
|
|
47
|
+
export function getIconComponent(name, options) {
|
|
48
|
+
if (options?.useTestCache !== false) {
|
|
49
|
+
const cachedTestIcon = testIconCache.get(name);
|
|
50
|
+
if (cachedTestIcon) {
|
|
51
|
+
return cachedTestIcon;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return getLazyIcon(name);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Preloads an icon module so it is available synchronously on the next render.
|
|
58
|
+
* Useful for warming commonly used icons before they appear on screen.
|
|
59
|
+
*
|
|
60
|
+
* @param name - The icon name to preload.
|
|
61
|
+
* @returns A promise that resolves when the icon module has loaded.
|
|
62
|
+
*/
|
|
63
|
+
export function preloadIcon(name) {
|
|
64
|
+
return iconLoaders[name]().then(() => undefined);
|
|
65
|
+
}
|
|
66
|
+
export { isIconName };
|
|
67
|
+
//# sourceMappingURL=Icon.registry.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Icon.registry.mjs","sourceRoot":"","sources":["../../../src/components/Icon/Icon.registry.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,IAAI,EAAE,cAAc;AAG7B,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,0BAAgB;AAElD,MAAM,aAAa,GAAG,IAAI,GAAG,EAG1B,CAAC;AAEJ,MAAM,aAAa,GAAG,IAAI,GAAG,EAA+B,CAAC;AAE7D,IAAI,kBAA6C,CAAC;AAElD;;;;;;GAMG;AACH,MAAM,UAAU,oBAAoB;IAClC,kBAAkB,KAAlB,kBAAkB,GAAK,OA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port type { LazyExoticComponent } from 'react';\nimport { lazy } from 'react';\n\nimport type { IconComponentType } from './icons';\nimport { iconLoaders, isIconName } from './icons';\n\nconst lazyIconCache = new Map<\n IconName,\n LazyExoticComponent<IconComponentType>\n>();\n\nconst testIconCache = new Map<IconName, IconComponentType>();\n\nlet testPreloadPromise: Promise<void> | undefined;\n\n/**\n * Preloads all icon modules for the Jest test environment.\n * Icons are cached as synchronous components so tests can query the DOM\n * immediately without waiting for React.lazy resolution.\n *\n * @returns A promise that resolves when all icons are cached.\n */\nexport function preloadIconsForTests(): Promise<void> {\n testPreloadPromise ??= Promise.all(\n Object.entries(iconLoaders).map(async ([name, loader]) => {\n const mod = await loader();\n testIconCache.set(name as IconName, mod.default);\n }),\n ).then(() => undefined);\n\n return testPreloadPromise;\n}\n\n/**\n * Returns a cached React.lazy wrapper for the given icon name.\n * Each icon is loaded on demand via dynamic import, enabling per-icon\n * code splitting instead of bundling all ~291 icons upfront.\n *\n * @param name - The icon name to resolve.\n * @returns A lazy-loaded icon component.\n */\nexport function getLazyIcon(\n name: IconName,\n): LazyExoticComponent<IconComponentType> {\n let lazyIcon = lazyIconCache.get(name);\n\n if (!lazyIcon) {\n lazyIcon = lazy(iconLoaders[name]);\n lazyIconCache.set(name, lazyIcon);\n }\n\n return lazyIcon;\n}\n\ntype GetIconComponentOptions = {\n useTestCache?: boolean;\n};\n\n/**\n * Resolves an icon component for rendering.\n * Returns a synchronously cached component when present in the test preload\n * cache (populated by preloadIconsForTests()). Otherwise returns a React.lazy\n * wrapper for per-icon code splitting.\n *\n * @param name - The icon name to resolve.\n * @param options - Optional resolver configuration.\n * @param options.useTestCache - When false, skips the test preload cache.\n * @returns The icon component to render.\n */\nexport function getIconComponent(\n name: IconName,\n options?: GetIconComponentOptions,\n): IconComponentType | LazyExoticComponent<IconComponentType> {\n if (options?.useTestCache !== false) {\n const cachedTestIcon = testIconCache.get(name);\n\n if (cachedTestIcon) {\n return cachedTestIcon;\n }\n }\n\n return getLazyIcon(name);\n}\n\n/**\n * Preloads an icon module so it is available synchronously on the next render.\n * Useful for warming commonly used icons before they appear on screen.\n *\n * @param name - The icon name to preload.\n * @returns A promise that resolves when the icon module has loaded.\n */\nexport function preloadIcon(name: IconName): Promise<void> {\n return iconLoaders[name]().then(() => undefined);\n}\n\nexport { isIconName };\n"]}
|