summaryrefslogtreecommitdiff
path: root/src/components/_sila/Global/SilaComponents/PopoverWithSlot.vue
blob: 4c908083697c814a9b7787ecfbae78c4c328061d (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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
<template>
  <div id="popover-container">
    <slot />
    <b-popover
      ref="popover"
      :target="id"
      triggers="focus"
      :show.sync="popoverShow"
      :placement="placement"
      container="popover-container"
      @show="onShow"
      @shown="onShown"
      @hidden="onHidden"
    >
      <template #title>
        <div class="popup-title">
          <span class="bold-16px__caps">{{ popupLabel }}</span>
          <b-button class="popup-title__button_close" @click="onClose">
            <img src="@/assets/images/_sila/popups/x-icon.svg" />
          </b-button>
        </div>
      </template>

      <div class="popup-body">
        <div>
          <label class="light-12px" style="margin-right: 5px">{{
            'HEX для ввода'
          }}</label>
          <img
            id="popover-tooltip"
            src="@/assets/images/_sila/popups/red-sign.svg"
          />
          <popover-info
            id="popover-tooltip"
            description="Введите HEX в поле для подтверждения действия"
          />
          <div class="hex-label">
            <span class="medium-12px"> 9c1735b3f819142393146a5d03314f0a </span>
          </div>
        </div>
        <div class="popup-body__input-container">
          <span style="margin-left: 12px" class="regular-12px tretiatry"
            >Поле для ввода</span
          >
          <b-form-input
            id="popover-input-1"
            ref="input"
            v-model="input"
            class="medium-12px"
          ></b-form-input>
        </div>
        <b-button
          class="popup-button"
          variant="primary"
          :disabled="!input"
          @click="onOk"
        >
          {{ buttonLabel }}
        </b-button>
      </div>
    </b-popover>
  </div>
</template>

<script>
import PopoverInfo from '../PopoverInfo';
import BVToastMixin from '@/components/_sila/Mixins/BVToastMixin';
export default {
  components: {
    PopoverInfo,
  },
  mixins: [BVToastMixin],
  props: {
    id: {
      type: String,
      default: '',
    },
    placement: {
      type: String,
      default: 'auto',
    },
    popupLabel: {
      type: String,
      default: '',
    },
    buttonLabel: {
      type: String,
      default: 'global.action.reload',
    },
    action: {
      type: Function,
      default: null,
    },
  },
  data() {
    return {
      input: '',
      popoverShow: false,
    };
  },
  methods: {
    onClose() {
      this.popoverShow = false;
    },
    onOk() {
      if (this.input === '9c1735b3f819142393146a5d03314f0a') {
        this.action();
        this.onClose();
      } else {
        this.warningToast(
          this.$t('Неправильный HEX в поле для подтверждения действия'),
          {
            title: this.$t('Неправильный НЕХ'),
          }
        );
      }
    },
    onShow() {
      // This is called just before the popover is shown
      // Reset our popover form variables
      this.$root.$emit('bv::hide::popover');
      this.input = '';
    },
    onShown() {
      // Called just after the popover has been shown
      // Transfer focus to the first input
      this.focusRef(this.$refs.input);
    },
    onHidden() {
      // Called just after the popover has finished hiding
      // Bring focus back to the button
      // this.focusRef(this.$refs.button);
    },
    focusRef(ref) {
      // Some references may be a component, functional component, or plain element
      // This handles that check before focusing, assuming a `focus()` method exists
      // We do this in a double `$nextTick()` to ensure components have
      // updated & popover positioned first
      this.$nextTick(() => {
        this.$nextTick(() => {
          (ref.$el || ref).focus();
        });
      });
    },
  },
};
</script>
<style lang="scss" scoped>
.form-group {
  margin: 0;
}

.popup-title {
  display: flex;
  flex-flow: row nowrap;
  align-items: baseline;
}

.popup-title__button_close {
  margin: 0 28px 0 auto;
  background: none;
  border: none;
  height: 25px;
  &:active {
    background-color: $faint-secondary-primary-5-hover !important;
    box-shadow: none !important;
    border-radius: 8px;
  }
  &:focus-visible {
    border: none !important;
    border-radius: 8px;
  }
  &:focus {
    box-shadow: none;
    border-radius: 8px;
  }
}

.popup-body {
  display: flex;
  flex-direction: column;
  align-content: center;
  justify-content: center;
  align-items: center;
}

.form-control {
  width: 341px;
  height: 52px;
  margin: -25px auto;
  padding-top: 30px;
}

.hex-label {
  height: 32px;
  width: 341px;
  display: flex;
  justify-content: center;
  align-items: center;
  background: $faint-secondary-primary-5;
  border-radius: 8px;
  border: none;
  margin: 0 auto;
}

.popup-button {
  width: 341px;
  height: 40px;
  margin-bottom: 10px;
}

.popup-body__input-container {
  height: 52px;
  margin: 24px auto 16px auto;
}

.popover-info {
  background-color: $on-surface-primary;
  // border: 1px solid $text-primary;
  // box-shadow: 0px 6px 16px -12px rgba(23, 40, 77, 0.06);
  border-radius: 8px;
  width: 168px;
  height: 76px;
  &.arrow {
    display: block;
  }
}
</style>