Skip to content

Commit 2458f3a

Browse files
author
Ivan Strilets
committed
update paragraph constructor
1 parent 335005b commit 2458f3a

File tree

4 files changed

+45
-39
lines changed

4 files changed

+45
-39
lines changed

src/shared/paragraphConstructor/ui/index.tsx

+2-23
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,16 @@
11
import styles from "./styles.module.css";
22
import type { ParagraphConstructorRow } from "../api/types";
3+
import { Row } from "./row";
34

45
interface ParagraphConstructorProps {
56
rows: ParagraphConstructorRow[];
67
}
78

8-
const createRow = (row: ParagraphConstructorRow) => {
9-
const rowClassName = row.accentColor ? styles[row.accentColor] : "";
10-
11-
if (row.isTag) {
12-
return <span className={rowClassName}>&lt;{row.text}&gt;</span>;
13-
}
14-
15-
if (row.accentSubstring) {
16-
const [firstChunk, lastChunk] = row.text.split(row.accentSubstring);
17-
18-
return (
19-
<span>
20-
{firstChunk}
21-
<span className={rowClassName}>{row.accentSubstring}</span>
22-
{lastChunk}
23-
</span>
24-
);
25-
}
26-
27-
return <span>{row.text}</span>;
28-
};
29-
309
export const ParagraphConstructor = ({ rows }: ParagraphConstructorProps) => {
3110
return (
3211
<p className={styles.paragraph}>
3312
{rows.map((row, rowIndex) => {
34-
return <span key={rowIndex}>{createRow(row)}</span>;
13+
return <Row key={rowIndex} data={row} />;
3514
})}
3615
</p>
3716
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import styles from "./styles.module.css";
2+
import type { ParagraphConstructorRow } from "../../api/types";
3+
4+
interface RowProps {
5+
data: ParagraphConstructorRow;
6+
}
7+
8+
export const Row = ({ data }: RowProps) => {
9+
const rowClassName = data.accentColor ? styles[data.accentColor] : "";
10+
11+
if (data.isTag) {
12+
return <span className={rowClassName}>&lt;{data.text}&gt;</span>;
13+
}
14+
15+
if (data.accentSubstring) {
16+
const [firstChunk, lastChunk] = data.text.split(data.accentSubstring);
17+
18+
return (
19+
<span>
20+
{firstChunk}
21+
<span className={rowClassName}>{data.accentSubstring}</span>
22+
{lastChunk}
23+
</span>
24+
);
25+
}
26+
27+
return <span>{data.text}</span>;
28+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
.yellow {
2+
color: var(--color-yellow);
3+
}
4+
.red {
5+
color: var(--color-red);
6+
}
7+
.purple {
8+
color: var(--color-purple);
9+
}
10+
.blue {
11+
color: var(--color-blue);
12+
}
13+
.green {
14+
color: var(--color-green);
15+
}

src/shared/paragraphConstructor/ui/styles.module.css

-16
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,3 @@
77
font-size: 16px;
88
}
99
}
10-
11-
.yellow {
12-
color: var(--color-yellow);
13-
}
14-
.red {
15-
color: var(--color-red);
16-
}
17-
.purple {
18-
color: var(--color-purple);
19-
}
20-
.blue {
21-
color: var(--color-blue);
22-
}
23-
.green {
24-
color: var(--color-green);
25-
}

0 commit comments

Comments
 (0)