Live data from Hacker News

Working with Tailwind CSS every day for 2 years

themosaad.com

211–215 of 215 posts

Re: Working with Tailwind CSS every day for 2 years

#211
post #85

Earlier quoted context omitted.

From that link: ` ... ;` That must be one of the most horrid things I've ever seen done to CSS.

Yep, that looks like what a few seconds of my vim typing looks like but tossed into source code. Ill take the wall of tailwind any day over that.

You're not wrong re vim. :-)

Definitely use whatever you like, but just like vim bindings, which look "omg wtf" to newbies but then become "cannot live without" once you learn them, once you learn the Tachyons-style abbreviations, I/we find that they fade into the background/become 2nd nature, and the succinctness ROI is worth it.

But happy to have you disagree/stick with TW.

Re: Working with Tailwind CSS every day for 2 years

#212

Earlier quoted context omitted.

Sorry, could you reformat your code? I can't read this well.

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…

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
    
      Hello world
    
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: Working with Tailwind CSS every day for 2 years

#213

Earlier quoted context omitted.

I wrote that because the benefit most people who liked styled-components told me they appreciated was that they didn't have to think about inheritance. Everything is encapsulated in the component. This, to me, is equivalent to saying "I think the cascading part of CSS is either a mistake, or too complicated to maintain in practice, so I am going to eliminate it."

> This, to me, is equivalent to saying "I think the cascading part of CSS is either a mistake, or too complicated to maintain in practice, so I am going to eliminate it." I agree both with your interpretation, and with the sentiment. I think, in many contexts, using the Cascading part of CSS is a mistake. It's great for low-level design system kinds of work (e.g. setting matching text and BG color, then override font…

Whether you like it or not, the cascading part of cascading style sheets is an integral part of the web platform, and one is better off in the long run swimming with the current of the platform rather than against it.

Re: Working with Tailwind CSS every day for 2 years

#214
post #129

Earlier quoted context omitted.

I actually think a lot of CSS-in-js frameworks became popular for the same reason that React became popular: css, html, and to some extent JavaScript can't really be decoupled. Things like CSS Zen garden made it seem like they were, but that was only a separation of control. If the HTML structure changes, then the CSS likely needs to change. That's a tight coupling. CSS-in-js embraces the coupling and makes it explic…

Agreed. I think he's completely misidentified why CSS-in-JS became a thing. I've done a lot of thinking about this - like "How would we adopt what we have done in frameworks into web standards"? And the closest I have come up with is Svelte. In Svelte your file is a component. It can have a tag which defines state that can be passed to it or any other arbitrary javascript. You can have a tag which scopes specifically…

I cannot agree with this comment any more. Every time I read any one of these Tailwind threads, I am yelling in my head "SVELTE!!!!" the whole time. Going against the current of the platform is a recipe for disaster every time, and Svelte is one of the few frameworks that is actually trying to go _with_ the current.

Re: Working with Tailwind CSS every day for 2 years

#215
post #137
post #57

Earlier quoted context omitted.

What would recommend for some sane CSS/SCSS defaults?

Oh, I guess I cannot edit it anymore. *EDIT* for the above. What are some typical defaults that I should start with for things like margin, padding, font size? What sort of items should I be initializing in ::root then overriding later?

I copied this from a specific project, so there might be a couple things missing, but here is generally what I use

https://gist.github.com/bdougherty/404b4ca33dfdbff48614b454f...

Post reply on HN