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

segmented_control_button_group.vue « 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: e0e8200580af35fb111d556cac225d90a0e8be84 (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
<script>
import { GlButtonGroup, GlButton } from '@gitlab/ui';

const validateOptionsProp = (options) => {
  const requiredOptionPropType = {
    value: ['string', 'number', 'boolean'],
    disabled: ['boolean', 'undefined'],
  };
  const optionProps = Object.keys(requiredOptionPropType);

  return options.every((option) => {
    if (!option) {
      return false;
    }
    return optionProps.every((name) => requiredOptionPropType[name].includes(typeof option[name]));
  });
};

// TODO: We're planning to move this component to GitLab UI
//       https://gitlab.com/gitlab-org/gitlab-ui/-/issues/1787
export default {
  components: {
    GlButtonGroup,
    GlButton,
  },
  props: {
    options: {
      type: Array,
      required: true,
      validator: validateOptionsProp,
    },
    value: {
      type: [String, Number, Boolean],
      required: true,
    },
  },
};
</script>
<template>
  <gl-button-group>
    <gl-button
      v-for="opt in options"
      :key="opt.value"
      :disabled="!!opt.disabled"
      :selected="value === opt.value"
      @click="$emit('input', opt.value)"
    >
      <slot name="button-content" v-bind="opt">{{ opt.text }}</slot>
    </gl-button>
  </gl-button-group>
</template>