Scoped styles macro! #583
eboody
started this conversation in
Show and tell
Replies: 1 comment 1 reply
-
Thanks for writing this up! I'm going to cross-post it to our Discord, which has a lot of active discussion as well. |
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
-
Hey guys!
I made a macro that wraps around Leptos's view! macro to make it really easy to add scoped styles to your components!
Let me know what you think! The crate is available at crates.io
Styled: Easy Styling for Leptos Components
If you're looking for an easy way to apply scoped styles to your
Leptos
components,Styled
is the Leptos macro you need. WithStyled
, you can apply high-level selectors likebutton
ordiv
to specific components, keeping your markup clean and organized.Installation
Use
cargo add
in your project rootUsage
First create a basic
Leptos
component. This will serve as the foundation for this little guide.Next, import the
style
macro, powered by an awesome crate calledStylist
, to create your styles.Just add this to the top of your file.
You can then use the
style
macro to create aResult
containing your styles. Let's modify our component:Now, let's apply those styles with our
styled::view!
macro!Now we can define another component that also uses the
div
CSS selector but it's styles will only apply to the elements inside of it's enclosingstyled::view!
macro.Beta Was this translation helpful? Give feedback.
All reactions