Skip to content

Commit

Permalink
Merge pull request #18 from deanblackborough/v0.65
Browse files Browse the repository at this point in the history
V0.65
  • Loading branch information
deanblackborough authored Oct 11, 2017
2 parents bab8d24 + 910ebe3 commit 4b877f4
Show file tree
Hide file tree
Showing 5 changed files with 325 additions and 89 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

Full changelog for Zend Framework 3 view helpers library.

## v0.65.0 - Base class - 2017-10-11

* Additional tests for Bootstrap 4 Progress bar view helper.
* Added a base class for Bootstrap 4 view helpers, Progress bar now extends it for base functionality.
* Minor changes to method names.

## v0.64.0 - Tests and Jumbotron - 2017-10-11

* Added tests for Bootstrap 4 Jumbotron view helper.
Expand Down
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ A collection of Zend Framework 3 view helpers, primarily focused on Bootstrap 3
* Bootstrap 4 Card component
* Bootstrap 4 Jumbotron component - [26 tests]
* Bootstrap 4 Navbar component (lite)
* Bootstrap 4 Progress bar component - [17 tests]
* Bootstrap 4 Progress bar component - [27 tests]
* Bootstrap 4 Multiple progress bar component

### Bootstrap 3
Expand Down Expand Up @@ -151,7 +151,7 @@ echo $this->bootstrap4NavbarLite()->

### Bootstrap 4 progress bar

Create a progress bar
Create a progress bar component.

##### Public methods

Expand All @@ -177,9 +177,10 @@ Create a progress bar with multiple bars
##### Public methods

* animate() - Animate the striped background style
* colors() - Set the background colors for the progress bar
* height() - Set the height of the progress bar
* label() - Set the label for the progress bar
* setBgStyle() - Set the background colour utility class
* setHeight() - Set the height of the progress bar
* setLabel() - Set the label to display in the progress bar
* setTextStyle() - Set the text colour utility class
* striped() - Enable the striped style for the progress bar background

#### Example
Expand Down
105 changes: 105 additions & 0 deletions src/Bootstrap4Helper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<?php

declare(strict_types=1);

namespace DBlackborough\Zf3ViewHelpers;

use Zend\View\Helper\AbstractHelper;

/**
* Generate a Bootstrap 4 progress bar
*
* @package DBlackborough\Zf3ViewHelpers
* @author Dean Blackborough <dean@g3d-development.com>
* @copyright Dean Blackborough
* @license https://github.com/deanblackborough/zf3-view-helpers/blob/master/LICENSE
*/
abstract class Bootstrap4Helper extends AbstractHelper
{
/**
* @var array Bootstrap styles
*/
protected $supported_bg_styles = [
'primary',
'secondary',
'success',
'danger',
'warning',
'info',
'light',
'dark',
'white'
];

/**
* @var array Bootstrap styles
*/
protected $supported_text_styles = [
'primary',
'secondary',
'success',
'danger',
'warning',
'info',
'light',
'dark'
];

/**
* @var string Assign an alternate background colour for the component
*/
protected $bg_color;

/**
* @var string Assign an alternate text colour for the component
*/
protected $text_color;

/**
* Override the __toString() method to allow echo/print of the view helper directly,
* saves a call to render()
*
* @return string
*/
public function __toString() : string
{
return $this->render();
}

/**
* Validate and assign the background colour, needs to be one of the following, primary, secondary, success,
* danger, warning, info, light, dark or white, if an incorrect style is passed in we don't apply the class.
*
* @param string $color
*/
protected function assignBgStyle(string $color)
{
if (in_array($color, $this->supported_bg_styles) === true) {
$this->bg_color = $color;
}
}

/**
* Validate and assign the text colour, need to be one of the following, primary, secondary, success, danger,
* warning, info, light or dark, if an incorrect style is passed in we don't apply the class.
*
* @param string $color
*/
protected function assignTextStyle(string $color)
{
if (in_array($color, $this->supported_text_styles) === true) {
$this->text_color = $color;
}
}

/**
* Worker method for the view helper, generates the HTML, the method is protected, called by __toString when
* echo or print are called on the view helper
*
* @return string
*/
protected function render() : string
{
return $this->__toString();
}
}
Loading

0 comments on commit 4b877f4

Please sign in to comment.