-
Notifications
You must be signed in to change notification settings - Fork 43
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
8 changed files
with
156 additions
and
148 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,61 +1,104 @@ | ||
<script context="module"> | ||
// import { writable } from 'svelte/store' | ||
|
||
// export let noticesTop | ||
// export let noticesBottom | ||
export const notices = {} | ||
export function fitlerProps(props) { | ||
const { active, type, position, duration } = props | ||
return { active, type, position, duration } | ||
} | ||
</script> | ||
|
||
<script> | ||
// import { onMount } from 'svelte' | ||
|
||
// const div = () => document.createElement('div') | ||
|
||
// onMount(() => { | ||
// if (!noticesTop) { | ||
// noticesTop = div() | ||
// noticesTop.className = 'notices is-top' | ||
// document.body.appendChild(noticesTop) | ||
// } | ||
// if (!noticesBottom) { | ||
// noticesBottom = div() | ||
// noticesBottom.className = 'notices is-bottom' | ||
// document.body.appendChild(noticesBottom) | ||
// } | ||
// }) | ||
import { createEventDispatcher, onDestroy, onMount } from 'svelte' | ||
import { fly, fade } from 'svelte/transition' | ||
import Notices, { notices } from './Notices.svelte' | ||
|
||
const dispatch = createEventDispatcher() | ||
|
||
export let active = true | ||
export let type = 'is-dark' | ||
export let position = 'is-top' | ||
export let duration = 2000 | ||
|
||
let el | ||
let parent | ||
let timer | ||
const div = () => document.createElement('div') | ||
|
||
$: transitionY = ~position.indexOf('is-top') ? -200 : 200 | ||
|
||
function close() { | ||
active = false | ||
} | ||
|
||
function remove() { | ||
clearTimeout(timer) | ||
|
||
// Just making sure | ||
active = false | ||
|
||
dispatch('destroyed') | ||
} | ||
|
||
function setupContainers() { | ||
if (!notices.top) { | ||
notices.top = div() | ||
notices.top.className = 'notices is-top' | ||
document.body.appendChild(notices.top) | ||
} | ||
if (!notices.bottom) { | ||
notices.bottom = div() | ||
notices.bottom.className = 'notices is-bottom' | ||
document.body.appendChild(notices.bottom) | ||
} | ||
} | ||
|
||
function chooseParent() { | ||
parent = notices.top | ||
if (position && position.indexOf('is-bottom') === 0) parent = notices.bottom | ||
|
||
// el.parentNode.removeChild(el) | ||
parent.insertAdjacentElement('afterbegin', el) | ||
} | ||
|
||
onMount(() => { | ||
setupContainers() | ||
chooseParent() | ||
|
||
timer = setTimeout(() => { | ||
close() | ||
}, duration) | ||
}) | ||
</script> | ||
|
||
<style lang="sass"> | ||
:global(.notices) { | ||
position: fixed; | ||
top: 0; | ||
left: 0; | ||
right: 0; | ||
bottom: 0; | ||
overflow: hidden; | ||
padding: 3em; | ||
z-index: 1000; | ||
pointer-events: none; | ||
display: flex; | ||
|
||
&.is-top { | ||
flex-direction: column; | ||
} | ||
.notice { | ||
display: inline-flex; | ||
pointer-events: auto; | ||
|
||
&.is-top, | ||
&.is-bottom { | ||
flex-direction: column-reverse; | ||
align-self: center; | ||
} | ||
|
||
[class*='has-background-'] * { | ||
color: transparent !important; | ||
filter: invert(1) brightness(2.5) grayscale(1) contrast(9); | ||
background: inherit; | ||
background-clip: text !important; | ||
-webkit-background-clip: text !important; | ||
&.is-top-left, | ||
&.is-bottom-left { | ||
align-self: flex-start; | ||
} | ||
|
||
&.is-top-right, | ||
&.is-bottom-right { | ||
align-self: flex-end; | ||
} | ||
} | ||
</style> | ||
|
||
<div class="notice"> | ||
<slot /> | ||
</div> | ||
{#if active} | ||
<div | ||
class="notice {position}" | ||
aria-hidden={!active} | ||
in:fly={{ y: transitionY }} | ||
out:fade | ||
on:outroend={remove} | ||
bind:this={el}> | ||
|
||
<slot /> | ||
</div> | ||
{/if} |
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,36 @@ | ||
<script context="module"> | ||
export const notices = {} | ||
</script> | ||
|
||
<style lang="sass"> | ||
:global(.notices) { | ||
position: fixed; | ||
top: 0; | ||
left: 0; | ||
right: 0; | ||
bottom: 0; | ||
overflow: hidden; | ||
padding: 3em; | ||
z-index: 1000; | ||
pointer-events: none; | ||
display: flex; | ||
|
||
&.is-top { | ||
flex-direction: column; | ||
} | ||
|
||
&.is-bottom { | ||
flex-direction: column-reverse; | ||
} | ||
|
||
[class*='has-background-'] * { | ||
color: transparent !important; | ||
filter: invert(1) brightness(2.5) grayscale(1) contrast(9); | ||
background: inherit; | ||
background-clip: text !important; | ||
-webkit-background-clip: text !important; | ||
} | ||
} | ||
</style> | ||
|
||
<div class="notice" /> |
Oops, something went wrong.