-
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.
Merge pull request #16 from projectstorm/feature_confirm_dialog
confirm deletes + confirm dialog
- Loading branch information
Showing
8 changed files
with
157 additions
and
4 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,51 @@ | ||
import * as React from 'react'; | ||
import { Layer, LayerStore } from './LayerStore'; | ||
import { DialogWidget } from '../widgets/dialog/DialogWidget'; | ||
import { ButtonType } from '../widgets/forms/ButtonWidget'; | ||
|
||
export interface DialogStoreOptions { | ||
layerStore: LayerStore; | ||
} | ||
|
||
export class DialogStore { | ||
constructor(protected options: DialogStoreOptions) {} | ||
|
||
async showConfirmDialog(options: { title: string; desc: string }): Promise<boolean> { | ||
return await new Promise<boolean>((resolve) => { | ||
let confirm = false; | ||
const layer = new Layer(() => { | ||
return ( | ||
<DialogWidget | ||
title={options.title} | ||
desc={options.desc} | ||
btns={[ | ||
{ | ||
label: 'Confirm', | ||
action: async () => { | ||
confirm = true; | ||
layer.dispose(); | ||
}, | ||
type: ButtonType.PRIMARY | ||
}, | ||
{ | ||
label: 'Cancel', | ||
action: async () => { | ||
layer.dispose(); | ||
}, | ||
type: ButtonType.NORMAL | ||
} | ||
]} | ||
/> | ||
); | ||
}); | ||
const l1 = layer.registerListener({ | ||
disposed: () => { | ||
l1(); | ||
resolve(confirm); | ||
} | ||
}); | ||
|
||
this.options.layerStore.addLayer(layer); | ||
}); | ||
} | ||
} |
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,70 @@ | ||
import * as React from 'react'; | ||
import { styled } from '../../theme/theme'; | ||
import { ButtonWidget, ButtonWidgetProps } from '../forms/ButtonWidget'; | ||
import { FONT } from '../../fonts'; | ||
|
||
export interface DialogWidgetProps { | ||
title: string; | ||
desc: string; | ||
btns: ButtonWidgetProps[]; | ||
} | ||
|
||
export const DialogWidget: React.FC<React.PropsWithChildren<DialogWidgetProps>> = (props) => { | ||
return ( | ||
<S.DialogLayer> | ||
<S.Container> | ||
<S.Title>{props.title}</S.Title> | ||
<S.Desc>{props.desc}</S.Desc> | ||
{props.children ? <S.Content>{props.children}</S.Content> : null} | ||
<S.Buttons> | ||
{props.btns.map((b) => { | ||
return <S.Button {...b} key={b.label} />; | ||
})} | ||
</S.Buttons> | ||
</S.Container> | ||
</S.DialogLayer> | ||
); | ||
}; | ||
namespace S { | ||
export const DialogLayer = styled.div` | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
height: 100%; | ||
`; | ||
export const Container = styled.div` | ||
padding: 50px; | ||
border-radius: 8px; | ||
background: ${(p) => p.theme.dialog.background}; | ||
border: solid 1px ${(p) => p.theme.dialog.border}; | ||
box-shadow: 0 11px 30px ${(p) => p.theme.dialog.shadow}; | ||
`; | ||
|
||
export const Title = styled.div` | ||
color: ${(p) => p.theme.dialog.header}; | ||
font-size: 25px; | ||
padding-bottom: 20px; | ||
user-select: none; | ||
${FONT}; | ||
`; | ||
|
||
export const Desc = styled.div` | ||
color: ${(p) => p.theme.dialog.desc}; | ||
font-size: 14px; | ||
padding-bottom: 20px; | ||
${FONT}; | ||
`; | ||
|
||
export const Content = styled.div` | ||
padding-bottom: 20px; | ||
`; | ||
|
||
export const Button = styled(ButtonWidget)` | ||
margin-left: 5px; | ||
`; | ||
|
||
export const Buttons = styled.div` | ||
display: flex; | ||
justify-content: flex-end; | ||
`; | ||
} |
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