]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blobdiff - vendor/oojs/oojs-ui/php/mixins/IndicatorElement.php
MediaWiki 1.30.2
[autoinstallsdev/mediawiki.git] / vendor / oojs / oojs-ui / php / mixins / IndicatorElement.php
diff --git a/vendor/oojs/oojs-ui/php/mixins/IndicatorElement.php b/vendor/oojs/oojs-ui/php/mixins/IndicatorElement.php
new file mode 100644 (file)
index 0000000..61f31f7
--- /dev/null
@@ -0,0 +1,88 @@
+<?php
+
+namespace OOUI;
+
+/**
+ * Element containing an indicator.
+ *
+ * Indicators are graphics, smaller than normal text. They can be used to describe unique status or
+ * behavior. Indicators should only be used in exceptional cases; such as a button that opens a menu
+ * instead of performing an action directly, or an item in a list which has errors that need to be
+ * resolved.
+ *
+ * @abstract
+ */
+trait IndicatorElement {
+       /**
+        * Symbolic indicator name
+        *
+        * @var string|null
+        */
+       protected $indicatorName = null;
+
+       /**
+        * @var Tag
+        */
+       protected $indicator;
+
+       /**
+        * @param array $config Configuration options
+        * @param string $config['indicator'] Symbolic indicator name
+        */
+       public function initializeIndicatorElement( array $config = [] ) {
+               // Properties
+               // FIXME 'indicatorElement' is a very stupid way to call '$indicator'
+               $this->indicator = isset( $config['indicatorElement'] )
+                       ? $config['indicatorElement']
+                       : new Tag( 'span' );
+
+               // Initialization
+               $this->indicator->addClasses( [ 'oo-ui-indicatorElement-indicator' ] );
+               $this->setIndicator( isset( $config['indicator'] ) ? $config['indicator'] : null );
+
+               $this->registerConfigCallback( function ( &$config ) {
+                       if ( $this->indicatorName !== null ) {
+                               $config['indicator'] = $this->indicatorName;
+                       }
+               } );
+       }
+
+       /**
+        * Set indicator name.
+        *
+        * @param string|null $indicator Symbolic name of indicator to use or null for no indicator
+        * @return $this
+        */
+       public function setIndicator( $indicator = null ) {
+               if ( $this->indicatorName !== null ) {
+                       $this->indicator->removeClasses( [ 'oo-ui-indicator-' . $this->indicatorName ] );
+               }
+               if ( $indicator !== null ) {
+                       $this->indicator->addClasses( [ 'oo-ui-indicator-' . $indicator ] );
+               }
+
+               $this->indicatorName = $indicator;
+               $this->toggleClasses( [ 'oo-ui-indicatorElement' ], (bool)$this->indicatorName );
+
+               return $this;
+       }
+
+       /**
+        * Get indicator name.
+        *
+        * @return string Symbolic name of indicator
+        */
+       public function getIndicator() {
+               return $this->indicatorName;
+       }
+
+       /**
+        * Do not use outside of Theme::updateElementClasses
+        *
+        * @protected
+        * @return Tag
+        */
+       public function getIndicatorElement() {
+               return $this->indicator;
+       }
+}