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

@rpxl/recast-tailwind-plugin

v0.2.4

Published

Recast offers tight integration with Tailwind CSS through our dedicated plugin, enhancing your development experience and unlocking powerful styling capabilities.

Downloads

54

Readme

Recast Tailwind CSS Integration

Recast offers tight integration with Tailwind CSS through our dedicated plugin, enhancing your development experience and unlocking powerful styling capabilities.

Installation

First, install the Recast Tailwind Plugin:

npm install @rpxl/recast-tailwind-plugin

Setup

Add the plugin to your tailwind.config.js file:

module.exports = {
  // ...other config
  plugins: [require("@rpxl/recast-tailwind")],
};

This plugin automatically generates a safelist for your Recast components and provides better integration with Tailwind CSS.

Features

  1. Automatic Safelist Generation: Ensures all your Recast component classes are included in your production build.
  2. Responsive Styling: Easily apply responsive styles to your Recast components using Tailwind's breakpoint syntax.
  3. Improved Performance: Optimizes class generation for better runtime performance.

VS Code Setup

To get Tailwind CSS IntelliSense working with Recast in VS Code:

  1. Install the Tailwind CSS IntelliSense VS Code extension.

  2. Add the following to your .vscode/settings.json:

{
  "tailwindCSS.experimental.classRegex": [
    ["recast\\(([^)]_)\\)", "[\"'`]([^\"'`]_).*?[\"'`]"]
  ]
}

Responsive Styling Example

With the Recast Tailwind plugin, you can easily apply responsive styles:

Responsive Variants

const Button = recast(ButtonPrimitive, {
  variants: {
    size: {
      sm: "px-2 py-1 text-sm",
      md: "px-4 py-2 text-base",
      lg: "px-6 py-3 text-lg",
    },
  },
});

<Button size={{ default: "sm", md: "md", lg: "lg" }}>Responsive Button</Button>;

This button will be small by default, medium on md screens, and large on lg screens. The plugin will generate classes like:

<button
  class="px-2 py-1 text-sm md:px-4 md:py-2 md:text-base lg:px-6 lg:py-3 lg:text-lg"
>
  Responsive Button
</button>

Modifiers

Recast also supports modifiers with Tailwind CSS. Here's how you can use them:

const Button = recast(ButtonPrimitive, {
  modifiers: { pill: "rounded-full" },
});

<Button pill>Pill Button</Button>;

The plugin generates HTML with classes like this:

<button class="rounded-full">Pill Button</button>

Prettier Integration

Recast works seamlessly with the prettier-plugin-tailwindcss. Add the following to your .prettierrc:

{ "tailwindFunctions": ["recast"] }

This ensures that your Tailwind classes within Recast components are properly sorted.

Breakpoints Configuration

Recast uses the breakpoints defined in your Tailwind configuration. Here's an example of how to set up breakpoints:

export const breakpoints = {
  sm: "640px",
  md: "768px",
  lg: "1024px",
  xl: "1280px",
  "2xl": "1536px",
};

These breakpoints are then used in your Recast components for responsive styling.

Plugin Implementation

The Recast Tailwind plugin handles the generation of safelist classes based on your component definitions and usages.

usages.forEach((usage) => {
  const component = components[usage.componentName];
  if (!component) {
    return;
  }

  // Add base classes to safelist
  if (component.base) {
    addToSafelist(safelist, component.base);
  }

  Object.entries(usage.props).forEach(([propName, propValue]) => {
    const variantGroup = component.variants?.[propName];
    if (!variantGroup) {
      return;
    }

    if (typeof propValue === "object" && propValue !== null) {
      Object.entries(propValue).forEach(([breakpoint, value]) => {
        if (typeof value === "string") {
          const classes = variantGroup[value];
          if (classes) {
            addToSafelist(
              safelist,
              classes,
              breakpoint !== "default" ? breakpoint : ""
            );
          }
        }
      });
    } else if (typeof propValue === "string") {
      const classes = variantGroup[propValue];
      if (classes) {
        addToSafelist(safelist, classes);
      }
    }
  });
});

This implementation ensures that all necessary classes for your Recast components are included in your final CSS, even when using dynamic class generation.

By following this setup and usage guide, you can leverage the full power of Recast with Tailwind CSS, creating flexible and responsive components with ease.