Skip to content

Commit 27500ba

Browse files
committed
Added class option to form component (closes #16)
1 parent a9b113d commit 27500ba

File tree

3 files changed

+38
-7
lines changed

3 files changed

+38
-7
lines changed

dist/vue-typed-ui.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2518,6 +2518,10 @@ function FormComponent(options$$1) {
25182518
args.push({ key: ':validate-inline', val: options$$1.validateInline });
25192519
delete options$$1.validateInline;
25202520
}
2521+
if (options$$1.class !== undefined) {
2522+
args.push({ key: 'class', val: options$$1.class });
2523+
delete options$$1.class;
2524+
}
25212525
var argsStr = ' ' + args.map(function (v) {
25222526
return v.key + '="' + v.val + '"';
25232527
}).join(' ');
@@ -2532,14 +2536,18 @@ function FormComponent(options$$1) {
25322536

25332537
var node = htmlToElement(options$$1.template);
25342538
var newNode = document.createElement('ui-form');
2539+
var classes = [];
25352540
for (var i = 0; i < node.attributes.length; i++) {
25362541
var attr = node.attributes[i];
2537-
newNode.setAttribute(attr.name, attr.value);
2542+
if (attr.name == 'class') classes.push(attr.value);else newNode.setAttribute(attr.name, attr.value);
25382543
}
25392544
newNode.setAttribute(':validator', ValidatorPropName);
25402545
for (var i = 0; i < args.length; i++) {
25412546
var arg = args[i];
2542-
newNode.setAttribute(arg['key'], arg['val']);
2547+
if (arg.key == 'class') classes.push(arg.val);else newNode.setAttribute(arg.key, arg.val);
2548+
}
2549+
if (classes.length) {
2550+
newNode.setAttribute('class', classes.join(' '));
25432551
}
25442552
newNode.innerHTML = node['innerHTML'];
25452553
options$$1.template = newNode.outerHTML;

lib/form-options.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,12 @@ export interface FormOptions extends ComponentOptions<Vue> {
3838
* @memberOf FormOptions
3939
*/
4040
replace?: boolean
41+
42+
/**
43+
* CSS class for generated form
44+
*
45+
* @type {string}
46+
* @memberOf FormOptions
47+
*/
48+
class? : string
4149
}

src/decorators/form/index.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,14 @@ export function FormComponent(options: FormOptions): ClassDecorator {
2222
delete options.validateInline
2323
}
2424

25-
let argsStr = ' ' + args.map((v)=>{
25+
if (options.class !== undefined) {
26+
args.push({ key: 'class', val: options.class })
27+
delete options.class
28+
}
29+
30+
let argsStr = ' ' + args.map((v) => {
2631
return v.key + '="' + v.val + '"';
27-
}) .join(' ')
32+
}).join(' ')
2833

2934
if (!options.replace) {
3035
options.template = `<ui-form :validator="${ValidatorPropName}"${argsStr}>${options.template}<ui-form>`
@@ -37,21 +42,31 @@ export function FormComponent(options: FormOptions): ClassDecorator {
3742

3843
var node = htmlToElement(options.template)
3944
var newNode = document.createElement('ui-form')
45+
var classes = []
4046
for (var i = 0; i < node.attributes.length; i++) {
4147
let attr = node.attributes[i]
42-
newNode.setAttribute(attr.name, attr.value)
48+
if (attr.name == 'class')
49+
classes.push(attr.value)
50+
else
51+
newNode.setAttribute(attr.name, attr.value)
4352
}
4453

4554
newNode.setAttribute(':validator', ValidatorPropName)
4655
for (var i = 0; i < args.length; i++) {
4756
let arg = args[i]
48-
newNode.setAttribute(arg['key'], arg['val'])
57+
if (arg.key == 'class')
58+
classes.push(arg.val)
59+
else
60+
newNode.setAttribute(arg.key, arg.val)
4961
}
5062

63+
if (classes.length) {
64+
newNode.setAttribute('class', classes.join(' '))
65+
}
5166

5267
newNode.innerHTML = node['innerHTML']
5368
options.template = newNode.outerHTML
54-
69+
5570
}
5671

5772
return function (target: typeof Function) {

0 commit comments

Comments
 (0)