-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: warn about unsaved changes in editor
- Loading branch information
Showing
23 changed files
with
455 additions
and
366 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,5 @@ | ||
.confirmation-dialog { | ||
&__message { | ||
white-space: pre-wrap; | ||
} | ||
} |
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,99 @@ | ||
import * as NiceModal from '@ebay/nice-modal-react'; | ||
import type {ButtonView} from '@gravity-ui/uikit'; | ||
import {Dialog} from '@gravity-ui/uikit'; | ||
|
||
import {cn} from '../../utils/cn'; | ||
|
||
import {confirmationDialogKeyset} from './i18n'; | ||
|
||
import './ConfirmationDialog.scss'; | ||
|
||
const block = cn('confirmation-dialog'); | ||
|
||
interface CommonDialogProps { | ||
caption?: string; | ||
message?: React.ReactNode; | ||
body?: React.ReactNode; | ||
|
||
progress?: boolean; | ||
textButtonCancel?: string; | ||
textButtonApply?: string; | ||
buttonApplyView?: ButtonView; | ||
className?: string; | ||
onConfirm?: () => void; | ||
} | ||
|
||
interface ConfirmationDialogNiceModalProps extends CommonDialogProps { | ||
onClose?: () => void; | ||
} | ||
|
||
interface ConfirmationDialogProps extends CommonDialogProps { | ||
onClose: () => void; | ||
open: boolean; | ||
children?: React.ReactNode; | ||
} | ||
|
||
export const CONFIRMATION_DIALOG = 'confirmation-dialog'; | ||
function ConfirmationDialog({ | ||
caption = '', | ||
children, | ||
onConfirm, | ||
onClose, | ||
progress, | ||
textButtonApply, | ||
textButtonCancel, | ||
buttonApplyView = 'normal', | ||
className, | ||
open, | ||
}: ConfirmationDialogProps) { | ||
return ( | ||
<Dialog | ||
className={block(null, className)} | ||
size="s" | ||
onClose={onClose} | ||
disableOutsideClick | ||
open={open} | ||
> | ||
<Dialog.Header caption={caption} /> | ||
<Dialog.Body>{children}</Dialog.Body> | ||
<Dialog.Footer | ||
onClickButtonApply={onConfirm} | ||
propsButtonApply={{view: buttonApplyView}} | ||
textButtonApply={textButtonApply} | ||
textButtonCancel={textButtonCancel ?? confirmationDialogKeyset('action_cancel')} | ||
onClickButtonCancel={onClose} | ||
loading={progress} | ||
/> | ||
</Dialog> | ||
); | ||
} | ||
|
||
export const ConfirmationDialogNiceModal = NiceModal.create( | ||
(props: ConfirmationDialogNiceModalProps) => { | ||
const modal = NiceModal.useModal(); | ||
|
||
const handleClose = () => { | ||
modal.hide(); | ||
modal.remove(); | ||
}; | ||
|
||
return ( | ||
<ConfirmationDialog | ||
{...props} | ||
onConfirm={async () => { | ||
await props.onConfirm?.(); | ||
modal.resolve(true); | ||
handleClose(); | ||
}} | ||
onClose={() => { | ||
props.onClose?.(); | ||
modal.resolve(false); | ||
handleClose(); | ||
}} | ||
open={modal.visible} | ||
/> | ||
); | ||
}, | ||
); | ||
|
||
NiceModal.register(CONFIRMATION_DIALOG, ConfirmationDialogNiceModal); |
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,3 @@ | ||
{ | ||
"action_cancel": "Cancel" | ||
} |
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,7 @@ | ||
import {registerKeysets} from '../../../utils/i18n'; | ||
|
||
import en from './en.json'; | ||
|
||
const COMPONENT = 'ydb-confirmation-dialog'; | ||
|
||
export const confirmationDialogKeyset = registerKeysets(COMPONENT, {en}); |
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
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
Oops, something went wrong.