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 🙏

© 2026 – Pkg Stats / Ryan Hefner

react-conditional-ui

v1.2.3

Published

A React component for building conditions using natural language input

Downloads

39

Readme

CI Release npm Coverage React License: MIT

Live Demo

Components

<ConditionalUI />

All-in-one component: input field + parsed condition output with editing and drag-and-drop.

import { ConditionalUI } from "react-conditional-ui";

<ConditionalUI
    fields={[
        { label: "Status", value: "status" },
        { label: "Age", value: "age", type: "number" },
    ]}
    onConditionsChange={(groups) => console.log(groups)}
/>;

<Input />

Standalone text input with fuzzy parsing, ghost autocomplete, and inline diagnostics.

import { Input } from "react-conditional-ui";

<Input fields={fields} operators={operators} onSubmit={(group) => console.log(group)} />;

Also supports a fully controlled mode via useConditionalInput:

import { Input, useConditionalInput } from "react-conditional-ui";

const { text, diagnostics, handleChange, handleSubmit, getSuggestion } = useConditionalInput({
    fields,
    onSubmit: handleGroup,
});

<Input
    value={text}
    onChange={handleChange}
    onSubmit={handleSubmit}
    getSuggestion={getSuggestion}
    diagnostics={diagnostics}
/>;

<Output />

Renders parsed condition groups as interactive chip rows with drag-and-drop reordering, chip editing via popovers, connector toggling, and entry removal.

Uncontrolled (manages its own state):

import { Output } from "react-conditional-ui";

<Output fields={fields} operators={operators} />;

Controlled:

<Output groups={groups} fields={fields} operators={operators} onGroupsChange={setGroups} />

Read-only (pass groups without onGroupsChange):

<Output groups={groups} fields={fields} operators={operators} />

Data Model

The <Input /> parser converts free-text into a ConditionGroup which the <Output /> renders. The full type hierarchy:

ConditionGroup
├── id: string
├── config?: GroupConfig
└── entries: ConditionEntry[]
        ├── id: string
        ├── connector: "and" | "or"
        └── condition: ParsedCondition
                ├── field:    { raw, value, label, isValid }
                ├── operator: { raw, value, label, isValid }
                └── value:    { raw, value, label, isValid, errorMessage?, matchedOption? }

For example, typing "status is active and age greater than 18" produces:

{
  "id": "g1",
  "entries": [
    {
      "id": "e1",
      "connector": "and",
      "condition": {
        "field":    { "raw": "status",       "value": "status", "label": "Status",       "isValid": true },
        "operator": { "raw": "is",           "value": "is",     "label": "is",           "isValid": true },
        "value":    { "raw": "active",       "value": "active", "label": "active",       "isValid": true }
      }
    },
    {
      "id": "e2",
      "connector": "and",
      "condition": {
        "field":    { "raw": "age",          "value": "age",    "label": "Age",          "isValid": true },
        "operator": { "raw": "greater than", "value": "gt",     "label": "greater than", "isValid": true },
        "value":    { "raw": "18",           "value": "18",     "label": "18",           "isValid": true }
      }
    }
  ]
}

This is the same object surfaced by onConditionsChange (as an array of groups), onSubmit on the <Input />, and useConditionalOutput's groups state.

Customization

Use these when you want to keep parser behavior but tailor UI/interaction details.

Component-level options

  • <ConditionalUI />: pass InputComponent and/or OutputComponent to replace either half of the default UI.
  • <Input />: customize placeholder, className, and style.
  • <Output />: customize defaultGroupConfig, className, and style.
  • All components support controlled patterns (value/onChange, groups/onGroupsChange) where applicable.
<ConditionalUI
    fields={fields}
    InputComponent={MyInput}
    OutputComponent={MyOutput}
    onConditionsChange={setGroups}
/>

Field-level parser options

FieldOption supports per-field parsing behavior:

  • operators: override allowed operators for a specific field
  • fieldValues: provide known values (useful for enum-like suggestions)
  • type: built-in value checks ("text" | "number" | "enum")
  • validateValue: custom validator (true or error string)

Group configuration

Each ConditionGroup can define config:

const group: ConditionGroup = {
    id: "1",
    entries: [...],
    config: {
        editable: false,
        removable: false,
        variant: "filled", // "outlined" (default) or "filled"
        label: "Filters",
    },
};

Set defaults for all groups with defaultGroupConfig on <Output />.

Hooks for custom UI

Use hooks when you want your own input/output rendering and state wiring.

useConditionDataProvider

Lowest-level API: returns parseComplexCondition, getSuggestion, getCompletions, diagnose, and provider. Use it when you already control input state and submit flow.

import { useConditionDataProvider, DEFAULT_OPERATORS } from "react-conditional-ui";

const { parseComplexCondition, getSuggestion, diagnose } = useConditionDataProvider({
    fields,
    operators: DEFAULT_OPERATORS,
});

const group = parseComplexCondition(raw);
const issues = diagnose(raw);

useConditionalInput

Input-state helper for controlled/uncontrolled text, submit validation, and diagnostics.

useConditionalOutput

Group-state + mutations without rendering <Output />; use this to build your own chips/list/table UI.

Includes helpers like addGroup, removeEntry, toggleConnector, updateCondition, updateGroupConfig, reordering/move helpers, and setGroups.

import { useConditionalOutput } from "react-conditional-ui";

const { groups, mutations } = useConditionalOutput({
    onGroupsChange: (groups) => console.log(groups),
});

mutations.addGroup(parsedGroup);

Styling

All components accept className and style props. Internal elements use rcui-* CSS classes that can be overridden.

Error handling

  • Parsing/validation issues are exposed as Diagnostic[] (start, end, message) via useConditionalInput and controlled <Input /> mode.
  • Managed input submit is fail-safe: invalid conditions are not emitted via onSubmit; diagnostics are shown instead.
  • Use useConditionDataProvider().diagnose(text) when building custom UIs and FieldOption.validateValue for field-specific validation rules.

Debug logging

The library uses the debug package. Logs are silent by default. Enable them to see how the fuzzy parser resolves fields, operators, and values:

// Browser — enable all library logs
localStorage.debug = "react-conditional-ui:*";

// Browser — specific namespace only
localStorage.debug = "react-conditional-ui:parser";
# Node / SSR
DEBUG=react-conditional-ui:* node app.js

Available namespaces: parser, match-engine.

Local development

npm install
npm run dev
npm run build
npm test
npm run lint
npm run format