From 4d529e7e3f4a0ba8c3480fe421f57a36dc3d0581 Mon Sep 17 00:00:00 2001 From: Jan Prochazka Date: Sun, 6 Jun 2021 12:39:05 +0200 Subject: [PATCH] snackbar imlementation --- packages/web/src/Screen.svelte | 15 ++ .../web/src/datagrid/SqlDataGridCore.svelte | 4 - packages/web/src/formview/SqlFormView.svelte | 8 -- packages/web/src/stores.ts | 1 + packages/web/src/tabs/TableDataTab.svelte | 4 + packages/web/src/widgets/Snackbar.svelte | 135 ++++++++++++++++++ 6 files changed, 155 insertions(+), 12 deletions(-) create mode 100644 packages/web/src/widgets/Snackbar.svelte diff --git a/packages/web/src/Screen.svelte b/packages/web/src/Screen.svelte index 3d0ab19e..5d87f330 100644 --- a/packages/web/src/Screen.svelte +++ b/packages/web/src/Screen.svelte @@ -6,6 +6,7 @@ currentThemeDefinition, isFileDragActive, leftPanelWidth, + openedSnackbars, selectedWidget, visibleCommandPalette, visibleToolbar, @@ -17,11 +18,13 @@ import splitterDrag from './utility/splitterDrag'; import CurrentDropDownMenu from './modals/CurrentDropDownMenu.svelte'; import StatusBar from './widgets/StatusBar.svelte'; + import Snackbar from './widgets/Snackbar.svelte'; import ModalLayer from './modals/ModalLayer.svelte'; import DragAndDropFileTarget from './DragAndDropFileTarget.svelte'; import dragDropFileTarget from './utility/dragDropFileTarget'; $: currentThemeType = $currentThemeDefinition?.themeType == 'dark' ? 'theme-type-dark' : 'theme-type-light'; +
@@ -64,6 +67,11 @@ {#if $isFileDragActive} {/if} +
+ {#each $openedSnackbars as snackbar} + + {/each} +
diff --git a/packages/web/src/datagrid/SqlDataGridCore.svelte b/packages/web/src/datagrid/SqlDataGridCore.svelte index f1c8ae84..d25829c4 100644 --- a/packages/web/src/datagrid/SqlDataGridCore.svelte +++ b/packages/web/src/datagrid/SqlDataGridCore.svelte @@ -71,11 +71,7 @@ + import { openedSnackbars } from '../stores'; + + export interface SnackbarButton { + label: string; + onClick: Function; + } + + export interface SnackbarInfo { + message: string; + icon?: string; + autoClose?: boolean; + allowClose?: boolean; + buttons?: SnackbarButton[]; + } + + let lastSnackbarId = 0; + + export function showSnackbar(snackbar: SnackbarInfo) { + lastSnackbarId += 1; + openedSnackbars.update(x => [ + ...x, + { + ...snackbar, + id: lastSnackbarId, + }, + ]); + } + + export function showSnackbarSuccess(message: string) { + showSnackbar({ + message, + icon: 'img ok', + allowClose: true, + autoClose: true, + }); + } + +// showSnackbar({ +// icon: 'img ok', +// message: 'Test snackbar', +// allowClose: true, +// }); +// showSnackbar({ +// icon: 'img ok', +// message: 'Auto close', +// autoClose: true, +// }); +// showSnackbar({ +// icon: 'img warn', +// message: 'Buttons', +// buttons: [{ label: 'OK', onClick: () => console.log('OK') }], +// }); + + + + + +
+
+ + {message} +
+ + {#if allowClose} +
+ +
+ {/if} + + {#if buttons?.length > 0} +
+ {#each buttons as button} +
+ +
+ {/each} +
+ {/if} +
+ +