News for hackers. Stuff that matters.
Re:What working with Tailwind CSS every day for 2 years look... by lvl102 on Tuesday November 29, 2022 @12:25PM (#33790425)
I don’t think you realize that there are a lot of old school developers such as myself (going +25 years) who’s simply looking for quick and dirty front end tools that simply work and get out of the way. Tailwind does exactly that.
Re:What working with Tailwind CSS every day for 2 years look... by postalrat on Tuesday November 29, 2022 @12:31PM (#33790527)
How does it not get in your way? If you ignore it?
Re:What working with Tailwind CSS every day for 2 years look... by dmitriid on Tuesday November 29, 2022 @12:46PM (#33790717)
It gives you a consistent design system with sensible defaults and easy-to-use (and rather memorable or easy to deduce) utility classes.

Unlike the yet-another umpteenth bespoke `.card-header__buttons .card-header__button--secondary` that no one can remember and create an umpteenth+1

Tailwind works great when your site/app is a collection of components

Re:What working with Tailwind CSS every day for 2 years look... by atsjie on Tuesday November 29, 2022 @01:09PM (#33791022)
`.card-header__buttons` that example makes no sense unless you use global CSS/SASS, which very few projects do anymore. Component CSS/SCSS or CSS-in-JS are very common which resolve this scoping problem.

So why bother with a DSL like Tailwind over Component CSS/SCSS for example?

Re:What working with Tailwind CSS every day for 2 years look... by atsjie on Tuesday November 29, 2022 @01:22PM (#33791172)
> How do you enforce consistency in CSS-in-JS? Paddings, margins, sizes, colors?

JavaScript variables, css variables? Both can be used. It's pretty trivial tbh.

Re:What working with Tailwind CSS every day for 2 years look... by dmitriid on Tuesday November 29, 2022 @01:20PM (#33791140)
How do you enforce consistency in CSS-in-JS? Paddings, margins, sizes, colors?

Everywhere I've seen CSS-in-JS used, everywhere it's people busy writing bespoke styles in every file.

Re:What working with Tailwind CSS every day for 2 years look... by postalrat on Tuesday November 29, 2022 @01:29PM (#33791268)
That's the same problem I see with tailwind.

I prefer a global set of styles and more specific selectors to override styles where needed. It may not work well on projects with many teams but for the projects I typically work on it's fine.

Re:What working with Tailwind CSS every day for 2 years look... by dmitriid on Tuesday November 29, 2022 @02:05PM (#33791716)
> That's the same problem I see with tailwind.

The thing with Tailwinf is that it already has a decent design syste encoded in its utility classes. It's very easy to slap a p-2 for a standardized padding than trying to remember what it was when you write the next component with `{ padding: 2 2 2 2 }`

> I prefer a global set of styles and more specific selectors to override styles where needed.

That's kinda what I mean. In all projects I've seen you have a global stylesheet with a bunch of classes that no one remembers, and hundreds of one-ofs in every component either reimplementing stuff from scratch or serving as an `!important` of sorts

Re:What working with Tailwind CSS every day for 2 years look... by atsjie on Tuesday November 29, 2022 @01:46PM (#33791485)
> How do you enforce consistency in CSS-in-JS? Paddings, margins, sizes, colors? JavaScript variables, css variables? Both can be used. It's pretty trivial tbh.
Re:What working with Tailwind CSS every day for 2 years look... by satvikpendem on Tuesday November 29, 2022 @02:03PM (#33791697)
By having a style guide with variants, StitchesJS pioneered this but there are others like Vanilla-Extract. With TypeScript, you can then enforce that only a certain variant can be used with a certain component at compile time, basically making sure that your design style guide gets mapped 1:1 to your code.

https://stitches.dev/

Re:What working with Tailwind CSS every day for 2 years look... by dmitriid on Tuesday November 29, 2022 @03:10PM (#33792596)
Hm. I see the same CSS-in-JS with a sprinkle of string interpolation for some variables :)

I may run into the same issues as the other CSS-in-JS solutions (I only encountered stitch once, and not for a long period of time)

Re:What working with Tailwind CSS every day for 2 years look... by satvikpendem on Tuesday November 29, 2022 @04:11PM (#33793369)
Unlike other CSS-in-JS though, the way it's made, via object properties, enforces compliance to the design system. In things like styled-components, it doesn't.

Doubly so when using TypeScript, as with Vanilla-Extract: https://vanilla-extract.style

Re:What working with Tailwind CSS every day for 2 years look... by dmitriid on Tuesday November 29, 2022 @04:46PM (#33793801)
> the way it's made, via object properties, enforces compliance to the design system.

The link literally has this:

``` export const className = style({ display: 'flex', flexDirection: 'column', selectors: { '&:nth-child(2n)': { background: 'aliceblue' } }, '@media': { 'screen and (min-width: 768px)': { flexDirection: 'row' } } }); ```

Which is indistinguishable from any other CSS-in-JS which has hundreds of these one-off things scattered everywhere. With a theme somewhere exposing another hundred or so variables of varing quality. And all these solutions basically converge on Tailwind (or other utility-first CSS approaches):

``` export const hero = style({ backgroundColor: vars.color.brandd, color: vars.color.white, padding: vars.space.large }); ```

is nothing more than `bg-brand color-white p-4`

But TypeScript support is definitely nice.

Re:What working with Tailwind CSS every day for 2 years look... by satvikpendem on Tuesday November 29, 2022 @04:59PM (#33793960)
Sorry, could you reformat your code? I can't read this well.
Re:What working with Tailwind CSS every day for 2 years look... by dmitriid on Wednesday November 30, 2022 @05:11AM (#33798900)
Sorry, I keep forgetting that HN is weird with line breaks

Re-typing/re-quoting:

--------

The link literally has this:

    export const className = style({
      display: 'flex',
      flexDirection: 'column',
      selectors: {
        '&:nth-child(2n)': {
          background: 'aliceblue'
        }
      },
      '@media': {
        'screen and (min-width: 768px)': {
          flexDirection: 'row'
        }
      }
    });
Which is indistinguishable from any other CSS-in-JS which has hundreds of these one-off things scattered everywhere. With a theme somewhere exposing another hundred or so variables of varing quality. And all these solutions basically converge on Tailwind (or other utility-first CSS approaches):

    export const hero = style({
      backgroundColor: vars.color.brandd,
      color: vars.color.white,
      padding: vars.space.large
    });
is nothing more than `bg-brand color-white p-4`

But TypeScript support is definitely nice.

----

Re:What working with Tailwind CSS every day for 2 years look... by satvikpendem on Wednesday November 30, 2022 @12:42PM (#33804411)
This video from Stitches shows their API well, which VE copied with their Recipes plugin, code example below (timestamped to 31:07 in case the link doesn't work) [0].

    /// Define variants for a specific component, such as a button
    export const button = recipe({
      base: {
        borderRadius: 6
      },
    
      variants: {
        color: {
          neutral: { background: 'whitesmoke' },
          brand: { background: 'blueviolet' },
          accent: { background: 'slateblue' }
        },
        size: {
          small: { padding: 12 },
          medium: { padding: 16 },
          large: { padding: 24 }
        },
        rounded: {
          true: { borderRadius: 999 }
        }
      },
    
      // Applied when multiple variants are set at once
      compoundVariants: [
        {
          variants: {
            color: 'neutral',
            size: 'large'
          },
          style: {
            background: 'ghostwhite'
          }
        }
      ],
    
      defaultVariants: {
        color: 'accent',
        size: 'medium'
      }
    });

    /// Use in code
    <button className={
      button({
        color: 'accent',
        size: 'large',
        rounded: true
      })
    }>
      Hello world
    </button>
Basically, unlike other CSS-in-JS libraries, you can encode your design system into something called variants, then you use them by calling the function `button()` to generate a class name.

Notice how `button()` takes in certain properties and only those properties with their corresponding values (enforced by TypeScript). If you try to put in `button({ color2: 'testColor', ...})`, TS won't compile.

In this way, you can take the design team's ButtonSmall, ButtonLarge, NeutralButtonLarge etc and codify them into TypeScript such that you literally can't make a mistake. You simply can't do that in Tailwind, unless you use some outside plugin I assume.

(Note that VE also has a Tailwind-like atomic CSS API called Sprinkles, but since I don't like Tailwind I don't use this either).

[0] https://youtu.be/Gw28VgyKGkw?t=1867

Re:What working with Tailwind CSS every day for 2 years look... by icedchai on Tuesday November 29, 2022 @03:09PM (#33792588)
I'm in the same boat, and Tailwind looks like something that would get in my way (or at least becoming annoying very quickly.) I don't want the equivalent of inline styles all over the place.
Re:What working with Tailwind CSS every day for 2 years look... by greenhatman on Tuesday November 29, 2022 @03:36PM (#33792920)
This is probably the main thing that puts people in one camp or the other.

Before Tailwind came along I very often found myself just wanting to put some inline styling in various places. It's so much easier to just add some CSS to an element than having to think of a class name, think of where the best place would be to put the class, etc.