| 1 |
<?php if (! defined('ABSPATH')) exit; // Exit if accessed directly |
| 2 |
class HC3_Ui_Element_Labelled extends HC3_Ui_Abstract_Collection |
| 3 |
{ |
| 4 |
protected $htmlFactory = NULL; |
| 5 |
protected $label = NULL; |
| 6 |
protected $content = NULL; |
| 7 |
|
| 8 |
public function __construct( HC3_Ui $html, $label, $content, $labelFor = NULL ) |
| 9 |
{ |
| 10 |
$this->htmlFactory = $html; |
| 11 |
$this->label = $label; |
| 12 |
$this->content = $content; |
| 13 |
$this->labelFor = $labelFor; |
| 14 |
|
| 15 |
$this->add( $this->label ); |
| 16 |
$this->add( $this->content ); |
| 17 |
} |
| 18 |
|
| 19 |
public function renderFieldset() |
| 20 |
{ |
| 21 |
$label = $this->htmlFactory->makeElement( 'legend', $this->label ); |
| 22 |
$content = $this->htmlFactory->makeCollection( array($label, $this->content) ); |
| 23 |
|
| 24 |
$out = $this->htmlFactory->makeElement( 'fieldset', $content ) |
| 25 |
; |
| 26 |
|
| 27 |
return $out; |
| 28 |
} |
| 29 |
|
| 30 |
public function render() |
| 31 |
{ |
| 32 |
$label = $this->htmlFactory->makeElement('label', $this->label) |
| 33 |
// ->addAttr('class', 'hc-fs2') |
| 34 |
->addAttr('class', 'hc-bold') |
| 35 |
; |
| 36 |
|
| 37 |
if( strlen($this->labelFor) ){ |
| 38 |
$label |
| 39 |
->addAttr('for', $this->labelFor ) |
| 40 |
; |
| 41 |
} |
| 42 |
|
| 43 |
$out = $this->htmlFactory->makeList( array($label, $this->content) ) |
| 44 |
->gutter(1) |
| 45 |
; |
| 46 |
|
| 47 |
return $out; |
| 48 |
} |
| 49 |
} |