Can't get it working #49
-
Hi I'm not sure if I correctly understood what this library does. Can I use this and export Svelte components to Web Components and use those Web Components in for example a pure HTML project? If the answer is yes, well then, I tried using it for this library: https://github.com/babakfp/scrollephant and this is the result. This is what I expect: This is the result: Can you @patricknelson please take a look into my library and try to get it to work for me? 😭 I think it's been a year that I've been struggling with converting this library to work with Web Components so I can use it in a PHP project... Thanks 🌸🌸🌸 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
Sure (as long as JS is also ok 😅). Ironically the project you linked uses SvelteKit, which is of course far more than just HTML/JS. Note that
I would need to see the code that you’re actually running. I searched that repo and I don’t see If it helps, essentially the way it works is as follows, assuming you’re starting with a plain Vite project and have
Also note that SvelteKit isn’t necessary at all in any of that (so I typically recommend folks avoid it unless they need it for something else). I’m guessing maybe that is what is tripping you up. SvelteKit is fine for a full blown and fully fledged separate/demo site maybe, but See my hello world demo, specifically the |
Beta Was this translation helpful? Give feedback.
First issue I found was that you're not referencing
wc.js
properly, so nothing really runs at all inwc:dev
mode, but that's easy to fix.Everything is just fine, it appears that you're styling is breaking encapsulation a bit, at least in a way that is not compatible w/ custom elements, not just
svelte-retag
since you had some direct child selectors (i.e.>
) that were breaking styling, that's it. I submitted a quick hack proof of concept that fixes it using a known working layout (turned out to not be necessary). See PR babakfp/scrollephant#1 and the screenshots attached at bottom of this comment:Essentially: