You are here

protected function StyleBase::styleElement in GridStack 8.2

Return the style element.

2 calls to StyleBase::styleElement()
Color::colorElement in src/Plugin/gridstack/stylizer/Color.php
Provides extras form elements.
Range::rangeElement in src/Plugin/gridstack/stylizer/Range.php
Returns the range element.

File

src/Plugin/gridstack/stylizer/StyleBase.php, line 239

Class

StyleBase
Provides the base styles.

Namespace

Drupal\gridstack\Plugin\gridstack\stylizer

Code

protected function styleElement($key, $value, array $settings) {
  $context = $settings['_scope'];
  $range = in_array($key, GridStackDefault::rangeElements());
  $css = str_replace([
    '_',
    ':',
  ], '-', $key);
  $type = $key == 'rgba' ? 'hidden' : 'color';
  $type = $range ? 'range' : $type;
  $height = strpos($key, 'height') !== FALSE;
  $property = $key == 'bg' ? 'background-color' : 'color';
  $property = $range || $key == 'rgba' ? $key : $property;
  $title = $key == 'alpha' ? 'BG transparency' : $key;
  $title = $key == 'opacity' ? 'Image opacity' : $title;
  $title = $range ? $title : mb_strtoupper($title);
  $selector = $key !== 'text' && in_array($key, GridStackDefault::textElements()) ? $key : '';
  $selector = $key == 'opacity' ? '.b-gs' : $selector;
  $selector = $height ? '.is-gs-ete' : $selector;
  $group_type = $type == 'hidden' ? 'color' : $type;
  $group_css = $type;
  if (in_array($key, [
    'alpha',
    'opacity',
  ])) {
    $group_css = 'color';
  }
  $element = [
    '#type' => $type,
    '#title' => $this
      ->t('@title', [
      '@title' => $title,
    ]),
    '#default_value' => $range && empty($value) ? 1 : $value,
    '#attributes' => [
      'class' => [
        'form-' . $group_type . '--gs',
        'form-' . $group_type . '--gs-' . $css,
        'form-' . $group_type . '--gs-' . $context,
        'form-' . $group_type . '--gs-' . $group_css,
      ],
      'data-gs-color-picker' => $property,
      'data-gs-color-region' => $context,
      'data-gs-target-selector' => $selector,
    ],
  ];
  if ($height) {
    $element['#attributes']['class'][] = 'form-range--gs-height';
  }
  return $element;
}