Skip to content

Commit 551c88d

Browse files
committed
Merge remote-tracking branch 'origin/develop'
2 parents 3fb8545 + 07fd703 commit 551c88d

21 files changed

+124
-81
lines changed

README.md

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,39 +6,42 @@
66

77
----
88

9-
This is the current, actively developed 3.x branch which is implementing Materialize version 1.0 and thus breaking backwards compatibility.
9+
This is the current, actively developed 4.x branch which is implementing Materialize version 1.1 and thus breaking backwards compatibility.
1010

1111
[Go to 1.x version](https://github.com/MacGyer/yii2-materializecss/tree/1.x)
1212

1313
[Go to 2.x version](https://github.com/MacGyer/yii2-materializecss/tree/2.x)
1414

15+
[Go to 3.x version](https://github.com/MacGyer/yii2-materializecss/tree/3.x)
16+
1517
----
1618

1719
This package integrates the Materialize CSS framework into [Yii2](http://www.yiiframework.com/).
18-
[Materialize](http://materializecss.com/) is a modern responsive front-end framework based on Material Design.
19-
20-
See [official documentation](http://macgyer.github.io/yii2-materializecss/) for detailed information.
20+
[Materialize](https://materializecss.github.io/materialize/) is a modern responsive front-end framework based on Material Design.
2121

22-
Have a look at the [official demo page](https://yii2-materializecss.pluspunkt-coding.de) to see the repo in action (needs adaption to v3)
22+
Have a look at the [official documentation page](https://yii2-materializecss.pluspunkt-coding.de) to see the repo in action (v4 only).
2323

24-
Current Materialize version implemented: 1.0.0.
24+
Current Materialize version implemented: 1.1.0.
2525

2626
## Installation
2727

2828
The preferred way of installation is through Composer.
2929
If you don't have Composer you can get it here: https://getcomposer.org/
3030

31-
You also should install the Composer Asset Plugin to handle NPM and Bower assets:
32-
```
33-
$ composer global require "fxp/composer-asset-plugin:~1.4"
31+
You also should reference Asset Packagist in the ```repositories``` section to handle NPM and Bower assets:
32+
```json
33+
"repositories": [
34+
{
35+
"type": "composer",
36+
"url": "https://asset-packagist.org"
37+
}
38+
]
3439
```
3540

36-
Or you can make use of Asset Packagist: <https://asset-packagist.org/>
37-
3841
To install the package add the following to the ```require``` section of your composer.json:
39-
```
42+
```json
4043
"require": {
41-
"macgyer/yii2-materializecss": "~3.0.0"
44+
"macgyer/yii2-materializecss": "^4.0"
4245
},
4346
```
4447

@@ -65,6 +68,18 @@ public $depends = [
6568
];
6669
```
6770

71+
### Material Icons
72+
73+
To be compatible with GDPR (EU) the MaterializeFontAsset is not loaded automatically via the MaterializeAsset. The font asset requests the Material Icon font from Google servers (as stated in the Materialize docs).
74+
75+
If you are **not** affected by GDPR, simply load the MaterializeFontAsset in your layout or AppAsset.
76+
77+
Otherwise you need to self-host the Material Icon font (i. e. do not request them from Google). You could use ```material-icons``` (https://www.npmjs.com/package/material-icons) to load the font files, CSS and SCSS from NPM and include them in your build process.
78+
79+
### SCSS
80+
81+
Customizing Materialize via SCSS is easy. Integrate the Materialize SCSS in your own SCSS files and build your own version. Do not use the MaterializeAsset then as it loads the pre-built CSS provided by Materialize.
82+
6883
## Widgets
6984

7085
The following widgets are currently available:
@@ -137,6 +152,14 @@ You can find the sample layout file in ```src/layout/main.php```.
137152

138153
## Change log
139154

155+
### 4.0.0 - 2022-11-27
156+
* implement Materialize v1.1.0 (community fork https://materializecss.github.io/materialize/)
157+
* PHP 8 support
158+
* use NPM instead of Bower
159+
* use constants to configure [Icon](https://github.com/MacGyer/yii2-materializecss/blob/master/src/widgets/Icon.php)
160+
* **Breaking changes included**:
161+
* MaterializeFontAsset not loaded automatically
162+
140163
### 3.0.0 - 2018-11-16
141164
* implement Materialize v1.0.0
142165
* **Breaking changes included**

composer.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@
1313
"role": "Developer"
1414
}
1515
],
16-
"version": "3.0.0",
1716
"require": {
18-
"php": ">=5.6.0",
17+
"php": "^7.4 || ^8.0",
1918
"yiisoft/yii2": "~2.0.0",
2019

21-
"bower-asset/materialize": "1.0.0"
20+
"npm-asset/materializecss--materialize": "1.1.0"
2221
},
2322
"autoload": {
2423
"psr-4": {

src/assets/MaterializeAsset.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,12 @@ class MaterializeAsset extends AssetBundle
2020
/**
2121
* @var string the directory that contains the source asset files for this asset bundle.
2222
*/
23-
public $sourcePath = '@bower/materialize/dist';
23+
public $sourcePath = '@npm/materializecss--materialize/dist';
2424

2525
/**
2626
* @var array list of CSS files that this bundle contains.
2727
*/
2828
public $css = [
2929
'css/materialize.min.css'
3030
];
31-
32-
/**
33-
* @var array list of bundle class names that this bundle depends on.
34-
*/
35-
public $depends = [
36-
MaterializeFontAsset::class,
37-
];
3831
}

src/assets/MaterializePluginAsset.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class MaterializePluginAsset extends AssetBundle
2020
/**
2121
* @var string the directory that contains the source asset files for this asset bundle.
2222
*/
23-
public $sourcePath = '@bower/materialize/dist';
23+
public $sourcePath = '@npm/materializecss--materialize/dist';
2424

2525
/**
2626
* @var array list of JS files that this bundle contains.

src/assets/NoUiSliderAsset.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class NoUiSliderAsset extends AssetBundle
2121
/**
2222
* @var string the directory that contains the source asset files for this asset bundle.
2323
*/
24-
public $sourcePath = '@bower/materialize/extras/noUiSlider';
24+
public $sourcePath = '@npm/materializecss--materialize/extras/noUiSlider';
2525

2626
/**
2727
* @var array list of CSS files that this bundle contains.

src/lib/Html.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public static function activeTextarea($model, $attribute, $options = [])
112112
* @param string $attribute the attribute name or expression.
113113
* @param array $options the tag options in terms of name-value pairs.
114114
*
115-
* @see http://materializecss.com/forms.html#character-counter
115+
* @see https://materializecss.github.io/materialize/text-inputs.html#character-counter
116116
*/
117117
private static function normalizeMaxLength($model, $attribute, &$options)
118118
{

src/lib/MaterializeWidgetTrait.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ trait MaterializeWidgetTrait
3737
* @var array the options for the underlying Materialize JS plugin.
3838
* Please refer to the corresponding Materialize documentation web page.
3939
*
40-
* @see http://materializecss.com/
40+
* @see https://materializecss.github.io/materialize/
4141
*/
4242
public $clientOptions = [];
4343

4444
/**
4545
* @var array the event handlers for the underlying Materialize JS plugin.
4646
* Please refer to the corresponding Materialize documentation web page.
4747
*
48-
* @see http://materializecss.com/
48+
* @see https://materializecss.github.io/materialize/
4949
*/
5050
public $clientEvents = [];
5151

@@ -103,7 +103,7 @@ protected function registerClientEvents()
103103
/** @var View $view */
104104
$view = $this->getView();
105105
$id = $this->options['id'];
106-
$js[] = "var elem_$id = document.getElementById('$id');";
106+
$js[] = "let elem_$id = document.getElementById('$id');";
107107
foreach ($this->clientEvents as $event => $handler) {
108108
$js[] = "elem_$id.addEventListener('$event', $handler);";
109109
}

src/widgets/Icon.php

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,42 @@
1515
/**
1616
* Icon can be used to display a Materialize icon.
1717
*
18-
* Please note that the Materialize icons are shipped in a separate font file. This font file is automatically registered
19-
* by the [[\macgyer\yii2materializecss\assets\MaterializeAsset|MaterializeAsset]].
18+
* To be compatible with GDPR (EU) the MaterializeFontAsset is not loaded automatically via the [[\macgyer\yii2materializecss\assets\MaterializeAsset|MaterializeAsset]]. The font asset requests the Material Icon font from Google servers (as stated in the Materialize docs).
19+
* If you are not affected by GDPR, simply load the [[\macgyer\yii2materializecss\assets\MaterializeFontAsset|MaterializeFontAsset]] in your layout or AppAsset.
2020
*
21-
* If you do not load the default [[\macgyer\yii2materializecss\assets\MaterializeAsset|MaterializeAsset]] make sure to at least load
22-
* [[\macgyer\yii2materializecss\assets\MaterializeFontAsset|MaterializeFontAsset]] (or another source providing the font file) to correctly
23-
* display the icons.
21+
* Otherwise you need to self-host the Material Icon font (i. e. do not request them from Google). You could use `material-icons` (https://www.npmjs.com/package/material-icons) to load the font files, CSS and SCSS from NPM and include them in your build process.
2422
*
2523
* @author Christoph Erdmann <yii2-materializecss@pluspunkt-coding.de>
2624
* @package widgets
2725
* @see https://materializecss.com/icons.html
2826
*/
2927
class Icon extends BaseWidget
3028
{
29+
/**
30+
* Sets the [[size]] of the icon to "tiny".
31+
*/
32+
public const SIZE_TINY = 'tiny';
33+
/**
34+
* Sets the [[size]] of the icon to "small". This is the default.
35+
*/
36+
public const SIZE_SMALL = 'small';
37+
/**
38+
* Sets the [[size]] of the icon to "medium".
39+
*/
40+
public const SIZE_MEDIUM = 'medium';
41+
/**
42+
* Sets the [[size]] of the icon to "large".
43+
*/
44+
public const SIZE_LARGE = 'large';
45+
/**
46+
* Sets the [[position]] of the icon to "left".
47+
*/
48+
public const POSITION_LEFT = 'left';
49+
/**
50+
* Sets the [[position]] of the icon to "right".
51+
*/
52+
public const POSITION_RIGHT = 'right';
53+
3154
/**
3255
* @var string the name of the icon.
3356
*
@@ -40,11 +63,16 @@ class Icon extends BaseWidget
4063
*
4164
* Currently "left" and "right" are natively supported by Materialize, but you can set this property to a custom string
4265
* which will be added to the HTML class attribute and thus can be individually styled.
43-
*
44-
* The default icon position is "left".
4566
*/
4667
public $position;
4768

69+
/**
70+
* @var string the size of the icon.
71+
*
72+
* The default icon size is "small".
73+
*/
74+
public $size = self::SIZE_SMALL;
75+
4876
/**
4977
* @var array the HTML options for the icon tag.
5078
*
@@ -69,12 +97,15 @@ public function init()
6997
if (!$this->name) {
7098
throw new InvalidConfigException('The icon name must be specified.');
7199
}
100+
Html::addCssClass($this->options, ['widget' => 'material-icons']);
72101

73-
if ($this->position === null) {
74-
$this->position = 'left';
102+
if ($this->position) {
103+
Html::addCssClass($this->options, ['material-icon-position' => $this->position]);
75104
}
76105

77-
Html::addCssClass($this->options, ['material-icons', $this->position]);
106+
if ($this->size) {
107+
Html::addCssClass($this->options, ['material-icon-size' => $this->size]);
108+
}
78109
}
79110

80111
/**

src/widgets/Modal.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ class Modal extends BaseWidget
122122
* - label: string, the label of the button. Defaults to '&times;'.
123123
*
124124
* The rest of the options will be rendered as the HTML attributes of the button tag.
125-
* Please refer to the [Modal plugin help](http://materializecss.com/modals.html)
125+
* Please refer to the [Modal plugin help](https://materializecss.github.io/materialize/modals.html)
126126
* for the supported HTML attributes.
127127
* @see [\yii\helpers\Html::renderTagAttributes()](http://www.yiiframework.com/doc-2.0/yii-helpers-basehtml.html#renderTagAttributes()-detail) for details on how attributes are being rendered.
128128
*/
@@ -155,7 +155,7 @@ class Modal extends BaseWidget
155155
* - label: string, the label of the button. Defaults to 'Show'.
156156
*
157157
* The rest of the options will be rendered as the HTML attributes of the button tag.
158-
* Please refer to the [Modal plugin help](http://materializecss.com/modals.html)
158+
* Please refer to the [Modal plugin help](https://materializecss.github.io/materialize/modals.html)
159159
* for the supported HTML attributes.
160160
* @see [\yii\helpers\Html::renderTagAttributes()](http://www.yiiframework.com/doc-2.0/yii-helpers-basehtml.html#renderTagAttributes()-detail) for details on how attributes are being rendered.
161161
*/

src/widgets/form/ActiveField.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ class ActiveField extends \yii\widgets\ActiveField
111111
*
112112
* Note: the `characterCounter()` is currently available for input types `text` and `password`, and for `textarea`.
113113
*
114-
* @see http://materializecss.com/forms.html#character-counter
114+
* @see https://materializecss.github.io/materialize/text-inputs.html#character-counter
115115
*/
116116
public $showCharacterCounter = false;
117117

@@ -475,7 +475,7 @@ public function numberInput($options = [])
475475
* the Materialize character counter JS plugin is initialized for this field.
476476
*
477477
* @return $this the field object itself.
478-
* @see http://materializecss.com/forms.html#character-counter
478+
* @see https://materializecss.github.io/materialize/text-inputs.html#input
479479
*/
480480
public function passwordInput($options = [])
481481
{
@@ -602,8 +602,8 @@ public function telInput($options = [])
602602
* - autocomplete: string|array, see [[initAutoComplete()]] for details
603603
*
604604
* @return $this the field object itself.
605-
* @see http://materializecss.com/forms.html#character-counter
606-
* @see http://materializecss.com/forms.html#autocomplete
605+
* @see https://materializecss.github.io/materialize/text-inputs.html#textarea
606+
* @see https://materializecss.github.io/materialize/autocomplete.html
607607
* @see https://www.w3.org/TR/html5/forms.html#attr-fe-autocomplete
608608
*/
609609
public function textarea($options = [])
@@ -633,8 +633,8 @@ public function textarea($options = [])
633633
* - autocomplete: string|array, see [[initAutoComplete()]] for details
634634
*
635635
* @return $this the field object itself.
636-
* @see http://materializecss.com/forms.html#character-counter
637-
* @see http://materializecss.com/forms.html#autocomplete
636+
* @see https://materializecss.github.io/materialize/text-inputs.html#textarea
637+
* @see https://materializecss.github.io/materialize/autocomplete.html
638638
* @see https://www.w3.org/TR/html5/forms.html#attr-fe-autocomplete
639639
*/
640640
public function textInput($options = [])

0 commit comments

Comments
 (0)