Liking cljdoc? Tell your friends :D

x-notification-center

A fixed-position stack that manages a collection of x-alert notifications, exposing a programmatic push() / clear() API.

Dependency: x-alert must be registered (via its own init()) before calling push().


Tag

<x-notification-center></x-notification-center>

Attributes

AttributeTypeDefaultNotes
positionstring"top-right"One of: top-right, top-left, bottom-right, bottom-left, top-center, bottom-center
maxnumber5Maximum concurrent alerts; new pushes are silently ignored when full

Properties

PropertyTypeDefaultNotes
positionstring"top-right"Reflects position attribute
maxnumber5Reflects max attribute
countnumber(read-only)Live count of current x-alert children

Methods

MethodSignatureNotes
pushpush(options)Creates and appends an x-alert; ignored when count >= max
clearclear()Immediately removes all current x-alert elements (bypasses exit animation)

push(options)

Options object fields (all optional):

FieldTypeNotes
idstringCustom notification ID; auto-generated if omitted
typestring"info", "success", "warning", "error"
textstringAlert message text
iconstringIcon glyph or "none" to hide the icon
dismissiblebooleanPass false to make the alert non-dismissible
timeoutMsnumberAuto-dismiss after this many milliseconds

Events

All events bubble and are composed. None are cancelable.

Event namedetailFired when
x-notification-center-push{ id: string, count: number }An alert is pushed
x-notification-center-dismiss{ id: string, type: string, reason: string, text: string, count: number }An x-alert-dismiss event is received (forwarded)
x-notification-center-empty{}The count reaches 0 after a dismiss

CSS Custom Properties

PropertyDefaultNotes
--x-notification-center-width360pxWidth of the alert stack
--x-notification-center-gap8pxGap between alerts
--x-notification-center-offset-x16pxHorizontal inset from the viewport edge
--x-notification-center-offset-y16pxVertical inset from the viewport edge
--x-notification-center-z-index9999Stack z-index

Parts

PartElementNotes
container<div>Flex column containing pushed alerts; column-reverse for bottom positions

Shadow DOM Structure

#shadow-root (open)
  <style>
  <div part="container">
    <!-- x-alert elements appended here programmatically -->
  </div>

Accessibility

  • x-notification-center itself has no interactive content; all accessibility is delegated to the individual x-alert elements.
  • x-alert elements use role="alert" (assertive) for warning/error types and role="status" (polite) for info/success.

Usage Examples

Basic push

import '@vanelsas/baredom/x-alert';
import '@vanelsas/baredom/x-notification-center';

const nc = document.querySelector('x-notification-center');

nc.push({ type: 'success', text: 'File saved.' });
nc.push({ type: 'error',   text: 'Network error. Please retry.' });

Auto-dismiss

nc.push({ type: 'info', text: 'Session expires soon.', timeoutMs: 5000 });

Non-dismissible

nc.push({ type: 'warning', text: 'Read-only mode.', dismissible: false });

Clear all

nc.clear();

Listening to events

nc.addEventListener('x-notification-center-push', e => {
  console.log('pushed', e.detail.id, 'count:', e.detail.count);
});

nc.addEventListener('x-notification-center-dismiss', e => {
  const { id, type, reason, text, count } = e.detail;
  console.log(`dismissed ${id} (${type}) via ${reason} — "${text}". Remaining: ${count}`);
});

nc.addEventListener('x-notification-center-empty', () => {
  console.log('All notifications cleared');
});

Position

<x-notification-center position="bottom-right"></x-notification-center>
nc.position = 'bottom-center';

Custom max

<x-notification-center max="3"></x-notification-center>

Can you improve this documentation?Edit on GitHub

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close