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

panda-plugin-crv

v0.3.1

Published

A Panda CSS plugin for responsive variants

Downloads

2,345

Readme

panda-plugin-crv

A Panda CSS plugin for responsive cva variants. This plugin allows you to to use Panda's responsive syntax, without config recipes, such as:

<Component variant={{ base: 'secondary', lg: 'primary' }} />

Installation

npm i panda-plugin-crv
// panda.config.ts

import { defineConfig } from '@pandacss/dev';
import { pluginResponsiveVariants } from 'panda-plugin-crv';

export default defineConfig({
  plugins: [pluginResponsiveVariants()],
});

Usage

This plugin removes the boilerplate required to build responsive variants within cva. This allows you to (1) co-locate variants near your components instead of in Panda's config, and (2) generate atomic class names.

Example component styles:

import { crv, cva } from '@/styled-system/css';

const styles = cva({
  variants: {
    // Create responsive variants
    ...crv('variant', {
      primary: { bg: 'blue.500' },
      secondary: { bg: 'gray.500' },
      destructive: { bg: 'red.500' },
    }),
  },
});

This plugins ships two helpers to parse responsive variants in your components.

  • ResponsiveVariant – creates appropriate types, with your theme's breakpoints
  • splitResponsiveVariant – translates the incoming responsive object into variants generated by crv
import {
  splitResponsiveVariant,
  type ResponsiveVariant,
} from '@/styled-system/css';

type ComponentProps = PropsWithChildren<{
  variant?: ResponsiveVariant<'primary' | 'secondary' | 'destructive'>;
}>;

const Component: FC<ComponentProps> = (props) => {
  const { children, variant = 'secondary' } = props;
  const variants = splitResponsiveVariant('variant', variant);

  return <div className={styles({ ...variants })}>{children}</div>;
};

Using your component will look like this:

<Component variant="primary" />
<Component variant={{ base: 'secondary', lg: 'primary' }} />

Compound Variants

This plugin supports responsive compound variants, through the ccv function. Note: this can produce a large amount of compound variants. Make sure your unused CSS is purged properly.

import { ccv, crv, cva } from '@/styled-system/css';

const styles = cva({
  variants: {
    ...crv('variant1', {
      primary: { bg: 'blue.500' },
      secondary: { bg: 'gray.500' },
      destructive: { bg: 'red.500' },
    }),
    ...crv('variant2', {
      true: { opacity: 1 },
      false: { opacity: 0 },
    }),
  },
  compoundVariants: [
    // Create compound variants
    ...ccv({
      variant1: 'primary',
      variant2: true,
      css: {
        color: 'green.500',
      },
    }),
  ],
});

The above code will render "green.500" if variant1 is "primary" and if variant2 is true

<Component variant1="primary" variant2>
// -> opacity_1 bg_blue.500 text_green.500

<Component
  variant1={{ base: 'secondary', lg: 'primary' }}
  variant2={{ base: false, lg: true }}
/>
// -> opacity_0 lg:opacity_1 lg:bg_blue.500 bg_gray.500 lg:text_green.500

Current Limitations

  • The plugin generates variants for all breakpoints defined in your theme, and does not include Panda's generated breakpoints, such as mdDown, mdOnly, mdToLg.
  • There is currently no way to limit or pick which breakpoints you wish to generate.