Notify examples.
Useful notification flows to try, understand and adapt. Every example includes the live package and complete HTML / CDN and Package / ESM source.
Read the outcome on the page as well as in the toast. Previews share one toaster; the active example controls its preferences. Keyboard, swipe and reduced-motion behavior come from Notify.
A save worth confirming
Profile settings
A little more like you.Update your public display name. Nothing leaves this page.
Your profile is up to date.
A loading notification becomes a success on the same id. The saved name stays visible in the form.
Explore the code
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>A save worth confirming</title>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@samline/notify@5.0.1/dist/style.css"
/>
<link rel="stylesheet" href="./style.css" />
</head>
<body>
<main
style="max-width: 48rem; margin: 2rem auto; padding: 1rem; font-family: system-ui, sans-serif"
>
<section
class="notify-demo"
data-notify-demo
data-preset="save"
aria-label="Profile settings"
>
<p class="notify-demo-eyebrow">Profile settings</p>
<strong class="notify-demo-heading">A little more like you.</strong>
<p class="notify-demo-description">
Update your public display name. Nothing leaves this page.
</p>
<label class="notify-demo-field"
>Display name<input
type="text"
value="Nora Quinn"
required
maxlength="60"
autocomplete="name"
/></label>
<p class="notify-demo-result" data-demo-result role="status">Your profile is up to date.</p>
<div class="notify-demo-actions">
<button type="button" data-demo-action>Save changes</button>
<button type="button" data-demo-reset>Reset this preview</button>
</div>
</section>
</main>
<script src="https://cdn.jsdelivr.net/npm/@samline/notify@5.0.1/dist/browser/notify.global.js"></script>
<script src="./main.js"></script>
</body>
</html>
/* Demo form only. Toast appearance and motion come from @samline/notify/style.css. */
.notify-demo {
display: grid;
gap: 1rem;
min-width: 0;
color: #26232b;
}
.notify-demo-eyebrow {
font: 0.625rem/1.6 monospace;
letter-spacing: 0.12em;
text-transform: uppercase;
color: #655d68;
}
.notify-demo-heading {
font-size: clamp(1.4rem, 3vw, 1.9rem);
line-height: 1.25;
font-weight: 500;
letter-spacing: -0.035em;
}
.notify-demo-description {
max-width: 45rem;
color: #5f5763;
line-height: 1.7;
}
.notify-demo p {
margin: 0;
}
.notify-demo-field {
display: grid;
gap: 0.5rem;
min-width: 0;
max-width: 28rem;
color: #5f5763;
font-size: 0.8125rem;
}
.notify-demo-field input {
display: block;
box-sizing: border-box;
min-width: 0;
width: 100%;
min-height: 3.125rem;
padding: 0.75rem 1rem;
font:
400 1rem/1.5 system-ui,
sans-serif;
color: #26232b;
background: #f4f2f7;
border: 0.0625rem solid #b7adb9;
border-radius: 0.5rem;
}
.notify-demo-field input {
cursor: text;
}
.notify-demo-field input:disabled {
opacity: 0.5;
cursor: not-allowed;
}
@media (hover: hover) {
.notify-demo-field input:enabled:hover {
border-color: #8d7a98;
}
}
.notify-demo-result {
min-height: 1.5rem;
font-size: 0.8125rem;
color: #5f5763;
}
.notify-demo-actions {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 0.625rem;
padding-top: 0.5rem;
}
.notify-demo-actions button {
display: inline-flex;
align-items: center;
justify-content: center;
box-sizing: border-box;
min-height: 3.125rem;
padding: 0.5rem 1.4rem;
font:
500 0.875rem/1.5 system-ui,
sans-serif;
letter-spacing: -0.01em;
cursor: pointer;
border: 0.0625rem solid #b7adb9;
border-radius: 0.875rem;
color: #26232b;
background: #f4f2f7;
}
.notify-demo-actions [data-demo-action] {
background: #b45309;
border-color: transparent;
color: #fff;
}
.notify-demo-actions [data-demo-reset] {
min-height: 2.5rem;
padding-inline: 1rem;
border-radius: 624.9375rem;
color: #5f5763;
border-color: #b7adb9;
background: transparent;
}
.notify-demo-actions button:disabled {
opacity: 0.5;
cursor: not-allowed;
}
@media (hover: hover) {
.notify-demo-actions button:enabled:hover {
background: #e8e5ed;
border-color: #8d7a98;
}
.notify-demo-actions [data-demo-action]:enabled:hover {
background: #92400e;
border-color: transparent;
}
.notify-demo-actions [data-demo-reset]:enabled:hover {
color: #b45309;
background: #fef3c7;
}
}
.notify-demo :focus-visible {
outline: 0.125rem solid #b45309;
outline-offset: 0.1875rem;
}
.notify-demo [hidden] {
display: none;
}
.notify-demo-actions button {
overflow-wrap: anywhere;
max-width: 100%;
}
const notify = window.Notify
const copy = { saving: 'Saving your profile…', saved: 'Profile saved' }
const saveDemo = (element, notify, copy, signal) => {
const input = element.querySelector('input')
const action = element.querySelector('[data-demo-action]')
const result = element.querySelector('[data-demo-result]')
const initial = result.textContent
let pending = new AbortController()
action.addEventListener(
'click',
() => {
const name = input.value.trim()
if (!name) return input.reportValidity()
notify.createToaster({ richColors: true, closeButton: true })
action.disabled = true
const saving = wait(1200, pending.signal).then(done => {
if (!done) throw new DOMException('Reset', 'AbortError')
return name
})
notify.toast.promise(saving, {
loading: copy.saving,
success: saved => {
result.textContent = `${copy.saved}: ${saved}`
action.disabled = false
return { message: copy.saved, description: saved }
},
})
},
{ signal }
)
element.querySelector('[data-demo-reset]').addEventListener(
'click',
() => {
pending.abort()
pending = new AbortController()
notify.toast.dismiss()
action.disabled = false
result.textContent = initial
},
{ signal }
)
}
// Resolves true after `ms`, or false as soon as `signal` aborts.
const wait = (ms, signal) =>
new Promise(resolve => {
const timer = setTimeout(resolve, ms, true)
signal.addEventListener(
'abort',
() => {
clearTimeout(timer)
resolve(false)
},
{ once: true }
)
})
saveDemo(document.querySelector('[data-notify-demo]'), notify, copy)
// A page that is leaving no longer needs its toaster.
window.addEventListener('pagehide', event => {
if (!event.persisted) notify.destroyToaster()
})
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>A save worth confirming</title>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@samline/notify@5.0.1/dist/style.css"
/>
<style>
/* Demo form only. Toast appearance and motion come from @samline/notify/style.css. */
.notify-demo {
display: grid;
gap: 1rem;
min-width: 0;
color: #26232b;
}
.notify-demo-eyebrow {
font: 0.625rem/1.6 monospace;
letter-spacing: 0.12em;
text-transform: uppercase;
color: #655d68;
}
.notify-demo-heading {
font-size: clamp(1.4rem, 3vw, 1.9rem);
line-height: 1.25;
font-weight: 500;
letter-spacing: -0.035em;
}
.notify-demo-description {
max-width: 45rem;
color: #5f5763;
line-height: 1.7;
}
.notify-demo p {
margin: 0;
}
.notify-demo-field {
display: grid;
gap: 0.5rem;
min-width: 0;
max-width: 28rem;
color: #5f5763;
font-size: 0.8125rem;
}
.notify-demo-field input {
display: block;
box-sizing: border-box;
min-width: 0;
width: 100%;
min-height: 3.125rem;
padding: 0.75rem 1rem;
font:
400 1rem/1.5 system-ui,
sans-serif;
color: #26232b;
background: #f4f2f7;
border: 0.0625rem solid #b7adb9;
border-radius: 0.5rem;
}
.notify-demo-field input {
cursor: text;
}
.notify-demo-field input:disabled {
opacity: 0.5;
cursor: not-allowed;
}
@media (hover: hover) {
.notify-demo-field input:enabled:hover {
border-color: #8d7a98;
}
}
.notify-demo-result {
min-height: 1.5rem;
font-size: 0.8125rem;
color: #5f5763;
}
.notify-demo-actions {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 0.625rem;
padding-top: 0.5rem;
}
.notify-demo-actions button {
display: inline-flex;
align-items: center;
justify-content: center;
box-sizing: border-box;
min-height: 3.125rem;
padding: 0.5rem 1.4rem;
font:
500 0.875rem/1.5 system-ui,
sans-serif;
letter-spacing: -0.01em;
cursor: pointer;
border: 0.0625rem solid #b7adb9;
border-radius: 0.875rem;
color: #26232b;
background: #f4f2f7;
}
.notify-demo-actions [data-demo-action] {
background: #b45309;
border-color: transparent;
color: #fff;
}
.notify-demo-actions [data-demo-reset] {
min-height: 2.5rem;
padding-inline: 1rem;
border-radius: 624.9375rem;
color: #5f5763;
border-color: #b7adb9;
background: transparent;
}
.notify-demo-actions button:disabled {
opacity: 0.5;
cursor: not-allowed;
}
@media (hover: hover) {
.notify-demo-actions button:enabled:hover {
background: #e8e5ed;
border-color: #8d7a98;
}
.notify-demo-actions [data-demo-action]:enabled:hover {
background: #92400e;
border-color: transparent;
}
.notify-demo-actions [data-demo-reset]:enabled:hover {
color: #b45309;
background: #fef3c7;
}
}
.notify-demo :focus-visible {
outline: 0.125rem solid #b45309;
outline-offset: 0.1875rem;
}
.notify-demo [hidden] {
display: none;
}
.notify-demo-actions button {
overflow-wrap: anywhere;
max-width: 100%;
}
</style>
</head>
<body>
<main
style="max-width: 48rem; margin: 2rem auto; padding: 1rem; font-family: system-ui, sans-serif"
>
<section
class="notify-demo"
data-notify-demo
data-preset="save"
aria-label="Profile settings"
>
<p class="notify-demo-eyebrow">Profile settings</p>
<strong class="notify-demo-heading">A little more like you.</strong>
<p class="notify-demo-description">
Update your public display name. Nothing leaves this page.
</p>
<label class="notify-demo-field"
>Display name<input
type="text"
value="Nora Quinn"
required
maxlength="60"
autocomplete="name"
/></label>
<p class="notify-demo-result" data-demo-result role="status">Your profile is up to date.</p>
<div class="notify-demo-actions">
<button type="button" data-demo-action>Save changes</button>
<button type="button" data-demo-reset>Reset this preview</button>
</div>
</section>
</main>
<script src="https://cdn.jsdelivr.net/npm/@samline/notify@5.0.1/dist/browser/notify.global.js"></script>
<script>
const notify = window.Notify
const copy = { saving: 'Saving your profile…', saved: 'Profile saved' }
const saveDemo = (element, notify, copy, signal) => {
const input = element.querySelector('input')
const action = element.querySelector('[data-demo-action]')
const result = element.querySelector('[data-demo-result]')
const initial = result.textContent
let pending = new AbortController()
action.addEventListener(
'click',
() => {
const name = input.value.trim()
if (!name) return input.reportValidity()
notify.createToaster({ richColors: true, closeButton: true })
action.disabled = true
const saving = wait(1200, pending.signal).then(done => {
if (!done) throw new DOMException('Reset', 'AbortError')
return name
})
notify.toast.promise(saving, {
loading: copy.saving,
success: saved => {
result.textContent = `${copy.saved}: ${saved}`
action.disabled = false
return { message: copy.saved, description: saved }
},
})
},
{ signal }
)
element.querySelector('[data-demo-reset]').addEventListener(
'click',
() => {
pending.abort()
pending = new AbortController()
notify.toast.dismiss()
action.disabled = false
result.textContent = initial
},
{ signal }
)
}
// Resolves true after `ms`, or false as soon as `signal` aborts.
const wait = (ms, signal) =>
new Promise(resolve => {
const timer = setTimeout(resolve, ms, true)
signal.addEventListener(
'abort',
() => {
clearTimeout(timer)
resolve(false)
},
{ once: true }
)
})
saveDemo(document.querySelector('[data-notify-demo]'), notify, copy)
// A page that is leaving no longer needs its toaster.
window.addEventListener('pagehide', event => {
if (!event.persisted) notify.destroyToaster()
})
</script>
</body>
</html>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>A save worth confirming</title>
</head>
<body>
<main
style="max-width: 48rem; margin: 2rem auto; padding: 1rem; font-family: system-ui, sans-serif"
>
<section
class="notify-demo"
data-notify-demo
data-preset="save"
aria-label="Profile settings"
>
<p class="notify-demo-eyebrow">Profile settings</p>
<strong class="notify-demo-heading">A little more like you.</strong>
<p class="notify-demo-description">
Update your public display name. Nothing leaves this page.
</p>
<label class="notify-demo-field"
>Display name<input
type="text"
value="Nora Quinn"
required
maxlength="60"
autocomplete="name"
/></label>
<p class="notify-demo-result" data-demo-result role="status">Your profile is up to date.</p>
<div class="notify-demo-actions">
<button type="button" data-demo-action>Save changes</button>
<button type="button" data-demo-reset>Reset this preview</button>
</div>
</section>
</main>
<script type="module" src="./main.js"></script>
</body>
</html>
/* Demo form only. Toast appearance and motion come from @samline/notify/style.css. */
.notify-demo {
display: grid;
gap: 1rem;
min-width: 0;
color: #26232b;
}
.notify-demo-eyebrow {
font: 0.625rem/1.6 monospace;
letter-spacing: 0.12em;
text-transform: uppercase;
color: #655d68;
}
.notify-demo-heading {
font-size: clamp(1.4rem, 3vw, 1.9rem);
line-height: 1.25;
font-weight: 500;
letter-spacing: -0.035em;
}
.notify-demo-description {
max-width: 45rem;
color: #5f5763;
line-height: 1.7;
}
.notify-demo p {
margin: 0;
}
.notify-demo-field {
display: grid;
gap: 0.5rem;
min-width: 0;
max-width: 28rem;
color: #5f5763;
font-size: 0.8125rem;
}
.notify-demo-field input {
display: block;
box-sizing: border-box;
min-width: 0;
width: 100%;
min-height: 3.125rem;
padding: 0.75rem 1rem;
font:
400 1rem/1.5 system-ui,
sans-serif;
color: #26232b;
background: #f4f2f7;
border: 0.0625rem solid #b7adb9;
border-radius: 0.5rem;
}
.notify-demo-field input {
cursor: text;
}
.notify-demo-field input:disabled {
opacity: 0.5;
cursor: not-allowed;
}
@media (hover: hover) {
.notify-demo-field input:enabled:hover {
border-color: #8d7a98;
}
}
.notify-demo-result {
min-height: 1.5rem;
font-size: 0.8125rem;
color: #5f5763;
}
.notify-demo-actions {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 0.625rem;
padding-top: 0.5rem;
}
.notify-demo-actions button {
display: inline-flex;
align-items: center;
justify-content: center;
box-sizing: border-box;
min-height: 3.125rem;
padding: 0.5rem 1.4rem;
font:
500 0.875rem/1.5 system-ui,
sans-serif;
letter-spacing: -0.01em;
cursor: pointer;
border: 0.0625rem solid #b7adb9;
border-radius: 0.875rem;
color: #26232b;
background: #f4f2f7;
}
.notify-demo-actions [data-demo-action] {
background: #b45309;
border-color: transparent;
color: #fff;
}
.notify-demo-actions [data-demo-reset] {
min-height: 2.5rem;
padding-inline: 1rem;
border-radius: 624.9375rem;
color: #5f5763;
border-color: #b7adb9;
background: transparent;
}
.notify-demo-actions button:disabled {
opacity: 0.5;
cursor: not-allowed;
}
@media (hover: hover) {
.notify-demo-actions button:enabled:hover {
background: #e8e5ed;
border-color: #8d7a98;
}
.notify-demo-actions [data-demo-action]:enabled:hover {
background: #92400e;
border-color: transparent;
}
.notify-demo-actions [data-demo-reset]:enabled:hover {
color: #b45309;
background: #fef3c7;
}
}
.notify-demo :focus-visible {
outline: 0.125rem solid #b45309;
outline-offset: 0.1875rem;
}
.notify-demo [hidden] {
display: none;
}
.notify-demo-actions button {
overflow-wrap: anywhere;
max-width: 100%;
}
import { browser as notify } from '@samline/notify'
import '@samline/notify/style.css'
import './style.css'
const copy = { saving: 'Saving your profile…', saved: 'Profile saved' }
const saveDemo = (element, notify, copy, signal) => {
const input = element.querySelector('input')
const action = element.querySelector('[data-demo-action]')
const result = element.querySelector('[data-demo-result]')
const initial = result.textContent
let pending = new AbortController()
action.addEventListener(
'click',
() => {
const name = input.value.trim()
if (!name) return input.reportValidity()
notify.createToaster({ richColors: true, closeButton: true })
action.disabled = true
const saving = wait(1200, pending.signal).then(done => {
if (!done) throw new DOMException('Reset', 'AbortError')
return name
})
notify.toast.promise(saving, {
loading: copy.saving,
success: saved => {
result.textContent = `${copy.saved}: ${saved}`
action.disabled = false
return { message: copy.saved, description: saved }
},
})
},
{ signal }
)
element.querySelector('[data-demo-reset]').addEventListener(
'click',
() => {
pending.abort()
pending = new AbortController()
notify.toast.dismiss()
action.disabled = false
result.textContent = initial
},
{ signal }
)
}
// Resolves true after `ms`, or false as soon as `signal` aborts.
const wait = (ms, signal) =>
new Promise(resolve => {
const timer = setTimeout(resolve, ms, true)
signal.addEventListener(
'abort',
() => {
clearTimeout(timer)
resolve(false)
},
{ once: true }
)
})
saveDemo(document.querySelector('[data-notify-demo]'), notify, copy)
// A page that is leaving no longer needs its toaster.
window.addEventListener('pagehide', event => {
if (!event.persisted) notify.destroyToaster()
})
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>A save worth confirming</title>
<style>
/* Demo form only. Toast appearance and motion come from @samline/notify/style.css. */
.notify-demo {
display: grid;
gap: 1rem;
min-width: 0;
color: #26232b;
}
.notify-demo-eyebrow {
font: 0.625rem/1.6 monospace;
letter-spacing: 0.12em;
text-transform: uppercase;
color: #655d68;
}
.notify-demo-heading {
font-size: clamp(1.4rem, 3vw, 1.9rem);
line-height: 1.25;
font-weight: 500;
letter-spacing: -0.035em;
}
.notify-demo-description {
max-width: 45rem;
color: #5f5763;
line-height: 1.7;
}
.notify-demo p {
margin: 0;
}
.notify-demo-field {
display: grid;
gap: 0.5rem;
min-width: 0;
max-width: 28rem;
color: #5f5763;
font-size: 0.8125rem;
}
.notify-demo-field input {
display: block;
box-sizing: border-box;
min-width: 0;
width: 100%;
min-height: 3.125rem;
padding: 0.75rem 1rem;
font:
400 1rem/1.5 system-ui,
sans-serif;
color: #26232b;
background: #f4f2f7;
border: 0.0625rem solid #b7adb9;
border-radius: 0.5rem;
}
.notify-demo-field input {
cursor: text;
}
.notify-demo-field input:disabled {
opacity: 0.5;
cursor: not-allowed;
}
@media (hover: hover) {
.notify-demo-field input:enabled:hover {
border-color: #8d7a98;
}
}
.notify-demo-result {
min-height: 1.5rem;
font-size: 0.8125rem;
color: #5f5763;
}
.notify-demo-actions {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 0.625rem;
padding-top: 0.5rem;
}
.notify-demo-actions button {
display: inline-flex;
align-items: center;
justify-content: center;
box-sizing: border-box;
min-height: 3.125rem;
padding: 0.5rem 1.4rem;
font:
500 0.875rem/1.5 system-ui,
sans-serif;
letter-spacing: -0.01em;
cursor: pointer;
border: 0.0625rem solid #b7adb9;
border-radius: 0.875rem;
color: #26232b;
background: #f4f2f7;
}
.notify-demo-actions [data-demo-action] {
background: #b45309;
border-color: transparent;
color: #fff;
}
.notify-demo-actions [data-demo-reset] {
min-height: 2.5rem;
padding-inline: 1rem;
border-radius: 624.9375rem;
color: #5f5763;
border-color: #b7adb9;
background: transparent;
}
.notify-demo-actions button:disabled {
opacity: 0.5;
cursor: not-allowed;
}
@media (hover: hover) {
.notify-demo-actions button:enabled:hover {
background: #e8e5ed;
border-color: #8d7a98;
}
.notify-demo-actions [data-demo-action]:enabled:hover {
background: #92400e;
border-color: transparent;
}
.notify-demo-actions [data-demo-reset]:enabled:hover {
color: #b45309;
background: #fef3c7;
}
}
.notify-demo :focus-visible {
outline: 0.125rem solid #b45309;
outline-offset: 0.1875rem;
}
.notify-demo [hidden] {
display: none;
}
.notify-demo-actions button {
overflow-wrap: anywhere;
max-width: 100%;
}
</style>
</head>
<body>
<main
style="max-width: 48rem; margin: 2rem auto; padding: 1rem; font-family: system-ui, sans-serif"
>
<section
class="notify-demo"
data-notify-demo
data-preset="save"
aria-label="Profile settings"
>
<p class="notify-demo-eyebrow">Profile settings</p>
<strong class="notify-demo-heading">A little more like you.</strong>
<p class="notify-demo-description">
Update your public display name. Nothing leaves this page.
</p>
<label class="notify-demo-field"
>Display name<input
type="text"
value="Nora Quinn"
required
maxlength="60"
autocomplete="name"
/></label>
<p class="notify-demo-result" data-demo-result role="status">Your profile is up to date.</p>
<div class="notify-demo-actions">
<button type="button" data-demo-action>Save changes</button>
<button type="button" data-demo-reset>Reset this preview</button>
</div>
</section>
</main>
<script type="module">
import { browser as notify } from '@samline/notify'
import '@samline/notify/style.css'
const copy = { saving: 'Saving your profile…', saved: 'Profile saved' }
const saveDemo = (element, notify, copy, signal) => {
const input = element.querySelector('input')
const action = element.querySelector('[data-demo-action]')
const result = element.querySelector('[data-demo-result]')
const initial = result.textContent
let pending = new AbortController()
action.addEventListener(
'click',
() => {
const name = input.value.trim()
if (!name) return input.reportValidity()
notify.createToaster({ richColors: true, closeButton: true })
action.disabled = true
const saving = wait(1200, pending.signal).then(done => {
if (!done) throw new DOMException('Reset', 'AbortError')
return name
})
notify.toast.promise(saving, {
loading: copy.saving,
success: saved => {
result.textContent = `${copy.saved}: ${saved}`
action.disabled = false
return { message: copy.saved, description: saved }
},
})
},
{ signal }
)
element.querySelector('[data-demo-reset]').addEventListener(
'click',
() => {
pending.abort()
pending = new AbortController()
notify.toast.dismiss()
action.disabled = false
result.textContent = initial
},
{ signal }
)
}
// Resolves true after `ms`, or false as soon as `signal` aborts.
const wait = (ms, signal) =>
new Promise(resolve => {
const timer = setTimeout(resolve, ms, true)
signal.addEventListener(
'abort',
() => {
clearTimeout(timer)
resolve(false)
},
{ once: true }
)
})
saveDemo(document.querySelector('[data-notify-demo]'), notify, copy)
// A page that is leaving no longer needs its toaster.
window.addEventListener('pagehide', event => {
if (!event.persisted) notify.destroyToaster()
})
</script>
</body>
</html>
Give a failed request a way back
Report delivery
Your report, ready to send.Send the October report. The first simulated request fails; retrying succeeds.
October report · Not sent
An error stays available with a real Retry action. Retry changes the local delivery receipt.
Explore the code
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Give a failed request a way back</title>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@samline/notify@5.0.1/dist/style.css"
/>
<link rel="stylesheet" href="./style.css" />
</head>
<body>
<main
style="max-width: 48rem; margin: 2rem auto; padding: 1rem; font-family: system-ui, sans-serif"
>
<section
class="notify-demo"
data-notify-demo
data-preset="retry"
aria-label="Report delivery"
>
<p class="notify-demo-eyebrow">Report delivery</p>
<strong class="notify-demo-heading">Your report, ready to send.</strong>
<p class="notify-demo-description">
Send the October report. The first simulated request fails; retrying succeeds.
</p>
<p class="notify-demo-result" data-demo-result role="status">October report · Not sent</p>
<div class="notify-demo-actions">
<button type="button" data-demo-action>Send report</button>
<button type="button" data-demo-reset>Reset this preview</button>
</div>
</section>
</main>
<script src="https://cdn.jsdelivr.net/npm/@samline/notify@5.0.1/dist/browser/notify.global.js"></script>
<script src="./main.js"></script>
</body>
</html>
/* Demo form only. Toast appearance and motion come from @samline/notify/style.css. */
.notify-demo {
display: grid;
gap: 1rem;
min-width: 0;
color: #26232b;
}
.notify-demo-eyebrow {
font: 0.625rem/1.6 monospace;
letter-spacing: 0.12em;
text-transform: uppercase;
color: #655d68;
}
.notify-demo-heading {
font-size: clamp(1.4rem, 3vw, 1.9rem);
line-height: 1.25;
font-weight: 500;
letter-spacing: -0.035em;
}
.notify-demo-description {
max-width: 45rem;
color: #5f5763;
line-height: 1.7;
}
.notify-demo p {
margin: 0;
}
.notify-demo-result {
min-height: 1.5rem;
font-size: 0.8125rem;
color: #5f5763;
}
.notify-demo-actions {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 0.625rem;
padding-top: 0.5rem;
}
.notify-demo-actions button {
display: inline-flex;
align-items: center;
justify-content: center;
box-sizing: border-box;
min-height: 3.125rem;
padding: 0.5rem 1.4rem;
font:
500 0.875rem/1.5 system-ui,
sans-serif;
letter-spacing: -0.01em;
cursor: pointer;
border: 0.0625rem solid #b7adb9;
border-radius: 0.875rem;
color: #26232b;
background: #f4f2f7;
}
.notify-demo-actions [data-demo-action] {
background: #b45309;
border-color: transparent;
color: #fff;
}
.notify-demo-actions [data-demo-reset] {
min-height: 2.5rem;
padding-inline: 1rem;
border-radius: 624.9375rem;
color: #5f5763;
border-color: #b7adb9;
background: transparent;
}
.notify-demo-actions button:disabled {
opacity: 0.5;
cursor: not-allowed;
}
@media (hover: hover) {
.notify-demo-actions button:enabled:hover {
background: #e8e5ed;
border-color: #8d7a98;
}
.notify-demo-actions [data-demo-action]:enabled:hover {
background: #92400e;
border-color: transparent;
}
.notify-demo-actions [data-demo-reset]:enabled:hover {
color: #b45309;
background: #fef3c7;
}
}
.notify-demo :focus-visible {
outline: 0.125rem solid #b45309;
outline-offset: 0.1875rem;
}
.notify-demo [hidden] {
display: none;
}
.notify-demo-actions button {
overflow-wrap: anywhere;
max-width: 100%;
}
const notify = window.Notify
const copy = {
notSent: 'October report · Delivery failed',
sendFailed: 'The report could not be sent',
retryHint: 'Your report is safe. Try sending it again.',
retry: 'Retry sending',
sent: 'October report sent',
sentHint: 'Your team can now read the report.',
}
const retryDemo = (element, notify, copy, signal) => {
const action = element.querySelector('[data-demo-action]')
const result = element.querySelector('[data-demo-result]')
const initial = result.textContent
let attempts = 0
const send = () => {
attempts += 1
if (attempts === 1) {
result.textContent = copy.notSent
notify.toast.error(copy.sendFailed, {
description: copy.retryHint,
duration: Infinity,
action: { label: copy.retry, onClick: send },
})
} else {
result.textContent = copy.sent
notify.toast.success(copy.sent, { description: copy.sentHint })
}
}
action.addEventListener(
'click',
() => {
notify.createToaster({ richColors: true, closeButton: true })
send()
},
{ signal }
)
element.querySelector('[data-demo-reset]').addEventListener(
'click',
() => {
attempts = 0
notify.toast.dismiss()
result.textContent = initial
},
{ signal }
)
}
retryDemo(document.querySelector('[data-notify-demo]'), notify, copy)
// A page that is leaving no longer needs its toaster.
window.addEventListener('pagehide', event => {
if (!event.persisted) notify.destroyToaster()
})
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Give a failed request a way back</title>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@samline/notify@5.0.1/dist/style.css"
/>
<style>
/* Demo form only. Toast appearance and motion come from @samline/notify/style.css. */
.notify-demo {
display: grid;
gap: 1rem;
min-width: 0;
color: #26232b;
}
.notify-demo-eyebrow {
font: 0.625rem/1.6 monospace;
letter-spacing: 0.12em;
text-transform: uppercase;
color: #655d68;
}
.notify-demo-heading {
font-size: clamp(1.4rem, 3vw, 1.9rem);
line-height: 1.25;
font-weight: 500;
letter-spacing: -0.035em;
}
.notify-demo-description {
max-width: 45rem;
color: #5f5763;
line-height: 1.7;
}
.notify-demo p {
margin: 0;
}
.notify-demo-result {
min-height: 1.5rem;
font-size: 0.8125rem;
color: #5f5763;
}
.notify-demo-actions {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 0.625rem;
padding-top: 0.5rem;
}
.notify-demo-actions button {
display: inline-flex;
align-items: center;
justify-content: center;
box-sizing: border-box;
min-height: 3.125rem;
padding: 0.5rem 1.4rem;
font:
500 0.875rem/1.5 system-ui,
sans-serif;
letter-spacing: -0.01em;
cursor: pointer;
border: 0.0625rem solid #b7adb9;
border-radius: 0.875rem;
color: #26232b;
background: #f4f2f7;
}
.notify-demo-actions [data-demo-action] {
background: #b45309;
border-color: transparent;
color: #fff;
}
.notify-demo-actions [data-demo-reset] {
min-height: 2.5rem;
padding-inline: 1rem;
border-radius: 624.9375rem;
color: #5f5763;
border-color: #b7adb9;
background: transparent;
}
.notify-demo-actions button:disabled {
opacity: 0.5;
cursor: not-allowed;
}
@media (hover: hover) {
.notify-demo-actions button:enabled:hover {
background: #e8e5ed;
border-color: #8d7a98;
}
.notify-demo-actions [data-demo-action]:enabled:hover {
background: #92400e;
border-color: transparent;
}
.notify-demo-actions [data-demo-reset]:enabled:hover {
color: #b45309;
background: #fef3c7;
}
}
.notify-demo :focus-visible {
outline: 0.125rem solid #b45309;
outline-offset: 0.1875rem;
}
.notify-demo [hidden] {
display: none;
}
.notify-demo-actions button {
overflow-wrap: anywhere;
max-width: 100%;
}
</style>
</head>
<body>
<main
style="max-width: 48rem; margin: 2rem auto; padding: 1rem; font-family: system-ui, sans-serif"
>
<section
class="notify-demo"
data-notify-demo
data-preset="retry"
aria-label="Report delivery"
>
<p class="notify-demo-eyebrow">Report delivery</p>
<strong class="notify-demo-heading">Your report, ready to send.</strong>
<p class="notify-demo-description">
Send the October report. The first simulated request fails; retrying succeeds.
</p>
<p class="notify-demo-result" data-demo-result role="status">October report · Not sent</p>
<div class="notify-demo-actions">
<button type="button" data-demo-action>Send report</button>
<button type="button" data-demo-reset>Reset this preview</button>
</div>
</section>
</main>
<script src="https://cdn.jsdelivr.net/npm/@samline/notify@5.0.1/dist/browser/notify.global.js"></script>
<script>
const notify = window.Notify
const copy = {
notSent: 'October report · Delivery failed',
sendFailed: 'The report could not be sent',
retryHint: 'Your report is safe. Try sending it again.',
retry: 'Retry sending',
sent: 'October report sent',
sentHint: 'Your team can now read the report.',
}
const retryDemo = (element, notify, copy, signal) => {
const action = element.querySelector('[data-demo-action]')
const result = element.querySelector('[data-demo-result]')
const initial = result.textContent
let attempts = 0
const send = () => {
attempts += 1
if (attempts === 1) {
result.textContent = copy.notSent
notify.toast.error(copy.sendFailed, {
description: copy.retryHint,
duration: Infinity,
action: { label: copy.retry, onClick: send },
})
} else {
result.textContent = copy.sent
notify.toast.success(copy.sent, { description: copy.sentHint })
}
}
action.addEventListener(
'click',
() => {
notify.createToaster({ richColors: true, closeButton: true })
send()
},
{ signal }
)
element.querySelector('[data-demo-reset]').addEventListener(
'click',
() => {
attempts = 0
notify.toast.dismiss()
result.textContent = initial
},
{ signal }
)
}
retryDemo(document.querySelector('[data-notify-demo]'), notify, copy)
// A page that is leaving no longer needs its toaster.
window.addEventListener('pagehide', event => {
if (!event.persisted) notify.destroyToaster()
})
</script>
</body>
</html>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Give a failed request a way back</title>
</head>
<body>
<main
style="max-width: 48rem; margin: 2rem auto; padding: 1rem; font-family: system-ui, sans-serif"
>
<section
class="notify-demo"
data-notify-demo
data-preset="retry"
aria-label="Report delivery"
>
<p class="notify-demo-eyebrow">Report delivery</p>
<strong class="notify-demo-heading">Your report, ready to send.</strong>
<p class="notify-demo-description">
Send the October report. The first simulated request fails; retrying succeeds.
</p>
<p class="notify-demo-result" data-demo-result role="status">October report · Not sent</p>
<div class="notify-demo-actions">
<button type="button" data-demo-action>Send report</button>
<button type="button" data-demo-reset>Reset this preview</button>
</div>
</section>
</main>
<script type="module" src="./main.js"></script>
</body>
</html>
/* Demo form only. Toast appearance and motion come from @samline/notify/style.css. */
.notify-demo {
display: grid;
gap: 1rem;
min-width: 0;
color: #26232b;
}
.notify-demo-eyebrow {
font: 0.625rem/1.6 monospace;
letter-spacing: 0.12em;
text-transform: uppercase;
color: #655d68;
}
.notify-demo-heading {
font-size: clamp(1.4rem, 3vw, 1.9rem);
line-height: 1.25;
font-weight: 500;
letter-spacing: -0.035em;
}
.notify-demo-description {
max-width: 45rem;
color: #5f5763;
line-height: 1.7;
}
.notify-demo p {
margin: 0;
}
.notify-demo-result {
min-height: 1.5rem;
font-size: 0.8125rem;
color: #5f5763;
}
.notify-demo-actions {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 0.625rem;
padding-top: 0.5rem;
}
.notify-demo-actions button {
display: inline-flex;
align-items: center;
justify-content: center;
box-sizing: border-box;
min-height: 3.125rem;
padding: 0.5rem 1.4rem;
font:
500 0.875rem/1.5 system-ui,
sans-serif;
letter-spacing: -0.01em;
cursor: pointer;
border: 0.0625rem solid #b7adb9;
border-radius: 0.875rem;
color: #26232b;
background: #f4f2f7;
}
.notify-demo-actions [data-demo-action] {
background: #b45309;
border-color: transparent;
color: #fff;
}
.notify-demo-actions [data-demo-reset] {
min-height: 2.5rem;
padding-inline: 1rem;
border-radius: 624.9375rem;
color: #5f5763;
border-color: #b7adb9;
background: transparent;
}
.notify-demo-actions button:disabled {
opacity: 0.5;
cursor: not-allowed;
}
@media (hover: hover) {
.notify-demo-actions button:enabled:hover {
background: #e8e5ed;
border-color: #8d7a98;
}
.notify-demo-actions [data-demo-action]:enabled:hover {
background: #92400e;
border-color: transparent;
}
.notify-demo-actions [data-demo-reset]:enabled:hover {
color: #b45309;
background: #fef3c7;
}
}
.notify-demo :focus-visible {
outline: 0.125rem solid #b45309;
outline-offset: 0.1875rem;
}
.notify-demo [hidden] {
display: none;
}
.notify-demo-actions button {
overflow-wrap: anywhere;
max-width: 100%;
}
import { browser as notify } from '@samline/notify'
import '@samline/notify/style.css'
import './style.css'
const copy = {
notSent: 'October report · Delivery failed',
sendFailed: 'The report could not be sent',
retryHint: 'Your report is safe. Try sending it again.',
retry: 'Retry sending',
sent: 'October report sent',
sentHint: 'Your team can now read the report.',
}
const retryDemo = (element, notify, copy, signal) => {
const action = element.querySelector('[data-demo-action]')
const result = element.querySelector('[data-demo-result]')
const initial = result.textContent
let attempts = 0
const send = () => {
attempts += 1
if (attempts === 1) {
result.textContent = copy.notSent
notify.toast.error(copy.sendFailed, {
description: copy.retryHint,
duration: Infinity,
action: { label: copy.retry, onClick: send },
})
} else {
result.textContent = copy.sent
notify.toast.success(copy.sent, { description: copy.sentHint })
}
}
action.addEventListener(
'click',
() => {
notify.createToaster({ richColors: true, closeButton: true })
send()
},
{ signal }
)
element.querySelector('[data-demo-reset]').addEventListener(
'click',
() => {
attempts = 0
notify.toast.dismiss()
result.textContent = initial
},
{ signal }
)
}
retryDemo(document.querySelector('[data-notify-demo]'), notify, copy)
// A page that is leaving no longer needs its toaster.
window.addEventListener('pagehide', event => {
if (!event.persisted) notify.destroyToaster()
})
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Give a failed request a way back</title>
<style>
/* Demo form only. Toast appearance and motion come from @samline/notify/style.css. */
.notify-demo {
display: grid;
gap: 1rem;
min-width: 0;
color: #26232b;
}
.notify-demo-eyebrow {
font: 0.625rem/1.6 monospace;
letter-spacing: 0.12em;
text-transform: uppercase;
color: #655d68;
}
.notify-demo-heading {
font-size: clamp(1.4rem, 3vw, 1.9rem);
line-height: 1.25;
font-weight: 500;
letter-spacing: -0.035em;
}
.notify-demo-description {
max-width: 45rem;
color: #5f5763;
line-height: 1.7;
}
.notify-demo p {
margin: 0;
}
.notify-demo-result {
min-height: 1.5rem;
font-size: 0.8125rem;
color: #5f5763;
}
.notify-demo-actions {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 0.625rem;
padding-top: 0.5rem;
}
.notify-demo-actions button {
display: inline-flex;
align-items: center;
justify-content: center;
box-sizing: border-box;
min-height: 3.125rem;
padding: 0.5rem 1.4rem;
font:
500 0.875rem/1.5 system-ui,
sans-serif;
letter-spacing: -0.01em;
cursor: pointer;
border: 0.0625rem solid #b7adb9;
border-radius: 0.875rem;
color: #26232b;
background: #f4f2f7;
}
.notify-demo-actions [data-demo-action] {
background: #b45309;
border-color: transparent;
color: #fff;
}
.notify-demo-actions [data-demo-reset] {
min-height: 2.5rem;
padding-inline: 1rem;
border-radius: 624.9375rem;
color: #5f5763;
border-color: #b7adb9;
background: transparent;
}
.notify-demo-actions button:disabled {
opacity: 0.5;
cursor: not-allowed;
}
@media (hover: hover) {
.notify-demo-actions button:enabled:hover {
background: #e8e5ed;
border-color: #8d7a98;
}
.notify-demo-actions [data-demo-action]:enabled:hover {
background: #92400e;
border-color: transparent;
}
.notify-demo-actions [data-demo-reset]:enabled:hover {
color: #b45309;
background: #fef3c7;
}
}
.notify-demo :focus-visible {
outline: 0.125rem solid #b45309;
outline-offset: 0.1875rem;
}
.notify-demo [hidden] {
display: none;
}
.notify-demo-actions button {
overflow-wrap: anywhere;
max-width: 100%;
}
</style>
</head>
<body>
<main
style="max-width: 48rem; margin: 2rem auto; padding: 1rem; font-family: system-ui, sans-serif"
>
<section
class="notify-demo"
data-notify-demo
data-preset="retry"
aria-label="Report delivery"
>
<p class="notify-demo-eyebrow">Report delivery</p>
<strong class="notify-demo-heading">Your report, ready to send.</strong>
<p class="notify-demo-description">
Send the October report. The first simulated request fails; retrying succeeds.
</p>
<p class="notify-demo-result" data-demo-result role="status">October report · Not sent</p>
<div class="notify-demo-actions">
<button type="button" data-demo-action>Send report</button>
<button type="button" data-demo-reset>Reset this preview</button>
</div>
</section>
</main>
<script type="module">
import { browser as notify } from '@samline/notify'
import '@samline/notify/style.css'
const copy = {
notSent: 'October report · Delivery failed',
sendFailed: 'The report could not be sent',
retryHint: 'Your report is safe. Try sending it again.',
retry: 'Retry sending',
sent: 'October report sent',
sentHint: 'Your team can now read the report.',
}
const retryDemo = (element, notify, copy, signal) => {
const action = element.querySelector('[data-demo-action]')
const result = element.querySelector('[data-demo-result]')
const initial = result.textContent
let attempts = 0
const send = () => {
attempts += 1
if (attempts === 1) {
result.textContent = copy.notSent
notify.toast.error(copy.sendFailed, {
description: copy.retryHint,
duration: Infinity,
action: { label: copy.retry, onClick: send },
})
} else {
result.textContent = copy.sent
notify.toast.success(copy.sent, { description: copy.sentHint })
}
}
action.addEventListener(
'click',
() => {
notify.createToaster({ richColors: true, closeButton: true })
send()
},
{ signal }
)
element.querySelector('[data-demo-reset]').addEventListener(
'click',
() => {
attempts = 0
notify.toast.dismiss()
result.textContent = initial
},
{ signal }
)
}
retryDemo(document.querySelector('[data-notify-demo]'), notify, copy)
// A page that is leaving no longer needs its toaster.
window.addEventListener('pagehide', event => {
if (!event.persisted) notify.destroyToaster()
})
</script>
</body>
</html>
One upload. One notification.
Asset library
Make room for the next idea.Upload campaign-cover.jpg, a 2.4 MB sample asset. Progress is simulated locally.
campaign-cover.jpg · Ready
A manual loading toast updates by id, then becomes success. Repeated clicks cannot start overlapping uploads.
Explore the code
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>One upload. One notification.</title>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@samline/notify@5.0.1/dist/style.css"
/>
<link rel="stylesheet" href="./style.css" />
</head>
<body>
<main
style="max-width: 48rem; margin: 2rem auto; padding: 1rem; font-family: system-ui, sans-serif"
>
<section class="notify-demo" data-notify-demo data-preset="upload" aria-label="Asset library">
<p class="notify-demo-eyebrow">Asset library</p>
<strong class="notify-demo-heading">Make room for the next idea.</strong>
<p class="notify-demo-description">
Upload campaign-cover.jpg, a 2.4 MB sample asset. Progress is simulated locally.
</p>
<label class="notify-demo-field"
>Upload progress<progress max="100" value="0"></progress
></label>
<p class="notify-demo-result" data-demo-result role="status">campaign-cover.jpg · Ready</p>
<div class="notify-demo-actions">
<button type="button" data-demo-action>Upload sample</button>
<button type="button" data-demo-reset>Reset this preview</button>
</div>
</section>
</main>
<script src="https://cdn.jsdelivr.net/npm/@samline/notify@5.0.1/dist/browser/notify.global.js"></script>
<script src="./main.js"></script>
</body>
</html>
/* Demo form only. Toast appearance and motion come from @samline/notify/style.css. */
.notify-demo {
display: grid;
gap: 1rem;
min-width: 0;
color: #26232b;
}
.notify-demo-eyebrow {
font: 0.625rem/1.6 monospace;
letter-spacing: 0.12em;
text-transform: uppercase;
color: #655d68;
}
.notify-demo-heading {
font-size: clamp(1.4rem, 3vw, 1.9rem);
line-height: 1.25;
font-weight: 500;
letter-spacing: -0.035em;
}
.notify-demo-description {
max-width: 45rem;
color: #5f5763;
line-height: 1.7;
}
.notify-demo p {
margin: 0;
}
.notify-demo-field {
display: grid;
gap: 0.5rem;
min-width: 0;
max-width: 28rem;
color: #5f5763;
font-size: 0.8125rem;
}
.notify-demo-field progress {
width: 100%;
accent-color: #b45309;
}
.notify-demo-result {
min-height: 1.5rem;
font-size: 0.8125rem;
color: #5f5763;
}
.notify-demo-actions {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 0.625rem;
padding-top: 0.5rem;
}
.notify-demo-actions button {
display: inline-flex;
align-items: center;
justify-content: center;
box-sizing: border-box;
min-height: 3.125rem;
padding: 0.5rem 1.4rem;
font:
500 0.875rem/1.5 system-ui,
sans-serif;
letter-spacing: -0.01em;
cursor: pointer;
border: 0.0625rem solid #b7adb9;
border-radius: 0.875rem;
color: #26232b;
background: #f4f2f7;
}
.notify-demo-actions [data-demo-action] {
background: #b45309;
border-color: transparent;
color: #fff;
}
.notify-demo-actions [data-demo-reset] {
min-height: 2.5rem;
padding-inline: 1rem;
border-radius: 624.9375rem;
color: #5f5763;
border-color: #b7adb9;
background: transparent;
}
.notify-demo-actions button:disabled {
opacity: 0.5;
cursor: not-allowed;
}
@media (hover: hover) {
.notify-demo-actions button:enabled:hover {
background: #e8e5ed;
border-color: #8d7a98;
}
.notify-demo-actions [data-demo-action]:enabled:hover {
background: #92400e;
border-color: transparent;
}
.notify-demo-actions [data-demo-reset]:enabled:hover {
color: #b45309;
background: #fef3c7;
}
}
.notify-demo :focus-visible {
outline: 0.125rem solid #b45309;
outline-offset: 0.1875rem;
}
.notify-demo [hidden] {
display: none;
}
.notify-demo-actions button {
overflow-wrap: anywhere;
max-width: 100%;
}
const notify = window.Notify
const copy = { uploading: 'Uploading…', uploaded: 'Upload complete' }
const uploadDemo = (element, notify, copy, signal) => {
const progress = element.querySelector('progress')
const action = element.querySelector('[data-demo-action]')
const result = element.querySelector('[data-demo-result]')
const initial = result.textContent
let pending = new AbortController()
action.addEventListener(
'click',
async () => {
notify.createToaster({ richColors: true, closeButton: true })
action.disabled = true
const id = notify.toast.loading(copy.uploading)
for (const percent of [25, 50, 75, 100]) {
if (!(await wait(550, pending.signal))) return
progress.value = percent
result.textContent = `${copy.uploading} ${percent}%`
if (percent < 100) notify.toast.loading(`${copy.uploading} ${percent}%`, { id })
}
// Passing the same id turns the loading toast into a success.
notify.toast.success(copy.uploaded, { id, description: 'campaign-cover.jpg' })
result.textContent = copy.uploaded
action.disabled = false
},
{ signal }
)
element.querySelector('[data-demo-reset]').addEventListener(
'click',
() => {
pending.abort()
pending = new AbortController()
notify.toast.dismiss()
progress.value = 0
action.disabled = false
result.textContent = initial
},
{ signal }
)
}
// Resolves true after `ms`, or false as soon as `signal` aborts.
const wait = (ms, signal) =>
new Promise(resolve => {
const timer = setTimeout(resolve, ms, true)
signal.addEventListener(
'abort',
() => {
clearTimeout(timer)
resolve(false)
},
{ once: true }
)
})
uploadDemo(document.querySelector('[data-notify-demo]'), notify, copy)
// A page that is leaving no longer needs its toaster.
window.addEventListener('pagehide', event => {
if (!event.persisted) notify.destroyToaster()
})
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>One upload. One notification.</title>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@samline/notify@5.0.1/dist/style.css"
/>
<style>
/* Demo form only. Toast appearance and motion come from @samline/notify/style.css. */
.notify-demo {
display: grid;
gap: 1rem;
min-width: 0;
color: #26232b;
}
.notify-demo-eyebrow {
font: 0.625rem/1.6 monospace;
letter-spacing: 0.12em;
text-transform: uppercase;
color: #655d68;
}
.notify-demo-heading {
font-size: clamp(1.4rem, 3vw, 1.9rem);
line-height: 1.25;
font-weight: 500;
letter-spacing: -0.035em;
}
.notify-demo-description {
max-width: 45rem;
color: #5f5763;
line-height: 1.7;
}
.notify-demo p {
margin: 0;
}
.notify-demo-field {
display: grid;
gap: 0.5rem;
min-width: 0;
max-width: 28rem;
color: #5f5763;
font-size: 0.8125rem;
}
.notify-demo-field progress {
width: 100%;
accent-color: #b45309;
}
.notify-demo-result {
min-height: 1.5rem;
font-size: 0.8125rem;
color: #5f5763;
}
.notify-demo-actions {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 0.625rem;
padding-top: 0.5rem;
}
.notify-demo-actions button {
display: inline-flex;
align-items: center;
justify-content: center;
box-sizing: border-box;
min-height: 3.125rem;
padding: 0.5rem 1.4rem;
font:
500 0.875rem/1.5 system-ui,
sans-serif;
letter-spacing: -0.01em;
cursor: pointer;
border: 0.0625rem solid #b7adb9;
border-radius: 0.875rem;
color: #26232b;
background: #f4f2f7;
}
.notify-demo-actions [data-demo-action] {
background: #b45309;
border-color: transparent;
color: #fff;
}
.notify-demo-actions [data-demo-reset] {
min-height: 2.5rem;
padding-inline: 1rem;
border-radius: 624.9375rem;
color: #5f5763;
border-color: #b7adb9;
background: transparent;
}
.notify-demo-actions button:disabled {
opacity: 0.5;
cursor: not-allowed;
}
@media (hover: hover) {
.notify-demo-actions button:enabled:hover {
background: #e8e5ed;
border-color: #8d7a98;
}
.notify-demo-actions [data-demo-action]:enabled:hover {
background: #92400e;
border-color: transparent;
}
.notify-demo-actions [data-demo-reset]:enabled:hover {
color: #b45309;
background: #fef3c7;
}
}
.notify-demo :focus-visible {
outline: 0.125rem solid #b45309;
outline-offset: 0.1875rem;
}
.notify-demo [hidden] {
display: none;
}
.notify-demo-actions button {
overflow-wrap: anywhere;
max-width: 100%;
}
</style>
</head>
<body>
<main
style="max-width: 48rem; margin: 2rem auto; padding: 1rem; font-family: system-ui, sans-serif"
>
<section class="notify-demo" data-notify-demo data-preset="upload" aria-label="Asset library">
<p class="notify-demo-eyebrow">Asset library</p>
<strong class="notify-demo-heading">Make room for the next idea.</strong>
<p class="notify-demo-description">
Upload campaign-cover.jpg, a 2.4 MB sample asset. Progress is simulated locally.
</p>
<label class="notify-demo-field"
>Upload progress<progress max="100" value="0"></progress
></label>
<p class="notify-demo-result" data-demo-result role="status">campaign-cover.jpg · Ready</p>
<div class="notify-demo-actions">
<button type="button" data-demo-action>Upload sample</button>
<button type="button" data-demo-reset>Reset this preview</button>
</div>
</section>
</main>
<script src="https://cdn.jsdelivr.net/npm/@samline/notify@5.0.1/dist/browser/notify.global.js"></script>
<script>
const notify = window.Notify
const copy = { uploading: 'Uploading…', uploaded: 'Upload complete' }
const uploadDemo = (element, notify, copy, signal) => {
const progress = element.querySelector('progress')
const action = element.querySelector('[data-demo-action]')
const result = element.querySelector('[data-demo-result]')
const initial = result.textContent
let pending = new AbortController()
action.addEventListener(
'click',
async () => {
notify.createToaster({ richColors: true, closeButton: true })
action.disabled = true
const id = notify.toast.loading(copy.uploading)
for (const percent of [25, 50, 75, 100]) {
if (!(await wait(550, pending.signal))) return
progress.value = percent
result.textContent = `${copy.uploading} ${percent}%`
if (percent < 100) notify.toast.loading(`${copy.uploading} ${percent}%`, { id })
}
// Passing the same id turns the loading toast into a success.
notify.toast.success(copy.uploaded, { id, description: 'campaign-cover.jpg' })
result.textContent = copy.uploaded
action.disabled = false
},
{ signal }
)
element.querySelector('[data-demo-reset]').addEventListener(
'click',
() => {
pending.abort()
pending = new AbortController()
notify.toast.dismiss()
progress.value = 0
action.disabled = false
result.textContent = initial
},
{ signal }
)
}
// Resolves true after `ms`, or false as soon as `signal` aborts.
const wait = (ms, signal) =>
new Promise(resolve => {
const timer = setTimeout(resolve, ms, true)
signal.addEventListener(
'abort',
() => {
clearTimeout(timer)
resolve(false)
},
{ once: true }
)
})
uploadDemo(document.querySelector('[data-notify-demo]'), notify, copy)
// A page that is leaving no longer needs its toaster.
window.addEventListener('pagehide', event => {
if (!event.persisted) notify.destroyToaster()
})
</script>
</body>
</html>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>One upload. One notification.</title>
</head>
<body>
<main
style="max-width: 48rem; margin: 2rem auto; padding: 1rem; font-family: system-ui, sans-serif"
>
<section class="notify-demo" data-notify-demo data-preset="upload" aria-label="Asset library">
<p class="notify-demo-eyebrow">Asset library</p>
<strong class="notify-demo-heading">Make room for the next idea.</strong>
<p class="notify-demo-description">
Upload campaign-cover.jpg, a 2.4 MB sample asset. Progress is simulated locally.
</p>
<label class="notify-demo-field"
>Upload progress<progress max="100" value="0"></progress
></label>
<p class="notify-demo-result" data-demo-result role="status">campaign-cover.jpg · Ready</p>
<div class="notify-demo-actions">
<button type="button" data-demo-action>Upload sample</button>
<button type="button" data-demo-reset>Reset this preview</button>
</div>
</section>
</main>
<script type="module" src="./main.js"></script>
</body>
</html>
/* Demo form only. Toast appearance and motion come from @samline/notify/style.css. */
.notify-demo {
display: grid;
gap: 1rem;
min-width: 0;
color: #26232b;
}
.notify-demo-eyebrow {
font: 0.625rem/1.6 monospace;
letter-spacing: 0.12em;
text-transform: uppercase;
color: #655d68;
}
.notify-demo-heading {
font-size: clamp(1.4rem, 3vw, 1.9rem);
line-height: 1.25;
font-weight: 500;
letter-spacing: -0.035em;
}
.notify-demo-description {
max-width: 45rem;
color: #5f5763;
line-height: 1.7;
}
.notify-demo p {
margin: 0;
}
.notify-demo-field {
display: grid;
gap: 0.5rem;
min-width: 0;
max-width: 28rem;
color: #5f5763;
font-size: 0.8125rem;
}
.notify-demo-field progress {
width: 100%;
accent-color: #b45309;
}
.notify-demo-result {
min-height: 1.5rem;
font-size: 0.8125rem;
color: #5f5763;
}
.notify-demo-actions {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 0.625rem;
padding-top: 0.5rem;
}
.notify-demo-actions button {
display: inline-flex;
align-items: center;
justify-content: center;
box-sizing: border-box;
min-height: 3.125rem;
padding: 0.5rem 1.4rem;
font:
500 0.875rem/1.5 system-ui,
sans-serif;
letter-spacing: -0.01em;
cursor: pointer;
border: 0.0625rem solid #b7adb9;
border-radius: 0.875rem;
color: #26232b;
background: #f4f2f7;
}
.notify-demo-actions [data-demo-action] {
background: #b45309;
border-color: transparent;
color: #fff;
}
.notify-demo-actions [data-demo-reset] {
min-height: 2.5rem;
padding-inline: 1rem;
border-radius: 624.9375rem;
color: #5f5763;
border-color: #b7adb9;
background: transparent;
}
.notify-demo-actions button:disabled {
opacity: 0.5;
cursor: not-allowed;
}
@media (hover: hover) {
.notify-demo-actions button:enabled:hover {
background: #e8e5ed;
border-color: #8d7a98;
}
.notify-demo-actions [data-demo-action]:enabled:hover {
background: #92400e;
border-color: transparent;
}
.notify-demo-actions [data-demo-reset]:enabled:hover {
color: #b45309;
background: #fef3c7;
}
}
.notify-demo :focus-visible {
outline: 0.125rem solid #b45309;
outline-offset: 0.1875rem;
}
.notify-demo [hidden] {
display: none;
}
.notify-demo-actions button {
overflow-wrap: anywhere;
max-width: 100%;
}
import { browser as notify } from '@samline/notify'
import '@samline/notify/style.css'
import './style.css'
const copy = { uploading: 'Uploading…', uploaded: 'Upload complete' }
const uploadDemo = (element, notify, copy, signal) => {
const progress = element.querySelector('progress')
const action = element.querySelector('[data-demo-action]')
const result = element.querySelector('[data-demo-result]')
const initial = result.textContent
let pending = new AbortController()
action.addEventListener(
'click',
async () => {
notify.createToaster({ richColors: true, closeButton: true })
action.disabled = true
const id = notify.toast.loading(copy.uploading)
for (const percent of [25, 50, 75, 100]) {
if (!(await wait(550, pending.signal))) return
progress.value = percent
result.textContent = `${copy.uploading} ${percent}%`
if (percent < 100) notify.toast.loading(`${copy.uploading} ${percent}%`, { id })
}
// Passing the same id turns the loading toast into a success.
notify.toast.success(copy.uploaded, { id, description: 'campaign-cover.jpg' })
result.textContent = copy.uploaded
action.disabled = false
},
{ signal }
)
element.querySelector('[data-demo-reset]').addEventListener(
'click',
() => {
pending.abort()
pending = new AbortController()
notify.toast.dismiss()
progress.value = 0
action.disabled = false
result.textContent = initial
},
{ signal }
)
}
// Resolves true after `ms`, or false as soon as `signal` aborts.
const wait = (ms, signal) =>
new Promise(resolve => {
const timer = setTimeout(resolve, ms, true)
signal.addEventListener(
'abort',
() => {
clearTimeout(timer)
resolve(false)
},
{ once: true }
)
})
uploadDemo(document.querySelector('[data-notify-demo]'), notify, copy)
// A page that is leaving no longer needs its toaster.
window.addEventListener('pagehide', event => {
if (!event.persisted) notify.destroyToaster()
})
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>One upload. One notification.</title>
<style>
/* Demo form only. Toast appearance and motion come from @samline/notify/style.css. */
.notify-demo {
display: grid;
gap: 1rem;
min-width: 0;
color: #26232b;
}
.notify-demo-eyebrow {
font: 0.625rem/1.6 monospace;
letter-spacing: 0.12em;
text-transform: uppercase;
color: #655d68;
}
.notify-demo-heading {
font-size: clamp(1.4rem, 3vw, 1.9rem);
line-height: 1.25;
font-weight: 500;
letter-spacing: -0.035em;
}
.notify-demo-description {
max-width: 45rem;
color: #5f5763;
line-height: 1.7;
}
.notify-demo p {
margin: 0;
}
.notify-demo-field {
display: grid;
gap: 0.5rem;
min-width: 0;
max-width: 28rem;
color: #5f5763;
font-size: 0.8125rem;
}
.notify-demo-field progress {
width: 100%;
accent-color: #b45309;
}
.notify-demo-result {
min-height: 1.5rem;
font-size: 0.8125rem;
color: #5f5763;
}
.notify-demo-actions {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 0.625rem;
padding-top: 0.5rem;
}
.notify-demo-actions button {
display: inline-flex;
align-items: center;
justify-content: center;
box-sizing: border-box;
min-height: 3.125rem;
padding: 0.5rem 1.4rem;
font:
500 0.875rem/1.5 system-ui,
sans-serif;
letter-spacing: -0.01em;
cursor: pointer;
border: 0.0625rem solid #b7adb9;
border-radius: 0.875rem;
color: #26232b;
background: #f4f2f7;
}
.notify-demo-actions [data-demo-action] {
background: #b45309;
border-color: transparent;
color: #fff;
}
.notify-demo-actions [data-demo-reset] {
min-height: 2.5rem;
padding-inline: 1rem;
border-radius: 624.9375rem;
color: #5f5763;
border-color: #b7adb9;
background: transparent;
}
.notify-demo-actions button:disabled {
opacity: 0.5;
cursor: not-allowed;
}
@media (hover: hover) {
.notify-demo-actions button:enabled:hover {
background: #e8e5ed;
border-color: #8d7a98;
}
.notify-demo-actions [data-demo-action]:enabled:hover {
background: #92400e;
border-color: transparent;
}
.notify-demo-actions [data-demo-reset]:enabled:hover {
color: #b45309;
background: #fef3c7;
}
}
.notify-demo :focus-visible {
outline: 0.125rem solid #b45309;
outline-offset: 0.1875rem;
}
.notify-demo [hidden] {
display: none;
}
.notify-demo-actions button {
overflow-wrap: anywhere;
max-width: 100%;
}
</style>
</head>
<body>
<main
style="max-width: 48rem; margin: 2rem auto; padding: 1rem; font-family: system-ui, sans-serif"
>
<section class="notify-demo" data-notify-demo data-preset="upload" aria-label="Asset library">
<p class="notify-demo-eyebrow">Asset library</p>
<strong class="notify-demo-heading">Make room for the next idea.</strong>
<p class="notify-demo-description">
Upload campaign-cover.jpg, a 2.4 MB sample asset. Progress is simulated locally.
</p>
<label class="notify-demo-field"
>Upload progress<progress max="100" value="0"></progress
></label>
<p class="notify-demo-result" data-demo-result role="status">campaign-cover.jpg · Ready</p>
<div class="notify-demo-actions">
<button type="button" data-demo-action>Upload sample</button>
<button type="button" data-demo-reset>Reset this preview</button>
</div>
</section>
</main>
<script type="module">
import { browser as notify } from '@samline/notify'
import '@samline/notify/style.css'
const copy = { uploading: 'Uploading…', uploaded: 'Upload complete' }
const uploadDemo = (element, notify, copy, signal) => {
const progress = element.querySelector('progress')
const action = element.querySelector('[data-demo-action]')
const result = element.querySelector('[data-demo-result]')
const initial = result.textContent
let pending = new AbortController()
action.addEventListener(
'click',
async () => {
notify.createToaster({ richColors: true, closeButton: true })
action.disabled = true
const id = notify.toast.loading(copy.uploading)
for (const percent of [25, 50, 75, 100]) {
if (!(await wait(550, pending.signal))) return
progress.value = percent
result.textContent = `${copy.uploading} ${percent}%`
if (percent < 100) notify.toast.loading(`${copy.uploading} ${percent}%`, { id })
}
// Passing the same id turns the loading toast into a success.
notify.toast.success(copy.uploaded, { id, description: 'campaign-cover.jpg' })
result.textContent = copy.uploaded
action.disabled = false
},
{ signal }
)
element.querySelector('[data-demo-reset]').addEventListener(
'click',
() => {
pending.abort()
pending = new AbortController()
notify.toast.dismiss()
progress.value = 0
action.disabled = false
result.textContent = initial
},
{ signal }
)
}
// Resolves true after `ms`, or false as soon as `signal` aborts.
const wait = (ms, signal) =>
new Promise(resolve => {
const timer = setTimeout(resolve, ms, true)
signal.addEventListener(
'abort',
() => {
clearTimeout(timer)
resolve(false)
},
{ once: true }
)
})
uploadDemo(document.querySelector('[data-notify-demo]'), notify, copy)
// A page that is leaving no longer needs its toaster.
window.addEventListener('pagehide', event => {
if (!event.persisted) notify.destroyToaster()
})
</script>
</body>
</html>
Undo that actually restores the item
Team inbox
Keep a clear inbox.Archive the launch checklist. Use Undo in the notification to bring the same item back.
Design review · Today, 10:30
Launch checklist · In your inbox
The toast action restores the item in the page. Archiving is a local preview, not a connected inbox.
Explore the code
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Undo that actually restores the item</title>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@samline/notify@5.0.1/dist/style.css"
/>
<link rel="stylesheet" href="./style.css" />
</head>
<body>
<main
style="max-width: 48rem; margin: 2rem auto; padding: 1rem; font-family: system-ui, sans-serif"
>
<section class="notify-demo" data-notify-demo data-preset="undo" aria-label="Team inbox">
<p class="notify-demo-eyebrow">Team inbox</p>
<strong class="notify-demo-heading">Keep a clear inbox.</strong>
<p class="notify-demo-description">
Archive the launch checklist. Use Undo in the notification to bring the same item back.
</p>
<div class="notify-demo-item" data-demo-item>
<svg
width="1em"
height="1em"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
>
<path d="M7 17 17 7M8 7h9v9" /></svg
><span><strong>Launch checklist</strong><br />Design review · Today, 10:30</span>
</div>
<p class="notify-demo-result" data-demo-result role="status">
Launch checklist · In your inbox
</p>
<div class="notify-demo-actions">
<button type="button" data-demo-action>Archive checklist</button>
<button type="button" data-demo-reset>Reset this preview</button>
</div>
</section>
</main>
<script src="https://cdn.jsdelivr.net/npm/@samline/notify@5.0.1/dist/browser/notify.global.js"></script>
<script src="./main.js"></script>
</body>
</html>
/* Demo form only. Toast appearance and motion come from @samline/notify/style.css. */
.notify-demo {
display: grid;
gap: 1rem;
min-width: 0;
color: #26232b;
}
.notify-demo-eyebrow {
font: 0.625rem/1.6 monospace;
letter-spacing: 0.12em;
text-transform: uppercase;
color: #655d68;
}
.notify-demo-heading {
font-size: clamp(1.4rem, 3vw, 1.9rem);
line-height: 1.25;
font-weight: 500;
letter-spacing: -0.035em;
}
.notify-demo-description {
max-width: 45rem;
color: #5f5763;
line-height: 1.7;
}
.notify-demo p {
margin: 0;
}
.notify-demo-result {
min-height: 1.5rem;
font-size: 0.8125rem;
color: #5f5763;
}
.notify-demo-item {
display: flex;
align-items: center;
gap: 1rem;
padding: 1rem;
border-block: 0.0625rem solid #cfc7d2;
font-size: 0.875rem;
line-height: 1.7;
}
.notify-demo-item[hidden] {
display: none;
}
.notify-demo-actions {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 0.625rem;
padding-top: 0.5rem;
}
.notify-demo-actions button {
display: inline-flex;
align-items: center;
justify-content: center;
box-sizing: border-box;
min-height: 3.125rem;
padding: 0.5rem 1.4rem;
font:
500 0.875rem/1.5 system-ui,
sans-serif;
letter-spacing: -0.01em;
cursor: pointer;
border: 0.0625rem solid #b7adb9;
border-radius: 0.875rem;
color: #26232b;
background: #f4f2f7;
}
.notify-demo-actions [data-demo-action] {
background: #b45309;
border-color: transparent;
color: #fff;
}
.notify-demo-actions [data-demo-reset] {
min-height: 2.5rem;
padding-inline: 1rem;
border-radius: 624.9375rem;
color: #5f5763;
border-color: #b7adb9;
background: transparent;
}
.notify-demo-actions button:disabled {
opacity: 0.5;
cursor: not-allowed;
}
@media (hover: hover) {
.notify-demo-actions button:enabled:hover {
background: #e8e5ed;
border-color: #8d7a98;
}
.notify-demo-actions [data-demo-action]:enabled:hover {
background: #92400e;
border-color: transparent;
}
.notify-demo-actions [data-demo-reset]:enabled:hover {
color: #b45309;
background: #fef3c7;
}
}
.notify-demo :focus-visible {
outline: 0.125rem solid #b45309;
outline-offset: 0.1875rem;
}
.notify-demo [hidden] {
display: none;
}
.notify-demo-actions button {
overflow-wrap: anywhere;
max-width: 100%;
}
const notify = window.Notify
const copy = {
archived: 'Launch checklist archived',
undoHint: 'You can restore it to your inbox.',
undo: 'Undo archive',
restored: 'Launch checklist restored',
}
const undoDemo = (element, notify, copy, signal) => {
const item = element.querySelector('[data-demo-item]')
const action = element.querySelector('[data-demo-action]')
const result = element.querySelector('[data-demo-result]')
const initial = result.textContent
action.addEventListener(
'click',
() => {
if (item.hidden) return
notify.createToaster({ richColors: true, closeButton: true })
item.hidden = true
result.textContent = copy.archived
notify.toast(copy.archived, {
description: copy.undoHint,
duration: 10000,
action: {
label: copy.undo,
onClick: () => {
item.hidden = false
result.textContent = copy.restored
notify.toast.success(copy.restored)
},
},
})
},
{ signal }
)
element.querySelector('[data-demo-reset]').addEventListener(
'click',
() => {
notify.toast.dismiss()
item.hidden = false
result.textContent = initial
},
{ signal }
)
}
undoDemo(document.querySelector('[data-notify-demo]'), notify, copy)
// A page that is leaving no longer needs its toaster.
window.addEventListener('pagehide', event => {
if (!event.persisted) notify.destroyToaster()
})
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Undo that actually restores the item</title>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@samline/notify@5.0.1/dist/style.css"
/>
<style>
/* Demo form only. Toast appearance and motion come from @samline/notify/style.css. */
.notify-demo {
display: grid;
gap: 1rem;
min-width: 0;
color: #26232b;
}
.notify-demo-eyebrow {
font: 0.625rem/1.6 monospace;
letter-spacing: 0.12em;
text-transform: uppercase;
color: #655d68;
}
.notify-demo-heading {
font-size: clamp(1.4rem, 3vw, 1.9rem);
line-height: 1.25;
font-weight: 500;
letter-spacing: -0.035em;
}
.notify-demo-description {
max-width: 45rem;
color: #5f5763;
line-height: 1.7;
}
.notify-demo p {
margin: 0;
}
.notify-demo-result {
min-height: 1.5rem;
font-size: 0.8125rem;
color: #5f5763;
}
.notify-demo-item {
display: flex;
align-items: center;
gap: 1rem;
padding: 1rem;
border-block: 0.0625rem solid #cfc7d2;
font-size: 0.875rem;
line-height: 1.7;
}
.notify-demo-item[hidden] {
display: none;
}
.notify-demo-actions {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 0.625rem;
padding-top: 0.5rem;
}
.notify-demo-actions button {
display: inline-flex;
align-items: center;
justify-content: center;
box-sizing: border-box;
min-height: 3.125rem;
padding: 0.5rem 1.4rem;
font:
500 0.875rem/1.5 system-ui,
sans-serif;
letter-spacing: -0.01em;
cursor: pointer;
border: 0.0625rem solid #b7adb9;
border-radius: 0.875rem;
color: #26232b;
background: #f4f2f7;
}
.notify-demo-actions [data-demo-action] {
background: #b45309;
border-color: transparent;
color: #fff;
}
.notify-demo-actions [data-demo-reset] {
min-height: 2.5rem;
padding-inline: 1rem;
border-radius: 624.9375rem;
color: #5f5763;
border-color: #b7adb9;
background: transparent;
}
.notify-demo-actions button:disabled {
opacity: 0.5;
cursor: not-allowed;
}
@media (hover: hover) {
.notify-demo-actions button:enabled:hover {
background: #e8e5ed;
border-color: #8d7a98;
}
.notify-demo-actions [data-demo-action]:enabled:hover {
background: #92400e;
border-color: transparent;
}
.notify-demo-actions [data-demo-reset]:enabled:hover {
color: #b45309;
background: #fef3c7;
}
}
.notify-demo :focus-visible {
outline: 0.125rem solid #b45309;
outline-offset: 0.1875rem;
}
.notify-demo [hidden] {
display: none;
}
.notify-demo-actions button {
overflow-wrap: anywhere;
max-width: 100%;
}
</style>
</head>
<body>
<main
style="max-width: 48rem; margin: 2rem auto; padding: 1rem; font-family: system-ui, sans-serif"
>
<section class="notify-demo" data-notify-demo data-preset="undo" aria-label="Team inbox">
<p class="notify-demo-eyebrow">Team inbox</p>
<strong class="notify-demo-heading">Keep a clear inbox.</strong>
<p class="notify-demo-description">
Archive the launch checklist. Use Undo in the notification to bring the same item back.
</p>
<div class="notify-demo-item" data-demo-item>
<svg
width="1em"
height="1em"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
>
<path d="M7 17 17 7M8 7h9v9" /></svg
><span><strong>Launch checklist</strong><br />Design review · Today, 10:30</span>
</div>
<p class="notify-demo-result" data-demo-result role="status">
Launch checklist · In your inbox
</p>
<div class="notify-demo-actions">
<button type="button" data-demo-action>Archive checklist</button>
<button type="button" data-demo-reset>Reset this preview</button>
</div>
</section>
</main>
<script src="https://cdn.jsdelivr.net/npm/@samline/notify@5.0.1/dist/browser/notify.global.js"></script>
<script>
const notify = window.Notify
const copy = {
archived: 'Launch checklist archived',
undoHint: 'You can restore it to your inbox.',
undo: 'Undo archive',
restored: 'Launch checklist restored',
}
const undoDemo = (element, notify, copy, signal) => {
const item = element.querySelector('[data-demo-item]')
const action = element.querySelector('[data-demo-action]')
const result = element.querySelector('[data-demo-result]')
const initial = result.textContent
action.addEventListener(
'click',
() => {
if (item.hidden) return
notify.createToaster({ richColors: true, closeButton: true })
item.hidden = true
result.textContent = copy.archived
notify.toast(copy.archived, {
description: copy.undoHint,
duration: 10000,
action: {
label: copy.undo,
onClick: () => {
item.hidden = false
result.textContent = copy.restored
notify.toast.success(copy.restored)
},
},
})
},
{ signal }
)
element.querySelector('[data-demo-reset]').addEventListener(
'click',
() => {
notify.toast.dismiss()
item.hidden = false
result.textContent = initial
},
{ signal }
)
}
undoDemo(document.querySelector('[data-notify-demo]'), notify, copy)
// A page that is leaving no longer needs its toaster.
window.addEventListener('pagehide', event => {
if (!event.persisted) notify.destroyToaster()
})
</script>
</body>
</html>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Undo that actually restores the item</title>
</head>
<body>
<main
style="max-width: 48rem; margin: 2rem auto; padding: 1rem; font-family: system-ui, sans-serif"
>
<section class="notify-demo" data-notify-demo data-preset="undo" aria-label="Team inbox">
<p class="notify-demo-eyebrow">Team inbox</p>
<strong class="notify-demo-heading">Keep a clear inbox.</strong>
<p class="notify-demo-description">
Archive the launch checklist. Use Undo in the notification to bring the same item back.
</p>
<div class="notify-demo-item" data-demo-item>
<svg
width="1em"
height="1em"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
>
<path d="M7 17 17 7M8 7h9v9" /></svg
><span><strong>Launch checklist</strong><br />Design review · Today, 10:30</span>
</div>
<p class="notify-demo-result" data-demo-result role="status">
Launch checklist · In your inbox
</p>
<div class="notify-demo-actions">
<button type="button" data-demo-action>Archive checklist</button>
<button type="button" data-demo-reset>Reset this preview</button>
</div>
</section>
</main>
<script type="module" src="./main.js"></script>
</body>
</html>
/* Demo form only. Toast appearance and motion come from @samline/notify/style.css. */
.notify-demo {
display: grid;
gap: 1rem;
min-width: 0;
color: #26232b;
}
.notify-demo-eyebrow {
font: 0.625rem/1.6 monospace;
letter-spacing: 0.12em;
text-transform: uppercase;
color: #655d68;
}
.notify-demo-heading {
font-size: clamp(1.4rem, 3vw, 1.9rem);
line-height: 1.25;
font-weight: 500;
letter-spacing: -0.035em;
}
.notify-demo-description {
max-width: 45rem;
color: #5f5763;
line-height: 1.7;
}
.notify-demo p {
margin: 0;
}
.notify-demo-result {
min-height: 1.5rem;
font-size: 0.8125rem;
color: #5f5763;
}
.notify-demo-item {
display: flex;
align-items: center;
gap: 1rem;
padding: 1rem;
border-block: 0.0625rem solid #cfc7d2;
font-size: 0.875rem;
line-height: 1.7;
}
.notify-demo-item[hidden] {
display: none;
}
.notify-demo-actions {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 0.625rem;
padding-top: 0.5rem;
}
.notify-demo-actions button {
display: inline-flex;
align-items: center;
justify-content: center;
box-sizing: border-box;
min-height: 3.125rem;
padding: 0.5rem 1.4rem;
font:
500 0.875rem/1.5 system-ui,
sans-serif;
letter-spacing: -0.01em;
cursor: pointer;
border: 0.0625rem solid #b7adb9;
border-radius: 0.875rem;
color: #26232b;
background: #f4f2f7;
}
.notify-demo-actions [data-demo-action] {
background: #b45309;
border-color: transparent;
color: #fff;
}
.notify-demo-actions [data-demo-reset] {
min-height: 2.5rem;
padding-inline: 1rem;
border-radius: 624.9375rem;
color: #5f5763;
border-color: #b7adb9;
background: transparent;
}
.notify-demo-actions button:disabled {
opacity: 0.5;
cursor: not-allowed;
}
@media (hover: hover) {
.notify-demo-actions button:enabled:hover {
background: #e8e5ed;
border-color: #8d7a98;
}
.notify-demo-actions [data-demo-action]:enabled:hover {
background: #92400e;
border-color: transparent;
}
.notify-demo-actions [data-demo-reset]:enabled:hover {
color: #b45309;
background: #fef3c7;
}
}
.notify-demo :focus-visible {
outline: 0.125rem solid #b45309;
outline-offset: 0.1875rem;
}
.notify-demo [hidden] {
display: none;
}
.notify-demo-actions button {
overflow-wrap: anywhere;
max-width: 100%;
}
import { browser as notify } from '@samline/notify'
import '@samline/notify/style.css'
import './style.css'
const copy = {
archived: 'Launch checklist archived',
undoHint: 'You can restore it to your inbox.',
undo: 'Undo archive',
restored: 'Launch checklist restored',
}
const undoDemo = (element, notify, copy, signal) => {
const item = element.querySelector('[data-demo-item]')
const action = element.querySelector('[data-demo-action]')
const result = element.querySelector('[data-demo-result]')
const initial = result.textContent
action.addEventListener(
'click',
() => {
if (item.hidden) return
notify.createToaster({ richColors: true, closeButton: true })
item.hidden = true
result.textContent = copy.archived
notify.toast(copy.archived, {
description: copy.undoHint,
duration: 10000,
action: {
label: copy.undo,
onClick: () => {
item.hidden = false
result.textContent = copy.restored
notify.toast.success(copy.restored)
},
},
})
},
{ signal }
)
element.querySelector('[data-demo-reset]').addEventListener(
'click',
() => {
notify.toast.dismiss()
item.hidden = false
result.textContent = initial
},
{ signal }
)
}
undoDemo(document.querySelector('[data-notify-demo]'), notify, copy)
// A page that is leaving no longer needs its toaster.
window.addEventListener('pagehide', event => {
if (!event.persisted) notify.destroyToaster()
})
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Undo that actually restores the item</title>
<style>
/* Demo form only. Toast appearance and motion come from @samline/notify/style.css. */
.notify-demo {
display: grid;
gap: 1rem;
min-width: 0;
color: #26232b;
}
.notify-demo-eyebrow {
font: 0.625rem/1.6 monospace;
letter-spacing: 0.12em;
text-transform: uppercase;
color: #655d68;
}
.notify-demo-heading {
font-size: clamp(1.4rem, 3vw, 1.9rem);
line-height: 1.25;
font-weight: 500;
letter-spacing: -0.035em;
}
.notify-demo-description {
max-width: 45rem;
color: #5f5763;
line-height: 1.7;
}
.notify-demo p {
margin: 0;
}
.notify-demo-result {
min-height: 1.5rem;
font-size: 0.8125rem;
color: #5f5763;
}
.notify-demo-item {
display: flex;
align-items: center;
gap: 1rem;
padding: 1rem;
border-block: 0.0625rem solid #cfc7d2;
font-size: 0.875rem;
line-height: 1.7;
}
.notify-demo-item[hidden] {
display: none;
}
.notify-demo-actions {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 0.625rem;
padding-top: 0.5rem;
}
.notify-demo-actions button {
display: inline-flex;
align-items: center;
justify-content: center;
box-sizing: border-box;
min-height: 3.125rem;
padding: 0.5rem 1.4rem;
font:
500 0.875rem/1.5 system-ui,
sans-serif;
letter-spacing: -0.01em;
cursor: pointer;
border: 0.0625rem solid #b7adb9;
border-radius: 0.875rem;
color: #26232b;
background: #f4f2f7;
}
.notify-demo-actions [data-demo-action] {
background: #b45309;
border-color: transparent;
color: #fff;
}
.notify-demo-actions [data-demo-reset] {
min-height: 2.5rem;
padding-inline: 1rem;
border-radius: 624.9375rem;
color: #5f5763;
border-color: #b7adb9;
background: transparent;
}
.notify-demo-actions button:disabled {
opacity: 0.5;
cursor: not-allowed;
}
@media (hover: hover) {
.notify-demo-actions button:enabled:hover {
background: #e8e5ed;
border-color: #8d7a98;
}
.notify-demo-actions [data-demo-action]:enabled:hover {
background: #92400e;
border-color: transparent;
}
.notify-demo-actions [data-demo-reset]:enabled:hover {
color: #b45309;
background: #fef3c7;
}
}
.notify-demo :focus-visible {
outline: 0.125rem solid #b45309;
outline-offset: 0.1875rem;
}
.notify-demo [hidden] {
display: none;
}
.notify-demo-actions button {
overflow-wrap: anywhere;
max-width: 100%;
}
</style>
</head>
<body>
<main
style="max-width: 48rem; margin: 2rem auto; padding: 1rem; font-family: system-ui, sans-serif"
>
<section class="notify-demo" data-notify-demo data-preset="undo" aria-label="Team inbox">
<p class="notify-demo-eyebrow">Team inbox</p>
<strong class="notify-demo-heading">Keep a clear inbox.</strong>
<p class="notify-demo-description">
Archive the launch checklist. Use Undo in the notification to bring the same item back.
</p>
<div class="notify-demo-item" data-demo-item>
<svg
width="1em"
height="1em"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
>
<path d="M7 17 17 7M8 7h9v9" /></svg
><span><strong>Launch checklist</strong><br />Design review · Today, 10:30</span>
</div>
<p class="notify-demo-result" data-demo-result role="status">
Launch checklist · In your inbox
</p>
<div class="notify-demo-actions">
<button type="button" data-demo-action>Archive checklist</button>
<button type="button" data-demo-reset>Reset this preview</button>
</div>
</section>
</main>
<script type="module">
import { browser as notify } from '@samline/notify'
import '@samline/notify/style.css'
const copy = {
archived: 'Launch checklist archived',
undoHint: 'You can restore it to your inbox.',
undo: 'Undo archive',
restored: 'Launch checklist restored',
}
const undoDemo = (element, notify, copy, signal) => {
const item = element.querySelector('[data-demo-item]')
const action = element.querySelector('[data-demo-action]')
const result = element.querySelector('[data-demo-result]')
const initial = result.textContent
action.addEventListener(
'click',
() => {
if (item.hidden) return
notify.createToaster({ richColors: true, closeButton: true })
item.hidden = true
result.textContent = copy.archived
notify.toast(copy.archived, {
description: copy.undoHint,
duration: 10000,
action: {
label: copy.undo,
onClick: () => {
item.hidden = false
result.textContent = copy.restored
notify.toast.success(copy.restored)
},
},
})
},
{ signal }
)
element.querySelector('[data-demo-reset]').addEventListener(
'click',
() => {
notify.toast.dismiss()
item.hidden = false
result.textContent = initial
},
{ signal }
)
}
undoDemo(document.querySelector('[data-notify-demo]'), notify, copy)
// A page that is leaving no longer needs its toaster.
window.addEventListener('pagehide', event => {
if (!event.persisted) notify.destroyToaster()
})
</script>
</body>
</html>
Keep the important details within reach
Workspace access
An invitation waiting for you.Keep an invitation notice open while you read. Its details also remain on the page.
Studio workspace · Invitation available
duration: Infinity leaves time to read. A native close button and an explicit dismiss action keep the notice under your control.
Explore the code
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Keep the important details within reach</title>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@samline/notify@5.0.1/dist/style.css"
/>
<link rel="stylesheet" href="./style.css" />
</head>
<body>
<main
style="max-width: 48rem; margin: 2rem auto; padding: 1rem; font-family: system-ui, sans-serif"
>
<section
class="notify-demo"
data-notify-demo
data-preset="persistent"
aria-label="Workspace access"
>
<p class="notify-demo-eyebrow">Workspace access</p>
<strong class="notify-demo-heading">An invitation waiting for you.</strong>
<p class="notify-demo-description">
Keep an invitation notice open while you read. Its details also remain on the page.
</p>
<p class="notify-demo-result" data-demo-result role="status">
Studio workspace · Invitation available
</p>
<div class="notify-demo-actions">
<button type="button" data-demo-action>Show invitation</button>
<button type="button" data-demo-dismiss>Dismiss notification</button>
<button type="button" data-demo-reset>Reset this preview</button>
</div>
</section>
</main>
<script src="https://cdn.jsdelivr.net/npm/@samline/notify@5.0.1/dist/browser/notify.global.js"></script>
<script src="./main.js"></script>
</body>
</html>
/* Demo form only. Toast appearance and motion come from @samline/notify/style.css. */
.notify-demo {
display: grid;
gap: 1rem;
min-width: 0;
color: #26232b;
}
.notify-demo-eyebrow {
font: 0.625rem/1.6 monospace;
letter-spacing: 0.12em;
text-transform: uppercase;
color: #655d68;
}
.notify-demo-heading {
font-size: clamp(1.4rem, 3vw, 1.9rem);
line-height: 1.25;
font-weight: 500;
letter-spacing: -0.035em;
}
.notify-demo-description {
max-width: 45rem;
color: #5f5763;
line-height: 1.7;
}
.notify-demo p {
margin: 0;
}
.notify-demo-result {
min-height: 1.5rem;
font-size: 0.8125rem;
color: #5f5763;
}
.notify-demo-actions {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 0.625rem;
padding-top: 0.5rem;
}
.notify-demo-actions button {
display: inline-flex;
align-items: center;
justify-content: center;
box-sizing: border-box;
min-height: 3.125rem;
padding: 0.5rem 1.4rem;
font:
500 0.875rem/1.5 system-ui,
sans-serif;
letter-spacing: -0.01em;
cursor: pointer;
border: 0.0625rem solid #b7adb9;
border-radius: 0.875rem;
color: #26232b;
background: #f4f2f7;
}
.notify-demo-actions [data-demo-action] {
background: #b45309;
border-color: transparent;
color: #fff;
}
.notify-demo-actions [data-demo-reset] {
min-height: 2.5rem;
padding-inline: 1rem;
border-radius: 624.9375rem;
color: #5f5763;
border-color: #b7adb9;
background: transparent;
}
.notify-demo-actions button:disabled {
opacity: 0.5;
cursor: not-allowed;
}
@media (hover: hover) {
.notify-demo-actions button:enabled:hover {
background: #e8e5ed;
border-color: #8d7a98;
}
.notify-demo-actions [data-demo-action]:enabled:hover {
background: #92400e;
border-color: transparent;
}
.notify-demo-actions [data-demo-reset]:enabled:hover {
color: #b45309;
background: #fef3c7;
}
}
.notify-demo :focus-visible {
outline: 0.125rem solid #b45309;
outline-offset: 0.1875rem;
}
.notify-demo [hidden] {
display: none;
}
.notify-demo-actions button {
overflow-wrap: anywhere;
max-width: 100%;
}
const notify = window.Notify
const copy = {
invitation: 'You are invited to Studio',
invitationDetails: 'Studio workspace · Editor access · Accept the invitation from your account.',
dismissed: 'Notification dismissed. The details stay on this page.',
}
const persistentDemo = (element, notify, copy, signal) => {
const action = element.querySelector('[data-demo-action]')
const result = element.querySelector('[data-demo-result]')
const initial = result.textContent
action.addEventListener(
'click',
() => {
notify.createToaster({ richColors: true, closeButton: true })
notify.toast.info(copy.invitation, {
description: copy.invitationDetails,
duration: Infinity,
})
result.textContent = copy.invitationDetails
},
{ signal }
)
element.querySelector('[data-demo-dismiss]').addEventListener(
'click',
() => {
notify.toast.dismiss()
result.textContent = copy.dismissed
},
{ signal }
)
element.querySelector('[data-demo-reset]').addEventListener(
'click',
() => {
notify.toast.dismiss()
result.textContent = initial
},
{ signal }
)
}
persistentDemo(document.querySelector('[data-notify-demo]'), notify, copy)
// A page that is leaving no longer needs its toaster.
window.addEventListener('pagehide', event => {
if (!event.persisted) notify.destroyToaster()
})
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Keep the important details within reach</title>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@samline/notify@5.0.1/dist/style.css"
/>
<style>
/* Demo form only. Toast appearance and motion come from @samline/notify/style.css. */
.notify-demo {
display: grid;
gap: 1rem;
min-width: 0;
color: #26232b;
}
.notify-demo-eyebrow {
font: 0.625rem/1.6 monospace;
letter-spacing: 0.12em;
text-transform: uppercase;
color: #655d68;
}
.notify-demo-heading {
font-size: clamp(1.4rem, 3vw, 1.9rem);
line-height: 1.25;
font-weight: 500;
letter-spacing: -0.035em;
}
.notify-demo-description {
max-width: 45rem;
color: #5f5763;
line-height: 1.7;
}
.notify-demo p {
margin: 0;
}
.notify-demo-result {
min-height: 1.5rem;
font-size: 0.8125rem;
color: #5f5763;
}
.notify-demo-actions {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 0.625rem;
padding-top: 0.5rem;
}
.notify-demo-actions button {
display: inline-flex;
align-items: center;
justify-content: center;
box-sizing: border-box;
min-height: 3.125rem;
padding: 0.5rem 1.4rem;
font:
500 0.875rem/1.5 system-ui,
sans-serif;
letter-spacing: -0.01em;
cursor: pointer;
border: 0.0625rem solid #b7adb9;
border-radius: 0.875rem;
color: #26232b;
background: #f4f2f7;
}
.notify-demo-actions [data-demo-action] {
background: #b45309;
border-color: transparent;
color: #fff;
}
.notify-demo-actions [data-demo-reset] {
min-height: 2.5rem;
padding-inline: 1rem;
border-radius: 624.9375rem;
color: #5f5763;
border-color: #b7adb9;
background: transparent;
}
.notify-demo-actions button:disabled {
opacity: 0.5;
cursor: not-allowed;
}
@media (hover: hover) {
.notify-demo-actions button:enabled:hover {
background: #e8e5ed;
border-color: #8d7a98;
}
.notify-demo-actions [data-demo-action]:enabled:hover {
background: #92400e;
border-color: transparent;
}
.notify-demo-actions [data-demo-reset]:enabled:hover {
color: #b45309;
background: #fef3c7;
}
}
.notify-demo :focus-visible {
outline: 0.125rem solid #b45309;
outline-offset: 0.1875rem;
}
.notify-demo [hidden] {
display: none;
}
.notify-demo-actions button {
overflow-wrap: anywhere;
max-width: 100%;
}
</style>
</head>
<body>
<main
style="max-width: 48rem; margin: 2rem auto; padding: 1rem; font-family: system-ui, sans-serif"
>
<section
class="notify-demo"
data-notify-demo
data-preset="persistent"
aria-label="Workspace access"
>
<p class="notify-demo-eyebrow">Workspace access</p>
<strong class="notify-demo-heading">An invitation waiting for you.</strong>
<p class="notify-demo-description">
Keep an invitation notice open while you read. Its details also remain on the page.
</p>
<p class="notify-demo-result" data-demo-result role="status">
Studio workspace · Invitation available
</p>
<div class="notify-demo-actions">
<button type="button" data-demo-action>Show invitation</button>
<button type="button" data-demo-dismiss>Dismiss notification</button>
<button type="button" data-demo-reset>Reset this preview</button>
</div>
</section>
</main>
<script src="https://cdn.jsdelivr.net/npm/@samline/notify@5.0.1/dist/browser/notify.global.js"></script>
<script>
const notify = window.Notify
const copy = {
invitation: 'You are invited to Studio',
invitationDetails:
'Studio workspace · Editor access · Accept the invitation from your account.',
dismissed: 'Notification dismissed. The details stay on this page.',
}
const persistentDemo = (element, notify, copy, signal) => {
const action = element.querySelector('[data-demo-action]')
const result = element.querySelector('[data-demo-result]')
const initial = result.textContent
action.addEventListener(
'click',
() => {
notify.createToaster({ richColors: true, closeButton: true })
notify.toast.info(copy.invitation, {
description: copy.invitationDetails,
duration: Infinity,
})
result.textContent = copy.invitationDetails
},
{ signal }
)
element.querySelector('[data-demo-dismiss]').addEventListener(
'click',
() => {
notify.toast.dismiss()
result.textContent = copy.dismissed
},
{ signal }
)
element.querySelector('[data-demo-reset]').addEventListener(
'click',
() => {
notify.toast.dismiss()
result.textContent = initial
},
{ signal }
)
}
persistentDemo(document.querySelector('[data-notify-demo]'), notify, copy)
// A page that is leaving no longer needs its toaster.
window.addEventListener('pagehide', event => {
if (!event.persisted) notify.destroyToaster()
})
</script>
</body>
</html>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Keep the important details within reach</title>
</head>
<body>
<main
style="max-width: 48rem; margin: 2rem auto; padding: 1rem; font-family: system-ui, sans-serif"
>
<section
class="notify-demo"
data-notify-demo
data-preset="persistent"
aria-label="Workspace access"
>
<p class="notify-demo-eyebrow">Workspace access</p>
<strong class="notify-demo-heading">An invitation waiting for you.</strong>
<p class="notify-demo-description">
Keep an invitation notice open while you read. Its details also remain on the page.
</p>
<p class="notify-demo-result" data-demo-result role="status">
Studio workspace · Invitation available
</p>
<div class="notify-demo-actions">
<button type="button" data-demo-action>Show invitation</button>
<button type="button" data-demo-dismiss>Dismiss notification</button>
<button type="button" data-demo-reset>Reset this preview</button>
</div>
</section>
</main>
<script type="module" src="./main.js"></script>
</body>
</html>
/* Demo form only. Toast appearance and motion come from @samline/notify/style.css. */
.notify-demo {
display: grid;
gap: 1rem;
min-width: 0;
color: #26232b;
}
.notify-demo-eyebrow {
font: 0.625rem/1.6 monospace;
letter-spacing: 0.12em;
text-transform: uppercase;
color: #655d68;
}
.notify-demo-heading {
font-size: clamp(1.4rem, 3vw, 1.9rem);
line-height: 1.25;
font-weight: 500;
letter-spacing: -0.035em;
}
.notify-demo-description {
max-width: 45rem;
color: #5f5763;
line-height: 1.7;
}
.notify-demo p {
margin: 0;
}
.notify-demo-result {
min-height: 1.5rem;
font-size: 0.8125rem;
color: #5f5763;
}
.notify-demo-actions {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 0.625rem;
padding-top: 0.5rem;
}
.notify-demo-actions button {
display: inline-flex;
align-items: center;
justify-content: center;
box-sizing: border-box;
min-height: 3.125rem;
padding: 0.5rem 1.4rem;
font:
500 0.875rem/1.5 system-ui,
sans-serif;
letter-spacing: -0.01em;
cursor: pointer;
border: 0.0625rem solid #b7adb9;
border-radius: 0.875rem;
color: #26232b;
background: #f4f2f7;
}
.notify-demo-actions [data-demo-action] {
background: #b45309;
border-color: transparent;
color: #fff;
}
.notify-demo-actions [data-demo-reset] {
min-height: 2.5rem;
padding-inline: 1rem;
border-radius: 624.9375rem;
color: #5f5763;
border-color: #b7adb9;
background: transparent;
}
.notify-demo-actions button:disabled {
opacity: 0.5;
cursor: not-allowed;
}
@media (hover: hover) {
.notify-demo-actions button:enabled:hover {
background: #e8e5ed;
border-color: #8d7a98;
}
.notify-demo-actions [data-demo-action]:enabled:hover {
background: #92400e;
border-color: transparent;
}
.notify-demo-actions [data-demo-reset]:enabled:hover {
color: #b45309;
background: #fef3c7;
}
}
.notify-demo :focus-visible {
outline: 0.125rem solid #b45309;
outline-offset: 0.1875rem;
}
.notify-demo [hidden] {
display: none;
}
.notify-demo-actions button {
overflow-wrap: anywhere;
max-width: 100%;
}
import { browser as notify } from '@samline/notify'
import '@samline/notify/style.css'
import './style.css'
const copy = {
invitation: 'You are invited to Studio',
invitationDetails: 'Studio workspace · Editor access · Accept the invitation from your account.',
dismissed: 'Notification dismissed. The details stay on this page.',
}
const persistentDemo = (element, notify, copy, signal) => {
const action = element.querySelector('[data-demo-action]')
const result = element.querySelector('[data-demo-result]')
const initial = result.textContent
action.addEventListener(
'click',
() => {
notify.createToaster({ richColors: true, closeButton: true })
notify.toast.info(copy.invitation, {
description: copy.invitationDetails,
duration: Infinity,
})
result.textContent = copy.invitationDetails
},
{ signal }
)
element.querySelector('[data-demo-dismiss]').addEventListener(
'click',
() => {
notify.toast.dismiss()
result.textContent = copy.dismissed
},
{ signal }
)
element.querySelector('[data-demo-reset]').addEventListener(
'click',
() => {
notify.toast.dismiss()
result.textContent = initial
},
{ signal }
)
}
persistentDemo(document.querySelector('[data-notify-demo]'), notify, copy)
// A page that is leaving no longer needs its toaster.
window.addEventListener('pagehide', event => {
if (!event.persisted) notify.destroyToaster()
})
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Keep the important details within reach</title>
<style>
/* Demo form only. Toast appearance and motion come from @samline/notify/style.css. */
.notify-demo {
display: grid;
gap: 1rem;
min-width: 0;
color: #26232b;
}
.notify-demo-eyebrow {
font: 0.625rem/1.6 monospace;
letter-spacing: 0.12em;
text-transform: uppercase;
color: #655d68;
}
.notify-demo-heading {
font-size: clamp(1.4rem, 3vw, 1.9rem);
line-height: 1.25;
font-weight: 500;
letter-spacing: -0.035em;
}
.notify-demo-description {
max-width: 45rem;
color: #5f5763;
line-height: 1.7;
}
.notify-demo p {
margin: 0;
}
.notify-demo-result {
min-height: 1.5rem;
font-size: 0.8125rem;
color: #5f5763;
}
.notify-demo-actions {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 0.625rem;
padding-top: 0.5rem;
}
.notify-demo-actions button {
display: inline-flex;
align-items: center;
justify-content: center;
box-sizing: border-box;
min-height: 3.125rem;
padding: 0.5rem 1.4rem;
font:
500 0.875rem/1.5 system-ui,
sans-serif;
letter-spacing: -0.01em;
cursor: pointer;
border: 0.0625rem solid #b7adb9;
border-radius: 0.875rem;
color: #26232b;
background: #f4f2f7;
}
.notify-demo-actions [data-demo-action] {
background: #b45309;
border-color: transparent;
color: #fff;
}
.notify-demo-actions [data-demo-reset] {
min-height: 2.5rem;
padding-inline: 1rem;
border-radius: 624.9375rem;
color: #5f5763;
border-color: #b7adb9;
background: transparent;
}
.notify-demo-actions button:disabled {
opacity: 0.5;
cursor: not-allowed;
}
@media (hover: hover) {
.notify-demo-actions button:enabled:hover {
background: #e8e5ed;
border-color: #8d7a98;
}
.notify-demo-actions [data-demo-action]:enabled:hover {
background: #92400e;
border-color: transparent;
}
.notify-demo-actions [data-demo-reset]:enabled:hover {
color: #b45309;
background: #fef3c7;
}
}
.notify-demo :focus-visible {
outline: 0.125rem solid #b45309;
outline-offset: 0.1875rem;
}
.notify-demo [hidden] {
display: none;
}
.notify-demo-actions button {
overflow-wrap: anywhere;
max-width: 100%;
}
</style>
</head>
<body>
<main
style="max-width: 48rem; margin: 2rem auto; padding: 1rem; font-family: system-ui, sans-serif"
>
<section
class="notify-demo"
data-notify-demo
data-preset="persistent"
aria-label="Workspace access"
>
<p class="notify-demo-eyebrow">Workspace access</p>
<strong class="notify-demo-heading">An invitation waiting for you.</strong>
<p class="notify-demo-description">
Keep an invitation notice open while you read. Its details also remain on the page.
</p>
<p class="notify-demo-result" data-demo-result role="status">
Studio workspace · Invitation available
</p>
<div class="notify-demo-actions">
<button type="button" data-demo-action>Show invitation</button>
<button type="button" data-demo-dismiss>Dismiss notification</button>
<button type="button" data-demo-reset>Reset this preview</button>
</div>
</section>
</main>
<script type="module">
import { browser as notify } from '@samline/notify'
import '@samline/notify/style.css'
const copy = {
invitation: 'You are invited to Studio',
invitationDetails:
'Studio workspace · Editor access · Accept the invitation from your account.',
dismissed: 'Notification dismissed. The details stay on this page.',
}
const persistentDemo = (element, notify, copy, signal) => {
const action = element.querySelector('[data-demo-action]')
const result = element.querySelector('[data-demo-result]')
const initial = result.textContent
action.addEventListener(
'click',
() => {
notify.createToaster({ richColors: true, closeButton: true })
notify.toast.info(copy.invitation, {
description: copy.invitationDetails,
duration: Infinity,
})
result.textContent = copy.invitationDetails
},
{ signal }
)
element.querySelector('[data-demo-dismiss]').addEventListener(
'click',
() => {
notify.toast.dismiss()
result.textContent = copy.dismissed
},
{ signal }
)
element.querySelector('[data-demo-reset]').addEventListener(
'click',
() => {
notify.toast.dismiss()
result.textContent = initial
},
{ signal }
)
}
persistentDemo(document.querySelector('[data-notify-demo]'), notify, copy)
// A page that is leaving no longer needs its toaster.
window.addEventListener('pagehide', event => {
if (!event.persisted) notify.destroyToaster()
})
</script>
</body>
</html>
Your content. Notify’s lifecycle.
Release desk
A release ready for review.Open a release card, write a note inside the notification and save it back to the page. Your integration owns the DOM and appearance.
The release notes are ready for your review.
Runtime fixes · Compatible API · Native DOMRelease 4.0.0 · Ready for review
toast.custom uses safe DOM construction. Your integration supplies the custom appearance and close action.
Explore the code
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Your content. Notify’s lifecycle.</title>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@samline/notify@5.0.1/dist/style.css"
/>
<link rel="stylesheet" href="./style.css" />
</head>
<body>
<main
style="max-width: 48rem; margin: 2rem auto; padding: 1rem; font-family: system-ui, sans-serif"
>
<section class="notify-demo" data-notify-demo data-preset="custom" aria-label="Release desk">
<p class="notify-demo-eyebrow">Release desk</p>
<strong class="notify-demo-heading">A release ready for review.</strong>
<p class="notify-demo-description">
Open a release card, write a note inside the notification and save it back to the page.
Your integration owns the DOM and appearance.
</p>
<template>
<div class="notify-receipt">
<strong>Release 4.0.0</strong>
<p>The release notes are ready for your review.</p>
<small>Runtime fixes · Compatible API · Native DOM</small>
<label
>Release note<textarea
placeholder="What should your team know?"
maxlength="160"
rows="2"
></textarea>
</label>
<div class="notify-receipt-actions">
<button type="button" data-save-note>Save release note</button>
<button type="button" data-close-receipt>Close release receipt</button>
</div>
</div>
</template>
<p class="notify-demo-result" data-demo-result role="status">
Release 4.0.0 · Ready for review
</p>
<div class="notify-demo-actions">
<button type="button" data-demo-action>Show release receipt</button>
<button type="button" data-demo-reset>Reset this preview</button>
</div>
</section>
</main>
<script src="https://cdn.jsdelivr.net/npm/@samline/notify@5.0.1/dist/browser/notify.global.js"></script>
<script src="./main.js"></script>
</body>
</html>
/* Demo form and custom receipt. Notify supplies positioning, stacking and motion. */
.notify-demo {
display: grid;
gap: 1rem;
min-width: 0;
color: #26232b;
}
.notify-demo-eyebrow {
font: 0.625rem/1.6 monospace;
letter-spacing: 0.12em;
text-transform: uppercase;
color: #655d68;
}
.notify-demo-heading {
font-size: clamp(1.4rem, 3vw, 1.9rem);
line-height: 1.25;
font-weight: 500;
letter-spacing: -0.035em;
}
.notify-demo-description {
max-width: 45rem;
color: #5f5763;
line-height: 1.7;
}
.notify-demo p {
margin: 0;
}
.notify-receipt textarea {
display: block;
box-sizing: border-box;
min-width: 0;
width: 100%;
min-height: 3.125rem;
padding: 0.75rem 1rem;
font:
400 1rem/1.5 system-ui,
sans-serif;
color: #26232b;
background: #f4f2f7;
border: 0.0625rem solid #b7adb9;
border-radius: 0.5rem;
}
.notify-receipt textarea {
cursor: text;
}
.notify-receipt textarea:disabled {
opacity: 0.5;
cursor: not-allowed;
}
@media (hover: hover) {
.notify-receipt textarea:enabled:hover {
border-color: #8d7a98;
}
}
.notify-demo-result {
min-height: 1.5rem;
font-size: 0.8125rem;
color: #5f5763;
}
.notify-demo-actions {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 0.625rem;
padding-top: 0.5rem;
}
.notify-demo-actions button,
.notify-receipt button {
display: inline-flex;
align-items: center;
justify-content: center;
box-sizing: border-box;
min-height: 3.125rem;
padding: 0.5rem 1.4rem;
font:
500 0.875rem/1.5 system-ui,
sans-serif;
letter-spacing: -0.01em;
cursor: pointer;
border: 0.0625rem solid #b7adb9;
border-radius: 0.875rem;
color: #26232b;
background: #f4f2f7;
}
.notify-demo-actions [data-demo-action],
.notify-receipt-actions button:first-child {
background: #b45309;
border-color: transparent;
color: #fff;
}
.notify-demo-actions [data-demo-reset] {
min-height: 2.5rem;
padding-inline: 1rem;
border-radius: 624.9375rem;
color: #5f5763;
border-color: #b7adb9;
background: transparent;
}
.notify-demo-actions button:disabled,
.notify-receipt button:disabled {
opacity: 0.5;
cursor: not-allowed;
}
@media (hover: hover) {
.notify-demo-actions button:enabled:hover,
.notify-receipt button:enabled:hover {
background: #e8e5ed;
border-color: #8d7a98;
}
.notify-demo-actions [data-demo-action]:enabled:hover,
.notify-receipt-actions button:first-child:enabled:hover {
background: #92400e;
border-color: transparent;
}
.notify-demo-actions [data-demo-reset]:enabled:hover {
color: #b45309;
background: #fef3c7;
}
}
.notify-demo :focus-visible,
.notify-receipt :focus-visible {
outline: 0.125rem solid #b45309;
outline-offset: 0.1875rem;
}
.notify-receipt {
display: grid;
gap: 0.625rem;
box-sizing: border-box;
width: 100%;
max-width: 100%;
max-height: calc(100dvh - 4rem);
overflow: auto;
overscroll-behavior: contain;
padding: 1rem;
border: 0.0625rem solid #cfc7d2;
border-radius: 1rem;
background: #fff;
color: #26232b;
font:
0.875rem/1.6 system-ui,
sans-serif;
}
.notify-receipt p {
margin: 0;
}
.notify-receipt strong {
font-size: 1.25rem;
letter-spacing: -0.03em;
}
.notify-receipt small {
color: #5f5763;
}
.notify-receipt label {
display: grid;
gap: 0.5rem;
}
.notify-receipt textarea {
resize: vertical;
max-height: 8rem;
}
.notify-receipt-actions {
display: flex;
flex-wrap: wrap;
gap: 0.5rem;
}
.notify-receipt-actions button {
max-width: 100%;
overflow-wrap: anywhere;
min-height: 2.5rem;
border-radius: 0.5rem;
font-size: 0.8125rem;
padding: 0.5rem 0.625rem;
}
.notify-demo [hidden] {
display: none;
}
.notify-demo-actions button {
overflow-wrap: anywhere;
max-width: 100%;
}
const notify = window.Notify
const copy = {
releaseDetails: 'The release notes are ready for your review.',
noteSaved: 'Release note saved locally',
}
const customDemo = (element, notify, copy, signal) => {
// The card's markup lives in a <template> inside the demo.
const template = element.querySelector('template')
const action = element.querySelector('[data-demo-action]')
const result = element.querySelector('[data-demo-result]')
const initial = result.textContent
action.addEventListener(
'click',
() => {
notify.createToaster({ richColors: true, closeButton: true, style: { '--width': '23rem' } })
action.disabled = true
let note = '' // Kept outside the factory: Notify may render the card again.
notify.toast.custom(
(container, { dismiss }) => {
const card = template.content.cloneNode(true)
const textarea = card.querySelector('textarea')
textarea.value = note
textarea.addEventListener('input', () => {
note = textarea.value
})
card.querySelector('[data-save-note]').addEventListener('click', () => {
result.textContent = `${copy.noteSaved}: ${note.trim() || copy.releaseDetails}`
})
card.querySelector('[data-close-receipt]').addEventListener('click', dismiss)
container.append(card)
},
{
duration: Infinity,
onDismiss: () => {
action.disabled = false
},
}
)
result.textContent = copy.releaseDetails
},
{ signal }
)
element.querySelector('[data-demo-reset]').addEventListener(
'click',
() => {
notify.toast.dismiss()
action.disabled = false
result.textContent = initial
},
{ signal }
)
}
customDemo(document.querySelector('[data-notify-demo]'), notify, copy)
// A page that is leaving no longer needs its toaster.
window.addEventListener('pagehide', event => {
if (!event.persisted) notify.destroyToaster()
})
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Your content. Notify’s lifecycle.</title>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@samline/notify@5.0.1/dist/style.css"
/>
<style>
/* Demo form and custom receipt. Notify supplies positioning, stacking and motion. */
.notify-demo {
display: grid;
gap: 1rem;
min-width: 0;
color: #26232b;
}
.notify-demo-eyebrow {
font: 0.625rem/1.6 monospace;
letter-spacing: 0.12em;
text-transform: uppercase;
color: #655d68;
}
.notify-demo-heading {
font-size: clamp(1.4rem, 3vw, 1.9rem);
line-height: 1.25;
font-weight: 500;
letter-spacing: -0.035em;
}
.notify-demo-description {
max-width: 45rem;
color: #5f5763;
line-height: 1.7;
}
.notify-demo p {
margin: 0;
}
.notify-receipt textarea {
display: block;
box-sizing: border-box;
min-width: 0;
width: 100%;
min-height: 3.125rem;
padding: 0.75rem 1rem;
font:
400 1rem/1.5 system-ui,
sans-serif;
color: #26232b;
background: #f4f2f7;
border: 0.0625rem solid #b7adb9;
border-radius: 0.5rem;
}
.notify-receipt textarea {
cursor: text;
}
.notify-receipt textarea:disabled {
opacity: 0.5;
cursor: not-allowed;
}
@media (hover: hover) {
.notify-receipt textarea:enabled:hover {
border-color: #8d7a98;
}
}
.notify-demo-result {
min-height: 1.5rem;
font-size: 0.8125rem;
color: #5f5763;
}
.notify-demo-actions {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 0.625rem;
padding-top: 0.5rem;
}
.notify-demo-actions button,
.notify-receipt button {
display: inline-flex;
align-items: center;
justify-content: center;
box-sizing: border-box;
min-height: 3.125rem;
padding: 0.5rem 1.4rem;
font:
500 0.875rem/1.5 system-ui,
sans-serif;
letter-spacing: -0.01em;
cursor: pointer;
border: 0.0625rem solid #b7adb9;
border-radius: 0.875rem;
color: #26232b;
background: #f4f2f7;
}
.notify-demo-actions [data-demo-action],
.notify-receipt-actions button:first-child {
background: #b45309;
border-color: transparent;
color: #fff;
}
.notify-demo-actions [data-demo-reset] {
min-height: 2.5rem;
padding-inline: 1rem;
border-radius: 624.9375rem;
color: #5f5763;
border-color: #b7adb9;
background: transparent;
}
.notify-demo-actions button:disabled,
.notify-receipt button:disabled {
opacity: 0.5;
cursor: not-allowed;
}
@media (hover: hover) {
.notify-demo-actions button:enabled:hover,
.notify-receipt button:enabled:hover {
background: #e8e5ed;
border-color: #8d7a98;
}
.notify-demo-actions [data-demo-action]:enabled:hover,
.notify-receipt-actions button:first-child:enabled:hover {
background: #92400e;
border-color: transparent;
}
.notify-demo-actions [data-demo-reset]:enabled:hover {
color: #b45309;
background: #fef3c7;
}
}
.notify-demo :focus-visible,
.notify-receipt :focus-visible {
outline: 0.125rem solid #b45309;
outline-offset: 0.1875rem;
}
.notify-receipt {
display: grid;
gap: 0.625rem;
box-sizing: border-box;
width: 100%;
max-width: 100%;
max-height: calc(100dvh - 4rem);
overflow: auto;
overscroll-behavior: contain;
padding: 1rem;
border: 0.0625rem solid #cfc7d2;
border-radius: 1rem;
background: #fff;
color: #26232b;
font:
0.875rem/1.6 system-ui,
sans-serif;
}
.notify-receipt p {
margin: 0;
}
.notify-receipt strong {
font-size: 1.25rem;
letter-spacing: -0.03em;
}
.notify-receipt small {
color: #5f5763;
}
.notify-receipt label {
display: grid;
gap: 0.5rem;
}
.notify-receipt textarea {
resize: vertical;
max-height: 8rem;
}
.notify-receipt-actions {
display: flex;
flex-wrap: wrap;
gap: 0.5rem;
}
.notify-receipt-actions button {
max-width: 100%;
overflow-wrap: anywhere;
min-height: 2.5rem;
border-radius: 0.5rem;
font-size: 0.8125rem;
padding: 0.5rem 0.625rem;
}
.notify-demo [hidden] {
display: none;
}
.notify-demo-actions button {
overflow-wrap: anywhere;
max-width: 100%;
}
</style>
</head>
<body>
<main
style="max-width: 48rem; margin: 2rem auto; padding: 1rem; font-family: system-ui, sans-serif"
>
<section class="notify-demo" data-notify-demo data-preset="custom" aria-label="Release desk">
<p class="notify-demo-eyebrow">Release desk</p>
<strong class="notify-demo-heading">A release ready for review.</strong>
<p class="notify-demo-description">
Open a release card, write a note inside the notification and save it back to the page.
Your integration owns the DOM and appearance.
</p>
<template>
<div class="notify-receipt">
<strong>Release 4.0.0</strong>
<p>The release notes are ready for your review.</p>
<small>Runtime fixes · Compatible API · Native DOM</small>
<label
>Release note<textarea
placeholder="What should your team know?"
maxlength="160"
rows="2"
></textarea>
</label>
<div class="notify-receipt-actions">
<button type="button" data-save-note>Save release note</button>
<button type="button" data-close-receipt>Close release receipt</button>
</div>
</div>
</template>
<p class="notify-demo-result" data-demo-result role="status">
Release 4.0.0 · Ready for review
</p>
<div class="notify-demo-actions">
<button type="button" data-demo-action>Show release receipt</button>
<button type="button" data-demo-reset>Reset this preview</button>
</div>
</section>
</main>
<script src="https://cdn.jsdelivr.net/npm/@samline/notify@5.0.1/dist/browser/notify.global.js"></script>
<script>
const notify = window.Notify
const copy = {
releaseDetails: 'The release notes are ready for your review.',
noteSaved: 'Release note saved locally',
}
const customDemo = (element, notify, copy, signal) => {
// The card's markup lives in a <template> inside the demo.
const template = element.querySelector('template')
const action = element.querySelector('[data-demo-action]')
const result = element.querySelector('[data-demo-result]')
const initial = result.textContent
action.addEventListener(
'click',
() => {
notify.createToaster({
richColors: true,
closeButton: true,
style: { '--width': '23rem' },
})
action.disabled = true
let note = '' // Kept outside the factory: Notify may render the card again.
notify.toast.custom(
(container, { dismiss }) => {
const card = template.content.cloneNode(true)
const textarea = card.querySelector('textarea')
textarea.value = note
textarea.addEventListener('input', () => {
note = textarea.value
})
card.querySelector('[data-save-note]').addEventListener('click', () => {
result.textContent = `${copy.noteSaved}: ${note.trim() || copy.releaseDetails}`
})
card.querySelector('[data-close-receipt]').addEventListener('click', dismiss)
container.append(card)
},
{
duration: Infinity,
onDismiss: () => {
action.disabled = false
},
}
)
result.textContent = copy.releaseDetails
},
{ signal }
)
element.querySelector('[data-demo-reset]').addEventListener(
'click',
() => {
notify.toast.dismiss()
action.disabled = false
result.textContent = initial
},
{ signal }
)
}
customDemo(document.querySelector('[data-notify-demo]'), notify, copy)
// A page that is leaving no longer needs its toaster.
window.addEventListener('pagehide', event => {
if (!event.persisted) notify.destroyToaster()
})
</script>
</body>
</html>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Your content. Notify’s lifecycle.</title>
</head>
<body>
<main
style="max-width: 48rem; margin: 2rem auto; padding: 1rem; font-family: system-ui, sans-serif"
>
<section class="notify-demo" data-notify-demo data-preset="custom" aria-label="Release desk">
<p class="notify-demo-eyebrow">Release desk</p>
<strong class="notify-demo-heading">A release ready for review.</strong>
<p class="notify-demo-description">
Open a release card, write a note inside the notification and save it back to the page.
Your integration owns the DOM and appearance.
</p>
<template>
<div class="notify-receipt">
<strong>Release 4.0.0</strong>
<p>The release notes are ready for your review.</p>
<small>Runtime fixes · Compatible API · Native DOM</small>
<label
>Release note<textarea
placeholder="What should your team know?"
maxlength="160"
rows="2"
></textarea>
</label>
<div class="notify-receipt-actions">
<button type="button" data-save-note>Save release note</button>
<button type="button" data-close-receipt>Close release receipt</button>
</div>
</div>
</template>
<p class="notify-demo-result" data-demo-result role="status">
Release 4.0.0 · Ready for review
</p>
<div class="notify-demo-actions">
<button type="button" data-demo-action>Show release receipt</button>
<button type="button" data-demo-reset>Reset this preview</button>
</div>
</section>
</main>
<script type="module" src="./main.js"></script>
</body>
</html>
/* Demo form and custom receipt. Notify supplies positioning, stacking and motion. */
.notify-demo {
display: grid;
gap: 1rem;
min-width: 0;
color: #26232b;
}
.notify-demo-eyebrow {
font: 0.625rem/1.6 monospace;
letter-spacing: 0.12em;
text-transform: uppercase;
color: #655d68;
}
.notify-demo-heading {
font-size: clamp(1.4rem, 3vw, 1.9rem);
line-height: 1.25;
font-weight: 500;
letter-spacing: -0.035em;
}
.notify-demo-description {
max-width: 45rem;
color: #5f5763;
line-height: 1.7;
}
.notify-demo p {
margin: 0;
}
.notify-receipt textarea {
display: block;
box-sizing: border-box;
min-width: 0;
width: 100%;
min-height: 3.125rem;
padding: 0.75rem 1rem;
font:
400 1rem/1.5 system-ui,
sans-serif;
color: #26232b;
background: #f4f2f7;
border: 0.0625rem solid #b7adb9;
border-radius: 0.5rem;
}
.notify-receipt textarea {
cursor: text;
}
.notify-receipt textarea:disabled {
opacity: 0.5;
cursor: not-allowed;
}
@media (hover: hover) {
.notify-receipt textarea:enabled:hover {
border-color: #8d7a98;
}
}
.notify-demo-result {
min-height: 1.5rem;
font-size: 0.8125rem;
color: #5f5763;
}
.notify-demo-actions {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 0.625rem;
padding-top: 0.5rem;
}
.notify-demo-actions button,
.notify-receipt button {
display: inline-flex;
align-items: center;
justify-content: center;
box-sizing: border-box;
min-height: 3.125rem;
padding: 0.5rem 1.4rem;
font:
500 0.875rem/1.5 system-ui,
sans-serif;
letter-spacing: -0.01em;
cursor: pointer;
border: 0.0625rem solid #b7adb9;
border-radius: 0.875rem;
color: #26232b;
background: #f4f2f7;
}
.notify-demo-actions [data-demo-action],
.notify-receipt-actions button:first-child {
background: #b45309;
border-color: transparent;
color: #fff;
}
.notify-demo-actions [data-demo-reset] {
min-height: 2.5rem;
padding-inline: 1rem;
border-radius: 624.9375rem;
color: #5f5763;
border-color: #b7adb9;
background: transparent;
}
.notify-demo-actions button:disabled,
.notify-receipt button:disabled {
opacity: 0.5;
cursor: not-allowed;
}
@media (hover: hover) {
.notify-demo-actions button:enabled:hover,
.notify-receipt button:enabled:hover {
background: #e8e5ed;
border-color: #8d7a98;
}
.notify-demo-actions [data-demo-action]:enabled:hover,
.notify-receipt-actions button:first-child:enabled:hover {
background: #92400e;
border-color: transparent;
}
.notify-demo-actions [data-demo-reset]:enabled:hover {
color: #b45309;
background: #fef3c7;
}
}
.notify-demo :focus-visible,
.notify-receipt :focus-visible {
outline: 0.125rem solid #b45309;
outline-offset: 0.1875rem;
}
.notify-receipt {
display: grid;
gap: 0.625rem;
box-sizing: border-box;
width: 100%;
max-width: 100%;
max-height: calc(100dvh - 4rem);
overflow: auto;
overscroll-behavior: contain;
padding: 1rem;
border: 0.0625rem solid #cfc7d2;
border-radius: 1rem;
background: #fff;
color: #26232b;
font:
0.875rem/1.6 system-ui,
sans-serif;
}
.notify-receipt p {
margin: 0;
}
.notify-receipt strong {
font-size: 1.25rem;
letter-spacing: -0.03em;
}
.notify-receipt small {
color: #5f5763;
}
.notify-receipt label {
display: grid;
gap: 0.5rem;
}
.notify-receipt textarea {
resize: vertical;
max-height: 8rem;
}
.notify-receipt-actions {
display: flex;
flex-wrap: wrap;
gap: 0.5rem;
}
.notify-receipt-actions button {
max-width: 100%;
overflow-wrap: anywhere;
min-height: 2.5rem;
border-radius: 0.5rem;
font-size: 0.8125rem;
padding: 0.5rem 0.625rem;
}
.notify-demo [hidden] {
display: none;
}
.notify-demo-actions button {
overflow-wrap: anywhere;
max-width: 100%;
}
import { browser as notify } from '@samline/notify'
import '@samline/notify/style.css'
import './style.css'
const copy = {
releaseDetails: 'The release notes are ready for your review.',
noteSaved: 'Release note saved locally',
}
const customDemo = (element, notify, copy, signal) => {
// The card's markup lives in a <template> inside the demo.
const template = element.querySelector('template')
const action = element.querySelector('[data-demo-action]')
const result = element.querySelector('[data-demo-result]')
const initial = result.textContent
action.addEventListener(
'click',
() => {
notify.createToaster({ richColors: true, closeButton: true, style: { '--width': '23rem' } })
action.disabled = true
let note = '' // Kept outside the factory: Notify may render the card again.
notify.toast.custom(
(container, { dismiss }) => {
const card = template.content.cloneNode(true)
const textarea = card.querySelector('textarea')
textarea.value = note
textarea.addEventListener('input', () => {
note = textarea.value
})
card.querySelector('[data-save-note]').addEventListener('click', () => {
result.textContent = `${copy.noteSaved}: ${note.trim() || copy.releaseDetails}`
})
card.querySelector('[data-close-receipt]').addEventListener('click', dismiss)
container.append(card)
},
{
duration: Infinity,
onDismiss: () => {
action.disabled = false
},
}
)
result.textContent = copy.releaseDetails
},
{ signal }
)
element.querySelector('[data-demo-reset]').addEventListener(
'click',
() => {
notify.toast.dismiss()
action.disabled = false
result.textContent = initial
},
{ signal }
)
}
customDemo(document.querySelector('[data-notify-demo]'), notify, copy)
// A page that is leaving no longer needs its toaster.
window.addEventListener('pagehide', event => {
if (!event.persisted) notify.destroyToaster()
})
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Your content. Notify’s lifecycle.</title>
<style>
/* Demo form and custom receipt. Notify supplies positioning, stacking and motion. */
.notify-demo {
display: grid;
gap: 1rem;
min-width: 0;
color: #26232b;
}
.notify-demo-eyebrow {
font: 0.625rem/1.6 monospace;
letter-spacing: 0.12em;
text-transform: uppercase;
color: #655d68;
}
.notify-demo-heading {
font-size: clamp(1.4rem, 3vw, 1.9rem);
line-height: 1.25;
font-weight: 500;
letter-spacing: -0.035em;
}
.notify-demo-description {
max-width: 45rem;
color: #5f5763;
line-height: 1.7;
}
.notify-demo p {
margin: 0;
}
.notify-receipt textarea {
display: block;
box-sizing: border-box;
min-width: 0;
width: 100%;
min-height: 3.125rem;
padding: 0.75rem 1rem;
font:
400 1rem/1.5 system-ui,
sans-serif;
color: #26232b;
background: #f4f2f7;
border: 0.0625rem solid #b7adb9;
border-radius: 0.5rem;
}
.notify-receipt textarea {
cursor: text;
}
.notify-receipt textarea:disabled {
opacity: 0.5;
cursor: not-allowed;
}
@media (hover: hover) {
.notify-receipt textarea:enabled:hover {
border-color: #8d7a98;
}
}
.notify-demo-result {
min-height: 1.5rem;
font-size: 0.8125rem;
color: #5f5763;
}
.notify-demo-actions {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 0.625rem;
padding-top: 0.5rem;
}
.notify-demo-actions button,
.notify-receipt button {
display: inline-flex;
align-items: center;
justify-content: center;
box-sizing: border-box;
min-height: 3.125rem;
padding: 0.5rem 1.4rem;
font:
500 0.875rem/1.5 system-ui,
sans-serif;
letter-spacing: -0.01em;
cursor: pointer;
border: 0.0625rem solid #b7adb9;
border-radius: 0.875rem;
color: #26232b;
background: #f4f2f7;
}
.notify-demo-actions [data-demo-action],
.notify-receipt-actions button:first-child {
background: #b45309;
border-color: transparent;
color: #fff;
}
.notify-demo-actions [data-demo-reset] {
min-height: 2.5rem;
padding-inline: 1rem;
border-radius: 624.9375rem;
color: #5f5763;
border-color: #b7adb9;
background: transparent;
}
.notify-demo-actions button:disabled,
.notify-receipt button:disabled {
opacity: 0.5;
cursor: not-allowed;
}
@media (hover: hover) {
.notify-demo-actions button:enabled:hover,
.notify-receipt button:enabled:hover {
background: #e8e5ed;
border-color: #8d7a98;
}
.notify-demo-actions [data-demo-action]:enabled:hover,
.notify-receipt-actions button:first-child:enabled:hover {
background: #92400e;
border-color: transparent;
}
.notify-demo-actions [data-demo-reset]:enabled:hover {
color: #b45309;
background: #fef3c7;
}
}
.notify-demo :focus-visible,
.notify-receipt :focus-visible {
outline: 0.125rem solid #b45309;
outline-offset: 0.1875rem;
}
.notify-receipt {
display: grid;
gap: 0.625rem;
box-sizing: border-box;
width: 100%;
max-width: 100%;
max-height: calc(100dvh - 4rem);
overflow: auto;
overscroll-behavior: contain;
padding: 1rem;
border: 0.0625rem solid #cfc7d2;
border-radius: 1rem;
background: #fff;
color: #26232b;
font:
0.875rem/1.6 system-ui,
sans-serif;
}
.notify-receipt p {
margin: 0;
}
.notify-receipt strong {
font-size: 1.25rem;
letter-spacing: -0.03em;
}
.notify-receipt small {
color: #5f5763;
}
.notify-receipt label {
display: grid;
gap: 0.5rem;
}
.notify-receipt textarea {
resize: vertical;
max-height: 8rem;
}
.notify-receipt-actions {
display: flex;
flex-wrap: wrap;
gap: 0.5rem;
}
.notify-receipt-actions button {
max-width: 100%;
overflow-wrap: anywhere;
min-height: 2.5rem;
border-radius: 0.5rem;
font-size: 0.8125rem;
padding: 0.5rem 0.625rem;
}
.notify-demo [hidden] {
display: none;
}
.notify-demo-actions button {
overflow-wrap: anywhere;
max-width: 100%;
}
</style>
</head>
<body>
<main
style="max-width: 48rem; margin: 2rem auto; padding: 1rem; font-family: system-ui, sans-serif"
>
<section class="notify-demo" data-notify-demo data-preset="custom" aria-label="Release desk">
<p class="notify-demo-eyebrow">Release desk</p>
<strong class="notify-demo-heading">A release ready for review.</strong>
<p class="notify-demo-description">
Open a release card, write a note inside the notification and save it back to the page.
Your integration owns the DOM and appearance.
</p>
<template>
<div class="notify-receipt">
<strong>Release 4.0.0</strong>
<p>The release notes are ready for your review.</p>
<small>Runtime fixes · Compatible API · Native DOM</small>
<label
>Release note<textarea
placeholder="What should your team know?"
maxlength="160"
rows="2"
></textarea>
</label>
<div class="notify-receipt-actions">
<button type="button" data-save-note>Save release note</button>
<button type="button" data-close-receipt>Close release receipt</button>
</div>
</div>
</template>
<p class="notify-demo-result" data-demo-result role="status">
Release 4.0.0 · Ready for review
</p>
<div class="notify-demo-actions">
<button type="button" data-demo-action>Show release receipt</button>
<button type="button" data-demo-reset>Reset this preview</button>
</div>
</section>
</main>
<script type="module">
import { browser as notify } from '@samline/notify'
import '@samline/notify/style.css'
const copy = {
releaseDetails: 'The release notes are ready for your review.',
noteSaved: 'Release note saved locally',
}
const customDemo = (element, notify, copy, signal) => {
// The card's markup lives in a <template> inside the demo.
const template = element.querySelector('template')
const action = element.querySelector('[data-demo-action]')
const result = element.querySelector('[data-demo-result]')
const initial = result.textContent
action.addEventListener(
'click',
() => {
notify.createToaster({
richColors: true,
closeButton: true,
style: { '--width': '23rem' },
})
action.disabled = true
let note = '' // Kept outside the factory: Notify may render the card again.
notify.toast.custom(
(container, { dismiss }) => {
const card = template.content.cloneNode(true)
const textarea = card.querySelector('textarea')
textarea.value = note
textarea.addEventListener('input', () => {
note = textarea.value
})
card.querySelector('[data-save-note]').addEventListener('click', () => {
result.textContent = `${copy.noteSaved}: ${note.trim() || copy.releaseDetails}`
})
card.querySelector('[data-close-receipt]').addEventListener('click', dismiss)
container.append(card)
},
{
duration: Infinity,
onDismiss: () => {
action.disabled = false
},
}
)
result.textContent = copy.releaseDetails
},
{ signal }
)
element.querySelector('[data-demo-reset]').addEventListener(
'click',
() => {
notify.toast.dismiss()
action.disabled = false
result.textContent = initial
},
{ signal }
)
}
customDemo(document.querySelector('[data-notify-demo]'), notify, copy)
// A page that is leaving no longer needs its toaster.
window.addEventListener('pagehide', event => {
if (!event.persisted) notify.destroyToaster()
})
</script>
</body>
</html>
Change the setting, keep the controller
Notification preferences
Put feedback where it belongs.Choose position, theme and reading direction. Preview the same notification, then apply changes while it is still open.
Bottom right · Follows the page theme
update() preserves omitted settings. Corner toasts swipe toward their edges; centered toasts swipe vertically.
Explore the code
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Change the setting, keep the controller</title>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@samline/notify@5.0.1/dist/style.css"
/>
<link rel="stylesheet" href="./style.css" />
</head>
<body>
<main
style="max-width: 48rem; margin: 2rem auto; padding: 1rem; font-family: system-ui, sans-serif"
>
<section
class="notify-demo"
data-notify-demo
data-preset="position"
aria-label="Notification preferences"
>
<p class="notify-demo-eyebrow">Notification preferences</p>
<strong class="notify-demo-heading">Put feedback where it belongs.</strong>
<p class="notify-demo-description">
Choose position, theme and reading direction. Preview the same notification, then apply
changes while it is still open.
</p>
<div class="notify-demo-fields">
<label class="notify-demo-field"
>Position<span class="notify-demo-select"
><select data-position>
<option value="bottom-right">Bottom right</option>
<option value="bottom-left">Bottom left</option>
<option value="top-right">Top right</option>
<option value="top-left">Top left</option>
<option value="top-center">Top center</option>
<option value="bottom-center">Bottom center</option>
</select></span
></label
><label class="notify-demo-field"
>Theme<span class="notify-demo-select"
><select data-theme>
<option value="page">Follow the page</option>
<option value="light">Light</option>
<option value="dark">Dark</option>
<option value="system">Follow the operating system</option>
</select></span
></label
><label class="notify-demo-field"
>Reading direction<span class="notify-demo-select"
><select data-direction>
<option value="ltr">Left to right</option>
<option value="rtl">Right to left</option>
</select></span
></label
>
</div>
<p class="notify-demo-result" data-demo-result role="status">
Bottom right · Follows the page theme
</p>
<div class="notify-demo-actions">
<button type="button" data-demo-action>Preview preference</button>
<button type="button" data-demo-reset>Reset this preview</button>
</div>
</section>
</main>
<script src="https://cdn.jsdelivr.net/npm/@samline/notify@5.0.1/dist/browser/notify.global.js"></script>
<script src="./main.js"></script>
</body>
</html>
/* Demo form only. Toast appearance and motion come from @samline/notify/style.css. */
.notify-demo {
display: grid;
gap: 1rem;
min-width: 0;
color: #26232b;
}
.notify-demo-eyebrow {
font: 0.625rem/1.6 monospace;
letter-spacing: 0.12em;
text-transform: uppercase;
color: #655d68;
}
.notify-demo-heading {
font-size: clamp(1.4rem, 3vw, 1.9rem);
line-height: 1.25;
font-weight: 500;
letter-spacing: -0.035em;
}
.notify-demo-description {
max-width: 45rem;
color: #5f5763;
line-height: 1.7;
}
.notify-demo p {
margin: 0;
}
.notify-demo-field {
display: grid;
gap: 0.5rem;
min-width: 0;
max-width: 28rem;
color: #5f5763;
font-size: 0.8125rem;
}
.notify-demo-field select {
display: block;
box-sizing: border-box;
min-width: 0;
width: 100%;
min-height: 3.125rem;
padding: 0.75rem 1rem;
font:
400 1rem/1.5 system-ui,
sans-serif;
color: #26232b;
background: #f4f2f7;
border: 0.0625rem solid #b7adb9;
border-radius: 0.5rem;
}
.notify-demo-select {
display: block;
position: relative;
min-width: 0;
color: #5f5763;
}
.notify-demo-select::after {
content: '';
box-sizing: border-box;
position: absolute;
inset-inline-end: min(1rem, 5vw);
top: 50%;
width: 0.5rem;
height: 0.5rem;
border-right: 0.125rem solid currentColor;
border-bottom: 0.125rem solid currentColor;
transform: translateY(-70%) rotate(45deg);
pointer-events: none;
}
.notify-demo-select select {
appearance: none;
cursor: pointer;
padding-inline-start: min(1rem, 5vw);
padding-inline-end: min(2.75rem, 12vw);
}
.notify-demo-select:has(select:disabled)::after {
opacity: 0.5;
}
.notify-demo-field select:disabled {
opacity: 0.5;
cursor: not-allowed;
}
@media (hover: hover) {
.notify-demo-field select:enabled:hover {
border-color: #8d7a98;
}
}
.notify-demo-result {
min-height: 1.5rem;
font-size: 0.8125rem;
color: #5f5763;
}
.notify-demo-actions {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 0.625rem;
padding-top: 0.5rem;
}
.notify-demo-actions button {
display: inline-flex;
align-items: center;
justify-content: center;
box-sizing: border-box;
min-height: 3.125rem;
padding: 0.5rem 1.4rem;
font:
500 0.875rem/1.5 system-ui,
sans-serif;
letter-spacing: -0.01em;
cursor: pointer;
border: 0.0625rem solid #b7adb9;
border-radius: 0.875rem;
color: #26232b;
background: #f4f2f7;
}
.notify-demo-actions [data-demo-action] {
background: #b45309;
border-color: transparent;
color: #fff;
}
.notify-demo-actions [data-demo-reset] {
min-height: 2.5rem;
padding-inline: 1rem;
border-radius: 624.9375rem;
color: #5f5763;
border-color: #b7adb9;
background: transparent;
}
.notify-demo-actions button:disabled {
opacity: 0.5;
cursor: not-allowed;
}
@media (hover: hover) {
.notify-demo-actions button:enabled:hover {
background: #e8e5ed;
border-color: #8d7a98;
}
.notify-demo-actions [data-demo-action]:enabled:hover {
background: #92400e;
border-color: transparent;
}
.notify-demo-actions [data-demo-reset]:enabled:hover {
color: #b45309;
background: #fef3c7;
}
}
.notify-demo :focus-visible {
outline: 0.125rem solid #b45309;
outline-offset: 0.1875rem;
}
.notify-demo-fields {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(min(100%, 12rem), 1fr));
gap: 1rem;
align-items: end;
}
.notify-demo [hidden] {
display: none;
}
.notify-demo-actions button {
overflow-wrap: anywhere;
max-width: 100%;
}
const notify = window.Notify
const copy = { preference: 'Notification preference applied' }
const positionDemo = (element, notify, copy, signal) => {
const [place, theme, direction] = ['position', 'theme', 'direction'].map(name =>
element.querySelector(`[data-${name}]`)
)
const result = element.querySelector('[data-demo-result]')
const initial = result.textContent
// "Follow the page" sends no theme, so the toaster keeps its default.
const preferences = () => ({
position: place.value,
theme: theme.value === 'page' ? undefined : theme.value,
dir: direction.value,
})
// Changing a preference updates the toast that is already on screen.
for (const select of [place, theme, direction]) {
select.addEventListener(
'change',
() => {
if (notify.toast.getToasts().length) notify.createToaster(preferences())
},
{ signal }
)
}
element.querySelector('[data-demo-action]').addEventListener(
'click',
() => {
notify.createToaster({ richColors: true, closeButton: true, ...preferences() })
const label = place.selectedOptions[0].textContent
notify.toast.success(copy.preference, { description: label })
result.textContent = label
},
{ signal }
)
element.querySelector('[data-demo-reset]').addEventListener(
'click',
() => {
notify.toast.dismiss()
result.textContent = initial
},
{ signal }
)
}
positionDemo(document.querySelector('[data-notify-demo]'), notify, copy)
// A page that is leaving no longer needs its toaster.
window.addEventListener('pagehide', event => {
if (!event.persisted) notify.destroyToaster()
})
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Change the setting, keep the controller</title>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@samline/notify@5.0.1/dist/style.css"
/>
<style>
/* Demo form only. Toast appearance and motion come from @samline/notify/style.css. */
.notify-demo {
display: grid;
gap: 1rem;
min-width: 0;
color: #26232b;
}
.notify-demo-eyebrow {
font: 0.625rem/1.6 monospace;
letter-spacing: 0.12em;
text-transform: uppercase;
color: #655d68;
}
.notify-demo-heading {
font-size: clamp(1.4rem, 3vw, 1.9rem);
line-height: 1.25;
font-weight: 500;
letter-spacing: -0.035em;
}
.notify-demo-description {
max-width: 45rem;
color: #5f5763;
line-height: 1.7;
}
.notify-demo p {
margin: 0;
}
.notify-demo-field {
display: grid;
gap: 0.5rem;
min-width: 0;
max-width: 28rem;
color: #5f5763;
font-size: 0.8125rem;
}
.notify-demo-field select {
display: block;
box-sizing: border-box;
min-width: 0;
width: 100%;
min-height: 3.125rem;
padding: 0.75rem 1rem;
font:
400 1rem/1.5 system-ui,
sans-serif;
color: #26232b;
background: #f4f2f7;
border: 0.0625rem solid #b7adb9;
border-radius: 0.5rem;
}
.notify-demo-select {
display: block;
position: relative;
min-width: 0;
color: #5f5763;
}
.notify-demo-select::after {
content: '';
box-sizing: border-box;
position: absolute;
inset-inline-end: min(1rem, 5vw);
top: 50%;
width: 0.5rem;
height: 0.5rem;
border-right: 0.125rem solid currentColor;
border-bottom: 0.125rem solid currentColor;
transform: translateY(-70%) rotate(45deg);
pointer-events: none;
}
.notify-demo-select select {
appearance: none;
cursor: pointer;
padding-inline-start: min(1rem, 5vw);
padding-inline-end: min(2.75rem, 12vw);
}
.notify-demo-select:has(select:disabled)::after {
opacity: 0.5;
}
.notify-demo-field select:disabled {
opacity: 0.5;
cursor: not-allowed;
}
@media (hover: hover) {
.notify-demo-field select:enabled:hover {
border-color: #8d7a98;
}
}
.notify-demo-result {
min-height: 1.5rem;
font-size: 0.8125rem;
color: #5f5763;
}
.notify-demo-actions {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 0.625rem;
padding-top: 0.5rem;
}
.notify-demo-actions button {
display: inline-flex;
align-items: center;
justify-content: center;
box-sizing: border-box;
min-height: 3.125rem;
padding: 0.5rem 1.4rem;
font:
500 0.875rem/1.5 system-ui,
sans-serif;
letter-spacing: -0.01em;
cursor: pointer;
border: 0.0625rem solid #b7adb9;
border-radius: 0.875rem;
color: #26232b;
background: #f4f2f7;
}
.notify-demo-actions [data-demo-action] {
background: #b45309;
border-color: transparent;
color: #fff;
}
.notify-demo-actions [data-demo-reset] {
min-height: 2.5rem;
padding-inline: 1rem;
border-radius: 624.9375rem;
color: #5f5763;
border-color: #b7adb9;
background: transparent;
}
.notify-demo-actions button:disabled {
opacity: 0.5;
cursor: not-allowed;
}
@media (hover: hover) {
.notify-demo-actions button:enabled:hover {
background: #e8e5ed;
border-color: #8d7a98;
}
.notify-demo-actions [data-demo-action]:enabled:hover {
background: #92400e;
border-color: transparent;
}
.notify-demo-actions [data-demo-reset]:enabled:hover {
color: #b45309;
background: #fef3c7;
}
}
.notify-demo :focus-visible {
outline: 0.125rem solid #b45309;
outline-offset: 0.1875rem;
}
.notify-demo-fields {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(min(100%, 12rem), 1fr));
gap: 1rem;
align-items: end;
}
.notify-demo [hidden] {
display: none;
}
.notify-demo-actions button {
overflow-wrap: anywhere;
max-width: 100%;
}
</style>
</head>
<body>
<main
style="max-width: 48rem; margin: 2rem auto; padding: 1rem; font-family: system-ui, sans-serif"
>
<section
class="notify-demo"
data-notify-demo
data-preset="position"
aria-label="Notification preferences"
>
<p class="notify-demo-eyebrow">Notification preferences</p>
<strong class="notify-demo-heading">Put feedback where it belongs.</strong>
<p class="notify-demo-description">
Choose position, theme and reading direction. Preview the same notification, then apply
changes while it is still open.
</p>
<div class="notify-demo-fields">
<label class="notify-demo-field"
>Position<span class="notify-demo-select"
><select data-position>
<option value="bottom-right">Bottom right</option>
<option value="bottom-left">Bottom left</option>
<option value="top-right">Top right</option>
<option value="top-left">Top left</option>
<option value="top-center">Top center</option>
<option value="bottom-center">Bottom center</option>
</select></span
></label
><label class="notify-demo-field"
>Theme<span class="notify-demo-select"
><select data-theme>
<option value="page">Follow the page</option>
<option value="light">Light</option>
<option value="dark">Dark</option>
<option value="system">Follow the operating system</option>
</select></span
></label
><label class="notify-demo-field"
>Reading direction<span class="notify-demo-select"
><select data-direction>
<option value="ltr">Left to right</option>
<option value="rtl">Right to left</option>
</select></span
></label
>
</div>
<p class="notify-demo-result" data-demo-result role="status">
Bottom right · Follows the page theme
</p>
<div class="notify-demo-actions">
<button type="button" data-demo-action>Preview preference</button>
<button type="button" data-demo-reset>Reset this preview</button>
</div>
</section>
</main>
<script src="https://cdn.jsdelivr.net/npm/@samline/notify@5.0.1/dist/browser/notify.global.js"></script>
<script>
const notify = window.Notify
const copy = { preference: 'Notification preference applied' }
const positionDemo = (element, notify, copy, signal) => {
const [place, theme, direction] = ['position', 'theme', 'direction'].map(name =>
element.querySelector(`[data-${name}]`)
)
const result = element.querySelector('[data-demo-result]')
const initial = result.textContent
// "Follow the page" sends no theme, so the toaster keeps its default.
const preferences = () => ({
position: place.value,
theme: theme.value === 'page' ? undefined : theme.value,
dir: direction.value,
})
// Changing a preference updates the toast that is already on screen.
for (const select of [place, theme, direction]) {
select.addEventListener(
'change',
() => {
if (notify.toast.getToasts().length) notify.createToaster(preferences())
},
{ signal }
)
}
element.querySelector('[data-demo-action]').addEventListener(
'click',
() => {
notify.createToaster({ richColors: true, closeButton: true, ...preferences() })
const label = place.selectedOptions[0].textContent
notify.toast.success(copy.preference, { description: label })
result.textContent = label
},
{ signal }
)
element.querySelector('[data-demo-reset]').addEventListener(
'click',
() => {
notify.toast.dismiss()
result.textContent = initial
},
{ signal }
)
}
positionDemo(document.querySelector('[data-notify-demo]'), notify, copy)
// A page that is leaving no longer needs its toaster.
window.addEventListener('pagehide', event => {
if (!event.persisted) notify.destroyToaster()
})
</script>
</body>
</html>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Change the setting, keep the controller</title>
</head>
<body>
<main
style="max-width: 48rem; margin: 2rem auto; padding: 1rem; font-family: system-ui, sans-serif"
>
<section
class="notify-demo"
data-notify-demo
data-preset="position"
aria-label="Notification preferences"
>
<p class="notify-demo-eyebrow">Notification preferences</p>
<strong class="notify-demo-heading">Put feedback where it belongs.</strong>
<p class="notify-demo-description">
Choose position, theme and reading direction. Preview the same notification, then apply
changes while it is still open.
</p>
<div class="notify-demo-fields">
<label class="notify-demo-field"
>Position<span class="notify-demo-select"
><select data-position>
<option value="bottom-right">Bottom right</option>
<option value="bottom-left">Bottom left</option>
<option value="top-right">Top right</option>
<option value="top-left">Top left</option>
<option value="top-center">Top center</option>
<option value="bottom-center">Bottom center</option>
</select></span
></label
><label class="notify-demo-field"
>Theme<span class="notify-demo-select"
><select data-theme>
<option value="page">Follow the page</option>
<option value="light">Light</option>
<option value="dark">Dark</option>
<option value="system">Follow the operating system</option>
</select></span
></label
><label class="notify-demo-field"
>Reading direction<span class="notify-demo-select"
><select data-direction>
<option value="ltr">Left to right</option>
<option value="rtl">Right to left</option>
</select></span
></label
>
</div>
<p class="notify-demo-result" data-demo-result role="status">
Bottom right · Follows the page theme
</p>
<div class="notify-demo-actions">
<button type="button" data-demo-action>Preview preference</button>
<button type="button" data-demo-reset>Reset this preview</button>
</div>
</section>
</main>
<script type="module" src="./main.js"></script>
</body>
</html>
/* Demo form only. Toast appearance and motion come from @samline/notify/style.css. */
.notify-demo {
display: grid;
gap: 1rem;
min-width: 0;
color: #26232b;
}
.notify-demo-eyebrow {
font: 0.625rem/1.6 monospace;
letter-spacing: 0.12em;
text-transform: uppercase;
color: #655d68;
}
.notify-demo-heading {
font-size: clamp(1.4rem, 3vw, 1.9rem);
line-height: 1.25;
font-weight: 500;
letter-spacing: -0.035em;
}
.notify-demo-description {
max-width: 45rem;
color: #5f5763;
line-height: 1.7;
}
.notify-demo p {
margin: 0;
}
.notify-demo-field {
display: grid;
gap: 0.5rem;
min-width: 0;
max-width: 28rem;
color: #5f5763;
font-size: 0.8125rem;
}
.notify-demo-field select {
display: block;
box-sizing: border-box;
min-width: 0;
width: 100%;
min-height: 3.125rem;
padding: 0.75rem 1rem;
font:
400 1rem/1.5 system-ui,
sans-serif;
color: #26232b;
background: #f4f2f7;
border: 0.0625rem solid #b7adb9;
border-radius: 0.5rem;
}
.notify-demo-select {
display: block;
position: relative;
min-width: 0;
color: #5f5763;
}
.notify-demo-select::after {
content: '';
box-sizing: border-box;
position: absolute;
inset-inline-end: min(1rem, 5vw);
top: 50%;
width: 0.5rem;
height: 0.5rem;
border-right: 0.125rem solid currentColor;
border-bottom: 0.125rem solid currentColor;
transform: translateY(-70%) rotate(45deg);
pointer-events: none;
}
.notify-demo-select select {
appearance: none;
cursor: pointer;
padding-inline-start: min(1rem, 5vw);
padding-inline-end: min(2.75rem, 12vw);
}
.notify-demo-select:has(select:disabled)::after {
opacity: 0.5;
}
.notify-demo-field select:disabled {
opacity: 0.5;
cursor: not-allowed;
}
@media (hover: hover) {
.notify-demo-field select:enabled:hover {
border-color: #8d7a98;
}
}
.notify-demo-result {
min-height: 1.5rem;
font-size: 0.8125rem;
color: #5f5763;
}
.notify-demo-actions {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 0.625rem;
padding-top: 0.5rem;
}
.notify-demo-actions button {
display: inline-flex;
align-items: center;
justify-content: center;
box-sizing: border-box;
min-height: 3.125rem;
padding: 0.5rem 1.4rem;
font:
500 0.875rem/1.5 system-ui,
sans-serif;
letter-spacing: -0.01em;
cursor: pointer;
border: 0.0625rem solid #b7adb9;
border-radius: 0.875rem;
color: #26232b;
background: #f4f2f7;
}
.notify-demo-actions [data-demo-action] {
background: #b45309;
border-color: transparent;
color: #fff;
}
.notify-demo-actions [data-demo-reset] {
min-height: 2.5rem;
padding-inline: 1rem;
border-radius: 624.9375rem;
color: #5f5763;
border-color: #b7adb9;
background: transparent;
}
.notify-demo-actions button:disabled {
opacity: 0.5;
cursor: not-allowed;
}
@media (hover: hover) {
.notify-demo-actions button:enabled:hover {
background: #e8e5ed;
border-color: #8d7a98;
}
.notify-demo-actions [data-demo-action]:enabled:hover {
background: #92400e;
border-color: transparent;
}
.notify-demo-actions [data-demo-reset]:enabled:hover {
color: #b45309;
background: #fef3c7;
}
}
.notify-demo :focus-visible {
outline: 0.125rem solid #b45309;
outline-offset: 0.1875rem;
}
.notify-demo-fields {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(min(100%, 12rem), 1fr));
gap: 1rem;
align-items: end;
}
.notify-demo [hidden] {
display: none;
}
.notify-demo-actions button {
overflow-wrap: anywhere;
max-width: 100%;
}
import { browser as notify } from '@samline/notify'
import '@samline/notify/style.css'
import './style.css'
const copy = { preference: 'Notification preference applied' }
const positionDemo = (element, notify, copy, signal) => {
const [place, theme, direction] = ['position', 'theme', 'direction'].map(name =>
element.querySelector(`[data-${name}]`)
)
const result = element.querySelector('[data-demo-result]')
const initial = result.textContent
// "Follow the page" sends no theme, so the toaster keeps its default.
const preferences = () => ({
position: place.value,
theme: theme.value === 'page' ? undefined : theme.value,
dir: direction.value,
})
// Changing a preference updates the toast that is already on screen.
for (const select of [place, theme, direction]) {
select.addEventListener(
'change',
() => {
if (notify.toast.getToasts().length) notify.createToaster(preferences())
},
{ signal }
)
}
element.querySelector('[data-demo-action]').addEventListener(
'click',
() => {
notify.createToaster({ richColors: true, closeButton: true, ...preferences() })
const label = place.selectedOptions[0].textContent
notify.toast.success(copy.preference, { description: label })
result.textContent = label
},
{ signal }
)
element.querySelector('[data-demo-reset]').addEventListener(
'click',
() => {
notify.toast.dismiss()
result.textContent = initial
},
{ signal }
)
}
positionDemo(document.querySelector('[data-notify-demo]'), notify, copy)
// A page that is leaving no longer needs its toaster.
window.addEventListener('pagehide', event => {
if (!event.persisted) notify.destroyToaster()
})
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Change the setting, keep the controller</title>
<style>
/* Demo form only. Toast appearance and motion come from @samline/notify/style.css. */
.notify-demo {
display: grid;
gap: 1rem;
min-width: 0;
color: #26232b;
}
.notify-demo-eyebrow {
font: 0.625rem/1.6 monospace;
letter-spacing: 0.12em;
text-transform: uppercase;
color: #655d68;
}
.notify-demo-heading {
font-size: clamp(1.4rem, 3vw, 1.9rem);
line-height: 1.25;
font-weight: 500;
letter-spacing: -0.035em;
}
.notify-demo-description {
max-width: 45rem;
color: #5f5763;
line-height: 1.7;
}
.notify-demo p {
margin: 0;
}
.notify-demo-field {
display: grid;
gap: 0.5rem;
min-width: 0;
max-width: 28rem;
color: #5f5763;
font-size: 0.8125rem;
}
.notify-demo-field select {
display: block;
box-sizing: border-box;
min-width: 0;
width: 100%;
min-height: 3.125rem;
padding: 0.75rem 1rem;
font:
400 1rem/1.5 system-ui,
sans-serif;
color: #26232b;
background: #f4f2f7;
border: 0.0625rem solid #b7adb9;
border-radius: 0.5rem;
}
.notify-demo-select {
display: block;
position: relative;
min-width: 0;
color: #5f5763;
}
.notify-demo-select::after {
content: '';
box-sizing: border-box;
position: absolute;
inset-inline-end: min(1rem, 5vw);
top: 50%;
width: 0.5rem;
height: 0.5rem;
border-right: 0.125rem solid currentColor;
border-bottom: 0.125rem solid currentColor;
transform: translateY(-70%) rotate(45deg);
pointer-events: none;
}
.notify-demo-select select {
appearance: none;
cursor: pointer;
padding-inline-start: min(1rem, 5vw);
padding-inline-end: min(2.75rem, 12vw);
}
.notify-demo-select:has(select:disabled)::after {
opacity: 0.5;
}
.notify-demo-field select:disabled {
opacity: 0.5;
cursor: not-allowed;
}
@media (hover: hover) {
.notify-demo-field select:enabled:hover {
border-color: #8d7a98;
}
}
.notify-demo-result {
min-height: 1.5rem;
font-size: 0.8125rem;
color: #5f5763;
}
.notify-demo-actions {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 0.625rem;
padding-top: 0.5rem;
}
.notify-demo-actions button {
display: inline-flex;
align-items: center;
justify-content: center;
box-sizing: border-box;
min-height: 3.125rem;
padding: 0.5rem 1.4rem;
font:
500 0.875rem/1.5 system-ui,
sans-serif;
letter-spacing: -0.01em;
cursor: pointer;
border: 0.0625rem solid #b7adb9;
border-radius: 0.875rem;
color: #26232b;
background: #f4f2f7;
}
.notify-demo-actions [data-demo-action] {
background: #b45309;
border-color: transparent;
color: #fff;
}
.notify-demo-actions [data-demo-reset] {
min-height: 2.5rem;
padding-inline: 1rem;
border-radius: 624.9375rem;
color: #5f5763;
border-color: #b7adb9;
background: transparent;
}
.notify-demo-actions button:disabled {
opacity: 0.5;
cursor: not-allowed;
}
@media (hover: hover) {
.notify-demo-actions button:enabled:hover {
background: #e8e5ed;
border-color: #8d7a98;
}
.notify-demo-actions [data-demo-action]:enabled:hover {
background: #92400e;
border-color: transparent;
}
.notify-demo-actions [data-demo-reset]:enabled:hover {
color: #b45309;
background: #fef3c7;
}
}
.notify-demo :focus-visible {
outline: 0.125rem solid #b45309;
outline-offset: 0.1875rem;
}
.notify-demo-fields {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(min(100%, 12rem), 1fr));
gap: 1rem;
align-items: end;
}
.notify-demo [hidden] {
display: none;
}
.notify-demo-actions button {
overflow-wrap: anywhere;
max-width: 100%;
}
</style>
</head>
<body>
<main
style="max-width: 48rem; margin: 2rem auto; padding: 1rem; font-family: system-ui, sans-serif"
>
<section
class="notify-demo"
data-notify-demo
data-preset="position"
aria-label="Notification preferences"
>
<p class="notify-demo-eyebrow">Notification preferences</p>
<strong class="notify-demo-heading">Put feedback where it belongs.</strong>
<p class="notify-demo-description">
Choose position, theme and reading direction. Preview the same notification, then apply
changes while it is still open.
</p>
<div class="notify-demo-fields">
<label class="notify-demo-field"
>Position<span class="notify-demo-select"
><select data-position>
<option value="bottom-right">Bottom right</option>
<option value="bottom-left">Bottom left</option>
<option value="top-right">Top right</option>
<option value="top-left">Top left</option>
<option value="top-center">Top center</option>
<option value="bottom-center">Bottom center</option>
</select></span
></label
><label class="notify-demo-field"
>Theme<span class="notify-demo-select"
><select data-theme>
<option value="page">Follow the page</option>
<option value="light">Light</option>
<option value="dark">Dark</option>
<option value="system">Follow the operating system</option>
</select></span
></label
><label class="notify-demo-field"
>Reading direction<span class="notify-demo-select"
><select data-direction>
<option value="ltr">Left to right</option>
<option value="rtl">Right to left</option>
</select></span
></label
>
</div>
<p class="notify-demo-result" data-demo-result role="status">
Bottom right · Follows the page theme
</p>
<div class="notify-demo-actions">
<button type="button" data-demo-action>Preview preference</button>
<button type="button" data-demo-reset>Reset this preview</button>
</div>
</section>
</main>
<script type="module">
import { browser as notify } from '@samline/notify'
import '@samline/notify/style.css'
const copy = { preference: 'Notification preference applied' }
const positionDemo = (element, notify, copy, signal) => {
const [place, theme, direction] = ['position', 'theme', 'direction'].map(name =>
element.querySelector(`[data-${name}]`)
)
const result = element.querySelector('[data-demo-result]')
const initial = result.textContent
// "Follow the page" sends no theme, so the toaster keeps its default.
const preferences = () => ({
position: place.value,
theme: theme.value === 'page' ? undefined : theme.value,
dir: direction.value,
})
// Changing a preference updates the toast that is already on screen.
for (const select of [place, theme, direction]) {
select.addEventListener(
'change',
() => {
if (notify.toast.getToasts().length) notify.createToaster(preferences())
},
{ signal }
)
}
element.querySelector('[data-demo-action]').addEventListener(
'click',
() => {
notify.createToaster({ richColors: true, closeButton: true, ...preferences() })
const label = place.selectedOptions[0].textContent
notify.toast.success(copy.preference, { description: label })
result.textContent = label
},
{ signal }
)
element.querySelector('[data-demo-reset]').addEventListener(
'click',
() => {
notify.toast.dismiss()
result.textContent = initial
},
{ signal }
)
}
positionDemo(document.querySelector('[data-notify-demo]'), notify, copy)
// A page that is leaving no longer needs its toaster.
window.addEventListener('pagehide', event => {
if (!event.persisted) notify.destroyToaster()
})
</script>
</body>
</html>
Dismiss the toast. Keep the receipt.
Activity log
A useful record of what happened.Create a local activity entry, dismiss its notification, then compare the active state and history.
No activity in this preview yet.
getToasts() excludes dismissed records. getHistory() keeps the latest record for each id until reset, not an append-only event log.
Explore the code
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Dismiss the toast. Keep the receipt.</title>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@samline/notify@5.0.1/dist/style.css"
/>
<link rel="stylesheet" href="./style.css" />
</head>
<body>
<main
style="max-width: 48rem; margin: 2rem auto; padding: 1rem; font-family: system-ui, sans-serif"
>
<section class="notify-demo" data-notify-demo data-preset="history" aria-label="Activity log">
<p class="notify-demo-eyebrow">Activity log</p>
<strong class="notify-demo-heading">A useful record of what happened.</strong>
<p class="notify-demo-description">
Create a local activity entry, dismiss its notification, then compare the active state and
history.
</p>
<p class="notify-demo-result" data-demo-result role="status">
No activity in this preview yet.
</p>
<div class="notify-demo-actions">
<button type="button" data-demo-action>Add activity</button>
<button type="button" data-demo-dismiss>Dismiss notification</button>
<button type="button" data-demo-reset>Reset this preview</button>
</div>
</section>
</main>
<script src="https://cdn.jsdelivr.net/npm/@samline/notify@5.0.1/dist/browser/notify.global.js"></script>
<script src="./main.js"></script>
</body>
</html>
/* Demo form only. Toast appearance and motion come from @samline/notify/style.css. */
.notify-demo {
display: grid;
gap: 1rem;
min-width: 0;
color: #26232b;
}
.notify-demo-eyebrow {
font: 0.625rem/1.6 monospace;
letter-spacing: 0.12em;
text-transform: uppercase;
color: #655d68;
}
.notify-demo-heading {
font-size: clamp(1.4rem, 3vw, 1.9rem);
line-height: 1.25;
font-weight: 500;
letter-spacing: -0.035em;
}
.notify-demo-description {
max-width: 45rem;
color: #5f5763;
line-height: 1.7;
}
.notify-demo p {
margin: 0;
}
.notify-demo-result {
min-height: 1.5rem;
font-size: 0.8125rem;
color: #5f5763;
}
.notify-demo-actions {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 0.625rem;
padding-top: 0.5rem;
}
.notify-demo-actions button {
display: inline-flex;
align-items: center;
justify-content: center;
box-sizing: border-box;
min-height: 3.125rem;
padding: 0.5rem 1.4rem;
font:
500 0.875rem/1.5 system-ui,
sans-serif;
letter-spacing: -0.01em;
cursor: pointer;
border: 0.0625rem solid #b7adb9;
border-radius: 0.875rem;
color: #26232b;
background: #f4f2f7;
}
.notify-demo-actions [data-demo-action] {
background: #b45309;
border-color: transparent;
color: #fff;
}
.notify-demo-actions [data-demo-reset] {
min-height: 2.5rem;
padding-inline: 1rem;
border-radius: 624.9375rem;
color: #5f5763;
border-color: #b7adb9;
background: transparent;
}
.notify-demo-actions button:disabled {
opacity: 0.5;
cursor: not-allowed;
}
@media (hover: hover) {
.notify-demo-actions button:enabled:hover {
background: #e8e5ed;
border-color: #8d7a98;
}
.notify-demo-actions [data-demo-action]:enabled:hover {
background: #92400e;
border-color: transparent;
}
.notify-demo-actions [data-demo-reset]:enabled:hover {
color: #b45309;
background: #fef3c7;
}
}
.notify-demo :focus-visible {
outline: 0.125rem solid #b45309;
outline-offset: 0.1875rem;
}
.notify-demo [hidden] {
display: none;
}
.notify-demo-actions button {
overflow-wrap: anywhere;
max-width: 100%;
}
const notify = window.Notify
const copy = { active: 'Active', history: 'History', activity: 'Activity recorded' }
const historyDemo = (element, notify, copy, signal) => {
const action = element.querySelector('[data-demo-action]')
const result = element.querySelector('[data-demo-result]')
const initial = result.textContent
const mine = new Set() // ids created by this demo
let count = 0
// A dismissed toast leaves getToasts() but stays in getHistory().
const snapshot = () => {
const owned = records => records.filter(record => mine.has(record.id)).length
const active = owned(notify.toast.getToasts())
const history = owned(notify.toast.getHistory())
result.textContent = `${copy.active}: ${active} · ${copy.history}: ${history}`
}
action.addEventListener(
'click',
() => {
notify.createToaster({ richColors: true, closeButton: true })
count += 1
// Functions are evaluated each time the toast renders.
const id = notify.toast.success(() => `${copy.activity} ${count}`, {
description: () =>
new Date().toLocaleTimeString('en', { hour: '2-digit', minute: '2-digit' }),
onDismiss: snapshot,
})
mine.add(id)
snapshot()
},
{ signal }
)
element.querySelector('[data-demo-dismiss]').addEventListener(
'click',
() => {
notify.toast.dismiss()
snapshot()
},
{ signal }
)
element.querySelector('[data-demo-reset]').addEventListener(
'click',
() => {
notify.toast.dismiss()
mine.clear()
result.textContent = initial
},
{ signal }
)
}
historyDemo(document.querySelector('[data-notify-demo]'), notify, copy)
// A page that is leaving no longer needs its toaster.
window.addEventListener('pagehide', event => {
if (!event.persisted) notify.destroyToaster()
})
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Dismiss the toast. Keep the receipt.</title>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@samline/notify@5.0.1/dist/style.css"
/>
<style>
/* Demo form only. Toast appearance and motion come from @samline/notify/style.css. */
.notify-demo {
display: grid;
gap: 1rem;
min-width: 0;
color: #26232b;
}
.notify-demo-eyebrow {
font: 0.625rem/1.6 monospace;
letter-spacing: 0.12em;
text-transform: uppercase;
color: #655d68;
}
.notify-demo-heading {
font-size: clamp(1.4rem, 3vw, 1.9rem);
line-height: 1.25;
font-weight: 500;
letter-spacing: -0.035em;
}
.notify-demo-description {
max-width: 45rem;
color: #5f5763;
line-height: 1.7;
}
.notify-demo p {
margin: 0;
}
.notify-demo-result {
min-height: 1.5rem;
font-size: 0.8125rem;
color: #5f5763;
}
.notify-demo-actions {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 0.625rem;
padding-top: 0.5rem;
}
.notify-demo-actions button {
display: inline-flex;
align-items: center;
justify-content: center;
box-sizing: border-box;
min-height: 3.125rem;
padding: 0.5rem 1.4rem;
font:
500 0.875rem/1.5 system-ui,
sans-serif;
letter-spacing: -0.01em;
cursor: pointer;
border: 0.0625rem solid #b7adb9;
border-radius: 0.875rem;
color: #26232b;
background: #f4f2f7;
}
.notify-demo-actions [data-demo-action] {
background: #b45309;
border-color: transparent;
color: #fff;
}
.notify-demo-actions [data-demo-reset] {
min-height: 2.5rem;
padding-inline: 1rem;
border-radius: 624.9375rem;
color: #5f5763;
border-color: #b7adb9;
background: transparent;
}
.notify-demo-actions button:disabled {
opacity: 0.5;
cursor: not-allowed;
}
@media (hover: hover) {
.notify-demo-actions button:enabled:hover {
background: #e8e5ed;
border-color: #8d7a98;
}
.notify-demo-actions [data-demo-action]:enabled:hover {
background: #92400e;
border-color: transparent;
}
.notify-demo-actions [data-demo-reset]:enabled:hover {
color: #b45309;
background: #fef3c7;
}
}
.notify-demo :focus-visible {
outline: 0.125rem solid #b45309;
outline-offset: 0.1875rem;
}
.notify-demo [hidden] {
display: none;
}
.notify-demo-actions button {
overflow-wrap: anywhere;
max-width: 100%;
}
</style>
</head>
<body>
<main
style="max-width: 48rem; margin: 2rem auto; padding: 1rem; font-family: system-ui, sans-serif"
>
<section class="notify-demo" data-notify-demo data-preset="history" aria-label="Activity log">
<p class="notify-demo-eyebrow">Activity log</p>
<strong class="notify-demo-heading">A useful record of what happened.</strong>
<p class="notify-demo-description">
Create a local activity entry, dismiss its notification, then compare the active state and
history.
</p>
<p class="notify-demo-result" data-demo-result role="status">
No activity in this preview yet.
</p>
<div class="notify-demo-actions">
<button type="button" data-demo-action>Add activity</button>
<button type="button" data-demo-dismiss>Dismiss notification</button>
<button type="button" data-demo-reset>Reset this preview</button>
</div>
</section>
</main>
<script src="https://cdn.jsdelivr.net/npm/@samline/notify@5.0.1/dist/browser/notify.global.js"></script>
<script>
const notify = window.Notify
const copy = { active: 'Active', history: 'History', activity: 'Activity recorded' }
const historyDemo = (element, notify, copy, signal) => {
const action = element.querySelector('[data-demo-action]')
const result = element.querySelector('[data-demo-result]')
const initial = result.textContent
const mine = new Set() // ids created by this demo
let count = 0
// A dismissed toast leaves getToasts() but stays in getHistory().
const snapshot = () => {
const owned = records => records.filter(record => mine.has(record.id)).length
const active = owned(notify.toast.getToasts())
const history = owned(notify.toast.getHistory())
result.textContent = `${copy.active}: ${active} · ${copy.history}: ${history}`
}
action.addEventListener(
'click',
() => {
notify.createToaster({ richColors: true, closeButton: true })
count += 1
// Functions are evaluated each time the toast renders.
const id = notify.toast.success(() => `${copy.activity} ${count}`, {
description: () =>
new Date().toLocaleTimeString('en', { hour: '2-digit', minute: '2-digit' }),
onDismiss: snapshot,
})
mine.add(id)
snapshot()
},
{ signal }
)
element.querySelector('[data-demo-dismiss]').addEventListener(
'click',
() => {
notify.toast.dismiss()
snapshot()
},
{ signal }
)
element.querySelector('[data-demo-reset]').addEventListener(
'click',
() => {
notify.toast.dismiss()
mine.clear()
result.textContent = initial
},
{ signal }
)
}
historyDemo(document.querySelector('[data-notify-demo]'), notify, copy)
// A page that is leaving no longer needs its toaster.
window.addEventListener('pagehide', event => {
if (!event.persisted) notify.destroyToaster()
})
</script>
</body>
</html>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Dismiss the toast. Keep the receipt.</title>
</head>
<body>
<main
style="max-width: 48rem; margin: 2rem auto; padding: 1rem; font-family: system-ui, sans-serif"
>
<section class="notify-demo" data-notify-demo data-preset="history" aria-label="Activity log">
<p class="notify-demo-eyebrow">Activity log</p>
<strong class="notify-demo-heading">A useful record of what happened.</strong>
<p class="notify-demo-description">
Create a local activity entry, dismiss its notification, then compare the active state and
history.
</p>
<p class="notify-demo-result" data-demo-result role="status">
No activity in this preview yet.
</p>
<div class="notify-demo-actions">
<button type="button" data-demo-action>Add activity</button>
<button type="button" data-demo-dismiss>Dismiss notification</button>
<button type="button" data-demo-reset>Reset this preview</button>
</div>
</section>
</main>
<script type="module" src="./main.js"></script>
</body>
</html>
/* Demo form only. Toast appearance and motion come from @samline/notify/style.css. */
.notify-demo {
display: grid;
gap: 1rem;
min-width: 0;
color: #26232b;
}
.notify-demo-eyebrow {
font: 0.625rem/1.6 monospace;
letter-spacing: 0.12em;
text-transform: uppercase;
color: #655d68;
}
.notify-demo-heading {
font-size: clamp(1.4rem, 3vw, 1.9rem);
line-height: 1.25;
font-weight: 500;
letter-spacing: -0.035em;
}
.notify-demo-description {
max-width: 45rem;
color: #5f5763;
line-height: 1.7;
}
.notify-demo p {
margin: 0;
}
.notify-demo-result {
min-height: 1.5rem;
font-size: 0.8125rem;
color: #5f5763;
}
.notify-demo-actions {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 0.625rem;
padding-top: 0.5rem;
}
.notify-demo-actions button {
display: inline-flex;
align-items: center;
justify-content: center;
box-sizing: border-box;
min-height: 3.125rem;
padding: 0.5rem 1.4rem;
font:
500 0.875rem/1.5 system-ui,
sans-serif;
letter-spacing: -0.01em;
cursor: pointer;
border: 0.0625rem solid #b7adb9;
border-radius: 0.875rem;
color: #26232b;
background: #f4f2f7;
}
.notify-demo-actions [data-demo-action] {
background: #b45309;
border-color: transparent;
color: #fff;
}
.notify-demo-actions [data-demo-reset] {
min-height: 2.5rem;
padding-inline: 1rem;
border-radius: 624.9375rem;
color: #5f5763;
border-color: #b7adb9;
background: transparent;
}
.notify-demo-actions button:disabled {
opacity: 0.5;
cursor: not-allowed;
}
@media (hover: hover) {
.notify-demo-actions button:enabled:hover {
background: #e8e5ed;
border-color: #8d7a98;
}
.notify-demo-actions [data-demo-action]:enabled:hover {
background: #92400e;
border-color: transparent;
}
.notify-demo-actions [data-demo-reset]:enabled:hover {
color: #b45309;
background: #fef3c7;
}
}
.notify-demo :focus-visible {
outline: 0.125rem solid #b45309;
outline-offset: 0.1875rem;
}
.notify-demo [hidden] {
display: none;
}
.notify-demo-actions button {
overflow-wrap: anywhere;
max-width: 100%;
}
import { browser as notify } from '@samline/notify'
import '@samline/notify/style.css'
import './style.css'
const copy = { active: 'Active', history: 'History', activity: 'Activity recorded' }
const historyDemo = (element, notify, copy, signal) => {
const action = element.querySelector('[data-demo-action]')
const result = element.querySelector('[data-demo-result]')
const initial = result.textContent
const mine = new Set() // ids created by this demo
let count = 0
// A dismissed toast leaves getToasts() but stays in getHistory().
const snapshot = () => {
const owned = records => records.filter(record => mine.has(record.id)).length
const active = owned(notify.toast.getToasts())
const history = owned(notify.toast.getHistory())
result.textContent = `${copy.active}: ${active} · ${copy.history}: ${history}`
}
action.addEventListener(
'click',
() => {
notify.createToaster({ richColors: true, closeButton: true })
count += 1
// Functions are evaluated each time the toast renders.
const id = notify.toast.success(() => `${copy.activity} ${count}`, {
description: () =>
new Date().toLocaleTimeString('en', { hour: '2-digit', minute: '2-digit' }),
onDismiss: snapshot,
})
mine.add(id)
snapshot()
},
{ signal }
)
element.querySelector('[data-demo-dismiss]').addEventListener(
'click',
() => {
notify.toast.dismiss()
snapshot()
},
{ signal }
)
element.querySelector('[data-demo-reset]').addEventListener(
'click',
() => {
notify.toast.dismiss()
mine.clear()
result.textContent = initial
},
{ signal }
)
}
historyDemo(document.querySelector('[data-notify-demo]'), notify, copy)
// A page that is leaving no longer needs its toaster.
window.addEventListener('pagehide', event => {
if (!event.persisted) notify.destroyToaster()
})
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Dismiss the toast. Keep the receipt.</title>
<style>
/* Demo form only. Toast appearance and motion come from @samline/notify/style.css. */
.notify-demo {
display: grid;
gap: 1rem;
min-width: 0;
color: #26232b;
}
.notify-demo-eyebrow {
font: 0.625rem/1.6 monospace;
letter-spacing: 0.12em;
text-transform: uppercase;
color: #655d68;
}
.notify-demo-heading {
font-size: clamp(1.4rem, 3vw, 1.9rem);
line-height: 1.25;
font-weight: 500;
letter-spacing: -0.035em;
}
.notify-demo-description {
max-width: 45rem;
color: #5f5763;
line-height: 1.7;
}
.notify-demo p {
margin: 0;
}
.notify-demo-result {
min-height: 1.5rem;
font-size: 0.8125rem;
color: #5f5763;
}
.notify-demo-actions {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 0.625rem;
padding-top: 0.5rem;
}
.notify-demo-actions button {
display: inline-flex;
align-items: center;
justify-content: center;
box-sizing: border-box;
min-height: 3.125rem;
padding: 0.5rem 1.4rem;
font:
500 0.875rem/1.5 system-ui,
sans-serif;
letter-spacing: -0.01em;
cursor: pointer;
border: 0.0625rem solid #b7adb9;
border-radius: 0.875rem;
color: #26232b;
background: #f4f2f7;
}
.notify-demo-actions [data-demo-action] {
background: #b45309;
border-color: transparent;
color: #fff;
}
.notify-demo-actions [data-demo-reset] {
min-height: 2.5rem;
padding-inline: 1rem;
border-radius: 624.9375rem;
color: #5f5763;
border-color: #b7adb9;
background: transparent;
}
.notify-demo-actions button:disabled {
opacity: 0.5;
cursor: not-allowed;
}
@media (hover: hover) {
.notify-demo-actions button:enabled:hover {
background: #e8e5ed;
border-color: #8d7a98;
}
.notify-demo-actions [data-demo-action]:enabled:hover {
background: #92400e;
border-color: transparent;
}
.notify-demo-actions [data-demo-reset]:enabled:hover {
color: #b45309;
background: #fef3c7;
}
}
.notify-demo :focus-visible {
outline: 0.125rem solid #b45309;
outline-offset: 0.1875rem;
}
.notify-demo [hidden] {
display: none;
}
.notify-demo-actions button {
overflow-wrap: anywhere;
max-width: 100%;
}
</style>
</head>
<body>
<main
style="max-width: 48rem; margin: 2rem auto; padding: 1rem; font-family: system-ui, sans-serif"
>
<section class="notify-demo" data-notify-demo data-preset="history" aria-label="Activity log">
<p class="notify-demo-eyebrow">Activity log</p>
<strong class="notify-demo-heading">A useful record of what happened.</strong>
<p class="notify-demo-description">
Create a local activity entry, dismiss its notification, then compare the active state and
history.
</p>
<p class="notify-demo-result" data-demo-result role="status">
No activity in this preview yet.
</p>
<div class="notify-demo-actions">
<button type="button" data-demo-action>Add activity</button>
<button type="button" data-demo-dismiss>Dismiss notification</button>
<button type="button" data-demo-reset>Reset this preview</button>
</div>
</section>
</main>
<script type="module">
import { browser as notify } from '@samline/notify'
import '@samline/notify/style.css'
const copy = { active: 'Active', history: 'History', activity: 'Activity recorded' }
const historyDemo = (element, notify, copy, signal) => {
const action = element.querySelector('[data-demo-action]')
const result = element.querySelector('[data-demo-result]')
const initial = result.textContent
const mine = new Set() // ids created by this demo
let count = 0
// A dismissed toast leaves getToasts() but stays in getHistory().
const snapshot = () => {
const owned = records => records.filter(record => mine.has(record.id)).length
const active = owned(notify.toast.getToasts())
const history = owned(notify.toast.getHistory())
result.textContent = `${copy.active}: ${active} · ${copy.history}: ${history}`
}
action.addEventListener(
'click',
() => {
notify.createToaster({ richColors: true, closeButton: true })
count += 1
// Functions are evaluated each time the toast renders.
const id = notify.toast.success(() => `${copy.activity} ${count}`, {
description: () =>
new Date().toLocaleTimeString('en', { hour: '2-digit', minute: '2-digit' }),
onDismiss: snapshot,
})
mine.add(id)
snapshot()
},
{ signal }
)
element.querySelector('[data-demo-dismiss]').addEventListener(
'click',
() => {
notify.toast.dismiss()
snapshot()
},
{ signal }
)
element.querySelector('[data-demo-reset]').addEventListener(
'click',
() => {
notify.toast.dismiss()
mine.clear()
result.textContent = initial
},
{ signal }
)
}
historyDemo(document.querySelector('[data-notify-demo]'), notify, copy)
// A page that is leaving no longer needs its toaster.
window.addEventListener('pagehide', event => {
if (!event.persisted) notify.destroyToaster()
})
</script>
</body>
</html>
An action can begin a conversation
Workspace invitation
The right access, before you join.Review an Editor invitation to Studio. Read its permissions, then join or choose Not now. This is a local decision preview.
Studio · Editor invitation pending
action and cancel offer two real outcomes. closeOnClick: false keeps the same notification alive while Review becomes Join. A notification supports a lightweight choice; use a dialog for a blocking decision.
Explore the code
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>An action can begin a conversation</title>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@samline/notify@5.0.1/dist/style.css"
/>
<link rel="stylesheet" href="./style.css" />
</head>
<body>
<main
style="max-width: 48rem; margin: 2rem auto; padding: 1rem; font-family: system-ui, sans-serif"
>
<section
class="notify-demo"
data-notify-demo
data-preset="decisions"
aria-label="Workspace invitation"
>
<p class="notify-demo-eyebrow">Workspace invitation</p>
<strong class="notify-demo-heading">The right access, before you join.</strong>
<p class="notify-demo-description">
Review an Editor invitation to Studio. Read its permissions, then join or choose Not now.
This is a local decision preview.
</p>
<p data-review-details hidden></p>
<p class="notify-demo-result" data-demo-result role="status">
Studio · Editor invitation pending
</p>
<div class="notify-demo-actions">
<button type="button" data-demo-action>Review invitation</button>
<button type="button" data-demo-reset>Reset this preview</button>
</div>
</section>
</main>
<script src="https://cdn.jsdelivr.net/npm/@samline/notify@5.0.1/dist/browser/notify.global.js"></script>
<script src="./main.js"></script>
</body>
</html>
/* Demo form only. Toast appearance and motion come from @samline/notify/style.css. */
.notify-demo {
display: grid;
gap: 1rem;
min-width: 0;
color: #26232b;
}
.notify-demo-eyebrow {
font: 0.625rem/1.6 monospace;
letter-spacing: 0.12em;
text-transform: uppercase;
color: #655d68;
}
.notify-demo-heading {
font-size: clamp(1.4rem, 3vw, 1.9rem);
line-height: 1.25;
font-weight: 500;
letter-spacing: -0.035em;
}
.notify-demo-description {
max-width: 45rem;
color: #5f5763;
line-height: 1.7;
}
.notify-demo p {
margin: 0;
}
.notify-demo-result {
min-height: 1.5rem;
font-size: 0.8125rem;
color: #5f5763;
}
.notify-demo-actions {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 0.625rem;
padding-top: 0.5rem;
}
.notify-demo-actions button {
display: inline-flex;
align-items: center;
justify-content: center;
box-sizing: border-box;
min-height: 3.125rem;
padding: 0.5rem 1.4rem;
font:
500 0.875rem/1.5 system-ui,
sans-serif;
letter-spacing: -0.01em;
cursor: pointer;
border: 0.0625rem solid #b7adb9;
border-radius: 0.875rem;
color: #26232b;
background: #f4f2f7;
}
.notify-demo-actions [data-demo-action] {
background: #b45309;
border-color: transparent;
color: #fff;
}
.notify-demo-actions [data-demo-reset] {
min-height: 2.5rem;
padding-inline: 1rem;
border-radius: 624.9375rem;
color: #5f5763;
border-color: #b7adb9;
background: transparent;
}
.notify-demo-actions button:disabled {
opacity: 0.5;
cursor: not-allowed;
}
@media (hover: hover) {
.notify-demo-actions button:enabled:hover {
background: #e8e5ed;
border-color: #8d7a98;
}
.notify-demo-actions [data-demo-action]:enabled:hover {
background: #92400e;
border-color: transparent;
}
.notify-demo-actions [data-demo-reset]:enabled:hover {
color: #b45309;
background: #fef3c7;
}
}
.notify-demo :focus-visible {
outline: 0.125rem solid #b45309;
outline-offset: 0.1875rem;
}
.notify-demo [hidden] {
display: none;
}
.notify-demo-actions button {
overflow-wrap: anywhere;
max-width: 100%;
}
const notify = window.Notify
const copy = {
invitation: 'You are invited to Studio',
review: 'Review access',
reviewDetails:
'Editor: upload assets and edit content. Billing and workspace administration stay with owners.',
joinQuestion: 'Join Studio as an Editor?',
join: 'Join workspace',
joined: 'You joined Studio as an Editor',
later: 'Not now',
deferred: 'Invitation saved for later. You have not joined Studio.',
}
const decisionsDemo = (element, notify, copy, signal) => {
const details = element.querySelector('[data-review-details]')
const result = element.querySelector('[data-demo-result]')
const initial = result.textContent
const notNow = { label: copy.later, onClick: () => (result.textContent = copy.deferred) }
let id
// closeOnClick: false keeps one toast alive while its action changes.
const join = () => {
result.textContent = copy.joined
notify.toast.success(copy.joined, { id, duration: 6000, action: undefined, cancel: undefined })
}
const review = () => {
details.hidden = false
details.textContent = copy.reviewDetails
result.textContent = copy.joinQuestion
notify.toast.info(copy.joinQuestion, {
id,
description: copy.reviewDetails,
duration: Infinity,
action: { label: copy.join, closeOnClick: false, onClick: join },
cancel: notNow,
})
}
element.querySelector('[data-demo-action]').addEventListener(
'click',
() => {
notify.createToaster({ richColors: true, closeButton: true })
id = notify.toast.info(copy.invitation, {
description: copy.reviewDetails,
duration: Infinity,
action: { label: copy.review, closeOnClick: false, onClick: review },
cancel: notNow,
})
},
{ signal }
)
element.querySelector('[data-demo-reset]').addEventListener(
'click',
() => {
notify.toast.dismiss()
details.hidden = true
details.textContent = ''
result.textContent = initial
},
{ signal }
)
}
decisionsDemo(document.querySelector('[data-notify-demo]'), notify, copy)
// A page that is leaving no longer needs its toaster.
window.addEventListener('pagehide', event => {
if (!event.persisted) notify.destroyToaster()
})
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>An action can begin a conversation</title>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@samline/notify@5.0.1/dist/style.css"
/>
<style>
/* Demo form only. Toast appearance and motion come from @samline/notify/style.css. */
.notify-demo {
display: grid;
gap: 1rem;
min-width: 0;
color: #26232b;
}
.notify-demo-eyebrow {
font: 0.625rem/1.6 monospace;
letter-spacing: 0.12em;
text-transform: uppercase;
color: #655d68;
}
.notify-demo-heading {
font-size: clamp(1.4rem, 3vw, 1.9rem);
line-height: 1.25;
font-weight: 500;
letter-spacing: -0.035em;
}
.notify-demo-description {
max-width: 45rem;
color: #5f5763;
line-height: 1.7;
}
.notify-demo p {
margin: 0;
}
.notify-demo-result {
min-height: 1.5rem;
font-size: 0.8125rem;
color: #5f5763;
}
.notify-demo-actions {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 0.625rem;
padding-top: 0.5rem;
}
.notify-demo-actions button {
display: inline-flex;
align-items: center;
justify-content: center;
box-sizing: border-box;
min-height: 3.125rem;
padding: 0.5rem 1.4rem;
font:
500 0.875rem/1.5 system-ui,
sans-serif;
letter-spacing: -0.01em;
cursor: pointer;
border: 0.0625rem solid #b7adb9;
border-radius: 0.875rem;
color: #26232b;
background: #f4f2f7;
}
.notify-demo-actions [data-demo-action] {
background: #b45309;
border-color: transparent;
color: #fff;
}
.notify-demo-actions [data-demo-reset] {
min-height: 2.5rem;
padding-inline: 1rem;
border-radius: 624.9375rem;
color: #5f5763;
border-color: #b7adb9;
background: transparent;
}
.notify-demo-actions button:disabled {
opacity: 0.5;
cursor: not-allowed;
}
@media (hover: hover) {
.notify-demo-actions button:enabled:hover {
background: #e8e5ed;
border-color: #8d7a98;
}
.notify-demo-actions [data-demo-action]:enabled:hover {
background: #92400e;
border-color: transparent;
}
.notify-demo-actions [data-demo-reset]:enabled:hover {
color: #b45309;
background: #fef3c7;
}
}
.notify-demo :focus-visible {
outline: 0.125rem solid #b45309;
outline-offset: 0.1875rem;
}
.notify-demo [hidden] {
display: none;
}
.notify-demo-actions button {
overflow-wrap: anywhere;
max-width: 100%;
}
</style>
</head>
<body>
<main
style="max-width: 48rem; margin: 2rem auto; padding: 1rem; font-family: system-ui, sans-serif"
>
<section
class="notify-demo"
data-notify-demo
data-preset="decisions"
aria-label="Workspace invitation"
>
<p class="notify-demo-eyebrow">Workspace invitation</p>
<strong class="notify-demo-heading">The right access, before you join.</strong>
<p class="notify-demo-description">
Review an Editor invitation to Studio. Read its permissions, then join or choose Not now.
This is a local decision preview.
</p>
<p data-review-details hidden></p>
<p class="notify-demo-result" data-demo-result role="status">
Studio · Editor invitation pending
</p>
<div class="notify-demo-actions">
<button type="button" data-demo-action>Review invitation</button>
<button type="button" data-demo-reset>Reset this preview</button>
</div>
</section>
</main>
<script src="https://cdn.jsdelivr.net/npm/@samline/notify@5.0.1/dist/browser/notify.global.js"></script>
<script>
const notify = window.Notify
const copy = {
invitation: 'You are invited to Studio',
review: 'Review access',
reviewDetails:
'Editor: upload assets and edit content. Billing and workspace administration stay with owners.',
joinQuestion: 'Join Studio as an Editor?',
join: 'Join workspace',
joined: 'You joined Studio as an Editor',
later: 'Not now',
deferred: 'Invitation saved for later. You have not joined Studio.',
}
const decisionsDemo = (element, notify, copy, signal) => {
const details = element.querySelector('[data-review-details]')
const result = element.querySelector('[data-demo-result]')
const initial = result.textContent
const notNow = { label: copy.later, onClick: () => (result.textContent = copy.deferred) }
let id
// closeOnClick: false keeps one toast alive while its action changes.
const join = () => {
result.textContent = copy.joined
notify.toast.success(copy.joined, {
id,
duration: 6000,
action: undefined,
cancel: undefined,
})
}
const review = () => {
details.hidden = false
details.textContent = copy.reviewDetails
result.textContent = copy.joinQuestion
notify.toast.info(copy.joinQuestion, {
id,
description: copy.reviewDetails,
duration: Infinity,
action: { label: copy.join, closeOnClick: false, onClick: join },
cancel: notNow,
})
}
element.querySelector('[data-demo-action]').addEventListener(
'click',
() => {
notify.createToaster({ richColors: true, closeButton: true })
id = notify.toast.info(copy.invitation, {
description: copy.reviewDetails,
duration: Infinity,
action: { label: copy.review, closeOnClick: false, onClick: review },
cancel: notNow,
})
},
{ signal }
)
element.querySelector('[data-demo-reset]').addEventListener(
'click',
() => {
notify.toast.dismiss()
details.hidden = true
details.textContent = ''
result.textContent = initial
},
{ signal }
)
}
decisionsDemo(document.querySelector('[data-notify-demo]'), notify, copy)
// A page that is leaving no longer needs its toaster.
window.addEventListener('pagehide', event => {
if (!event.persisted) notify.destroyToaster()
})
</script>
</body>
</html>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>An action can begin a conversation</title>
</head>
<body>
<main
style="max-width: 48rem; margin: 2rem auto; padding: 1rem; font-family: system-ui, sans-serif"
>
<section
class="notify-demo"
data-notify-demo
data-preset="decisions"
aria-label="Workspace invitation"
>
<p class="notify-demo-eyebrow">Workspace invitation</p>
<strong class="notify-demo-heading">The right access, before you join.</strong>
<p class="notify-demo-description">
Review an Editor invitation to Studio. Read its permissions, then join or choose Not now.
This is a local decision preview.
</p>
<p data-review-details hidden></p>
<p class="notify-demo-result" data-demo-result role="status">
Studio · Editor invitation pending
</p>
<div class="notify-demo-actions">
<button type="button" data-demo-action>Review invitation</button>
<button type="button" data-demo-reset>Reset this preview</button>
</div>
</section>
</main>
<script type="module" src="./main.js"></script>
</body>
</html>
/* Demo form only. Toast appearance and motion come from @samline/notify/style.css. */
.notify-demo {
display: grid;
gap: 1rem;
min-width: 0;
color: #26232b;
}
.notify-demo-eyebrow {
font: 0.625rem/1.6 monospace;
letter-spacing: 0.12em;
text-transform: uppercase;
color: #655d68;
}
.notify-demo-heading {
font-size: clamp(1.4rem, 3vw, 1.9rem);
line-height: 1.25;
font-weight: 500;
letter-spacing: -0.035em;
}
.notify-demo-description {
max-width: 45rem;
color: #5f5763;
line-height: 1.7;
}
.notify-demo p {
margin: 0;
}
.notify-demo-result {
min-height: 1.5rem;
font-size: 0.8125rem;
color: #5f5763;
}
.notify-demo-actions {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 0.625rem;
padding-top: 0.5rem;
}
.notify-demo-actions button {
display: inline-flex;
align-items: center;
justify-content: center;
box-sizing: border-box;
min-height: 3.125rem;
padding: 0.5rem 1.4rem;
font:
500 0.875rem/1.5 system-ui,
sans-serif;
letter-spacing: -0.01em;
cursor: pointer;
border: 0.0625rem solid #b7adb9;
border-radius: 0.875rem;
color: #26232b;
background: #f4f2f7;
}
.notify-demo-actions [data-demo-action] {
background: #b45309;
border-color: transparent;
color: #fff;
}
.notify-demo-actions [data-demo-reset] {
min-height: 2.5rem;
padding-inline: 1rem;
border-radius: 624.9375rem;
color: #5f5763;
border-color: #b7adb9;
background: transparent;
}
.notify-demo-actions button:disabled {
opacity: 0.5;
cursor: not-allowed;
}
@media (hover: hover) {
.notify-demo-actions button:enabled:hover {
background: #e8e5ed;
border-color: #8d7a98;
}
.notify-demo-actions [data-demo-action]:enabled:hover {
background: #92400e;
border-color: transparent;
}
.notify-demo-actions [data-demo-reset]:enabled:hover {
color: #b45309;
background: #fef3c7;
}
}
.notify-demo :focus-visible {
outline: 0.125rem solid #b45309;
outline-offset: 0.1875rem;
}
.notify-demo [hidden] {
display: none;
}
.notify-demo-actions button {
overflow-wrap: anywhere;
max-width: 100%;
}
import { browser as notify } from '@samline/notify'
import '@samline/notify/style.css'
import './style.css'
const copy = {
invitation: 'You are invited to Studio',
review: 'Review access',
reviewDetails:
'Editor: upload assets and edit content. Billing and workspace administration stay with owners.',
joinQuestion: 'Join Studio as an Editor?',
join: 'Join workspace',
joined: 'You joined Studio as an Editor',
later: 'Not now',
deferred: 'Invitation saved for later. You have not joined Studio.',
}
const decisionsDemo = (element, notify, copy, signal) => {
const details = element.querySelector('[data-review-details]')
const result = element.querySelector('[data-demo-result]')
const initial = result.textContent
const notNow = { label: copy.later, onClick: () => (result.textContent = copy.deferred) }
let id
// closeOnClick: false keeps one toast alive while its action changes.
const join = () => {
result.textContent = copy.joined
notify.toast.success(copy.joined, { id, duration: 6000, action: undefined, cancel: undefined })
}
const review = () => {
details.hidden = false
details.textContent = copy.reviewDetails
result.textContent = copy.joinQuestion
notify.toast.info(copy.joinQuestion, {
id,
description: copy.reviewDetails,
duration: Infinity,
action: { label: copy.join, closeOnClick: false, onClick: join },
cancel: notNow,
})
}
element.querySelector('[data-demo-action]').addEventListener(
'click',
() => {
notify.createToaster({ richColors: true, closeButton: true })
id = notify.toast.info(copy.invitation, {
description: copy.reviewDetails,
duration: Infinity,
action: { label: copy.review, closeOnClick: false, onClick: review },
cancel: notNow,
})
},
{ signal }
)
element.querySelector('[data-demo-reset]').addEventListener(
'click',
() => {
notify.toast.dismiss()
details.hidden = true
details.textContent = ''
result.textContent = initial
},
{ signal }
)
}
decisionsDemo(document.querySelector('[data-notify-demo]'), notify, copy)
// A page that is leaving no longer needs its toaster.
window.addEventListener('pagehide', event => {
if (!event.persisted) notify.destroyToaster()
})
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>An action can begin a conversation</title>
<style>
/* Demo form only. Toast appearance and motion come from @samline/notify/style.css. */
.notify-demo {
display: grid;
gap: 1rem;
min-width: 0;
color: #26232b;
}
.notify-demo-eyebrow {
font: 0.625rem/1.6 monospace;
letter-spacing: 0.12em;
text-transform: uppercase;
color: #655d68;
}
.notify-demo-heading {
font-size: clamp(1.4rem, 3vw, 1.9rem);
line-height: 1.25;
font-weight: 500;
letter-spacing: -0.035em;
}
.notify-demo-description {
max-width: 45rem;
color: #5f5763;
line-height: 1.7;
}
.notify-demo p {
margin: 0;
}
.notify-demo-result {
min-height: 1.5rem;
font-size: 0.8125rem;
color: #5f5763;
}
.notify-demo-actions {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 0.625rem;
padding-top: 0.5rem;
}
.notify-demo-actions button {
display: inline-flex;
align-items: center;
justify-content: center;
box-sizing: border-box;
min-height: 3.125rem;
padding: 0.5rem 1.4rem;
font:
500 0.875rem/1.5 system-ui,
sans-serif;
letter-spacing: -0.01em;
cursor: pointer;
border: 0.0625rem solid #b7adb9;
border-radius: 0.875rem;
color: #26232b;
background: #f4f2f7;
}
.notify-demo-actions [data-demo-action] {
background: #b45309;
border-color: transparent;
color: #fff;
}
.notify-demo-actions [data-demo-reset] {
min-height: 2.5rem;
padding-inline: 1rem;
border-radius: 624.9375rem;
color: #5f5763;
border-color: #b7adb9;
background: transparent;
}
.notify-demo-actions button:disabled {
opacity: 0.5;
cursor: not-allowed;
}
@media (hover: hover) {
.notify-demo-actions button:enabled:hover {
background: #e8e5ed;
border-color: #8d7a98;
}
.notify-demo-actions [data-demo-action]:enabled:hover {
background: #92400e;
border-color: transparent;
}
.notify-demo-actions [data-demo-reset]:enabled:hover {
color: #b45309;
background: #fef3c7;
}
}
.notify-demo :focus-visible {
outline: 0.125rem solid #b45309;
outline-offset: 0.1875rem;
}
.notify-demo [hidden] {
display: none;
}
.notify-demo-actions button {
overflow-wrap: anywhere;
max-width: 100%;
}
</style>
</head>
<body>
<main
style="max-width: 48rem; margin: 2rem auto; padding: 1rem; font-family: system-ui, sans-serif"
>
<section
class="notify-demo"
data-notify-demo
data-preset="decisions"
aria-label="Workspace invitation"
>
<p class="notify-demo-eyebrow">Workspace invitation</p>
<strong class="notify-demo-heading">The right access, before you join.</strong>
<p class="notify-demo-description">
Review an Editor invitation to Studio. Read its permissions, then join or choose Not now.
This is a local decision preview.
</p>
<p data-review-details hidden></p>
<p class="notify-demo-result" data-demo-result role="status">
Studio · Editor invitation pending
</p>
<div class="notify-demo-actions">
<button type="button" data-demo-action>Review invitation</button>
<button type="button" data-demo-reset>Reset this preview</button>
</div>
</section>
</main>
<script type="module">
import { browser as notify } from '@samline/notify'
import '@samline/notify/style.css'
const copy = {
invitation: 'You are invited to Studio',
review: 'Review access',
reviewDetails:
'Editor: upload assets and edit content. Billing and workspace administration stay with owners.',
joinQuestion: 'Join Studio as an Editor?',
join: 'Join workspace',
joined: 'You joined Studio as an Editor',
later: 'Not now',
deferred: 'Invitation saved for later. You have not joined Studio.',
}
const decisionsDemo = (element, notify, copy, signal) => {
const details = element.querySelector('[data-review-details]')
const result = element.querySelector('[data-demo-result]')
const initial = result.textContent
const notNow = { label: copy.later, onClick: () => (result.textContent = copy.deferred) }
let id
// closeOnClick: false keeps one toast alive while its action changes.
const join = () => {
result.textContent = copy.joined
notify.toast.success(copy.joined, {
id,
duration: 6000,
action: undefined,
cancel: undefined,
})
}
const review = () => {
details.hidden = false
details.textContent = copy.reviewDetails
result.textContent = copy.joinQuestion
notify.toast.info(copy.joinQuestion, {
id,
description: copy.reviewDetails,
duration: Infinity,
action: { label: copy.join, closeOnClick: false, onClick: join },
cancel: notNow,
})
}
element.querySelector('[data-demo-action]').addEventListener(
'click',
() => {
notify.createToaster({ richColors: true, closeButton: true })
id = notify.toast.info(copy.invitation, {
description: copy.reviewDetails,
duration: Infinity,
action: { label: copy.review, closeOnClick: false, onClick: review },
cancel: notNow,
})
},
{ signal }
)
element.querySelector('[data-demo-reset]').addEventListener(
'click',
() => {
notify.toast.dismiss()
details.hidden = true
details.textContent = ''
result.textContent = initial
},
{ signal }
)
}
decisionsDemo(document.querySelector('[data-notify-demo]'), notify, copy)
// A page that is leaving no longer needs its toaster.
window.addEventListener('pagehide', event => {
if (!event.persisted) notify.destroyToaster()
})
</script>
</body>
</html>
A busy workspace. A readable stack.
Studio activity
Catch up without losing your place.Play a local sequence of uploads, comments and transfer alerts. The page retains the feed while notifications stack, expire or are dismissed.
No new workspace activity.
Normal, success, info, warning and error messages share one stack. Change its visible limit and expansion live. Hover or focus to pause a timer, use Alt+T from outside a field, or swipe a corner notification. Auto-close and manual dismissal are counted separately.
Explore the code
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>A busy workspace. A readable stack.</title>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@samline/notify@5.0.1/dist/style.css"
/>
<link rel="stylesheet" href="./style.css" />
</head>
<body>
<main
style="max-width: 48rem; margin: 2rem auto; padding: 1rem; font-family: system-ui, sans-serif"
>
<section
class="notify-demo"
data-notify-demo
data-preset="stream"
aria-label="Studio activity"
>
<p class="notify-demo-eyebrow">Studio activity</p>
<strong class="notify-demo-heading">Catch up without losing your place.</strong>
<p class="notify-demo-description">
Play a local sequence of uploads, comments and transfer alerts. The page retains the feed
while notifications stack, expire or are dismissed.
</p>
<div class="notify-demo-fields">
<label class="notify-demo-field"
>Visible notifications<span class="notify-demo-select"
><select data-visible-limit>
<option value="3">3</option>
<option value="1">1</option>
<option value="5">5</option>
</select></span
></label
><label class="notify-demo-check"
><input type="checkbox" data-stack-expanded />Keep the stack expanded</label
>
</div>
<ol class="notify-demo-feed" data-event-log aria-label="Studio activity"></ol>
<p class="notify-demo-result" data-demo-result role="status">No new workspace activity.</p>
<div class="notify-demo-actions">
<button type="button" data-demo-action>Play workspace activity</button>
<button type="button" data-demo-reset>Reset this preview</button>
</div>
</section>
</main>
<script src="https://cdn.jsdelivr.net/npm/@samline/notify@5.0.1/dist/browser/notify.global.js"></script>
<script src="./main.js"></script>
</body>
</html>
/* Demo form only. Toast appearance and motion come from @samline/notify/style.css. */
.notify-demo {
display: grid;
gap: 1rem;
min-width: 0;
color: #26232b;
}
.notify-demo-eyebrow {
font: 0.625rem/1.6 monospace;
letter-spacing: 0.12em;
text-transform: uppercase;
color: #655d68;
}
.notify-demo-heading {
font-size: clamp(1.4rem, 3vw, 1.9rem);
line-height: 1.25;
font-weight: 500;
letter-spacing: -0.035em;
}
.notify-demo-description {
max-width: 45rem;
color: #5f5763;
line-height: 1.7;
}
.notify-demo p {
margin: 0;
}
.notify-demo-field {
display: grid;
gap: 0.5rem;
min-width: 0;
max-width: 28rem;
color: #5f5763;
font-size: 0.8125rem;
}
.notify-demo-field input,
.notify-demo-field select {
display: block;
box-sizing: border-box;
min-width: 0;
width: 100%;
min-height: 3.125rem;
padding: 0.75rem 1rem;
font:
400 1rem/1.5 system-ui,
sans-serif;
color: #26232b;
background: #f4f2f7;
border: 0.0625rem solid #b7adb9;
border-radius: 0.5rem;
}
.notify-demo-field input {
cursor: text;
}
.notify-demo-select {
display: block;
position: relative;
min-width: 0;
color: #5f5763;
}
.notify-demo-select::after {
content: '';
box-sizing: border-box;
position: absolute;
inset-inline-end: min(1rem, 5vw);
top: 50%;
width: 0.5rem;
height: 0.5rem;
border-right: 0.125rem solid currentColor;
border-bottom: 0.125rem solid currentColor;
transform: translateY(-70%) rotate(45deg);
pointer-events: none;
}
.notify-demo-select select {
appearance: none;
cursor: pointer;
padding-inline-start: min(1rem, 5vw);
padding-inline-end: min(2.75rem, 12vw);
}
.notify-demo-select:has(select:disabled)::after {
opacity: 0.5;
}
.notify-demo-field input:disabled,
.notify-demo-field select:disabled {
opacity: 0.5;
cursor: not-allowed;
}
@media (hover: hover) {
.notify-demo-field input:enabled:hover,
.notify-demo-field select:enabled:hover {
border-color: #8d7a98;
}
}
.notify-demo-result {
min-height: 1.5rem;
font-size: 0.8125rem;
color: #5f5763;
}
.notify-demo-actions {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 0.625rem;
padding-top: 0.5rem;
}
.notify-demo-actions button {
display: inline-flex;
align-items: center;
justify-content: center;
box-sizing: border-box;
min-height: 3.125rem;
padding: 0.5rem 1.4rem;
font:
500 0.875rem/1.5 system-ui,
sans-serif;
letter-spacing: -0.01em;
cursor: pointer;
border: 0.0625rem solid #b7adb9;
border-radius: 0.875rem;
color: #26232b;
background: #f4f2f7;
}
.notify-demo-actions [data-demo-action] {
background: #b45309;
border-color: transparent;
color: #fff;
}
.notify-demo-actions [data-demo-reset] {
min-height: 2.5rem;
padding-inline: 1rem;
border-radius: 624.9375rem;
color: #5f5763;
border-color: #b7adb9;
background: transparent;
}
.notify-demo-actions button:disabled {
opacity: 0.5;
cursor: not-allowed;
}
@media (hover: hover) {
.notify-demo-actions button:enabled:hover {
background: #e8e5ed;
border-color: #8d7a98;
}
.notify-demo-actions [data-demo-action]:enabled:hover {
background: #92400e;
border-color: transparent;
}
.notify-demo-actions [data-demo-reset]:enabled:hover {
color: #b45309;
background: #fef3c7;
}
}
.notify-demo :focus-visible {
outline: 0.125rem solid #b45309;
outline-offset: 0.1875rem;
}
.notify-demo-fields {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(min(100%, 12rem), 1fr));
gap: 1rem;
align-items: end;
}
.notify-demo-check {
cursor: pointer;
display: flex;
align-items: center;
gap: 0.5rem;
min-height: 3rem;
font-size: 0.875rem;
}
.notify-demo-check input {
flex: 0 0 auto;
width: 1.125rem;
height: 1.125rem;
margin: 0;
padding: 0;
cursor: pointer;
accent-color: #b45309;
}
.notify-demo-check:has(input:disabled),
.notify-demo-check input:disabled {
cursor: not-allowed;
opacity: 0.5;
}
.notify-demo-feed {
margin: 0;
padding-inline-start: 1.25rem;
font-size: 0.8125rem;
line-height: 1.8;
color: #5f5763;
}
.notify-demo [hidden] {
display: none;
}
.notify-demo-actions button {
overflow-wrap: anywhere;
max-width: 100%;
}
const notify = window.Notify
const copy = {
normalEvent: 'Maya joined the workspace',
successEvent: 'Campaign cover uploaded',
infoEvent: 'Alex commented on the launch checklist',
warningEvent: 'Workspace storage is almost full',
errorEvent: 'The archive transfer failed',
played: 'Activity events',
expired: 'Auto-closed',
manual: 'Dismissed manually',
}
const streamDemo = (element, notify, copy, signal) => {
const feed = element.querySelector('[data-event-log]')
const limit = element.querySelector('[data-visible-limit]')
const expanded = element.querySelector('[data-stack-expanded]')
const action = element.querySelector('[data-demo-action]')
const result = element.querySelector('[data-demo-result]')
const initial = result.textContent
const stack = () => ({ visibleToasts: Number(limit.value), expand: expanded.checked })
const events = [
[undefined, copy.normalEvent],
['success', copy.successEvent],
['info', copy.infoEvent],
['warning', copy.warningEvent],
['error', copy.errorEvent],
]
let pending = new AbortController()
let autoClosed = 0
let dismissedByYou = 0
const summary = () => {
result.textContent = `${copy.played}: ${feed.children.length} · ${copy.expired}: ${autoClosed} · ${copy.manual}: ${dismissedByYou}`
}
// Changing the stack updates the toasts that are already on screen.
for (const control of [limit, expanded]) {
control.addEventListener(
'change',
() => {
if (notify.toast.getToasts().length) notify.createToaster(stack())
},
{ signal }
)
}
action.addEventListener(
'click',
async () => {
notify.createToaster({ richColors: true, closeButton: true, ...stack() })
action.disabled = true
const run = pending
const timedOut = new Set()
for (const [index, [type, message]] of events.entries()) {
if (index > 0 && !(await wait(220, run.signal))) return
feed.append(Object.assign(document.createElement('li'), { textContent: message }))
const options = {
duration: 9000,
// onAutoClose runs before onDismiss when the timer ends the toast.
onAutoClose: toast => timedOut.add(toast.id),
onDismiss: toast => {
if (run !== pending) return
if (timedOut.delete(toast.id)) autoClosed += 1
else dismissedByYou += 1
summary()
},
}
if (type) notify.toast[type](message, options)
else notify.toast(message, options)
summary()
}
action.disabled = false
},
{ signal }
)
element.querySelector('[data-demo-reset]').addEventListener(
'click',
() => {
pending.abort()
pending = new AbortController()
notify.toast.dismiss()
feed.replaceChildren()
autoClosed = 0
dismissedByYou = 0
action.disabled = false
result.textContent = initial
},
{ signal }
)
}
// Resolves true after `ms`, or false as soon as `signal` aborts.
const wait = (ms, signal) =>
new Promise(resolve => {
const timer = setTimeout(resolve, ms, true)
signal.addEventListener(
'abort',
() => {
clearTimeout(timer)
resolve(false)
},
{ once: true }
)
})
streamDemo(document.querySelector('[data-notify-demo]'), notify, copy)
// A page that is leaving no longer needs its toaster.
window.addEventListener('pagehide', event => {
if (!event.persisted) notify.destroyToaster()
})
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>A busy workspace. A readable stack.</title>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@samline/notify@5.0.1/dist/style.css"
/>
<style>
/* Demo form only. Toast appearance and motion come from @samline/notify/style.css. */
.notify-demo {
display: grid;
gap: 1rem;
min-width: 0;
color: #26232b;
}
.notify-demo-eyebrow {
font: 0.625rem/1.6 monospace;
letter-spacing: 0.12em;
text-transform: uppercase;
color: #655d68;
}
.notify-demo-heading {
font-size: clamp(1.4rem, 3vw, 1.9rem);
line-height: 1.25;
font-weight: 500;
letter-spacing: -0.035em;
}
.notify-demo-description {
max-width: 45rem;
color: #5f5763;
line-height: 1.7;
}
.notify-demo p {
margin: 0;
}
.notify-demo-field {
display: grid;
gap: 0.5rem;
min-width: 0;
max-width: 28rem;
color: #5f5763;
font-size: 0.8125rem;
}
.notify-demo-field input,
.notify-demo-field select {
display: block;
box-sizing: border-box;
min-width: 0;
width: 100%;
min-height: 3.125rem;
padding: 0.75rem 1rem;
font:
400 1rem/1.5 system-ui,
sans-serif;
color: #26232b;
background: #f4f2f7;
border: 0.0625rem solid #b7adb9;
border-radius: 0.5rem;
}
.notify-demo-field input {
cursor: text;
}
.notify-demo-select {
display: block;
position: relative;
min-width: 0;
color: #5f5763;
}
.notify-demo-select::after {
content: '';
box-sizing: border-box;
position: absolute;
inset-inline-end: min(1rem, 5vw);
top: 50%;
width: 0.5rem;
height: 0.5rem;
border-right: 0.125rem solid currentColor;
border-bottom: 0.125rem solid currentColor;
transform: translateY(-70%) rotate(45deg);
pointer-events: none;
}
.notify-demo-select select {
appearance: none;
cursor: pointer;
padding-inline-start: min(1rem, 5vw);
padding-inline-end: min(2.75rem, 12vw);
}
.notify-demo-select:has(select:disabled)::after {
opacity: 0.5;
}
.notify-demo-field input:disabled,
.notify-demo-field select:disabled {
opacity: 0.5;
cursor: not-allowed;
}
@media (hover: hover) {
.notify-demo-field input:enabled:hover,
.notify-demo-field select:enabled:hover {
border-color: #8d7a98;
}
}
.notify-demo-result {
min-height: 1.5rem;
font-size: 0.8125rem;
color: #5f5763;
}
.notify-demo-actions {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 0.625rem;
padding-top: 0.5rem;
}
.notify-demo-actions button {
display: inline-flex;
align-items: center;
justify-content: center;
box-sizing: border-box;
min-height: 3.125rem;
padding: 0.5rem 1.4rem;
font:
500 0.875rem/1.5 system-ui,
sans-serif;
letter-spacing: -0.01em;
cursor: pointer;
border: 0.0625rem solid #b7adb9;
border-radius: 0.875rem;
color: #26232b;
background: #f4f2f7;
}
.notify-demo-actions [data-demo-action] {
background: #b45309;
border-color: transparent;
color: #fff;
}
.notify-demo-actions [data-demo-reset] {
min-height: 2.5rem;
padding-inline: 1rem;
border-radius: 624.9375rem;
color: #5f5763;
border-color: #b7adb9;
background: transparent;
}
.notify-demo-actions button:disabled {
opacity: 0.5;
cursor: not-allowed;
}
@media (hover: hover) {
.notify-demo-actions button:enabled:hover {
background: #e8e5ed;
border-color: #8d7a98;
}
.notify-demo-actions [data-demo-action]:enabled:hover {
background: #92400e;
border-color: transparent;
}
.notify-demo-actions [data-demo-reset]:enabled:hover {
color: #b45309;
background: #fef3c7;
}
}
.notify-demo :focus-visible {
outline: 0.125rem solid #b45309;
outline-offset: 0.1875rem;
}
.notify-demo-fields {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(min(100%, 12rem), 1fr));
gap: 1rem;
align-items: end;
}
.notify-demo-check {
cursor: pointer;
display: flex;
align-items: center;
gap: 0.5rem;
min-height: 3rem;
font-size: 0.875rem;
}
.notify-demo-check input {
flex: 0 0 auto;
width: 1.125rem;
height: 1.125rem;
margin: 0;
padding: 0;
cursor: pointer;
accent-color: #b45309;
}
.notify-demo-check:has(input:disabled),
.notify-demo-check input:disabled {
cursor: not-allowed;
opacity: 0.5;
}
.notify-demo-feed {
margin: 0;
padding-inline-start: 1.25rem;
font-size: 0.8125rem;
line-height: 1.8;
color: #5f5763;
}
.notify-demo [hidden] {
display: none;
}
.notify-demo-actions button {
overflow-wrap: anywhere;
max-width: 100%;
}
</style>
</head>
<body>
<main
style="max-width: 48rem; margin: 2rem auto; padding: 1rem; font-family: system-ui, sans-serif"
>
<section
class="notify-demo"
data-notify-demo
data-preset="stream"
aria-label="Studio activity"
>
<p class="notify-demo-eyebrow">Studio activity</p>
<strong class="notify-demo-heading">Catch up without losing your place.</strong>
<p class="notify-demo-description">
Play a local sequence of uploads, comments and transfer alerts. The page retains the feed
while notifications stack, expire or are dismissed.
</p>
<div class="notify-demo-fields">
<label class="notify-demo-field"
>Visible notifications<span class="notify-demo-select"
><select data-visible-limit>
<option value="3">3</option>
<option value="1">1</option>
<option value="5">5</option>
</select></span
></label
><label class="notify-demo-check"
><input type="checkbox" data-stack-expanded />Keep the stack expanded</label
>
</div>
<ol class="notify-demo-feed" data-event-log aria-label="Studio activity"></ol>
<p class="notify-demo-result" data-demo-result role="status">No new workspace activity.</p>
<div class="notify-demo-actions">
<button type="button" data-demo-action>Play workspace activity</button>
<button type="button" data-demo-reset>Reset this preview</button>
</div>
</section>
</main>
<script src="https://cdn.jsdelivr.net/npm/@samline/notify@5.0.1/dist/browser/notify.global.js"></script>
<script>
const notify = window.Notify
const copy = {
normalEvent: 'Maya joined the workspace',
successEvent: 'Campaign cover uploaded',
infoEvent: 'Alex commented on the launch checklist',
warningEvent: 'Workspace storage is almost full',
errorEvent: 'The archive transfer failed',
played: 'Activity events',
expired: 'Auto-closed',
manual: 'Dismissed manually',
}
const streamDemo = (element, notify, copy, signal) => {
const feed = element.querySelector('[data-event-log]')
const limit = element.querySelector('[data-visible-limit]')
const expanded = element.querySelector('[data-stack-expanded]')
const action = element.querySelector('[data-demo-action]')
const result = element.querySelector('[data-demo-result]')
const initial = result.textContent
const stack = () => ({ visibleToasts: Number(limit.value), expand: expanded.checked })
const events = [
[undefined, copy.normalEvent],
['success', copy.successEvent],
['info', copy.infoEvent],
['warning', copy.warningEvent],
['error', copy.errorEvent],
]
let pending = new AbortController()
let autoClosed = 0
let dismissedByYou = 0
const summary = () => {
result.textContent = `${copy.played}: ${feed.children.length} · ${copy.expired}: ${autoClosed} · ${copy.manual}: ${dismissedByYou}`
}
// Changing the stack updates the toasts that are already on screen.
for (const control of [limit, expanded]) {
control.addEventListener(
'change',
() => {
if (notify.toast.getToasts().length) notify.createToaster(stack())
},
{ signal }
)
}
action.addEventListener(
'click',
async () => {
notify.createToaster({ richColors: true, closeButton: true, ...stack() })
action.disabled = true
const run = pending
const timedOut = new Set()
for (const [index, [type, message]] of events.entries()) {
if (index > 0 && !(await wait(220, run.signal))) return
feed.append(Object.assign(document.createElement('li'), { textContent: message }))
const options = {
duration: 9000,
// onAutoClose runs before onDismiss when the timer ends the toast.
onAutoClose: toast => timedOut.add(toast.id),
onDismiss: toast => {
if (run !== pending) return
if (timedOut.delete(toast.id)) autoClosed += 1
else dismissedByYou += 1
summary()
},
}
if (type) notify.toast[type](message, options)
else notify.toast(message, options)
summary()
}
action.disabled = false
},
{ signal }
)
element.querySelector('[data-demo-reset]').addEventListener(
'click',
() => {
pending.abort()
pending = new AbortController()
notify.toast.dismiss()
feed.replaceChildren()
autoClosed = 0
dismissedByYou = 0
action.disabled = false
result.textContent = initial
},
{ signal }
)
}
// Resolves true after `ms`, or false as soon as `signal` aborts.
const wait = (ms, signal) =>
new Promise(resolve => {
const timer = setTimeout(resolve, ms, true)
signal.addEventListener(
'abort',
() => {
clearTimeout(timer)
resolve(false)
},
{ once: true }
)
})
streamDemo(document.querySelector('[data-notify-demo]'), notify, copy)
// A page that is leaving no longer needs its toaster.
window.addEventListener('pagehide', event => {
if (!event.persisted) notify.destroyToaster()
})
</script>
</body>
</html>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>A busy workspace. A readable stack.</title>
</head>
<body>
<main
style="max-width: 48rem; margin: 2rem auto; padding: 1rem; font-family: system-ui, sans-serif"
>
<section
class="notify-demo"
data-notify-demo
data-preset="stream"
aria-label="Studio activity"
>
<p class="notify-demo-eyebrow">Studio activity</p>
<strong class="notify-demo-heading">Catch up without losing your place.</strong>
<p class="notify-demo-description">
Play a local sequence of uploads, comments and transfer alerts. The page retains the feed
while notifications stack, expire or are dismissed.
</p>
<div class="notify-demo-fields">
<label class="notify-demo-field"
>Visible notifications<span class="notify-demo-select"
><select data-visible-limit>
<option value="3">3</option>
<option value="1">1</option>
<option value="5">5</option>
</select></span
></label
><label class="notify-demo-check"
><input type="checkbox" data-stack-expanded />Keep the stack expanded</label
>
</div>
<ol class="notify-demo-feed" data-event-log aria-label="Studio activity"></ol>
<p class="notify-demo-result" data-demo-result role="status">No new workspace activity.</p>
<div class="notify-demo-actions">
<button type="button" data-demo-action>Play workspace activity</button>
<button type="button" data-demo-reset>Reset this preview</button>
</div>
</section>
</main>
<script type="module" src="./main.js"></script>
</body>
</html>
/* Demo form only. Toast appearance and motion come from @samline/notify/style.css. */
.notify-demo {
display: grid;
gap: 1rem;
min-width: 0;
color: #26232b;
}
.notify-demo-eyebrow {
font: 0.625rem/1.6 monospace;
letter-spacing: 0.12em;
text-transform: uppercase;
color: #655d68;
}
.notify-demo-heading {
font-size: clamp(1.4rem, 3vw, 1.9rem);
line-height: 1.25;
font-weight: 500;
letter-spacing: -0.035em;
}
.notify-demo-description {
max-width: 45rem;
color: #5f5763;
line-height: 1.7;
}
.notify-demo p {
margin: 0;
}
.notify-demo-field {
display: grid;
gap: 0.5rem;
min-width: 0;
max-width: 28rem;
color: #5f5763;
font-size: 0.8125rem;
}
.notify-demo-field input,
.notify-demo-field select {
display: block;
box-sizing: border-box;
min-width: 0;
width: 100%;
min-height: 3.125rem;
padding: 0.75rem 1rem;
font:
400 1rem/1.5 system-ui,
sans-serif;
color: #26232b;
background: #f4f2f7;
border: 0.0625rem solid #b7adb9;
border-radius: 0.5rem;
}
.notify-demo-field input {
cursor: text;
}
.notify-demo-select {
display: block;
position: relative;
min-width: 0;
color: #5f5763;
}
.notify-demo-select::after {
content: '';
box-sizing: border-box;
position: absolute;
inset-inline-end: min(1rem, 5vw);
top: 50%;
width: 0.5rem;
height: 0.5rem;
border-right: 0.125rem solid currentColor;
border-bottom: 0.125rem solid currentColor;
transform: translateY(-70%) rotate(45deg);
pointer-events: none;
}
.notify-demo-select select {
appearance: none;
cursor: pointer;
padding-inline-start: min(1rem, 5vw);
padding-inline-end: min(2.75rem, 12vw);
}
.notify-demo-select:has(select:disabled)::after {
opacity: 0.5;
}
.notify-demo-field input:disabled,
.notify-demo-field select:disabled {
opacity: 0.5;
cursor: not-allowed;
}
@media (hover: hover) {
.notify-demo-field input:enabled:hover,
.notify-demo-field select:enabled:hover {
border-color: #8d7a98;
}
}
.notify-demo-result {
min-height: 1.5rem;
font-size: 0.8125rem;
color: #5f5763;
}
.notify-demo-actions {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 0.625rem;
padding-top: 0.5rem;
}
.notify-demo-actions button {
display: inline-flex;
align-items: center;
justify-content: center;
box-sizing: border-box;
min-height: 3.125rem;
padding: 0.5rem 1.4rem;
font:
500 0.875rem/1.5 system-ui,
sans-serif;
letter-spacing: -0.01em;
cursor: pointer;
border: 0.0625rem solid #b7adb9;
border-radius: 0.875rem;
color: #26232b;
background: #f4f2f7;
}
.notify-demo-actions [data-demo-action] {
background: #b45309;
border-color: transparent;
color: #fff;
}
.notify-demo-actions [data-demo-reset] {
min-height: 2.5rem;
padding-inline: 1rem;
border-radius: 624.9375rem;
color: #5f5763;
border-color: #b7adb9;
background: transparent;
}
.notify-demo-actions button:disabled {
opacity: 0.5;
cursor: not-allowed;
}
@media (hover: hover) {
.notify-demo-actions button:enabled:hover {
background: #e8e5ed;
border-color: #8d7a98;
}
.notify-demo-actions [data-demo-action]:enabled:hover {
background: #92400e;
border-color: transparent;
}
.notify-demo-actions [data-demo-reset]:enabled:hover {
color: #b45309;
background: #fef3c7;
}
}
.notify-demo :focus-visible {
outline: 0.125rem solid #b45309;
outline-offset: 0.1875rem;
}
.notify-demo-fields {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(min(100%, 12rem), 1fr));
gap: 1rem;
align-items: end;
}
.notify-demo-check {
cursor: pointer;
display: flex;
align-items: center;
gap: 0.5rem;
min-height: 3rem;
font-size: 0.875rem;
}
.notify-demo-check input {
flex: 0 0 auto;
width: 1.125rem;
height: 1.125rem;
margin: 0;
padding: 0;
cursor: pointer;
accent-color: #b45309;
}
.notify-demo-check:has(input:disabled),
.notify-demo-check input:disabled {
cursor: not-allowed;
opacity: 0.5;
}
.notify-demo-feed {
margin: 0;
padding-inline-start: 1.25rem;
font-size: 0.8125rem;
line-height: 1.8;
color: #5f5763;
}
.notify-demo [hidden] {
display: none;
}
.notify-demo-actions button {
overflow-wrap: anywhere;
max-width: 100%;
}
import { browser as notify } from '@samline/notify'
import '@samline/notify/style.css'
import './style.css'
const copy = {
normalEvent: 'Maya joined the workspace',
successEvent: 'Campaign cover uploaded',
infoEvent: 'Alex commented on the launch checklist',
warningEvent: 'Workspace storage is almost full',
errorEvent: 'The archive transfer failed',
played: 'Activity events',
expired: 'Auto-closed',
manual: 'Dismissed manually',
}
const streamDemo = (element, notify, copy, signal) => {
const feed = element.querySelector('[data-event-log]')
const limit = element.querySelector('[data-visible-limit]')
const expanded = element.querySelector('[data-stack-expanded]')
const action = element.querySelector('[data-demo-action]')
const result = element.querySelector('[data-demo-result]')
const initial = result.textContent
const stack = () => ({ visibleToasts: Number(limit.value), expand: expanded.checked })
const events = [
[undefined, copy.normalEvent],
['success', copy.successEvent],
['info', copy.infoEvent],
['warning', copy.warningEvent],
['error', copy.errorEvent],
]
let pending = new AbortController()
let autoClosed = 0
let dismissedByYou = 0
const summary = () => {
result.textContent = `${copy.played}: ${feed.children.length} · ${copy.expired}: ${autoClosed} · ${copy.manual}: ${dismissedByYou}`
}
// Changing the stack updates the toasts that are already on screen.
for (const control of [limit, expanded]) {
control.addEventListener(
'change',
() => {
if (notify.toast.getToasts().length) notify.createToaster(stack())
},
{ signal }
)
}
action.addEventListener(
'click',
async () => {
notify.createToaster({ richColors: true, closeButton: true, ...stack() })
action.disabled = true
const run = pending
const timedOut = new Set()
for (const [index, [type, message]] of events.entries()) {
if (index > 0 && !(await wait(220, run.signal))) return
feed.append(Object.assign(document.createElement('li'), { textContent: message }))
const options = {
duration: 9000,
// onAutoClose runs before onDismiss when the timer ends the toast.
onAutoClose: toast => timedOut.add(toast.id),
onDismiss: toast => {
if (run !== pending) return
if (timedOut.delete(toast.id)) autoClosed += 1
else dismissedByYou += 1
summary()
},
}
if (type) notify.toast[type](message, options)
else notify.toast(message, options)
summary()
}
action.disabled = false
},
{ signal }
)
element.querySelector('[data-demo-reset]').addEventListener(
'click',
() => {
pending.abort()
pending = new AbortController()
notify.toast.dismiss()
feed.replaceChildren()
autoClosed = 0
dismissedByYou = 0
action.disabled = false
result.textContent = initial
},
{ signal }
)
}
// Resolves true after `ms`, or false as soon as `signal` aborts.
const wait = (ms, signal) =>
new Promise(resolve => {
const timer = setTimeout(resolve, ms, true)
signal.addEventListener(
'abort',
() => {
clearTimeout(timer)
resolve(false)
},
{ once: true }
)
})
streamDemo(document.querySelector('[data-notify-demo]'), notify, copy)
// A page that is leaving no longer needs its toaster.
window.addEventListener('pagehide', event => {
if (!event.persisted) notify.destroyToaster()
})
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>A busy workspace. A readable stack.</title>
<style>
/* Demo form only. Toast appearance and motion come from @samline/notify/style.css. */
.notify-demo {
display: grid;
gap: 1rem;
min-width: 0;
color: #26232b;
}
.notify-demo-eyebrow {
font: 0.625rem/1.6 monospace;
letter-spacing: 0.12em;
text-transform: uppercase;
color: #655d68;
}
.notify-demo-heading {
font-size: clamp(1.4rem, 3vw, 1.9rem);
line-height: 1.25;
font-weight: 500;
letter-spacing: -0.035em;
}
.notify-demo-description {
max-width: 45rem;
color: #5f5763;
line-height: 1.7;
}
.notify-demo p {
margin: 0;
}
.notify-demo-field {
display: grid;
gap: 0.5rem;
min-width: 0;
max-width: 28rem;
color: #5f5763;
font-size: 0.8125rem;
}
.notify-demo-field input,
.notify-demo-field select {
display: block;
box-sizing: border-box;
min-width: 0;
width: 100%;
min-height: 3.125rem;
padding: 0.75rem 1rem;
font:
400 1rem/1.5 system-ui,
sans-serif;
color: #26232b;
background: #f4f2f7;
border: 0.0625rem solid #b7adb9;
border-radius: 0.5rem;
}
.notify-demo-field input {
cursor: text;
}
.notify-demo-select {
display: block;
position: relative;
min-width: 0;
color: #5f5763;
}
.notify-demo-select::after {
content: '';
box-sizing: border-box;
position: absolute;
inset-inline-end: min(1rem, 5vw);
top: 50%;
width: 0.5rem;
height: 0.5rem;
border-right: 0.125rem solid currentColor;
border-bottom: 0.125rem solid currentColor;
transform: translateY(-70%) rotate(45deg);
pointer-events: none;
}
.notify-demo-select select {
appearance: none;
cursor: pointer;
padding-inline-start: min(1rem, 5vw);
padding-inline-end: min(2.75rem, 12vw);
}
.notify-demo-select:has(select:disabled)::after {
opacity: 0.5;
}
.notify-demo-field input:disabled,
.notify-demo-field select:disabled {
opacity: 0.5;
cursor: not-allowed;
}
@media (hover: hover) {
.notify-demo-field input:enabled:hover,
.notify-demo-field select:enabled:hover {
border-color: #8d7a98;
}
}
.notify-demo-result {
min-height: 1.5rem;
font-size: 0.8125rem;
color: #5f5763;
}
.notify-demo-actions {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 0.625rem;
padding-top: 0.5rem;
}
.notify-demo-actions button {
display: inline-flex;
align-items: center;
justify-content: center;
box-sizing: border-box;
min-height: 3.125rem;
padding: 0.5rem 1.4rem;
font:
500 0.875rem/1.5 system-ui,
sans-serif;
letter-spacing: -0.01em;
cursor: pointer;
border: 0.0625rem solid #b7adb9;
border-radius: 0.875rem;
color: #26232b;
background: #f4f2f7;
}
.notify-demo-actions [data-demo-action] {
background: #b45309;
border-color: transparent;
color: #fff;
}
.notify-demo-actions [data-demo-reset] {
min-height: 2.5rem;
padding-inline: 1rem;
border-radius: 624.9375rem;
color: #5f5763;
border-color: #b7adb9;
background: transparent;
}
.notify-demo-actions button:disabled {
opacity: 0.5;
cursor: not-allowed;
}
@media (hover: hover) {
.notify-demo-actions button:enabled:hover {
background: #e8e5ed;
border-color: #8d7a98;
}
.notify-demo-actions [data-demo-action]:enabled:hover {
background: #92400e;
border-color: transparent;
}
.notify-demo-actions [data-demo-reset]:enabled:hover {
color: #b45309;
background: #fef3c7;
}
}
.notify-demo :focus-visible {
outline: 0.125rem solid #b45309;
outline-offset: 0.1875rem;
}
.notify-demo-fields {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(min(100%, 12rem), 1fr));
gap: 1rem;
align-items: end;
}
.notify-demo-check {
cursor: pointer;
display: flex;
align-items: center;
gap: 0.5rem;
min-height: 3rem;
font-size: 0.875rem;
}
.notify-demo-check input {
flex: 0 0 auto;
width: 1.125rem;
height: 1.125rem;
margin: 0;
padding: 0;
cursor: pointer;
accent-color: #b45309;
}
.notify-demo-check:has(input:disabled),
.notify-demo-check input:disabled {
cursor: not-allowed;
opacity: 0.5;
}
.notify-demo-feed {
margin: 0;
padding-inline-start: 1.25rem;
font-size: 0.8125rem;
line-height: 1.8;
color: #5f5763;
}
.notify-demo [hidden] {
display: none;
}
.notify-demo-actions button {
overflow-wrap: anywhere;
max-width: 100%;
}
</style>
</head>
<body>
<main
style="max-width: 48rem; margin: 2rem auto; padding: 1rem; font-family: system-ui, sans-serif"
>
<section
class="notify-demo"
data-notify-demo
data-preset="stream"
aria-label="Studio activity"
>
<p class="notify-demo-eyebrow">Studio activity</p>
<strong class="notify-demo-heading">Catch up without losing your place.</strong>
<p class="notify-demo-description">
Play a local sequence of uploads, comments and transfer alerts. The page retains the feed
while notifications stack, expire or are dismissed.
</p>
<div class="notify-demo-fields">
<label class="notify-demo-field"
>Visible notifications<span class="notify-demo-select"
><select data-visible-limit>
<option value="3">3</option>
<option value="1">1</option>
<option value="5">5</option>
</select></span
></label
><label class="notify-demo-check"
><input type="checkbox" data-stack-expanded />Keep the stack expanded</label
>
</div>
<ol class="notify-demo-feed" data-event-log aria-label="Studio activity"></ol>
<p class="notify-demo-result" data-demo-result role="status">No new workspace activity.</p>
<div class="notify-demo-actions">
<button type="button" data-demo-action>Play workspace activity</button>
<button type="button" data-demo-reset>Reset this preview</button>
</div>
</section>
</main>
<script type="module">
import { browser as notify } from '@samline/notify'
import '@samline/notify/style.css'
const copy = {
normalEvent: 'Maya joined the workspace',
successEvent: 'Campaign cover uploaded',
infoEvent: 'Alex commented on the launch checklist',
warningEvent: 'Workspace storage is almost full',
errorEvent: 'The archive transfer failed',
played: 'Activity events',
expired: 'Auto-closed',
manual: 'Dismissed manually',
}
const streamDemo = (element, notify, copy, signal) => {
const feed = element.querySelector('[data-event-log]')
const limit = element.querySelector('[data-visible-limit]')
const expanded = element.querySelector('[data-stack-expanded]')
const action = element.querySelector('[data-demo-action]')
const result = element.querySelector('[data-demo-result]')
const initial = result.textContent
const stack = () => ({ visibleToasts: Number(limit.value), expand: expanded.checked })
const events = [
[undefined, copy.normalEvent],
['success', copy.successEvent],
['info', copy.infoEvent],
['warning', copy.warningEvent],
['error', copy.errorEvent],
]
let pending = new AbortController()
let autoClosed = 0
let dismissedByYou = 0
const summary = () => {
result.textContent = `${copy.played}: ${feed.children.length} · ${copy.expired}: ${autoClosed} · ${copy.manual}: ${dismissedByYou}`
}
// Changing the stack updates the toasts that are already on screen.
for (const control of [limit, expanded]) {
control.addEventListener(
'change',
() => {
if (notify.toast.getToasts().length) notify.createToaster(stack())
},
{ signal }
)
}
action.addEventListener(
'click',
async () => {
notify.createToaster({ richColors: true, closeButton: true, ...stack() })
action.disabled = true
const run = pending
const timedOut = new Set()
for (const [index, [type, message]] of events.entries()) {
if (index > 0 && !(await wait(220, run.signal))) return
feed.append(Object.assign(document.createElement('li'), { textContent: message }))
const options = {
duration: 9000,
// onAutoClose runs before onDismiss when the timer ends the toast.
onAutoClose: toast => timedOut.add(toast.id),
onDismiss: toast => {
if (run !== pending) return
if (timedOut.delete(toast.id)) autoClosed += 1
else dismissedByYou += 1
summary()
},
}
if (type) notify.toast[type](message, options)
else notify.toast(message, options)
summary()
}
action.disabled = false
},
{ signal }
)
element.querySelector('[data-demo-reset]').addEventListener(
'click',
() => {
pending.abort()
pending = new AbortController()
notify.toast.dismiss()
feed.replaceChildren()
autoClosed = 0
dismissedByYou = 0
action.disabled = false
result.textContent = initial
},
{ signal }
)
}
// Resolves true after `ms`, or false as soon as `signal` aborts.
const wait = (ms, signal) =>
new Promise(resolve => {
const timer = setTimeout(resolve, ms, true)
signal.addEventListener(
'abort',
() => {
clearTimeout(timer)
resolve(false)
},
{ once: true }
)
})
streamDemo(document.querySelector('[data-notify-demo]'), notify, copy)
// A page that is leaving no longer needs its toaster.
window.addEventListener('pagehide', event => {
if (!event.persisted) notify.destroyToaster()
})
</script>
</body>
</html>
A promise with a result you can use
Reports
Your numbers, ready to take with you.Generate a small CSV from local sample data. Try success, a simulated server error, or cancel the pending operation. No request leaves this page.
October report · Ready to export
toast.promise follows the operation; unwrap() gives the original result to your application. An AbortController cancels the work. finally releases the form in every outcome. Notify does not cancel requests for you.
Explore the code
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>A promise with a result you can use</title>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@samline/notify@5.0.1/dist/style.css"
/>
<link rel="stylesheet" href="./style.css" />
</head>
<body>
<main
style="max-width: 48rem; margin: 2rem auto; padding: 1rem; font-family: system-ui, sans-serif"
>
<section class="notify-demo" data-notify-demo data-preset="task" aria-label="Reports">
<p class="notify-demo-eyebrow">Reports</p>
<strong class="notify-demo-heading">Your numbers, ready to take with you.</strong>
<p class="notify-demo-description">
Generate a small CSV from local sample data. Try success, a simulated server error, or
cancel the pending operation. No request leaves this page.
</p>
<label class="notify-demo-field"
>Sample service response<span class="notify-demo-select"
><select data-task-outcome>
<option value="success">Success</option>
<option value="error">Server error</option>
</select></span
></label
>
<pre
class="notify-demo-output"
data-export-output
aria-label="CSV preview"
tabindex="0"
hidden
></pre>
<p class="notify-demo-result" data-demo-result role="status">
October report · Ready to export
</p>
<div class="notify-demo-actions">
<button type="button" data-demo-action>Generate CSV</button>
<button type="button" data-demo-cancel disabled>Cancel export</button>
<button type="button" data-demo-reset>Reset this preview</button>
</div>
</section>
</main>
<script src="https://cdn.jsdelivr.net/npm/@samline/notify@5.0.1/dist/browser/notify.global.js"></script>
<script src="./main.js"></script>
</body>
</html>
/* Demo form only. Toast appearance and motion come from @samline/notify/style.css. */
.notify-demo {
display: grid;
gap: 1rem;
min-width: 0;
color: #26232b;
}
.notify-demo-eyebrow {
font: 0.625rem/1.6 monospace;
letter-spacing: 0.12em;
text-transform: uppercase;
color: #655d68;
}
.notify-demo-heading {
font-size: clamp(1.4rem, 3vw, 1.9rem);
line-height: 1.25;
font-weight: 500;
letter-spacing: -0.035em;
}
.notify-demo-description {
max-width: 45rem;
color: #5f5763;
line-height: 1.7;
}
.notify-demo p {
margin: 0;
}
.notify-demo-field {
display: grid;
gap: 0.5rem;
min-width: 0;
max-width: 28rem;
color: #5f5763;
font-size: 0.8125rem;
}
.notify-demo-field select {
display: block;
box-sizing: border-box;
min-width: 0;
width: 100%;
min-height: 3.125rem;
padding: 0.75rem 1rem;
font:
400 1rem/1.5 system-ui,
sans-serif;
color: #26232b;
background: #f4f2f7;
border: 0.0625rem solid #b7adb9;
border-radius: 0.5rem;
}
.notify-demo-select {
display: block;
position: relative;
min-width: 0;
color: #5f5763;
}
.notify-demo-select::after {
content: '';
box-sizing: border-box;
position: absolute;
inset-inline-end: min(1rem, 5vw);
top: 50%;
width: 0.5rem;
height: 0.5rem;
border-right: 0.125rem solid currentColor;
border-bottom: 0.125rem solid currentColor;
transform: translateY(-70%) rotate(45deg);
pointer-events: none;
}
.notify-demo-select select {
appearance: none;
cursor: pointer;
padding-inline-start: min(1rem, 5vw);
padding-inline-end: min(2.75rem, 12vw);
}
.notify-demo-select:has(select:disabled)::after {
opacity: 0.5;
}
.notify-demo-field select:disabled {
opacity: 0.5;
cursor: not-allowed;
}
@media (hover: hover) {
.notify-demo-field select:enabled:hover {
border-color: #8d7a98;
}
}
.notify-demo-result {
min-height: 1.5rem;
font-size: 0.8125rem;
color: #5f5763;
}
.notify-demo-actions {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 0.625rem;
padding-top: 0.5rem;
}
.notify-demo-actions button {
display: inline-flex;
align-items: center;
justify-content: center;
box-sizing: border-box;
min-height: 3.125rem;
padding: 0.5rem 1.4rem;
font:
500 0.875rem/1.5 system-ui,
sans-serif;
letter-spacing: -0.01em;
cursor: pointer;
border: 0.0625rem solid #b7adb9;
border-radius: 0.875rem;
color: #26232b;
background: #f4f2f7;
}
.notify-demo-actions [data-demo-action] {
background: #b45309;
border-color: transparent;
color: #fff;
}
.notify-demo-actions [data-demo-reset] {
min-height: 2.5rem;
padding-inline: 1rem;
border-radius: 624.9375rem;
color: #5f5763;
border-color: #b7adb9;
background: transparent;
}
.notify-demo-actions button:disabled {
opacity: 0.5;
cursor: not-allowed;
}
@media (hover: hover) {
.notify-demo-actions button:enabled:hover {
background: #e8e5ed;
border-color: #8d7a98;
}
.notify-demo-actions [data-demo-action]:enabled:hover {
background: #92400e;
border-color: transparent;
}
.notify-demo-actions [data-demo-reset]:enabled:hover {
color: #b45309;
background: #fef3c7;
}
}
.notify-demo :focus-visible {
outline: 0.125rem solid #b45309;
outline-offset: 0.1875rem;
}
.notify-demo-output {
max-width: 100%;
overflow: auto;
padding: 1rem;
border: 0.0625rem solid #cfc7d2;
border-radius: 0.5rem;
font: 0.75rem/1.7 monospace;
}
.notify-demo [hidden] {
display: none;
}
.notify-demo-actions button {
overflow-wrap: anywhere;
max-width: 100%;
}
const notify = window.Notify
const copy = {
exporting: 'Generating October report…',
exported: 'October report is ready',
exportFailed: 'The report could not be generated',
exportStopped: 'Export canceled',
exportError: 'The sample report service is unavailable. Choose Success and try again.',
viewCsv: 'View CSV',
csvReady: 'CSV generated · 3 rows · Preview available below',
}
const taskDemo = (element, notify, copy, signal) => {
const action = element.querySelector('[data-demo-action]')
const cancel = element.querySelector('[data-demo-cancel]')
const preview = element.querySelector('[data-export-output]')
const outcome = element.querySelector('[data-task-outcome]')
const result = element.querySelector('[data-demo-result]')
const initial = result.textContent
const csv =
'month,category,total\nOctober,Design,240\nOctober,Engineering,680\nOctober,Support,120'
let pending = new AbortController()
action.addEventListener(
'click',
async () => {
notify.createToaster({ richColors: true, closeButton: true })
const run = (pending = new AbortController())
action.disabled = true
cancel.disabled = false
preview.hidden = true
// A stand-in for a request: it fails on demand and can be canceled.
const request = wait(2200, run.signal).then(done => {
if (!done) throw new DOMException(copy.exportStopped, 'AbortError')
if (outcome.value === 'error') throw new Error(copy.exportError)
return csv
})
const toast = notify.toast.promise(request, {
loading: copy.exporting,
success: data => ({
message: copy.exported,
description: copy.csvReady,
action: {
label: copy.viewCsv,
onClick: () => {
preview.textContent = data
preview.hidden = false
},
},
}),
error: error => ({ message: copy.exportFailed, description: error.message }),
})
result.textContent = copy.exporting
try {
await toast.unwrap()
result.textContent = copy.csvReady
} catch (error) {
if (run !== pending) return // reset while waiting
const canceled = error.name === 'AbortError'
result.textContent = canceled ? copy.exportStopped : copy.exportFailed
if (canceled) notify.toast.dismiss(toast.id)
}
action.disabled = false
cancel.disabled = true
},
{ signal }
)
cancel.addEventListener('click', () => pending.abort(), { signal })
element.querySelector('[data-demo-reset]').addEventListener(
'click',
() => {
pending.abort()
pending = new AbortController()
notify.toast.dismiss()
action.disabled = false
cancel.disabled = true
preview.hidden = true
preview.textContent = ''
result.textContent = initial
},
{ signal }
)
}
// Resolves true after `ms`, or false as soon as `signal` aborts.
const wait = (ms, signal) =>
new Promise(resolve => {
const timer = setTimeout(resolve, ms, true)
signal.addEventListener(
'abort',
() => {
clearTimeout(timer)
resolve(false)
},
{ once: true }
)
})
taskDemo(document.querySelector('[data-notify-demo]'), notify, copy)
// A page that is leaving no longer needs its toaster.
window.addEventListener('pagehide', event => {
if (!event.persisted) notify.destroyToaster()
})
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>A promise with a result you can use</title>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@samline/notify@5.0.1/dist/style.css"
/>
<style>
/* Demo form only. Toast appearance and motion come from @samline/notify/style.css. */
.notify-demo {
display: grid;
gap: 1rem;
min-width: 0;
color: #26232b;
}
.notify-demo-eyebrow {
font: 0.625rem/1.6 monospace;
letter-spacing: 0.12em;
text-transform: uppercase;
color: #655d68;
}
.notify-demo-heading {
font-size: clamp(1.4rem, 3vw, 1.9rem);
line-height: 1.25;
font-weight: 500;
letter-spacing: -0.035em;
}
.notify-demo-description {
max-width: 45rem;
color: #5f5763;
line-height: 1.7;
}
.notify-demo p {
margin: 0;
}
.notify-demo-field {
display: grid;
gap: 0.5rem;
min-width: 0;
max-width: 28rem;
color: #5f5763;
font-size: 0.8125rem;
}
.notify-demo-field select {
display: block;
box-sizing: border-box;
min-width: 0;
width: 100%;
min-height: 3.125rem;
padding: 0.75rem 1rem;
font:
400 1rem/1.5 system-ui,
sans-serif;
color: #26232b;
background: #f4f2f7;
border: 0.0625rem solid #b7adb9;
border-radius: 0.5rem;
}
.notify-demo-select {
display: block;
position: relative;
min-width: 0;
color: #5f5763;
}
.notify-demo-select::after {
content: '';
box-sizing: border-box;
position: absolute;
inset-inline-end: min(1rem, 5vw);
top: 50%;
width: 0.5rem;
height: 0.5rem;
border-right: 0.125rem solid currentColor;
border-bottom: 0.125rem solid currentColor;
transform: translateY(-70%) rotate(45deg);
pointer-events: none;
}
.notify-demo-select select {
appearance: none;
cursor: pointer;
padding-inline-start: min(1rem, 5vw);
padding-inline-end: min(2.75rem, 12vw);
}
.notify-demo-select:has(select:disabled)::after {
opacity: 0.5;
}
.notify-demo-field select:disabled {
opacity: 0.5;
cursor: not-allowed;
}
@media (hover: hover) {
.notify-demo-field select:enabled:hover {
border-color: #8d7a98;
}
}
.notify-demo-result {
min-height: 1.5rem;
font-size: 0.8125rem;
color: #5f5763;
}
.notify-demo-actions {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 0.625rem;
padding-top: 0.5rem;
}
.notify-demo-actions button {
display: inline-flex;
align-items: center;
justify-content: center;
box-sizing: border-box;
min-height: 3.125rem;
padding: 0.5rem 1.4rem;
font:
500 0.875rem/1.5 system-ui,
sans-serif;
letter-spacing: -0.01em;
cursor: pointer;
border: 0.0625rem solid #b7adb9;
border-radius: 0.875rem;
color: #26232b;
background: #f4f2f7;
}
.notify-demo-actions [data-demo-action] {
background: #b45309;
border-color: transparent;
color: #fff;
}
.notify-demo-actions [data-demo-reset] {
min-height: 2.5rem;
padding-inline: 1rem;
border-radius: 624.9375rem;
color: #5f5763;
border-color: #b7adb9;
background: transparent;
}
.notify-demo-actions button:disabled {
opacity: 0.5;
cursor: not-allowed;
}
@media (hover: hover) {
.notify-demo-actions button:enabled:hover {
background: #e8e5ed;
border-color: #8d7a98;
}
.notify-demo-actions [data-demo-action]:enabled:hover {
background: #92400e;
border-color: transparent;
}
.notify-demo-actions [data-demo-reset]:enabled:hover {
color: #b45309;
background: #fef3c7;
}
}
.notify-demo :focus-visible {
outline: 0.125rem solid #b45309;
outline-offset: 0.1875rem;
}
.notify-demo-output {
max-width: 100%;
overflow: auto;
padding: 1rem;
border: 0.0625rem solid #cfc7d2;
border-radius: 0.5rem;
font: 0.75rem/1.7 monospace;
}
.notify-demo [hidden] {
display: none;
}
.notify-demo-actions button {
overflow-wrap: anywhere;
max-width: 100%;
}
</style>
</head>
<body>
<main
style="max-width: 48rem; margin: 2rem auto; padding: 1rem; font-family: system-ui, sans-serif"
>
<section class="notify-demo" data-notify-demo data-preset="task" aria-label="Reports">
<p class="notify-demo-eyebrow">Reports</p>
<strong class="notify-demo-heading">Your numbers, ready to take with you.</strong>
<p class="notify-demo-description">
Generate a small CSV from local sample data. Try success, a simulated server error, or
cancel the pending operation. No request leaves this page.
</p>
<label class="notify-demo-field"
>Sample service response<span class="notify-demo-select"
><select data-task-outcome>
<option value="success">Success</option>
<option value="error">Server error</option>
</select></span
></label
>
<pre
class="notify-demo-output"
data-export-output
aria-label="CSV preview"
tabindex="0"
hidden
></pre>
<p class="notify-demo-result" data-demo-result role="status">
October report · Ready to export
</p>
<div class="notify-demo-actions">
<button type="button" data-demo-action>Generate CSV</button>
<button type="button" data-demo-cancel disabled>Cancel export</button>
<button type="button" data-demo-reset>Reset this preview</button>
</div>
</section>
</main>
<script src="https://cdn.jsdelivr.net/npm/@samline/notify@5.0.1/dist/browser/notify.global.js"></script>
<script>
const notify = window.Notify
const copy = {
exporting: 'Generating October report…',
exported: 'October report is ready',
exportFailed: 'The report could not be generated',
exportStopped: 'Export canceled',
exportError: 'The sample report service is unavailable. Choose Success and try again.',
viewCsv: 'View CSV',
csvReady: 'CSV generated · 3 rows · Preview available below',
}
const taskDemo = (element, notify, copy, signal) => {
const action = element.querySelector('[data-demo-action]')
const cancel = element.querySelector('[data-demo-cancel]')
const preview = element.querySelector('[data-export-output]')
const outcome = element.querySelector('[data-task-outcome]')
const result = element.querySelector('[data-demo-result]')
const initial = result.textContent
const csv =
'month,category,total\nOctober,Design,240\nOctober,Engineering,680\nOctober,Support,120'
let pending = new AbortController()
action.addEventListener(
'click',
async () => {
notify.createToaster({ richColors: true, closeButton: true })
const run = (pending = new AbortController())
action.disabled = true
cancel.disabled = false
preview.hidden = true
// A stand-in for a request: it fails on demand and can be canceled.
const request = wait(2200, run.signal).then(done => {
if (!done) throw new DOMException(copy.exportStopped, 'AbortError')
if (outcome.value === 'error') throw new Error(copy.exportError)
return csv
})
const toast = notify.toast.promise(request, {
loading: copy.exporting,
success: data => ({
message: copy.exported,
description: copy.csvReady,
action: {
label: copy.viewCsv,
onClick: () => {
preview.textContent = data
preview.hidden = false
},
},
}),
error: error => ({ message: copy.exportFailed, description: error.message }),
})
result.textContent = copy.exporting
try {
await toast.unwrap()
result.textContent = copy.csvReady
} catch (error) {
if (run !== pending) return // reset while waiting
const canceled = error.name === 'AbortError'
result.textContent = canceled ? copy.exportStopped : copy.exportFailed
if (canceled) notify.toast.dismiss(toast.id)
}
action.disabled = false
cancel.disabled = true
},
{ signal }
)
cancel.addEventListener('click', () => pending.abort(), { signal })
element.querySelector('[data-demo-reset]').addEventListener(
'click',
() => {
pending.abort()
pending = new AbortController()
notify.toast.dismiss()
action.disabled = false
cancel.disabled = true
preview.hidden = true
preview.textContent = ''
result.textContent = initial
},
{ signal }
)
}
// Resolves true after `ms`, or false as soon as `signal` aborts.
const wait = (ms, signal) =>
new Promise(resolve => {
const timer = setTimeout(resolve, ms, true)
signal.addEventListener(
'abort',
() => {
clearTimeout(timer)
resolve(false)
},
{ once: true }
)
})
taskDemo(document.querySelector('[data-notify-demo]'), notify, copy)
// A page that is leaving no longer needs its toaster.
window.addEventListener('pagehide', event => {
if (!event.persisted) notify.destroyToaster()
})
</script>
</body>
</html>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>A promise with a result you can use</title>
</head>
<body>
<main
style="max-width: 48rem; margin: 2rem auto; padding: 1rem; font-family: system-ui, sans-serif"
>
<section class="notify-demo" data-notify-demo data-preset="task" aria-label="Reports">
<p class="notify-demo-eyebrow">Reports</p>
<strong class="notify-demo-heading">Your numbers, ready to take with you.</strong>
<p class="notify-demo-description">
Generate a small CSV from local sample data. Try success, a simulated server error, or
cancel the pending operation. No request leaves this page.
</p>
<label class="notify-demo-field"
>Sample service response<span class="notify-demo-select"
><select data-task-outcome>
<option value="success">Success</option>
<option value="error">Server error</option>
</select></span
></label
>
<pre
class="notify-demo-output"
data-export-output
aria-label="CSV preview"
tabindex="0"
hidden
></pre>
<p class="notify-demo-result" data-demo-result role="status">
October report · Ready to export
</p>
<div class="notify-demo-actions">
<button type="button" data-demo-action>Generate CSV</button>
<button type="button" data-demo-cancel disabled>Cancel export</button>
<button type="button" data-demo-reset>Reset this preview</button>
</div>
</section>
</main>
<script type="module" src="./main.js"></script>
</body>
</html>
/* Demo form only. Toast appearance and motion come from @samline/notify/style.css. */
.notify-demo {
display: grid;
gap: 1rem;
min-width: 0;
color: #26232b;
}
.notify-demo-eyebrow {
font: 0.625rem/1.6 monospace;
letter-spacing: 0.12em;
text-transform: uppercase;
color: #655d68;
}
.notify-demo-heading {
font-size: clamp(1.4rem, 3vw, 1.9rem);
line-height: 1.25;
font-weight: 500;
letter-spacing: -0.035em;
}
.notify-demo-description {
max-width: 45rem;
color: #5f5763;
line-height: 1.7;
}
.notify-demo p {
margin: 0;
}
.notify-demo-field {
display: grid;
gap: 0.5rem;
min-width: 0;
max-width: 28rem;
color: #5f5763;
font-size: 0.8125rem;
}
.notify-demo-field select {
display: block;
box-sizing: border-box;
min-width: 0;
width: 100%;
min-height: 3.125rem;
padding: 0.75rem 1rem;
font:
400 1rem/1.5 system-ui,
sans-serif;
color: #26232b;
background: #f4f2f7;
border: 0.0625rem solid #b7adb9;
border-radius: 0.5rem;
}
.notify-demo-select {
display: block;
position: relative;
min-width: 0;
color: #5f5763;
}
.notify-demo-select::after {
content: '';
box-sizing: border-box;
position: absolute;
inset-inline-end: min(1rem, 5vw);
top: 50%;
width: 0.5rem;
height: 0.5rem;
border-right: 0.125rem solid currentColor;
border-bottom: 0.125rem solid currentColor;
transform: translateY(-70%) rotate(45deg);
pointer-events: none;
}
.notify-demo-select select {
appearance: none;
cursor: pointer;
padding-inline-start: min(1rem, 5vw);
padding-inline-end: min(2.75rem, 12vw);
}
.notify-demo-select:has(select:disabled)::after {
opacity: 0.5;
}
.notify-demo-field select:disabled {
opacity: 0.5;
cursor: not-allowed;
}
@media (hover: hover) {
.notify-demo-field select:enabled:hover {
border-color: #8d7a98;
}
}
.notify-demo-result {
min-height: 1.5rem;
font-size: 0.8125rem;
color: #5f5763;
}
.notify-demo-actions {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 0.625rem;
padding-top: 0.5rem;
}
.notify-demo-actions button {
display: inline-flex;
align-items: center;
justify-content: center;
box-sizing: border-box;
min-height: 3.125rem;
padding: 0.5rem 1.4rem;
font:
500 0.875rem/1.5 system-ui,
sans-serif;
letter-spacing: -0.01em;
cursor: pointer;
border: 0.0625rem solid #b7adb9;
border-radius: 0.875rem;
color: #26232b;
background: #f4f2f7;
}
.notify-demo-actions [data-demo-action] {
background: #b45309;
border-color: transparent;
color: #fff;
}
.notify-demo-actions [data-demo-reset] {
min-height: 2.5rem;
padding-inline: 1rem;
border-radius: 624.9375rem;
color: #5f5763;
border-color: #b7adb9;
background: transparent;
}
.notify-demo-actions button:disabled {
opacity: 0.5;
cursor: not-allowed;
}
@media (hover: hover) {
.notify-demo-actions button:enabled:hover {
background: #e8e5ed;
border-color: #8d7a98;
}
.notify-demo-actions [data-demo-action]:enabled:hover {
background: #92400e;
border-color: transparent;
}
.notify-demo-actions [data-demo-reset]:enabled:hover {
color: #b45309;
background: #fef3c7;
}
}
.notify-demo :focus-visible {
outline: 0.125rem solid #b45309;
outline-offset: 0.1875rem;
}
.notify-demo-output {
max-width: 100%;
overflow: auto;
padding: 1rem;
border: 0.0625rem solid #cfc7d2;
border-radius: 0.5rem;
font: 0.75rem/1.7 monospace;
}
.notify-demo [hidden] {
display: none;
}
.notify-demo-actions button {
overflow-wrap: anywhere;
max-width: 100%;
}
import { browser as notify } from '@samline/notify'
import '@samline/notify/style.css'
import './style.css'
const copy = {
exporting: 'Generating October report…',
exported: 'October report is ready',
exportFailed: 'The report could not be generated',
exportStopped: 'Export canceled',
exportError: 'The sample report service is unavailable. Choose Success and try again.',
viewCsv: 'View CSV',
csvReady: 'CSV generated · 3 rows · Preview available below',
}
const taskDemo = (element, notify, copy, signal) => {
const action = element.querySelector('[data-demo-action]')
const cancel = element.querySelector('[data-demo-cancel]')
const preview = element.querySelector('[data-export-output]')
const outcome = element.querySelector('[data-task-outcome]')
const result = element.querySelector('[data-demo-result]')
const initial = result.textContent
const csv =
'month,category,total\nOctober,Design,240\nOctober,Engineering,680\nOctober,Support,120'
let pending = new AbortController()
action.addEventListener(
'click',
async () => {
notify.createToaster({ richColors: true, closeButton: true })
const run = (pending = new AbortController())
action.disabled = true
cancel.disabled = false
preview.hidden = true
// A stand-in for a request: it fails on demand and can be canceled.
const request = wait(2200, run.signal).then(done => {
if (!done) throw new DOMException(copy.exportStopped, 'AbortError')
if (outcome.value === 'error') throw new Error(copy.exportError)
return csv
})
const toast = notify.toast.promise(request, {
loading: copy.exporting,
success: data => ({
message: copy.exported,
description: copy.csvReady,
action: {
label: copy.viewCsv,
onClick: () => {
preview.textContent = data
preview.hidden = false
},
},
}),
error: error => ({ message: copy.exportFailed, description: error.message }),
})
result.textContent = copy.exporting
try {
await toast.unwrap()
result.textContent = copy.csvReady
} catch (error) {
if (run !== pending) return // reset while waiting
const canceled = error.name === 'AbortError'
result.textContent = canceled ? copy.exportStopped : copy.exportFailed
if (canceled) notify.toast.dismiss(toast.id)
}
action.disabled = false
cancel.disabled = true
},
{ signal }
)
cancel.addEventListener('click', () => pending.abort(), { signal })
element.querySelector('[data-demo-reset]').addEventListener(
'click',
() => {
pending.abort()
pending = new AbortController()
notify.toast.dismiss()
action.disabled = false
cancel.disabled = true
preview.hidden = true
preview.textContent = ''
result.textContent = initial
},
{ signal }
)
}
// Resolves true after `ms`, or false as soon as `signal` aborts.
const wait = (ms, signal) =>
new Promise(resolve => {
const timer = setTimeout(resolve, ms, true)
signal.addEventListener(
'abort',
() => {
clearTimeout(timer)
resolve(false)
},
{ once: true }
)
})
taskDemo(document.querySelector('[data-notify-demo]'), notify, copy)
// A page that is leaving no longer needs its toaster.
window.addEventListener('pagehide', event => {
if (!event.persisted) notify.destroyToaster()
})
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>A promise with a result you can use</title>
<style>
/* Demo form only. Toast appearance and motion come from @samline/notify/style.css. */
.notify-demo {
display: grid;
gap: 1rem;
min-width: 0;
color: #26232b;
}
.notify-demo-eyebrow {
font: 0.625rem/1.6 monospace;
letter-spacing: 0.12em;
text-transform: uppercase;
color: #655d68;
}
.notify-demo-heading {
font-size: clamp(1.4rem, 3vw, 1.9rem);
line-height: 1.25;
font-weight: 500;
letter-spacing: -0.035em;
}
.notify-demo-description {
max-width: 45rem;
color: #5f5763;
line-height: 1.7;
}
.notify-demo p {
margin: 0;
}
.notify-demo-field {
display: grid;
gap: 0.5rem;
min-width: 0;
max-width: 28rem;
color: #5f5763;
font-size: 0.8125rem;
}
.notify-demo-field select {
display: block;
box-sizing: border-box;
min-width: 0;
width: 100%;
min-height: 3.125rem;
padding: 0.75rem 1rem;
font:
400 1rem/1.5 system-ui,
sans-serif;
color: #26232b;
background: #f4f2f7;
border: 0.0625rem solid #b7adb9;
border-radius: 0.5rem;
}
.notify-demo-select {
display: block;
position: relative;
min-width: 0;
color: #5f5763;
}
.notify-demo-select::after {
content: '';
box-sizing: border-box;
position: absolute;
inset-inline-end: min(1rem, 5vw);
top: 50%;
width: 0.5rem;
height: 0.5rem;
border-right: 0.125rem solid currentColor;
border-bottom: 0.125rem solid currentColor;
transform: translateY(-70%) rotate(45deg);
pointer-events: none;
}
.notify-demo-select select {
appearance: none;
cursor: pointer;
padding-inline-start: min(1rem, 5vw);
padding-inline-end: min(2.75rem, 12vw);
}
.notify-demo-select:has(select:disabled)::after {
opacity: 0.5;
}
.notify-demo-field select:disabled {
opacity: 0.5;
cursor: not-allowed;
}
@media (hover: hover) {
.notify-demo-field select:enabled:hover {
border-color: #8d7a98;
}
}
.notify-demo-result {
min-height: 1.5rem;
font-size: 0.8125rem;
color: #5f5763;
}
.notify-demo-actions {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 0.625rem;
padding-top: 0.5rem;
}
.notify-demo-actions button {
display: inline-flex;
align-items: center;
justify-content: center;
box-sizing: border-box;
min-height: 3.125rem;
padding: 0.5rem 1.4rem;
font:
500 0.875rem/1.5 system-ui,
sans-serif;
letter-spacing: -0.01em;
cursor: pointer;
border: 0.0625rem solid #b7adb9;
border-radius: 0.875rem;
color: #26232b;
background: #f4f2f7;
}
.notify-demo-actions [data-demo-action] {
background: #b45309;
border-color: transparent;
color: #fff;
}
.notify-demo-actions [data-demo-reset] {
min-height: 2.5rem;
padding-inline: 1rem;
border-radius: 624.9375rem;
color: #5f5763;
border-color: #b7adb9;
background: transparent;
}
.notify-demo-actions button:disabled {
opacity: 0.5;
cursor: not-allowed;
}
@media (hover: hover) {
.notify-demo-actions button:enabled:hover {
background: #e8e5ed;
border-color: #8d7a98;
}
.notify-demo-actions [data-demo-action]:enabled:hover {
background: #92400e;
border-color: transparent;
}
.notify-demo-actions [data-demo-reset]:enabled:hover {
color: #b45309;
background: #fef3c7;
}
}
.notify-demo :focus-visible {
outline: 0.125rem solid #b45309;
outline-offset: 0.1875rem;
}
.notify-demo-output {
max-width: 100%;
overflow: auto;
padding: 1rem;
border: 0.0625rem solid #cfc7d2;
border-radius: 0.5rem;
font: 0.75rem/1.7 monospace;
}
.notify-demo [hidden] {
display: none;
}
.notify-demo-actions button {
overflow-wrap: anywhere;
max-width: 100%;
}
</style>
</head>
<body>
<main
style="max-width: 48rem; margin: 2rem auto; padding: 1rem; font-family: system-ui, sans-serif"
>
<section class="notify-demo" data-notify-demo data-preset="task" aria-label="Reports">
<p class="notify-demo-eyebrow">Reports</p>
<strong class="notify-demo-heading">Your numbers, ready to take with you.</strong>
<p class="notify-demo-description">
Generate a small CSV from local sample data. Try success, a simulated server error, or
cancel the pending operation. No request leaves this page.
</p>
<label class="notify-demo-field"
>Sample service response<span class="notify-demo-select"
><select data-task-outcome>
<option value="success">Success</option>
<option value="error">Server error</option>
</select></span
></label
>
<pre
class="notify-demo-output"
data-export-output
aria-label="CSV preview"
tabindex="0"
hidden
></pre>
<p class="notify-demo-result" data-demo-result role="status">
October report · Ready to export
</p>
<div class="notify-demo-actions">
<button type="button" data-demo-action>Generate CSV</button>
<button type="button" data-demo-cancel disabled>Cancel export</button>
<button type="button" data-demo-reset>Reset this preview</button>
</div>
</section>
</main>
<script type="module">
import { browser as notify } from '@samline/notify'
import '@samline/notify/style.css'
const copy = {
exporting: 'Generating October report…',
exported: 'October report is ready',
exportFailed: 'The report could not be generated',
exportStopped: 'Export canceled',
exportError: 'The sample report service is unavailable. Choose Success and try again.',
viewCsv: 'View CSV',
csvReady: 'CSV generated · 3 rows · Preview available below',
}
const taskDemo = (element, notify, copy, signal) => {
const action = element.querySelector('[data-demo-action]')
const cancel = element.querySelector('[data-demo-cancel]')
const preview = element.querySelector('[data-export-output]')
const outcome = element.querySelector('[data-task-outcome]')
const result = element.querySelector('[data-demo-result]')
const initial = result.textContent
const csv =
'month,category,total\nOctober,Design,240\nOctober,Engineering,680\nOctober,Support,120'
let pending = new AbortController()
action.addEventListener(
'click',
async () => {
notify.createToaster({ richColors: true, closeButton: true })
const run = (pending = new AbortController())
action.disabled = true
cancel.disabled = false
preview.hidden = true
// A stand-in for a request: it fails on demand and can be canceled.
const request = wait(2200, run.signal).then(done => {
if (!done) throw new DOMException(copy.exportStopped, 'AbortError')
if (outcome.value === 'error') throw new Error(copy.exportError)
return csv
})
const toast = notify.toast.promise(request, {
loading: copy.exporting,
success: data => ({
message: copy.exported,
description: copy.csvReady,
action: {
label: copy.viewCsv,
onClick: () => {
preview.textContent = data
preview.hidden = false
},
},
}),
error: error => ({ message: copy.exportFailed, description: error.message }),
})
result.textContent = copy.exporting
try {
await toast.unwrap()
result.textContent = copy.csvReady
} catch (error) {
if (run !== pending) return // reset while waiting
const canceled = error.name === 'AbortError'
result.textContent = canceled ? copy.exportStopped : copy.exportFailed
if (canceled) notify.toast.dismiss(toast.id)
}
action.disabled = false
cancel.disabled = true
},
{ signal }
)
cancel.addEventListener('click', () => pending.abort(), { signal })
element.querySelector('[data-demo-reset]').addEventListener(
'click',
() => {
pending.abort()
pending = new AbortController()
notify.toast.dismiss()
action.disabled = false
cancel.disabled = true
preview.hidden = true
preview.textContent = ''
result.textContent = initial
},
{ signal }
)
}
// Resolves true after `ms`, or false as soon as `signal` aborts.
const wait = (ms, signal) =>
new Promise(resolve => {
const timer = setTimeout(resolve, ms, true)
signal.addEventListener(
'abort',
() => {
clearTimeout(timer)
resolve(false)
},
{ once: true }
)
})
taskDemo(document.querySelector('[data-notify-demo]'), notify, copy)
// A page that is leaving no longer needs its toaster.
window.addEventListener('pagehide', event => {
if (!event.persisted) notify.destroyToaster()
})
</script>
</body>
</html>
This gallery shows a few of the flows Notify supports. The rest are yours to combine: pair the toast factory with your own content, your own layout and your own interactions, and build the notification experience your product actually needs.
Read the example guideDownload the Notify integration skill