-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Why use className as interface #3
Comments
Using inline styles is fine, and you are free to do that. But in my opinion, that should be left for dynamic values. But remember, if you go with the inline style approach, you have to find a way to do pseudo selectors, media queries + all the other 'simple' things that you normally take for granted in CSS. Sure, it's possible to do all those in javascript, but it leads to unnecessary bloated code. (...Just try and make a simple selector widget with an icon before the text, with a hover + active state that should look slightly different on mobile and tablet devices. It's certainly possible in js, but not in a clean way.) Stilr takes a different approach. We embrace css but gives you javascript to manipulate it. But you wont have trouble with the classic css namespace collisions, because all class names are based on a content hashes. In fact, don't mind the class name property. It's just an implementation detail to bypass having to reinvent simple css stuff. |
So is there a way for me to pass in class names directly to tags? And does stilr just return a string that's a class I can use? |
Yes, the E.g. const styles = StyleSheet.create({
container: {
color: 'blue'
}
});
// styles.container is now a string, containing: `_1UXA3k`
// Use this as your class name on tags/components
<AppComponent className={ styles.container } />
You are free to add additional classes to your component besides the Stilr generated class. Since const classes = [
styles.container,
'your-class-name'
].join(' ');
<AppComponent className={ classes } /> |
This seems like the strictly the wrong way to inject styles.
I'd prefer the react-style method, where they shim in a new property (styles) and you pass them in. Or alternatively, why not just have an interface where I can pass them directly into
style={}
? Or is that already possible?The text was updated successfully, but these errors were encountered: