-
Notifications
You must be signed in to change notification settings - Fork 0
/
Progress.php
101 lines (95 loc) · 2.23 KB
/
Progress.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
namespace pjkui\uikit;
use yii\base\InvalidConfigException;
use yii\helpers\Html;
/**
* Progress renders a UIkit progress bar component.
*
* For example,
*
* ```php
* // default with label
* echo Progress::widget([
* 'percent' => 60,
* 'label' => 'test',
* ]);
*
* // styled
* echo Progress::widget([
* 'percent' => 65,
* 'barOptions' => ['class' => 'uk-progress-success']
* ]);
*
* // striped
* echo Progress::widget([
* 'percent' => 70,
* 'options' => ['class' => 'uk-progress-striped']
* ]);
*
* // striped animated
* echo Progress::widget([
* 'percent' => 70,
* 'options' => ['class' => 'uk-progress-striped uk-active']
* ]);
*
* ```
* @see https://getuikit.com/docs/progress
* @author Quinn Pan <pjkui@qq.com>
* @since 3.0
*/
class Progress extends Widget
{
/**
* @var string the button label
*/
public $label;
/**
* @var integer the amount of progress as a percentage.
*/
public $percent = 0;
/**
* @var array the HTML attributes of the
*/
public $barOptions = [];
/**
* Initializes the widget.
* If you override this method, make sure you call the parent implementation first.
*/
public function init()
{
parent::init();
Html::addCssClass($this->options, 'uk-progress');
}
/**
* Renders the widget.
*/
public function run()
{
echo Html::beginTag('div', $this->options) . "\n";
echo $this->renderProgress() . "\n";
echo Html::endTag('div') . "\n";
UIkitAsset::register($this->getView());
}
/**
* Renders the progress.
* @return string the rendering result.
* @throws InvalidConfigException if the "percent" option is not set in a stacked progress bar.
*/
protected function renderProgress()
{
return $this->renderBar($this->percent, $this->label, $this->barOptions);
}
/**
* Generates a bar
* @param int $percent the percentage of the bar
* @param string $label, optional, the label to display at the bar
* @param array $options the HTML attributes of the bar
* @return string the rendering result.
*/
protected function renderBar($percent, $label = '', $options = [])
{
Html::addCssClass($options, 'uk-progress-bar');
$options['style'] = "width:{$percent}%";
return Html::tag('div', $label, $options);
}
}