Replies: 4 comments 6 replies
-
Found the cause of no. 5, the background transition issue. Something in the tooltip js is doing it. |
Beta Was this translation helpful? Give feedback.
-
Based on the cherrypicking section in the the installation page of the docs, it seems either approach is fine. https://shoelace.style/getting-started/installation#cherry-picking |
Beta Was this translation helpful? Give feedback.
-
@b-d-m-p I can't really help you with your actual problem but I can answer this question for you:
You actually do, that's what you do here: <script>
import "@shoelace-style/shoelace/dist/components/button/button.js"
import "@shoelace-style/shoelace/dist/components/dropdown/dropdown.js"
import "@shoelace-style/shoelace/dist/components/switch/switch.js"
import "@shoelace-style/shoelace/dist/components/menu-item/menu-item.js"
import "@shoelace-style/shoelace/dist/components/menu-label/menu-label.js"
</script> Those files register the Custom Element in the page so the browser knows what to render when you use |
Beta Was this translation helpful? Give feedback.
-
I still have some questions that I don't have an answer to, but I made a starter https://github.com/b-d-m-p/astro-shoelace-starter-kit-blog. It is not official, but it works and is probably what most people looking to use. I also made a tutorial for the docs, which I've submitted as a PR. #2098 Hope it helps someone. |
Beta Was this translation helpful? Give feedback.
-
I would appreciate any guidance on best practices for using Shoelace in Astro. I have a working Astro / Shoelace set up, that solves a particular issue I have, but using Shoelace is not very straight forward and examples I've seen vary wildly. I'd like to make a starter project for Shoelace for others, so they have a clear approach to using Shoelace in Astro.
I've included specific questions at the bottom, but you might want to read the steps I went through to see what I ended up with.
I apologize if this is a bit chaotic, it just shows how little information there is on using Shoelace in Astro.
Here's a bit of background. Astro has some documentation on using Lit, but it assumes that you are making your own web components, not using a web component library.
Also, my set up is unique because I have a background-color/scheme transition that fades between light and dark along with view transitions, and for whatever reason, the set up that I thought would be optimal for Shoelace in Astro prevents this from working. I will explain below.
So here a few setups I went through. I originally had my set up working one way, from examples I found on the web, but I couldn't set the default animations for the tool tip, so I made a Shoelace discussion. In the solution example, the code looks like this:
The code above works, but later I realized that my transitions were not working, and I thought it was due to the light/dark theme
color-scheme:
property, but after testing if I completely disable the css, it still happens, so I knew it was something else.Later I realized that if the
import "@shoelace-style/shoelace"
is there the transition issue appears, but it is not related to css—it is related to js in some way. And in trying to fix that I ended up trying other people's set ups like the one below, which is only js, and that also caused the issue.After testing several ways of doing it, and stumbled across the fact that individual js imports solve the issue.
So, now I have something like the below...
This works, but I am concerned it is not a best practice, and I am confused as to how web components work in Astro in some ways.
One other thing to keep in mind is that in order for some js to work properly with Astro's view transitions some js needs this
is:inline
on the script tag. Incidentally, in Ex. A, if the script tag is on it, the js for the components doesn't load at all. (You do need it when setting the default animations though.)So my questions are...
(All of these questions assume importing of Shoelace through npm, not a cdn.)
1. Why do you not have to import Shoelace components, like you would in React?
2. Why do Shoelace components not need
client:load
like framework components?Strangely, Shoelace components work with out it and if you do use this on a Shoelace component, it complains of an import error.
3. Should shoelace be imported in one import or individually?
4. Where should Shoelace components be imported in Astro?
There are several ways to import that I've seen, some work with certain types of imports and some with others. And there are several places to import:
5. Bonus: what javascript would cause the background transitions to stop working?
This is specific to my set up, but after narrowing it down to js, I am very curious.
Anyway, sorry for all the questions. I will make somethign for others, so people don't have to struggle with these questions in the future. Cheers.
Beta Was this translation helpful? Give feedback.
All reactions