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) => {
},
},
},
},
},
};
const update = input({
command: rootCommand,
onUpdate: (updates) => {
},
});
update({ value: 'o', index: 1 });
update({ value: 'open s', index: 6 });
When the input matches a command with a run
function, the onUpdate
callback will include a refrence to it.
const update = input({
command: rootCommand,
onUpdate: (updates) => {
},
});
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.