Skip to content

Commit 5f77e3e

Browse files
committed
input icon - closes #14
1 parent 1d215b7 commit 5f77e3e

File tree

12 files changed

+120
-9
lines changed

12 files changed

+120
-9
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
## Input Component
File renamed without changes.

demo/src/demo/input/index.ts renamed to demo/src/demo/input/basic/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { Component } from 'vue-typed';
2-
import { Base } from '../base'
2+
import { Base } from '../../base'
33
import * as Vue from 'vue'
44

55
@Component({
66
template: require('./index.html')
77
})
8-
export class Input extends Base {
8+
export class InputBasic extends Base {
99
firstName: string = 'John'
1010
lastName: string = 'Doe'
1111
password: string = 'supersecretpassword'
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<div>
2+
<ui-form>
3+
<ui-input icon="user" v-model="userName" label="First Name" placeholder="Please enter your user name"></ui-input>
4+
<ui-input icon="lock" v-model="password" :password="true" label="Password" placeholder="Please enter password"></ui-input>
5+
</ui-form>
6+
</div>

demo/src/demo/input/icon/index.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { Component } from 'vue-typed';
2+
import { Base } from '../../base'
3+
import * as Vue from 'vue'
4+
5+
@Component({
6+
template: require('./index.html')
7+
})
8+
export class InputIcon extends Base {
9+
userName: string = 'superuser'
10+
password: string = 'supersecretpassword'
11+
}

demo/src/demo/routes.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import { FormBasic } from './form/basic';
22
import { FormInline } from './form/inline';
33
import { FormComponentBasic } from './form-component/basic';
44
import { FormComponentReplace } from './form-component/replace';
5-
import { Input } from './input';
5+
import { InputBasic } from './input/basic';
6+
import { InputIcon } from './input/icon';
67
import { Numeric } from './numeric';
78
import { Currency } from './currency';
89
import { TabBasic } from './tab/basic';
@@ -29,7 +30,8 @@ const m = [
2930
{ group: 'component/form', text: 'Inline Form', path: 'form/inline', component: FormInline },
3031
{ group: 'decorator/form', text: 'Basic', path: 'form-component/basic', component: FormComponentBasic },
3132
{ group: 'decorator/form', text: 'Replace', path: 'form-component/replace', component: FormComponentReplace },
32-
{ group: 'component/input', text: 'Input', path: 'input', component: Input },
33+
{ group: 'component/input', text: 'Basic Input', path: 'input/basic', component: InputBasic },
34+
{ group: 'component/input', text: 'Input With Icon', path: 'input/icon', component: InputIcon },
3335
{ group: 'component/numeric', text: 'Numeric', path: 'numeric', component: Numeric },
3436
{ group: 'component/currency', text: 'Currency', path: 'currency', component: Currency },
3537
{ group: 'component/date', text: 'Date', path: 'date', component: DateDemo },

dist/vue-typed-ui.js

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,17 @@ var _InputBase = function (_FieldBase) {
688688

689689
function _InputBase() {
690690
classCallCheck(this, _InputBase);
691-
return possibleConstructorReturn(this, (_InputBase.__proto__ || Object.getPrototypeOf(_InputBase)).apply(this, arguments));
691+
692+
/**
693+
* Icon position
694+
*
695+
* @default 'left'
696+
* @type {'left' | 'right' | string}
697+
*/
698+
var _this = possibleConstructorReturn(this, (_InputBase.__proto__ || Object.getPrototypeOf(_InputBase)).apply(this, arguments));
699+
700+
_this.iconPos = 'left';
701+
return _this;
692702
}
693703

694704
return _InputBase;
@@ -704,6 +714,10 @@ __decorate([vueTyped.Prop()], _InputBase.prototype, "value", void 0);
704714
__decorate([vueTyped.Prop({
705715
type: Boolean
706716
})], _InputBase.prototype, "password", void 0);
717+
__decorate([vueTyped.Prop({
718+
type: String
719+
})], _InputBase.prototype, "icon", void 0);
720+
__decorate([vueTyped.Prop()], _InputBase.prototype, "iconPos", void 0);
707721

708722
// ref: http://vuejs.org/guide/components.html#Form-Input-Components-using-Custom-Events
709723
var Input = function (_InputBase2) {
@@ -723,7 +737,7 @@ var Input = function (_InputBase2) {
723737
}, {
724738
key: 'createComponent',
725739
value: function createComponent(ch) {
726-
return ch('input', {
740+
var input = ch('input', {
727741
attrs: {
728742
type: this.password ? 'password' : 'text',
729743
name: this.name,
@@ -734,6 +748,23 @@ var Input = function (_InputBase2) {
734748
change: this.emiter('change')
735749
}
736750
});
751+
if (!this.icon) return input;
752+
var icon = ch('i', {
753+
class: 'icon ' + this.icon
754+
});
755+
var contents = [];
756+
var css = 'ui left icon input';
757+
if (this.iconPos == 'left') {
758+
contents.push(icon);
759+
contents.push(input);
760+
} else {
761+
contents.push(input);
762+
contents.push(icon);
763+
css = 'ui icon input';
764+
}
765+
return ch('div', {
766+
class: css
767+
}, contents);
737768
}
738769
}, {
739770
key: 'mounted',

doc/api.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,8 +511,17 @@
511511
"FieldBase": "../../fields/field-base"
512512
},
513513
"type": "component",
514-
"readme": false,
514+
"readme": true,
515515
"props": {
516+
"icon": {
517+
"type": "string",
518+
"description": "Name of icon to be displayed"
519+
},
520+
"icon-pos": {
521+
"type": "'left' | 'right' | string",
522+
"description": "Icon position",
523+
"default": "'left'"
524+
},
516525
"kind": {
517526
"type": "'default' | 'grouped' | 'inline'",
518527
"description": "Field layout style"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
## Input Component

src/components/form-inputs/input/_base.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,23 @@ export abstract class _InputBase extends FieldBase {
4848
})
4949
password: boolean
5050

51+
/**
52+
* Name of icon to be displayed
53+
*
54+
* @type {string}
55+
*/
56+
@Prop({
57+
type: String
58+
})
59+
icon: string
60+
61+
/**
62+
* Icon position
63+
*
64+
* @default 'left'
65+
* @type {'left' | 'right' | string}
66+
*/
67+
@Prop()
68+
iconPos: 'left' | 'right' | string = 'left'
69+
5170
}

0 commit comments

Comments
 (0)