Skip to content

Commit 11102b6

Browse files
committed
Move Scrollable component to common directory and implement shadow support for scrollable areas
- in `apps/editor/src/views/panel/frontend/Home/Home.tsx` handle trigger 'commit' ("Commited") - inline dropdown should have an optional param 'max height' - scrollable should be used in the dropdown when max height is set - move scrollable component to `packages/ui/src/components/editor/common` - in dropdown, the scrollbar doesn't stick to the edge - fix paddings - `packages/ui/src/components/editor/common/Scrollable/Scrollable.tsx` should accept prop top_shadow?:boolean, set as true for all component uses. - `packages/ui/src/components/editor/common/Scrollable/Scrollable.tsx` should accept prop bottom_shadow?:boolean, set as true in `packages/ui/src/components/editor/common/DropdownMenu/DropdownMenu.tsx` - style simplebar from within scrollable, not global styles
1 parent 59170b5 commit 11102b6

19 files changed

Lines changed: 167 additions & 114 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useState, useEffect } from 'react'
22
import styles from './Home.module.scss'
3-
import { Scrollable as UiScrollable } from '@ui/components/editor/panel/Scrollable'
3+
import { Scrollable as UiScrollable } from '@ui/components/editor/common/Scrollable'
44
import { Checkpoints as UiCheckpoints } from '@ui/components/editor/panel/Checkpoints'
55
import { ModeButton as UiModeButton } from '@ui/components/editor/panel/ModeButton'
66
import cn from 'classnames'
@@ -121,7 +121,7 @@ export const Home: React.FC<Props> = (props) => {
121121
/>
122122
</div>
123123

124-
<UiScrollable on_scroll={handle_scroll}>
124+
<UiScrollable on_scroll={handle_scroll} top_shadow>
125125
<div
126126
className={cn(styles.content, {
127127
[styles['content--sticky']]: is_mode_sticky

‎apps/editor/src/views/panel/frontend/Main/MainView/MainView.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { ResponseHistoryItem } from '@shared/types/response-history-item'
88
import { EditFormat } from '@shared/types/edit-format'
99
import { MODE, Mode } from '@/views/panel/types/main-view-mode'
1010
import { ApiPromptType, WebPromptType } from '@shared/types/prompt-types'
11-
import { Scrollable as UiScrollable } from '@ui/components/editor/panel/Scrollable'
11+
import { Scrollable as UiScrollable } from '@ui/components/editor/common/Scrollable'
1212
import { BrowserExtensionMessage as UiBrowserExtensionMessage } from '@ui/components/editor/panel/BrowserExtensionMessage'
1313
import { ApiConfiguration } from '@/views/panel/types/messages'
1414
import { use_last_choice_tooltip } from './hooks/use-last-choice-tooltip'
@@ -324,7 +324,7 @@ export const MainView: React.FC<Props> = (props) => {
324324
are_keyboard_shortcuts_disabled={props.are_keyboard_shortcuts_disabled}
325325
is_setup_complete={props.is_setup_complete}
326326
/>
327-
<UiScrollable scroll_to_top_key={props.scroll_reset_key}>
327+
<UiScrollable scroll_to_top_key={props.scroll_reset_key} top_shadow>
328328
<UiSeparator height={4} />
329329

330330
{is_in_find_relevant_files_prompt_type && (

‎apps/editor/src/views/panel/frontend/Main/MainView/components/Header/Header.tsx‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ export const Header: React.FC<Props> = (props) => {
6464
onClick={handle_heading_click}
6565
title={`Change mode (${is_mac ? '⌥Esc' : 'Alt+Esc'})`}
6666
>
67-
<span>
68-
{props.mode == MODE.WEB ? MODE.WEB : MODE.API}
69-
</span>
70-
{is_alt_pressed && <span className={styles['header__left__toggler__esc']}>esc</span>}
67+
<span>{props.mode == MODE.WEB ? MODE.WEB : MODE.API}</span>
68+
{is_alt_pressed && (
69+
<span className={styles['header__left__toggler__esc']}>esc</span>
70+
)}
7171
</button>
7272
</div>
7373

@@ -87,7 +87,7 @@ export const Header: React.FC<Props> = (props) => {
8787
)}
8888
selected_value={props.web_prompt_type}
8989
on_change={props.on_web_prompt_type_change}
90-
menu_max_width="calc(100vw - 52px)"
90+
menu_max_height="calc(100vh - 80px)"
9191
info={t('header.prompt-type')}
9292
title={
9393
is_mac
@@ -107,7 +107,7 @@ export const Header: React.FC<Props> = (props) => {
107107
)}
108108
selected_value={props.api_prompt_type}
109109
on_change={props.on_api_prompt_type_change}
110-
menu_max_width="calc(100vw - 60px)"
110+
menu_max_height="calc(100vh - 80px)"
111111
info={is_narrow_viewport ? undefined : t('header.prompt-type')}
112112
title={
113113
is_mac

‎apps/editor/src/views/settings/frontend/forms/EditModelProviderForm/EditModelProviderForm.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import styles from './EditModelProviderForm.module.scss'
33
import { Provider } from '@/views/settings/types/messages'
44
import { Field as UiField } from '@ui/components/editor/common/Field'
55
import { Input as UiInput } from '@ui/components/editor/common/Input'
6-
import { Scrollable as UiScrollable } from '@ui/components/editor/panel/Scrollable'
6+
import { Scrollable as UiScrollable } from '@ui/components/editor/common/Scrollable'
77
import { Fieldset as UiFieldset } from '@ui/components/editor/panel/Fieldset'
88
import { Toggler as UiToggler } from '@ui/components/editor/common/Toggler'
99

@@ -40,7 +40,7 @@ export const EditModelProviderForm: React.FC<Props> = (props) => {
4040
}, [name, base_url, api_key, is_api_key_cleared, extended_cache])
4141

4242
return (
43-
<UiScrollable>
43+
<UiScrollable top_shadow>
4444
<div className={styles.form}>
4545
<UiFieldset>
4646
<UiField label="Name" html_for="name">

‎apps/editor/src/views/shared/forms/EditApiConfigurationForm/EditApiConfigurationForm.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { ApiConfiguration } from '@/views/panel/types/messages'
44
import { Field as UiField } from '@ui/components/editor/common/Field'
55
import { Slider as UiSlider } from '@ui/components/editor/panel/Slider'
66
import { BackendMessage } from '@/views/panel/types/messages'
7-
import { Scrollable as UiScrollable } from '@ui/components/editor/panel/Scrollable'
7+
import { Scrollable as UiScrollable } from '@ui/components/editor/common/Scrollable'
88
import { Fieldset as UiFieldset } from '@ui/components/editor/panel/Fieldset'
99
import { QuickPickButton as UiQuickPickButton } from '@ui/components/editor/common/QuickPickButton'
1010
import { TextButton as UiTextButton } from '@ui/components/editor/common/TextButton'
@@ -63,7 +63,7 @@ export const EditApiConfigurationForm: React.FC<Props> = (props) => {
6363
}, [])
6464

6565
return (
66-
<UiScrollable>
66+
<UiScrollable top_shadow>
6767
<div className={styles.form}>
6868
<UiFieldset>
6969
<UiField label="Model Provider" html_for="model-provider">

‎apps/editor/src/views/shared/forms/EditWebConfigurationForm/EditWebConfigurationForm.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { Input as UiInput } from '@ui/components/editor/common/Input'
88
import { Textarea as UiTextarea } from '@ui/components/editor/common/Textarea'
99
import { BackendMessage } from '@/views/panel/types/messages'
1010
import { PresetOption as UiPresetOption } from '@ui/components/editor/panel/PresetOption'
11-
import { Scrollable as UiScrollable } from '@ui/components/editor/panel/Scrollable'
11+
import { Scrollable as UiScrollable } from '@ui/components/editor/common/Scrollable'
1212
import { Fieldset as UiFieldset } from '@ui/components/editor/panel/Fieldset'
1313
import { QuickPickButton as UiQuickPickButton } from '@ui/components/editor/common/QuickPickButton'
1414
import { TextButton as UiTextButton } from '@ui/components/editor/common/TextButton'
@@ -194,7 +194,7 @@ export const EditWebConfigurationForm: React.FC<Props> = (props) => {
194194
}, [reasoning_effort, supported_reasoning_efforts])
195195

196196
return (
197-
<UiScrollable>
197+
<UiScrollable top_shadow>
198198
<div className={styles.form}>
199199
<UiFieldset>
200200
{chatbot && (

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,14 @@
1313
border-radius: 8px;
1414
border: 1px solid var(--cwc-border-color-dimmed);
1515
box-shadow: 0 0 8px 2px var(--vscode-widget-shadow);
16-
padding: 4px;
16+
overflow: hidden;
1717
}
1818
}
1919

20+
.content {
21+
padding: 4px;
22+
}
23+
2024
.header {
2125
padding: 0 6px 4px 6px;
2226
font-size: 12px;

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

Lines changed: 66 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { useState } from 'react'
2+
import { Scrollable } from '../Scrollable'
23
import styles from './DropdownMenu.module.scss'
34

45
export namespace DropdownMenu {
@@ -14,6 +15,7 @@ export namespace DropdownMenu {
1415
items: Item[]
1516
underline_non_selected_items?: boolean
1617
max_width?: number | string
18+
max_height?: number | string
1719
info?: string
1820
}
1921
}
@@ -24,53 +26,73 @@ export const DropdownMenu: React.FC<DropdownMenu.Props> = (props) => {
2426

2527
const has_any_checked = props.items.some((item) => item.checked)
2628

27-
return (
28-
<div className={styles.menu} style={{ maxWidth: props.max_width }}>
29-
<div className={styles.menu__inner}>
30-
{props.info && <div className={styles.header}>{props.info}</div>}
31-
{props.items.map((item, index) => {
32-
const is_selected = item.is_selected && is_preselection_respected
33-
const should_underline =
34-
props.underline_non_selected_items && !is_selected
29+
const content = (
30+
<div className={styles.content}>
31+
{props.info && <div className={styles.header}>{props.info}</div>}
32+
{props.items.map((item, index) => {
33+
const is_selected = item.is_selected && is_preselection_respected
34+
const should_underline =
35+
props.underline_non_selected_items && !is_selected
3536

36-
return (
37-
<div
38-
key={index}
39-
className={styles.item}
40-
onClick={item.on_click}
41-
data-selected={is_selected}
42-
onMouseEnter={() => {
43-
set_is_preselection_respected(false)
44-
}}
45-
>
46-
<div className={styles.item__left}>
47-
{has_any_checked && (
48-
<span
49-
className="codicon codicon-check"
50-
style={{ visibility: item.checked ? 'visible' : 'hidden' }}
51-
/>
52-
)}
53-
<span>
54-
{should_underline ? (
55-
<>
56-
<span className={styles.underlined}>
57-
{item.label.substring(0, 1)}
58-
</span>
59-
{item.label.substring(1)}
60-
</>
61-
) : (
62-
item.label
63-
)}
64-
</span>
65-
</div>
66-
{item.shortcut && (
67-
<div className={styles.item__right}>
68-
<span className={styles.shortcut}>{item.shortcut}</span>
69-
</div>
37+
return (
38+
<div
39+
key={index}
40+
className={styles.item}
41+
onClick={item.on_click}
42+
data-selected={is_selected}
43+
onMouseEnter={() => {
44+
set_is_preselection_respected(false)
45+
}}
46+
>
47+
<div className={styles.item__left}>
48+
{has_any_checked && (
49+
<span
50+
className="codicon codicon-check"
51+
style={{ visibility: item.checked ? 'visible' : 'hidden' }}
52+
/>
7053
)}
54+
<span>
55+
{should_underline ? (
56+
<>
57+
<span className={styles.underlined}>
58+
{item.label.substring(0, 1)}
59+
</span>
60+
{item.label.substring(1)}
61+
</>
62+
) : (
63+
item.label
64+
)}
65+
</span>
7166
</div>
72-
)
73-
})}
67+
{item.shortcut && (
68+
<div className={styles.item__right}>
69+
<span className={styles.shortcut}>{item.shortcut}</span>
70+
</div>
71+
)}
72+
</div>
73+
)
74+
})}
75+
</div>
76+
)
77+
78+
return (
79+
<div className={styles.menu} style={{ maxWidth: props.max_width }}>
80+
<div className={styles.menu__inner}>
81+
{props.max_height ? (
82+
<Scrollable
83+
top_shadow
84+
bottom_shadow
85+
max_height={
86+
typeof props.max_height == 'number'
87+
? `${props.max_height}px`
88+
: props.max_height
89+
}
90+
>
91+
{content}
92+
</Scrollable>
93+
) : (
94+
content
95+
)}
7496
</div>
7597
</div>
7698
)
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
.scrollable {
2+
overflow: hidden;
3+
flex: 1;
4+
position: relative;
5+
height: 100%;
6+
7+
&--shadow::before {
8+
content: '';
9+
position: absolute;
10+
z-index: 1;
11+
height: 3px;
12+
width: 100%;
13+
opacity: 1;
14+
box-shadow: var(--vscode-scrollbar-shadow) 0 6px 6px -6px inset;
15+
top: 0;
16+
}
17+
18+
&--bottom-shadow::after {
19+
content: '';
20+
position: absolute;
21+
z-index: 1;
22+
height: 3px;
23+
width: 100%;
24+
opacity: 1;
25+
box-shadow: var(--vscode-scrollbar-shadow) 0 -6px 6px -6px inset;
26+
bottom: 0;
27+
}
28+
29+
:global {
30+
.simplebar-content {
31+
height: 100%;
32+
}
33+
34+
.simplebar-scrollable-y {
35+
width: 100%;
36+
}
37+
38+
.simplebar-scrollbar::before {
39+
background-color: var(--vscode-scrollbarSlider-background);
40+
width: 10px !important;
41+
border-radius: 0 !important;
42+
top: 0 !important;
43+
right: 0 !important;
44+
bottom: 0 !important;
45+
left: 0 !important;
46+
}
47+
48+
[data-simplebar]:hover .simplebar-scrollbar::before {
49+
opacity: 1 !important;
50+
}
51+
52+
.simplebar-track.simplebar-vertical {
53+
width: 10px;
54+
}
55+
}
56+
}

packages/ui/src/components/editor/panel/Scrollable/Scrollable.tsx renamed to packages/ui/src/components/editor/common/Scrollable/Scrollable.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,13 @@ type Props = {
1818
on_scroll?: (top: number) => void
1919
on_scrolled_change?: (is_scrolled: boolean) => void
2020
scroll_trigger?: number
21+
top_shadow?: boolean
22+
bottom_shadow?: boolean
2123
}
2224

2325
export const Scrollable = forwardRef<any, Props>((props, ref) => {
2426
const [has_top_shadow, set_has_top_shadow] = useState(false)
27+
const [has_bottom_shadow, set_has_bottom_shadow] = useState(false)
2528
const simplebar_ref = useRef<any>(null)
2629

2730
useImperativeHandle(ref, () => simplebar_ref.current)
@@ -48,7 +51,11 @@ export const Scrollable = forwardRef<any, Props>((props, ref) => {
4851
const { scrollTop, scrollHeight, clientHeight } = scroll_element
4952
const is_scrollable = scrollHeight > clientHeight
5053
const is_scrolled = is_scrollable && scrollTop > 0
54+
const is_scrolled_bottom =
55+
Math.ceil(scrollTop + clientHeight) >= scrollHeight
56+
5157
set_has_top_shadow(is_scrolled)
58+
set_has_bottom_shadow(is_scrollable && !is_scrolled_bottom)
5259
if (props.on_scroll) props.on_scroll(scrollTop)
5360
if (props.on_scrolled_change) props.on_scrolled_change(is_scrolled)
5461
}
@@ -86,7 +93,9 @@ export const Scrollable = forwardRef<any, Props>((props, ref) => {
8693
return (
8794
<div
8895
className={cn(styles.scrollable, {
89-
[styles['scrollable--shadow']]: has_top_shadow
96+
[styles['scrollable--shadow']]: props.top_shadow && has_top_shadow,
97+
[styles['scrollable--bottom-shadow']]:
98+
props.bottom_shadow && has_bottom_shadow
9099
})}
91100
>
92101
<SimpleBar

0 commit comments

Comments
 (0)