Skip to content

Commit 8bd20f3

Browse files
committed
Implement support for displaying keyboard shortcuts within the dropdown menu items
1 parent 202edcb commit 8bd20f3

4 files changed

Lines changed: 28 additions & 10 deletions

File tree

‎packages/ui/src/components/editor/common/DropdownMenu/DropdownMenu.module.scss‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,21 @@
2121
display: flex;
2222
justify-content: space-between;
2323
align-items: center;
24-
gap: 12px;
24+
gap: 8px;
2525
padding: 0 6px;
2626
height: 24px;
2727
cursor: pointer;
2828
color: var(--vscode-quickInput-foreground);
2929
white-space: nowrap;
3030
border-radius: 4px;
3131

32+
&__label {
33+
overflow: hidden;
34+
text-overflow: ellipsis;
35+
white-space: nowrap;
36+
37+
}
38+
3239
&:hover,
3340
&[data-selected='true'] {
3441
background-color: var(--vscode-list-activeSelectionBackground);

‎packages/ui/src/components/editor/common/DropdownMenu/DropdownMenu.tsx‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export namespace DropdownMenu {
1212
export type Props = {
1313
items: Item[]
1414
underline_non_selected_items?: boolean
15+
max_width?: number | string
1516
}
1617
}
1718

@@ -20,7 +21,7 @@ export const DropdownMenu: React.FC<DropdownMenu.Props> = (props) => {
2021
useState<boolean>(true)
2122

2223
return (
23-
<div className={styles.menu}>
24+
<div className={styles.menu} style={{ maxWidth: props.max_width }}>
2425
<div className={styles.menu__inner}>
2526
{props.items.map((item, index) => {
2627
const is_selected = item.is_selected && is_preselection_respected
@@ -37,7 +38,7 @@ export const DropdownMenu: React.FC<DropdownMenu.Props> = (props) => {
3738
set_is_preselection_respected(false)
3839
}}
3940
>
40-
<span>
41+
<span className={styles.item__label}>
4142
{should_underline ? (
4243
<>
4344
<span className={styles.underlined}>

‎packages/ui/src/components/editor/panel/Dropdown/Dropdown.tsx‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ export namespace Dropdown {
77
export type Option<T extends string> = {
88
value: T
99
label: string
10+
shortcut?: string
1011
}
1112

1213
export type Props<T extends string> = {
1314
options: Option<T>[]
1415
selected_value: T
1516
on_change: (value: T) => void
1617
max_width?: number
18+
menu_max_width?: number | string
1719
info?: string
1820
title?: string
1921
}
@@ -158,9 +160,11 @@ export const Dropdown = <T extends string>(props: Dropdown.Props<T>) => {
158160
items={props.options.map((option) => ({
159161
label: option.label,
160162
on_click: () => handle_select(option.value),
161-
is_selected: just_opened && option.value == props.selected_value
163+
is_selected: just_opened && option.value == props.selected_value,
164+
shortcut: option.shortcut,
162165
}))}
163166
underline_non_selected_items={opened_by_shortcut.current}
167+
max_width={props.menu_max_width}
164168
/>
165169
)}
166170
</div>

‎packages/vscode/src/views/panel/frontend/Main/MainView/components/Header/Header.tsx‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,15 @@ export const Header: React.FC<Props> = (props) => {
9292
<div className={styles.header__right__dropdown}>
9393
{props.mode == MODE.WEB && (
9494
<UiDropdown
95-
options={Object.entries(web_mode_labels).map(
96-
([value, label]) => ({ value: value as WebPromptType, label })
97-
)}
95+
options={Object.entries(web_mode_labels).map(([value, label]) => ({
96+
value: value as WebPromptType,
97+
label,
98+
shortcut: `${is_mac ? '⇧⌥' : 'Shift+Alt+'}${label.charAt(0)}`,
99+
}))}
98100
selected_value={props.web_prompt_type}
99101
on_change={props.on_web_prompt_type_change}
100102
max_width={dropdown_max_width}
103+
menu_max_width="calc(100vw - 52px)"
101104
info={is_narrow_viewport ? undefined : 'prompt type'}
102105
title={
103106
is_mac ? 'Change prompt type (⇧⌥)' : 'Change prompt type (Shift+Alt)'
@@ -106,12 +109,15 @@ export const Header: React.FC<Props> = (props) => {
106109
)}
107110
{props.mode == MODE.API && (
108111
<UiDropdown
109-
options={Object.entries(api_mode_labels).map(
110-
([value, label]) => ({ value: value as ApiPromptType, label })
111-
)}
112+
options={Object.entries(api_mode_labels).map(([value, label]) => ({
113+
value: value as ApiPromptType,
114+
label,
115+
shortcut: `${is_mac ? '⇧⌥' : 'Shift+Alt+'}${label.charAt(0)}`,
116+
}))}
112117
selected_value={props.api_prompt_type}
113118
on_change={props.on_api_prompt_type_change}
114119
max_width={dropdown_max_width}
120+
menu_max_width="calc(100vw - 60px)"
115121
info={is_narrow_viewport ? undefined : 'prompt type'}
116122
title={
117123
is_mac ? 'Change prompt type (⇧⌥)' : 'Change prompt type (Shift+Alt)'

0 commit comments

Comments
 (0)