Skip to content

Commit 5ecfc53

Browse files
committed
Loading Module
1 parent a1f6d7d commit 5ecfc53

File tree

11 files changed

+144
-4
lines changed

11 files changed

+144
-4
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
## focus
2+
3+
Add/remove `loading` class to target element
4+
5+
Usage:
6+
7+
```
8+
$ui.loading(<target-element>)
9+
```
10+
11+
Start loading manually:
12+
13+
```
14+
var target = $ui.loading(<target-element>, false)
15+
target.start()
16+
```
17+
18+
To stop:
19+
20+
```
21+
$ui.loading(<target-element>).stop()
22+
```
23+
or
24+
```
25+
target.stop()
26+
```
27+

demo/src/demo/loading/index.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<div>
2+
<ui-segment id="segment-1">
3+
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
4+
</ui-segment>
5+
6+
<ui-button @click="start">Start</ui-button> <ui-button @click="stop">Stop</ui-button>
7+
</div>

demo/src/demo/loading/index.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { Component } from 'vue-typed';
2+
import { Base } from '../base'
3+
4+
@Component({
5+
template: require('./index.html')
6+
})
7+
export class Loading extends Base {
8+
9+
loading = undefined
10+
11+
start() {
12+
this.loading = this.$ui.loading('#segment-1')
13+
}
14+
15+
stop() {
16+
if (this.loading) this.loading.stop()
17+
}
18+
}

demo/src/demo/routes.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import { Alert } from './alert';
2626
import { Toastr } from './toastr';
2727
import { Focus } from './focus';
2828
import { Int } from './filters/int';
29+
import { Loading } from './loading';
2930

3031

3132
// Main routes builder
@@ -57,7 +58,8 @@ const m = [
5758
{ group: 'module/alert', text: 'Alert', path: 'alert', component: Alert },
5859
{ group: 'module/toastr', text: 'Toastr', path: 'toastr', component: Toastr },
5960
{ group: 'module/focus', text: 'Focus', path: 'focus', component: Focus },
60-
{ group: 'filter/int', text: 'Int', path: 'filters/int', component: Int }
61+
{ group: 'module/loading', text: 'Loading', path: 'loading', component: Loading },
62+
{ group: 'filter/int', text: 'Int', path: 'filters/int', component: Int },
6163
]
6264

6365
// Build router routes

dist/vue-typed-ui.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ declare class VueTypedUI extends VueTypedUIMethods {
2020
alert: modules.Alert
2121
toast: modules.Toastr
2222
focus: modules.Focus
23+
loading: modules.Loading
2324
}
2425

2526
declare class VueTypedUIRoot {

dist/vue-typed-ui.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3085,12 +3085,32 @@ function focus(instance, $this) {
30853085
};
30863086
}
30873087

3088+
function loading$1(instance, $this) {
3089+
return function loading$1(element) {
3090+
var auto = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
3091+
3092+
var target = $($this.$el).find(element);
3093+
if (!target || !target.length) return;
3094+
var module = {
3095+
start: function start() {
3096+
target.addClass('loading');
3097+
},
3098+
stop: function stop() {
3099+
target.removeClass('loading');
3100+
}
3101+
};
3102+
if (auto) module.start();
3103+
return module;
3104+
};
3105+
}
3106+
30883107

30893108

30903109
var modules = Object.freeze({
30913110
alert: alert,
30923111
toast: toast,
3093-
focus: focus
3112+
focus: focus,
3113+
loading: loading$1
30943114
});
30953115

30963116
function DateTime$1(instance) {

doc/api.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,6 +1188,13 @@
11881188
"type": "module",
11891189
"readme": true
11901190
},
1191+
"module/loading": {
1192+
"dir": "src/modules/loading",
1193+
"id": "module/loading",
1194+
"module": "loading",
1195+
"type": "module",
1196+
"readme": true
1197+
},
11911198
"module/toastr": {
11921199
"dir": "src/modules/toastr",
11931200
"id": "module/toastr",

lib/modules.d.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,11 @@ import * as toastr from 'toastr'
33

44
export type Alert = typeof swal
55
export type Toastr = typeof toastr
6-
export type Focus = (element: string | HTMLElement | JQuery) => JQuery
6+
export type Focus = (element: string | HTMLElement | JQuery) => JQuery
7+
8+
interface LoadingModule {
9+
start()
10+
stop()
11+
}
12+
13+
export type Loading = (element: string, auto?: boolean) => LoadingModule

src/modules/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export * from './alert'
22
export * from './toastr'
3-
export * from './focus'
3+
export * from './focus'
4+
export * from './loading'

src/modules/loading/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
## focus
2+
3+
Add/remove `loading` class to target element
4+
5+
Usage:
6+
7+
```
8+
$ui.loading(<target-element>)
9+
```
10+
11+
Start loading manually:
12+
13+
```
14+
var target = $ui.loading(<target-element>, false)
15+
target.start()
16+
```
17+
18+
To stop:
19+
20+
```
21+
$ui.loading(<target-element>).stop()
22+
```
23+
or
24+
```
25+
target.stop()
26+
```
27+

0 commit comments

Comments
 (0)