|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Tabs block class. |
| 4 | + * |
| 5 | + * @package Creode Blocks |
| 6 | + */ |
| 7 | + |
| 8 | +namespace Creode_Blocks; |
| 9 | + |
| 10 | +/** |
| 11 | + * Tabs block class. |
| 12 | + * |
| 13 | + * @wordpress-block-version 2.6.0 |
| 14 | + */ |
| 15 | +class Tabs_Block extends Block { |
| 16 | + |
| 17 | + use Trait_Block_Pattern_Options; |
| 18 | + use Trait_Has_Reduce_Bottom_Space_Option; |
| 19 | + |
| 20 | + /** |
| 21 | + * The blocks icon from https://developer.wordpress.org/resource/dashicons/ or an inline SVG. |
| 22 | + * |
| 23 | + * @var string |
| 24 | + */ |
| 25 | + protected $icon = 'table-row-after'; |
| 26 | + |
| 27 | + /** |
| 28 | + * {@inheritdoc} |
| 29 | + */ |
| 30 | + protected function name(): string { |
| 31 | + return 'tabs'; |
| 32 | + } |
| 33 | + |
| 34 | + /** |
| 35 | + * {@inheritdoc} |
| 36 | + */ |
| 37 | + protected function label(): string { |
| 38 | + return 'Tabs'; |
| 39 | + } |
| 40 | + |
| 41 | + /** |
| 42 | + * {@inheritdoc} |
| 43 | + */ |
| 44 | + protected function additional_attributes(): array { |
| 45 | + return array( |
| 46 | + 'active_tab' => array( |
| 47 | + 'type' => 'number', |
| 48 | + 'default' => 0, |
| 49 | + ), |
| 50 | + 'patterns' => array( |
| 51 | + 'type' => 'string', |
| 52 | + 'default' => array(), |
| 53 | + ), |
| 54 | + ); |
| 55 | + } |
| 56 | + |
| 57 | + /** |
| 58 | + * {@inheritdoc} |
| 59 | + */ |
| 60 | + protected function child_blocks(): array { |
| 61 | + return array( |
| 62 | + new Child_Block( |
| 63 | + 'tab', |
| 64 | + 'Tab', |
| 65 | + array( |
| 66 | + array( |
| 67 | + 'key' => 'field_tabs_block_pattern', |
| 68 | + 'name' => 'pattern', |
| 69 | + 'label' => 'Pattern', |
| 70 | + 'type' => 'select', |
| 71 | + 'choices' => $this->get_block_pattern_choices(), |
| 72 | + ), |
| 73 | + ), |
| 74 | + __DIR__ . '/templates/tab.php', |
| 75 | + array(), |
| 76 | + '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24" context="list-view" aria-hidden="true" focusable="false"><path d="M19 6H6c-1.1 0-2 .9-2 2v9c0 1.1.9 2 2 2h13c1.1 0 2-.9 2-2V8c0-1.1-.9-2-2-2zM6 17.5c-.3 0-.5-.2-.5-.5V8c0-.3.2-.5.5-.5h3v10H6zm13.5-.5c0 .3-.2.5-.5.5h-3v-10h3c.3 0 .5.2.5.5v9z"></path></svg>', |
| 77 | + array( |
| 78 | + 'mode' => false, |
| 79 | + 'color' => array( |
| 80 | + 'text' => false, |
| 81 | + 'background' => true, |
| 82 | + ), |
| 83 | + ) |
| 84 | + ), |
| 85 | + ); |
| 86 | + } |
| 87 | + |
| 88 | + /** |
| 89 | + * {@inheritdoc} |
| 90 | + */ |
| 91 | + protected function template(): string { |
| 92 | + return __DIR__ . '/templates/block.php'; |
| 93 | + } |
| 94 | + |
| 95 | + /** |
| 96 | + * {@inheritdoc} |
| 97 | + */ |
| 98 | + protected function use_default_wrapper_template(): bool { |
| 99 | + return false; |
| 100 | + } |
| 101 | + |
| 102 | + /** |
| 103 | + * {@inheritdoc} |
| 104 | + */ |
| 105 | + protected function supports(): array { |
| 106 | + return array( |
| 107 | + 'mode' => false, |
| 108 | + 'color' => array( |
| 109 | + 'text' => false, |
| 110 | + 'background' => true, |
| 111 | + ), |
| 112 | + ); |
| 113 | + } |
| 114 | + |
| 115 | + /** |
| 116 | + * {@inheritdoc} |
| 117 | + */ |
| 118 | + protected function admin_scripts(): array { |
| 119 | + return array( |
| 120 | + new Script( |
| 121 | + 'tabs-block', |
| 122 | + plugin_dir_url( __FILE__ ) . 'assets/admin.js', |
| 123 | + array( 'jquery', 'admin-block-initializer', 'admin-block' ), |
| 124 | + '1.0.0' |
| 125 | + ), |
| 126 | + ); |
| 127 | + } |
| 128 | + |
| 129 | + /** |
| 130 | + * {@inheritdoc} |
| 131 | + */ |
| 132 | + protected function scripts(): array { |
| 133 | + return array( |
| 134 | + new Script( |
| 135 | + 'tabs-block', |
| 136 | + plugin_dir_url( __FILE__ ) . 'assets/tabs.js', |
| 137 | + array( 'jquery' ), |
| 138 | + '1.0.0' |
| 139 | + ), |
| 140 | + ); |
| 141 | + } |
| 142 | +} |
0 commit comments