@@ -49,6 +49,7 @@ Icon comes with three built-in icon sets:
4949
50501 . ` fas ` : Font Awesome Free Solid icons (the default set)
51511 . ` far ` : Font Awesome Free Regular icons
52+ 1 . ` fab ` : Font Awesome Free Bold icons
52531 . ` patternfly ` : PatternFly icons
5354
5455Use the ` set ` attribute to pick an alternative icon set.
@@ -61,19 +62,31 @@ Use the `set` attribute to pick an alternative icon set.
6162It is possible to add custom icon sets or override the default sets.
6263Icon sets are defined in detail in [ the docs] [ icon-sets ] .
6364
64- ### Bundling
65+ ### Bundling and custom loading behaviour
6566
66- When bundling PfIcon with other modules, the default icon imports will be
67- relative to the bundle, not the source file, so be sure to either register all
68- the icon sets you'll need, or override the default getter.
67+ When bundling ` <pf-icon> ` with other modules (e.g. using webpack, rollup,
68+ esbuild, vite, or similar tools), icon imports will be code-split into chunks,
69+ as they are imported from the ` @patternfly/icons ` package. Ensure that your
70+ bundler is configured to permit dynamic imports, or mark the ` @patternfly/icons `
71+ package as "external" and apply an [ import map] [ importmap ] to your page instead.
72+ If you would like to
73+ customize the loading behaviour, override the ` PfIcon.resolve() ` static method.
74+ This methods takes two arguments: the icon set (a string) and the icon name
75+ (a string), and returns a promise of the icon contents, which is a DOM node, or
76+ [ anything else that lit-html can render] [ renderable ] .
6977
7078``` js
71- // Workaround for bundled pf-icon: make icon imports absolute, instead of
72- relative to the bundle
7379import { PfIcon } from ' /pfe.min.js' ;
74- PfIcon .getIconUrl = (set , icon ) =>
75- new URL (` /assets/icons/${ set} /${ icon} .js` , import .meta.url);
76- // default: new URL(`./icons/${set}/${icon}.js`, import.meta.url);
80+ PfIcon .resolve = async function (set , icon ) {
81+ try {
82+ const { default: content } = await import (` /assets/icons/${ set} /${ icon} .js` );
83+ if (content instanceof Node ) {
84+ return content .cloneNode (true );
85+ }
86+ } catch (e) {
87+ return ' ' ;
88+ }
89+ }
7790```
7891
7992## Loading
@@ -84,3 +97,5 @@ see the [docs][docs] for more info.
8497
8598[ docs ] : https://patternflyelements.org/components/icon/
8699[ icon-sets ] : https://patternflyelements.org/components/icon/#icon-sets
100+ [ renderable ] : https://lit.dev/docs/components/rendering/#renderable-values
101+ [ importmap ] : https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script/type/importmap
0 commit comments