Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

variable width using css custom properties #7

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions src/Notifications.svelte
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<ul class="toasts">
<ul class="toasts" bind:this={toastsElement}>
{#each toasts as toast (toast.id)}
<li class="toast" style="background: {toast.background};" out:animateOut>
<div class="content">
Expand Down Expand Up @@ -27,7 +27,7 @@
:global(.toasts) > .toast {
position: relative;
margin: 10px;
min-width: 40vw;
min-width: var(--width);
position: relative;
animation: animate-in 350ms forwards;
color: #fff;
Expand Down Expand Up @@ -75,15 +75,15 @@
transform: scale(1.15) translateY(20px);
}
100% {
width: 40vw;
width: var(--width);
opacity: 1;
transform: scale(1) translateY(0);
}
}

@keyframes shrink {
0% {
width: 40vw;
width: var(--width);
}
100% {
width: 0;
Expand All @@ -104,12 +104,24 @@
default: '#aaaaaa'
}

export let timeout = 3000
export let options;

const DEFAULT_OPTIONS = {
timeout: 3000,
width: '40vw'
}

$: o = Object.assign({}, DEFAULT_OPTIONS, options || {});

let count = 0
let toasts = [ ]
let toasts = [ ]
let toastsElement;
let unsubscribe

onMount(() => {
toastsElement.style.setProperty('--width', o.width);
});

function animateOut(node, { delay = 0, duration = 300 }) {
function vhTOpx (value) {
var w = window,
Expand All @@ -135,7 +147,7 @@
id: count,
msg,
background,
timeout: to || timeout,
timeout: to || o.timeout,
width: '100%'
}, ...toasts];
count = count + 1
Expand Down