summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/registry/settings/components/expiration_toggle.vue
blob: 6aa78c69ba9e723f0a27d6e89cbea2d20f7ce5ab (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
<script>
import { GlFormGroup, GlToggle, GlSprintf } from '@gitlab/ui';
import { s__ } from '~/locale';
import { ENABLED_TOGGLE_DESCRIPTION, DISABLED_TOGGLE_DESCRIPTION } from '../constants';

export default {
  i18n: {
    toggleLabel: s__('ContainerRegistry|Enable expiration policy'),
  },
  components: {
    GlFormGroup,
    GlToggle,
    GlSprintf,
  },
  props: {
    disabled: {
      type: Boolean,
      required: false,
      default: false,
    },
    value: {
      type: Boolean,
      required: false,
      default: false,
    },
  },
  computed: {
    enabled: {
      get() {
        return this.value;
      },
      set(value) {
        this.$emit('input', value);
      },
    },
    toggleText() {
      return this.enabled ? ENABLED_TOGGLE_DESCRIPTION : DISABLED_TOGGLE_DESCRIPTION;
    },
  },
};
</script>

<template>
  <gl-form-group id="expiration-policy-toggle-group" label-for="expiration-policy-toggle">
    <div class="gl-display-flex">
      <gl-toggle
        id="expiration-policy-toggle"
        v-model="enabled"
        :label="$options.i18n.toggleLabel"
        label-position="hidden"
        :disabled="disabled"
      />
      <span class="gl-ml-5 gl-line-height-24" data-testid="description">
        <gl-sprintf :message="toggleText">
          <template #strong="{ content }">
            <strong>{{ content }}</strong>
          </template>
        </gl-sprintf>
      </span>
    </div>
  </gl-form-group>
</template>