summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/comment_type_toggle.js
blob: df337441a40ad19e51f61e14b61f0bfc42173130 (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
import DropLab from '@gitlab-org/droplab';
import InputSetter from '@gitlab-org/droplab/dist/plugins/InputSetter';

class CommentTypeToggle {
  constructor(trigger, list, input, button, secondaryButton) {
    this.trigger = trigger;
    this.list = list;
    this.input = input;
    this.button = button;
    this.secondaryButton = secondaryButton;
  }

  initDroplab() {
    this.droplab = new DropLab();

    const inputSetterConfig = [{
      input: this.input,
      valueAttribute: 'data-value',
    },
    {
      input: this.button,
      valueAttribute: 'data-button-text',
    }];
    if (this.secondaryButton) {
      inputSetterConfig.push({
        input: this.secondaryButton,
        valueAttribute: 'data-secondary-button-text',
      });
    }

    this.droplab.init(this.trigger, this.list, [InputSetter], {
      InputSetter: inputSetterConfig
    });
  }
}

export default CommentTypeToggle;