Skip to content

Commit 07174e5

Browse files
committed
mixins + focus module (closes #19)
1 parent 6deb9c1 commit 07174e5

File tree

19 files changed

+141
-41
lines changed

19 files changed

+141
-41
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
## focus
2+
3+
Is a helper function to change focus to target element.
4+
5+
Usage:
6+
7+
```
8+
$ui.focus(<target-element>)
9+
```

demo/src/demo/focus/index.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<div class="ui form">
2+
<ui-input id="foo" label="Foo" v-model="text"></ui-input>
3+
<ui-input id="bar" label="Bar" v-model="text"></ui-input>
4+
5+
<ui-button @click="focusToFoo">Focus to Foo</ui-button>
6+
<ui-button @click="focusToBar">Focus to Bar</ui-button>
7+
</div>

demo/src/demo/focus/index.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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 Focus extends Base {
9+
10+
text = ''
11+
12+
focusToFoo() {
13+
this.$ui.focus('#foo')
14+
}
15+
16+
focusToBar() {
17+
this.$ui.focus('#bar')
18+
}
19+
20+
}

demo/src/demo/routes.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { Menu } from './menu';
1818
import { Message } from './message';
1919
import { Alert } from './alert';
2020
import { Toastr } from './toastr';
21+
import { Focus } from './focus';
2122

2223

2324
// Main routes builder
@@ -41,7 +42,8 @@ const m = [
4142
{ group: 'component/menu', text: 'Menu', path: 'menu', component: Menu },
4243
{ group: 'component/message', text: 'Message', path: 'message', component: Message },
4344
{ group: 'module/alert', text: 'Alert', path: 'alert', component: Alert },
44-
{ group: 'module/toastr', text: 'Toastr', path: 'toastr', component: Toastr }
45+
{ group: 'module/toastr', text: 'Toastr', path: 'toastr', component: Toastr },
46+
{ group: 'module/focus', text: 'Focus', path: 'focus', component: Focus }
4547
]
4648

4749
// Build router routes

demo/src/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import * as Vue from 'vue';
22
import * as VueRouter from 'vue-router';
33
import { Component } from 'vue-typed';
4-
import * as VueTypedUI from '../../dist/vue-typed-ui';
4+
import { Options } from '../../dist/vue-typed-ui';
5+
import * as VueTypedUI from '../../src/index';
56
import { SettingsPage } from './settings-page';
67

78

@@ -12,7 +13,7 @@ import { SettingsPage } from './settings-page';
1213
// --------------------------------------------------------------------------------------
1314
Vue.use(VueRouter);
1415

15-
Vue.use(VueTypedUI, <VueTypedUI.Options>{
16+
Vue.use(VueTypedUI, <Options>{
1617
prefix: 'ui',
1718
toastr: {
1819
showDuration: 300,

dist/vue-typed-ui.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ declare class VueTypedUI extends VueTypedUIMethods {
2020
createValidationRule(name: string, rule: Function)
2121
alert: modules.Alert
2222
toast: modules.Toastr
23+
focus: modules.Focus
24+
2325
}
2426

2527
declare module "vue/types/vue" {

dist/vue-typed-ui.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2816,11 +2816,18 @@ function toast(instance) {
28162816
return toastr;
28172817
}
28182818

2819+
function focus(instance) {
2820+
return function focus(element) {
2821+
console.log('focus to', instance, element);
2822+
};
2823+
}
2824+
28192825

28202826

28212827
var md = Object.freeze({
28222828
alert: alert,
2823-
toast: toast
2829+
toast: toast,
2830+
focus: focus
28242831
});
28252832

28262833
function DateTime$1(instance) {

doc/api.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1089,7 +1089,7 @@
10891089
"id": "module/focus",
10901090
"module": "focus",
10911091
"type": "module",
1092-
"readme": false
1092+
"readme": true
10931093
},
10941094
"module/toastr": {
10951095
"dir": "src/modules/toastr",

lib/modules.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ import * as swal from 'sweetalert'
22
import * as toastr from 'toastr'
33

44
export type Alert = typeof swal
5-
export type Toastr = typeof toastr
5+
export type Toastr = typeof toastr
6+
export type Focus = (element: string | HTMLElement | JQuery) => JQuery

src/components/containers/tab/methods.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import * as Vue from 'vue'
12
import { Tab } from '../../../../lib/methods'
23

3-
export function tab(instance) {
4+
export function tab(instance, $this: Vue) {
45
return function (element: string | HTMLElement | JQuery): Tab {
56
return {
67
changeTab(path: string) { return $(element).tab('change tab', path); }

0 commit comments

Comments
 (0)