nur-sery/nur_src/v/bs3/fo/ControlCheckbox.php

55 lines
1.4 KiB
PHP

<?php
namespace nur\v\bs3\fo;
use nur\b\params\Tparametrable;
use nur\v\v;
class ControlCheckbox extends ControlVisual {
use Tparametrable;
const PARAMETRABLE_PARAMS_SCHEMA = [
"text" => ["?content", null, "libellé de la case à cocher"],
"checked" => ["?bool", null, "la case est-elle cochée?"],
"naked_label" => ["?bool", null, "faut-il retourner le bouton avec le label en mode naked?"]
];
/** @var array|string */
protected $ppText;
/** @var bool */
protected $ppChecked;
/** @var bool */
protected $ppNakedLabel;
function getControl(): array {
$name = $this->ppName;
$value = $this->ppValue;
$checked = $this->ppChecked;
$disabled = $this->ppDisabled;
$control = v::tag1("input", [
"type" => "checkbox",
"id" => $this->ppId,
"name" => $name,
"value" => $value,
"checked" => $checked? "checked": false,
"readonly" => $this->ppReadonly? "readonly": false,
"disabled" => $disabled ? "disabled": false,
"class" => $this->ppClass,
"style" => $this->ppStyle,
$this->ppAttrs,
]);
if ($this->ppNaked && !$this->ppNakedLabel) return $control;
$controlLabel = v::div([
"class" => ["checkbox", $disabled ? "disabled" : false],
v::tag("label", [
$control, "&nbsp;", q($this->ppText),
]),
]);
if ($this->ppNaked) return $controlLabel;
return $this->getFgsLayout($controlLabel);
}
}