What's the simplest way to swap out the sl-icon (chevron-right) being used in the <sl-details> #1046
Replies: 1 comment 6 replies
-
This was discussed a bit in #985. While improvements have been made here, icon customizations still rely on the icon library to make such changes. The idea is that, if you're going to customize one icon, you probably want to customize all icons to make things consistent throughout the library. Some components let you slot in icons to override them. If details worked this way, it might look like this: <sl-details summary="Toggle">
<sl-icon slot="summary-icon" name="chevron-thick" library="yours"></sl-icon>
Content here.
</sl-details> Alternatively, you'd be able to slot in an SVG: <sl-details summary="Toggle">
<svg slot="summary-icon">…</svg>
Content here.
</sl-details> I'm thinking all components should allow this, so I'll probably make the change to allow this. The drawback is that every component needs to have a custom icon slotted in, whereas customizing the system icon library would apply to all components without slotting anything in. Another alternative might be a function that lets you override certain icons. Something like this, perhaps: import { setIcon } from '@shoelace-style/shoelace/dist/utilities/icon-library.js';
setIcon('system', 'chevron-right', `<svg>…</svg>`); This makes it simpler, but it goes against the spirit of "if you're going to customize the icon library, you should customize all icons for consistency." So maybe slotting is better for your use case? WorkaroundHere's a quick workaround using a hard coded SVG as a background image. It works in light/dark because it covers the existing icon. sl-details::part(summary-icon) {
background-repeat: no-repeat;
background-image: url("data:image/svg+xml,%3Csvg fill='currentColor' xmlns='http://www.w3.org/2000/svg' viewBox='0 0 384 512'%3E%3Cpath d='M342.6 233.4c12.5 12.5 12.5 32.8 0 45.3l-192 192c-12.5 12.5-32.8 12.5-45.3 0s-12.5-32.8 0-45.3L274.7 256 105.4 86.6c-12.5-12.5-12.5-32.8 0-45.3s32.8-12.5 45.3 0l192 192z'/%3E%3C/svg%3E");
} If the background image icon didn't cover the normal icon, you'd need to set Hopefully that gets you by for now. |
Beta Was this translation helpful? Give feedback.
-
I simply need to use a fatter chevron icon, but honestly going through the trouble of registering a completely new library set of icons seems way over kill for just this one component. Any creative ways to swap this out? Can I target the "summary-icon" as part of the css and change it somehow 🤔
Beta Was this translation helpful? Give feedback.
All reactions