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