PluginProbe
Tableberg – Simple Gutenberg Table Block / trunk
Tableberg – Simple Gutenberg Table Block vtrunk
1.1.4 1.1.3 1.1.2 1.1.1 1.1.0 1.0.5 1.0.4 1.0.3 1.0.2 1.0.1 trunk 0.0.2 0.2.1 0.3.2 0.3.3 0.4.1 0.5.0 0.5.1 0.5.2 0.5.3 0.5.4 0.5.5 0.5.6 0.5.7 0.5.8 All 41 releases
tableberg / renderer / ToggleBlockRenderer.php

ToggleBlockRenderer.php in Tableberg – Simple Gutenberg Table Block trunk, at renderer/ToggleBlockRenderer.php

71 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Tableberg\Renderer;
4
5 class ToggleBlockRenderer {
6 private function get_css_variable_from_spacing_preset($value) {
7 if (!$value || !is_string($value)) {
8 return $value;
9 }
10 if ('0' === $value) {
11 return $value;
12 }
13 if (strpos($value, 'var:preset|spacing|') !== 0) {
14 return $value;
15 }
16 $matches = [];
17 preg_match('/var:preset\|spacing\|(.+)/', $value, $matches);
18 if (empty($matches)) {
19 return $value;
20 }
21 return "var(--wp--preset--spacing--{$matches[1]})";
22 }
23
24 public function render($attributes, $content) {
25 $alignment_class = isset($attributes['alignment']) ? $attributes['alignment'] : 'left';
26 $gap = isset($attributes['gap']) ? $this->get_css_variable_from_spacing_preset($attributes['gap']) : '0';
27 $border_radius = isset($attributes['tabBorderRadius']) ? $this->get_css_variable_from_spacing_preset($attributes['tabBorderRadius']) : '0';
28 $active_background = isset($attributes['activeTabBackgroundColor']) ? $attributes['activeTabBackgroundColor'] : '#ffffff';
29 $inactive_background = isset($attributes['inactiveTabBackgroundColor']) ? $attributes['inactiveTabBackgroundColor'] : '#f0f0f0';
30 $active_text = isset($attributes['activeTabTextColor']) ? $attributes['activeTabTextColor'] : '#ffffff';
31 $inactive_text = isset($attributes['inactiveTabTextColor']) ? $attributes['inactiveTabTextColor'] : '#333333';
32
33 $output = '<div
34 class="tab-block"
35 data-active-background-color="' . \esc_attr($active_background) . '"
36 data-active-color="' . \esc_attr($active_text) . '"
37 data-background-color="' . \esc_attr($inactive_background) . '"
38 data-color="' . \esc_attr($inactive_text) . '"
39 >';
40 $output .= '<nav
41 class="tab-headings ' . \esc_attr($alignment_class) . '"
42 style="margin-bottom: ' . \esc_attr($gap) . ';"
43 >';
44
45 $default_active_tab_index = isset($attributes['defaultActiveTabIndex']) ? $attributes['defaultActiveTabIndex'] : 0;
46 $tabs = isset($attributes['tabs']) && is_array($attributes['tabs']) ? $attributes['tabs'] : [];
47
48 foreach ($tabs as $index => $title) {
49 $active_class = ((int) $index === (int) $default_active_tab_index) ? 'active' : '';
50
51 $output .= '<div
52 class="tab-heading ' . \esc_attr($active_class) . '"
53 data-index="' . \esc_attr($index) . '"
54 style="border-radius: ' . \esc_attr($border_radius) . ';"
55 >
56 <p>' . \esc_html($title) . '</p>
57 </div>';
58 }
59
60 $output .= '</nav>';
61
62 $output .= '<div class="tab-content" style="display:block;">';
63 $output .= $content;
64 $output .= '</div>';
65
66 $output .= '</div>';
67
68 return $output;
69 }
70 }
71