-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add TextDialog Component Add React Hooks ESLint Clean Code * Add Delete Node Dialog * Disable Delete and Unlock Menu Items for Root Node * Remove Alerts * Remove Gear * Fix Double Click Binding * ESLint Fixes * Bug Fixes
- Loading branch information
Showing
10 changed files
with
465 additions
and
306 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import React, { ReactNode, useEffect, useState } from 'react'; | ||
import { | ||
Button, | ||
Dialog, | ||
DialogActions, | ||
DialogContent, | ||
DialogContentText, | ||
DialogTitle, | ||
TextField, | ||
TextFieldProps, | ||
} from '@mui/material'; | ||
|
||
const TextDialog = ({ | ||
isOpen, | ||
onApprove, | ||
onReject, | ||
title, | ||
description, | ||
approveButtonText, | ||
rejectButtonText, | ||
suggestedAction, | ||
initialValue, | ||
updateOnInitialValueChange, | ||
textFieldProps, | ||
}: { | ||
isOpen: boolean; | ||
onApprove: (value: string) => void; | ||
onReject: () => void; | ||
title: string; | ||
description?: ReactNode; | ||
approveButtonText?: string; | ||
rejectButtonText?: string; | ||
suggestedAction?: 'approve' | 'reject' | undefined; | ||
initialValue?: string; | ||
updateOnInitialValueChange?: boolean; | ||
textFieldProps?: TextFieldProps; | ||
}) => { | ||
const [value, setValue] = useState(initialValue || ''); | ||
|
||
useEffect(() => { | ||
if (updateOnInitialValueChange && initialValue) setValue(initialValue); | ||
}, [initialValue, updateOnInitialValueChange]); | ||
|
||
const onClose = () => { | ||
setValue(initialValue || ''); | ||
onReject(); | ||
}; | ||
|
||
return ( | ||
<Dialog open={isOpen} onClose={onClose}> | ||
<form | ||
onSubmit={(e) => { | ||
onApprove(value); | ||
onClose(); | ||
e.preventDefault(); | ||
}} | ||
> | ||
<DialogTitle>{title}</DialogTitle> | ||
<DialogContent> | ||
{description && <DialogContentText>{description}</DialogContentText>} | ||
<TextField | ||
sx={{ m: 2 }} | ||
value={value} | ||
onChange={(e) => setValue(e.target.value)} | ||
inputProps={{ autoFocus: true }} | ||
// eslint-disable-next-line react/jsx-props-no-spreading | ||
{...textFieldProps} | ||
/> | ||
</DialogContent> | ||
<DialogActions> | ||
<Button | ||
variant={suggestedAction === 'reject' ? 'contained' : 'text'} | ||
onClick={() => onClose()} | ||
type={suggestedAction === 'reject' ? 'submit' : 'button'} | ||
> | ||
{rejectButtonText} | ||
</Button> | ||
<Button | ||
variant={suggestedAction === 'approve' ? 'contained' : 'text'} | ||
type={suggestedAction === 'approve' ? 'submit' : 'button'} | ||
> | ||
{approveButtonText} | ||
</Button> | ||
</DialogActions> | ||
</form> | ||
</Dialog> | ||
); | ||
}; | ||
|
||
export default TextDialog; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.