Skip to content

Commit

Permalink
chore(docs): add documentation on the directive
Browse files Browse the repository at this point in the history
Signed-off-by: Maksim Sukharev <[email protected]>
  • Loading branch information
Antreesy committed Aug 2, 2024
1 parent 5dcd798 commit ee0c7aa
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 0 deletions.
85 changes: 85 additions & 0 deletions docs/directives/keystroke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<!--
- SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
- SPDX-License-Identifier: AGPL-3.0-or-later
-->

```js static
import Keystroke from '@nextcloud/vue/dist/Directives/Keystroke.js'
```

Allows to use keyboard shortcuts in the application.
Extended version of [VueUse onKeyStroke](https://vueuse.org/core/onKeyStroke/)

```vue
<template>
<div class="container">
<h3>Use `WSAD` keys to move the ball</h3>
<div v-key-stroke:w="moveUp"
v-key-stroke:s="moveDown"
v-key-stroke:a="moveLeft"
v-key-stroke:d="moveRight"
class="square">
<div class="circle" :style="circlePosition" ></div>
</div>
<p>position: {{ circleX }} / {{ circleY }}</p>
<h3>Use Ctrl + F to focus input</h3>
<input ref="input" v-key-stroke:f.ctrl.stop.prevent="focusInput" />
</div>
</template>
<script>
export default {
data() {
return {
circleX: 50,
circleY: 50
}
},
computed: {
circlePosition() {
return {
left: this.circleX + 'px',
top: this.circleY + 'px'
}
}
},
methods: {
moveUp() {
this.circleY = Math.max(0, this.circleY - 10)
},
moveDown() {
this.circleY = Math.min(170, this.circleY + 10)
},
moveLeft() {
this.circleX = Math.max(0, this.circleX - 10)
},
moveRight() {
this.circleX = Math.min(170, this.circleX + 10)
},
focusInput() {
this.$refs.input.focus()
}
},
}
</script>
<style scoped>
p {
margin: 8px;
}
.square {
position: relative;
width: 200px;
height: 200px;
outline: 4px solid black;
}
.circle {
position: absolute;
width: 30px;
height: 30px;
background-color: red;
border-radius: 50%;
}
</style>
```
4 changes: 4 additions & 0 deletions styleguide.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ module.exports = async () => {
name: 'Focus',
content: 'docs/directives/focus.md',
},
{
name: 'KeyStroke',
content: 'docs/directives/keystroke.md',
},
{
name: 'Linkify',
content: 'docs/directives/linkify.md',
Expand Down
2 changes: 2 additions & 0 deletions styleguide/global.requires.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { EmojiSkinTone, emojiSearch, emojiAddRecent, getCurrentSkinTone, setCurr
import usernameToColor from '../src/functions/usernameToColor/index.js'
import Tooltip from './../src/directives/Tooltip/index.js'
import Focus from './../src/directives/Focus/index.js'
import KeyStroke from './../src/directives/KeyStroke/index.js'
import Linkify from './../src/directives/Linkify/index.js'

import axios from '@nextcloud/axios'
Expand Down Expand Up @@ -170,4 +171,5 @@ window.usernameToColor = usernameToColor
// Directives
Vue.directive('Tooltip', Tooltip)
Vue.directive('Focus', Focus)
Vue.directive('KeyStroke', KeyStroke)
Vue.directive('Linkify', Linkify)

0 comments on commit ee0c7aa

Please sign in to comment.