@@ -5,6 +5,8 @@ import Image from "next/image";
5
5
import { SetStateAction , useState } from "react" ;
6
6
import Textarea from "../textarea/Textarea" ;
7
7
import { CgClose } from "react-icons/cg" ;
8
+ import CharacterCount from "./CharacterCount" ;
9
+ import { MAX_ALT_TEXT_LENGTH } from "@/lib/consts/general" ;
8
10
9
11
interface Props {
10
12
images : UploadImage [ ] ;
@@ -19,7 +21,7 @@ export default function UploadPreview(props: Props) {
19
21
20
22
const handleRemove = ( image : UploadImage ) => {
21
23
onUpdate ( ( prev ) =>
22
- prev ?. filter ( ( prevImage ) => prevImage . url !== image . url )
24
+ prev ?. filter ( ( prevImage ) => prevImage . url !== image . url ) ,
23
25
) ;
24
26
} ;
25
27
@@ -74,43 +76,51 @@ export default function UploadPreview(props: Props) {
74
76
< Textarea
75
77
rows = { 6 }
76
78
autoFocus = { false }
79
+ maxLength = { MAX_ALT_TEXT_LENGTH }
77
80
placeholder = "Describe what's happening in this image"
78
81
defaultValue = { selectedImage . altText ?? "" }
79
82
onChange = { ( e ) =>
80
83
setAltText ( e . currentTarget . value )
81
84
}
82
85
className = "resize-none"
83
86
/>
84
- < div className = "mt-2 flex justify-end gap-3" >
85
- < Button
86
- onClick = { ( ) => {
87
- setShowAltTextModal ( false ) ;
88
- setAltText ( "" ) ;
89
- } }
90
- className = "border-skin-base text-skin-base hover:bg-skin-secondary rounded-full border px-4 py-2 text-sm font-semibold"
91
- >
92
- Cancel
93
- </ Button >
94
- < Button
95
- onClick = { ( ) => {
96
- setShowAltTextModal ( false ) ;
97
- onUpdate ( ( prev ) =>
98
- prev ?. map ( ( prevImage ) =>
99
- prevImage . url === selectedImage . url
100
- ? Object . assign ( prevImage , {
101
- altText :
102
- altText !== selectedImage . altText
103
- ? altText
104
- : selectedImage . altText ,
105
- } )
106
- : prevImage
107
- )
108
- ) ;
109
- } }
110
- className = "bg-primary hover:bg-primary-dark text-skin-icon-inverted rounded-full px-6 py-2 text-sm font-semibold"
111
- >
112
- Save
113
- </ Button >
87
+ < div className = "flex flex-wrap gap-2 items-center justify-between mt-2 " >
88
+ < CharacterCount
89
+ charCount = { altText . length }
90
+ max = { MAX_ALT_TEXT_LENGTH }
91
+ />
92
+ < div className = "flex justify-end gap-3" >
93
+ < Button
94
+ onClick = { ( ) => {
95
+ setShowAltTextModal ( false ) ;
96
+ setAltText ( "" ) ;
97
+ } }
98
+ className = "border-skin-base text-skin-base hover:bg-skin-secondary rounded-full border px-4 py-2 text-sm font-semibold"
99
+ >
100
+ Cancel
101
+ </ Button >
102
+ < Button
103
+ onClick = { ( ) => {
104
+ setShowAltTextModal ( false ) ;
105
+ onUpdate ( ( prev ) =>
106
+ prev ?. map ( ( prevImage ) =>
107
+ prevImage . url === selectedImage . url
108
+ ? Object . assign ( prevImage , {
109
+ altText :
110
+ altText !==
111
+ selectedImage . altText
112
+ ? altText
113
+ : selectedImage . altText ,
114
+ } )
115
+ : prevImage ,
116
+ ) ,
117
+ ) ;
118
+ } }
119
+ className = "bg-primary hover:bg-primary-dark text-skin-icon-inverted rounded-full px-6 py-2 text-sm font-semibold"
120
+ >
121
+ Save
122
+ </ Button >
123
+ </ div >
114
124
</ div >
115
125
</ div >
116
126
</ div >
0 commit comments