| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Widget; |
| 4 |
|
| 5 |
use MediaWiki\Html\Html; |
| 6 |
use Stringable; |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
class SpinnerWidget implements Stringable { |
| 18 |
|
| 19 |
|
| 20 |
private $attributes; |
| 21 |
|
| 22 |
private $content; |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
public function __construct( array $config = [] ) { |
| 28 |
$size = $config['size'] ?? 'small'; |
| 29 |
$type = $config['type'] ?? 'inline'; |
| 30 |
|
| 31 |
$this->attributes = []; |
| 32 |
|
| 33 |
if ( isset( $config['id'] ) ) { |
| 34 |
$this->attributes['id'] = $config['id']; |
| 35 |
} |
| 36 |
|
| 37 |
|
| 38 |
$this->attributes['class'] = [ |
| 39 |
'mw-spinner', |
| 40 |
$size === 'small' ? 'mw-spinner-small' : 'mw-spinner-large', |
| 41 |
$type === 'inline' ? 'mw-spinner-inline' : 'mw-spinner-block', |
| 42 |
]; |
| 43 |
|
| 44 |
$this->content = |
| 45 |
'<div class="mw-spinner-container">' . |
| 46 |
str_repeat( '<div></div>', 12 ) . |
| 47 |
'</div>'; |
| 48 |
} |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
public function toString() { |
| 55 |
return Html::rawElement( 'div', $this->attributes, $this->content ); |
| 56 |
} |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
public function __toString() { |
| 66 |
return $this->toString(); |
| 67 |
} |
| 68 |
} |