Final Class Yiisoft\Bootstrap5\Progress
| Inheritance | Yiisoft\Bootstrap5\Progress » Yiisoft\Widget\Widget |
|---|
Progress renders a bootstrap progress bar component.
For example,
<?= Progress::widget()->percent(60) ?>
//
<?= Progress::widget()
->backgroundColor(BackgroundColor::SUCCESS)
->percent(60)
->variant(ProgressVariant::ANIMATED_STRIPED)
?>
Public Methods
Constants
| Constant | Value | Description | Defined By |
|---|---|---|---|
| NAME | 'progress' | Yiisoft\Bootstrap5\Progress | |
| PROGRESS_BAR | 'progress-bar' | Yiisoft\Bootstrap5\Progress |
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 for the bar.
| public self addBarClass ( \BackedEnum|string|null $class ) | ||
| $class | \BackedEnum|string|null |
One or more CSS class names to add to the bar. Pass |
| return | self |
A new instance with the specified CSS classes added to the bar. Example usage:
|
|---|---|---|
public function addBarClass(BackedEnum|string|null ...$class): self
{
$new = clone $this;
$new->barClasses = [...$this->barClasses, ...$class];
return $new;
}
Adds one or more CSS classes to the existing classes.
| 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
$progress->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;
}
Sets the ARIA label.
| public self ariaLabel ( string $label ) | ||
| $label | string |
The ARIA label. |
| return | self |
A new instance with the specified ARIA label. |
|---|---|---|
public function ariaLabel(string $label): self
{
return $this->attribute('aria-label', $label);
}
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 set. 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 the background color of the bar.
| public self backgroundColor ( \Yiisoft\Bootstrap5\Utility\BackgroundColor $color ) | ||
| $color | \Yiisoft\Bootstrap5\Utility\BackgroundColor |
The background color class to apply to the bar. |
| return | self |
A new instance with the specified background color applied. |
|---|---|---|
public function backgroundColor(BackgroundColor $color): self
{
return $this->addBarClass($color);
}
Sets the HTML attributes for the bar.
| public self barAttributes ( array $attributes ) | ||
| $attributes | array |
Attribute values indexed by attribute names. |
| return | self |
A new instance with the specified attributes for the bar. |
|---|---|---|
public function barAttributes(array $attributes): self
{
$new = clone $this;
$new->barAttributes = $attributes;
return $new;
}
Replaces all existing CSS classes with the specified one(s).
| 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 content.
| public self content ( string $content ) | ||
| $content | string |
The content to be displayed in the bar. |
| return | self |
A new instance with the specified content. Example usage:
|
|---|---|---|
public function content(string $content): self
{
$new = clone $this;
$new->content = $content;
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:
|
|---|---|---|
public function id(bool|string $id): self
{
$new = clone $this;
$new->id = $id;
return $new;
}
Sets the maximum value.
| public self max ( float|integer $max ) | ||
| $max | float|integer |
The maximum value. This value is used to calculate the progress percentage. |
| return | self |
A new instance with the specified maximum value. Example usage:
|
|---|---|---|
public function max(int|float $max): self
{
$new = clone $this;
$new->max = $max;
return $new;
}
Sets the minimum value.
| public self min ( float|integer $min ) | ||
| $min | float|integer |
The minimum value. This value is used to calculate the progress percentage. |
| return | self |
A new instance with the specified minimum value. Example usage:
|
|---|---|---|
public function min(int|float $min): self
{
$new = clone $this;
$new->min = $min;
return $new;
}
Sets the percentage value for the bar.
| public self percent ( float|integer $percent ) | ||
| $percent | float|integer |
The percentage value. Must be greater than or equal to 0. |
| return | self |
A new instance with the specified percentage value. Example usage:
|
|---|---|---|
| throws | LogicException |
When percentage value is less than 0. |
public function percent(int|float $percent): self
{
if ($percent < 0) {
throw new LogicException(
sprintf('"$percent" must be positive. %d given', $percent)
);
}
$new = clone $this;
$new->percent = $percent;
return $new;
}
Run the widget.
| public string render ( ) | ||
| return | string |
The HTML representation of the element. |
|---|---|---|
public function render(): string
{
$attributes = $this->attributes;
$classes = $attributes['class'] ?? null;
unset($attributes['class']);
if ($this->stacked) {
$attributes['style'] = 'width: ' . $this->percent . '%';
}
return Div::tag()
->attributes($attributes)
->addClass(
self::NAME,
...$this->cssClasses,
)
->addClass($classes)
->attribute('role', 'progressbar')
->attribute('aria-valuenow', $this->percent)
->attribute('aria-valuemin', $this->min)
->attribute('aria-valuemax', $this->max)
->content(
"\n",
$this->renderBar(),
"\n",
)
->id($this->getId())
->encode(false)
->render();
}
Sets the sizing variant.
| public self sizing ( \Yiisoft\Bootstrap5\Utility\Sizing $size ) | ||
| $size | \Yiisoft\Bootstrap5\Utility\Sizing |
The sizing variant to apply. This affects the width class of the bar. |
| return | self |
A new instance with the specified sizing variant. Example usage:
|
|---|---|---|
public function sizing(Sizing $size): self
{
$new = clone $this;
$new->sizing = true;
return $new->addBarClass($size);
}
Sets the bar to be stacked.
| public self stacked ( ) | ||
| return | self |
A new instance with the bar stacked. Example usage:
|
|---|---|---|
public function stacked(): self
{
$new = clone $this;
$new->stacked = true;
return $new;
}
Sets the variant.
| public self variant ( \Yiisoft\Bootstrap5\ProgressVariant $variant ) | ||
| $variant | \Yiisoft\Bootstrap5\ProgressVariant |
The variant to apply to the progress bar. |
| return | self |
A new instance with the specified variant. Example usage:
|
|---|---|---|
public function variant(ProgressVariant $variant): self
{
return $this->addBarClass($variant);
}
Signup or Login in order to comment.