Giter Club home page Giter Club logo

reclsx's Introduction

Reclsx


NPM version NPM Weekly Downloads License

Dynamically classnames in React
Based on react/jsx-runtime
Using clsx

Example

example

Install

# via pnpm
$ pnpm i reclsx clsx

# via npm
$ npm i reclsx clsx

# via yarn
$ yarn add reclsx clsx

Usage

The constructing className conditionally using lukeed/clsx, For detailed API options, please refer to clsx

// basic
<div className="header navbar" /> // => <div class="header navbar"></div>

// conditionally
<div className={{ 'header': true, 'navbar': false, 'foo': true }} /> // => <div class="header foo"></div>
<div className={[ 'header', { 'navbar': false }, 'content', { 'foo': true } ]} /> // => <div class="header content foo"></div>
<div className={[ 'header', 'navbar', { 'navbar': false }, 'foo' ]} /> // => <div class="header foo"></div>

// dedupe
<div className={[ 'header', 'header', 'foo' ]} /> // => <div class="header foo"></div>

Configure

Use Reclsx's jsx functions instead of the default jsx-runtime when compiling JSX.

TypeScript support(Optional)

Make the Typescript compiler recognize Reclsx's className types in React.

{
  "compilerOptions": {
    "jsxImportSource": "reclsx"
  }
}

For Vite

// vite.config.js
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    react({
      jsxImportSource: "reclsx",
    }),
  ],
});

For Babel

Works with Webpack Rollup Taro etc.

// .babelrc
{
  "presets": [
    [
      "@babel/preset-react",
      {
        "runtime": "automatic",
        "importSource": "reclsx"
      }
    ]
  ]
}

For Esbuild

// via JS
require("esbuild").buildSync({
  entryPoints: ["app.jsx"],
  bundle: true,
  jsxFactory: "jsx",
  inject: ['./node_modules/reclsx/dist/jsx-runtime.js'],
  outfile: "out.js",
});

Support

@babel/preset-react >= v7.9.0
jsxRuntime: "automatic"

LICENSE MIT

Copyright © 2022 Daniel Zhao.

reclsx's People

Contributors

domisolo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 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.