@@ -35,7 +35,22 @@ const getStatusColor = (status: string): string => {
35
35
}
36
36
} ;
37
37
38
+ //in case the desciption contian no space, to break long words
39
+ const breakLongWords = ( text : string , maxLength : number = 18 ) : string => {
40
+ return text
41
+ . split ( " " )
42
+ . map ( ( word ) => {
43
+ if ( word . length > maxLength ) {
44
+ return word . match ( new RegExp ( ".{1," + maxLength + "}" , "g" ) ) ?. join ( " " ) ?? word ;
45
+ }
46
+ return word ;
47
+ } )
48
+ . join ( " " ) ;
49
+ } ;
50
+
38
51
export function ReviewCard ( { review } : ReviewCardProps ) : JSX . Element {
52
+ const formattedDescription = breakLongWords ( review . description ) ;
53
+
39
54
return (
40
55
< Card radius = "md" shadow = "sm" >
41
56
< Flex direction = "row" gap = "lg" justify = "center" >
@@ -60,7 +75,7 @@ export function ReviewCard({ review }: ReviewCardProps): JSX.Element {
60
75
</ Text >
61
76
< Spoiler maxHeight = { 75 } showLabel = "Show more" hideLabel = "Hide" >
62
77
< TypographyStylesProvider mt = "md" >
63
- < ReactMarkdown > { review . description } </ ReactMarkdown >
78
+ < ReactMarkdown > { formattedDescription } </ ReactMarkdown >
64
79
</ TypographyStylesProvider >
65
80
</ Spoiler >
66
81
</ Flex >
@@ -75,14 +90,16 @@ export function MyReviewCard({ review, onEditReview, onDeleteReview }: ReviewCar
75
90
const [ openedEdit , { open : openEdit , close : closeEdit } ] = useDisclosure ( false ) ;
76
91
const [ openedDelete , { open : openDelete , close : closeDelete } ] = useDisclosure ( false ) ;
77
92
93
+ const formattedDescription = breakLongWords ( review . description ) ;
94
+
78
95
return (
79
96
< >
80
97
< Card
81
98
bg = "gray.9"
82
99
padding = "md"
83
100
radius = "md"
84
101
withBorder
85
- className = { `border-${ getStatusColor ( review . status ) } -500` }
102
+ className = { `border-${ getStatusColor ( review . status ) } -500 break-words ` }
86
103
>
87
104
< Flex direction = "row" gap = "md" justify = "center" >
88
105
{ /* user profile and badges */ }
@@ -118,7 +135,7 @@ export function MyReviewCard({ review, onEditReview, onDeleteReview }: ReviewCar
118
135
</ Text >
119
136
< Spoiler maxHeight = { 75 } showLabel = "Show more" hideLabel = "Hide" >
120
137
< TypographyStylesProvider mt = "sm" >
121
- < ReactMarkdown > { review . description } </ ReactMarkdown >
138
+ < ReactMarkdown > { formattedDescription } </ ReactMarkdown >
122
139
</ TypographyStylesProvider >
123
140
</ Spoiler >
124
141
</ Flex >
0 commit comments