Replies: 1 comment 1 reply
-
Unfortunately is not that simple for a series of reasons:
those are only the first problems that comes to mind but there will likely be a bit more. That said there are discussion about allowing the parent component to style the child component in the future. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
TLDR;
Svelte components have everything that regular HTML tags have, except custom styles. This is a serious shortcoming that prevents people from sharing re-usable components and UI libraries. Custom styles would allow the user of a component to control the appearance of a component leaving the author to focus on the functionality.
What is missing
HTML tags have features that Svelte components replicate but there is clearly an imbalance in the design where CSS is concerned.
When I use an HTML element I have complete control over its appearance using CSS. When I use a component that someone else has authored I have no control over its appearance using CSS.
I do have indirect control over a component's appearance using methods like CSS globals, CSS tokens and Svelte props but they are poor workarounds. Why? Because CSS globals are indiscriminate. And CSS tokens and props require the component's author to anticipate every possible use case, which is impossible, of course. So the author is required to endlessly provide updates as their users request support for new use cases. The user experience of this is bad too. Every component a user downloads will have its own unique set of tokens and props that the user must learn.
Example
I have created a dynamic search component, called Search.svelte. Internally it has a text input field and a ContextMenu component. The value of Search.svelte is the way it caches results so that as the user types more characters further round trips to the server are unnecessary. It would make a nice thing for me to contribute back to Svelte.
I use Search.svelte in a number of places in my application: in a page header, in the main section and in forms. In each location I have specific requirements for it's appearance. Variously, in my application the following CSS properties depend on the location.
If other people were to use Search.svelte they would have just as many more special requirements for the appearance. But I have no interest in supporting Search.svelte to that degree. I won't go into my reasons why here, but I don't think I'm alone in this.
The solution
Boost the syntax of CSS to allow style to be defined from outside components. Allow a component name to be used in CSS rules just like tab names. For example, if Main.svelte uses component Search.svelte then the style of the elements of Search could be controlled from Main.svelte as follows.
Search.svelte
Main.svelte
Beta Was this translation helpful? Give feedback.
All reactions