]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - vendor/oojs/oojs-ui/php/mixins/IndicatorElement.php
MediaWiki 1.30.2
[autoinstallsdev/mediawiki.git] / vendor / oojs / oojs-ui / php / mixins / IndicatorElement.php
1 <?php
2
3 namespace OOUI;
4
5 /**
6  * Element containing an indicator.
7  *
8  * Indicators are graphics, smaller than normal text. They can be used to describe unique status or
9  * behavior. Indicators should only be used in exceptional cases; such as a button that opens a menu
10  * instead of performing an action directly, or an item in a list which has errors that need to be
11  * resolved.
12  *
13  * @abstract
14  */
15 trait IndicatorElement {
16         /**
17          * Symbolic indicator name
18          *
19          * @var string|null
20          */
21         protected $indicatorName = null;
22
23         /**
24          * @var Tag
25          */
26         protected $indicator;
27
28         /**
29          * @param array $config Configuration options
30          * @param string $config['indicator'] Symbolic indicator name
31          */
32         public function initializeIndicatorElement( array $config = [] ) {
33                 // Properties
34                 // FIXME 'indicatorElement' is a very stupid way to call '$indicator'
35                 $this->indicator = isset( $config['indicatorElement'] )
36                         ? $config['indicatorElement']
37                         : new Tag( 'span' );
38
39                 // Initialization
40                 $this->indicator->addClasses( [ 'oo-ui-indicatorElement-indicator' ] );
41                 $this->setIndicator( isset( $config['indicator'] ) ? $config['indicator'] : null );
42
43                 $this->registerConfigCallback( function ( &$config ) {
44                         if ( $this->indicatorName !== null ) {
45                                 $config['indicator'] = $this->indicatorName;
46                         }
47                 } );
48         }
49
50         /**
51          * Set indicator name.
52          *
53          * @param string|null $indicator Symbolic name of indicator to use or null for no indicator
54          * @return $this
55          */
56         public function setIndicator( $indicator = null ) {
57                 if ( $this->indicatorName !== null ) {
58                         $this->indicator->removeClasses( [ 'oo-ui-indicator-' . $this->indicatorName ] );
59                 }
60                 if ( $indicator !== null ) {
61                         $this->indicator->addClasses( [ 'oo-ui-indicator-' . $indicator ] );
62                 }
63
64                 $this->indicatorName = $indicator;
65                 $this->toggleClasses( [ 'oo-ui-indicatorElement' ], (bool)$this->indicatorName );
66
67                 return $this;
68         }
69
70         /**
71          * Get indicator name.
72          *
73          * @return string Symbolic name of indicator
74          */
75         public function getIndicator() {
76                 return $this->indicatorName;
77         }
78
79         /**
80          * Do not use outside of Theme::updateElementClasses
81          *
82          * @protected
83          * @return Tag
84          */
85         public function getIndicatorElement() {
86                 return $this->indicator;
87         }
88 }