Skip to content

Commit 3f8ad3c

Browse files
committed
Refactor Item component to use slot_right and slot_below props instead of slot_placement, remove max_rows_when_collapsed feature from Textarea, and update all usages accordingly
1 parent ec1426b commit 3f8ad3c

7 files changed

Lines changed: 134 additions & 102 deletions

File tree

‎packages/ui/src/components/editor/common/Textarea/Textarea.stories.tsx‎

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,3 @@ export const WithValue = () => {
3232
/>
3333
)
3434
}
35-
36-
export const WithMaxRowsWhenCollapsed = () => {
37-
const [value, set_value] = useState(
38-
'This is a long text that should be truncated when not focused.\nLine 2\nLine 3\nLine 4\nLine 5'
39-
)
40-
41-
return (
42-
<Textarea
43-
value={value}
44-
on_change={set_value}
45-
placeholder="Will be ignored because value is set"
46-
min_rows={1}
47-
max_rows={10}
48-
max_rows_when_collapsed={2}
49-
/>
50-
)
51-
}

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

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState } from 'react'
1+
import React from 'react'
22
import TextareaAutosize from 'react-textarea-autosize'
33
import styles from './Textarea.module.scss'
44

@@ -9,7 +9,6 @@ type Props = {
99
autofocus?: boolean
1010
min_rows?: number
1111
max_rows?: number
12-
max_rows_when_collapsed?: number
1312
on_change: (value: string) => void
1413
on_blur?: () => void
1514
on_key_down?: (e: React.KeyboardEvent<HTMLTextAreaElement>) => void
@@ -18,7 +17,6 @@ type Props = {
1817

1918
export const Textarea = React.forwardRef<HTMLTextAreaElement, Props>(
2019
(props, ref) => {
21-
const [has_been_focused, set_has_been_focused] = useState(!!props.autofocus)
2220
const internal_ref = React.useRef<HTMLTextAreaElement | null>(null)
2321

2422
const set_ref = React.useCallback(
@@ -52,18 +50,13 @@ export const Textarea = React.forwardRef<HTMLTextAreaElement, Props>(
5250
}
5351

5452
const handle_focus = (e: React.FocusEvent<HTMLTextAreaElement>) => {
55-
set_has_been_focused(true)
5653
props.onFocus?.(e)
5754
}
5855

5956
const handle_blur = (e: React.FocusEvent<HTMLTextAreaElement>) => {
6057
props.on_blur?.()
6158
}
6259

63-
const max_rows = has_been_focused
64-
? props.max_rows
65-
: (props.max_rows_when_collapsed ?? props.max_rows)
66-
6760
return (
6861
<TextareaAutosize
6962
id={props.id}
@@ -74,7 +67,7 @@ export const Textarea = React.forwardRef<HTMLTextAreaElement, Props>(
7467
className={styles.textarea}
7568
placeholder={props.placeholder}
7669
minRows={props.min_rows}
77-
maxRows={max_rows}
70+
maxRows={props.max_rows}
7871
onFocus={handle_focus}
7972
ref={set_ref}
8073
/>
Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
.container {
2+
display: flex;
3+
flex-direction: column;
4+
gap: 12px;
5+
padding: 12px;
6+
}
7+
8+
.main {
29
display: flex;
310
align-items: center;
411
justify-content: space-between;
512
gap: 16px;
6-
padding: 12px;
7-
8-
&--below {
9-
flex-direction: column;
10-
align-items: stretch;
11-
justify-content: flex-start;
12-
}
1313
}
1414

1515
.content {
@@ -18,6 +18,10 @@
1818
flex-direction: column;
1919
min-width: 0;
2020
gap: 2px;
21+
22+
&__right {
23+
flex-shrink: 0;
24+
}
2125
}
2226

2327
.title {
@@ -28,6 +32,6 @@
2832
color: var(--cwc-text-secondary);
2933
}
3034

31-
.slot {
32-
flex-shrink: 0;
35+
.below {
36+
width: 100%;
3337
}
Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
import styles from './Item.module.scss'
22
import React from 'react'
3-
import cn from 'classnames'
43

54
type Props = {
65
title: string
76
description: React.ReactNode
8-
slot: React.ReactNode
9-
slot_placement?: 'right' | 'below'
7+
slot_right?: React.ReactNode
8+
slot_below?: React.ReactNode
109
}
1110

1211
export const Item: React.FC<Props> = (props) => {
13-
const is_below = props.slot_placement == 'below'
14-
1512
return (
16-
<div
17-
className={cn(styles.container, {
18-
[styles['container--below']]: is_below
19-
})}
20-
>
21-
<div className={styles.content}>
22-
<div className={styles.title}>{props.title}</div>
23-
<div className={styles.description} style={{ whiteSpace: 'normal' }}>
24-
{props.description}
13+
<div className={styles.container}>
14+
<div className={styles.main}>
15+
<div className={styles.content}>
16+
<div className={styles.title}>{props.title}</div>
17+
<div className={styles.description} style={{ whiteSpace: 'normal' }}>
18+
{props.description}
19+
</div>
2520
</div>
21+
{props.slot_right && (
22+
<div className={styles.content__right}>{props.slot_right}</div>
23+
)}
2624
</div>
27-
<div className={styles.slot}>{props.slot}</div>
25+
{props.slot_below && (
26+
<div className={styles.below}>{props.slot_below}</div>
27+
)}
2828
</div>
2929
)
3030
}

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -348,8 +348,7 @@ export const Home: React.FC<Props> = (props) => {
348348
<Item
349349
title="System Instructions"
350350
description="Tone and style instructions for the model."
351-
slot_placement="below"
352-
slot={
351+
slot_below={
353352
<Textarea
354353
value={edit_context_instructions}
355354
on_change={set_edit_context_instructions}
@@ -444,8 +443,7 @@ export const Home: React.FC<Props> = (props) => {
444443
<Item
445444
title="Instructions"
446445
description="Describe style and conventions (e.g. Conventional Commits, gitmoji) for the generated commit message."
447-
slot_placement="below"
448-
slot={
446+
slot_below={
449447
<Textarea
450448
value={commit_instructions}
451449
on_change={set_commit_instructions}
@@ -458,7 +456,7 @@ export const Home: React.FC<Props> = (props) => {
458456
<Item
459457
title="Modal Duration"
460458
description="Automatically accept the generated commit message after a specified number of seconds."
461-
slot={
459+
slot_right={
462460
<Input
463461
type="number"
464462
value={commit_message_auto_accept_after_str}

0 commit comments

Comments
 (0)