Skip to content

Commit f8709ba

Browse files
author
Christoph Erdmann
committed
Merge remote-tracking branch 'origin/develop'
2 parents 50ba921 + adf8b62 commit f8709ba

File tree

7 files changed

+570
-9
lines changed

7 files changed

+570
-9
lines changed

README.md

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ The following widgets are currently available:
6262
* Alert
6363
* Breadcrumbs
6464
* Button
65+
* Carousel
6566
* Chip
6667
* DatePicker
6768
* DetailView
@@ -70,25 +71,21 @@ The following widgets are currently available:
7071
* GridView with ActionColumn
7172
* Icon
7273
* LinkPager
74+
* MaterialBox
7375
* Modal
7476
* Nav
7577
* NavBar
78+
* Parallax
7679
* Progress
7780
* RangeInput
7881
* Select
7982
* SideNav
83+
* Slider
8084
* Spinner
8185
* SubmitButton
8286
* SwitchButton
8387
* TimePicker
8488

85-
These widgets are planned for development:
86-
87-
* Card
88-
* Collapsible
89-
* Collection
90-
* Toast
91-
9289
## Gii support
9390

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

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

127+
130128
## Sample layout
131129

132130
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
@@ -136,6 +134,13 @@ You can find the sample layout file in ```src/layout/main.php```.
136134

137135
## Change log
138136

