import React from 'react'; import { Input, Dialog, ButtonEnums } from '@ohif/ui'; /** * * @param {*} data * @param {*} data.text * @param {*} data.label * @param {*} event * @param {*} callback * @param {*} isArrowAnnotateInputDialog * @param {*} dialogConfig * @param {string?} dialogConfig.dialogTitle - title of the input dialog * @param {string?} dialogConfig.inputLabel - show label above the input */ function callInputDialog( uiDialogService, data, callback, isArrowAnnotateInputDialog = true, dialogConfig: any = {} ) { const dialogId = 'dialog-enter-annotation'; const label = data ? isArrowAnnotateInputDialog ? data.text : data.label : ''; const { dialogTitle = 'Annotation', inputLabel = 'Enter your annotation', validateFunc = value => true, } = dialogConfig; const onSubmitHandler = ({ action, value }) => { switch (action.id) { case 'save': if (typeof validateFunc === 'function' && !validateFunc(value.label)) return; callback(value.label, action.id); break; case 'cancel': callback('', action.id); break; } uiDialogService.dismiss({ id: dialogId }); }; if (uiDialogService) { uiDialogService.create({ id: dialogId, centralize: true, isDraggable: false, showOverlay: true, content: Dialog, contentProps: { title: dialogTitle, value: { label }, noCloseButton: true, onClose: () => uiDialogService.dismiss({ id: dialogId }), actions: [ { id: 'cancel', text: 'Cancel', type: ButtonEnums.type.secondary }, { id: 'save', text: 'Save', type: ButtonEnums.type.primary }, ], onSubmit: onSubmitHandler, body: ({ value, setValue }) => { return ( { event.persist(); setValue(value => ({ ...value, label: event.target.value })); }} onKeyPress={event => { if (event.key === 'Enter') { onSubmitHandler({ value, action: { id: 'save' } }); } }} /> ); }, }, }); } } export default callInputDialog;