openrat-cms

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

GroupComponent.class.php (1998B)


      1 <?php
      2 
      3 namespace template_engine\components\html\component_group;
      4 
      5 use template_engine\components\html\Component;
      6 use template_engine\element\CMSElement;
      7 use template_engine\element\HtmlElement;
      8 use template_engine\element\Value;
      9 use template_engine\element\ValueExpression;
     10 
     11 /**
     12  * A group.
     13  */
     14 class GroupComponent extends Component
     15 {
     16 
     17 	public $open = true;
     18 	public $show = true;
     19 	public $collapsible = true;
     20 	public $title;
     21 	public $description;
     22 	public $icon;
     23 	
     24 	public function createElement()
     25 	{
     26 		$group = (new HtmlElement('section'))->addStyleClass('group');
     27 
     28 		if  ( $this->collapsible )
     29 			$group->addStyleClass('collapsible');
     30 
     31 		$headline = (new HtmlElement('h2'))
     32 			->addStyleClass('collapsible-title')
     33 			->addStyleClass('group-title')
     34 			->addStyleClass('collapsible-act-switch')
     35 			->asChildOf( $group );
     36 
     37 		if   ( $this->open || !$this->collapsible )
     38 			$group->addStyleClass(['collapsible--is-open','collapsible--is-visible']);
     39 
     40 		if   ( $this->show )
     41 			$group->addStyleClass('collapsible--show' );
     42 
     43 		if	( $this->title )
     44 		{
     45 
     46 			if   ( $this->collapsible ) {
     47 
     48 				$arrowRight = (new HtmlElement('i'))->addStyleClass(['image-icon','image-icon--node-closed','collapsible--on-closed']);
     49 				$headline->addChild($arrowRight );
     50 
     51 				$arrowDown  = (new HtmlElement('i'))->addStyleClass(['image-icon','image-icon--node-open','collapsible--on-open']);
     52 				$headline->addChild($arrowDown  );
     53 			}
     54 
     55 			if	( $this->icon ) {
     56 
     57 				$image = new CMSElement('i');
     58 				$image->addStyleClass(['image-icon','image-icon--'.$this->icon]);
     59 				$headline->addChild( $image );
     60 			}
     61 
     62 			(new HtmlElement('span'))->content( $this->title )->asChildOf($headline);
     63 		}
     64 
     65 		if   ( $this->description )
     66 			(new HtmlElement('p'))
     67 				->addStyleClass(['group-description'])
     68 				->content( $this->description )
     69 				->asChildOf($group);
     70 
     71 		$value = (new HtmlElement('div'))
     72 			->addStyleClass(['collapsible-value','group-value'])
     73 			->asChildOf($group);
     74 
     75 		$this->adoptiveElement = $value;
     76 
     77 		return $group;
     78 	}
     79 
     80 }