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

58 lines
1.6 KiB
PHP
Raw Normal View History

2023-12-03 22:10:18 +04:00
<?php
namespace nur\v\bs3\fo;
use nur\b\params\Tparametrable;
use nur\v\v;
class ControlFile extends ControlVisualInput {
use Tparametrable;
const INPUT_TYPE = "file";
const PARAMETRABLE_PARAMS_SCHEMA = [
"accept" => ["?string", ".pdf,image/*", "types MIME acceptés"],
"btn_class" => ["?string", "btn-default", "Classe du bouton"],
"btn_style" => ["?string", null, "Style du bouton"],
"btn_label" => ["content", "Sélectionner un fichier", "Texte du bouton"],
];
function __construct(Form $form, ?array $params=null) {
parent::__construct($form, $params);
$this->ppPlaceholder = null;
}
function pp_setAccept(?string $accept) {
$this->ppAttrs["accept"] = $accept;
}
/** @var ?string */
protected $ppBtnClass;
/** @var string|array */
protected $ppBtnLabel;
function buildControl(): array {
$name = $this->ppName;
$value = $this->ppValue;
return v::tag("label", [
"class" => ["btn btn-file", $this->ppBtnClass],
v::tag1("input", [
"type" => static::INPUT_TYPE,
"id" => $this->ppId,
"name" => $name,
"value" => $value,
"readonly" => $this->ppReadonly? "readonly": false,
"disabled" => $this->ppDisabled? "disabled": false,
"required" => $this->ppRequired? "required": false,
"style" => "display: inline; visibility: hidden; width: 0px; height: 0px; vertical-align: middle;",
$this->ppAttrs,
]),
v::span([
"class" => ["file-label", $this->ppClass],
"style" => $this->ppStyle,
$this->ppBtnLabel,
]),
]);
}
}