GithubHelp home page GithubHelp logo

react-cva's Introduction

react-cva

NPM Version Types Included Minizipped Size NPM Downloads Follow @NFS__21 on Twitter

Introduction

this is a helper library for cva which this uses internally, for creating react components. for more information view cva docs.

Acknowledgements

Installation

npm i react-cva

Examples

with tailwind css
import { styled } from "react-cva";

const Button = styled("button")("button", {
  variants: {
    intent: {
      primary: [
        "bg-blue-500",
        "text-white",
        "border-transparent",
        "hover:bg-blue-600",
      ],
      secondary: [
        "bg-white",
        "text-gray-800",
        "border-gray-400",
        "hover:bg-gray-100",
      ],
    },
    size: {
      small: ["text-sm", "py-1", "px-2"],
      medium: ["text-base", "py-2", "px-4"],
    },
  },
  compoundVariants: [{ intent: "primary", size: "medium", class: "uppercase" }],
  defaultVariants: {
    intent: "primary",
    size: "medium",
  },
});

const Render = () => {
  return (
    <div>
      <Button intent="primary">test</Button>
    </div>
  );
};
with css modules
import { styled } from "react-cva";
import style from "./button.module.css";

const Button = styled("button")(style.base, {
  variants: {
    intent: {
      primary: style.primary,
      secondary: style.secondary,
    },
    size: {
      small: style.small,
      medium: style.medium,
    },
  },
  compoundVariants: [
    { intent: "primary", size: "medium", class: style.primaryMedium },
  ],
  defaultVariants: {
    intent: "primary",
    size: "medium",
  },
});

const Render = () => {
  return (
    <div>
      <Button>test</Button>
    </div>
  );
};

API Reference

styled

Builds a styled component

const Component = styled("div")("base", options);

Parameters

  1. div: tag type (HtmlElement)
  2. base: the base class name (string, string[] or null)
  3. options (optional)
    • variants: your variants schema
    • compoundVariants: variants based on a combination of previously defined variants
    • defaultVariants: set default values for previously defined variants

Returns

A JSX Element

react-cva's People

Contributors

g3root avatar

Stargazers

Roman avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.