[help] Failed to create custom components #292
-
How do I use global custom components with svelte kit? I don't understand the custom components section of the docs. Could you provide an example of the contents of <!-- EDIT: Here's the mistake. This file should be ./src/layout.svelte -->
<!-- ./src/routes/__layout.svelte -->
<script context="module">
import { h1, p, li } from './components.js';
export { h1, p, li };
</script> I want the classes on this <!-- ./lib/components/p.svelte -->
<p class="text-4xl text-blue-600"><slot /></p> How exactly do I export this |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 10 replies
-
I'm not sure if this is how this was intended to work, but I did get something working with custom components! 🎉 Here's what I needed: <!-- p.svelte -->
<p class="text-4xl text-blue-600"><slot /></p> // components.js
import p from './p.svelte'
export {p} // layout.svelte
<script context="module">
import { p } from './components/';
export { p };
</script>
// rest of your layout content goes here Essentially, create a custom |
Beta Was this translation helpful? Give feedback.
-
I am also unable to get a custom component working. As far as I can tell I have everything set up correctly but when the HTML is rendered it is not picking up my classes. <!-- $lib/components/markdown/h1.svelte -->
<h1 class="font-bold"><slot /></h1> <!-- __layout.svelte -->
<script lang="ts" context="module">
import h1 from "$lib/components/markdown/h1.svelte";
export { h1 };
</script>
<slot /> When my |
Beta Was this translation helpful? Give feedback.
I'm not sure if this is how this was intended to work, but I did get something working with custom components! 🎉
Here's what I needed:
Essentially, create a custom
.svelte
component that styles the element the way you need it to. Import that intocomponents.js
then export it (along with any other custom components). Then importcomponents.js
into thecontext="module"
section of your layout file. Hope this helps!