Skip to content

Commit 1f2eeff

Browse files
committed
Refactor the TextItem component to consolidate expanded and collapsed states into a single header element
1 parent aa0381d commit 1f2eeff

3 files changed

Lines changed: 34 additions & 23 deletions

File tree

‎.prettierrc‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"singleQuote": true,
33
"trailingComma": "none",
4+
"semi": false,
45
"printWidth": 80
56
}

‎packages/ui/src/components/editor/panel/ResponsePreview/components/TextItem.module.scss‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
.container {
2+
display: flex;
3+
flex-direction: column;
4+
}
5+
16
.text {
27
margin: var(--padding-6px) var(--padding-12px);
38
word-wrap: break-word;
@@ -30,26 +35,28 @@
3035

3136
&__collapse > span {
3237
cursor: pointer;
33-
font-weight: 500;
38+
font-style: italic;
3439
font-size: var(--font-size-12px);
40+
color: var(--cwc-text-color-dimmed);
3541

3642
&:hover {
3743
text-decoration: underline;
3844
}
3945
}
4046
}
4147

42-
.hidden {
48+
.header {
4349
display: flex;
4450
align-items: center;
4551
margin: 0 var(--padding-12px);
4652
padding-right: var(--padding-9px);
4753
position: relative;
54+
cursor: pointer;
4855

4956
&:hover {
5057
color: var(--cwc-text-color);
5158

52-
& .hidden__line {
59+
& .header__line {
5360
background-color: var(--cwc-border-color) !important;
5461
}
5562
}
Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { FC, useRef } from 'react'
22
import ReactMarkdown from 'react-markdown'
33
import styles from './TextItem.module.scss'
4-
import cn from 'classnames'
54
import { IconButton } from '../../IconButton'
65

76
type Props = {
@@ -11,15 +10,32 @@ type Props = {
1110
}
1211

1312
export const TextItem: FC<Props> = (props) => {
14-
const ref = useRef<HTMLDivElement>(null)
13+
const header_ref = useRef<HTMLDivElement>(null)
1514

1615
return (
17-
<>
18-
{props.is_expanded ? (
16+
<div className={styles.container}>
17+
<div
18+
ref={header_ref}
19+
className={styles.header}
20+
onClick={() =>
21+
header_ref.current && props.on_toggle(header_ref.current)
22+
}
23+
title={props.content}
24+
>
25+
<IconButton
26+
codicon_icon={props.is_expanded ? 'chevron-down' : 'chevron-right'}
27+
/>
28+
<div className={styles.header__line} />
29+
<span className={styles.header__tokens}>
30+
{Math.floor(props.content.length * 0.25) || 1}
31+
</span>
32+
</div>
33+
{props.is_expanded && (
1934
<div
20-
ref={ref}
2135
className={styles.text}
22-
onClick={() => ref.current && props.on_toggle(ref.current)}
36+
onClick={() =>
37+
header_ref.current && props.on_toggle(header_ref.current)
38+
}
2339
>
2440
<ReactMarkdown disallowedElements={['hr']}>
2541
{props.content}
@@ -28,20 +44,7 @@ export const TextItem: FC<Props> = (props) => {
2844
<span>Show less</span>
2945
</div>
3046
</div>
31-
) : (
32-
<div
33-
ref={ref}
34-
className={styles.hidden}
35-
onClick={() => ref.current && props.on_toggle(ref.current)}
36-
title={props.content}
37-
>
38-
<IconButton codicon_icon="chevron-right" />
39-
<div className={styles.hidden__line} />
40-
<span className={styles.hidden__tokens}>
41-
{Math.floor(props.content.length * 0.25) || 1}
42-
</span>
43-
</div>
4447
)}
45-
</>
48+
</div>
4649
)
4750
}

0 commit comments

Comments
 (0)