-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathProgress.php
executable file
·125 lines (112 loc) · 3.5 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
/**
* @link https://github.com/MacGyer/yii2-materializecss
* @copyright Copyright (c) 2016 ... MacGyer for pluspunkt coding
* @license https://github.com/MacGyer/yii2-materializecss/blob/master/LICENSE
*/
namespace macgyer\yii2materializecss\widgets;
use macgyer\yii2materializecss\lib\BaseWidget;
use macgyer\yii2materializecss\lib\Html;
/**
* Progress renders a linear progress bar.
*
* Use this widget to give the user feedback about the loading of content or if you have actions that require multiple
* steps to complete.
*
* There are two types of progress bars available:
* - inderterminated with an animated recurring bar
* - determinated with a defined length
*
* For an indeterminated progress bar simply add the following
*
* ```php
* <?= Progress::widget() ?>
* ```
*
* To render an determinated progress bar with an initial value set [[value]] to the desired value and
* change [[type]] to "determinate"
*
* ```php
* <?= Progress::widget([
* 'type' => 'determinate',
* 'value' => 10
* ]) ?>
* ```
*
* @see Spinner|Spinner
* @author Christoph Erdmann <yii2-materializecss@pluspunkt-coding.de>
* @since 1.0.2
* @package widgets
*/
class Progress extends BaseWidget
{
/**
* Sets the [[type]] of the progress bar to 'determinate'.
*/
const TYPE_DETERMINATE = 'determinate';
/**
* Sets the [[type]] of the progress bar to 'indeterminate'. This is the default.
*/
const TYPE_INDETERMINATE = 'indeterminate';
/**
* @var array the HTML attributes for the widget container tag
*
* @see [yii\helpers\BaseHtml::renderTagAttributes()](http://www.yiiframework.com/doc-2.0/yii-helpers-basehtml.html#renderTagAttributes()-detail)
* for details on how attributes are being rendered.
*/
public $options = [];
/**
* @var array the HTML attributes for the progress tag.
*
* @see [yii\helpers\BaseHtml::renderTagAttributes()](http://www.yiiframework.com/doc-2.0/yii-helpers-basehtml.html#renderTagAttributes()-detail)
* for details on how attributes are being rendered.
*/
public $progressOptions = [];
/**
* @var string the type of the progress bar.
*
* The following options are supported:
*
* - indeterminate (default)
* - determinate
*
* @see https://materializecss.com/preloader.html
*/
public $type = self::TYPE_INDETERMINATE;
/**
* @var integer the (initial) value for 'determinate' progress bars.
*
* The supported range is [0 ... 100].
* This value will be applied as inline CSS style to show the progress:
*
* ```
* <div class="determinate" style="width: 70%"></div>
* ```
*
* @see https://materializecss.com/preloader.html
*/
public $value = 0;
/**
* Initializes the widget.
*/
public function init()
{
parent::init();
Html::addCssClass($this->options, ['widget' => 'progress']);
Html::addCssClass($this->progressOptions, ['type' => $this->type]);
if ($this->type === self::TYPE_DETERMINATE) {
Html::addCssStyle($this->progressOptions, ['width' => $this->value . '%']);
}
}
/**
* Executes the widget.
* @return string the result of widget execution to be outputted.
*/
public function run()
{
$html[] = Html::beginTag('div', $this->options);
$html[] = Html::tag('div', null, $this->progressOptions);
$html[] = Html::endTag('div');
return implode("\n", $html);
}
}