<div class="demo-caption">In a form: required, one entry per value</div>
<form class="demo-auth" id="demo-cbg-form" novalidate>
<ray-checkbox-group id="demo-cbg-channels" name="channels" label="Send me updates by" description="Pick at least one." required value="email">
<ray-checkbox value="email" label="Email" description="A weekly summary"></ray-checkbox>
<ray-checkbox value="push" label="Push" description="On this device"></ray-checkbox>
<ray-checkbox value="sms" label="SMS" description="Only for security alerts"></ray-checkbox>
<ray-checkbox value="slack" label="Slack" description="Connect a workspace first" disabled></ray-checkbox>
</ray-checkbox-group>
<div class="demo-actions"><ray-button type="submit">Save</ray-button><span class="demo-muted" id="demo-cbg-out"></span></div>
</form>
<div class="demo-caption">max: up to three</div>
<ray-checkbox-group label="Interests" orientation="horizontal" max="3" color="violet" value="components,tokens">
<ray-checkbox value="components" label="Components"></ray-checkbox>
<ray-checkbox value="tokens" label="Design tokens"></ray-checkbox>
<ray-checkbox value="a11y" label="Accessibility"></ray-checkbox>
<ray-checkbox value="charts" label="Charts"></ray-checkbox>
<ray-checkbox value="mobile" label="Mobile"></ray-checkbox>
<ray-checkbox value="raylang" label="raylang"></ray-checkbox>
</ray-checkbox-group>
<div class="demo-caption">Select all (indeterminate)</div>
<div class="demo-cbg-all">
<ray-checkbox id="demo-cbg-all" label="All environments"></ray-checkbox>
<ray-checkbox-group id="demo-cbg-envs" aria-label="Environments" value="staging" class="demo-cbg-nested">
<ray-checkbox value="dev" label="Development"></ray-checkbox>
<ray-checkbox value="staging" label="Staging"></ray-checkbox>
<ray-checkbox value="prod" label="Production"></ray-checkbox>
</ray-checkbox-group>
</div>
<div class="demo-caption">Sizes, colors and disabled</div>
<div class="demo-grid">
<ray-checkbox-group label="Small, teal" size="xs" color="teal" value="a"><ray-checkbox value="a" label="Alpha"></ray-checkbox><ray-checkbox value="b" label="Beta"></ray-checkbox></ray-checkbox-group>
<ray-checkbox-group label="Large, orange" size="md" color="orange" value="b"><ray-checkbox value="a" label="Alpha"></ray-checkbox><ray-checkbox value="b" label="Beta"></ray-checkbox></ray-checkbox-group>
<ray-checkbox-group label="Disabled" disabled value="a"><ray-checkbox value="a" label="Alpha"></ray-checkbox><ray-checkbox value="b" label="Beta"></ray-checkbox></ray-checkbox-group>
<ray-checkbox-group label="With an error" error="Choose a plan feature." description-position="below" description="Billed monthly."><ray-checkbox value="a" label="Backups"></ray-checkbox><ray-checkbox value="b" label="Analytics"></ray-checkbox></ray-checkbox-group>
</div>
<script type="module">
const form = document.getElementById("demo-cbg-form");
const channels = document.getElementById("demo-cbg-channels");
form.addEventListener("submit", (e) => {
e.preventDefault();
if (!channels.value.length) {
channels.error = "Pick at least one channel.";
document.getElementById("demo-cbg-out").textContent = "";
return;
}
document.getElementById("demo-cbg-out").textContent = `channels = ${new FormData(form).getAll("channels").join(", ")}`;
});
channels.addEventListener("change", () => { channels.error = ""; });
const all = document.getElementById("demo-cbg-all");
const envs = document.getElementById("demo-cbg-envs");
const values = ["dev", "staging", "prod"];
const sync = () => {
const n = envs.value.length;
all.checked = n === values.length;
all.indeterminate = n > 0 && n < values.length;
};
all.addEventListener("change", () => { envs.value = all.checked ? values.slice() : []; sync(); });
envs.addEventListener("change", sync);
customElements.whenDefined("ray-checkbox-group").then(() => queueMicrotask(sync));
</script>
import { RayCheckboxGroup, RayCheckbox, RayButton } from "@raylang/react";
export function CheckboxGroupExample() {
return (
<>
<div className="demo-caption">In a form: required, one entry per value</div>
<form className="demo-auth" id="demo-cbg-form" novalidate>
<RayCheckboxGroup id="demo-cbg-channels" name="channels" label="Send me updates by" description="Pick at least one." required value="email">
<RayCheckbox value="email" label="Email" description="A weekly summary" />
<RayCheckbox value="push" label="Push" description="On this device" />
<RayCheckbox value="sms" label="SMS" description="Only for security alerts" />
<RayCheckbox value="slack" label="Slack" description="Connect a workspace first" disabled />
</RayCheckboxGroup>
<div className="demo-actions"><RayButton type="submit">Save</RayButton><span className="demo-muted" id="demo-cbg-out" /></div>
</form>
<div className="demo-caption">max: up to three</div>
<RayCheckboxGroup label="Interests" orientation="horizontal" max={3} color="violet" value="components,tokens">
<RayCheckbox value="components" label="Components" />
<RayCheckbox value="tokens" label="Design tokens" />
<RayCheckbox value="a11y" label="Accessibility" />
<RayCheckbox value="charts" label="Charts" />
<RayCheckbox value="mobile" label="Mobile" />
<RayCheckbox value="raylang" label="raylang" />
</RayCheckboxGroup>
<div className="demo-caption">Select all (indeterminate)</div>
<div className="demo-cbg-all">
<RayCheckbox id="demo-cbg-all" label="All environments" />
<RayCheckboxGroup id="demo-cbg-envs" aria-label="Environments" value="staging" className="demo-cbg-nested">
<RayCheckbox value="dev" label="Development" />
<RayCheckbox value="staging" label="Staging" />
<RayCheckbox value="prod" label="Production" />
</RayCheckboxGroup>
</div>
<div className="demo-caption">Sizes, colors and disabled</div>
<div className="demo-grid">
<RayCheckboxGroup label="Small, teal" size="xs" color="teal" value="a"><RayCheckbox value="a" label="Alpha" /><RayCheckbox value="b" label="Beta" /></RayCheckboxGroup>
<RayCheckboxGroup label="Large, orange" size="md" color="orange" value="b"><RayCheckbox value="a" label="Alpha" /><RayCheckbox value="b" label="Beta" /></RayCheckboxGroup>
<RayCheckboxGroup label="Disabled" disabled value="a"><RayCheckbox value="a" label="Alpha" /><RayCheckbox value="b" label="Beta" /></RayCheckboxGroup>
<RayCheckboxGroup label="With an error" error="Choose a plan feature." descriptionPosition="below" description="Billed monthly."><RayCheckbox value="a" label="Backups" /><RayCheckbox value="b" label="Analytics" /></RayCheckboxGroup>
</div>
</>
);
}
<template>
<div class="demo-caption">In a form: required, one entry per value</div>
<form class="demo-auth" id="demo-cbg-form" novalidate>
<RayCheckboxGroup id="demo-cbg-channels" name="channels" label="Send me updates by" description="Pick at least one." required value="email">
<RayCheckbox value="email" label="Email" description="A weekly summary" />
<RayCheckbox value="push" label="Push" description="On this device" />
<RayCheckbox value="sms" label="SMS" description="Only for security alerts" />
<RayCheckbox value="slack" label="Slack" description="Connect a workspace first" disabled />
</RayCheckboxGroup>
<div class="demo-actions"><RayButton type="submit">Save</RayButton><span class="demo-muted" id="demo-cbg-out"></span></div>
</form>
<div class="demo-caption">max: up to three</div>
<RayCheckboxGroup label="Interests" orientation="horizontal" :max="3" color="violet" value="components,tokens">
<RayCheckbox value="components" label="Components" />
<RayCheckbox value="tokens" label="Design tokens" />
<RayCheckbox value="a11y" label="Accessibility" />
<RayCheckbox value="charts" label="Charts" />
<RayCheckbox value="mobile" label="Mobile" />
<RayCheckbox value="raylang" label="raylang" />
</RayCheckboxGroup>
<div class="demo-caption">Select all (indeterminate)</div>
<div class="demo-cbg-all">
<RayCheckbox id="demo-cbg-all" label="All environments" />
<RayCheckboxGroup id="demo-cbg-envs" aria-label="Environments" value="staging" class="demo-cbg-nested">
<RayCheckbox value="dev" label="Development" />
<RayCheckbox value="staging" label="Staging" />
<RayCheckbox value="prod" label="Production" />
</RayCheckboxGroup>
</div>
<div class="demo-caption">Sizes, colors and disabled</div>
<div class="demo-grid">
<RayCheckboxGroup label="Small, teal" size="xs" color="teal" value="a"><RayCheckbox value="a" label="Alpha" /><RayCheckbox value="b" label="Beta" /></RayCheckboxGroup>
<RayCheckboxGroup label="Large, orange" size="md" color="orange" value="b"><RayCheckbox value="a" label="Alpha" /><RayCheckbox value="b" label="Beta" /></RayCheckboxGroup>
<RayCheckboxGroup label="Disabled" disabled value="a"><RayCheckbox value="a" label="Alpha" /><RayCheckbox value="b" label="Beta" /></RayCheckboxGroup>
<RayCheckboxGroup label="With an error" error="Choose a plan feature." description-position="below" description="Billed monthly."><RayCheckbox value="a" label="Backups" /><RayCheckbox value="b" label="Analytics" /></RayCheckboxGroup>
</div>
</template>