Final Class Yiisoft\Bootstrap5\AccordionItem
| Inheritance | Yiisoft\Bootstrap5\AccordionItem |
|---|
AccordionItem represents a single collapsible item within an Accordion widget.
Each item consists of a header that can be clicked to show/hide the body content. The item can be set as active (expanded) by default and supports both raw and HTML content.
For example:
AccordionItem::to(
'Collapsible Group Item #1'
'Any sufficiently advanced technology is indistinguishable from magic.',
);
Public Methods
| Method | Description | Defined By |
|---|---|---|
| active() | Sets the active state. | Yiisoft\Bootstrap5\AccordionItem |
| body() | Sets the body content. | Yiisoft\Bootstrap5\AccordionItem |
| encodeBody() | Sets whether to encode the body content. | Yiisoft\Bootstrap5\AccordionItem |
| encodeHeader() | Sets whether to encode the header content. | Yiisoft\Bootstrap5\AccordionItem |
| getBody() | Yiisoft\Bootstrap5\AccordionItem | |
| getHeader() | Yiisoft\Bootstrap5\AccordionItem | |
| getId() | Returns the ID. | Yiisoft\Bootstrap5\AccordionItem |
| header() | Sets the header content. | Yiisoft\Bootstrap5\AccordionItem |
| id() | Sets the ID. | Yiisoft\Bootstrap5\AccordionItem |
| isActive() | Yiisoft\Bootstrap5\AccordionItem | |
| to() | Creates a new {@see AccordionItem} instance. | Yiisoft\Bootstrap5\AccordionItem |
Constants
| Constant | Value | Description | Defined By |
|---|---|---|---|
| DEFAULT_ID_PREFIX | 'collapse' | Yiisoft\Bootstrap5\AccordionItem |
Method Details
Sets the active state.
| public self active ( boolean $enabled ) | ||
| $enabled | boolean |
Whether the accordion item is active. |
| return | self |
A new instance with the specified active state. |
|---|---|---|
public function active(bool $enabled): self
{
$new = clone $this;
$new->active = $enabled;
return $new;
}
Sets the body content.
| public self body ( string $content ) | ||
| $content | string |
The body content. |
| return | self |
A new instance with the specified body content. |
|---|---|---|
public function body(string $content): self
{
$new = clone $this;
$new->body = $content;
return $new;
}
Sets whether to encode the body content.
| public self encodeBody ( boolean $enabled ) | ||
| $enabled | boolean |
Whether to encode the body content. |
| return | self |
A new instance with the specified encoding setting. |
|---|---|---|
public function encodeBody(bool $enabled): self
{
$new = clone $this;
$new->encodeBody = $enabled;
return $new;
}
Sets whether to encode the header content.
| public self encodeHeader ( boolean $enabled ) | ||
| $enabled | boolean |
Whether to encode the header content. |
| return | self |
A new instance with the specified encoding setting. |
|---|---|---|
public function encodeHeader(bool $enabled): self
{
$new = clone $this;
$new->encodeHeader = $enabled;
return $new;
}
| public string getBody ( ) | ||
| return | string |
The encoded body content. If {@see \Yiisoft\Bootstrap5\encodeBody} is |
|---|---|---|
public function getBody(): string
{
return $this->encodeBody ? Html::encode($this->body) : $this->body;
}
| public string getHeader ( ) | ||
| return | string |
The encoded header content. If {@see \Yiisoft\Bootstrap5\encodeHeader} is |
|---|---|---|
public function getHeader(): string
{
return $this->encodeHeader ? Html::encode($this->header) : $this->header;
}
Returns the ID.
| public boolean|string getId ( ) | ||
| return | boolean|string |
The ID. |
|---|---|---|
| throws | InvalidArgumentException |
If the "id" property is invalid. |
public function getId(): bool|string
{
return match ($this->id) {
true => Html::generateId(self::DEFAULT_ID_PREFIX . '-'),
'', false => throw new InvalidArgumentException('The "id" property must be a non-empty string or `true`.'),
default => $this->id,
};
}
Sets the header content.
| public self header ( string $content ) | ||
| $content | string |
The header content. |
| return | self |
A new instance with the specified header content. |
|---|---|---|
public function header(string $content): self
{
$new = clone $this;
$new->header = $content;
return $new;
}
Sets the ID.
| public self id ( boolean|string $id ) | ||
| $id | boolean|string |
The ID of the accordion item. If |
| return | self |
A new instance with the specified ID. |
|---|---|---|
| throws | InvalidArgumentException |
If the "id" property is empty or |
public function id(bool|string $id): self
{
if ($id === '' || $id === false) {
throw new InvalidArgumentException('The "id" property must be a non-empty string or `true`.');
}
$new = clone $this;
$new->id = $id;
return $new;
}
| public boolean isActive ( ) | ||
| return | boolean |
Whether the item is active. |
|---|---|---|
public function isActive(): bool
{
return $this->active;
}
Creates a new {@see AccordionItem} instance.
| public static self to ( string $header = '', string $body = '', boolean|string $id = true, boolean $encodeHeader = true, boolean $encodeBody = true, boolean $active = false ) | ||
| $header | string |
The header content. |
| $body | string |
The body content. |
| $id | boolean|string |
The ID of the accordion item. If |
| $encodeHeader | boolean |
Whether to encode the header content. |
| $encodeBody | boolean |
Whether to encode the body content. |
| $active | boolean |
Whether the item is active. |
| return | self |
A new instance with the specified configuration. |
|---|---|---|
public static function to(
string $header = '',
string $body = '',
bool|string $id = true,
bool $encodeHeader = true,
bool $encodeBody = true,
bool $active = false
): self {
return new self($active, $body, $encodeBody, $encodeHeader, $header, $id);
}
Signup or Login in order to comment.