(
props: {
readonly actions: [
icon: string,
title: string,
component: (props: OnDoneProp & Props) => JSXElement,
][];
} & Props,
)
| 185 | }; |
| 186 | |
| 187 | const ConfirmableActions = < |
| 188 | Props extends TableProps | RowProps | CellProps | ValuesProps | ValueProps, |
| 189 | >( |
| 190 | props: { |
| 191 | readonly actions: [ |
| 192 | icon: string, |
| 193 | title: string, |
| 194 | component: (props: OnDoneProp & Props) => JSXElement, |
| 195 | ][]; |
| 196 | } & Props, |
| 197 | ) => { |
| 198 | const [confirming, setConfirming] = createSignal<number>(); |
| 199 | const handleDone = () => setConfirming(undefined); |
| 200 | |
| 201 | createEffect(() => { |
| 202 | if (!isUndefined(confirming())) { |
| 203 | const handleKeyDown = (event: KeyboardEvent) => { |
| 204 | if (!isUndefined(confirming()) && event.key == 'Escape') { |
| 205 | event.preventDefault(); |
| 206 | handleDone(); |
| 207 | } |
| 208 | }; |
| 209 | document.addEventListener('keydown', handleKeyDown); |
| 210 | onCleanup(() => document.removeEventListener('keydown', handleKeyDown)); |
| 211 | } |
| 212 | }); |
| 213 | |
| 214 | const content = () => { |
| 215 | const confirmingIndex = confirming(); |
| 216 | const Component = isUndefined(confirmingIndex) |
| 217 | ? undefined |
| 218 | : props.actions[confirmingIndex][2]; |
| 219 | return ( |
| 220 | <> |
| 221 | {Component ? ( |
| 222 | <> |
| 223 | {Component({...props, onDone: handleDone})} |
| 224 | <img onClick={handleDone} title="Cancel" class="cancel" /> |
| 225 | </> |
| 226 | ) : ( |
| 227 | arrayMap(props.actions, ([icon, title], index) => ( |
| 228 | <img |
| 229 | title={title} |
| 230 | class={icon} |
| 231 | onClick={() => setConfirming(index)} |
| 232 | /> |
| 233 | )) |
| 234 | )} |
| 235 | </> |
| 236 | ); |
| 237 | }; |
| 238 | |
| 239 | return <>{content()}</>; |
| 240 | }; |
| 241 | |
| 242 | const NewId = ( |
| 243 | props: OnDoneProp & { |
no test coverage detected
searching dependent graphs…