Readit News logoReadit News
01brett commented on Goodbye CSS Modules, Hello TailwindCSS   polytomic.com/blog-posts/... · Posted by u/01brett
dimal · 4 years ago
Ah, I see. I was working on the web portion of a system that was meant to encompass web, mobile, and smart TV devices, and was very custom. The designers would not have even considered using off-the-shelf Tailwind values, and the mobile teams would not have wanted to translate a web-framework's values into mobile-land. I suppose if you have an organization that's ok with that constraint, that makes it more doable.

> I chalk this up as a design system win more than Tailwind. Any well-defined design system would open up these collaboration benefits. I found Tailwind to be an asset to these both for my own DX and for collaboration with my designer.

Yeah, this seems like the real takeaway. If you have a framework that gives you defaults for the design system, that reduces the friction even more, but I tend to work on very custom stuff where framework defaults won't be appropriate. Are the Tailwind values customizable, so you can use the same Tailwind structure, but have your designers specify their own tokens?

01brett · 4 years ago
Absolutely. The Tailwind config makes this really powerful to extend or override. You can reuse the same API for things like spacing with your own values/scale or make your own.

The Tailwind docs get into it a bit as you can see here: https://tailwindcss.com/docs/configuration#theme

Here is the spacing section in my config where I've extended the default with interstitial values. What's really cool is these propagate to all the spacing utilities (padding, margin, margin between, etc)

  spacing: {
      0.75: '0.1875rem',
      1.25: '0.3125rem',
      1.75: '0.4375rem',
      2.25: '0.5625rem',
      2.75: '0.6875rem',
      3.25: '0.8125rem',
      4.5: '1.125rem',
      4.75: '1.1875rem',
  }

01brett commented on Goodbye CSS Modules, Hello TailwindCSS   polytomic.com/blog-posts/... · Posted by u/01brett
bezieio · 4 years ago
If you like the idea of tailwind and don't want to look at utility classes and still want the power of styled-components or react-emotion I'd check out Chakra UI [0].

[0] https://chakra-ui.com/

01brett · 4 years ago
Chakra is excellent. I recommend it for any React devs considering Bootstrap. It's doubly useful if you don't have a designer.
01brett commented on Goodbye CSS Modules, Hello TailwindCSS   polytomic.com/blog-posts/... · Posted by u/01brett
spoiler · 4 years ago
Hi! I'm someone who worked with a designer closely to create a style guide/system and a React component library (using styled-components) for our product.

I don't see how Tailwind would've made our job any easier, or the implementation any "better" than what it is now. So, I'd definitely love to hear a non-vague (most Tailwind CSS praise I find around is very broad strokes or vague) success story.

Like, concrete examples where Tailwind reduced complexity or helped DX-wise, (etc) would be really appreciated. I believe there's many others like me who think Tailwind is kinda cool and we wouldn't mind playing with it in personal projects, but would hesitate to choose it at work/production...

I love the productivity idea its trying to sell me, but it sounds a bit... Wrong to me? Maybe I'm just too "old school", even if I'd like to think I'm keeping up lol.

01brett · 4 years ago
Author here, it depends on what your designer has made. Our designer was using the Tailwind Figma file for the redesign with most of the defaults in place. We added our brand green and a different font to the default config.

When I was working through some of the component structures and spacing, the designer explained to me which Tailwind values he used most often and in what scenarios. For example, spacing around sections/containers was 24px or p-6; spacing within sections (like between form inputs) was 12px or p-3; and spacing within elements (like between button icon and text) was 6px or p-1.5.

While these were not absolutes in the redesign, they greatly sped up my scaffolding and allowed my first passes to be either dead-on or close enough to reason about. And when it was close enough (but not dead-on), toggling up or down a value usually settled it to match the mocks.

Personally, this was the easiest time I've had for getting an implementation "pixel perfect." I chalk this up as a design system win more than Tailwind. Any well-defined design system would open up these collaboration benefits. I found Tailwind to be an asset to these both for my own DX and for collaboration with my designer. I think Theme UI or styled-components could fit that goal just as well.

01brett commented on Goodbye CSS Modules, Hello TailwindCSS   polytomic.com/blog-posts/... · Posted by u/01brett
jarek83 · 4 years ago
Was it Pollen? I really love that concept million times more over Tailwind.
01brett · 4 years ago
I haven't heard of Pollen before. I don't think it was what I was thinking of. Thanks for sharing though. Pollen looks really interesting.
01brett commented on Goodbye CSS Modules, Hello TailwindCSS   polytomic.com/blog-posts/... · Posted by u/01brett
uzername · 4 years ago
It's a shame that the Tailwind docs recommend to use craco. I think that's a major turn off. In that situation, I rolled my own npm-run-all customizations of the default scripts for start and build. It's extra noise but less than the documented approach.
01brett · 4 years ago
Author here, I am eagerly awaiting the next version of Create React App. I'm hoping the upgraded internals will remove the need for CRACO. Here's a link to CRA v5 on Github:

