# ProgressBar

> Represents a Progress bar: the single bar, or a segment of a stacked bar.

[API reference](/docs/api/index.md) › [Bootstrap 6](/docs/extensions/bootstrap6/reference/index.md) › [item](/docs/extensions/bootstrap6/reference/item/index.md) › ProgressBar

| final readonly class | `yii2\extensions\bootstrap6\item\ProgressBar` |
| --- | --- |
| Uses traits | [`ItemTrait`](/docs/extensions/bootstrap6/reference/item/itemtrait/index.md) |
| Source | [`src/item/ProgressBar.php`](https://github.com/yii2-extensions/bootstrap6/blob/main/src/item/ProgressBar.php#L23) |

Represents a `Progress` bar: the single bar, or a segment of a stacked bar.

The range of [`$percent`](/docs/extensions/bootstrap6/reference/item/progressbar/index.md#property-percent) depends on the widget `min` and `max`, so the widget validates it when rendering.

## Properties

| Property | Type | Description | Defined by |
| --- | --- | --- | --- |
| <span id="property-animated"></span>`$animated` readonly constructor | `bool` | Whether to animate the stripes (`progress-bar-animated`). Default: `false`. | `ProgressBar` |
| <span id="property-ariaLabel"></span>`$ariaLabel` readonly constructor | `string\|null` | Accessible name rendered as `aria-label`, or `null` to omit it. Default: `null`. | `ProgressBar` |
| <span id="property-label"></span>`$label` readonly constructor | `string\|`[`Stringable`](https://www.php.net/manual/en/class.stringable.php) | Content of the `.progress-bar` element. Default: `''`. | `ProgressBar` |
| <span id="property-options"></span>`$options` readonly constructor | `array<array-key, mixed>` | HTML attributes of the `.progress-bar` element. Default: `[]`. | `ProgressBar` |
| <span id="property-percent"></span>`$percent` readonly constructor | `float\|int` | Current value, between the widget `min` and `max`. | `ProgressBar` |
| <span id="property-striped"></span>`$striped` readonly constructor | `bool` | Whether to render stripes (`progress-bar-striped`). Default: `false`. | `ProgressBar` |
| <span id="property-theme"></span>`$theme` readonly constructor | [`yii2\extensions\bootstrap6\enum\Theme`](/docs/extensions/bootstrap6/reference/enum/theme/index.md)`\|string\|null` | Theme color rendered as the `theme-{value}` class, or `null` for the default. Default: `null`. | `ProgressBar` |

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`fromArray()`](#method-fromArray) static | Creates a bar from the array configuration documented in `Progress::$bars`. | `ProgressBar` |
| [`to()`](#method-to) static | Creates a bar. | `ProgressBar` |
| [`withAnimated()`](#method-withAnimated) | Returns a copy with the given stripe animation flag. | `ProgressBar` |
| [`withAriaLabel()`](#method-withAriaLabel) | Returns a copy with the given accessible name. | `ProgressBar` |
| [`withLabel()`](#method-withLabel) | Returns a copy with the given label. | `ProgressBar` |
| [`withOptions()`](#method-withOptions) | Returns a copy with the given `.progress-bar` attributes. | `ProgressBar` |
| [`withPercent()`](#method-withPercent) | Returns a copy with the given value. | `ProgressBar` |
| [`withStriped()`](#method-withStriped) | Returns a copy with the given stripes flag. | `ProgressBar` |
| [`withTheme()`](#method-withTheme) | Returns a copy with the given theme color. | `ProgressBar` |

## Method details

### fromArray() <span id="method-fromArray"></span>

```php
public static function fromArray(array<array-key, mixed> $config): self
```

Creates a bar from the array configuration documented in `Progress::$bars`.

Only `true` enables `striped` and `animated`; a `label`, `theme`, `ariaLabel`, or `options` of another type is
ignored.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$config` | `array<array-key, mixed>` | Bar configuration. |

**Returns**

`self`

**Throws**

- [`yii\base\InvalidConfigException`](/docs/api/yii/base/invalidconfigexception/index.md): if the bar has no `float|int` `percent`, or its `theme` is a `string` that is not a [`Theme`](/docs/extensions/bootstrap6/reference/enum/theme/index.md) value.

### to() <span id="method-to"></span>

```php
public static function to(float|int $percent, string|Stringable $label = ''): self
```

Creates a bar.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$percent` | `float\|int` | Current value, between the widget `min` and `max`. |
| `$label` | `string\|`[`Stringable`](https://www.php.net/manual/en/class.stringable.php) | Content of the `.progress-bar` element. |

**Returns**

`self`

### withAnimated() <span id="method-withAnimated"></span>

```php
public function withAnimated(bool $animated): self
```

Returns a copy with the given stripe animation flag.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$animated` | `bool` |  |

**Returns**

`self`

### withAriaLabel() <span id="method-withAriaLabel"></span>

```php
public function withAriaLabel(string|null $ariaLabel): self
```

Returns a copy with the given accessible name.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$ariaLabel` | `string\|null` |  |

**Returns**

`self`

### withLabel() <span id="method-withLabel"></span>

```php
public function withLabel(string|Stringable $label): self
```

Returns a copy with the given label.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$label` | `string\|`[`Stringable`](https://www.php.net/manual/en/class.stringable.php) |  |

**Returns**

`self`

### withOptions() <span id="method-withOptions"></span>

```php
public function withOptions(array<array-key, mixed> $options): self
```

Returns a copy with the given `.progress-bar` attributes.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$options` | `array<array-key, mixed>` | HTML attributes of the `.progress-bar` element. |

**Returns**

`self`

### withPercent() <span id="method-withPercent"></span>

```php
public function withPercent(float|int $percent): self
```

Returns a copy with the given value.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$percent` | `float\|int` |  |

**Returns**

`self`

### withStriped() <span id="method-withStriped"></span>

```php
public function withStriped(bool $striped): self
```

Returns a copy with the given stripes flag.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$striped` | `bool` |  |

**Returns**

`self`

### withTheme() <span id="method-withTheme"></span>

```php
public function withTheme(yii2\extensions\bootstrap6\enum\Theme|string|null $theme): self
```

Returns a copy with the given theme color.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$theme` | [`yii2\extensions\bootstrap6\enum\Theme`](/docs/extensions/bootstrap6/reference/enum/theme/index.md)`\|string\|null` |  |

**Returns**

`self`

**Throws**

- [`yii\base\InvalidConfigException`](/docs/api/yii/base/invalidconfigexception/index.md): if `$theme` is a `string` that is not a [`Theme`](/docs/extensions/bootstrap6/reference/enum/theme/index.md) value.