Skip to content

Commit ed444f9

Browse files
committed
Refactor IconButton component to support labels and apply the with-label style, and update the UI layout in Home and MainView to include a dedicated settings icon button
1 parent 95f979a commit ed444f9

8 files changed

Lines changed: 103 additions & 37 deletions

File tree

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,20 @@
1919
background-color: var(--vscode-toolbar-hoverBackground);
2020
text-decoration: none;
2121
}
22+
23+
&.with-label {
24+
width: auto;
25+
justify-content: flex-start;
26+
gap: var(--padding-4px);
27+
padding-left: var(--padding-4px);
28+
}
29+
}
30+
31+
.icon-wrapper {
32+
display: flex;
33+
align-items: center;
34+
justify-content: center;
35+
width: 20px;
36+
height: 20px;
37+
flex-shrink: 0;
2238
}

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

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,44 @@ type Props = {
66
on_click?: (e: any) => void
77
href?: string
88
title?: string
9+
label?: string
910
}
1011

1112
export const IconButton: React.FC<Props> = (props) => {
13+
const icon_element = (
14+
<span className={styles['icon-wrapper']}>
15+
<span className={cn('codicon', `codicon-${props.codicon_icon}`)} />
16+
</span>
17+
)
18+
19+
const label_element = props.label && <span>{props.label}</span>
20+
1221
if (props.href) {
1322
return (
1423
<a
1524
href={props.href}
16-
className={styles['icon-button']}
25+
className={cn(styles['icon-button'], {
26+
[styles['with-label']]: !!props.label
27+
})}
1728
title={props.title}
1829
target="_blank"
1930
rel="noopener noreferrer"
2031
>
21-
<span className={cn('codicon', `codicon-${props.codicon_icon}`)} />
32+
{label_element}
33+
{icon_element}
2234
</a>
2335
)
2436
} else {
2537
return (
2638
<button
27-
className={styles['icon-button']}
39+
className={cn(styles['icon-button'], {
40+
[styles['with-label']]: !!props.label
41+
})}
2842
onClick={props.on_click}
2943
title={props.title}
3044
>
31-
<span className={cn('codicon', `codicon-${props.codicon_icon}`)} />
45+
{label_element}
46+
{icon_element}
3247
</button>
3348
)
3449
}

‎packages/vscode/package.json‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -463,17 +463,12 @@
463463
{
464464
"command": "codeWebChat.openRepository",
465465
"when": "view == codeWebChatView",
466-
"group": "navigation@1"
467-
},
468-
{
469-
"command": "codeWebChat.feedback",
470-
"when": "view == codeWebChatView",
471466
"group": "navigation@2"
472467
},
473468
{
474-
"command": "codeWebChat.settings",
469+
"command": "codeWebChat.feedback",
475470
"when": "view == codeWebChatView",
476-
"group": "navigation@3"
471+
"group": "navigation@1"
477472
}
478473
],
479474
"view/item/context": [

‎packages/vscode/src/views/panel/frontend/Home/Home.module.scss‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,18 @@
88
.header {
99
display: flex;
1010
align-items: center;
11+
justify-content: space-between;
1112
gap: var(--padding-4px);
1213
width: 100%;
1314
padding: var(--padding-5px) var(--padding-12px) var(--padding-6px)
1415
var(--padding-12px);
1516

17+
&__left {
18+
display: flex;
19+
align-items: center;
20+
gap: var(--padding-4px);
21+
}
22+
1623
&__home {
1724
display: flex;
1825
align-items: center;

‎packages/vscode/src/views/panel/frontend/Home/Home.tsx‎

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@ import { Donations } from '@ui/components/editor/panel/Donations'
66
import { Icon } from '@ui/components/editor/common/Icon'
77
import { use_latest_donations } from './hooks/latest-donations-hook'
88
import cn from 'classnames'
9+
import { IconButton } from '@ui/components/editor/panel/IconButton'
10+
import { post_message } from '../utils/post_message'
11+
import { FrontendMessage } from '@/views/panel/types/messages'
912

1013
type Props = {
14+
vscode: any
1115
is_active: boolean
1216
on_new_chat: () => void
1317
on_api_call: () => void
@@ -26,13 +30,28 @@ export const Home: React.FC<Props> = (props) => {
2630
has_more
2731
} = use_latest_donations(props.is_active, props.are_donations_visible)
2832

33+
const handle_settings_click = () => {
34+
post_message(props.vscode, {
35+
command: 'EXECUTE_COMMAND',
36+
command_id: 'codeWebChat.settings'
37+
} as FrontendMessage)
38+
}
39+
2940
return (
3041
<div className={styles.container}>
3142
<div className={styles['header']}>
32-
<div className={styles['header__home']}>
33-
<span className="codicon codicon-home" />
43+
<div className={styles['header__left']}>
44+
<div className={styles['header__home']}>
45+
<span className="codicon codicon-home" />
46+
</div>
47+
<span className={styles['header__text']}>Home</span>
3448
</div>
35-
<span className={styles['header__text']}>Home</span>
49+
<IconButton
50+
codicon_icon="settings-gear"
51+
on_click={handle_settings_click}
52+
title="Settings"
53+
label="Settings"
54+
/>
3655
</div>
3756

3857
<Scrollable>

‎packages/vscode/src/views/panel/frontend/Main/MainView/MainView.module.scss‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@
5858

5959
&__right {
6060
flex: 1;
61+
display: flex;
62+
align-items: center;
63+
64+
&__dropdown {
65+
width: 100%;
66+
}
6167
}
6268
}
6369

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

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ export const MainView: React.FC<Props> = (props) => {
153153

154154
const container_width = container_ref.current.offsetWidth
155155
const header_left_width = header_left_ref.current.offsetWidth
156-
const calculated_width = container_width - header_left_width - 36
156+
const calculated_width = container_width - header_left_width - 36 - 26 // 26 is for settings button and gap
157157

158158
set_dropdown_max_width(calculated_width)
159159
}
@@ -288,28 +288,35 @@ export const MainView: React.FC<Props> = (props) => {
288288
</div>
289289

290290
<div className={styles.header__right} ref={dropdown_container_ref}>
291-
{props.home_view_type == HOME_VIEW_TYPES.WEB && (
292-
<UiDropdown
293-
options={Object.entries(web_mode_labels).map(
294-
([value, label]) => ({ value: value as WebMode, label })
295-
)}
296-
selected_value={props.web_mode}
297-
on_change={props.on_web_mode_change}
298-
footer={dropdown_footer}
299-
max_width={dropdown_max_width}
300-
/>
301-
)}
302-
{props.home_view_type == HOME_VIEW_TYPES.API && (
303-
<UiDropdown
304-
options={Object.entries(api_mode_labels).map(
305-
([value, label]) => ({ value: value as ApiMode, label })
306-
)}
307-
selected_value={props.api_mode}
308-
on_change={props.on_api_mode_change}
309-
footer={dropdown_footer}
310-
max_width={dropdown_max_width}
311-
/>
312-
)}
291+
<div className={styles.header__right__dropdown}>
292+
{props.home_view_type == HOME_VIEW_TYPES.WEB && (
293+
<UiDropdown
294+
options={Object.entries(web_mode_labels).map(
295+
([value, label]) => ({ value: value as WebMode, label })
296+
)}
297+
selected_value={props.web_mode}
298+
on_change={props.on_web_mode_change}
299+
footer={dropdown_footer}
300+
max_width={dropdown_max_width}
301+
/>
302+
)}
303+
{props.home_view_type == HOME_VIEW_TYPES.API && (
304+
<UiDropdown
305+
options={Object.entries(api_mode_labels).map(
306+
([value, label]) => ({ value: value as ApiMode, label })
307+
)}
308+
selected_value={props.api_mode}
309+
on_change={props.on_api_mode_change}
310+
footer={dropdown_footer}
311+
max_width={dropdown_max_width}
312+
/>
313+
)}
314+
</div>
315+
<UiIconButton
316+
codicon_icon="settings-gear"
317+
on_click={() => props.on_quick_action_click('codeWebChat.settings')}
318+
title="Settings"
319+
/>
313320
</div>
314321
</div>
315322
<Scrollable scroll_to_top_key={scroll_to_top_key}>

‎packages/vscode/src/views/panel/frontend/Panel.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,7 @@ export const Panel = () => {
406406
})}
407407
>
408408
<Home
409+
vscode={vscode}
409410
is_active={active_view == 'home'}
410411
on_new_chat={() => {
411412
set_active_view('main')

0 commit comments

Comments
 (0)