Radio Group
Provides shared state to a series of radio buttons.
Partly measured from the app's Radio source. No radio is reachable without a paid plan, so the classes were read from source.
import { RadioGroup } from "@replicas/ui";
import { useId } from "react";
const orderings = [
{ value: "name", label: "Name" },
{ value: "updated", label: "Last updated" },
{ value: "created", label: "Created" },
{ value: "size", label: "Size" },
];
const label = { display: "flex", alignItems: "center", gap: 8, color: "var(--text-secondary)" };
export default function RadioGroupDemo() {
const id = useId();
return (
<RadioGroup.Root aria-labelledby={id} defaultValue="name">
<div id={id} style={{ fontWeight: "var(--font-weight-medium)" }}>
Sort by
</div>
{orderings.map((ordering) => (
<label key={ordering.value} style={label}>
<RadioGroup.Item value={ordering.value} />
{ordering.label}
</label>
))}
</RadioGroup.Root>
);
}Prompt
Copy Prompt hands your agent everything it needs to build the Radio Group in the Laravel Cloud style: the measured tokens, the CSS and the structure.
Show Prompt
# Laravel Cloud Radio Group
Provides shared state to a series of radio buttons.
Build a Radio Group in this project that looks and behaves like Laravel Cloud's. Measured from the running Laravel Cloud app (cloud.laravel.com). Keep every value exact. Map the tokens onto the project's own theme variables instead of hard-coding them. Use the project's own component library for behaviour, or [Base UI](https://base-ui.com/react/components/radio-group) if it has none.
Fidelity: Partly measured from the app's Radio source. No radio is reachable without a paid plan, so the classes were read from source.
## Tokens
| Token | Light | Dark |
| --- | --- | --- |
| `--background-color-brand` | `var(--cloud-dark-9)` | `var(--cloud-dark-9)` |
| `--border-color-default` | `var(--slate-dark-alpha-7)` | `var(--slate-dark-alpha-7)` |
| `--border-color-danger` | `var(--ruby-dark-alpha-10)` | `var(--ruby-dark-alpha-10)` |
| `--shadow-xs` | `0 0 1px 0 #0000004d, 0 1px 2px 0 #00000066` | `0 0 1px 0 #0000004d, 0 1px 2px 0 #00000066` |
## CSS
Scoped under `[data-style="laravel"]`; dark rules sit under `[data-theme="dark"]`. The `ui-*` classes and data attributes match the structure below.
```css
[data-style="laravel"] {
.ui-radio-group {
display: flex;
flex-direction: column;
align-items: flex-start;
gap: 16px;
}
.ui-radio-group-item {
position: relative;
isolation: isolate;
box-sizing: border-box;
display: inline-flex;
flex-shrink: 0;
align-items: center;
justify-content: center;
width: 16px;
height: 16px;
margin: 0;
padding: 0;
border: 1px solid var(--border-color-default);
border-radius: var(--radius-rounded);
background-color: transparent;
outline: none;
&::before {
content: "";
position: absolute;
inset: -1px;
z-index: -10;
border-radius: var(--radius-rounded);
box-shadow: var(--shadow-xs);
}
&:focus-visible {
box-shadow: var(--shadow-xs-selected);
}
&[data-checked] {
background-color: var(--background-color-brand);
}
&[aria-invalid="true"]:not([data-checked]) {
border-color: var(--border-color-danger);
}
&[data-disabled] {
opacity: 0.5;
}
}
.ui-radio-group-indicator {
width: 8px;
height: 8px;
border-radius: var(--radius-rounded);
background-color: var(--white);
}
}
```
## Structure
How Replicas assembles it on Base UI.
```tsx
import { Radio as BaseRadio } from "@base-ui/react/radio";
import { RadioGroup as BaseRadioGroup } from "@base-ui/react/radio-group";
const join = (base: string, extra?: string) => (extra ? `${base} ${extra}` : base);
function Root<Value>({ className, ...props }: Omit<BaseRadioGroup.Props<Value>, "className"> & { className?: string }) {
return <BaseRadioGroup className={join("ui-radio-group", className)} {...props} />;
}
function Item<Value>({ className, ...props }: Omit<BaseRadio.Root.Props<Value>, "className"> & { className?: string }) {
return (
<BaseRadio.Root className={join("ui-radio-group-item", className)} {...props}>
<BaseRadio.Indicator className="ui-radio-group-indicator" />
</BaseRadio.Root>
);
}
export const RadioGroup = {
Root,
Item,
};
```
## Example
```tsx
import { RadioGroup } from "@replicas/ui";
import { useId } from "react";
const orderings = [
{ value: "name", label: "Name" },
{ value: "updated", label: "Last updated" },
{ value: "created", label: "Created" },
{ value: "size", label: "Size" },
];
const label = { display: "flex", alignItems: "center", gap: 8, color: "var(--text-secondary)" };
export default function RadioGroupDemo() {
const id = useId();
return (
<RadioGroup.Root aria-labelledby={id} defaultValue="name">
<div id={id} style={{ fontWeight: "var(--font-weight-medium)" }}>
Sort by
</div>
{orderings.map((ordering) => (
<label key={ordering.value} style={label}>
<RadioGroup.Item value={ordering.value} />
{ordering.label}
</label>
))}
</RadioGroup.Root>
);
}
```
## Foundations
The rest of the Laravel Cloud style, as a skill: https://replicas.raphaelsalaja.com/skills/laravel/SKILL.md