https://github.com/facebook/create-react-app/milestone/81?cl...

01brett commented on Goodbye CSS Modules, Hello TailwindCSS   polytomic.com/blog-posts/... · Posted by u/01brett
tcfunk · 4 years ago
I've been using tailwind in combination with styled components, so that I can easily capture repeated sets of classes. Something like:

  const PostImage = styled(Img).attrs({
    className: `
      duration-100
      transform
      transition-transform
      ease-in
      hover:scale-110
    `
  })``

01brett · 4 years ago
Author here, have you looked at twin.macro?

https://github.com/ben-rogerson/twin.macro

01brett commented on Goodbye CSS Modules, Hello TailwindCSS   polytomic.com/blog-posts/... · Posted by u/01brett
paulgb · 4 years ago
> consider this comment an open-invitation for other good css references!

I'll take you up on that! Any good resources for learning tailwind that jibe particularly well with your “learning tool” approach?

01brett · 4 years ago
Author here, I would also highly recommend Josh Comeau's CSS for JS Devs course. He covers fundamentals useful in all styling approaches.

https://css-for-js.dev/

01brett commented on Goodbye CSS Modules, Hello TailwindCSS   polytomic.com/blog-posts/... · Posted by u/01brett
noisy_boy · 4 years ago
So in this example:

    <div class='text-base font-sans font-medium rounded-lg bg-gray-100 text-black py-3 text-center cursor-pointer'>Button</div>
What happens if I have 20 of these divs and need to modify py-3 to py-4? Can I create a "local" .css file to "group" these tailwind classes ala pseudocode below?

    .divxyz-default {
        @extend text-base;
        ...
        @extend bg-gray-100;
        ....
    }
If so, then the div becomes <div class='divxyz-default'>. A thought came to mind that in that case I have gone back to CSS modules but then we still have some benefits of standardized classes e.g. instead of specifying how much roundness, I am using standard amount of roundness via "rounded-lg" and if I want to change that globally, I can edit in one place. I am probably missing something.

01brett · 4 years ago
Author here, I am using React. What I've done for "it shares some styles but not others" is create a

  const sharedStyles = "..."
and in my component combine the shared with the unique attributes

  <CoolComponent className={`${sharedStyles} py-3`} />
or using a string combiner utility like classNames/clsx

  <CoolComponent className={clsx(sharedStyles, "py-3")} />
If you have a props to change on, you can do this

  <CoolComponent className={clsx(sharedStyles, someProp ? "py-3" : "py-4")} />

01brett commented on Goodbye CSS Modules, Hello TailwindCSS   polytomic.com/blog-posts/... · Posted by u/01brett
dimal · 4 years ago
Exactly. This post is extremely unconvincing. The vast majority of the post is explaining the background of what CSS Modules is, what CSS-in-JS is, what Tailwind is... Then then "Implementation Strategy" section is three whole paragraphs, with no real details about the implementation. I honestly wonder how people would set up a design system with Tailwind. I don't see how to do it without it being a mess. I've done it with CSS Modules and CSS vars and it's lovely.
01brett · 4 years ago
Author here, would you be interested to read a deep dive of how I'm using Tailwind? I wanted to include it here, but the addition made the post unbearably long.

Also, if you have written about your design system implementation with CSS Modules and CSS variables, I'd love to read it.

01brett commented on Goodbye CSS Modules, Hello TailwindCSS   polytomic.com/blog-posts/... · Posted by u/01brett
kmeisthax · 4 years ago
I don't get why you wouldn't use LESS mixins or SASS class extensions (or whatever the modern equivalent of that is) instead of inlining each utility class directly into each div.

Having a name for each element in your markup is really powerful and useful, and it seems like the Tailwind approach exists specifically to avoid having to name things.

01brett · 4 years ago
Author here, I have a few custom classes that look like more traditional CSS. Tailwind gives an example[0] of how to do this in their docs. I have about 15 of these extracted classes. I use them for common styling patterns, such as transforming "flex items-center justify-center" to "flex-center," or to unify styling on components I haven't abstracted into a styled version, such as "listbox-option" or "flyout."

[0] https://tailwindcss.com/docs/extracting-components#extractin...

u/01brett

KarmaCake day122December 17, 2020View Original