Skip to content

Commit

Permalink
Merge pull request #19 from deanblackborough/v0.66.0
Browse files Browse the repository at this point in the history
V0.66.0
  • Loading branch information
deanblackborough authored Oct 11, 2017
2 parents 4b877f4 + 738a126 commit 62f18df
Show file tree
Hide file tree
Showing 11 changed files with 537 additions and 383 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

Full changelog for Zend Framework 3 view helpers library.

## v0.66.0 - Minor updates

* Updated Bootstrap 4 jumbotron view helper, extends Bootstrap4Helper
* Updated Bootstrap 4 multiple progress bar view helper, extends Bootstrap4Helper
* Updated Bootstrap 4 badge view helper, extends Bootstrap4Helper
* Updated Bootstrap 4 button view helper, extends Bootstrap4Helper
* Added combined tests to view helpers
* Corrected README

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

* Additional tests for Bootstrap 4 Progress bar view helper.
Expand Down
68 changes: 43 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ A collection of Zend Framework 3 view helpers, primarily focused on Bootstrap 3

### Bootstrap 4

* Bootstrap 4 Badge component - [12 tests]
* Bootstrap 4 Badge component - [13 tests]
* Bootstrap 4 Button component - [31 tests]
* Bootstrap 4 Card component
* Bootstrap 4 Jumbotron component - [26 tests]
* Bootstrap 4 Jumbotron component - [27 tests]
* Bootstrap 4 Navbar component (lite)
* Bootstrap 4 Progress bar component - [27 tests]
* Bootstrap 4 Multiple progress bar component
* Bootstrap 4 Progress bar component - [28 tests]
* Bootstrap 4 Multiple progress bar component - [4 tests]

### Bootstrap 3

Expand Down Expand Up @@ -48,29 +48,49 @@ alternatively include the classes in src/ in your library.

Below is an overview of the more complex view helpers.

### Bootstrap 4 Badge

Create a Bootstrap 4 badge component

##### Public methods:

* asLink() - Display as a link
* pill() - Use the pill style
* setBgStyle() - Set the background colour utility class
* setTextStyle() - Set the text colour utility class

##### Example

```
echo $this->bootstrap4Badge($badge)->
pill()->
setBgStyle('primary');
```

### Bootstrap 4 Button

Create a Bootstrap 4 button
Create a Bootstrap 4 button component

##### Public methods:

* active() - Set button as active
* block() - Add display block style
* customClass() - Add a custom class
* disabled() - Set button as disabled
* large() - Add large class
* link() - Add URI/URL for default button type
* setBgStyle() - Set the background colour utility class
* setTextStyle() - Set the text colour utility class
* setModeButton() - Render as a button, not an anchor
* setModeInput() - Render as an input, not an anchor
* setOutlineStyle() - Set btn-outline-* style
* setStyle() - Set btn-* style
* small() - Add small class
* customClass() - Add a custom class

##### Example

