Browse Source

Fixes #1820: Update Progress to use bootstrap 3 markup

tags/2.0.0-beta
Alexander Makarov 11 years ago
parent
commit
e23eaaeda2
  1. 3
      extensions/yii/bootstrap/CHANGELOG.md
  2. 37
      extensions/yii/bootstrap/Progress.php

3
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 #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 #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) - 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 2.0.0 alpha, December 1, 2013
----------------------------- -----------------------------

37
extensions/yii/bootstrap/Progress.php

@ -26,34 +26,35 @@ use yii\helpers\Html;
* // styled * // styled
* echo Progress::widget([ * echo Progress::widget([
* 'percent' => 65, * 'percent' => 65,
* 'barOptions' => ['class' => 'bar-danger'] * 'barOptions' => ['class' => 'progress-bar-danger']
* ]); * ]);
* *
* // striped * // striped
* echo Progress::widget([ * echo Progress::widget([
* 'percent' => 70, * 'percent' => 70,
* 'barOptions' => ['class' => 'bar-warning'], * 'barOptions' => ['class' => 'progress-bar-warning'],
* 'options' => ['class' => 'progress-striped'] * 'options' => ['class' => 'progress-striped']
* ]); * ]);
* *
* // striped animated * // striped animated
* echo Progress::widget([ * echo Progress::widget([
* 'percent' => 70, * 'percent' => 70,
* 'barOptions' => ['class' => 'bar-success'], * 'barOptions' => ['class' => 'progress-bar-success'],
* 'options' => ['class' => 'active progress-striped'] * 'options' => ['class' => 'active progress-striped']
* ]); * ]);
* *
* // stacked bars * // stacked bars
* echo Progress::widget([ * echo Progress::widget([
* 'bars' => [ * 'bars' => [
* ['percent' => 30, 'options' => ['class' => 'bar-danger']], * ['percent' => 30, 'options' => ['class' => 'progress-bar-danger']],
* ['percent' => 30, 'label' => 'test', 'options' => ['class' => 'bar-success']], * ['percent' => 30, 'label' => 'test', 'options' => ['class' => 'progress-bar-success']],
* ['percent' => 35, 'options' => ['class' => 'bar-warning']], * ['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 <amigo.cobos@gmail.com> * @author Antonio Ramirez <amigo.cobos@gmail.com>
* @author Alexander Makarov <sam@rmcreative.ru>
* @since 2.0 * @since 2.0
*/ */
class Progress extends Widget class Progress extends Widget
@ -67,7 +68,7 @@ class Progress extends Widget
*/ */
public $percent = 0; public $percent = 0;
/** /**
* @var array the HTML attributes of the * @var array the HTML attributes of the bar
*/ */
public $barOptions = []; public $barOptions = [];
/** /**
@ -139,8 +140,22 @@ class Progress extends Widget
*/ */
protected function renderBar($percent, $label = '', $options = []) protected function renderBar($percent, $label = '', $options = [])
{ {
Html::addCssClass($options, 'bar'); $defaultOptions = [
$options['style'] = "width:{$percent}%"; 'role' => 'progressbar',
return Html::tag('div', $label, $options); '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;
} }
} }

Loading…
Cancel
Save