<div class="demo-caption">Dependent selects</div>
<div class="demo-split">
<div class="demo-stack">
<ray-select id="demo-country" label="Country" placeholder="Pick a country" name="country">
<option value="cl">Chile</option>
<option value="es">Spain</option>
<option value="jp">Japan</option>
<option value="us">United States</option>
</ray-select>
<ray-select id="demo-city" label="City" placeholder="Pick a country first" name="city" disabled></ray-select>
</div>
<div class="demo-ship" id="demo-ship"><ray-icon name="info"></ray-icon><span>Pick a country and a city to see the delivery estimate.</span></div>
</div>
<div class="demo-caption">Groups, descriptions and errors</div>
<div class="demo-grid">
<ray-select label="Region" value="eu-central" description="Where your data lives." description-position="below">
<optgroup label="Europe"><option value="eu-central">Frankfurt</option><option value="eu-west">London</option><option value="eu-south">Milan</option></optgroup>
<optgroup label="America"><option value="us-east">Virginia</option><option value="sa-east">São Paulo</option></optgroup>
<optgroup label="Asia"><option value="ap-north">Tokyo</option><option value="ap-south" disabled>Mumbai (soon)</option></optgroup>
</ray-select>
<ray-select label="Runtime" value="" placeholder="Pick one" error="A runtime is required to deploy." required>
<option value="native">Native binary</option>
<option value="wasm">WebAssembly</option>
</ray-select>
<ray-select id="demo-tz" label="Time zone" description="Loaded from data." value="America/Santiago"></ray-select>
</div>
<div class="demo-caption">Variants, sizes and states</div>
<div class="demo-grid">
<ray-select label="Filled" variant="filled" value="weekly"><option value="daily">Daily</option><option value="weekly">Weekly</option><option value="monthly">Monthly</option></ray-select>
<ray-select label="Large" size="lg" value="pro"><option value="free">Free</option><option value="pro">Pro</option><option value="team">Team</option></ray-select>
<ray-select label="Extra small" size="xs" value="10"><option value="10">10 per page</option><option value="25">25 per page</option><option value="50">50 per page</option></ray-select>
<ray-select label="Disabled" value="main" disabled><option value="main">main</option></ray-select>
</div>
<div class="demo-unstyled">
<span class="demo-muted">Sort by</span>
<ray-select aria-label="Sort by" variant="unstyled" size="xs" value="recent"><option value="recent">Most recent</option><option value="popular">Most popular</option><option value="name">Name</option></ray-select>
</div>
<script type="module">
const cities = {
cl: ["Santiago", "Valparaíso", "Concepción", "Punta Arenas"],
es: ["Madrid", "Barcelona", "Valencia", "Sevilla"],
jp: ["Tokyo", "Osaka", "Kyoto", "Sapporo"],
us: ["New York", "San Francisco", "Chicago", "Austin"],
};
const days = { cl: "2–3", es: "4–6", jp: "6–8", us: "3–5" };
const country = document.getElementById("demo-country");
const city = document.getElementById("demo-city");
const ship = document.getElementById("demo-ship").querySelector("span");
country.addEventListener("change", () => {
city.data = cities[country.value] ?? [];
city.value = "";
city.placeholder = "Pick a city";
city.disabled = false;
ship.textContent = "Now pick a city.";
});
city.addEventListener("change", () => {
const name = country.querySelector(`option[value="${country.value}"]`)?.textContent;
ship.textContent = city.value ? `Delivery to ${city.value}, ${name}: ${days[country.value]} business days.` : "Now pick a city.";
});
document.getElementById("demo-tz").data = [
{ value: "America/Santiago", label: "Santiago (UTC−3)" },
{ value: "America/New_York", label: "New York (UTC−4)" },
{ value: "Europe/Madrid", label: "Madrid (UTC+2)" },
{ value: "Asia/Tokyo", label: "Tokyo (UTC+9)" },
];
</script>
import { RaySelect, RayIcon } from "@raylang/react";
export function SelectExample() {
return (
<>
<div className="demo-caption">Dependent selects</div>
<div className="demo-split">
<div className="demo-stack">
<RaySelect id="demo-country" label="Country" placeholder="Pick a country" name="country">
<option value="cl">Chile</option>
<option value="es">Spain</option>
<option value="jp">Japan</option>
<option value="us">United States</option>
</RaySelect>
<RaySelect id="demo-city" label="City" placeholder="Pick a country first" name="city" disabled />
</div>
<div className="demo-ship" id="demo-ship"><RayIcon name="info" /><span>Pick a country and a city to see the delivery estimate.</span></div>
</div>
<div className="demo-caption">Groups, descriptions and errors</div>
<div className="demo-grid">
<RaySelect label="Region" value="eu-central" description="Where your data lives." descriptionPosition="below">
<optgroup label="Europe"><option value="eu-central">Frankfurt</option><option value="eu-west">London</option><option value="eu-south">Milan</option></optgroup>
<optgroup label="America"><option value="us-east">Virginia</option><option value="sa-east">São Paulo</option></optgroup>
<optgroup label="Asia"><option value="ap-north">Tokyo</option><option value="ap-south" disabled>Mumbai (soon)</option></optgroup>
</RaySelect>
<RaySelect label="Runtime" value="" placeholder="Pick one" error="A runtime is required to deploy." required>
<option value="native">Native binary</option>
<option value="wasm">WebAssembly</option>
</RaySelect>
<RaySelect id="demo-tz" label="Time zone" description="Loaded from data." value="America/Santiago" />
</div>
<div className="demo-caption">Variants, sizes and states</div>
<div className="demo-grid">
<RaySelect label="Filled" variant="filled" value="weekly"><option value="daily">Daily</option><option value="weekly">Weekly</option><option value="monthly">Monthly</option></RaySelect>
<RaySelect label="Large" size="lg" value="pro"><option value="free">Free</option><option value="pro">Pro</option><option value="team">Team</option></RaySelect>
<RaySelect label="Extra small" size="xs" value="10"><option value="10">10 per page</option><option value="25">25 per page</option><option value="50">50 per page</option></RaySelect>
<RaySelect label="Disabled" value="main" disabled><option value="main">main</option></RaySelect>
</div>
<div className="demo-unstyled">
<span className="demo-muted">Sort by</span>
<RaySelect aria-label="Sort by" variant="unstyled" size="xs" value="recent"><option value="recent">Most recent</option><option value="popular">Most popular</option><option value="name">Name</option></RaySelect>
</div>
</>
);
}
<template>
<div class="demo-caption">Dependent selects</div>
<div class="demo-split">
<div class="demo-stack">
<RaySelect id="demo-country" label="Country" placeholder="Pick a country" name="country">
<option value="cl">Chile</option>
<option value="es">Spain</option>
<option value="jp">Japan</option>
<option value="us">United States</option>
</RaySelect>
<RaySelect id="demo-city" label="City" placeholder="Pick a country first" name="city" disabled />
</div>
<div class="demo-ship" id="demo-ship"><RayIcon name="info" /><span>Pick a country and a city to see the delivery estimate.</span></div>
</div>
<div class="demo-caption">Groups, descriptions and errors</div>
<div class="demo-grid">
<RaySelect label="Region" value="eu-central" description="Where your data lives." description-position="below">
<optgroup label="Europe"><option value="eu-central">Frankfurt</option><option value="eu-west">London</option><option value="eu-south">Milan</option></optgroup>
<optgroup label="America"><option value="us-east">Virginia</option><option value="sa-east">São Paulo</option></optgroup>
<optgroup label="Asia"><option value="ap-north">Tokyo</option><option value="ap-south" disabled>Mumbai (soon)</option></optgroup>
</RaySelect>
<RaySelect label="Runtime" value="" placeholder="Pick one" error="A runtime is required to deploy." required>
<option value="native">Native binary</option>
<option value="wasm">WebAssembly</option>
</RaySelect>
<RaySelect id="demo-tz" label="Time zone" description="Loaded from data." value="America/Santiago" />
</div>
<div class="demo-caption">Variants, sizes and states</div>
<div class="demo-grid">
<RaySelect label="Filled" variant="filled" value="weekly"><option value="daily">Daily</option><option value="weekly">Weekly</option><option value="monthly">Monthly</option></RaySelect>
<RaySelect label="Large" size="lg" value="pro"><option value="free">Free</option><option value="pro">Pro</option><option value="team">Team</option></RaySelect>
<RaySelect label="Extra small" size="xs" value="10"><option value="10">10 per page</option><option value="25">25 per page</option><option value="50">50 per page</option></RaySelect>
<RaySelect label="Disabled" value="main" disabled><option value="main">main</option></RaySelect>
</div>
<div class="demo-unstyled">
<span class="demo-muted">Sort by</span>
<RaySelect aria-label="Sort by" variant="unstyled" size="xs" value="recent"><option value="recent">Most recent</option><option value="popular">Most popular</option><option value="name">Name</option></RaySelect>
</div>
</template>