-
-
Notifications
You must be signed in to change notification settings - Fork 32
/
sampleChromeCommand.js
36 lines (33 loc) · 1.21 KB
/
sampleChromeCommand.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import React from "react";
import "./sampleChromeCommand.css";
export default function sampleChromeCommand(suggestion) {
const { name, highlight = [], category, shortcut } = suggestion;
// handle simple highlight when searching a single key
if (!Array.isArray(highlight)) {
return (
<div className="chrome-suggestion">
<span className={`chrome-category ${category}`}>{category}</span>
<span dangerouslySetInnerHTML={{ __html: highlight || name }} />
<kbd className="chrome-shortcut">{shortcut}</kbd>
</div>
);
}
// handle multiple highlights when searching multiple keys, see:
// https://github.com/farzher/fuzzysort#advanced-usage
// Note that we are passing "keys" to the fuzzysort options, ex:
// <CommandPalette
// commands={commands}
// options={{keys: ["name", "category"]}}
// renderCommand={sampleChromeCommand}
// />
return (
<div className="chrome-suggestion">
<span
dangerouslySetInnerHTML={{ __html: highlight[1] || category }}
className={`chrome-category ${category}`}
/>
<span dangerouslySetInnerHTML={{ __html: highlight[0] || name }} />
<kbd className="chrome-shortcut">{shortcut}</kbd>
</div>
);
}