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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@notdutzi/kbar

v0.1.5

Published

kbar is a simple plug-n-play React component to add a fast, portable, and extensible command+k interface to your site.

Downloads

6

Readme

kbar

kbar is a simple plug-n-play React component to add a fast, portable, and extensible command+k interface to your site.

demo

Background

Command+k interfaces are used to create a web experience where any type of action users would be able to do via clicking can be done through a command menu.

With macOS's Spotlight and Linear's command+k experience in mind, kbar aims to be a simple abstraction to add a fast and extensible command+k menu to your site.

Features

  • Built in animations and fully customizable components
  • Keyboard navigation support; e.g. ctrl n / ctrl p for the navigation wizards
  • Keyboard shortcuts support for registering keystrokes to specific actions; e.g. hit t for Twitter
  • Nested actions enable creation of rich navigation experiences; e.g. hit backspace to navigate to the previous action
  • A simple data structure which enables anyone to easily build their own custom components

Usage

Have a fully functioning command menu for your site in minutes. First, install kbar.

npm install kbar

At the root of your site, import and wrap the site with a KBarProvider.

// app.tsx
import { KBarProvider } from "kbar";

return (
  <KBarProvider>
    <App />
  </KBarProvider>
);

kbar is built on top of actions. Actions define what to execute when a user selects it. Actions can have children which are just other actions.

We'll create a few static actions first. Static actions are actions with no external dependencies. Our example below sets the window.location.pathname, which does not rely on any external hook, for instance.

const actions = [
  {
    id: "blog",
    name: "Blog",
    shortcut: ["b"],
    keywords: "writing words",
    perform: () => (window.location.pathname = "blog"),
  },
  {
    id: "contact",
    name: "Contact",
    shortcut: ["c"],
    keywords: "email",
    perform: () => (window.location.pathname = "contact"),
  },
];

return (
  <KBarProvider actions={actions}>
    <App />
  </KBarProvider>
);

kbar exposes a few components which handle animations, keyboard events, default styles, etc. You can use them together like so:

import { 
  KBarProvider, 
  KBarPortal, 
  KBarPositioner, 
  KBarAnimator, 
  KBarSearch, 
  KBarResults 
} from "kbar";

<KBarProvider actions={actions}>
  <KBarPortal> // Renders the content outside the root node
    <KBarPositioner> // Centers the content
      <KBarAnimator> // Handles the show/hide and height animations
        <KBarSearch /> // Search input
        <KBarResults /> // Results renderer
      </KBarAnimator>
    </KBarPositioner>
  </KBarPortal>
  <MyApp />
</KBarProvider>;

Hit cmd+k (or ctrl+k) and you should see a primitive command menu. kbar allows you to have full control over all aspects of your command menu – refer to the docs to get an understanding of further capabilities. Excited to see what you build.

Contributing to kbar

Contributions are welcome!

New features

Please open a new issue so we can discuss prior to moving forward.

Bug fixes

Please open a new Pull Request for the given bug fix.

Nits and spelling mistakes

Please open a new issue for things like spelling mistakes and README tweaks – we will group the issues together and tackle them as a group. Please do not create a PR for it!