Skip to content

Commit ea4ab13

Browse files
author
Christoph Erdmann
committed
added Spinner & Progress
1 parent b5e1c3d commit ea4ab13

File tree

4 files changed

+186
-1
lines changed

4 files changed

+186
-1
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ The following widgets are currently available:
5858
* Fixed Action Button
5959
* DatePicker
6060
* Modal
61+
* Spinner
62+
* Progress
6163

6264
These widgets are planned for development:
6365

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"role": "Developer"
1313
}
1414
],
15-
"version": "1.0.1",
15+
"version": "1.0.2",
1616
"require": {
1717
"php": ">=5.4.0",
1818
"yiisoft/yii2": "~2.0",

src/widgets/Progress.php

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?php
2+
3+
namespace macgyer\yii2materializecss\widgets;
4+
5+
use macgyer\yii2materializecss\lib\BaseWidget;
6+
use macgyer\yii2materializecss\lib\Html;
7+
8+
/**
9+
* Class Progress
10+
* @package macgyer\yii2materializecss\widgets
11+
*/
12+
class Progress extends BaseWidget
13+
{
14+
/**
15+
* @var array the HTML attributes for the widget container tag
16+
*
17+
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
18+
*/
19+
public $options = [];
20+
21+
/**
22+
* @var array the HTML attributes for the progress tag
23+
*
24+
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
25+
*/
26+
public $progressOptions = [];
27+
28+
/**
29+
* @var string the type of the progress bar
30+
*
31+
* The following options are supported:
32+
*
33+
* - indeterminate (default)
34+
* - determinate
35+
*
36+
* @see http://materializecss.com/preloader.html
37+
*/
38+
public $type = 'indeterminate';
39+
40+
/**
41+
* @var int the (initial) value for 'determinate' progress bars
42+
*
43+
* The supported range is [0 ... 100].
44+
* This value will be applied as inline CSS style to show the progress:
45+
*
46+
* <div class="determinate" style="width: 70%"></div>
47+
*
48+
* @see http://materializecss.com/preloader.html
49+
*/
50+
public $value = 0;
51+
52+
/**
53+
* Initialize the widget.
54+
*/
55+
public function init()
56+
{
57+
parent::init();
58+
59+
Html::addCssClass($this->options, ['widget' => 'progress']);
60+
Html::addCssClass($this->progressOptions, ['type' => $this->type]);
61+
62+
if ($this->type === 'determinate') {
63+
Html::addCssStyle($this->progressOptions, ['width' => $this->value . '%']);
64+
}
65+
}
66+
67+
/**
68+
* Executes the widget.
69+
* @return string the result of widget execution to be outputted.
70+
*/
71+
public function run()
72+
{
73+
$html[] = Html::beginTag('div', $this->options);
74+
$html[] = Html::tag('div', null, $this->progressOptions);
75+
$html[] = Html::endTag('div');
76+
77+
return implode("\n", $html);
78+
}
79+
}

src/widgets/Spinner.php

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<?php
2+
3+
namespace macgyer\yii2materializecss\widgets;
4+
5+
use macgyer\yii2materializecss\lib\BaseWidget;
6+
use macgyer\yii2materializecss\lib\Html;
7+
8+
/**
9+
* Class Spinner
10+
* @package macgyer\yii2materializecss\widgets
11+
*/
12+
class Spinner extends BaseWidget
13+
{
14+
/**
15+
* @var array the HTML attributes for the widget container tag
16+
*
17+
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
18+
*/
19+
public $options = [];
20+
21+
/**
22+
* @var array the HTML attributes for the spinner
23+
*
24+
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
25+
*/
26+
public $spinnerOptions = [];
27+
28+
/**
29+
* @var bool whether to show alternating colors in spinner
30+
*
31+
* @see http://materializecss.com/preloader.html
32+
*/
33+
public $flashColors = false;
34+
35+
/**
36+
* @var array the colors alternating when $flashColors equals 'true'
37+
*/
38+
private $colors = [
39+
'blue',
40+
'red',
41+
'yellow',
42+
'green',
43+
];
44+
45+
/**
46+
* Initialize the widget.
47+
*/
48+
public function init()
49+
{
50+
parent::init();
51+
52+
Html::addCssClass($this->options, ['widget' => 'preloader-wrapper active']);
53+
Html::addCssClass($this->spinnerOptions, ['spinner' => 'spinner-layer']);
54+
}
55+
56+
/**
57+
* Executes the widget.
58+
* @return string the result of widget execution to be outputted.
59+
*/
60+
public function run()
61+
{
62+
$html[] = Html::beginTag('div', $this->options);
63+
64+
if ($this->flashColors !== false) {
65+
foreach ($this->colors as $color) {
66+
Html::addCssClass($this->spinnerOptions, ['color' => 'spinner-' . $color]);
67+
68+
$html[] = Html::beginTag('div', $this->spinnerOptions);
69+
$html[] = $this->renderSpinner();
70+
$html[] = Html::endTag('div');
71+
72+
Html::removeCssClass($this->spinnerOptions, ['color' => 'spinner-' . $color]);
73+
}
74+
} else {
75+
$html[] = Html::beginTag('div', $this->spinnerOptions);
76+
$html[] = $this->renderSpinner();
77+
$html[] = Html::endTag('div');
78+
}
79+
80+
$html[] = Html::endTag('div');
81+
82+
return implode("\n", $html);
83+
}
84+
85+
/**
86+
* @return string
87+
*/
88+
private function renderSpinner()
89+
{
90+
$html = [
91+
'<div class="circle-clipper left">',
92+
'<div class="circle"></div>',
93+
'</div>',
94+
'<div class="gap-patch">',
95+
'<div class="circle"></div>',
96+
'</div>',
97+
'<div class="circle-clipper right">',
98+
'<div class="circle"></div>',
99+
'</div>'
100+
];
101+
102+
return implode("\n", $html);
103+
}
104+
}

0 commit comments

Comments
 (0)