popup's onClose callback

Signed-off-by: Andrey Platov <andrey@hardcoreeng.com>
This commit is contained in:
Andrey Platov 2021-09-01 14:38:22 +02:00
parent aa48e78d29
commit 120dab0f04
No known key found for this signature in database
GPG Key ID: C8787EFEB4B64AF0
4 changed files with 14 additions and 7 deletions

View File

@ -31,6 +31,6 @@
<svelte:window on:keydown={handleKeydown} />
{#each $modal as popup, i}
<PopupInstance is={popup.is} props={popup.props} element={popup.element} zIndex={(i+1) * 500}/>
<PopupInstance is={popup.is} props={popup.props} element={popup.element} onClose={popup.onClose} zIndex={(i+1) * 500}/>
{/each}

View File

@ -22,12 +22,15 @@ import { closePopup } from '..'
export let is: AnyComponent | AnySvelteComponent
export let props: object
export let element: HTMLElement | undefined
export let onClose: (result: any) => void | undefined
export let zIndex: number
let modalHTML: HTMLElement
let modalOHTML: HTMLElement
function close() {
function close(ev: CustomEvent) {
console.log('got close, data', ev.detail)
if (onClose !== undefined) onClose(ev.detail)
closePopup()
}

View File

@ -71,13 +71,13 @@ export function createApp (target: HTMLElement): SvelteComponent {
interface CompAndProps {
is: AnySvelteComponent | AnyComponent | undefined
props: any
element: HTMLElement | undefined
element?: HTMLElement
onClose?: (result: any) => void
}
export const store = writable<CompAndProps>({
is: undefined,
props: {},
element: undefined
})
export function showModal (component: AnySvelteComponent | AnyComponent, props: any, element?: HTMLElement): void {
@ -90,9 +90,9 @@ export function closeModal (): void {
export const popupstore = writable<CompAndProps[]>([])
export function showPopup (component: AnySvelteComponent | AnyComponent, props: any, element?: HTMLElement): void {
export function showPopup (component: AnySvelteComponent | AnyComponent, props: any, element?: HTMLElement, onClose?: (result: any) => void): void {
popupstore.update(popups => {
popups.push({ is: component, props, element: element })
popups.push({ is: component, props, element, onClose })
return popups
})
}

View File

@ -15,11 +15,14 @@
-->
<script lang="ts">
import { EditBox } from '@anticrm/ui'
import { createEventDispatcher } from 'svelte'
import { EditBox, Button } from '@anticrm/ui'
import { getClient } from '@anticrm/presentation'
import contact, { ChannelProvider } from '@anticrm/contact'
const dispatch = createEventDispatcher()
let providers: ChannelProvider[] = []
let values: string[]
@ -40,6 +43,7 @@
<EditBox label={'Twitter'} placeholder={'@rosychen'} />
<EditBox label={'Facebook'} placeholder={'facebook/rosamundch'} />
</div> -->
<Button label="Apply" on:click={() => { dispatch('close', 42) }}/>
</div>
<style lang="scss">