<div class="bux-radio">
    <fieldset id="bux-radio__radio-678774447" class="bux-radio__fieldset" aria-describedby="bux-radio__helper-text-678774447">

        <legend class="bux-radio__legend">
            Form Input Label
        </legend>

        <span class="bux-radio__helper-text" id="bux-radio__helper-text-678774447">
            Helper Text
        </span>

        <div class="bux-radio__input-spacer">

            <div class="bux-radio__option">
                <input type="radio" id="bux-radio__option-110324114" name="radio-button-default" />
                <label for="bux-radio__option-110324114">Item 1</label>
            </div>

            <div class="bux-radio__option">
                <input type="radio" id="bux-radio__option-2047947689" name="radio-button-default" />
                <label for="bux-radio__option-2047947689">Item 2</label>
            </div>

            <div class="bux-radio__option">
                <input type="radio" id="bux-radio__option-895785619" name="radio-button-default" />
                <label for="bux-radio__option-895785619">Item 3</label>
            </div>
        </div>
    </fieldset>
</div>
{# 

Radio Button

Available variables:

- required:         Boolean. Set to true to require form element.
- modifier:         Sets the variant of the form item.
                    Allowed values:
                        - null, error, disabled.
- legend:           String for the form legend.
- helper_text:      String for the form helper text.
- input_name:       String for the form element name. Optional.
- items:            Array containing the form items.
- item.text:        Display text for the form item.
- error_helper_text:Content for the error helper text.

#}

{% import 'forms/_macros/attributes.twig' as Attributes %}

{% set random_seed = random() %}
{% set form_element = 'radio' %}
{% set element_id = "bux-" ~ form_element ~ "__" ~ form_element ~ "-" ~ random_seed %}
{% set base_class = "bux-" ~ form_element ~ "__fieldset" %}
{% set modifier_class = modifier ? ' ' ~ base_class ~ "--" ~ modifier : '' %}

{% set aria_describedby = "bux-" ~ form_element ~ "__helper-text-" ~ random_seed %}

{% if modifier == 'error' %}
    {% set aria_error_describedby = 'error' ? "bux-" ~ form_element ~ "__error-message-" ~ random_seed %}
    {% set aria_describedby = aria_error_describedby ~ ' ' ~ aria_describedby %}
{% endif %}

{% set field = {
    form_element: form_element,
    element_id: element_id,
    descriptor: {
        tag: 'legend',
        text: legend
    },
    required: required,
    random_seed: random_seed,
    helper_text: helper_text,
    attributes: {
        id: element_id,
        class: base_class ~ modifier_class,
        'aria-describedby': helper_text ? aria_describedby: false,
        placeholder: placeholder_text,
        required: required ? true : false,
        disabled: modifier == 'disabled' ? true : false,
        'aria-invalid': modifier == 'error' ? true : false,
    },
    error_helper_text: error_helper_text
} %}

<div class="bux-{{ field.form_element }}">
    <fieldset {{ Attributes.render(field.attributes) }}>

        {% include '@descriptor' with field only %}

        {% if helper_text %}
            {% include '@helper' with field only %}
        {% endif %}

        {% if modifier == 'error' %}
            {% include '@error' with field only %}
        {% endif %}

        <div class="bux-{{ field.form_element }}__input-spacer">
            {% for item in items %}
                {% set item_random_seed = random() %}
                {% set item_base_class = "bux-%s__option"|format(field.form_element) %}
                {% set item_modifier_class = modifier ? " %s--%s"|format(item_base_class, modifier) : '' %}

                {% set item_attributes = {
                    type: "radio",
                    id: "bux-%s__option-%s"|format(field.form_element, item_random_seed),
                    name: input_name ?? field.attributes.id,
                } %}

                {% if field.is_disabled %}
                    {% set item_attributes = item_attributes|merge({disabled: true}) %}
                {% endif %}

                <div class="{{ item_base_class }}{{ item_modifier_class }}">
                    <input {{ Attributes.render(item_attributes) }} />
                    <label for="{{ item_attributes.id }}">{{ item.text }}</label>
                </div>
            {% endfor %}
        </div>
    </fieldset>
</div>
legend: Form Input Label
helper_text: Helper Text
input_name: radio-button-default
items:
  - text: Item 1
  - text: Item 2
  - text: Item 3
  • Content:
    .bux-radio {
      @include form-element;
    
      &__option {
        display: grid;
        grid-template-columns: 18px auto;
        gap: 8px;
    
        label {
          margin-top: 2px;
        }
    
        & + & {
          margin-top: $sp-8;
        }
    
        input[type="radio"] {
          appearance: none;
          background-color: #fff;
          margin: 0;
          font: inherit;
          color: $gray-dark-80;
          width: 20px;
          height: 20px;
          border: 2px solid $gray-dark-80;
          border-radius: 50%;
          transform: translateY(2.5px);
          display: grid;
          place-content: center;
    
          &:before {
            content: "";
            width: 10px;
            height: 10px;
            border-radius: 50%;
            transform: scale(0);
            transition: 120ms transform ease-in-out;
            background-color: $scarlet;
          }
    
          &:checked:before {
            transform: scale(1);
          }
    
          &:checked {
            border-color: $scarlet;
          }
          &:focus {
              outline: 2px solid $focus!important;
          }
        }
    
        &--disabled input[type="radio"] {
          border: 2px solid $gray-light-40;
          background-color: $gray-light-80;
        }
    
        &--disabled label {
          color: $gray-light-20;
        }
    
    
        &--error > input[type="radio"] {
          background: #ffeff2;
          border-color: $scarlet;
        }
      }
    
      &__error-message {
        @include form-error-message;
        margin-top: 5px;
      }
    }
    
  • URL: /components/raw/radio-button/_radio-button.scss
  • Filesystem Path: src/components/forms/radio-button/_radio-button.scss
  • Size: 1.4 KB

No notes defined.