format: whole project
This commit is contained in:
1 parent
b883b5f6e0
commit
80269cf275
79 files changed
+590
-612
No files matched your search
+46
-46
@@ -4,62 +4,62 @@ import { writable } from 'svelte/store'
|
||||
export let shownModal = writable<Modal | undefined>(undefined)
|
||||
|
||||
interface Modal {
|
||||
actions: Action[]
|
||||
title: string
|
||||
body?: string
|
||||
/**
|
||||
* Whether the modal has a close button or not
|
||||
*/
|
||||
dismissable: boolean
|
||||
type: 'error' | 'info' | 'success'
|
||||
actions: Action[]
|
||||
title: string
|
||||
body?: string
|
||||
/**
|
||||
* Whether the modal has a close button or not
|
||||
*/
|
||||
dismissable: boolean
|
||||
type: 'error' | 'info' | 'success'
|
||||
}
|
||||
|
||||
type Action = {
|
||||
/**
|
||||
* What function to run when this action is clicked. If undefined, it'll close the window.
|
||||
*/
|
||||
action: () => any
|
||||
type: 'danger' | 'secondary' | 'primary'
|
||||
content: string
|
||||
icon?: IconSource
|
||||
close: boolean
|
||||
/**
|
||||
* What function to run when this action is clicked. If undefined, it'll close the window.
|
||||
*/
|
||||
action: () => any
|
||||
type: 'danger' | 'secondary' | 'primary'
|
||||
content: string
|
||||
icon?: IconSource
|
||||
close: boolean
|
||||
}
|
||||
|
||||
export const action = (action?: {
|
||||
action?: () => any
|
||||
type?: 'danger' | 'secondary' | 'primary'
|
||||
content?: string
|
||||
icon?: IconSource
|
||||
close?: boolean
|
||||
action?: () => any
|
||||
type?: 'danger' | 'secondary' | 'primary'
|
||||
content?: string
|
||||
icon?: IconSource
|
||||
close?: boolean
|
||||
}): Action => ({
|
||||
action: action?.action
|
||||
? () => {
|
||||
action?.action?.()
|
||||
if (action.close) shownModal.set(undefined)
|
||||
}
|
||||
: () => shownModal.set(undefined),
|
||||
type: action?.type ?? 'secondary',
|
||||
content: action?.content || 'OK',
|
||||
close: action?.close ?? true
|
||||
action: action?.action
|
||||
? () => {
|
||||
action?.action?.()
|
||||
if (action.close) shownModal.set(undefined)
|
||||
}
|
||||
: () => shownModal.set(undefined),
|
||||
type: action?.type ?? 'secondary',
|
||||
content: action?.content || 'OK',
|
||||
close: action?.close ?? true,
|
||||
})
|
||||
|
||||
export function modal(inputModal: {
|
||||
actions?: Action[]
|
||||
title: string
|
||||
body: string
|
||||
/**
|
||||
* Whether the modal has a close button or not
|
||||
*/
|
||||
dismissable?: boolean
|
||||
type?: 'error' | 'info' | 'success'
|
||||
actions?: Action[]
|
||||
title: string
|
||||
body: string
|
||||
/**
|
||||
* Whether the modal has a close button or not
|
||||
*/
|
||||
dismissable?: boolean
|
||||
type?: 'error' | 'info' | 'success'
|
||||
}) {
|
||||
const modal: Modal = {
|
||||
actions: inputModal.actions ?? [action()],
|
||||
dismissable: inputModal.dismissable ?? true,
|
||||
title: inputModal.title,
|
||||
body: inputModal.body,
|
||||
type: inputModal.type ?? 'info'
|
||||
}
|
||||
const modal: Modal = {
|
||||
actions: inputModal.actions ?? [action()],
|
||||
dismissable: inputModal.dismissable ?? true,
|
||||
title: inputModal.title,
|
||||
body: inputModal.body,
|
||||
type: inputModal.type ?? 'info',
|
||||
}
|
||||
|
||||
shownModal.set(modal)
|
||||
shownModal.set(modal)
|
||||
}
|
||||
Reference in new issue
Block a user