News for hackers. Stuff that matters.
Re:Why Tailwind Isn't for Me by dbbk on Friday January 26, 2024 @05:09AM (#39140833)
Why not Styled Components? I've been using them for years now and I'm extremely productive.

Tailwind on the other hand looks like a hellish nightmare, horizontal reading, proprietary syntax, no selector targeting of other components.

Re:Why Tailwind Isn't for Me by onion2k on Friday January 26, 2024 @05:30AM (#39141025)
Tailwind on the other hand looks like a hellish nightmare, horizontal reading, proprietary syntax, no selector targeting of other components.

Is "horizontal reading" worse than reading two files?

What if the other file is actually 30 files compiled with SASS?

What if they're 30 files, compiled with SASS, and written by a bunch of devs who don't know CSS well, didn't use BEM or anything to name things well, and didn't organise them at all?

Tailwind isn't better than great CSS, but it's significantly better than bad CSS.

Re:Why Tailwind Isn't for Me by dbbk on Friday January 26, 2024 @05:39AM (#39141081)
> Is "horizontal reading" worse than reading two files?

I see this complaint a lot but I don't really get it. You can have a styled component in the same file or a separate file. In VSCode, you just command click on the component and you go straight to the style definition. Not an issue.

> What if the other file is actually 30 files compiled with SASS?

I only work in Styled Components-exclusive codebases so can't comment

> What if they're 30 files, compiled with SASS, and written by a bunch of devs who don't know CSS well, didn't use BEM or anything to name things well, and didn't organise them at all?

You got bigger problems

Re:Why Tailwind Isn't for Me by onion2k on Friday January 26, 2024 @05:47AM (#39141146)
You got bigger problems

Yes, you have. And this is really, really common in large scale web apps, especially where they've been mostly written by people who are 'backend' or 'full stack' developers.

Tailwind didn't just spring forth as a tool to screw with web developers. It was developed as a solution to a problem. That problem being bad, unmanaged CSS at scale. If you don't have that problem obviously Tailwind isn't going to look useful to you.

Re:Why Tailwind Isn't for Me by lawn on Friday January 26, 2024 @01:36PM (#39146164)
> Is "horizontal reading" worse than reading two files?

Yes, very. I'm amazed that this is even in question.

Re:Why Tailwind Isn't for Me by 9dev on Friday January 26, 2024 @05:22AM (#39140959)
If horizontal reading bothers you so much it resembles a hellish nightmare (Dante would like to have a word with you), nobody stops you from going like this:

  <button class="
    flex
    bg-blue-400
    p-4
  ">Submit</button>
And you actually can target other components. There are lots of sibling selectors, including named groups:

  <label class="group/field">
    <input type="text" />
    <span class="order-1 text-black group-focus-within/field:text-blue-500">Name</span>
  </label>
Re:Why Tailwind Isn't for Me by s0laster on Friday January 26, 2024 @05:46AM (#39141138)
Damn, that's an awesome trick, thanks for sharing!
Re:Why Tailwind Isn't for Me by ricardobeat on Friday January 26, 2024 @05:27AM (#39141005)
> removes the thinking around CSS, naming, preprocessors etc
Re:Why Tailwind Isn't for Me by 9dev on Friday January 26, 2024 @05:34AM (#39141047)
It's a fairly limited set of rules that are mostly consistent, extensively documented, and easy to remember. But yeah, a little bit of effort is required when dealing with a styling language with over 300 properties.

Without Tailwind, you'll have to come up with a unique, declarative, distinctive name for each and every element you're piling styles upon. At first it's a button, then there's buttons that should look like links, and then clickable icons. They share some properties, but not others, and before you know it, you've invented an ad-hoc description language in CSS classes that nobody except you can understand right away. With Tailwind, you may have sequences of tokens that seem confusing at first, but at least it's the same -- few -- sequences in every single Tailwind project under the sun.

No side effects, no blurry concerns, no more specificity issues. If you don't appreciate that, you haven't seen large enough projects yet.

Re:Why Tailwind Isn't for Me by dbbk on Friday January 26, 2024 @05:40AM (#39141094)
> Without Tailwind, you'll have to come up with a unique, declarative, distinctive name for each and every element you're piling styles upon

I can honestly say I've never spent more than 5 seconds thinking about what to name a styled component, do you really get decision paralysis with this?

Re:Why Tailwind Isn't for Me by 9dev on Friday January 26, 2024 @05:52AM (#39141179)
This isn't about decision paralysis, but picking good names that other people will understand. But they won't, not all of them at least. No matter how great you're at naming things, you are going to do it differently than other people do. That doesn't matter on your personal home page, but it breaks down with a larger team. Inevitably, naming principles will drift apart, and after a few years, you'll have a mess. Don't believe me? Read the myriad of blog posts of development teams coming up with new CSS frameworks or migrating from one to another, to combat this.

