| 1 |
<?php |
| 2 |
|
| 3 |
namespace OOUI; |
| 4 |
|
| 5 |
/** |
| 6 |
* TabSelectWidget is a list that contains TabOptionWidget options |
| 7 |
*/ |
| 8 |
class TabSelectWidget extends SelectWidget { |
| 9 |
use TabIndexedElement; |
| 10 |
|
| 11 |
/** @var bool */ |
| 12 |
protected $framed; |
| 13 |
|
| 14 |
/** |
| 15 |
* @param array $config Configuration options |
| 16 |
* - bool $config['framed'] Use framed tabs (default: true) |
| 17 |
*/ |
| 18 |
public function __construct( array $config = [] ) { |
| 19 |
parent::__construct( $config ); |
| 20 |
|
| 21 |
$this->initializeTabIndexedElement( array_merge( $config, [ 'tabIndexed' => $this ] ) ); |
| 22 |
|
| 23 |
$this->addClasses( [ 'oo-ui-tabSelectWidget' ] ); |
| 24 |
$this->toggleFramed( $config[ 'framed' ] ?? true ); |
| 25 |
$this->setAttributes( [ |
| 26 |
'role' => 'tablist' |
| 27 |
] ); |
| 28 |
} |
| 29 |
|
| 30 |
/** |
| 31 |
* Check if tabs are framed. |
| 32 |
* |
| 33 |
* @return bool Tabs are framed |
| 34 |
*/ |
| 35 |
public function isFramed() { |
| 36 |
return $this->framed; |
| 37 |
} |
| 38 |
|
| 39 |
/** |
| 40 |
* Render the tabs with or without frames. |
| 41 |
* |
| 42 |
* @param bool|null $framed Make tabs framed, omit to toggle |
| 43 |
* @return $this |
| 44 |
*/ |
| 45 |
public function toggleFramed( $framed = null ) { |
| 46 |
$this->framed = $framed !== null ? (bool)$framed : !$this->framed; |
| 47 |
$this->toggleClasses( [ 'oo-ui-tabSelectWidget-framed' ], $this->framed ); |
| 48 |
$this->toggleClasses( [ 'oo-ui-tabSelectWidget-frameless' ], !$this->framed ); |
| 49 |
return $this; |
| 50 |
} |
| 51 |
|
| 52 |
/** @inheritDoc */ |
| 53 |
public function getConfig( &$config ) { |
| 54 |
if ( $this->framed !== true ) { |
| 55 |
$config['framed'] = $this->framed; |
| 56 |
} |
| 57 |
return parent::getConfig( $config ); |
| 58 |
} |
| 59 |
} |