Skip to content

Commit

Permalink
Merge pull request #20 from deanblackborough/v0.67.0
Browse files Browse the repository at this point in the history
V0.67.0
  • Loading branch information
deanblackborough committed Oct 13, 2017
2 parents 62f18df + 0642cdd commit 9f2df8f
Show file tree
Hide file tree
Showing 6 changed files with 687 additions and 66 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@

Full changelog for Zend Framework 3 view helpers library.

## v1.00.0 - Card component (Official release)

Official v1.00.0 release, tests in place for all the Bootstrap 4 view helpers.

* Card view helper extends Bootstrap4Helper
* Card view helper supports setTextStyle() and setBgStyle()
* Added tests for card view helper
* setFooter() in card view helper broken, incorrect property being used to generated HTML
* Fixed a couple of bugs with the navbar view helper
* Added tests for the navbar view helper

## v0.66.0 - Minor updates

* Updated Bootstrap 4 jumbotron view helper, extends Bootstrap4Helper
Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,11 @@ Create a Bootstrap 4 card
* addSubtitleToBody() - Add a subtitle to the card body
* addTextToBody() - Add a text section to the card body
* addTitleToBody() - Add a title section to the card body
* setBgStyle() - Set the background colour utility class
* setBody() - Set the entire card body
* setFooter() - Set the entire card footer
* setHeader() - Set the entire care header
* setTextStyle() - Set the text colour utility class

##### Example

Expand Down Expand Up @@ -156,17 +158,16 @@ Create a navbar component

* addBrand() - Add a brand an option uri
* addNavigation() - Pass in a navigation array
* bgColor() - Set a custom background color for the navbar
* bgStyle() - Set a class for the navbar
* inverseScheme() - Add the navbar-inverse style
* lightScheme() - Add the navbar-light style
* setBgStyle() - Set the background colour utility class
* setTextStyle() - Set the text colour utility class

#### Example

```
echo $this->bootstrap4NavbarLite()->
addBrand('Dlayer')->
bgStyle('bg-light')->
addBrand('Dlayer', '#uri')->
addNavigation([ ['uri' => '#', 'label' => 'Item 1', 'active' => false ] ]); ?>
```

Expand Down
74 changes: 58 additions & 16 deletions src/Bootstrap4Card.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 card component
*
Expand All @@ -13,7 +11,7 @@
* @copyright Dean Blackborough
* @license https://github.com/deanblackborough/zf3-view-helpers/blob/master/LICENSE
*/
class Bootstrap4Card extends AbstractHelper
class Bootstrap4Card extends Bootstrap4Helper
{
/**
* @var array Assigned classes
Expand Down Expand Up @@ -289,8 +287,8 @@ private function cardBodyHtml() : string
break;

case 'text':
$html .= '<div class="card-text' . $this->elementBodyClasses('text') . '"' .
$this->elementBodyAttr('text') . '>' . $section['content'] . '</div>';
$html .= '<p class="card-text' . $this->elementBodyClasses('text') . '"' .
$this->elementBodyAttr('text') . '>' . $section['content'] . '</p>';
break;

case 'link':
Expand Down Expand Up @@ -334,7 +332,7 @@ private function cardFooter() : string
{
$html = '';

if ($this->header !== null) {
if ($this->footer !== null) {
$html .= '<div class="card-footer' . $this->elementAttr('footer') .
'"' . $this->elementAttr('header') . '>' . $this->footer . '</div>';
}
Expand All @@ -348,7 +346,7 @@ private function cardFooter() : string
*
* @return string
*/
private function render(): string
protected function render(): string
{
$html = '<div class="card' . $this->elementClasses('card') . '"' .
$this->elementAttr('card') . '>' .
Expand Down Expand Up @@ -550,27 +548,71 @@ public function setHeader(string $content) : Bootstrap4Card
}

/**
* Set optional footer content for card
* 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 $content
* @param string $color
*
* @return Bootstrap4Card
*/
public function setFooter(string $content) : Bootstrap4Card
public function setBgStyle($color) : Bootstrap4Card
{
$this->footer = $content;
$this->assignBgStyle($color);

return $this;
}

/**
* Override the __toString() method to allow echo/print to call on the view helper, saves a
* call to render()
* Validate and assign the background colour, overrides the method in Bootstrap4Helper
*
* @return string
* @param string $color
*/
protected function assignBgStyle(string $color)
{
if (in_array($color, $this->supported_bg_styles) === true) {
$this->classes['card'][] = 'bg-' . $color;
}
}

/**
* 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.
*
* @param string $color
*
* @return Bootstrap4Card
*/
public function setTextStyle($color) : Bootstrap4Card
{
$this->assignTextStyle($color);

return $this;
}

/**
* 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
*/
public function __toString(): string
protected function assignTextStyle(string $color)
{
return $this->render();
if (in_array($color, $this->supported_text_styles) === true) {
$this->classes['card'][] = 'text-' . $color;
}
}

/**
* Set optional footer content for card
*
* @param string $content
*
* @return Bootstrap4Card
*/
public function setFooter(string $content) : Bootstrap4Card
{
$this->footer = $content;

return $this;
}
}
78 changes: 32 additions & 46 deletions src/Bootstrap4NavbarLite.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 Navbar component, this is the lite version of the view
* helper, there will be a full version which supports all the possible controls
Expand All @@ -14,7 +12,7 @@
* @copyright Dean Blackborough
* @license https://github.com/deanblackborough/zf3-view-helpers/blob/master/LICENSE
*/
class Bootstrap4NavbarLite extends AbstractHelper
class Bootstrap4NavbarLite extends Bootstrap4Helper
{
/**
* @var array Navbar content data array, populated by the add* methods
Expand All @@ -26,16 +24,6 @@ class Bootstrap4NavbarLite extends AbstractHelper
*/
private $scheme;

/**
* @var string An optional background class for the navbar
*/
private $bg_style;

/**
* @var string An optional background color for the navbar
*/
private $bg_color;

/**
* @var string Brand label/name
*/
Expand Down Expand Up @@ -68,8 +56,6 @@ private function reset() : void
$this->content = [];

$this->scheme = null;
$this->bg_style = null;
$this->bg_color = null;
$this->brand_label = null;
$this->brand_uri = null;
}
Expand All @@ -92,12 +78,8 @@ public function addNavigation(array $navigation) : Bootstrap4NavbarLite
array_key_exists('active', $nav) === true &&
array_key_exists('label', $nav) === true) {

$html .= '
<li class="nav-item' .
(($nav['active'] === true) ? ' active' : null) . '">
<a class="nav-link" href="' . $nav['uri'] .
'">' . $this->view->escapeHtml($nav['label']) . '</span></a>
</li>';
$html .= '<li class="nav-item' . (($nav['active'] === true) ? ' active' : null) . '"><a class="nav-link" href="' .
$nav['uri'] . '">' . $nav['label'] . '</a></li>';
} else {
$html .= '<!-- Failed to add navigation item, index(es) missing -->';
}
Expand Down Expand Up @@ -135,29 +117,31 @@ public function inverseScheme() : Bootstrap4NavbarLite
}

