Control helpers
@codeui/solid v0.3.0
Reactive mappings for custom control compositions and entry metadata.
createSwitchProps
import { createSwitchProps, type SwitchProps } from "@codeui/solid";
import * as S from "@codeui/solid/switch/parts";
import { createSignal } from "solid-js";
export default function Demo() {
const [checked, setChecked] = createSignal(true);
const props = (): SwitchProps => ({
label: "Line numbers",
checked: checked(),
onChange: setChecked,
name: "lines",
value: "include",
});
const field = createSwitchProps(props);
return (
<S.Root {...field.root()}>
<S.Input {...field.input()} />
<S.Control>
<S.Thumb />
</S.Control>
<S.Label {...field.label()}>{props().label}</S.Label>
</S.Root>
);
}Import createSwitchProps from @codeui/solid. Its signature is createSwitchProps(props: Accessor<SwitchProps>). Call it once in your component and pass an accessor so later signal changes remain visible.
The result contains root, input, label, description, and errorMessage accessors. Spread each accessor result onto its matching styled part from @codeui/solid/switch/parts. Root retains checked state, callbacks, and form props. Input receives the derived ID, accessible name, and input class. Label receives its ID and for association. Message accessors supply IDs and classes.
Prop
Type
The helper renders no DOM and does not insert the control, thumb, or messages. inputId wins over the generated ID. A named checked input submits its value. An unchecked or disabled input submits no entry. The helper does not add a false-value input.
createSliderProps
import { createSliderProps, type SliderProps } from "@codeui/solid";
import * as S from "@codeui/solid/slider/parts";
import { createSignal } from "solid-js";
export default function Demo() {
const [value, setValue] = createSignal(75);
const props = (): SliderProps => ({
label: "Opacity",
value: value(),
onChange: setValue,
name: "opacity",
});
const field = createSliderProps(props);
return (
<S.Root {...field.root()}>
<S.Label {...field.label()}>Opacity</S.Label>
<S.Track>
<S.Fill />
<S.Thumb aria-label="Opacity">
<S.Input {...field.input()} />
</S.Thumb>
</S.Track>
</S.Root>
);
}Import createSliderProps from @codeui/solid. Its signature is createSliderProps(props: Accessor<SliderProps>). The return value contains root, input, label, description, and errorMessage accessors.
Root converts scalar value and defaultValue to one-element arrays. An undefined scalar stays undefined so Kobalte can manage uncontrolled state. The root callbacks forward the first array value to scalar onChange and onChangeEnd callbacks. Input receives a derived ID and type="hidden". Place Input inside Thumb so Kobalte can read its index and submit the value under the root name.
Prop
Type
The helper supplies props, not the ready Slider behavior. A custom composition owns the thumb accessible name, formatted aria-valuetext, invalid state, read-only interaction guards, and optional visible ValueLabel. Use the ready Slider when you need those behaviors without custom markup. Use styled Root directly for a range with multiple thumbs.
createOptionCardItems
import {
createOptionCardItems,
OptionCardGroup,
type OptionCardEntry,
} from "@codeui/solid";
import { createSignal } from "solid-js";
export default function Demo() {
const [entries] = createSignal<readonly OptionCardEntry[]>([
{ value: "png", label: "PNG", description: "Raster image" },
{ value: "svg", label: "SVG", description: "Vector image" },
]);
const options = createOptionCardItems(entries);
return (
<OptionCardGroup label="Export format" items={options.items()} defaultValue="png" />
);
}Import createOptionCardItems and OptionCardEntry from @codeui/solid. The signature is createOptionCardItems<T extends string>(items: Accessor<readonly OptionCardEntry<T>[]>).
The helper returns { items } with the original accessor. It does not copy, filter, or memoize entries. Read result.items() in JSX to preserve reactive updates. The string generic keeps selection values tied to your entry type. An empty array is valid and renders no choices.
Prop
Type
label, description, preview, and badge are JSX content. value and disabled control selection. The helper does not strip content or serialize entries. OptionCardGroup owns selection state and form inputs.
createAccordionItems
import { Accordion, createAccordionItems, type AccordionEntry } from "@codeui/solid";
import { createSignal, For } from "solid-js";
export default function Demo() {
const [entries] = createSignal<readonly AccordionEntry[]>([
{
value: "export",
title: "Export",
summary: "PNG",
content: "Export your snippet as a PNG image.",
},
]);
const metadata = createAccordionItems(entries);
return (
<>
<nav aria-label="Settings sections">
<For each={metadata()}>{entry => <span>{entry.title}</span>}</For>
</nav>
<Accordion items={entries()} defaultValue="export" />
</>
);
}Import createAccordionItems and AccordionEntry from @codeui/solid. Its signature is createAccordionItems(accessor: Accessor<readonly AccordionEntry[]>).
The result is a memoized accessor that removes content from each entry. It retains value, title, icon, summary, and disabled. Use the result for navigation or summaries. Pass the original entries to Accordion to render panels. Empty input produces an empty metadata array.
Prop
Type
Titles, icons, and summaries remain JSX values. This metadata is not a JSON serialization format. Replace the source signal array to trigger the memo. Mutating an entry in place does not notify Solid.
All four helpers run during server rendering and add no portals or client effects. Create them inside the component so generated field IDs and reactive state belong to that render tree. The styled controls own ARIA and keyboard behavior. The ready components remain the default for complete fields.