summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/behaviors/shortcuts/shortcuts_toggle.vue
blob: 8f1518a1c9ca41e09ee5cfb34f487fa0b68be1e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<script>
import { GlToggle } from '@gitlab/ui';
import AccessorUtilities from '~/lib/utils/accessor';
import { __ } from '~/locale';
import { disableShortcuts, enableShortcuts, shouldDisableShortcuts } from './shortcuts_toggle';

export default {
  i18n: {
    toggleLabel: __('Toggle shortcuts'),
  },
  components: {
    GlToggle,
  },
  data() {
    return {
      localStorageUsable: AccessorUtilities.isLocalStorageAccessSafe(),
      shortcutsEnabled: !shouldDisableShortcuts(),
    };
  },
  methods: {
    onChange(value) {
      this.shortcutsEnabled = value;
      if (value) {
        enableShortcuts();
      } else {
        disableShortcuts();
      }
    },
  },
};
</script>

<template>
  <div v-if="localStorageUsable" class="js-toggle-shortcuts">
    <gl-toggle
      v-model="shortcutsEnabled"
      :label="$options.i18n.toggleLabel"
      label-position="left"
      @change="onChange"
    />
  </div>
</template>