nur-sery/nur_src/v/bs3/vc/CListGroup.php

90 lines
1.9 KiB
PHP
Raw Normal View History

2023-12-03 22:10:18 +04:00
<?php
namespace nur\v\bs3\vc;
use nur\b\params\Tparametrable;
use nur\b\ValueException;
use nur\v\vo;
/**
* Class CListGroup: afficher une liste d'éléments
*/
class CListGroup extends _CItemList {
use Tparametrable;
const CONTAINER = null;
const PARAMETRABLE_PARAMS_SCHEMA = [
"container" => ["string", "ul", "container de la liste: ul ou div"],
];
function __construct(?iterable $items=null, ?array $params=null) {
self::set_parametrable_params_defaults($params, [
"container" => static::CONTAINER,
]);
parent::__construct($items, $params);
}
private $ctag, $itag;
function pp_setContainer(string $container): self {
switch ($container) {
case "ul":
$this->ctag = "ul";
$this->itag = "li";
break;
case "div":
$this->ctag = "div";
$this->itag = "a";
break;
default:
throw ValueException::invalid_value($container, "container");
}
return $this;
}
/** retourner le contenu associé au conteneur */
function container(): ?array {
return null;
}
protected function _printStartContainer($container): void {
vo::start($this->ctag, [
"class" => "list-group",
$this->container(),
]);
}
function printStartContainer(): void {
$this->_printStartContainer($this->container());
}
function printEndContainer(): void {
vo::end($this->ctag);
}
/** retourner le contenu associé à l'élément spécifié. */
function item($item): ?iterable {
return [$item];
}
protected function _printStartItem(): void {
vo::start($this->itag, [
"class" => "list-group-item",
]);
}
protected function _printEndItem(): void {
vo::end($this->itag);
}
protected function _printItem($item): void {
vo::tag($this->itag, [
"class" => "list-group-item",
$item,
], true);
}
function printItem($item): void {
$this->_printItem($this->item($item));
}
}