diff --git a/.prettierignore b/.prettierignore index 104baae59..9f8c74141 100644 --- a/.prettierignore +++ b/.prettierignore @@ -9,3 +9,4 @@ src/react/index.ts node_modules package-lock.json tsconfig.json +cdn diff --git a/docs/_includes/default.njk b/docs/_includes/default.njk index 2a29169d4..a7b7e8b23 100644 --- a/docs/_includes/default.njk +++ b/docs/_includes/default.njk @@ -34,9 +34,9 @@ {# Shoelace #} - - - + + + {# Set the initial theme and menu states here to prevent flashing #} \n` + + `\n` + `\n${htmlExample}`; jsTemplate = ''; } @@ -191,10 +193,10 @@ jsTemplate = `import React from 'https://cdn.skypack.dev/react@${reactVersion}';\n` + `import ReactDOM from 'https://cdn.skypack.dev/react-dom@${reactVersion}';\n` + - `import { setBasePath } from 'https://cdn.skypack.dev/@shoelace-style/shoelace@${shoelaceVersion}/%CDNDIR%/utilities/base-path';\n` + + `import { setBasePath } from 'https://cdn.skypack.dev/@shoelace-style/shoelace@${shoelaceVersion}/${cdndir}/utilities/base-path';\n` + `\n` + `// Set the base path for Shoelace assets\n` + - `setBasePath('https://cdn.skypack.dev/@shoelace-style/shoelace@${shoelaceVersion}/%NPMDIR%/')\n` + + `setBasePath('https://cdn.skypack.dev/@shoelace-style/shoelace@${shoelaceVersion}/${npmdir}/')\n` + `\n${convertModuleLinks(reactExample)}\n` + `\n` + `ReactDOM.render(, document.getElementById('root'));`; @@ -202,7 +204,7 @@ // CSS templates cssTemplate = - `@import 'https://cdn.jsdelivr.net/npm/@shoelace-style/shoelace@${shoelaceVersion}/%CDNDIR%/themes/${ + `@import 'https://cdn.jsdelivr.net/npm/@shoelace-style/shoelace@${shoelaceVersion}/${cdndir}/themes/${ isDark ? 'dark' : 'light' }.css';\n` + '\n' + diff --git a/docs/pages/components/icon.md b/docs/pages/components/icon.md index 2b6a301a6..66e85bede 100644 --- a/docs/pages/components/icon.md +++ b/docs/pages/components/icon.md @@ -634,6 +634,39 @@ This example will load the same set of icons from the jsDelivr CDN instead of yo ``` +#### Customize the default library to use SVG sprites + +To improve performance you can use a SVG sprites to avoid multiple trips for each SVG. The browser will load the sprite sheet once and then you reference the particular SVG within the sprite sheet using hash selector. + +As always, make sure to benchmark these changes. When using HTTP/2, it may in fact be more bandwidth-friendly to use multiple small requests instead of 1 large sprite sheet. + +:::danger +When using sprite sheets, the `sl-load` and `sl-error` events will not fire. +::: + +:::danger +For security reasons, browsers may apply the same-origin policy on `` elements located in the `` shadow dom and +may refuse to load a cross-origin URL. There is currently no defined way to set a cross-origin policy for `` elements. +For this reason, sprite sheets should only be used if you're self-hosting them. +::: + +```html:preview + + +
+ + +
+``` + ### Customizing the System Library The system library contains only the icons used internally by Shoelace components. Unlike the default icon library, the system library does not rely on physical assets. Instead, its icons are hard-coded as data URIs into the resolver to ensure their availability. @@ -666,7 +699,7 @@ If you want to change the icons Shoelace uses internally, you can register an ic } fetch('/dist/assets/icons/icons.json') - .then(res => res.json()) + .then(res => res.json()) .then(icons => { const container = document.querySelector('.icon-search'); const input = container.querySelector('sl-input'); @@ -685,12 +718,12 @@ If you want to change the icons Shoelace uses internally, you can register an ic item.setAttribute('data-terms', [i.name, i.title, ...(i.tags || []), ...(i.categories || [])].join(' ')); item.innerHTML = ` - - + + `; list.appendChild(item); - // Wrap it with a tooltip the first time the mouse lands on it. We do this instead of baking them into the DOM + // Wrap it with a tooltip the first time the mouse lands on it. We do this instead of baking them into the DOM // to improve this page's performance. See: https://github.com/shoelace-style/shoelace/issues/1122 item.addEventListener('mouseover', () => wrapWithTooltip(item), { once: true }); @@ -833,6 +866,6 @@ If you want to change the icons Shoelace uses internally, you can register an ic @media screen and (max-width: 500px) { .icon-list { grid-template-columns: repeat(4, 1fr); - } + } } diff --git a/docs/pages/getting-started/usage.md b/docs/pages/getting-started/usage.md index 43cc9c929..f8195e929 100644 --- a/docs/pages/getting-started/usage.md +++ b/docs/pages/getting-started/usage.md @@ -108,9 +108,9 @@ Custom elements cannot have self-closing tags. Similar to `