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

Commit

Permalink
Refactored directives, added them to docs
Browse files Browse the repository at this point in the history
  • Loading branch information
romanslonov committed Apr 5, 2019
1 parent 2bf51cd commit 422d4a7
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 0 deletions.
8 changes: 8 additions & 0 deletions docs/.vuepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ module.exports = {
'components/textbox',
'components/toggle',
]
},
{
title: 'Directives',
collapsable: false,
children: [
'directives/autofocus',
'directives/clickoutside'
],
}
]
},
Expand Down
19 changes: 19 additions & 0 deletions docs/directives/autofocus.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Autofocus <badge text="stable" />

The `v-autofocus` directive do auto focus when document is ready.

## Example
<div class="p-3 border rounded-2 my-3 flex">
<input v-autofocus="true" placeholder="Auto focusable input" />
</div>


```html
<input v-autofocus="true" placeholder="Auto focusable input" />
```

## Arguments
Name | type | Description
-------- | -----------| -----
main | Boolean | Whether auto focus is enabled or not

43 changes: 43 additions & 0 deletions docs/directives/clickoutside.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Clickoutside <badge text="stable" />

The `v-clickoutside` directive allows to run callback on click out of element.

## Example
<div class="p-3 border rounded-2 my-3 flex">
<v-button v-clickoutside="handleClickoutside" appearance="primary">Click me or miss</v-button>
</div>


```html
<v-button
appearance="primary"
v-clickoutside="handleClickoutside"
>
Click me or miss
</v-button>
```

```javascript
export default {
methods: {
handleClickoutside() {
alert('You clicked outside the button!');
},
},
};
```

<script>
export default {
methods: {
handleClickoutside() {
alert('You clicked outside the button!');
},
},
};
</script>

## Arguments
Name | type | Description
-------- | -----------| -----
main | Function | Callback that will be executed on clickoutside
File renamed without changes.
8 changes: 8 additions & 0 deletions src/directives/autofocus/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import Autofocus from './autofocus';

// eslint-disable-next-line func-names
Autofocus.install = function (Vue) {
Vue.directive('Autofocus', Autofocus);
};

export default Autofocus;
8 changes: 8 additions & 0 deletions src/directives/clickoutside/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import Clickoutside from './clickoutside';

// eslint-disable-next-line func-names
Clickoutside.install = function (Vue) {
Vue.directive('Clickoutside', Clickoutside);
};

export default Clickoutside;
2 changes: 2 additions & 0 deletions src/directives/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { default as Autofocus } from './autofocus';
export { default as Clickoutside } from './clickoutside';
8 changes: 8 additions & 0 deletions src/entry.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Import vue components
import * as components from './components';
import * as directives from './directives';

// install function executed by Vue.use()
function install(Vue) {
Expand All @@ -8,6 +9,9 @@ function install(Vue) {
Object.keys(components).forEach((component) => {
Vue.component(component, components[component]);
});
Object.keys(directives).forEach((directive) => {
Vue.directive(directive, directives[directive]);
});
}

// Create module definition for Vue.use()
Expand All @@ -33,3 +37,7 @@ export default plugin;
// To allow individual component use, export components
// each can be registered via Vue.component()
export * from './components';

// To allow individual directive use, export directives
// each can be registered via Vue.directive()
export * from './directives';

0 comments on commit 422d4a7

Please sign in to comment.