@vectara/vectara-ui
Version:
Vectara's design system, codified as a React and Sass component library
35 lines (34 loc) • 1.35 kB
TypeScript
import { KeyboardEvent } from "react";
type Args = {
storageKey?: string;
value: string;
setValue: (value: string) => void;
};
/**
* Cycles through previous submissions with UP/DOWN arrow keys.
*
* State machine for navigation (3 phases):
*
* idle — no navigation active.
* primed — first key press (UP/DOWN) consumed by native cursor movement.
* cycling — UP/DOWN keys walk through the history stack.
*
* Transitions on arrow key press:
*
* idle + empty input + UP → cycling (skip primed, start navigating immediately)
* idle + empty input + DOWN → idle (nothing to cycle to)
* idle + has text + UP/DN → primed (let native cursor move first)
* primed + same direction → cycling (second press enters history)
* primed + diff direction → primed (re-prime for the new direction)
* cycling + same direction → cycling (keep walking history)
* cycling + diff direction → primed (let native cursor adjust, re-prime)
*
* The composer calls reset() on any user edit and record() on submit, both of
* which return the machine to idle.
*/
export declare function useComposerHistory({ storageKey, value, setValue }: Args): {
handleKeyDown: (e: KeyboardEvent) => void;
record: (input: string) => void;
reset: () => void;
};
export {};