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

101 lines
2.2 KiB
PHP

<?php
namespace nur\v\bs3\vc;
use Iterator;
use nur\A;
use nur\b\coll\BaseArray;
use nur\b\params\IParametrable;
use nur\b\params\Tparametrable;
use nur\b\params\Tparametrable1;
use nur\b\ValueException;
use nur\data\types\md_utils;
use nur\data\types\Metadata;
use nur\func;
use nur\iter;
use nur\v\base\ComponentPrintable;
use nur\v\vo;
use Traversable;
/**
* 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));
}
}