Skip to content

Commit d5e76ba

Browse files
committed
Refactor dropdown menu item states and add rotation animation to prompt type button
- on alternate button, border right should be made of pseudoelement moved 0.5px to the left - in the dropdown menu, the currently selected prompt type should be highlighted
1 parent 4df22af commit d5e76ba

5 files changed

Lines changed: 38 additions & 25 deletions

File tree

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,11 @@
6363
gap: 8px;
6464
}
6565

66-
&:hover,
67-
&[data-selected='true'] {
66+
&[data-active='true'] {
67+
background-color: var(--vscode-list-inactiveSelectionBackground);
68+
}
69+
70+
&:hover {
6871
background-color: var(--vscode-list-activeSelectionBackground);
6972
color: var(--vscode-list-activeSelectionForeground);
7073
}

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

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ export namespace DropdownMenu {
77
label: string
88
shortcut?: string
99
on_click: () => void
10-
checked?: boolean
11-
is_selected?: boolean
10+
is_checked?: boolean
11+
is_active?: boolean
1212
}
1313

1414
export type Props = {
@@ -26,9 +26,6 @@ export namespace DropdownMenu {
2626
}
2727

2828
export const DropdownMenu: React.FC<DropdownMenu.Props> = (props) => {
29-
const [is_preselection_respected, set_is_preselection_respected] =
30-
useState<boolean>(true)
31-
3229
const dropdown_ref = useRef<HTMLDivElement>(null)
3330
const [anchor_style, set_anchor_style] = useState<React.CSSProperties>({})
3431

@@ -75,35 +72,28 @@ export const DropdownMenu: React.FC<DropdownMenu.Props> = (props) => {
7572

7673
if (props.anchor_ref && !props.is_open) return null
7774

78-
const has_any_checked = props.items.some((item) => item.checked)
75+
const has_any_checked = props.items.some((item) => item.is_checked)
7976

8077
const content = (
8178
<div className={styles.content}>
8279
{props.info && <div className={styles.header}>{props.info}</div>}
8380
{props.items.map((item, index) => {
84-
const is_selected = item.is_selected && is_preselection_respected
85-
const should_underline =
86-
props.underline_non_selected_items && !is_selected
87-
8881
return (
8982
<div
9083
key={index}
9184
className={styles.item}
9285
onClick={item.on_click}
93-
data-selected={is_selected}
94-
onMouseEnter={() => {
95-
set_is_preselection_respected(false)
96-
}}
86+
data-active={item.is_active}
9787
>
9888
<div className={styles.item__left}>
9989
{has_any_checked && (
10090
<span
10191
className="codicon codicon-check"
102-
style={{ visibility: item.checked ? 'visible' : 'hidden' }}
92+
style={{ visibility: item.is_checked ? 'visible' : 'hidden' }}
10393
/>
10494
)}
10595
<span>
106-
{should_underline ? (
96+
{props.underline_non_selected_items ? (
10797
<>
10898
<span className={styles.underlined}>
10999
{item.label.substring(0, 1)}

‎packages/ui/src/components/editor/panel/PromptTypeDropdown/PromptTypeDropdown.module.scss‎

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
@keyframes rotate-once {
2+
from {
3+
transform: rotate(0deg);
4+
}
5+
to {
6+
transform: rotate(180deg);
7+
}
8+
}
9+
110
.container {
211
position: absolute;
312
top: 0;
@@ -8,7 +17,7 @@
817
display: flex;
918
align-items: center;
1019
height: 24px;
11-
outline: 1px solid var(--cwc-border-color-dimmed);
20+
border: 1px solid var(--cwc-border-color-dimmed);
1221
border-radius: 4px;
1322
color: var(--vscode-foreground);
1423
width: 100%;
@@ -17,11 +26,11 @@
1726
overflow: hidden;
1827

1928
&:hover {
20-
outline-color: var(--cwc-border-color);
29+
border-color: var(--cwc-border-color);
2130
}
2231

2332
&--open {
24-
outline-color: var(--cwc-border-color);
33+
outline-color: var(--vscode-focusBorder) !important;
2534
}
2635

2736
&__alternate {
@@ -38,6 +47,12 @@
3847
font-size: 15px !important;
3948
}
4049

50+
&--rotating {
51+
> span {
52+
animation: rotate-once 0.4s ease-in-out;
53+
}
54+
}
55+
4156
&:focus {
4257
outline: none;
4358
}
@@ -74,8 +89,7 @@
7489
text-overflow: ellipsis;
7590
white-space: nowrap;
7691
flex-grow: 1;
77-
text-align: left;
78-
padding-left: 7px;
92+
padding-left: 8px;
7993
}
8094

8195
&__icon {

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export const PromptTypeDropdown = <T extends string>(
3030
) => {
3131
const [is_open, set_is_open] = useState(false)
3232
const [just_opened, set_just_opened] = useState(false)
33+
const [is_rotating, set_is_rotating] = useState(false)
3334
const container_ref = useRef<HTMLDivElement>(null)
3435
const opened_by_shortcut = useRef(false)
3536

@@ -112,11 +113,15 @@ export const PromptTypeDropdown = <T extends string>(
112113
onClick={(e) => {
113114
e.stopPropagation()
114115
if (props.on_alternate_click) {
116+
set_is_rotating(true)
115117
props.on_alternate_click()
116118
}
117119
}}
118-
className={styles.button__alternate}
120+
className={cn(styles.button__alternate, {
121+
[styles['button__alternate--rotating']]: is_rotating
122+
})}
119123
title="Toggle previous prompt type"
124+
onAnimationEnd={() => set_is_rotating(false)}
120125
>
121126
<span className={cn('codicon', 'codicon-sync')} />
122127
</button>
@@ -166,6 +171,7 @@ export const PromptTypeDropdown = <T extends string>(
166171
label: option.label,
167172
on_click: () => handle_select(option.value),
168173
is_selected: just_opened && option.value == props.selected_value,
174+
is_active: option.value == props.selected_value,
169175
shortcut: option.shortcut
170176
}))}
171177
underline_non_selected_items={opened_by_shortcut.current}

‎packages/ui/src/components/editor/panel/prompts/PromptField/PromptField.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,7 @@ export const PromptField: React.FC<PromptFieldProps> = (props) => {
728728
is_open={is_invocation_dropdown_open}
729729
items={[1, 2, 3].map((count) => ({
730730
label: `${count}×`,
731-
checked: count == props.invocation_count,
731+
is_checked: count == props.invocation_count,
732732
shortcut: is_mac ? `⌥X ${count}` : `Alt+X ${count}`,
733733
on_click: () => {
734734
props.on_invocation_count_change(count)

0 commit comments

Comments
 (0)