network-status
Live connectivity readout — navigator.onLine plus connection type and
speed where the browser exposes them.
Features
- CSS-driven UI Style from
[is-online]/[connection-type] - Live events
online/offline/changefire as connectivity shifts — on transitions, never at mount - Bindable state
.provisionis the full snapshot; read it from Quark withprop("provision") - Network Information API Connection type + effective speed where supported
- Graceful degradation Unsupported fields stay
null; core online/offline still works everywhere
Installation
This package is available in the
<script src="https://unpkg.com/@excom/kit-utils@0.3.0/dist/index.umd.min.js"></script>
<script src="https://unpkg.com/@excom/neutron@0.2.0/dist/index.umd.min.js"></script>
<script src="https://unpkg.com/@excom/network-status@0.1.4/dist/index.umd.min.js"></script>npm install @excom/network-status<!-- import path to `node_modules` will depend on your build setup -->
<script type="module" src="/node_modules/@excom/network-status"></script>
<link rel="stylesheet" href="/node_modules/@excom/network-status">import "@excom/network-status";Peer dependencies (0)
Packages a consumer must install alongside this one. Workspace deps are bundled.
| Package | Version |
|---|---|
|
Usage
Drop it anywhere and hook [is-online] / [is-mounted] with CSS, or
listen for its events from a parent.
<network-status></network-status><network-status></network-status>network-status:not([is-mounted])::before {
content: "Loading…";
}
network-status[is-online]::before {
content: "📶 Online";
}
network-status[is-mounted]:not([is-online])::before {
content: "📵 Offline";
}network-status:not([is-mounted])::before {
content: "Loading…";
}
network-status[is-online]::before {
content: "📶 Online";
}
network-status[is-mounted]:not([is-online])::before {
content: "📵 Offline";
}Nothing fires at mount: the first read sets is-online and .provision
only. React to the attribute (or prop("provision")) for the initial
state; network-status-online / -offline report transitions.
The Network Information API (connection-type, effective-type,
downlink, rtt) is Chromium-only — Safari and Firefox leave those
fields null. Build critical UX on is-online alone; treat the rest as
a progressive enhancement. Safari/iOS also have known navigator.onLine
reliability quirks — see INTERNAL.md.
API Reference
Attributes
Role —option is configurable, state
is managed by the element (read-only), or hybrid which is both.
Provision
Thisprovision property lives on the DOM node.
Read / watch it with Quark’s prop("provision"), or listen
for the neutron-provision event from app JS.
Events
Type
command event (HTML Command API): from a
<button command commandfor>, an <event-handler
command-name>, or a CommandEvent.
Recognized Elements
Child or descendant elements are recognized by and relevant to its functionality.Styles
@custom-selector synonyms so custom elements can share
semantic styles. Element aliases match the host tag / .tag-* class; state
aliases match attributes (nested under the element alias).
network-status
Attributes (3)
Role —option is configurable, state
is managed by the element (read-only), or hybrid which is both.
connection-type
wifi, cellular, ethernet, …) from the Network Information API. null where unsupported (Safari, Firefox).
connectionType
string
nulleffective-type
4g, 3g, 2g, slow-2g) from the Network Information API. null where unsupported (Safari, Firefox).
effectiveType
string
nullis-online
navigator.onLine value.
isOnline
boolean
falseProvision (1)
Thisprovision property lives on the DOM node.
Read / watch it with Quark’s prop("provision"), or listen
for the neutron-provision event from app JS.
provision
{ isOnline, connectionType, effectiveType, downlink, rtt, lastOnline, lastOffline }. Set at mount and on every change; the same object dispatched as event.detail on every fired event. lastOnline / lastOffline are stamped on transitions only. Not reflected as an attribute.
provision
NetworkStatusProvision
Events (3)
e.preventDefault() is not
synchronously called on the event.
Type
network-status-change
event.detail is the full .provision payload.
Type
NetworkStatusChangeEvent
network-status-offline
event.detail is the full .provision payload.
Type
NetworkStatusOfflineEvent
network-status-online
event.detail is the full .provision payload.
Type
NetworkStatusOnlineEvent
command event (HTML Command API): from a
<button command commandfor>, an <event-handler
command-name>, or a CommandEvent.
Recognized Elements (0)
Child or descendant elements are recognized by network-status and relevant to its functionality.Styles (0)
all: revert-layer.
Valence.css ships this as .unstyled and .unstyled-all for the entire tree.
@custom-selector synonyms so custom elements can share
semantic styles. Element aliases match the host tag / .tag-* class; state
aliases match attributes (nested under the element alias).
Release notes (1)
0.1.1
- Ship only dist (and declared extras) in the npm tarball; drop build logs, tests and sources
Release notes
e.preventDefault() is not
synchronously called on the event.
all: revert-layer.
Valence.css ships this as .unstyled and .unstyled-all for the entire tree.
Examples
Offline banner
A banner shown purely by CSS attribute selector — no listeners needed.