futursolo / stylist-rs

A CSS-in-Rust styling solution for WebAssembly Applications
https://crates.io/crates/stylist
MIT License
366 stars 22 forks source link

Stylist Examples do not include how to use it with Yew Struct Components #124

Closed Tom-CSTech closed 1 year ago

Tom-CSTech commented 1 year ago

The function component stuff requires to annotate the functions with styled-component, but this is not possible in the view functions of struct components, and the examples do not elaborate on how Stylist gets around this with its other features. Please amend the text to explain how this is done.

futursolo commented 1 year ago

Stylist is not tied to Yew and can be used in any webassmebly application. Using it with struct components are supported with the platform-agnostic API.

However, the current Yew integration is exclusive to function component because of the limitation of struct components. We never achieved the kind of integration we'd like to see with struct components like we did with #[styled_component] / use_* procedural macro.

We previously made an attempt with the YieldStyle API, however, it never cut down any real boilerplate than the platform- agnostic API and this API can be replicated with public API exposed from this crate. So we removed this API.

You can find the source code of this API here and an example here. This API no longer exists so you need to copy the implementation to your application if you wish to use it.

Tom-CSTech commented 1 year ago

Thank you for explaining. That is quite straightforward to the extent that even with my level of skill I should be able to replicate it easily. I do however wish the documentation mentioned it since many Yew applications are bound to use struct components and this is the only style crate that is actively maintained to this day among the list on the Yew site. It is a bit less obvious than it should be, I feel. In any case, thank you for informing me.

futursolo commented 1 year ago

I think Yew's documentation has heavily promoted function components for tutorials and new projects. Function components are both more versatile and have less boilerplate. In addition, multiple maintainers have expressed their interest in forgoing struct components completely. If someone chooses to use struct components, it's their choice with a steeper learning curve and limited support. I wouldn't recommend anyone to actively pursue using struct components in new projects.

I am still open to a struct component integration if it can achieve the level of integration on par with styled_component / hooks. However, I am not in favour of documenting how to use vanilla APIs with a certain framework as it would be hard to justify why we don't want to if a user from another framework wanted to include documentation / example of their framework in which no one can maintain if a breaking change happens with that framework in a later version.