-
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.
[refactor] transfer IdeaDialog to Component-independent Class
[remove] IdeaDialog storybook
- Loading branch information
Showing
8 changed files
with
83 additions
and
141 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
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 |
---|---|---|
@@ -1,76 +1,33 @@ | ||
import { Defer } from 'iterable-observer'; | ||
import { observable } from 'mobx'; | ||
import { observer } from 'mobx-react'; | ||
import { FC } from 'react'; | ||
import { Button, Modal, ModalProps } from 'react-bootstrap'; | ||
|
||
import { SpinnerButton, SpinnerButtonProps } from './SpinnerButton'; | ||
export class DialogClose extends Error { | ||
constructor(message = 'Dialog closed') { | ||
super(message); | ||
} | ||
} | ||
|
||
export interface IdeaDialogProps | ||
extends Partial< | ||
Pick<SpinnerButtonProps, 'animation' | 'loading'> & | ||
Pick< | ||
ModalProps, | ||
| 'className' | ||
| 'show' | ||
| 'size' | ||
| 'fullscreen' | ||
| 'centered' | ||
| 'scrollable' | ||
| 'contentClassName' | ||
> | ||
> { | ||
title: string; | ||
formId?: string; | ||
confirmText?: string; | ||
onConfirm?: () => any; | ||
cancelText?: string; | ||
onCancel?: () => any; | ||
export interface DialogProps<T = any> { | ||
defer?: Defer<T>; | ||
} | ||
|
||
export const IdeaDialog: FC<IdeaDialogProps> = ({ | ||
children, | ||
title, | ||
formId, | ||
confirmText, | ||
onConfirm, | ||
cancelText, | ||
onCancel, | ||
animation = 'border', | ||
loading, | ||
...rest | ||
}) => ( | ||
<Modal {...rest} onHide={onCancel}> | ||
<Modal.Header closeButton> | ||
<Modal.Title>{title}</Modal.Title> | ||
</Modal.Header> | ||
<Modal.Body>{children}</Modal.Body> | ||
export class Dialog<T = any> { | ||
@observable | ||
defer?: Defer<T>; | ||
|
||
Component: FC; | ||
|
||
constructor(Factory: FC<DialogProps<T>>) { | ||
this.Component = observer(() => <Factory defer={this.defer} />); | ||
} | ||
|
||
{(confirmText || cancelText) && ( | ||
<Modal.Footer> | ||
{cancelText && ( | ||
<Button | ||
variant="secondary" | ||
type="reset" | ||
form={formId} | ||
disabled={loading} | ||
onClick={onCancel} | ||
> | ||
{cancelText} | ||
</Button> | ||
)} | ||
{confirmText && ( | ||
<SpinnerButton | ||
variant="primary" | ||
type="submit" | ||
form={formId} | ||
animation={animation} | ||
loading={loading} | ||
onClick={onConfirm} | ||
> | ||
{confirmText} | ||
</SpinnerButton> | ||
)} | ||
</Modal.Footer> | ||
)} | ||
</Modal> | ||
); | ||
open() { | ||
this.defer = new Defer(); | ||
|
||
IdeaDialog.displayName = 'IdeaDialog'; | ||
this.defer.promise.finally(() => (this.defer = undefined)); | ||
|
||
return this.defer.promise; | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
stories/IdeaPopover.stories.tsx → stories/OverlayBox.stories.tsx
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