@klass/react
TypeScript icon, indicating that this package has built-in type declarations

3.4.11 • Public • Published

klass

license version size size

klass react

Introduction

Class variant utility for React.

Installation

npm install @klass/core @klass/react
# or
yarn add @klass/core @klass/react
# or
pnpm add @klass/core @klass/react
# or
bun add @klass/core @klass/react

Usage

import { klassed, reklassed } from "@klass/react";

const Button = klassed(
  "button",
  {
    base: "inline-flex items-center justify-center rounded-md outline-none",
    variants: {
      color: {
        default: "bg-neutral-700 text-white",
        primary: "bg-indigo-700 text-white",
        secondary: "bg-orange-700 text-white",
      },
      size: {
        sm: "px-3 py-0.5 h-7 text-sm font-medium",
        md: "px-4 py-1 h-8 text-base font-medium",
        lg: "px-5 py-1.5 h-9 text-lg font-semibold",
      },
      block: {
        true: "w-full",
      },
      // "class" variant are not allowed
      // "className" variant are not allowed
    },
    defaultVariants: {
      color: "default",
      size: "md",
    },
  },
  {
    // default props
    dp: {
      type: "button",
    },
  }
);

const Box = reklassed("div", {
  conditions: {
    base: "",
    sm: "sm:",
    md: "md:",
    lg: "lg:",
    xl: "xl:",
    "2xl": "2xl:",
  },
  defaultCondition: "base",
  variants: {
    m: {
      "0": "m-0",
      "1": "m-1",
      "2": "m-2",
      "3": "m-3",
      "4": "m-4",
      "5": "m-5",
      "6": "m-6",
      "7": "m-7",
      "8": "m-8",
    },
    p: {
      "0": "p-0",
      "1": "p-1",
      "2": "p-2",
      "3": "p-3",
      "4": "p-4",
      "5": "p-5",
      "6": "p-6",
      "7": "p-7",
      "8": "p-8",
    },
  },
});

const App = () => {
  return (
    <Box m={{ base: "1", md: "2" }} p="2">
      <Box as="section">
        <Button color="primary" block>
          Primary Block Button
        </Button>
      </Box>

      <Box as="section">
        <Button as="a" color="secondary">
          Secondary Anchor Button
        </Button>
      </Box>
    </Box>
  );
};

export default App;

Documentation

docs

Authors

github

License

MIT License

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
3.4.11437latest
4.0.0-next.283next

Version History

VersionDownloads (Last 7 Days)Published
4.0.0-next.283
4.0.0-next.270
4.0.0-next.260
4.0.0-next.2510
4.0.0-next.240
4.0.0-next.230
4.0.0-next.220
4.0.0-next.210
4.0.0-next.200
4.0.0-next.190
4.0.0-next.180
4.0.0-next.170
4.0.0-next.160
4.0.0-next.150
4.0.0-next.140
4.0.0-next.130
4.0.0-next.120
4.0.0-next.110
4.0.0-next.100
4.0.0-next.92
4.0.0-next.80
4.0.0-next.70
4.0.0-next.60
4.0.0-next.50
4.0.0-next.40
4.0.0-next.30
4.0.0-next.20
4.0.0-next.10
4.0.0-next.00
3.4.11437
3.4.100
3.4.90
3.4.829
3.4.70
3.4.60
3.4.50
3.3.50
3.3.40
3.3.30
3.0.00
2.0.60
2.0.50
2.0.40
2.0.30
2.0.20
2.0.10
2.0.00
1.4.00
1.3.10
1.3.00
1.2.00
1.0.30
1.0.20
1.0.10
1.0.00
0.8.10
0.8.00
0.7.00
0.6.00
0.5.30
0.5.20
0.5.10
0.5.00
0.4.10
0.4.00
0.3.00
0.2.30
0.2.20
0.2.10
0.2.00
0.0.00

Package Sidebar

Install

npm i @klass/react

Weekly Downloads

481

Version

3.4.11

License

MIT

Unpacked Size

12.2 kB

Total Files

9

Last publish

Collaborators

  • flamrdevs