Skip to content

Commit f154464

Browse files
committed
Add NavigationSection component and refactor settings sidebar navigation grouping
- inactive sections are dimmed. This is correct behavior. Should be propely wrapped in div, allowing hover control so that whole section ,when hovered, has opacity restored. ├── apps │ └── editor │ └── src │ └── views │ └── settings │ └── frontend │ ├── Home │ │ └── Home.tsx │ └── Settings.tsx └── packages └── ui └── src └── components └── editor └── settings ├── NavigationItemGroup │ ├── NavigationItemGroup.module.scss │ ├── NavigationItemGroup.tsx │ └── index.ts ├── NavigationItemSection │ ├── NavigationItemSection.module.scss │ ├── NavigationItemSection.tsx │ └── index.ts └── NavigationSection ├── NavigationSection.module.scss ├── NavigationSection.tsx └── index.ts
1 parent c9d85dc commit f154464

7 files changed

Lines changed: 73 additions & 50 deletions

File tree

‎apps/editor/src/views/settings/frontend/Home/Home.tsx‎

Lines changed: 38 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { useState, useRef, useEffect, useCallback, useMemo } from 'react'
22
import { Layout as UiLayout } from '@ui/components/editor/settings/Layout'
3+
import { NavigationSection as UiNavigationSection } from '@ui/components/editor/settings/NavigationSection'
34
import { NavigationItemSection as UiNavigationItemSection } from '@ui/components/editor/settings/NavigationItemSection'
45
import { NavigationItemGroup as UiNavigationItemGroup } from '@ui/components/editor/settings/NavigationItemGroup'
56
import { ApiConfigurationsSection } from './sections/ApiConfigurationsSection'
@@ -353,47 +354,50 @@ export const Home: React.FC<Props> = (props) => {
353354
<UiLayout
354355
ref={scroll_container_ref}
355356
title={t('sections.settings')}
356-
sidebar={NAV_ITEMS_CONFIG.map((item, i) => {
357-
let current_parent: NavItem | null = null
358-
for (let j = i; j >= 0; j--) {
357+
sidebar={(() => {
358+
const sections: {
359+
parent: NavConfigItem
360+
groups: NavConfigItem[]
361+
}[] = []
362+
363+
for (const item of NAV_ITEMS_CONFIG) {
359364
if (
360-
NAV_ITEMS_CONFIG[j].id.startsWith('section:') &&
361-
!NAV_ITEMS_CONFIG[j].id.includes(':group:')
365+
item.id.startsWith('section:') &&
366+
!item.id.includes(':group:')
362367
) {
363-
current_parent = NAV_ITEMS_CONFIG[j].id
364-
break
368+
sections.push({ parent: item, groups: [] })
369+
} else if (sections.length > 0) {
370+
sections[sections.length - 1].groups.push(item)
365371
}
366372
}
367-
const is_parent_active =
368-
current_parent === active_nav_item_id ||
369-
current_parent === active_parent_id
370373

371-
if (item.id.includes(':group:')) {
374+
return sections.map((section, i) => {
375+
const is_section_active =
376+
section.parent.id === active_nav_item_id ||
377+
section.parent.id === active_parent_id
378+
372379
return (
373-
<UiNavigationItemGroup
374-
key={i}
375-
href={`#${item.id}`}
376-
label={t(item.label)}
377-
is_active={item.id == active_nav_item_id}
378-
is_parent_active={is_parent_active}
379-
has_warning={get_has_warning(item.id)}
380-
on_click={(e) => handle_nav_click(e, item.id)}
381-
is_last={!NAV_ITEMS_CONFIG[i + 1]?.id.includes(':group:')}
382-
/>
380+
<UiNavigationSection key={i} is_active={is_section_active}>
381+
<UiNavigationItemSection
382+
label={t(section.parent.label)}
383+
is_active={is_section_active}
384+
has_warning={get_has_warning(section.parent.id)}
385+
/>
386+
{section.groups.map((group, j) => (
387+
<UiNavigationItemGroup
388+
key={j}
389+
href={`#${group.id}`}
390+
label={t(group.label)}
391+
is_active={group.id === active_nav_item_id}
392+
has_warning={get_has_warning(group.id)}
393+
on_click={(e) => handle_nav_click(e, group.id)}
394+
is_last={j === section.groups.length - 1}
395+
/>
396+
))}
397+
</UiNavigationSection>
383398
)
384-
}
385-
386-
return (
387-
<UiNavigationItemSection
388-
key={i}
389-
label={t(item.label)}
390-
is_active={
391-
item.id == active_nav_item_id || item.id == active_parent_id
392-
}
393-
has_warning={get_has_warning(item.id)}
394-
/>
395-
)
396-
})}
399+
})
400+
})()}
397401
>
398402
<GeneralSection
399403
ref={(el) => set_section_ref('section:general', el)}

‎packages/ui/src/components/editor/settings/NavigationItemGroup/NavigationItemGroup.module.scss‎

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,12 @@
88
color: var(--vscode-foreground);
99
text-decoration: none;
1010
cursor: pointer;
11-
transition:
12-
background-color var(--transition-duration-150),
13-
opacity var(--transition-duration-250);
11+
transition: background-color var(--transition-duration-150);
1412

1513
font-size: 13px;
1614
height: 26px;
1715
padding-left: 20px;
1816
position: relative;
19-
opacity: var(--dimmed-opacity);
2017

2118
&:hover {
2219
background-color: var(--cwc-bg-tertiary);
@@ -34,13 +31,8 @@
3431
opacity: 0.2;
3532
}
3633

37-
&--parent-active {
38-
opacity: 1;
39-
}
40-
4134
&--active {
4235
background-color: var(--cwc-bg-secondary);
43-
opacity: 1;
4436

4537
&:hover {
4638
background-color: var(--cwc-bg-secondary);

‎packages/ui/src/components/editor/settings/NavigationItemGroup/NavigationItemGroup.tsx‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ type Props = {
66
href: string
77
on_click: (e: React.MouseEvent<HTMLAnchorElement>) => void
88
is_active: boolean
9-
is_parent_active?: boolean
109
has_warning?: boolean
1110
is_last?: boolean
1211
}
@@ -16,7 +15,6 @@ export const NavigationItemGroup: React.FC<Props> = (props) => {
1615
<a
1716
href={props.href}
1817
className={cn(styles.container, {
19-
[styles['container--parent-active']]: props.is_parent_active,
2018
[styles['container--active']]: props.is_active,
2119
[styles['container--last']]: props.is_last
2220
})}

‎packages/ui/src/components/editor/settings/NavigationItemSection/NavigationItemSection.module.scss‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,7 @@
88
color: var(--vscode-textLink-foreground);
99
height: 32px;
1010
transition: background-color 0.1s;
11-
opacity: var(--dimmed-opacity);
1211
font-weight: 500;
13-
14-
&--active {
15-
opacity: 1;
16-
}
1712
}
1813

1914
.label {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.container {
2+
opacity: var(--dimmed-opacity);
3+
transition: opacity var(--transition-duration-250);
4+
display: flex;
5+
flex-direction: column;
6+
7+
&--active {
8+
opacity: 1;
9+
}
10+
11+
&:hover {
12+
opacity: 1;
13+
}
14+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import cn from 'classnames'
2+
import styles from './NavigationSection.module.scss'
3+
4+
type Props = {
5+
children: React.ReactNode
6+
is_active?: boolean
7+
}
8+
9+
export const NavigationSection: React.FC<Props> = (props) => {
10+
return (
11+
<div
12+
className={cn(styles.container, {
13+
[styles['container--active']]: props.is_active
14+
})}
15+
>
16+
{props.children}
17+
</div>
18+
)
19+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './NavigationSection'

0 commit comments

Comments
 (0)