Final Class Yiisoft\Bootstrap5\Offcanvas
| Inheritance | Yiisoft\Bootstrap5\Offcanvas » Yiisoft\Widget\Widget |
|---|
Offcanvas renders a Bootstrap offcanvas component.
For example,
`php
<?= Offcanvas::widget()
->placement(OffcanvasPlacement::END)
->title('Offcanvas Title')
->togglerContent('Toggle Offcanvas')
->begin()
?>
// content of the offcanvas 'Offcanvas content here'
<?= Offcanvas::end ?>
`
Public Methods
Constants
| Constant | Value | Description | Defined By |
|---|---|---|---|
| BODY_CLASS | 'offcanvas-body' | Yiisoft\Bootstrap5\Offcanvas | |
| CLOSE_CLASS | 'btn-close' | Yiisoft\Bootstrap5\Offcanvas | |
| HEADER_CLASS | 'offcanvas-header' | Yiisoft\Bootstrap5\Offcanvas | |
| NAME | 'offcanvas' | Yiisoft\Bootstrap5\Offcanvas | |
| SHOW_CLASS | 'show' | Yiisoft\Bootstrap5\Offcanvas | |
| TITLE_CLASS | 'offcanvas-title' | Yiisoft\Bootstrap5\Offcanvas | |
| TOGGLER_CLASS | 'btn btn-primary' | Yiisoft\Bootstrap5\Offcanvas |
Method Details
Adds a set of attributes.
| public self addAttributes ( array $attributes ) | ||
| $attributes | array |
Attribute values indexed by attribute names. for example, |
| return | self |
A new instance with the specified attributes added. Example usage:
|
|---|---|---|
public function addAttributes(array $attributes): self
{
$new = clone $this;
$new->attributes = [...$this->attributes, ...$attributes];
return $new;
}
Adds one or more CSS classes to the existing classes.
Multiple classes can be added by passing them as separate arguments. null values are filtered out
automatically.
| public self addClass ( \BackedEnum|string|null $class ) | ||
| $class | \BackedEnum|string|null |
One or more CSS class names to add. Pass |
| return | self |
A new instance with the specified CSS classes added to existing ones. |
|---|---|---|
public function addClass(BackedEnum|string|null ...$class): self
{
$new = clone $this;
$new->cssClasses = [...$this->cssClasses, ...$class];
return $new;
}
Adds a CSS style.
| public self addCssStyle ( array|string $style, boolean $overwrite = true ) | ||
| $style | array|string |
The CSS style. If the value is an array, a space will separate the values.
For example, |
| $overwrite | boolean |
Whether to overwrite existing styles with the same name. If |
| return | self |
A new instance with the specified CSS style value added. Example usage:
// or
$offcanvas->addCssStyle(['color' => 'red', 'font-weight' => 'bold']);
|
|---|---|---|
public function addCssStyle(array|string $style, bool $overwrite = true): self
{
$new = clone $this;
Html::addCssStyle($new->attributes, $style, $overwrite);
return $new;
}
Adds toggler attribute value.
| public self addTogglerAttribute ( string $name, mixed $value ) | ||
| $name | string |
The attribute name. |
| $value | mixed |
The attribute value. |
| return | self |
A new instance with the specified attribute added. Example usage:
|
|---|---|---|
public function addTogglerAttribute(string $name, mixed $value): self
{
$new = clone $this;
$new->togglerAttributes[$name] = $value;
return $new;
}
Adds one or more CSS classes to the existing toggler classes.
Multiple classes can be added by passing them as separate arguments. null values are filtered out
automatically.
| public self addTogglerClass ( \BackedEnum|string|null $class ) | ||
| $class | \BackedEnum|string|null |
One or more CSS class names to add. Pass |
| return | self |
A new instance with the specified CSS classes added to existing ones. |
|---|---|---|
public function addTogglerClass(BackedEnum|string|null ...$class): self
{
$new = clone $this;
foreach ($class as $item) {
Html::addCssClass($new->togglerAttributes, $item);
}
return $new;
}
Adds a toggler CSS style.
| public self addTogglerCssStyle ( array|string $style, boolean $overwrite = true ) | ||
| $style | array|string |
The CSS style. If the value is an array, a space will separate the values.
for example, |
| $overwrite | boolean |
Whether to overwrite existing styles with the same name. If |
| return | self |
A new instance with the specified CSS style value added. Example usage:
// or
$offcanvas->addTogglerCssStyle(['color' => 'red', 'font-weight' => 'bold']);
|
|---|---|---|
public function addTogglerCssStyle(array|string $style, bool $overwrite = true): self
{
$new = clone $this;
Html::addCssStyle($new->togglerAttributes, $style, $overwrite);
return $new;
}
Adds a sets attribute value.
| public self attribute ( string $name, mixed $value ) | ||
| $name | string |
The attribute name. |
| $value | mixed |
The attribute value. |
| return | self |
A new instance with the specified attribute added. Example usage:
|
|---|---|---|
public function attribute(string $name, mixed $value): self
{
$new = clone $this;
$new->attributes[$name] = $value;
return $new;
}
Sets the HTML attributes.
| public self attributes ( array $attributes ) | ||
| $attributes | array |
Attribute values indexed by attribute names. |
| return | self |
A new instance with the specified attributes. |
|---|---|---|
public function attributes(array $attributes): self
{
$new = clone $this;
$new->attributes = $attributes;
return $new;
}
Sets whether to use a backdrop.
| public self backdrop ( ) | ||
| return | self |
A new instance with the specified backdrop setting. |
|---|---|---|
public function backdrop(): self
{
$new = clone $this;
$new->backdrop = true;
return $new;
}
Sets whether to use a static backdrop.
| public self backdropStatic ( ) | ||
| return | self |
A new instance with the specified static backdrop setting. |
|---|---|---|
public function backdropStatic(): self
{
$new = clone $this;
$new->backdropStatic = true;
return $new;
}
Begins the rendering.
| public string begin ( ) | ||
| return | string |
The opening HTML tags for the offcanvas. |
|---|---|---|
| throws | InvalidArgumentException |
if the tag is an empty string. |
public function begin(): string
{
parent::begin();
$id = $this->getId();
$html = '';
if ($this->toggler !== '' && $this->show === false) {
$html .= (string) $this->toggler . "\n";
}
if ($this->togglerContent !== '' && $this->show === false) {
$html .= $this->renderToggler($id) . "\n";
}
$html .= $this->renderOffcanvas($id);
return $html;
}
Sets the HTML attributes for the body.
| public self bodyAttributes ( array $attributes ) | ||
| $attributes | array |
Attribute values indexed by attribute names. |
| return | self |
A new instance with the specified body attributes. |
|---|---|---|
public function bodyAttributes(array $attributes): self
{
$new = clone $this;
$new->bodyAttributes = $attributes;
return $new;
}
Replaces all existing CSS classes with the specified one(s).
Multiple classes can be added by passing them as separate arguments. null values are filtered out
automatically.
| public self class ( \BackedEnum|string|null $class ) | ||
| $class | \BackedEnum|string|null |
One or more CSS class names to set. Pass |
| return | self |
A new instance with the specified CSS classes set. Example usage:
|
|---|---|---|
public function class(BackedEnum|string|null ...$class): self
{
$new = clone $this;
$new->cssClasses = $class;
return $new;
}
Sets the HTML attributes for the header.
| public self headerAttributes ( array $attributes ) | ||
| $attributes | array |
Attribute values indexed by attribute names. |
| return | self |
A new instance with the specified header attributes. |
|---|---|---|
public function headerAttributes(array $attributes): self
{
$new = clone $this;
$new->headerAttributes = $attributes;
return $new;
}
Sets the ID.
| public self id ( boolean|string $id ) | ||
| $id | boolean|string |
The ID of the component. If |
| return | self |
A new instance with the specified ID. Example usage:
|
|---|---|---|
| throws | InvalidArgumentException |
if the ID is an empty string or |
public function id(bool|string $id): self
{
$new = clone $this;
$new->id = $id;
return $new;
}
Sets the placement.
| public self placement ( \Yiisoft\Bootstrap5\OffcanvasPlacement $placement ) | ||
| $placement | \Yiisoft\Bootstrap5\OffcanvasPlacement |
The placement. |
| return | self |
A new instance with the specified placement setting. Example usage:
|
|---|---|---|
public function placement(OffcanvasPlacement $placement): self
{
$new = clone $this;
$new->placement = $placement;
return $new;
}
Run the widget.
| public string render ( ) | ||
| return | string |
The HTML representation of the element. |
|---|---|---|
public function render(): string
{
$html = Html::closeTag('div') . "\n";
$html .= Html::closeTag('div');
return $html;
}
Sets the responsive size.
| public self responsive ( \Yiisoft\Bootstrap5\Utility\Responsive $size ) | ||
| $size | \Yiisoft\Bootstrap5\Utility\Responsive |
The responsive size. |
| return | self |
A new instance with the specified responsive size setting. Example usage:
|
|---|---|---|
public function responsive(Responsive $size): self
{
$new = clone $this;
$new->responsive = $size->value;
return $new;
}
Sets whether it is scrollable.
| public self scrollable ( ) | ||
| return | self |
A new instance with the specified scrollable setting. |
|---|---|---|
public function scrollable(): self
{
$new = clone $this;
$new->scrollable = true;
return $new;
}
Sets whether it is visible.
| public self show ( ) | ||
| return | self |
A new instance with the specified visibility setting. Example usage:
|
|---|---|---|
public function show(): self
{
$new = clone $this;
$new->show = true;
return $new;
}
Sets the theme.
| public self theme ( string $theme ) | ||
| $theme | string |
The theme. If an empty string, the theme will be removed.
Valid values are |
| return | self |
A new instance with the specified theme. |
|---|---|---|
public function theme(string $theme): self
{
return $this->addAttributes(['data-bs-theme' => $theme === '' ? null : $theme]);
}
Sets the title.
| public self title ( string|\Stringable $title ) | ||
| $title | string|\Stringable |
The title. |
| return | self |
A new instance with the specified title. Example usage:
|
|---|---|---|
public function title(string|Stringable $title): self
{
$new = clone $this;
$new->title = $title;
return $new;
}
Sets the HTML attributes for the title.
| public self titleAttributes ( array $attributes ) | ||
| $attributes | array |
Attribute values indexed by attribute names. |
| return | self |
A new instance with the specified title attributes. |
|---|---|---|
public function titleAttributes(array $attributes): self
{
$new = clone $this;
$new->titleAttributes = $attributes;
return $new;
}
Sets the toggle button.
| public self toggler ( string|\Stringable $toggle ) | ||
| $toggle | string|\Stringable |
The toggle button. |
| return | self |
A new instance with the specified toggle button. Example usage:
// or
$offcanvas->toggler(Button::button('Toggle'));
|
|---|---|---|
public function toggler(string|Stringable $toggle): self
{
$new = clone $this;
$new->toggler = $toggle;
return $new;
}
Sets the HTML attributes for the toggler.
| public self togglerAttributes ( array $attributes ) | ||
| $attributes | array |
Attribute values indexed by attribute names. |
| return | self |
A new instance with the specified toggler attributes. |
|---|---|---|
public function togglerAttributes(array $attributes): self
{
$new = clone $this;
$new->togglerAttributes = $attributes;
return $new;
}
Sets the content of the toggler.
| public self togglerContent ( string|\Stringable $content ) | ||
| $content | string|\Stringable |
The content of the toggler. |
| return | self |
A new instance with the specified toggler content. Example usage:
|
|---|---|---|
public function togglerContent(string|Stringable $content): self
{
$new = clone $this;
$new->togglerContent = $content;
return $new;
}
Signup or Login in order to comment.