Skip to content
This repository was archived by the owner on Jan 22, 2018. It is now read-only.

Commit 6d98df8

Browse files
author
Kamil Kisiela
committed
Merge branch 'release/v0.2.0'
2 parents c39e1df + 8a5200e commit 6d98df8

File tree

13 files changed

+291
-30
lines changed

13 files changed

+291
-30
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
All notable changes to this project will be documented in this file.
33
This project adheres to [Semantic Versioning](http://semver.org/).
44

5+
## [0.2.0] - 2015-11-17
6+
### Added
7+
- Support for textarea with cols and rows
8+
- ApiCheck for label, radio and select
9+
- Support for md-theme
10+
511
## [0.1.0] - 2015-11-17
612
### Added
713
- Support for md-select with valueProp and labelProp
@@ -31,6 +37,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
3137

3238
## 0.0.1 - 2015-11-06
3339

40+
[0.2.0]: https://github.com/kamilkisiela/meteor-angular-formly-templates-material/compare/v0.1.0...v0.2.0
3441
[0.1.0]: https://github.com/kamilkisiela/meteor-angular-formly-templates-material/compare/v0.0.4...v0.1.0
3542
[0.0.4]: https://github.com/kamilkisiela/meteor-angular-formly-templates-material/compare/v0.0.3...v0.0.4
3643
[0.0.3]: https://github.com/kamilkisiela/meteor-angular-formly-templates-material/compare/v0.0.2...v0.0.3

README.md

Lines changed: 121 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,128 @@ angular.module('myAppName', [
2525
```
2626

2727
# Components
28-
_rest of angular-material directive in near future_
28+
29+
Any requests? Add issue!
30+
31+
## Common properties
32+
33+
### label (string)
34+
35+
### theme (string)
36+
37+
```
38+
md-theme attribute
39+
```
2940

3041
## Fields
3142

32-
- input
33-
- checkbox
34-
- select
43+
### input
44+
45+
```json
46+
{
47+
"type": "input",
48+
"key": "firstName",
49+
"templateOptions": {
50+
"type": "text",
51+
"label": "First name",
52+
"theme": "custom"
53+
}
54+
}
55+
```
56+
57+
### textarea
58+
59+
**rows (number, optional)**
60+
61+
```json
62+
{
63+
"type": "textarea",
64+
"key": "bio",
65+
"templateOptions": {
66+
"label": "Biography",
67+
"theme": "custom",
68+
"rows": 5
69+
}
70+
}
71+
```
72+
73+
### radio
74+
75+
**options (array, requred)**
76+
77+
**labelProp (string, optional)**
78+
79+
**valueProp (string, optional)**
80+
81+
```json
82+
{
83+
"type": "radio",
84+
"key": "name",
85+
"templateOptions": {
86+
"label": "Name",
87+
"theme": "custom",
88+
"labelProp": "firstName",
89+
"valueProp": "id",
90+
"options": [
91+
{"firstName": "Sarah", id: 1},
92+
{"firstName": "Jessica", id: 2},
93+
{"firstName": "Parker", id: 3}
94+
]
95+
}
96+
}
97+
```
98+
99+
### select
100+
101+
**options (array, requred)**
102+
103+
**labelProp (string, optional)**
104+
105+
**valueProp (string, optional)**
106+
107+
```json
108+
{
109+
"type": "select",
110+
"key": "name",
111+
"templateOptions": {
112+
"label": "Name",
113+
"theme": "custom",
114+
"labelProp": "firstName",
115+
"valueProp": "id",
116+
"options": [
117+
{"firstName": "Sarah", id: 1},
118+
{"firstName": "Jessica", id: 2},
119+
{"firstName": "Parker", id: 3}
120+
]
121+
}
122+
}
123+
```
124+
125+
### checkbox
126+
127+
```json
128+
{
129+
"type": "checkbox",
130+
"key": "terms",
131+
"templateOptions": {
132+
"label": "Terms and Conditions",
133+
"theme": "custom"
134+
}
135+
}
136+
```
137+
138+
### switch
139+
140+
```json
141+
{
142+
"type": "switch",
143+
"key": "terms",
144+
"templateOptions": {
145+
"label": "Terms and Conditions",
146+
"theme": "custom"
147+
}
148+
}
149+
```
35150

36151
## Wrappers
37152

@@ -44,12 +159,13 @@ _rest of angular-material directive in near future_
44159
- [ ] add md-chips
45160
- [ ] add md-datepicker
46161
- [ ] add md-icon wrapper
47-
- [ ] add md-radio-button and md-radio-group
48162
- [x] add md-select
49163
- [ ] add groups to md-select
50164
- [x] add valueProp, labelProp to md-select
51165
- [x] add md-radio with valueProp and labelProp
52166
- [ ] add groupProp to md-radio
167+
- [x] add textarea with cols and rows
168+
- [x] md-theme
53169
- [ ] e2e tests
54170

55171
Requests (?). Post an issue.

lib/client/formly-material.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
var {SetModule} = angular2now;
2+
3+
SetModule('formlyMaterial')
4+
.provider('formlyMaterial', formlyMaterial);
5+
6+
function formlyMaterial() {
7+
var self = this;
8+
9+
this.templateUrl = function (templateUrl) {
10+
return '/packages/wieldo:angular-formly-templates-material/' + templateUrl.replace(/^\//, "");
11+
};
12+
13+
this.$get = function () {
14+
return {
15+
templateUrl: self.templateUrl
16+
}
17+
};
18+
}

lib/client/main.js

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,4 @@ SetModule('formlyMaterial', [
44
'ngMessages',
55
'ngMaterial',
66
'formly'
7-
])
8-
.provider('formlyMaterial', formlyMaterial);
9-
10-
function formlyMaterial() {
11-
var self = this;
12-
13-
this.templateUrl = function (templateUrl) {
14-
return '/packages/wieldo:angular-formly-templates-material/' + templateUrl.replace(/^\//, "");
15-
};
16-
17-
this.$get = function () {
18-
return {
19-
templateUrl: self.templateUrl
20-
}
21-
};
22-
}
7+
]);
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
var {SetModule} = angular2now;
2+
3+
SetModule('formlyMaterial')
4+
.config((formlyConfigProvider) => {
5+
6+
const addIfNotPresent = (nodes, attr, val) => {
7+
angular.forEach(nodes, node => {
8+
if (!node.getAttribute(attr)) {
9+
node.setAttribute(attr, val)
10+
}
11+
})
12+
};
13+
14+
const nodeMatches = (node, selector) => {
15+
const div = document.createElement('div');
16+
17+
div.innerHTML = node.outerHTML;
18+
return div.querySelector(selector)
19+
};
20+
21+
const getNgModelNodes = (node, skip) => {
22+
const selectorNot = angular.isString(skip) ? `:not(${skip})` : '';
23+
const skipNot = ':not([formly-skip-ng-model-attrs-manipulator])';
24+
const query = `[ng-model]${selectorNot}${skipNot}, [data-ng-model]${selectorNot}${skipNot}`;
25+
26+
try {
27+
return node.querySelectorAll(query)
28+
} catch (e) {
29+
//this code is needed for IE8, as it does not support the CSS3 ':not' selector
30+
//it should be removed when IE8 support is dropped
31+
return getNgModelNodesFallback(node, skip)
32+
}
33+
};
34+
35+
const getNgModelNodesFallback = (node, skip) => {
36+
const allNgModelNodes = node.querySelectorAll('[ng-model], [data-ng-model]');
37+
const matchingNgModelNodes = [];
38+
39+
//make sure this array is compatible with NodeList type by adding an 'item' function
40+
matchingNgModelNodes.item = function (i) {
41+
return this[i]
42+
};
43+
44+
for (let i = 0; i < allNgModelNodes.length; i++) {
45+
const ngModelNode = allNgModelNodes[i];
46+
47+
if (!ngModelNode.hasAttribute('formly-skip-ng-model-attrs-manipulator') && !(angular.isString(skip) && nodeMatches(ngModelNode, skip))) {
48+
matchingNgModelNodes.push(ngModelNode)
49+
}
50+
}
51+
52+
return matchingNgModelNodes
53+
};
54+
55+
formlyConfigProvider.templateManipulators.preWrapper.push((template, options, scope) => {
56+
if (angular.isDefined(options.templateOptions.theme)) {
57+
const node = document.createElement('div');
58+
const skip = options.extras && options.extras.skipNgModelAttrsManipulator;
59+
if (skip === true) {
60+
return template
61+
}
62+
node.innerHTML = template;
63+
const modelNodes = getNgModelNodes(node, skip);
64+
65+
if (!modelNodes || !modelNodes.length) {
66+
return template;
67+
}
68+
69+
addIfNotPresent(modelNodes, 'md-theme', options.templateOptions.theme);
70+
71+
return node.innerHTML;
72+
73+
} else {
74+
return template;
75+
}
76+
});
77+
78+
});
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<div>
2-
<md-checkbox ng-model="model[options.key]" md-theme="{{to.mdTheme || 'primary'}}">
2+
<md-checkbox ng-model="model[options.key]">
33
{{to.label}}
44
</md-checkbox>
55
</div>

lib/client/types/radio/radio.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,14 @@ SetModule('formlyMaterial')
55

66
formlyConfigProvider.setType({
77
name: 'radio',
8-
templateUrl: formlyMaterialProvider.templateUrl('lib/client/types/radio/radio.ng.html')
8+
templateUrl: formlyMaterialProvider.templateUrl('lib/client/types/radio/radio.ng.html'),
9+
apiCheck: (check) => ({
10+
templateOptions: {
11+
options: check.arrayOf(check.object),
12+
labelProp: check.string.optional,
13+
valueProp: check.string.optional
14+
}
15+
})
916
});
1017

1118
});

lib/client/types/select/select.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,14 @@ SetModule('formlyMaterial')
66
formlyConfigProvider.setType({
77
name: 'select',
88
templateUrl: formlyMaterialProvider.templateUrl('lib/client/types/select/select.ng.html'),
9-
wrapper: ['mdLabel', 'mdMessages', 'mdInputContainer']
9+
wrapper: ['mdLabel', 'mdMessages', 'mdInputContainer'],
10+
apiCheck: (check) => ({
11+
templateOptions: {
12+
options: check.arrayOf(check.object),
13+
labelProp: check.string.optional,
14+
valueProp: check.string.optional
15+
}
16+
})
1017
});
1118

1219
});
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
<md-switch ng-model="model[options.key]" md-theme="{{to.mdTheme || 'primary'}}">
1+
<md-switch ng-model="model[options.key]">
22
{{to.label}}
33
</md-switch>

lib/client/types/textarea/textarea.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
var {SetModule} = angular2now;
2+
3+
SetModule('formlyMaterial')
4+
.config((formlyConfigProvider, formlyMaterialProvider) => {
5+
6+
formlyConfigProvider.setType({
7+
name: 'textarea',
8+
templateUrl: formlyMaterialProvider.templateUrl('lib/client/types/textarea/textarea.ng.html'),
9+
wrapper: ['mdLabel', 'mdMessages', 'mdInputContainer'],
10+
defaultOptions: {
11+
ngModelAttrs: {
12+
rows: {attribute: 'rows'},
13+
cols: {attribute: 'cols'}
14+
}
15+
},
16+
apiCheck: (check) => ({
17+
templateOptions: {
18+
rows: check.number.optional,
19+
cols: check.number.optional
20+
}
21+
})
22+
});
23+
24+
});

0 commit comments

Comments
 (0)