Corex.RadioGroup
(Corex v0.1.0-alpha.29)
View Source
Phoenix implementation of Zag.js Radio Group.
Examples
Basic (without indicator)
<.radio_group id="rg" name="choice" items={[["1", "Option A"], ["2", "Option B"]]} class="radio-group">
<:label>Choose one</:label>
</.radio_group>With indicator
<.radio_group id="rg" name="choice" items={[["1", "Option A"], ["2", "Option B"]]} class="radio-group">
<:label>Choose one</:label>
<:item_control><.icon name="hero-check" class="data-checked" /></:item_control>
</.radio_group>Items can be a list of {value, label} tuples or a list of maps with :value, :label, and optional :disabled, :invalid. Optional :item_control slot renders the check indicator for each item; when omitted, no indicator is shown.
Styling
Use data attributes to target elements:
[data-scope="radio-group"][data-part="root"] {}
[data-scope="radio-group"][data-part="label"] {}
[data-scope="radio-group"][data-part="indicator"] {}
[data-scope="radio-group"][data-part="item"] {}
[data-scope="radio-group"][data-part="item-text"] {}
[data-scope="radio-group"][data-part="item-control"] {}
[data-scope="radio-group"][data-part="item-hidden-input"] {}If you wish to use the default Corex styling, you can use the class radio-group on the component.
This requires to install Mix.Tasks.Corex.Design first and import the component css file.
@import "../corex/main.css";
@import "../corex/tokens/themes/neo/light.css";
@import "../corex/components/radio-group.css";You can then use modifiers
<.radio_group class="radio-group radio-group--accent radio-group--lg" items={[]}>
</.radio_group>Learn more about modifiers and Corex Design
Summary
Components
Attributes
id(:string)value(:string) - Defaults tonil.default_value(:string) - Defaults tonil.controlled(:boolean) - Defaults tofalse.name(:string) - Defaults tonil.form(:string) - Defaults tonil.disabled(:boolean) - Defaults tofalse.invalid(:boolean) - Defaults tofalse.required(:boolean) - Defaults tofalse.read_only(:boolean) - Defaults tofalse.dir(:string) - Defaults tonil.Must be one ofnil,"ltr", or"rtl".orientation(:string) - Defaults to"vertical". Must be one of"horizontal", or"vertical".on_value_change(:string) - Defaults tonil.on_value_change_client(:string) - Defaults tonil.items(:list) (required) - List of [value, label] or %{value: ..., label: ..., disabled: ..., invalid: ...}.- Global attributes are accepted.
Slots
labelitem_controlitem