reclsx
TypeScript icon, indicating that this package has built-in type declarations

1.0.9 • Public • Published

Reclsx


NPM version NPM Weekly Downloads License

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

Example

example

Install

# via npm
$ npm i reclsx classnames

# via yarn
$ yarn add reclsx classnames

Usage

The constructing className conditionally using JedWatson/classnames, For detailed API options, please refer to classNames/dedupe

// 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.

Versions

Current Tags

Version History

Package Sidebar

Install

npm i reclsx

Weekly Downloads

157

Version

1.0.9

License

MIT

Unpacked Size

8.06 kB

Total Files

9

Last publish

Collaborators

  • danielzd