@replit/clui-input
TypeScript icon, indicating that this package has built-in type declarations

0.0.18 • Public • Published

CLUI Input

@replit/clui-input implementes the logic for mapping text input to suggestions and a potential run function.

import input from '@replit/clui-input';

const rootCommand = {
  commands: {
    open: {
      commands: {
        sesame: {
          run: (args) => {
            /* do something */
          },
        },
      },
    },
  },
};

const update = input({
  command: rootCommand,
  onUpdate: (updates) => {
    /* Update #1: `updates.options` will be
     * [
     *   {
     *     "value": "open",
     *     "inputValue": "open",
     *     "searchValue": "o",
     *     "cursorTarget": 4
     *   }
     * ]
     */

    /* Update #2: `updates.options` will be
     * [
     *   {
     *     "value": "sesame",
     *     "inputValue": "open sesame",
     *     "searchValue": "s",
     *     "cursorTarget": 12
     *   }
     * ]
     */
  },
});

/* Update #1 */
update({ value: 'o', index: 1 });

/* Update #2 */
update({ value: 'open s', index: 6 });

When the input matches a command with a run function, the onUpdate callback will include a reference to it.

const update = input({
  command: rootCommand,
  onUpdate: (updates) => {
    // call or store reference to `updates.run` based on user interaction
  },
});

update({ value: 'open sesame', index: 6 });

@replit/clui-input a framework agnostic primitive that can be wrapped by more specific framework or application code (like a react hook). If using react you will most likey want to keep the result of onUpdate in a state object. For managing dropdown selection UX I highly recommend downshift.

Dependencies (0)

    Dev Dependencies (21)

    Package Sidebar

    Install

    npm i @replit/clui-input

    Weekly Downloads

    17,844

    Version

    0.0.18

    License

    MIT

    Unpacked Size

    97 kB

    Total Files

    29

    Last publish

    Collaborators

    • sareini
    • krishatreplit
    • mikewesthad
    • motzyball
    • juan.replit
    • ahulbert-replit
    • james-addison-replit
    • replitdstewart
    • ryanweingast
    • harryatreplit
    • theflowingsky
    • jonesit-replit
    • szymon_k
    • cdmistman
    • jackyzha0
    • jamesaustinreplit
    • lopezhoracio
    • bradymaddenreplit
    • ryantm
    • alexisreplit
    • ink404
    • brianpool
    • tobyho
    • brenoafb
    • masad-frost
    • lincolnreplit
    • stkenned
    • replitmatt
    • cbrewster
    • ltazmin_replit
    • moudy
    • schestakov
    • lhchavez
    • slmjkdbtl
    • lunaroyster