Skip to content

Commit 33817e2

Browse files
committed
feat: add CommandBar component with keyboard shortcuts and navigation
1 parent 531ff5b commit 33817e2

File tree

6 files changed

+647
-17
lines changed

6 files changed

+647
-17
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import { useEffect, useState } from 'react'
2+
3+
import { Backdrop, KeyboardShortcut, SearchBar, useRegisterShortcut } from '@devtron-labs/devtron-fe-common-lib'
4+
5+
import { SHORT_CUTS } from './constants'
6+
7+
import './CommandBar.scss'
8+
9+
const CommandBar = () => {
10+
const [showCommandBar, setShowCommandBar] = useState(false)
11+
12+
const { registerShortcut, unregisterShortcut } = useRegisterShortcut()
13+
14+
const handleClose = () => {
15+
setShowCommandBar(false)
16+
}
17+
18+
const handleOpen = () => {
19+
setShowCommandBar(true)
20+
}
21+
22+
useEffect(() => {
23+
registerShortcut({
24+
keys: SHORT_CUTS.OPEN_COMMAND_BAR.keys,
25+
description: 'Open Command Bar',
26+
callback: handleOpen,
27+
})
28+
29+
return () => {
30+
unregisterShortcut(SHORT_CUTS.OPEN_COMMAND_BAR.keys)
31+
}
32+
}, [])
33+
34+
if (!showCommandBar) {
35+
return null
36+
}
37+
38+
return (
39+
<Backdrop onEscape={handleClose}>
40+
<div className="dc__mxw-800 mxh-450 flexbox-col dc__overflow-auto dc__content-space br-12 bg__modal--primary command-bar__container w-100 h-100">
41+
<div className="flexbox-col dc__overflow-auto">
42+
<SearchBar
43+
inputProps={{
44+
autoFocus: true,
45+
placeholder: 'Search or jump to…',
46+
}}
47+
noBackgroundAndBorder
48+
/>
49+
50+
<div className="flexbox-col dc__overflow-auto border__primary--top pt-8" />
51+
</div>
52+
53+
<div className="flexbox dc__content-space dc__align-items-center px-20 py-12 border__primary--top bg__secondary">
54+
<div className="flexbox dc__gap-20 dc__align-items-center">
55+
<div className="flexbox dc__gap-8 dc__align-items-center">
56+
<KeyboardShortcut keyboardKey="ArrowUp" />
57+
<KeyboardShortcut keyboardKey="ArrowDown" />
58+
<span className="cn-9 fs-12 fw-4 lh-20">to navigate</span>
59+
</div>
60+
61+
<div className="flexbox dc__gap-8 dc__align-items-center">
62+
<KeyboardShortcut keyboardKey="Enter" />
63+
<span className="cn-9 fs-12 fw-4 lh-20">to select</span>
64+
</div>
65+
66+
<div className="flexbox dc__gap-8 dc__align-items-center">
67+
<KeyboardShortcut keyboardKey="Escape" />
68+
<span className="cn-9 fs-12 fw-4 lh-20">to close</span>
69+
</div>
70+
</div>
71+
72+
<div className="flexbox dc__gap-8 dc__align-items-center">
73+
<KeyboardShortcut keyboardKey=">" />
74+
<span className="cn-9 fs-12 fw-4 lh-20">to search actions</span>
75+
</div>
76+
</div>
77+
</div>
78+
</Backdrop>
79+
)
80+
}
81+
82+
export default CommandBar
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.command-bar {
2+
&__container {
3+
box-shadow: 0 1px 1px 0 rgba(0, 0, 0, 0.04), 0 2px 8px 0 rgba(0, 0, 0, 0.04), 0 3px 17px 0 rgba(0, 0, 0, 0.04), 0 4px 30px 0 rgba(0, 0, 0, 0.13), 0 8px 48px 0 rgba(0, 0, 0, 0.15);
4+
}
5+
}

0 commit comments

Comments
 (0)