From e23eaaeda2fe83a47d3a10fc75d96783369e462d Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Thu, 9 Jan 2014 03:44:53 +0400 Subject: [PATCH] Fixes #1820: Update Progress to use bootstrap 3 markup --- extensions/yii/bootstrap/CHANGELOG.md | 3 ++- extensions/yii/bootstrap/Progress.php | 37 ++++++++++++++++++++++++----------- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/extensions/yii/bootstrap/CHANGELOG.md b/extensions/yii/bootstrap/CHANGELOG.md index d6fbee3..58fc73d 100644 --- a/extensions/yii/bootstrap/CHANGELOG.md +++ b/extensions/yii/bootstrap/CHANGELOG.md @@ -7,7 +7,8 @@ Yii Framework 2 bootstrap extension Change Log - Enh #1474: Added option to make NavBar 100% width (cebe) - Enh #1553: Only add navbar-default class to NavBar when no other class is specified (cebe) - Enh #1601: Added support for tagName and encodeLabel parameters in ButtonDropdown (omnilight) -- Bug #1459: Update Collapse to use bootstrap 3 classes (tonydspaniard) +- Chg #1459: Update Collapse to use bootstrap 3 classes (tonydspaniard) +- Chg #1820: Update Progress to use bootstrap 3 markup (samdark) 2.0.0 alpha, December 1, 2013 ----------------------------- diff --git a/extensions/yii/bootstrap/Progress.php b/extensions/yii/bootstrap/Progress.php index 184451c..8f23a58 100644 --- a/extensions/yii/bootstrap/Progress.php +++ b/extensions/yii/bootstrap/Progress.php @@ -26,34 +26,35 @@ use yii\helpers\Html; * // styled * echo Progress::widget([ * 'percent' => 65, - * 'barOptions' => ['class' => 'bar-danger'] + * 'barOptions' => ['class' => 'progress-bar-danger'] * ]); * * // striped * echo Progress::widget([ * 'percent' => 70, - * 'barOptions' => ['class' => 'bar-warning'], + * 'barOptions' => ['class' => 'progress-bar-warning'], * 'options' => ['class' => 'progress-striped'] * ]); * * // striped animated * echo Progress::widget([ * 'percent' => 70, - * 'barOptions' => ['class' => 'bar-success'], + * 'barOptions' => ['class' => 'progress-bar-success'], * 'options' => ['class' => 'active progress-striped'] * ]); * * // stacked bars * echo Progress::widget([ * 'bars' => [ - * ['percent' => 30, 'options' => ['class' => 'bar-danger']], - * ['percent' => 30, 'label' => 'test', 'options' => ['class' => 'bar-success']], - * ['percent' => 35, 'options' => ['class' => 'bar-warning']], + * ['percent' => 30, 'options' => ['class' => 'progress-bar-danger']], + * ['percent' => 30, 'label' => 'test', 'options' => ['class' => 'progress-bar-success']], + * ['percent' => 35, 'options' => ['class' => 'progress-bar-warning']], * ] * ]); * ``` - * @see http://twitter.github.io/bootstrap/components.html#progress + * @see http://getbootstrap.com/components/#progress * @author Antonio Ramirez + * @author Alexander Makarov * @since 2.0 */ class Progress extends Widget @@ -67,7 +68,7 @@ class Progress extends Widget */ public $percent = 0; /** - * @var array the HTML attributes of the + * @var array the HTML attributes of the bar */ public $barOptions = []; /** @@ -139,8 +140,22 @@ class Progress extends Widget */ protected function renderBar($percent, $label = '', $options = []) { - Html::addCssClass($options, 'bar'); - $options['style'] = "width:{$percent}%"; - return Html::tag('div', $label, $options); + $defaultOptions = [ + 'role' => 'progressbar', + 'aria-valuenow' => $percent, + 'aria-valuemin' => 0, + 'aria-valuemax' => 100, + 'style' => "width:{$percent}%", + ]; + $options = array_merge($defaultOptions, $options); + Html::addCssClass($options, 'progress-bar'); + + $out = Html::beginTag('div', $options); + $out .= $label; + $out .= Html::tag('span', \Yii::t('yii', '{percent}% Complete', ['percent' => $percent]), [ + 'class' => 'sr-only' + ]); + $out .= Html::endTag('div'); + return $out; } }