Replies: 4 comments 1 reply
-
To 3. You can forward events by omitting the handler in the component like |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
A main problem with
|
Beta Was this translation helpful? Give feedback.
-
To style a child component I use CSS modules. Just import the stylesheet and pass the class as prop: Define a prop name you like, I use <script>
export let className = "";
</script>
<div class={className} /> And then just pass it: <script>
import styles from "./styles.module.css";
<script>
<Child
className={styles["some-class-name"]}
/> Also, as mentioned earlier, just use CSS custom properties, not preprocessors are needed. <div class="some-class">
<Child />
</div>
<style>
.some-class {
/* this will be inherited by children */
--some-property: red;
}
</style> |
Beta Was this translation helpful? Give feedback.
-
I love Svelte so much and it's my number 1 choice for every new project
But there's a few things I'm always struggling with, and I'm hoping that I'm just not doing it the best way and someone reading this could suggest me better methods.
:global(.class)
directives in my component's css to override a class in a child. And this breaks the idea of encapsulated class definitions. Feels like I'm messing up the cleanliness of my code this way and I'm hoping there's better approaches.@media(min-width:${desktopWidth}){...
and define this breakpoint globally. I don't like to define the same breakpoint in multiple places which is what I'm doing now.I'm aware of a javascript solution (with a global store for example) that listens to media query changes and propagates, but I'm looking for a solution within css.
<CustomInput on:input={...}/>
and<CustomButton on:click={...}/>
. Currently I have to passonClick={clickHandler}
, and in the child component writeexport let clickHandler
andon:click={clickHandler}
it would be amazing if I could pass the handlers directly somehow.Beta Was this translation helpful? Give feedback.
All reactions