forked from dineug/erd-editor
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
446 additions
and
46 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
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,68 @@ | ||
import { css } from '@/core/tagged'; | ||
|
||
export const ToastBarStyle = css` | ||
.vuerd-toast-bar { | ||
position: absolute; | ||
z-index: 9999999; | ||
right: 50px; | ||
bottom: 50px; | ||
display: flex; | ||
flex-direction: column; | ||
} | ||
.vuerd-toast-bar-container { | ||
padding: 8px 16px 16px 16px; | ||
margin-top: 20px; | ||
width: 200px; | ||
box-shadow: 0 0 6px 0 black; | ||
background-color: var(--vuerd-color-contextmenu); | ||
color: var(--vuerd-color-font); | ||
fill: var(--vuerd-color-font); | ||
animation: showMove 0.3s ease; | ||
} | ||
.vuerd-toast-bar-header { | ||
display: flex; | ||
margin-bottom: 10px; | ||
} | ||
.vuerd-toast-bar-body { | ||
} | ||
.vuerd-btn { | ||
color: var(--vuerd-color-font-active); | ||
background-color: var(--vuerd-color-contextmenu); | ||
cursor: pointer; | ||
padding: 5px; | ||
display: inline-block; | ||
} | ||
.vuerd-btn:hover { | ||
background-color: var(--vuerd-color-contextmenu-active); | ||
} | ||
.vuerd-button { | ||
cursor: pointer; | ||
margin-left: auto; | ||
} | ||
.vuerd-button:hover { | ||
fill: var(--vuerd-color-font-active); | ||
} | ||
/* animation flip */ | ||
.vuerd-toast-bar-container-move { | ||
transition: transform 0.3s; | ||
} | ||
@keyframes showMove { | ||
0% { | ||
transform: translateY(30px); | ||
opacity: 0; | ||
} | ||
100% { | ||
transform: translateY(0); | ||
opacity: 1; | ||
} | ||
} | ||
`; |
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,102 @@ | ||
import { | ||
beforeMount, | ||
defineComponent, | ||
FunctionalComponent, | ||
html, | ||
observable, | ||
TemplateResult, | ||
} from '@vuerd/lit-observable'; | ||
import { repeat } from 'lit-html/directives/repeat'; | ||
|
||
import { ToastBarStyle } from '@/components/ToastBar.style'; | ||
import { getIndex, uuid } from '@/core/helper'; | ||
import { Bus } from '@/core/helper/eventBus.helper'; | ||
import { useContext } from '@/core/hooks/context.hook'; | ||
import { useFlipAnimation } from '@/core/hooks/flipAnimation.hook'; | ||
import { useUnmounted } from '@/core/hooks/unmounted.hook'; | ||
|
||
declare global { | ||
interface HTMLElementTagNameMap { | ||
'vuerd-toast-bar': ToastBarElement; | ||
} | ||
} | ||
|
||
export interface ToastBarOptions { | ||
id: string; | ||
close: Promise<any>; | ||
headerTpl?: TemplateResult | null; | ||
bodyTpl?: TemplateResult | null; | ||
} | ||
|
||
export interface ToastBarProps {} | ||
|
||
export interface ToastBarElement extends ToastBarProps, HTMLElement {} | ||
|
||
const DEFAULT_TIME = 1000 * 5; | ||
|
||
const ToastBar: FunctionalComponent<ToastBarProps, ToastBarElement> = ( | ||
props, | ||
ctx | ||
) => { | ||
const contextRef = useContext(ctx); | ||
const { unmountedGroup } = useUnmounted(); | ||
const state = observable({ | ||
toastBars: [] as ToastBarOptions[], | ||
}); | ||
useFlipAnimation( | ||
ctx, | ||
'.vuerd-toast-bar-container', | ||
'vuerd-toast-bar-container-move' | ||
); | ||
|
||
const onClose = (toastBar: ToastBarOptions) => { | ||
const index = getIndex(state.toastBars, toastBar.id); | ||
index !== -1 && state.toastBars.splice(index, 1); | ||
}; | ||
|
||
const addToastBar = (options: ToastBarOptions) => { | ||
const toastBar = Object.assign( | ||
{ | ||
close: new Promise(resolve => setTimeout(resolve, DEFAULT_TIME)), | ||
}, | ||
options, | ||
{ id: uuid() } | ||
); | ||
state.toastBars.push(toastBar); | ||
toastBar.close.finally(() => onClose(toastBar)); | ||
}; | ||
|
||
beforeMount(() => { | ||
const { eventBus } = contextRef.value; | ||
|
||
unmountedGroup.push(eventBus.on(Bus.ToastBar.add).subscribe(addToastBar)); | ||
}); | ||
|
||
return () => html` | ||
<div class="vuerd-toast-bar"> | ||
${repeat( | ||
state.toastBars, | ||
toastBar => toastBar.id, | ||
toastBar => html` | ||
<div class="vuerd-toast-bar-container"> | ||
<div class="vuerd-toast-bar-header"> | ||
${toastBar.headerTpl} | ||
<vuerd-icon | ||
class="vuerd-button" | ||
name="times" | ||
size="12" | ||
@click=${() => onClose(toastBar)} | ||
></vuerd-icon> | ||
</div> | ||
<div class="vuerd-toast-bar-body">${toastBar.bodyTpl}</div> | ||
</div> | ||
` | ||
)} | ||
</div> | ||
`; | ||
}; | ||
|
||
defineComponent('vuerd-toast-bar', { | ||
style: ToastBarStyle, | ||
render: ToastBar, | ||
}); |
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
Oops, something went wrong.