Turn Web Push on for this browser, see devices that have it, turn one off and send a test.
<div class="cap-web-push" id="push-devices">
<div class="cap-web-push-live" role="status"><div class="cap-web-push-note">Test alert sent to each device.</div></div>
<div class="cap-web-push-actions">
<button type="button" class="cap-btn" data-variant="primary">Turn on for this device</button>
<button type="button" class="cap-btn">Send a test alert</button>
</div>
<ul class="cap-web-push-devices" aria-label="Devices with alerts on">
<li class="cap-web-push-device">
<span class="cap-web-push-device-name">Chrome on Android <span class="cap-web-push-device-detail">turned on 3 days ago, last alert an hour ago</span></span>
<button type="button" class="cap-btn">Turn off<span class="cap-sr-only"> Chrome on Android</span></button>
</li>
<li class="cap-web-push-device">
<span class="cap-web-push-device-name">Safari on iOS <span class="cap-web-push-device-detail">turned on a week ago, no alert yet</span></span>
<button type="button" class="cap-btn">Turn off<span class="cap-sr-only"> Safari on iOS</span></button>
</li>
</ul>
</div>
import "capsomer/tokens.css";
import "capsomer/web-push.css";
import { PushDevices } from "capsomer/react/web-push";
Usage
<div class="cap-push">
<div class="cap-push-note" role="status">Phone alerts are on for this device.</div> <!-- data-tone="crit" and role="alert" for a failure -->
<div class="cap-push-actions">
<button type="button" class="cap-btn" data-variant="primary">Turn on for this device</button>
<button type="button" class="cap-btn">Send a test alert</button>
</div>
<ul class="cap-push-devices" aria-label="Devices with alerts on">
<li class="cap-push-device">
<span class="cap-push-device-name">Chrome on Android <span class="cap-push-device-detail">turned on 3 days ago</span></span>
<button type="button" class="cap-btn">Turn off</button>
</li>
</ul>
</div>
Examples
Turning on failed
<div class="cap-web-push">
<div class="cap-web-push-note" data-tone="crit" role="alert">This browser did not allow notifications. Allow them for this site in the browser's settings, then try again.</div>
<div class="cap-web-push-actions">
<button type="button" class="cap-btn" data-variant="primary">Turn on for this device</button>
<button type="button" class="cap-btn" disabled>Send a test alert</button>
</div>
</div>
Not set up, and a browser with no Web Push
<div class="cap-web-push" id="push-setup">
<div class="cap-web-push-live" role="status"><div class="cap-web-push-note" data-tone="warn">Not set up yet: the VAPID key is not set.</div></div>
<div class="cap-web-push-actions">
<span class="cap-web-push-unsupported">This browser cannot receive Web Push.</span>
<button type="button" class="cap-btn" disabled>Send a test alert</button>
</div>
</div>
API reference
PushDevices
Prop
Type
Required
Does
publicKey
string | null
Yes
The server's VAPID public key; null while it is not set up.
worker
string
Yes
The worker to register (push-sw.js as the site serves it) and its scope.
scope
string
Yes
devices
PushDevice[]
Yes
busy
boolean
A request is in flight: the controls wait.
note
PushNote | null
The result of the last change, from the app (or set here when turning on fails).
problem
ReactNode
What the setup still needs, in the server's words.
Asks for permission, registers the worker and subscribes (or returns the subscription this browser already has). Throws PushRefused when the person or the browser said no.
Parts and data attributes
Class
Is
.cap-web-push
the root
.cap-web-push-actions
a part
.cap-web-push-device
a part
.cap-web-push-device-detail
a part
.cap-web-push-device-name
a part
.cap-web-push-devices
a part
.cap-web-push-live
a part
.cap-web-push-note
a part
.cap-web-push-unsupported
a part
Attribute
Values
data-tone
critwarn
State
Read from
:empty
the platform
Accessibility
Key
Does
Tab
Moves through Turn on, Send a test alert, then each device's Turn off
Enter, Space
Presses the button
A failure is an alert; a result is a status, so it is read when it changes.
The device list is a named list.
Buttons wait (disabled) while a request is in flight.