* zin: refactor checkbox.

This commit is contained in:
dingyongliang
2023-02-20 13:16:20 +08:00
parent c0dbb4a5a6
commit 42ed5661d6
+13 -5
View File
@@ -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')
);
}