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 🙏

© 2026 – Pkg Stats / Ryan Hefner

styled-tw-component

v1.1.4

Published

**`Styled-TW-Component`** is a utility library for creating stylish React components using Tailwind CSS. It provides a simple and flexible API to apply dynamic classes, manage variants, and customize your components with specific styles.

Downloads

10

Readme

Styled-TW-Component

Styled-TW-Component is a utility library for creating stylish React components using Tailwind CSS. It provides a simple and flexible API to apply dynamic classes, manage variants, and customize your components with specific styles.


🚀 Features

  • Create stylish components for all common HTML tags.
  • Supports dynamic classes via a function styleWithProps.
  • Handles style variants with the variants.
  • Includes a generic method create for more complex or customized components.
  • Compatible with TypeScript for an optimized development experience.

📦 Installation

# Use with Yarn
yarn add styled-tw-component

# Use with npm
npm install styled-tw-component

✨ Quick Use

import Styled from "styled-tw-component";

const Button = Styled.button(`px-4 py-2`);

// Use
export default function App() {
  return (
    <div>
      <Button>Bouton Principal</Button>
    </div>
  );
}

use variations

const Text = Styled.span("text-base", {
  variants: {
    primary: "text-blue-500",
    secondary: "text-gray-500",
  },
});

// Use
<Text variant="primary">Texte Principal</Text>
<Text variant="secondary">Texte Secondaire</Text>

Use the create method for a custom component

const Section = Styled.create<{ isActive: boolean }, "section">("p-4", {
  as: "section",
  styleWithProps: ({ isActive }) => (isActive ? "bg-green-500" : "bg-red-500"),
});

// Use
<Section isActive={true}>Section Active</Section>
<Section isActive={false}>Section Inactive</Section>

Use the create method to style another component.

Example 1:

const Button = ({ className }: { className?: string }) => {
  return <button className={className}>Button Label</button>;
};

const ButtonWrapper = Styled.create<{ className: string }, typeof Button>(
  `inline-flex items-center`,
  {
    as: Button,
    styleWithProps:(props)=> return props.className,
  }
);

// Use
<ButtonWrapper className="dark:bg-gray-800 dark:text-gray-400" />

-----------------------

Example 2:
const CustomComponent: React.FC<{ className: string; isActive: boolean }> = ({
  className,
  isActive,
}) => {
  return isActive ? (
    <p className={className}>This is active content</p>
  ) : (
    <p className={className}>This is Inactive content</p>
  );
};

const CustomComponentWrap = Styled.create<
  React.ComponentProps<typeof CustomComponent>,
  typeof CustomComponent
>('p-4', {
  as: CustomComponent,
  styleWithProps: ({ className }) => className,
});


// Use
<CustomComponentWrap isActive={false} className="bg-red-600" />

Use common HTML tags

Styled exposes a method for each current HTML tag such as div, span, button, etc.

const Wrapper = Styled.div("p-4 bg-gray-100");

const Title = Styled.h1("text-2xl font-bold text-center");

// Use
<Wrapper>
  <Title>Welcome on Styled-TW-Component</Title>
</Wrapper>

🛠️ API

Method create The create method allows you to create components with custom tags, custom component or advanced requirements

Styled.create<Props, As extends React.ElementType>(
  baseClass: string | ((props: Props) => string),
  config?: {
    as?: As;
    variants?: Record<string, string>;
    styleWithProps?: (props: Props) => string;
  }
): React.FC<React.ComponentPropsWithoutRef<As> & Props>;
  • baseClass (string | function) : The base class or function that dynamically generates the class.
  • config (object) :
    • as (React.ElementType) : Defines the HTML tag or component used.
    • variants (Record<string, string>) : Define variants for different configurations.
    • styleWithProps (function) : Generates dynamic classes based on props.

📝 The Future ?

For now compatible with React, make compatible angular, VueJS, add cool features etc.

📝 Contributions

Contributions are welcome! Please open an issue or submit a pull request.

💡 Auteur

Developed with ❤️ by AKS