Skip to content

Segmented Buttons #374

@cukabeka

Description

@cukabeka

Hi, ich wünsche mir als Alternative zu den Selectboxen oder den Radio/Checkboxen die Möglichkeit für Segmented Buttons, am besten inklusive icons. So ließen sich platzsparend und ohne tausende Klicks in den Selectboxen komplexe Interfaces stark vereinfachen und übersichtlicher machen.

Ich meine sowas (hier nur mit icon-platzhaltern):

Image

Ich dachte an so eine Verwendung:

$mform = new MForm();
$mform->addSegmentedButtonsField(1, 
    [
        'grid' => ['icon' => 'bi bi-grid', 'label' => 'Grid Layout'],
        'align' => ['icon' => 'bi bi-text-center', 'label' => 'Zentriert'],
        'spacing' => ['icon' => 'bi bi-arrows-expand', 'label' => 'Mit Spacing']
    ], 
    ['label' => 'Layout'],
    'horizontal'
);
echo $mform->show();

Und hier ein snippet, das vielleicht schon in die Richtung geht (funktioniert aber noch nicht, verstehe die Einbindung in MFORM nicht):

public function addSegmentedButtonsField(float|int|string $id, array $options = null, array $attributes = null, string $layout = 'horizontal', string $defaultValue = null): MForm
{
    $newOptions = [];

    foreach ($options as $key => $option) {
        if (is_array($option) && isset($option['label']) && isset($option['icon'])) {
            $newOptions[$key] = "<i class=\"{$option['icon']}\"></i><span> {$option['label']}</span>";
        }
    }

    // Layout-Option setzen (horizontal oder vertikal)
    $groupClass = ($layout === 'vertical') ? 'mform-inline-vertical' : 'mform-inline-horizontal';
    $attributes['form-group-class'] = 'mform-inline-segmented-buttons ' . $groupClass;

    $this->addOptionField('radio', $id, $attributes, $newOptions, $defaultValue);
    return $this;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions