index.php
64 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Kubio\Blocks; |
| 4 | |
| 5 | use Kubio\Core\Blocks\BlockBase; |
| 6 | use Kubio\Core\Registry; |
| 7 | use Kubio\Core\Utils; |
| 8 | |
| 9 | |
| 10 | class DropDownMenuBlock extends BlockBase { |
| 11 | const BLOCK_NAME = 'kubio/dropdown-menu'; |
| 12 | |
| 13 | public function mapPropsToElements() { |
| 14 | |
| 15 | $effect = $this->getProp( 'hoverEffect.type' ) === 'none' ? false : $this->getProp( 'hoverEffect.type' ); |
| 16 | |
| 17 | $border_effect = $this->isLineEffect( $effect ) ? $this->getProp( 'hoverEffect.border.effect' ) : false; |
| 18 | |
| 19 | $background_effect = $this->isBackgroundEffect( $effect ) ? $this->getProp( 'hoverEffect.background.effect' ) : false; |
| 20 | |
| 21 | $effect_classes = array( $effect, $border_effect, $background_effect ); |
| 22 | $effect_classes = array_filter( |
| 23 | $effect_classes, |
| 24 | function ( $item ) { |
| 25 | return ! ! $item; |
| 26 | } |
| 27 | ); |
| 28 | |
| 29 | $jsProps = Utils::useJSComponentProps( 'dropdown-menu' ); |
| 30 | |
| 31 | return array( |
| 32 | 'outer' => array_merge( |
| 33 | $jsProps, |
| 34 | array( |
| 35 | 'className' => array_merge( |
| 36 | array( |
| 37 | 'kubio-dropdown-menu', |
| 38 | $this->getAttribute( 'showOffscreenMenuOn', 'has-offcanvas-mobile' ), |
| 39 | ), |
| 40 | $effect_classes |
| 41 | ), |
| 42 | ) |
| 43 | ), |
| 44 | ); |
| 45 | } |
| 46 | |
| 47 | private function isLineEffect( $effect ) { |
| 48 | return ( $effect && strpos( $effect, 'bordered-active-item' ) !== false ); |
| 49 | } |
| 50 | |
| 51 | private function isBackgroundEffect( $effect ) { |
| 52 | return ( $effect && strpos( $effect, 'solid-active-item' ) !== false ); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | |
| 57 | Registry::registerBlock( |
| 58 | __DIR__, |
| 59 | DropDownMenuBlock::class, |
| 60 | array( |
| 61 | 'metadata_mixins' => array( '../menu-items-block-json-partial.json' ), |
| 62 | ) |
| 63 | ); |
| 64 |