forked from YL20181120/yii2-dwz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Button.php
38 lines (34 loc) · 858 Bytes
/
Button.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
<?php
namespace yii\dwz;
use yii\helpers\Html;
use \yii\base\InvalidParamException;
/**
*
*/
class Button extends Widget
{
public $content = 'Button';
public $buttonOptions = [];
public $type = 'button';
public $_TYPE = ['button','active','disabled'];
public function init(){
if(!in_array($this->type, $this->_TYPE))
throw new InvalidParamException("Param type must in range '".implode(' ', $this->_TYPE)."'",1);
}
public function run(){
switch ($this->type) {
case 'active':
$this->options['class'] = 'buttonActive';
break;
case 'disabled':
$this->options['class'] = 'buttonDisabled';
break;
default:
$this->options['class'] = 'button';
break;
}
return Html::tag('div',Html::tag('div',
Html::tag('button',$this->content,$this->buttonOptions)
,['class'=>'buttonContent']),$this->options);
}
}