Progress
Displays the status of a task that takes a long time.
<?phem
use Phem\Attribute\{Component, State};
use Phem\Node;
use Phem\Ui\Progress;
use function Phem\Ui\{ProgressIndicator, ProgressLabel, ProgressTrack, ProgressValue};
#[Component]
final class ProgressHeroDemo
{
#[State] public int $value = 20;
public function advance(): void
{
$this->value = min(100, $this->value + random_int(0, 25));
}
public function render(): Node
{
$bar = (
<Progress id="export" value={{ value }}>
<ProgressLabel>Export data</ProgressLabel>
<ProgressValue />
<ProgressTrack>
<ProgressIndicator />
</ProgressTrack>
</Progress>
);
return (
<div className="contents">
{% if value < 100 %}
<div className="contents" onPoll={{ advance }} phem:poll={{ 1000 }}>{{ bar }}</div>
{% else %}
<div className="contents">{{ bar }}</div>
{% endif %}
</div>
);
}
}
API reference#
Import the components of the family:
use Phem\Ui\Progress;
use function Phem\Ui\{ProgressLabel, ProgressValue, ProgressTrack, ProgressIndicator};Progress#
A progress bar: Base UI Progress.Root. A null value is an indeterminate progress.
All the parts get data-indeterminate, data-progressing or data-complete. Give an id to label the bar with its ProgressLabel.
The text of the value is the rounded percent (24%). The format options (style, currency, minimumFractionDigits, maximumFractionDigits) and the locale change it, as in Base UI: see ValueFormat. They need the intl extension of PHP.
| Prop | Type | Default |
|---|---|---|
value | ?float | null |
min | float | 0 |
max | float | 100 |
id | ?string | null |
format | array | [] |
locale | ?string | null |
children | ?Html | null |
...attrs | array | [] |
ProgressLabel#
The label of the progress bar. It names the progress bar (aria-labelledby).
| Prop | Type | Default |
|---|---|---|
children | ?Html | null |
...rest | mixed | — |
ProgressValue#
The text of the value. Its children replace the default text (a percent).
| Prop | Type | Default |
|---|---|---|
children | ?Html | null |
...rest | mixed | — |
ProgressTrack#
The bar of the progress: it holds the ProgressIndicator.
| Prop | Type | Default |
|---|---|---|
children | ?Html | null |
...rest | mixed | — |
ProgressIndicator#
The part of the track that shows the progress: its width is the percentage of the value.
| Prop | Type | Default |
|---|---|---|
...rest | mixed | — |
The source of the examples: examples/ui/Progress.phem.