npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

Iโ€™ve always been into building performant and accessible sites, but lately Iโ€™ve been taking it extremely seriously. So much so that Iโ€™ve been building a tool to help me optimize and monitor the sites that I build to make sure that Iโ€™m making an attempt to offer the best experience to those who visit them. If youโ€™re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, ๐Ÿ‘‹, Iโ€™m Ryan Hefnerย  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If youโ€™re interested in other things Iโ€™m working on, follow me on Twitter or check out the open source projects Iโ€™ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soonโ€“ish.

Open Software & Tools

This site wouldnโ€™t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you ๐Ÿ™

ยฉ 2024 โ€“ย Pkg Stats / Ryan Hefner

tailorwind

v0.4.0

Published

Reusable and extensible React components using Tailwind CSS ๐Ÿงถ๐Ÿ’™

Downloads

31

Readme

What's this? ๐Ÿงถ

Tailorwind is a super tiny little library that allows you to easily declare components with the utility class names from Tailwind. Basically - you'll be able to pull stunts like these:

// Super basic
const ChiliButtonStyle = tw`bg-[red]`

// Kinda basic
const ChiliButton = tw.button`bg-[red]`

// Spicy basic
const ChiliButton = tw('button')`bg-[red]`

// Whoa! Look at you go!
const AnimatedChiliButton = tw(motion.button)`bg-[red]`

// You should really chillax.
const StyledComponent = styled.button`display: flex; justify-content: center;`
const ChiliButton = tw(StyledComponent)`bg-[red]`

// NOOOOOOOOOOO! ๐Ÿ˜ญ
const ChiliButton = tw(styled(motion.button)`display: flex;`)`justify-center bg-[red]`

Getting the show on the road ๐Ÿป

I knew you'd buy right into this piece of super tiny software the moment you stepped into this repo! You can either check it out at npmjs - or just install it using your favorite package manager.

Using yarn ๐Ÿงถ

yarn add tailorwind

or npm ๐Ÿ“ฆ

npm install tailorwind

or even pnpm ๐Ÿป

pnpm install tailorwind

All lined up and ready to go! ๐ŸฅŠ Just slap an import like this right onto your code and you're golden ๐Ÿ‘‘

import { tw } from 'tailorwind'

What about the intellisense? ๐Ÿ˜ฑ

Wouldn't this break the amazing Tailwind intellisense extension? Fret not! There's a solution for this ๐Ÿ™

First off - you'll need the extension. Then you'll have to edit your vscode settings and add the following property:

"tailwindCSS.experimental.classRegex": [
    "tw\\.[^`]+`([^`]*)`", // tw.xxx`...`
    "tw\\(.*?\\).*?`([^`]*)" // tw(Component)`...`
]

I've stolen those regexes directly from tailwind-styled-components. In other words - don't thank me for em. Skip on over to that repo and give your thanks. ๐Ÿ™

Why this? ๐Ÿค”

I love Tailwind. It's simply great. But - I was starting to get a little bit tired of the whole "div-bonanza" consisting of <div className="p-8 bg-red-500 ... bla bla" /> and so on. I know what you're thinking - just declare a component that accepts children and use that bad boi if you'd like more verbose components. Fine, that's one way to go about it. But think of all the lines we're saving ๐Ÿ’™.

We're taking this chunky chunk-chunk:

const ChiliButton = (props: ButtonHTMLAttributes<HTMLButtonElement>) => {
  return (
    <button className="bg-[red]" {...props}>
      {children}
    </button>
  )
}

and replacing it with this slimmy slim-slim:

const ChiliButton = tw.button`bg-[red]`

It might be a ๐ŸŒถ๏ธHOT TAKE๐ŸŒถ๏ธ but I'd say it's at least a little bit of a win.

With the power of Tailorwind โšก

You get the gist. You write smaller amounts of code and it makes it a bit easier to read. Here's my final example to trick you into using my simple little library.

const BaseButton = tw(motion.button)`p-8 rounded-2xl`

const variants: Variants = {
  initial: {
    scale: 0.2,
    opacity: 0,
  },
  animate: {
    scale: 1,
    opacity: 1,
  },
  tap: {
    scale: 0.8,
  },
  hover: {
    scale: 1.2,
  },
}

BaseButton.setDefaultProps({
  initial: 'initial',
  animate: 'animate',
  whileTap: 'tap',
  whileHover: 'hover',
  variants,
})

const Button = {
  Primary: tw(BaseButton)`bg-[red]`,
  Secondary: tw(BaseButton)`bg-[green]`,
  Tertiary: tw(BaseButton)`bg-[blue]`,
}

Fully animated and ready to rumble - with the power of the all mighty framer-motion. Just slap one of those motion components right in there and watch that component purr. ๐Ÿงถ

Hey oh! Missing feature alert ๐Ÿšจ

You might end up in a corner where you need a bit more functionality. This teeny tiny lib is just supposed to do the absolute necessity to get the component declaration show on the road. If you're looking for a more styled-components type of wibe - I'd direct you right on over to: tailwind-styled-components. That's also a teeny tiny library that's just a tad bit larger - but also does a tad bit more. ๐Ÿป So check that out before wreaking havoc over here with your silly little feature requests. ๐Ÿ’™