@@ -52,6 +52,7 @@ class BootstrapHtmlHelper extends HtmlHelper {
5252 'javascriptend ' => '</script> '
5353 ],
5454 'useFontAwesome ' => false ,
55+ 'progressTextFormat ' => '%d%% Complete ' ,
5556 'tooltip ' => [
5657 'placement ' => 'right '
5758 ],
@@ -266,53 +267,38 @@ public function tooltip($text, $tooltip, $options = []) {
266267 public function progress ($ widths , $ options = []) {
267268 $ options += [
268269 'striped ' => false ,
269- 'active ' => false
270+ 'active ' => false ,
271+ 'format ' => $ this ->config ('progressTextFormat ' )
270272 ];
271273 $ striped = $ options ['striped ' ];
272274 $ active = $ options ['active ' ];
273275 unset($ options ['active ' ], $ options ['striped ' ]) ;
274276 $ bars = '' ;
275- if (is_array ($ widths )) {
276- foreach ($ widths as $ width ) {
277- $ width += [
278- 'type ' => $ this ->config ('progress.type ' ),
279- 'min ' => 0 ,
280- 'max ' => 100 ,
281- 'display ' => false
282- ];
283- $ class = 'progress-bar progress-bar- ' .$ width ['type ' ];
284- $ bars .= $ this ->div ($ class ,
285- $ width ['display ' ] ? $ width ['width ' ].'% ' : '' ,
286- [
287- 'aria-valuenow ' => $ width ['width ' ],
288- 'aria-valuemin ' => $ width ['min ' ],
289- 'aria-valuemax ' => $ width ['max ' ],
290- 'role ' => 'progressbar ' ,
291- 'style ' => 'width: ' .$ width ['width ' ].'%; '
292- ]
293- );
294- }
277+ if (!is_array ($ widths )) {
278+ $ widths = [
279+ array_merge ([
280+ 'width ' => $ widths
281+ ], $ options )
282+ ];
295283 }
296- else {
297- $ options += [
284+ foreach ( $ widths as $ width ) {
285+ $ width += [
298286 'type ' => $ this ->config ('progress.type ' ),
299287 'min ' => 0 ,
300288 'max ' => 100 ,
301289 'display ' => false
302290 ];
303- $ class = 'progress-bar progress-bar- ' .$ options ['type ' ];
304- $ bars = $ this ->div ($ class ,
305- $ options ['display ' ] ? $ widths .'% ' : '' ,
306- [
307- 'aria-valuenow ' => $ widths ,
308- 'aria-valuemin ' => $ options ['min ' ],
309- 'aria-valuemax ' => $ options ['max ' ],
310- 'role ' => 'progressbar ' ,
311- 'style ' => 'width: ' .$ widths .'%; '
312- ]
313- );
314- unset($ options ['type ' ], $ options ['min ' ],
315- $ options ['max ' ], $ options ['display ' ]);
291+ $ class = 'progress-bar progress-bar- ' .$ width ['type ' ];
292+ $ content = $ this ->tag ('span ' , sprintf ($ options ['format ' ], $ width ['width ' ]), [
293+ 'class ' => $ width ['display ' ] ? '' : 'sr-only '
294+ ]);
295+ $ bars .= $ this ->div ($ class , $ content , [
296+ 'aria-valuenow ' => $ width ['width ' ],
297+ 'aria-valuemin ' => $ width ['min ' ],
298+ 'aria-valuemax ' => $ width ['max ' ],
299+ 'role ' => 'progressbar ' ,
300+ 'style ' => 'width: ' .$ width ['width ' ].'%; '
301+ ]);
316302 }
317303 $ options = $ this ->addClass ($ options , 'progress ' ) ;
318304 if ($ active ) {
@@ -322,7 +308,8 @@ public function progress ($widths, $options = []) {
322308 $ options = $ this ->addClass ($ options , 'progress-striped ' ) ;
323309 }
324310 $ classes = $ options ['class ' ];
325- unset($ options ['class ' ]) ;
311+ unset($ options ['class ' ], $ options ['active ' ], $ options ['type ' ],
312+ $ options ['striped ' ], $ options ['format ' ]) ;
326313 return $ this ->div ($ classes , $ bars , $ options ) ;
327314 }
328315
0 commit comments