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

classifyx

v1.1.0

Published

🎨 ClassifyX 🎨 : Your Ultimate CSS Class Manager! Simplify styling in JavaScript/TypeScript with dynamic class generation, conditional styling, and more. Seamlessly integrate with CSS Frameworks, support TypeScript, and enjoy automatic camelCase conversi

Downloads

31

Readme

Features

  • Dynamic Class Generation: Easily generate class names based on conditions, values, and configurations.
  • TypeScript Support: Fully typed with TypeScript for improved development experience.
  • Conditional Classes: Apply classes conditionally based on boolean values.
  • Prefixing: Add prefixes to all generated class names for namespacing or styling consistency.
  • CSS Module Support: Integrate seamlessly with CSS modules for modular styling.
  • Automatic CamelCase Conversion: Convert kebab-case class names to camelCase for JavaScript/TypeScript conventions.
  • Unique Classes: Automatically remove duplicate classes for cleaner and more efficient styling.
  • Toggle Classes: Conditionally toggle classes based on boolean conditions.
  • Server-Side Rendering (SSR) Support: Designed to work well with server-side rendering environments.
  • Nested Arrays and Objects Support: Handle nested arrays and objects to build complex class name structures.
  • Inline Boolean Expressions: Easily include class names based on inline boolean expressions.

Installation

npm

npm install classifyx

bun

bun install classifyx

yarn

yarn install classifyx

pnpm

pnpm install classifyx

Usage

import React from "react";
import ClassifyX from "classifyx";
import styles from "./path/to/your/cssModule.module.css";

const MyComponent = ({ isActive, isPrimary, isLarge, isDisabled, variant }) => {
  return (
    <div>
      {/* Basic Usage */}
      <div className={ClassifyX("box", "bordered", "rounded")}>
        Hello, World!
      </div>

      {/* Conditional Classes */}
      <button className={ClassifyX("button", { active: isActive })}>
        {isActive ? "Active Button" : "Inactive Button"}
      </button>

      {/* Toggling Classes */}
      <div className={ClassifyX.toggle("box", isPrimary, "primary")}>
        {isPrimary ? "Primary Box" : "Default Box"}
      </div>

      {/* Prefixing Classes */}
      <div className={ClassifyX.prefix("section", "dark", "wide")}>
        Prefixed Section
      </div>

      {/* Using CSS Modules */}
      <button className={ClassifyX.cssModule(styles, "button", "primary")}>
        Styled Button
      </button>

      {/* Conditional Inline Expressions */}
      <button
        className={ClassifyX(
          "button",
          ClassifyX.conditionalClass(isPrimary && isLarge, "large"),
          ClassifyX.conditionalClass(isDisabled, "disabled")
        )}
      >
        Click me
      </button>

      {/* Unique Classes */}
      <div className={ClassifyX.unique("box", "bordered", "box", "rounded")}>
        Unique Classes
      </div>

      {/* Concatenating Classes */}
      <div>{ClassifyX.concat("box", "bordered", "rounded")}</div>

      {/* Checking if Classes Exist */}
      {ClassifyX.has("box", "bordered") ? (
        <p>Classes exist!</p>
      ) : (
        <p>Classes do not exist!</p>
      )}

      {/* Combining Multiple Features */}
      <button
        className={ClassifyX(
          "button",
          "primary",
          ClassifyX.prefix("btn", "large", { disabled: isDisabled }),
          ClassifyX.cssModule(styles, "custom", "module")
        )}
      >
        Click me
      </button>

      {/* Dynamic Component Styling */}
      <div className={ClassifyX("card", variant === "featured" && "featured")}>
        <h2>Title</h2>
        <p>Description goes here</p>
      </div>
    </div>
  );
};

export default MyComponent;

Super Complex scenarios :

Example 1 :

// Suppose you have a dynamic application with various data sources, and you want to apply conditional styling to a component based on external data. The styling rules are complex and depend on multiple factors. ClassifyX can help manage the dynamic class names.

