Implement a Dynamic Command Palette with Fuzzy Search
In a modern design and e-commerce platform like Livspace, efficient workflows are paramount. Users often need to quickly access features, navigate sections, or trigger actions without lifting their hands from the keyboard. A robust command palette significantly enhances productivity by providing a central, searchable interface for all available operations. This problem challenges you to build a dynamic command palette component that allows users to quickly find and execute commands using fuzzy search and keyboard navigation.
Your goal is to build a CommandPalette React component with the following functionalities:
Cmd+K (macOS) or Ctrl+K (Windows/Linux) is pressed, and disappear when Escape is pressed, or when clicking outside the palette, or when Cmd/Ctrl+K is pressed again.fuzzyMatch helper is provided, but you are free to enhance it.ArrowUp and ArrowDown keys. The currently selected command should be visually highlighted.Enter when a command is selected should execute that command.action (executes a predefined JavaScript function) or navigate (changes the current URL)./styles.css is provided to get you started.Cmd+K (or Ctrl+K) correctly toggles the command palette's visibility.Escape key closes the command palette.ArrowUp and ArrowDown keys navigate through the filtered list, and the active item is visually highlighted.Enter on a highlighted command executes its associated action or navigates to the specified URL.Constraints
fuzzyMatch utility function can be used as-is or improved upon. The primary focus is on integrating it correctly.window.location.href is sufficient for navigation commands).Loading editor...