Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Christoph Erdmann committed Jul 3, 2017
2 parents 50ba921 + adf8b62 commit f8709ba
Show file tree
Hide file tree
Showing 7 changed files with 570 additions and 9 deletions.
19 changes: 12 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ The following widgets are currently available:
* Alert
* Breadcrumbs
* Button
* Carousel
* Chip
* DatePicker
* DetailView
Expand All @@ -70,25 +71,21 @@ The following widgets are currently available:
* GridView with ActionColumn
* Icon
* LinkPager
* MaterialBox
* Modal
* Nav
* NavBar
* Parallax
* Progress
* RangeInput
* Select
* SideNav
* Slider
* Spinner
* SubmitButton
* SwitchButton
* TimePicker

These widgets are planned for development:

* Card
* Collapsible
* Collection
* Toast

## Gii support

If you are creating your CRUD controller and view files using Gii you can get materialized view files by integrating the adapted Gii templates.
Expand Down Expand Up @@ -127,6 +124,7 @@ Unfortunately the issue still exists in the latest release, but can be fixed tem

Hopefully one of the upcoming releases of Materialize will fix the issue.


## Sample layout

As of version 1.0.6 there is a sample layout file included in the package. You can use this file to get inspiration for
Expand All @@ -136,6 +134,13 @@ You can find the sample layout file in ```src/layout/main.php```.

## Change log