import React from "react";
import ClassifyX from "classifyx";

const ComplexStylingComponent = ({ data }) => {
  const shouldHighlight = data.some((item) => item.priority === "high");
  const shouldShowDetails = data.length > 5;

  return (
    <div
      className={ClassifyX(
        "complex-component",
        shouldHighlight && "highlight",
        shouldShowDetails && "show-details"
        // ... other complex conditions
      )}
    >
      <h2>Title</h2>
      <ul>
        {data.map((item, index) => (
          <li key={index}>{item.label}</li>
        ))}
      </ul>
    </div>
  );
};

export default ComplexStylingComponent;

Example 2:

// Imagine you are building a sophisticated dashboard for a dynamic analytics application. This dashboard comprises various widgets, each serving a unique purpose, such as charts, maps, and other data representations. The widgets are loaded dynamically from external sources, and the application needs to handle a multitude of complex styling scenarios.

// The dashboard has a highly interactive user interface, allowing users to toggle between different widgets, and even switch between a light and dark theme. Each widget has its own set of complex styling conditions based on its type, the amount of data it represents, and whether it's currently selected by the user.

// ClassifyX is employed to manage this complexity by dynamically applying class names to the widgets and the overall dashboard. For instance, it handles the dynamic switch between light and dark themes, highlights selected widgets, categorizes widgets based on their types (e.g., charts, maps), and even identifies widgets with a substantial amount of data for special styling.

// This example showcases the power of ClassifyX in addressing an ultra-complex scenario where the styling rules are intricate, dynamic, and contingent on multiple factors. It provides a clean and efficient way to handle the diverse styling needs of a modern, data-driven dashboard.

import React, { useState, useEffect } from "react";
import ClassifyX from "classifyx";

const UltraComplexDashboard = () => {
  const [widgets, setWidgets] = useState([]);
  const [selectedWidget, setSelectedWidget] = useState(null);
  const [darkMode, setDarkMode] = useState(false);

  useEffect(() => {
    // Simulate fetching dynamic widget data
    const fetchWidgets = async () => {
      const result = await fetch("https://api.example.com/widgets");
      const widgetData = await result.json();
      setWidgets(widgetData);
    };

    fetchWidgets();
  }, []);

  const handleWidgetClick = (widget) => {
    setSelectedWidget(widget);
  };

  const handleToggleDarkMode = () => {
    setDarkMode((prevDarkMode) => !prevDarkMode);
  };

  return (
    <div className={ClassifyX("dashboard", darkMode && "dark-mode")}>
      <div className="sidebar">
        <button
          className={ClassifyX("toggle-button", darkMode && "dark-mode-toggle")}
          onClick={handleToggleDarkMode}
        >
          Toggle Dark Mode
        </button>
        <ul>
          {widgets.map((widget) => (
            <li
              key={widget.id}
              className={ClassifyX(
                "widget",
                widget === selectedWidget && "selected-widget",
                widget.type === "chart" && "chart-widget",
                widget.type === "map" && "map-widget",
                widget.data.length > 100 && "large-data-widget"
                // ... other complex conditions based on widget properties
              )}
              onClick={() => handleWidgetClick(widget)}
            >
              {widget.name}
            </li>
          ))}
        </ul>
      </div>
      <div className="main-content">
        {selectedWidget && (
          <div className="widget-details">
            <h2>{selectedWidget.name}</h2>
            <p>{selectedWidget.description}</p>
            {/* Render widget details based on type */}
            {selectedWidget.type === "chart" && (
              <div className="chart-container">Chart goes here</div>
            )}
            {selectedWidget.type === "map" && (
              <div className="map-container">Map goes here</div>
            )}
            {/* ... other widget types */}
          </div>
        )}
      </div>
    </div>
  );
};

export default UltraComplexDashboard;