```
echo $this->bootstrap4Button($label)->
setStyle('primary')->
setBgStyle('primary')->
block()->
large()->
link($uri);
Expand Down Expand Up @@ -109,22 +129,23 @@ echo $this->bootstrap4Card('', 'width: 20rem;')->

### Bootstrap 4 Jumbotron

Create a Bootstrap 4 jumbotron, heading and content can be set and optionally the display level class
for the heading, a sub heading or whether or not the fluid class applied.
Create a Bootstrap 4 jumbotron component.

##### Public methods:

* headingDisplayLevel(integer[1-4]) - Set the display level class for the heading
* fluid() - Add the jumbotron-fluid class
* subHeading() - Add an optional sub heading, small tag inside the H1
* fluid() - Switch to the fluid layout
* setBgStyle() - Set the background colour utility class
* setHeadingDisplayLevel() - Set the display class for the H1
* setSubHeading() - Add an optional sub heading
* setTextStyle() - Set the text colour utility class

##### Example

```
echo $this->bootstrap4Jumbotron($heading, $content)->
subHeading($sub_heading)->
setSubHeading($sub_heading)->
fluid()->
headingDisplayLevel(1);
setHeadingDisplayLevel(1);
```

### Bootstrap 4 Navbar (lite version)
Expand Down Expand Up @@ -156,38 +177,35 @@ Create a progress bar component.
##### Public methods

* animate() - Animate the striped background style
* color() - Set the background color 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

```
echo $this->bootstrap4ProgressBar(25)->
color('info')->
setBgStyle('info')->
striped()->
animate(); ?>
```

### Bootstrap 4 multiple progress bar

Create a progress bar with multiple bars
Create a progress bar component with multiple bars

##### Public methods

* animate() - Animate the striped background style
* 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

```
echo $this->bootstrap4ProgressBar([25, 15])->
colors(['info', 'warning'])->
echo $this->bootstrap4ProgressBar([25, 15], ['primary', 'info'])->
striped()->
animate(); ?>
```
Expand Down
93 changes: 41 additions & 52 deletions src/Bootstrap4Badge.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

namespace DBlackborough\Zf3ViewHelpers;

use Zend\View\Helper\AbstractHelper;

/**
* Generate a Bootstrap 4 badge
*
Expand All @@ -13,7 +11,7 @@
* @copyright Dean Blackborough
* @license https://github.com/deanblackborough/zf3-view-helpers/blob/master/LICENSE
*/
class Bootstrap4Badge extends AbstractHelper
class Bootstrap4Badge extends Bootstrap4Helper
{
/**
* @var string Button label
Expand All @@ -35,20 +33,6 @@ class Bootstrap4Badge extends AbstractHelper
*/
private $uri;

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

/**
* Entry point for the view helper
*
Expand All @@ -66,60 +50,59 @@ public function __invoke(string $label): Bootstrap4Badge
}

/**
* Set the style for the badge, one of the following, primary, secondary, success,
* info, warning, danger or link. If an incorrect style is passed in we set the
* style to badge-primary
* Render the badge as a link
*
* @param string $style
* @param string $uri
*
* @return Bootstrap4Badge
*/
public function setStyle(string $style): Bootstrap4Badge
public function asLink(string $uri) : Bootstrap4Badge
{
if (in_array($style, $this->supported_styles) === true) {
$this->style = 'badge-' . $style;
} else {
$this->style = 'badge-primary';
}
$this->uri = $uri;

return $this;
}

/**
* Render the badge as a link
*
* @param string $uri
* Set the pill option
*
* @return Bootstrap4Badge
*/
public function asLink(string $uri)
public function pill(): Bootstrap4Badge
{
$this->uri = $uri;
$this->pill = true;

return $this;
}

/**
* Set the pill option
* Set the background colour for the component, 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
*
* @return Bootstrap4Badge
*/
public function pill(): Bootstrap4Badge
public function setBgStyle($color) : Bootstrap4Badge
{
$this->pill = true;
$this->assignBgStyle($color);

return $this;
}

/**
* Reset all properties in case the view helper is called multiple times within a script
* Set the text color for the component, 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.
*
* @return void
* @param string $color
*
* @return Bootstrap4Badge
*/
private function reset(): void
public function setTextStyle($color) : Bootstrap4Badge
{
$this->label = null;
$this->style = null;
$this->pill = false;
$this->uri = null;
$this->assignTextStyle($color);

return $this;
}

/**
Expand All @@ -128,7 +111,7 @@ private function reset(): void
*
* @return string
*/
private function render(): string
protected function render(): string
{
if ($this->uri === null) {
return '<span class="badge' . $this->classes() . '">' . $this->label . '</span>';
Expand All @@ -144,10 +127,14 @@ private function render(): string
*/
private function classes(): string
{
if ($this->style !== null) {
$classes = ' ' . $this->style;
} else {
$classes = ' badge-primary';
$classes = '';

if ($this->bg_color !== null) {
$classes = ' badge-' . $this->bg_color;
}

if ($this->text_color !== null) {
$classes .= ' text-' . $this->text_color;
}

if ($this->pill === true) {
Expand All @@ -158,13 +145,15 @@ private function classes(): string
}

/**
* Override the __toString() method to allow echo/print of the view helper directly,
* saves a call to render()
* Reset all properties in case the view helper is called multiple times within a script
*
* @return string
* @return void
*/
public function __toString(): string
private function reset(): void
{
return $this->render();
$this->label = null;
$this->style = null;
$this->pill = false;
$this->uri = null;
}
}
Loading

0 comments on commit 62f18df

Please sign in to comment.