* zin: refactor checkbox.
This commit is contained in:
+13
-5
@@ -5,16 +5,24 @@ class checkbox extends wg
|
||||
{
|
||||
protected static $defineProps = 'text?:string,checked?:bool';
|
||||
|
||||
public function onAddChild($child)
|
||||
{
|
||||
if(is_string($child) && !$this->props->has('text'))
|
||||
{
|
||||
$this->props->set('text', $child);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
protected function build()
|
||||
{
|
||||
$input = h::checkbox(set($this->props->skip(array_keys(static::getDefinedProps()))));
|
||||
if($this->prop('checked')) $input->setProp('checked', true);
|
||||
|
||||
return h::label
|
||||
(
|
||||
setClass('checkbox'),
|
||||
h::checkbox
|
||||
(
|
||||
set('checked', $this->prop('checked')),
|
||||
set($this->props->skip(array_keys(static::getDefinedProps()))),
|
||||
),
|
||||
$input,
|
||||
$this->prop('text')
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user