2
2
import type { KeyboardEventHandler } from 'react' ;
3
3
import { useRef , useState } from 'react' ;
4
4
5
- import { CircleLoader } from '@proton/atoms' ;
5
+ import { ButtonLike , CircleLoader } from '@proton/atoms' ;
6
+ import { Icon } from '@proton/components/index' ;
6
7
import clsx from '@proton/utils/clsx' ;
7
8
8
9
import type { ListFieldValue } from './ListField' ;
@@ -11,6 +12,7 @@ export type ListFieldItemProps<T> = ListFieldValue<T> & {
11
12
error ?: boolean ;
12
13
loading : boolean ;
13
14
onChange : ( value : string ) => void ;
15
+ onDelete : ( ) => void ;
14
16
onMoveLeft : ( ) => void ;
15
17
onMoveRight : ( ) => void ;
16
18
renderValue : ( value : T ) => string ;
@@ -37,6 +39,7 @@ export const ListFieldItem = <T,>({
37
39
loading,
38
40
value,
39
41
onChange,
42
+ onDelete,
40
43
onMoveLeft,
41
44
onMoveRight,
42
45
renderValue,
@@ -88,11 +91,12 @@ export const ListFieldItem = <T,>({
88
91
className = { clsx (
89
92
'pass-field-text-group--item flex flex-nowrap flex-row max-w-full overflow-hidden stop-propagation border rounded' ,
90
93
error && 'pass-field-text-group--item:error' ,
91
- loading && 'pass-field-text-group--item:loading'
94
+ loading && 'pass-field-text-group--item:loading' ,
95
+ editing && 'pass-field-text-group--item:editing'
92
96
) }
93
97
>
94
98
< button
95
- className = "pill-remove inline-flex flex-nowrap items-center px-2 py-1 max-w-full gap-2"
99
+ className = "pill-remove inline-flex flex-nowrap items-center px-2 py-1 max-w-full gap-2 relative "
96
100
type = "button"
97
101
tabIndex = { - 1 }
98
102
>
@@ -101,6 +105,7 @@ export const ListFieldItem = <T,>({
101
105
onBlur = { handleBlur }
102
106
onFocus = { ( ) => setEditing ( true ) }
103
107
onClick = { ( e ) => e . stopPropagation ( ) }
108
+ onMouseDown = { ( e ) => e . stopPropagation ( ) }
104
109
contentEditable
105
110
onKeyDown = { handleKeyDown }
106
111
ref = { ref }
@@ -110,7 +115,25 @@ export const ListFieldItem = <T,>({
110
115
>
111
116
{ renderValue ( value ) }
112
117
</ span >
118
+
113
119
{ loading && < CircleLoader size = "small" className = "shrink-0" /> }
120
+
121
+ { ! loading && (
122
+ < ButtonLike
123
+ as = "a"
124
+ className = "pass-field-text-group--item-delete flex absolute"
125
+ shape = "ghost"
126
+ pill
127
+ icon
128
+ onClick = { ( evt ) => {
129
+ evt . preventDefault ( ) ;
130
+ evt . stopPropagation ( ) ;
131
+ onDelete ( ) ;
132
+ } }
133
+ >
134
+ < Icon name = "cross" className = "shrink-0" />
135
+ </ ButtonLike >
136
+ ) }
114
137
</ button >
115
138
</ li >
116
139
) ;
0 commit comments