twc

Create reusable React + Tailwind components in one line

README

twc


Features


- ⚡️ Lightweight — only 0.46kb
- ✨ Autocompletion in all editors
- 🎨 Adapt the style based on props
- ♻️ Reuse classes with asChild prop
- 🦄 Work with all components
- 😎 Compatible with React Server Components
- 🚀 First-class tailwind-merge and cva support



Documentation



Usage


Without twc:

  1. ```tsx
  2. import * as React from "react";

  3. const Card = React.forwardRef<
  4.   HTMLDivElement,
  5.   React.HTMLAttributes<HTMLDivElement>
  6. >(({ className, ...props }, ref) => (
  7.   <div
  8.     ref={ref}
  9.     className={clsx(
  10.       "rounded-lg border bg-slate-100 text-white shadow-sm",
  11.       className,
  12.     )}
  13.     {...props}
  14.   />
  15. ));
  16. ```

With twc:

  1. ```tsx
  2. import { twc } from "react-twc";

  3. const Card = twc.div`rounded-lg border bg-slate-100 text-white shadow-sm`;
  4. ```

Contributing


Feel like contributing? That's awesome! We have a
contributing guide to help guide you.

Want to help improve the docs?


The docsite lives in the monorepo.

If you're interested in contributing to the documentation, check out the

Support


Having trouble? Ping me on X

Acknowledgement


The development of TWC was only possible due to the inspiration and ideas from these amazing projects.

- styled-components - where it all started

License


MIT License © 2023-Present Greg Bergé