/**
* Set the background class to use for the navbar, for example, bg-primary, bg-dark and bg-light
* 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 $class
* @param string $color
*
* @return Bootstrap4NavbarLite
*/
public function bgStyle(string $class) : Bootstrap4NavbarLite
public function setBgStyle(string $color) : Bootstrap4NavbarLite
{
$this->bg_style = $class;
$this->assignBgStyle($color);

return $this;
}

/**
* Set the background color for the navbar
* 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.
*
* @param string $hex
* @param string $color
*
* @return Bootstrap4NavbarLite
*/
public function bgColor(string $hex) : Bootstrap4NavbarLite
public function setTextStyle(string $color) : Bootstrap4NavbarLite
{
$this->bg_color = 'style="background-color:' . $this->view->escapeHtml($hex) . ';"';
$this->assignTextStyle($color);

return $this;
}
Expand Down Expand Up @@ -185,14 +169,14 @@ public function addBrand(string $label, string $uri = null) : Bootstrap4NavbarLi
*/
private function brand() : string
{
if ($this->brand_uri === null) {
return '<span class="h1 navbar-brand">' .
$this->view->escapeHtml($this->brand_label) . '</span>';
} else {
return '<a class="navbar-brand" href="' .
$this->brand_uri . '">' .
$this->view->escapeHtml($this->brand_label) . '</a>';
}
if ($this->brand_label !== null) {
if ($this->brand_uri === null) {
return '<span class="h1 navbar-brand">' . $this->brand_label . '</span>';
} else {
return '<a class="navbar-brand" href="' .
$this->brand_uri . '">' . $this->brand_label . '</a>';
}
} return '';
}

/**
Expand All @@ -201,25 +185,27 @@ private function brand() : string
*
* @return string
*/
private function render() : string
protected function render() : string
{
if ($this->scheme !== null) {
$class = ' ' . $this->scheme;
} else {
$class = ' navbar-light';
}
if ($this->bg_style !== null) {
$class .= ' ' . $this->bg_style;

if ($this->bg_color !== null) {
$class .= ' ' . $this->bg_color;
} else {
$class .= ' bg-light';
}

$html = '<nav class="navbar navbar-expand-lg' . $class . '" ' .
$this->bg_color . '>' . $this->brand() .
'<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">';
if ($this->text_color !== null) {
$class .= ' ' . $this->text_color;
}

$html = '<nav class="navbar navbar-expand-lg' . $class . '" ' . $this->bg_color . '>' . $this->brand() .
'<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">' .
'<span class="navbar-toggler-icon"></span></button><div class="collapse navbar-collapse" id="navbarSupportedContent">';

foreach ($this->content as $content) {
$html .= $content;
Expand Down
Loading

0 comments on commit 9f2df8f

Please sign in to comment.