Skip to content
This repository was archived by the owner on Mar 17, 2021. It is now read-only.

Commit 422d4a7

Browse files
committed
Refactored directives, added them to docs
1 parent 2bf51cd commit 422d4a7

File tree

9 files changed

+96
-0
lines changed

9 files changed

+96
-0
lines changed

docs/.vuepress/config.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ module.exports = {
4343
'components/textbox',
4444
'components/toggle',
4545
]
46+
},
47+
{
48+
title: 'Directives',
49+
collapsable: false,
50+
children: [
51+
'directives/autofocus',
52+
'directives/clickoutside'
53+
],
4654
}
4755
]
4856
},

docs/directives/autofocus.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Autofocus <badge text="stable" />
2+
3+
The `v-autofocus` directive do auto focus when document is ready.
4+
5+
## Example
6+
<div class="p-3 border rounded-2 my-3 flex">
7+
<input v-autofocus="true" placeholder="Auto focusable input" />
8+
</div>
9+
10+
11+
```html
12+
<input v-autofocus="true" placeholder="Auto focusable input" />
13+
```
14+
15+
## Arguments
16+
Name | type | Description
17+
-------- | -----------| -----
18+
main | Boolean | Whether auto focus is enabled or not
19+

docs/directives/clickoutside.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Clickoutside <badge text="stable" />
2+
3+
The `v-clickoutside` directive allows to run callback on click out of element.
4+
5+
## Example
6+
<div class="p-3 border rounded-2 my-3 flex">
7+
<v-button v-clickoutside="handleClickoutside" appearance="primary">Click me or miss</v-button>
8+
</div>
9+
10+
11+
```html
12+
<v-button
13+
appearance="primary"
14+
v-clickoutside="handleClickoutside"
15+
>
16+
Click me or miss
17+
</v-button>
18+
```
19+
20+
```javascript
21+
export default {
22+
methods: {
23+
handleClickoutside() {
24+
alert('You clicked outside the button!');
25+
},
26+
},
27+
};
28+
```
29+
30+
<script>
31+
export default {
32+
methods: {
33+
handleClickoutside() {
34+
alert('You clicked outside the button!');
35+
},
36+
},
37+
};
38+
</script>
39+
40+
## Arguments
41+
Name | type | Description
42+
-------- | -----------| -----
43+
main | Function | Callback that will be executed on clickoutside
File renamed without changes.

src/directives/autofocus/index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import Autofocus from './autofocus';
2+
3+
// eslint-disable-next-line func-names
4+
Autofocus.install = function (Vue) {
5+
Vue.directive('Autofocus', Autofocus);
6+
};
7+
8+
export default Autofocus;
File renamed without changes.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import Clickoutside from './clickoutside';
2+
3+
// eslint-disable-next-line func-names
4+
Clickoutside.install = function (Vue) {
5+
Vue.directive('Clickoutside', Clickoutside);
6+
};
7+
8+
export default Clickoutside;

src/directives/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export { default as Autofocus } from './autofocus';
2+
export { default as Clickoutside } from './clickoutside';

src/entry.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Import vue components
22
import * as components from './components';
3+
import * as directives from './directives';
34

45
// install function executed by Vue.use()
56
function install(Vue) {
@@ -8,6 +9,9 @@ function install(Vue) {
89
Object.keys(components).forEach((component) => {
910
Vue.component(component, components[component]);
1011
});
12+
Object.keys(directives).forEach((directive) => {
13+
Vue.directive(directive, directives[directive]);
14+
});
1115
}
1216

1317
// Create module definition for Vue.use()
@@ -33,3 +37,7 @@ export default plugin;
3337
// To allow individual component use, export components
3438
// each can be registered via Vue.component()
3539
export * from './components';
40+
41+
// To allow individual directive use, export directives
42+
// each can be registered via Vue.directive()
43+
export * from './directives';

0 commit comments

Comments
 (0)