-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathButtonGroup.php
72 lines (61 loc) · 2.04 KB
/
ButtonGroup.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
<?php
namespace demogorgorn\uikit;
use Yii;
use yii\base\InvalidConfigException;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
/**
* ButtonGroup renders an UIKit component, which groups buttons.
*
* For example:
*
* ```php
* <?php ButtonGroup::begin([
* 'options' => ['class' => 'uk-margin-top'],
* ]); ?>
* <?= Html::a('Южная Америка', \yii\helpers\Url::toRoute(['country/mainland', 'alias' => 'south-america']), ['class' => 'uk-button uk-button-primary'] ) ?>
* <?= Html::a('Африка', \yii\helpers\Url::toRoute(['country/mainland', 'alias' => 'africa']), ['class' => 'uk-button uk-button-primary'] ) ?>
* <?= Html::a('Австралия', \yii\helpers\Url::toRoute(['country/mainland', 'alias' => 'australia']), ['class' => 'uk-button uk-button-primary'] ) ?>
* <?php ButtonGroup::end(); ?>
* ```
*
* @see http://www.getuikit.com/docs/button.html
*
* @author Oleg Martemjanov <[email protected]>
* @since 2.0
*/
class ButtonGroup extends Widget
{
/**
* @var bool toggle between a group of buttons like a checkbox.
*/
public $checkboxButtons = false;
/**
* @var bool toggle between a group of buttons, like radio buttons.
*/
public $radioButtons = false;
/**
* Initializes the widget.
*/
public function init()
{
parent::init();
Html::addCssClass($this->options, 'uk-button-group');
if ($this->checkboxButtons)
$this->options = array_merge(['data-uk-button-checkbox' => ''], $this->options);
if ($this->radioButtons)
if ($this->checkboxButtons)
throw new InvalidConfigException("Options 'checkboxButtons' and 'radioButtons' cannot be used at the same time.");
else
$this->options = array_merge(['data-uk-button-radio' => ''], $this->options);
echo Html::beginTag('div', $this->options) . "\n";
}
/**
* Renders the widget.
*/
public function run()
{
echo Html::endTag('div');
$this->registerAsset();
}
}