Command palette

Putcode·16 hours ago
body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  place-items: center;
  background:
    linear-gradient(rgb(10 10 14 / 0.55), rgb(10 10 14 / 0.55)),
    repeating-linear-gradient(90deg, #e8e6e0 0 1px, #f4f3ef 1px 64px);
  color: #1a1b20;
  font: 14px/1.4 system-ui, sans-serif;
}

.palette {
  width: min(520px, 100% - 32px);
  overflow: hidden;
  border: 1px solid rgb(0 0 0 / 0.08);
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 40px 80px -30px rgb(0 0 0 / 0.55);
}

.palette__search {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid #ecebe6;
  color: #8a8d96;
}

.palette__search input {
  flex: 1;
  border: 0;
  color: #1a1b20;
  font: inherit;
  font-size: 1rem;
  outline: none;
}

kbd {
  padding: 2px 6px;
  border: 1px solid #e3e1db;
  border-radius: 6px;
  background: #faf9f7;
  color: #7c7f88;
  font: 11px/1.4 ui-monospace, monospace;
}

.palette__list {
  max-height: 300px;
  margin: 0;
  padding: 6px;
  overflow-y: auto;
  list-style: none;
}

.palette__group {
  padding: 10px 10px 4px;
  color: #8a8d96;
  font-size: 0.75rem;
  font-weight: 600;
}

.palette__item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 10px;
  cursor: pointer;
}

.palette__item kbd {
  margin-left: auto;
}

.palette__item[aria-selected="true"] {
  background: #f1f0ec;
}

.palette__icon {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border: 1px solid #e6e4de;
  border-radius: 7px;
  background: #fff;
  color: #55585f;
  font-size: 13px;
}

.palette__empty {
  margin: 0;
  padding: 24px;
  color: #8a8d96;
  text-align: center;
}

How to use it

Type to filter. Arrow keys move the highlight and Enter picks an item. It follows the combobox pattern: the input owns aria-activedescendant, and each result is an option in a listbox.