### 1.5.0 - 2017-06-05
* added [Carousel](https://github.com/MacGyer/yii2-materializecss/blob/master/src/widgets/media/Carousel.php)
* added [MaterialBox](https://github.com/MacGyer/yii2-materializecss/blob/master/src/widgets/media/MaterialBox.php)
* added [Parallax](https://github.com/MacGyer/yii2-materializecss/blob/master/src/widgets/media/Parallax.php)
* added [Slider](https://github.com/MacGyer/yii2-materializecss/blob/master/src/widgets/media/Slider.php)
* improved sample layout

### 1.4.0 - 2017-06-05
* added [RangeInput](https://github.com/MacGyer/yii2-materializecss/blob/master/src/widgets/form/RangeInput.php)
* updated Materialize to v0.98.2
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"role": "Developer"
}
],
"version": "1.4.0",
"version": "1.5.0",
"require": {
"php": ">=5.6.0",
"yiisoft/yii2": "~2.0.0",
Expand Down
3 changes: 2 additions & 1 deletion src/layout/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

<head>
<meta charset="<?= Yii::$app->charset ?>">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<?= Html::csrfMetaTags() ?>
<title><?= Html::encode($this->title) ?></title>
Expand Down Expand Up @@ -106,4 +107,4 @@
<?php $this->endBody() ?>
</body>
</html>
<?php $this->endPage() ?>
<?php $this->endPage() ?>
188 changes: 188 additions & 0 deletions src/widgets/media/Carousel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
<?php
/**
* @link https://github.com/MacGyer/yii2-materializecss
* @copyright Copyright (c) 2016 ... MacGyer for pluspunkt coding
* @license https://github.com/MacGyer/yii2-materializecss/blob/master/LICENSE
*/

namespace macgyer\yii2materializecss\widgets\media;

use macgyer\yii2materializecss\lib\BaseWidget;
use macgyer\yii2materializecss\lib\Html;
use yii\helpers\ArrayHelper;

/**
* Carousel is a robust and versatile component that can be an image slider or an item carousel with arbitrary HTML content.
*
* Simply provide the [[slides]] as an array of items.
* For each item you must define the `image` key with the image's `src`. Additionally you can define and align a caption
* for every slide individually. Caption content can be HTML and will <strong>not</strong> be encoded.
*
* ```php
* 'itemOptions' => [
* 'class' => 'amber white-text' // this class will be used for all carousel elements
* ],
* 'items' => [
* [
* 'content' => Html::img('http://lorempixel.com/800/800/sports/2'),
* ],
* [
* 'content' => '<h2>Carousel item heading</h2><p>Arbitrary content</p>'
* 'options' => ['class' => 'carusel-item-override'] // overrides $itemOptions
* ]
* ],
* 'fixedItemOptions' => [
* 'tag' => 'p',
* 'content' => 'Some content',
* ],
* ```
* @author Christoph Erdmann <yii2-materializecss@pluspunkt-coding.de>
* @package widgets
* @subpackage media
*
* @see http://materializecss.com/carousel.html
*/
class Carousel extends BaseWidget
{
/**
* @var array the HTML attributes for the carousel container tag.
* @see [yii\helpers\BaseHtml::renderTagAttributes()](http://www.yiiframework.com/doc-2.0/yii-helpers-basehtml.html#renderTagAttributes()-detail)
* for details on how attributes are being rendered.
*/
public $carouselOptions = [];

/**
* @var array the HTML attributes for each carousel item's tag.
* These options will be merged with the individual item options.
*
* @see [yii\helpers\BaseHtml::renderTagAttributes()](http://www.yiiframework.com/doc-2.0/yii-helpers-basehtml.html#renderTagAttributes()-detail)
* for details on how attributes are being rendered.
*/
public $itemOptions = [];

/**
* @var false|array the configuration for the fixed item.
*
* The following special options are recognized:
* - tag: the fixed item's HTML tag name
* - content: the content of the fixed item. Please note: this can be HTML and will not be encoded.
*
* If you do not want the fixed item to be rendered, set this option to `false`.
* @see http://materializecss.com/carousel.html#special
*/
public $fixedItemOptions = false;

/**
* @var array the carousel items.
* Provide a sub-array for each item which can have the keys `tag`, `content` and `options`.
*/
public $items = [];

/**
* @var boolean whether the carousel has full width.
*/
public $fullWidth = false;

/**
* @var boolean whether to show navigation indicators.
*/
public $showIndicators = false;

/**
* @var boolean whether to start with first slide at the end.
* @see http://materializecss.com/carousel.html#options
*/
public $noWrap = false;

/**
* Initialize the widget.
*/
public function init()
{
parent::init();

Html::addCssClass($this->carouselOptions, ['plugin' => 'carousel']);
if ($this->fullWidth) {
Html::addCssClass($this->carouselOptions, ['fullwidth' => 'carousel-slider']);
$this->clientOptions['fullWidth'] = true;
}

$this->clientOptions['noWrap'] = $this->noWrap;
$this->clientOptions['indicators'] = $this->showIndicators;

$this->registerPlugin('carousel', '.carousel');
}

/**
* Execute the widget.
*/
public function run()
{
$tag = ArrayHelper::remove($this->options, 'tag', 'div');
$html[] = Html::beginTag($tag, $this->options);
$html[] = Html::beginTag('div', $this->carouselOptions);
$html[] = $this->renderFixedItem();
$html[] = $this->renderItems();
$html[] = Html::endTag('div');
$html[] = Html::endTag($tag);

return implode("\n", $html);
}

/**
* Parses all [[items]] and renders item list.
*
* @return string the item list markup
*/
protected function renderItems()
{
if (!$this->items) {
return '';
}

$html = [];

foreach ($this->items as $item) {
$html[] = $this->renderItem($item);
}

return implode("\n", $html);
}

/**
* Renders a single carousel item.
*
* @param array $item the item configuration
* @return string the item markup
*/
protected function renderItem($item = [])
{
$tag = ArrayHelper::getValue($item, 'tag', 'div');
$content = ArrayHelper::getValue($item, 'content', '');
$options = ArrayHelper::getValue($item, 'options', []);
$options = ArrayHelper::merge($this->itemOptions, $options);

Html::addCssClass($options, ['item' => 'carousel-item']);

return Html::tag($tag, $content, $options);
}

/**
* Renders the optional fixed item.
*
* @return string the fixed item's markup
*/
protected function renderFixedItem()
{
if ($this->fixedItemOptions === false) {
return '';
}

$tag = ArrayHelper::remove($this->fixedItemOptions, 'tag', 'div');
$content = ArrayHelper::remove($this->fixedItemOptions, 'content', '');

Html::addCssClass($this->fixedItemOptions, ['fixed-item' => 'carousel-fixed-item']);

return Html::tag($tag, $content, $this->fixedItemOptions);
}
}
91 changes: 91 additions & 0 deletions src/widgets/media/MaterialBox.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?php
/**
* @link https://github.com/MacGyer/yii2-materializecss
* @copyright Copyright (c) 2016 ... MacGyer for pluspunkt coding
* @license https://github.com/MacGyer/yii2-materializecss/blob/master/LICENSE
*/

namespace macgyer\yii2materializecss\widgets\media;

use macgyer\yii2materializecss\lib\BaseWidget;
use macgyer\yii2materializecss\lib\Html;
use yii\base\InvalidConfigException;
use yii\helpers\ArrayHelper;

/**
* MaterialBox creates a lightweight lightbox variant to present images.
*
* @author Christoph Erdmann <yii2-materializecss@pluspunkt-coding.de>
* @package widgets
* @subpackage media
*
* @see http://materializecss.com/media.html#materialbox
*/
class MaterialBox extends BaseWidget
{
/**
* @var string the source of the image.
* You must either specify this option or provide an image source via [[$imageOptions]].
*/
public $imageSrc;

/**
* @var array the HTML attributes for the image tag.
* @see [yii\helpers\BaseHtml::renderTagAttributes()](http://www.yiiframework.com/doc-2.0/yii-helpers-basehtml.html#renderTagAttributes()-detail)
* for details on how attributes are being rendered.
*/
public $imageOptions = [];

/**
* @var string|false the caption of the image.
* If you do not want a caption to be rendered, set this option to `false`.
*/
public $imageCaption = false;

/**
* @var boolean whether the image caption shall be HTML-encoded. This defaults to `true`.
*/
public $encodeImageCaption = true;

/**
* Initialize the widget.
* @throws InvalidConfigException
*/
public function init()
{
parent::init();

if (!$this->imageSrc) {
$imageSrc = ArrayHelper::remove($this->imageOptions, 'src', null);
if (!$imageSrc) {
throw new InvalidConfigException("Image src must be defined.");
}

$this->imageSrc = $imageSrc;
}

Html::addCssClass($this->imageOptions, ['plugin' => 'materialboxed']);

if ($this->imageCaption !== false) {
$this->imageOptions['data-caption'] = $this->encodeImageCaption ? Html::encode($this->imageCaption) : $this->imageCaption;
}
}

/**
* Execute the widget.
* @return string the widget's markup.
*/
public function run()
{
$this->registerPlugin('materialbox', '.materialboxed');

$tag = ArrayHelper::remove($this->options, 'tag', 'div');
$html[] = Html::beginTag($tag, $this->options);

$html[] = Html::img($this->imageSrc, $this->imageOptions);

$html[] = Html::endTag($tag);

return implode("\n", $html);
}
}
Loading

0 comments on commit f8709ba

Please sign in to comment.