1<?php 2 3namespace OOUI; 4 5/** 6 * Layout that expands to cover the entire area of its parent, with optional scrolling and padding. 7 */ 8class PanelLayout extends Layout { 9 /** 10 * @param array $config Configuration options 11 * - bool $config['scrollable'] Allow vertical scrolling (default: false) 12 * - bool $config['padded'] Pad the content from the edges (default: false) 13 * - bool $config['expanded'] Expand size to fill the entire parent element 14 * (default: true) 15 * - bool $config['framed'] Wrap in a frame to visually separate from outside content 16 * (default: false) 17 * - bool $config['preserveContent'] Preserve DOM content when infusing (default: true) 18 */ 19 public function __construct( array $config = [] ) { 20 // Config initialization 21 $config = array_merge( [ 22 'scrollable' => false, 23 'padded' => false, 24 'expanded' => true, 25 'framed' => false, 26 ], $config ); 27 28 $this->preserveContent = $config['preserveContent'] ?? true; 29 30 // Parent constructor 31 parent::__construct( $config ); 32 33 // Initialization 34 $this->addClasses( [ 'oo-ui-panelLayout' ] ); 35 if ( $config['scrollable'] ) { 36 $this->addClasses( [ 'oo-ui-panelLayout-scrollable' ] ); 37 } 38 if ( $config['padded'] ) { 39 $this->addClasses( [ 'oo-ui-panelLayout-padded' ] ); 40 } 41 if ( $config['expanded'] ) { 42 $this->addClasses( [ 'oo-ui-panelLayout-expanded' ] ); 43 } 44 if ( $config['framed'] ) { 45 $this->addClasses( [ 'oo-ui-panelLayout-framed' ] ); 46 } 47 } 48 49 public function getConfig( &$config ) { 50 if ( !$this->preserveContent ) { 51 $config['preserveContent'] = false; 52 } 53 if ( $this->hasClass( 'oo-ui-panelLayout-scrollable' ) ) { 54 $config['scrollable'] = true; 55 } 56 if ( $this->hasClass( 'oo-ui-panelLayout-padded' ) ) { 57 $config['padded'] = true; 58 } 59 if ( !$this->hasClass( 'oo-ui-panelLayout-expanded' ) ) { 60 $config['expanded'] = false; 61 } 62 if ( $this->hasClass( 'oo-ui-panelLayout-framed' ) ) { 63 $config['framed'] = true; 64 } 65 return parent::getConfig( $config ); 66 } 67} 68