Tailwind removes the naming ambiguity here, by moving away from naming things to describing the styles in a composable way. Drop your new hire in the code base, give them access to the Tailwind docs, and they'll be productive immediately (even more so if they previously spent half an hour with it).

Re:Why Tailwind Isn't for Me by dbbk on Friday January 26, 2024 @06:21AM (#39141392)
Why does the name matter? If it's a Wrapper or a Container or an InnerWrapper or whatever. It's just a 'label'.
Re:Why Tailwind Isn't for Me by 9dev on Friday January 26, 2024 @06:30AM (#39141454)
Because there is a Stylesheet called main.css with 5000 lines, and somewhere in there is a block like this:

  .InnerWrapper {
    padding: 3px 7px;
    margin-left: -9px;
  }
The design just got a makeover, and you’re tasked with updating all buttons to have a wider spacing.

Good luck catching everything, including this class and its usages, without manually reviewing everything that is used like a button, inspecting the HTML, then going over the classes, one by one, without breaking some unintended side effect.

Re:Why Tailwind Isn't for Me by dbbk on Friday January 26, 2024 @07:35AM (#39141944)
But we're talking about Styled Components
Re:Why Tailwind Isn't for Me by 9dev on Friday January 26, 2024 @07:43AM (#39142009)
No, we're not. I responded to your second statement, starting with "Tailwind, on the other hand", and I'm arguing against some of the unfounded criticisms here.
Re:Why Tailwind Isn't for Me by dbbk on Friday January 26, 2024 @09:33AM (#39143015)
I'm comparing Styled Components and Tailwind and you're off talking about some other third thing
Re:Why Tailwind Isn't for Me by chrischen on Friday January 26, 2024 @07:39AM (#39141985)
When you label something the implicit purpose is that it is now reusable. But an InnerWrapper class defined within a React component should be private and not actually reused, whether you are using global styles or css in JS (because it should be a private implementation detail—otherwise the component consumer has to also figure out the classes to apply).
Re:Why Tailwind Isn't for Me by dbbk on Friday January 26, 2024 @09:34AM (#39143032)
> When you label something the implicit purpose is that it is now reusable.

What makes you think that? I wouldn't use a wrapper element from a different component in another component. At some point you just have to use common sense.

Re:Why Tailwind Isn't for Me by PUSH_AX on Friday January 26, 2024 @05:13AM (#39140883)
My personal opinion is that styled components creates an unnecessary and fuzzy extra abstraction on top of components.
Re:Why Tailwind Isn't for Me by dbbk on Friday January 26, 2024 @05:26AM (#39140996)
Not really? It's just an element with some attached styles.

styled.div`color:red` is a red-colored div. Hardly fuzzy.

Re:Why Tailwind Isn't for Me by onion2k on Friday January 26, 2024 @05:54AM (#39141201)
The equivalent styled component of the default Tailwind button of "bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded" is "styled.div`background-color:#8888ff;color:white;font-weight:bold;padding-y:2px;padding-x:4px;border-radius:4px;&hover{background-color:#aaaaff}`".

Obviously you wouldn't actually write it like that because it's inline in your code so you can format it better, but the Tailwind version is less verbose and easier to read if you did.

Re:Why Tailwind Isn't for Me by dbbk on Friday January 26, 2024 @07:36AM (#39141961)
"Less verbose" I guess by a few characters... at the expense that you're not writing real CSS rules. So you're having to translate every rule into whatever Tailwind's syntax is for the same thing.
Re:Why Tailwind Isn't for Me by 9dev on Friday January 26, 2024 @07:47AM (#39142030)
It's not the same thing, though. Tailwind applies rules from your design system, not plain CSS values. Assuming you're updating your corporate design to use border-radius 2 vs 4 everywhere, with Tailwind it's a matter of reconfiguring your design system configuration; with styled components (and other approaches) you're going on a string hunt.
Re:Why Tailwind Isn't for Me by onion2k on Friday January 26, 2024 @08:42AM (#39142491)
Styled components are code. You could easily have a value from a central config rather than a string, like ${company.padding.px}.
Re:Why Tailwind Isn't for Me by 9dev on Friday January 26, 2024 @09:00AM (#39142636)
Sure. But now you need to maintain both places, you must think of units, and all the edge cases the Tailwind code base already handles.
Re:Why Tailwind Isn't for Me by dbbk on Friday January 26, 2024 @09:36AM (#39143062)
What you're talking about is really a theming design system, which yes Tailwind does have out of the box and Styled Components does not. But the companies I work in always have their own in-house design system, which means you have to maintain it yourself no matter what.
Re:Why Tailwind Isn't for Me by bernawil on Saturday January 27, 2024 @01:22AM (#39153131)
hey no need to make this an hypothetical! styled components come with ThemeProvider that does just that.

  const StyledButton = styled.button`
    background-color: ${props => props.theme.primaryColor};
  `