You are here

protected function Color::paletteElement in GridStack 8.2

Return the color palette element.

1 call to Color::paletteElement()
Form::closingForm in src/Plugin/gridstack/stylizer/Form.php

File

src/Plugin/gridstack/stylizer/Color.php, line 55

Class

Color
Provides the color styles.

Namespace

Drupal\gridstack\Plugin\gridstack\stylizer

Code

protected function paletteElement(array $palettes) {
  $element = [
    '#type' => 'details',
    '#open' => FALSE,
    '#tree' => TRUE,
    '#title' => $this
      ->t('Color palettes'),
    '#description' => $this
      ->t('Use these as guidelines to select colors from with the color pickers.'),
    '#attributes' => [
      'class' => [
        'form-wrapper--color-palettes',
      ],
    ],
    '#weight' => 50,
  ];
  $items = [];
  foreach ($palettes as $group => $colors) {
    $groups = [];
    foreach ($colors as $delta => $color) {
      $title = '';
      if ($delta == 0) {
        $title = '<h3>' . $group . '</h3>';
      }
      $groups[] = [
        '#type' => 'inline_template',
        '#template' => '{{ prefix | raw }}{{ color }}{{ suffix | raw }}',
        '#context' => [
          'color' => $color,
          'prefix' => $title . '<span class="gs-color" style="background-color: ' . $color . '">',
          'suffix' => '</span>',
        ],
      ];
    }
    $items[] = $groups;
  }
  $element['palettes'] = [
    '#theme' => 'item_list',
    '#items' => $items,
  ];
  return $element;
}