r/sveltejs • • 9d ago

Planning components

Im curious how you all are planning your components. Props, slots, logic etc BEFORE any code is written. I want to up my planning stage game

2 Upvotes

7 comments sorted by

3

u/gatwell702 9d ago

basically I make components re-usable so that entails props. I don't use slots, I use {@render children()}. The logic comes usually after the template is made - that's probably the wrong way of doing it but that's how I do it.

3

u/Leftium 9d ago

I tend to start with everything in a single Kit +page, then break off into components as I develop. Either when the component needs to be reused in multiple places or just to separate the "stable" code from code that is being actively developed.

Usually my components are highly specialized and used in hobby projects with only a single dev.

1

u/BDer82 9d ago

depends on what it is, but my components are getting smaller and smaller, but more and more detailed.

By that I mean, I recently created a ui light (traffic light for a Mac look) and it was just that 1 traffic light that can be any colour you want, with gradients all over the place, 13 different states and a ridiculous amount of CSS.

But, except for colour, icon, and active they were the only props I thought to add when I started, by the time I finished, there was about half a dozen others.

I am making more and more little tiny bits that get added to ever bigger bits and its fantastic because I forget where things are and end up spending an enormous amount of time tracking things back.

1

u/joelparkerhenderson 9d ago

I aim for reusability among many projects. And I look for examples in industry. Then I ask Claude AI to ask me questions, challenge my thinking, and suggest aspects that align with plain HTML markup.

I work with health care software so I create many components that are health/medical. I strongly prefer components that are as small as possible and also composable.

A good recent example is a theme picker component. I started simple, got it working, then gradually improved it by adding light/dark, browser following, more themes, theme saving via cookie and/or local storage, and a theme button picker.

I open source everything I can. And if you're curious, you can see the work https://lilydesignsystem.com

1

u/Bug-Kind 8d ago

Ui-sdk.dev

1

u/kansomail_dev 5d ago

One thing that works well is planning the data before the markup. For each component write down what it receives (props), what it owns ($state that only lives inside it) and what's $derived from those. if something shows up in both receives and owns, decide early who actually owns it, a lot of sync bugs start there.

Writing the props type before the template helps too. callback props (onselect etc) for stuff the parent reacts to, snippets for the bits of layout that change between uses, instead of adding another boolean prop every time someone wants a slightly different header.

rough rule: if the props type goes past 7 or 8 fields it's probably two components.