<div class="demo-caption">A settings panel</div>
<div class="demo-prefs" id="demo-prefs">
<div class="demo-pref main">
<div><strong>Notifications</strong><span>Pause all of them at once.</span></div>
<ray-switch id="demo-notify-all" aria-label="Notifications" checked size="md"></ray-switch>
</div>
<div class="demo-pref">
<div><strong>Email</strong><span>Mentions, replies and invitations.</span></div>
<ray-switch data-child aria-label="Email" checked></ray-switch>
</div>
<div class="demo-pref">
<div><strong>Push</strong><span>On this device, while the app is closed.</span></div>
<ray-switch data-child aria-label="Push" checked></ray-switch>
</div>
<div class="demo-pref">
<div><strong>Weekly digest</strong><span>Every Monday at 9:00.</span></div>
<ray-switch data-child aria-label="Weekly digest"></ray-switch>
</div>
<p class="demo-muted" id="demo-prefs-out">On: Email, Push.</p>
</div>
<div class="demo-caption">Labels, descriptions and sides</div>
<div class="demo-grid">
<ray-switch label="Public profile" description="Anyone with the link can see it." checked></ray-switch>
<ray-switch label="Label before" label-position="start"></ray-switch>
<ray-switch label="Two-factor authentication" error="Required by your organization." color="red"></ray-switch>
<ray-switch label="Disabled, on" checked disabled></ray-switch>
</div>
<div class="demo-caption">Colors and sizes</div>
<div class="demo-row">
<ray-switch label="xs" size="xs" checked color="blue"></ray-switch>
<ray-switch label="sm" size="sm" checked color="teal"></ray-switch>
<ray-switch label="md" size="md" checked color="violet"></ray-switch>
<ray-switch label="lg" size="lg" checked color="orange"></ray-switch>
<ray-switch label="xl" size="xl" checked color="pink"></ray-switch>
<ray-switch label="yellow" checked color="yellow"></ray-switch>
</div>
<script type="module">
const all = document.getElementById("demo-notify-all");
const children = [...document.querySelectorAll("#demo-prefs [data-child]")];
const sum = () => {
const on = children.filter((s) => s.checked).map((s) => s.getAttribute("aria-label"));
document.getElementById("demo-prefs-out").textContent = !all.checked ? "All notifications paused."
: on.length ? `On: ${on.join(", ")}.` : "Every channel is off.";
};
all.addEventListener("change", () => {
for (const s of children) s.disabled = !all.checked;
sum();
});
for (const s of children) s.addEventListener("change", sum);
customElements.whenDefined("ray-switch").then(sum);
</script>
import { RaySwitch } from "@raylang/react";
export function SwitchExample() {
return (
<>
<div className="demo-caption">A settings panel</div>
<div className="demo-prefs" id="demo-prefs">
<div className="demo-pref main">
<div><strong>Notifications</strong><span>Pause all of them at once.</span></div>
<RaySwitch id="demo-notify-all" aria-label="Notifications" checked size="md" />
</div>
<div className="demo-pref">
<div><strong>Email</strong><span>Mentions, replies and invitations.</span></div>
<RaySwitch data-child aria-label="Email" checked />
</div>
<div className="demo-pref">
<div><strong>Push</strong><span>On this device, while the app is closed.</span></div>
<RaySwitch data-child aria-label="Push" checked />
</div>
<div className="demo-pref">
<div><strong>Weekly digest</strong><span>Every Monday at 9:00.</span></div>
<RaySwitch data-child aria-label="Weekly digest" />
</div>
<p className="demo-muted" id="demo-prefs-out">On: Email, Push.</p>
</div>
<div className="demo-caption">Labels, descriptions and sides</div>
<div className="demo-grid">
<RaySwitch label="Public profile" description="Anyone with the link can see it." checked />
<RaySwitch label="Label before" labelPosition="start" />
<RaySwitch label="Two-factor authentication" error="Required by your organization." color="red" />
<RaySwitch label="Disabled, on" checked disabled />
</div>
<div className="demo-caption">Colors and sizes</div>
<div className="demo-row">
<RaySwitch label="xs" size="xs" checked color="blue" />
<RaySwitch label="sm" size="sm" checked color="teal" />
<RaySwitch label="md" size="md" checked color="violet" />
<RaySwitch label="lg" size="lg" checked color="orange" />
<RaySwitch label="xl" size="xl" checked color="pink" />
<RaySwitch label="yellow" checked color="yellow" />
</div>
</>
);
}
<template>
<div class="demo-caption">A settings panel</div>
<div class="demo-prefs" id="demo-prefs">
<div class="demo-pref main">
<div><strong>Notifications</strong><span>Pause all of them at once.</span></div>
<RaySwitch id="demo-notify-all" aria-label="Notifications" checked size="md" />
</div>
<div class="demo-pref">
<div><strong>Email</strong><span>Mentions, replies and invitations.</span></div>
<RaySwitch data-child aria-label="Email" checked />
</div>
<div class="demo-pref">
<div><strong>Push</strong><span>On this device, while the app is closed.</span></div>
<RaySwitch data-child aria-label="Push" checked />
</div>
<div class="demo-pref">
<div><strong>Weekly digest</strong><span>Every Monday at 9:00.</span></div>
<RaySwitch data-child aria-label="Weekly digest" />
</div>
<p class="demo-muted" id="demo-prefs-out">On: Email, Push.</p>
</div>
<div class="demo-caption">Labels, descriptions and sides</div>
<div class="demo-grid">
<RaySwitch label="Public profile" description="Anyone with the link can see it." checked />
<RaySwitch label="Label before" label-position="start" />
<RaySwitch label="Two-factor authentication" error="Required by your organization." color="red" />
<RaySwitch label="Disabled, on" checked disabled />
</div>
<div class="demo-caption">Colors and sizes</div>
<div class="demo-row">
<RaySwitch label="xs" size="xs" checked color="blue" />
<RaySwitch label="sm" size="sm" checked color="teal" />
<RaySwitch label="md" size="md" checked color="violet" />
<RaySwitch label="lg" size="lg" checked color="orange" />
<RaySwitch label="xl" size="xl" checked color="pink" />
<RaySwitch label="yellow" checked color="yellow" />
</div>
</template>