Welcome to mirror list, hosted at ThFree Co, Russian Federation.

settings_block.vue « settings « components « vue_shared « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e68f0f31c13f322406d83884116d2f33ecc23dfe (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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<script>
import { GlButton } from '@gitlab/ui';
import { uniqueId } from 'lodash';

import { __ } from '~/locale';

export default {
  components: { GlButton },
  props: {
    slideAnimated: {
      type: Boolean,
      default: true,
      required: false,
    },
    defaultExpanded: {
      type: Boolean,
      default: false,
      required: false,
    },
    collapsible: {
      type: Boolean,
      default: true,
      required: false,
    },
  },
  data() {
    const forceOpen = !this.collapsible || this.defaultExpanded;
    return {
      // Non-collapsible sections should always be expanded.
      // For collapsible sections, fall back to defaultExpanded.
      sectionExpanded: forceOpen,
      initialised: forceOpen,
      animating: false,
    };
  },
  computed: {
    toggleText() {
      const { collapseText, expandText } = this.$options.i18n;
      return this.sectionExpanded ? collapseText : expandText;
    },
    settingsContentId() {
      return uniqueId('settings_content_');
    },
    settingsLabelId() {
      return uniqueId('settings_label_');
    },
    toggleButtonAriaLabel() {
      const { collapseAriaLabel, expandAriaLabel } = this.$options.i18n;
      return this.sectionExpanded ? collapseAriaLabel : expandAriaLabel;
    },
    ariaExpanded() {
      return String(this.sectionExpanded);
    },
  },
  methods: {
    toggleSectionExpanded() {
      this.sectionExpanded = !this.sectionExpanded;

      if (!this.initialised) {
        this.initialised = true;
      }

      if (this.sectionExpanded) {
        this.animating = true;
        this.$refs.settingsContent.focus();
      }
    },
  },
  i18n: {
    collapseText: __('Collapse'),
    expandText: __('Expand'),
    collapseAriaLabel: __('Collapse settings section'),
    expandAriaLabel: __('Expand settings section'),
  },
};
</script>

<template>
  <section
    class="settings"
    :class="{ 'no-animate': !slideAnimated, expanded: sectionExpanded, animating }"
  >
    <div class="settings-header">
      <h4>
        <span
          v-if="collapsible"
          :id="settingsLabelId"
          role="button"
          tabindex="0"
          class="gl-cursor-pointer"
          :aria-controls="settingsContentId"
          :aria-expanded="ariaExpanded"
          data-testid="section-title-button"
          @click="toggleSectionExpanded"
          @keydown.enter.space="toggleSectionExpanded"
        >
          <slot name="title"></slot>
        </span>
        <template v-else>
          <slot name="title"></slot>
        </template>
      </h4>
      <gl-button
        v-if="collapsible"
        :aria-controls="settingsContentId"
        :aria-expanded="ariaExpanded"
        :aria-label="toggleButtonAriaLabel"
        @click="toggleSectionExpanded"
      >
        {{ toggleText }}
      </gl-button>
      <p>
        <slot name="description"></slot>
      </p>
    </div>
    <div
      v-show="initialised"
      :id="settingsContentId"
      ref="settingsContent"
      :aria-labelledby="settingsLabelId"
      tabindex="-1"
      role="region"
      class="settings-content"
      @animationend="animating = false"
    >
      <slot></slot>
    </div>
  </section>
</template>