Skip to content

Commit a518141

Browse files
committed
Introduce the component to visually separate and label sections within the settings sidebar navigation
1 parent e3d8e7d commit a518141

5 files changed

Lines changed: 104 additions & 19 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.line {
2+
height: 1px;
3+
background-color: var(--vscode-settings-headerBorder);
4+
margin: 0 var(--padding-8px);
5+
}
6+
7+
.text {
8+
color: var(--vscode-descriptionForeground);
9+
font-size: 0.9em;
10+
font-weight: 600;
11+
padding: 0 var(--padding-8px);
12+
margin-top: var(--padding-8px);
13+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import type { Meta, StoryObj } from '@storybook/react'
2+
import { NavigationDivider } from './NavigationDivider'
3+
4+
const meta: Meta<typeof NavigationDivider> = {
5+
component: NavigationDivider,
6+
decorators: [
7+
(Story) => (
8+
<div
9+
style={{
10+
width: '200px',
11+
padding: '1rem',
12+
backgroundColor: 'var(--vscode-sideBar-background)',
13+
color: 'var(--vscode-foreground)'
14+
}}
15+
>
16+
<Story />
17+
</div>
18+
)
19+
]
20+
}
21+
22+
export default meta
23+
type Story = StoryObj<typeof NavigationDivider>
24+
25+
export const Default: Story = {
26+
render: () => (
27+
<>
28+
<div>Item 1</div>
29+
<NavigationDivider />
30+
<div>Item 2</div>
31+
</>
32+
)
33+
}
34+
35+
export const WithText: Story = {
36+
render: () => (
37+
<>
38+
<div>Item 1</div>
39+
<NavigationDivider text="API Tools" />
40+
<div>Item 2</div>
41+
<div>Item 3</div>
42+
</>
43+
)
44+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import styles from './NavigationDivider.module.scss'
2+
import React from 'react'
3+
4+
type Props = {
5+
text?: string
6+
}
7+
8+
export const NavigationDivider: React.FC<Props> = ({ text }) => {
9+
if (!text) {
10+
return <div className={styles.line} />
11+
}
12+
13+
return <div className={styles.text}>{text}</div>
14+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './NavigationDivider'

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

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { useState, useRef, useEffect, useCallback } from 'react'
22
import { Layout } from '@ui/components/editor/settings/Layout'
33
import { NavigationItem } from '@ui/components/editor/settings/NavigationItem'
44
import { ModelProvidersSection } from './sections/ModelProvidersSection'
5+
import { NavigationDivider } from '@ui/components/editor/settings/NavigationDivider'
56
import { Item } from '@ui/components/editor/settings/Item'
67
import { ApiToolConfigurationSection } from './sections/ApiToolConfigurationSection'
78
import { dictionary } from '@shared/constants/dictionary'
@@ -21,19 +22,26 @@ type NavItem =
2122
| 'intelligent-update'
2223
| 'commit-messages'
2324

24-
const NAV_ITEMS_CONFIG: { id: NavItem; label: string }[] = [
25+
type NavConfigItem =
26+
| { type: 'item'; id: NavItem; label: string }
27+
| { type: 'divider'; text?: string }
28+
29+
const NAV_ITEMS_CONFIG: NavConfigItem[] = [
2530
{
31+
type: 'item',
2632
id: 'general',
2733
label: 'General'
2834
},
2935
{
36+
type: 'item',
3037
id: 'model-providers',
3138
label: dictionary.settings.MODEL_PROVIDERS_LABEL
3239
},
33-
{ id: 'edit-context', label: 'Edit Context' },
34-
{ id: 'code-completions', label: 'Code Completions' },
35-
{ id: 'intelligent-update', label: 'Intelligent Update' },
36-
{ id: 'commit-messages', label: 'Commit Messages' }
40+
{ type: 'divider', text: 'API Tools' },
41+
{ type: 'item', id: 'edit-context', label: 'Edit Context' },
42+
{ type: 'item', id: 'code-completions', label: 'Code Completions' },
43+
{ type: 'item', id: 'intelligent-update', label: 'Intelligent Update' },
44+
{ type: 'item', id: 'commit-messages', label: 'Commit Messages' }
3745
]
3846

3947
type Props = {
@@ -124,7 +132,10 @@ export const Home: React.FC<Props> = (props) => {
124132
[handle_stuck_change]
125133
)
126134

127-
const nav_item_ids = NAV_ITEMS_CONFIG.map((item) => item.id)
135+
const nav_item_ids = NAV_ITEMS_CONFIG.filter(
136+
(item): item is Extract<NavConfigItem, { type: 'item' }> =>
137+
item.type === 'item'
138+
).map((item) => item.id)
128139
const active_nav_item_id =
129140
nav_item_ids.filter((id) => stuck_sections.has(id)).pop() || nav_item_ids[0]
130141

@@ -185,19 +196,21 @@ export const Home: React.FC<Props> = (props) => {
185196
<Layout
186197
ref={scroll_container_ref}
187198
title={dictionary.settings.SETTINGS_TITLE}
188-
sidebar={
189-
<>
190-
{NAV_ITEMS_CONFIG.map(({ id, label }) => (
191-
<NavigationItem
192-
key={id}
193-
href={`#${id}`}
194-
label={label}
195-
is_active={id === active_nav_item_id}
196-
on_click={(e) => handle_nav_click(e, id)}
197-
/>
198-
))}
199-
</>
200-
}
199+
sidebar={NAV_ITEMS_CONFIG.map((item, i) => {
200+
if (item.type == 'divider') {
201+
return <NavigationDivider key={i} text={item.text} />
202+
}
203+
204+
return (
205+
<NavigationItem
206+
key={i}
207+
href={`#${item.id}`}
208+
label={item.label}
209+
is_active={item.id === active_nav_item_id}
210+
on_click={(e) => handle_nav_click(e, item.id)}
211+
/>
212+
)
213+
})}
201214
>
202215
<Section
203216
ref={(el) => (section_refs.current['general'] = el)}

0 commit comments

Comments
 (0)