137+
### 1.5.0 - 2017-06-05
138+
* added [Carousel](https://github.com/MacGyer/yii2-materializecss/blob/master/src/widgets/media/Carousel.php)
139+
* added [MaterialBox](https://github.com/MacGyer/yii2-materializecss/blob/master/src/widgets/media/MaterialBox.php)
140+
* added [Parallax](https://github.com/MacGyer/yii2-materializecss/blob/master/src/widgets/media/Parallax.php)
141+
* added [Slider](https://github.com/MacGyer/yii2-materializecss/blob/master/src/widgets/media/Slider.php)
142+
* improved sample layout
143+
139144
### 1.4.0 - 2017-06-05
140145
* added [RangeInput](https://github.com/MacGyer/yii2-materializecss/blob/master/src/widgets/form/RangeInput.php)
141146
* updated Materialize to v0.98.2

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"role": "Developer"
1414
}
1515
],
16-
"version": "1.4.0",
16+
"version": "1.5.0",
1717
"require": {
1818
"php": ">=5.6.0",
1919
"yiisoft/yii2": "~2.0.0",

src/layout/main.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
<head>
1919
<meta charset="<?= Yii::$app->charset ?>">
20+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
2021
<meta name="viewport" content="width=device-width, initial-scale=1">
2122
<?= Html::csrfMetaTags() ?>
2223
<title><?= Html::encode($this->title) ?></title>
@@ -106,4 +107,4 @@
106107
<?php $this->endBody() ?>
107108
</body>
108109
</html>
109-
<?php $this->endPage() ?>
110+
<?php $this->endPage() ?>

src/widgets/media/Carousel.php

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
<?php
2+
/**
3+
* @link https://github.com/MacGyer/yii2-materializecss
4+
* @copyright Copyright (c) 2016 ... MacGyer for pluspunkt coding
5+
* @license https://github.com/MacGyer/yii2-materializecss/blob/master/LICENSE
6+
*/
7+
8+
namespace macgyer\yii2materializecss\widgets\media;
9+
10+
use macgyer\yii2materializecss\lib\BaseWidget;
11+
use macgyer\yii2materializecss\lib\Html;
12+
use yii\helpers\ArrayHelper;
13+
14+
/**
15+
* Carousel is a robust and versatile component that can be an image slider or an item carousel with arbitrary HTML content.
16+
*
17+
* Simply provide the [[slides]] as an array of items.
18+
* For each item you must define the `image` key with the image's `src`. Additionally you can define and align a caption
19+
* for every slide individually. Caption content can be HTML and will <strong>not</strong> be encoded.
20+
*
21+
* ```php
22+
* 'itemOptions' => [
23+
* 'class' => 'amber white-text' // this class will be used for all carousel elements
24+
* ],
25+
* 'items' => [
26+
* [
27+
* 'content' => Html::img('http://lorempixel.com/800/800/sports/2'),
28+
* ],
29+
* [
30+
* 'content' => '<h2>Carousel item heading</h2><p>Arbitrary content</p>'
31+
* 'options' => ['class' => 'carusel-item-override'] // overrides $itemOptions
32+
* ]
33+
* ],
34+
* 'fixedItemOptions' => [
35+
* 'tag' => 'p',
36+
* 'content' => 'Some content',
37+
* ],
38+
* ```
39+
* @author Christoph Erdmann <[email protected]>
40+
* @package widgets
41+
* @subpackage media
42+
*
43+
* @see http://materializecss.com/carousel.html
44+
*/
45+
class Carousel extends BaseWidget
46+
{
47+
/**
48+
* @var array the HTML attributes for the carousel container tag.
49+
* @see [yii\helpers\BaseHtml::renderTagAttributes()](http://www.yiiframework.com/doc-2.0/yii-helpers-basehtml.html#renderTagAttributes()-detail)
50+
* for details on how attributes are being rendered.
51+
*/
52+
public $carouselOptions = [];
53+
54+
/**
55+
* @var array the HTML attributes for each carousel item's tag.
56+
* These options will be merged with the individual item options.
57+
*
58+
* @see [yii\helpers\BaseHtml::renderTagAttributes()](http://www.yiiframework.com/doc-2.0/yii-helpers-basehtml.html#renderTagAttributes()-detail)
59+
* for details on how attributes are being rendered.
60+
*/
61+
public $itemOptions = [];
62+
63+
/**
64+
* @var false|array the configuration for the fixed item.
65+
*
66+
* The following special options are recognized:
67+
* - tag: the fixed item's HTML tag name
68+
* - content: the content of the fixed item. Please note: this can be HTML and will not be encoded.
69+
*
70+
* If you do not want the fixed item to be rendered, set this option to `false`.
71+
* @see http://materializecss.com/carousel.html#special
72+
*/
73+
public $fixedItemOptions = false;
74+
75+
/**
76+
* @var array the carousel items.
77+
* Provide a sub-array for each item which can have the keys `tag`, `content` and `options`.
78+
*/
79+
public $items = [];
80+
81+
/**
82+
* @var boolean whether the carousel has full width.
83+
*/
84+
public $fullWidth = false;
85+
86+
/**
87+
* @var boolean whether to show navigation indicators.
88+
*/
89+
public $showIndicators = false;
90+
91+
/**
92+
* @var boolean whether to start with first slide at the end.
93+
* @see http://materializecss.com/carousel.html#options
94+
*/
95+
public $noWrap = false;
96+
97+
/**
98+
* Initialize the widget.
99+
*/
100+
public function init()
101+
{
102+
parent::init();
103+
104+
Html::addCssClass($this->carouselOptions, ['plugin' => 'carousel']);
105+
if ($this->fullWidth) {
106+
Html::addCssClass($this->carouselOptions, ['fullwidth' => 'carousel-slider']);
107+
$this->clientOptions['fullWidth'] = true;
108+
}
109+
110+
$this->clientOptions['noWrap'] = $this->noWrap;
111+
$this->clientOptions['indicators'] = $this->showIndicators;
112+
113+
$this->registerPlugin('carousel', '.carousel');
114+
}
115+
116+
/**
117+
* Execute the widget.
118+
*/
119+
public function run()
120+
{
121+
$tag = ArrayHelper::remove($this->options, 'tag', 'div');
122+
$html[] = Html::beginTag($tag, $this->options);
123+
$html[] = Html::beginTag('div', $this->carouselOptions);
124+
$html[] = $this->renderFixedItem();
125+
$html[] = $this->renderItems();
126+
$html[] = Html::endTag('div');
127+
$html[] = Html::endTag($tag);
128+
129+
return implode("\n", $html);
130+
}
131+
132+
/**
133+
* Parses all [[items]] and renders item list.
134+
*
135+
* @return string the item list markup
136+
*/
137+
protected function renderItems()
138+
{
139+
if (!$this->items) {
140+
return '';
141+
}
142+
143+
$html = [];
144+
145+
foreach ($this->items as $item) {
146+
$html[] = $this->renderItem($item);
147+
}
148+
149+
return implode("\n", $html);
150+
}
151+
152+
/**
153+
* Renders a single carousel item.
154+
*
155+
* @param array $item the item configuration
156+
* @return string the item markup
157+
*/
158+
protected function renderItem($item = [])
159+
{
160+
$tag = ArrayHelper::getValue($item, 'tag', 'div');
161+
$content = ArrayHelper::getValue($item, 'content', '');
162+
$options = ArrayHelper::getValue($item, 'options', []);
163+
$options = ArrayHelper::merge($this->itemOptions, $options);
164+
165+
Html::addCssClass($options, ['item' => 'carousel-item']);
166+
167+
return Html::tag($tag, $content, $options);
168+
}
169+
170+
/**
171+
* Renders the optional fixed item.
172+
*
173+
* @return string the fixed item's markup
174+
*/
175+
protected function renderFixedItem()
176+
{
177+
if ($this->fixedItemOptions === false) {
178+
return '';
179+
}
180+
181+
$tag = ArrayHelper::remove($this->fixedItemOptions, 'tag', 'div');
182+
$content = ArrayHelper::remove($this->fixedItemOptions, 'content', '');
183+
184+
Html::addCssClass($this->fixedItemOptions, ['fixed-item' => 'carousel-fixed-item']);
185+
186+
return Html::tag($tag, $content, $this->fixedItemOptions);
187+
}
188+
}

src/widgets/media/MaterialBox.php

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?php
2+
/**
3+
* @link https://github.com/MacGyer/yii2-materializecss
4+
* @copyright Copyright (c) 2016 ... MacGyer for pluspunkt coding
5+
* @license https://github.com/MacGyer/yii2-materializecss/blob/master/LICENSE
6+
*/
7+
8+
namespace macgyer\yii2materializecss\widgets\media;
9+
10+
use macgyer\yii2materializecss\lib\BaseWidget;
11+
use macgyer\yii2materializecss\lib\Html;
12+
use yii\base\InvalidConfigException;
13+
use yii\helpers\ArrayHelper;
14+
15+
/**
16+
* MaterialBox creates a lightweight lightbox variant to present images.
17+
*
18+
* @author Christoph Erdmann <[email protected]>
19+
* @package widgets
20+
* @subpackage media
21+
*
22+
* @see http://materializecss.com/media.html#materialbox
23+
*/
24+
class MaterialBox extends BaseWidget
25+
{
26+
/**
27+
* @var string the source of the image.
28+
* You must either specify this option or provide an image source via [[$imageOptions]].
29+
*/
30+
public $imageSrc;
31+
32+
/**
33+
* @var array the HTML attributes for the image tag.
34+
* @see [yii\helpers\BaseHtml::renderTagAttributes()](http://www.yiiframework.com/doc-2.0/yii-helpers-basehtml.html#renderTagAttributes()-detail)
35+
* for details on how attributes are being rendered.
36+
*/
37+
public $imageOptions = [];
38+
39+
/**
40+
* @var string|false the caption of the image.
41+
* If you do not want a caption to be rendered, set this option to `false`.
42+
*/
43+
public $imageCaption = false;
44+
45+
/**
46+
* @var boolean whether the image caption shall be HTML-encoded. This defaults to `true`.
47+
*/
48+
public $encodeImageCaption = true;
49+
50+
/**
51+
* Initialize the widget.
52+
* @throws InvalidConfigException
53+
*/
54+
public function init()
55+
{
56+
parent::init();
57+
58+
if (!$this->imageSrc) {
59+
$imageSrc = ArrayHelper::remove($this->imageOptions, 'src', null);
60+
if (!$imageSrc) {
61+
throw new InvalidConfigException("Image src must be defined.");
62+
}
63+
64+
$this->imageSrc = $imageSrc;
65+
}
66+
67+
Html::addCssClass($this->imageOptions, ['plugin' => 'materialboxed']);
68+
69+
if ($this->imageCaption !== false) {
70+
$this->imageOptions['data-caption'] = $this->encodeImageCaption ? Html::encode($this->imageCaption) : $this->imageCaption;
71+
}
72+
}
73+
74+
/**
75+
* Execute the widget.
76+
* @return string the widget's markup.
77+
*/
78+
public function run()
79+
{
80+
$this->registerPlugin('materialbox', '.materialboxed');
81+
82+
$tag = ArrayHelper::remove($this->options, 'tag', 'div');
83+
$html[] = Html::beginTag($tag, $this->options);
84+
85+
$html[] = Html::img($this->imageSrc, $this->imageOptions);
86+
87+
$html[] = Html::endTag($tag);
88+
89+
return implode("\n", $html);
90+
}
91+
}

0 commit comments

Comments
 (0)