• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

uiv-lib / uiv / 7229750628

16 Dec 2023 12:21AM CUT coverage: 86.79%. Remained the same
7229750628

push

github

web-flow
chore(deps): update dependency eslint to v8.56.0

859 of 1065 branches covered (0.0%)

Branch coverage included in aggregate %.

1539 of 1698 relevant lines covered (90.64%)

185.22 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

78.64
/src/components/messagebox/MessageBox.vue
1
<template>
2
  <modal
3
    ref="modal"
4
    v-model="show"
27✔
5
    auto-focus
6
    :size="size"
7
    :title="title"
27✔
8
    :header="!!title"
9
    :backdrop="closeOnBackdropClick"
10
    :cancel-text="cancelText"
11
    :ok-text="okText"
12
    :class="customClass"
13
    @hide="cb"
14
  >
15
    <div v-if="html" v-html="content"></div>
16
    <p v-else>{{ content }}</p>
17
    <div v-if="type === TYPES.PROMPT">
18
      <div class="form-group" :class="{ 'has-error': inputNotValid }">
19
        <input
20
          v-model="input"
21
          :type="inputType"
22
          class="form-control"
23
          required
24
          data-action="auto-focus"
25
          @change="dirty = true"
26
          @keyup.enter="validate"
27
        />
27✔
28
        <span v-show="inputNotValid" class="help-block">{{ inputError }}</span>
29
      </div>
30
    </div>
31
    <template v-if="type === TYPES.ALERT" #footer>
32
      <btn
33
        :type="okType"
34
        :data-action="autoFocus === 'ok' ? 'auto-focus' : ''"
35
        @click="hide('ok')"
36
        >{{ okBtnText }}</btn
37
      >
38
    </template>
39
    <template v-else #footer>
40
      <template v-if="reverseButtons">
41
        <btn
42
          v-if="type === TYPES.CONFIRM"
43
          :type="okType"
44
          :data-action="autoFocus === 'ok' ? 'auto-focus' : ''"
45
          @click="hide('ok')"
46
          >{{ okBtnText }}</btn
47
        >
48
        <btn v-else :type="okType" @click="validate">{{ okBtnText }}</btn>
49
        <btn
50
          :type="cancelType"
51
          :data-action="autoFocus === 'cancel' ? 'auto-focus' : ''"
52
          @click="hide('cancel')"
53
          >{{ cancelBtnText }}</btn
54
        >
55
      </template>
56
      <template v-else>
57
        <btn
58
          :type="cancelType"
59
          :data-action="autoFocus === 'cancel' ? 'auto-focus' : ''"
60
          @click="hide('cancel')"
61
          >{{ cancelBtnText }}</btn
62
        >
63
        <btn
64
          v-if="type === TYPES.CONFIRM"
65
          :type="okType"
66
          :data-action="autoFocus === 'ok' ? 'auto-focus' : ''"
67
          @click="hide('ok')"
68
          >{{ okBtnText }}</btn
69
        >
70
        <btn v-else :type="okType" @click="validate">{{ okBtnText }}</btn>
71
      </template>
72
    </template>
73
  </modal>
74
</template>
75

76
<script setup>
4✔
77
import { TYPES } from '../../constants/messagebox.constants';
78
import { t } from '../../locale';
79
import Modal from '../../components/modal/Modal.vue';
80
import Btn from '../../components/button/Btn.vue';
81
import { isExist } from '../../utils/object.utils';
82
import { computed, ref } from 'vue';
83

84
const props = defineProps({
85
  backdrop: { type: null, default: undefined },
86
  title: { type: String, default: undefined },
87
  content: { type: String, default: undefined },
88
  html: { type: Boolean, default: false },
89
  okText: { type: String, default: undefined },
90
  okType: { type: String, default: 'primary' },
91
  cancelText: { type: String, default: undefined },
92
  cancelType: { type: String, default: 'default' },
93
  type: { type: Number, default: 0 },
94
  size: { type: String, default: 'sm' },
95
  cb: { type: Function, required: true },
96
  validator: {
97
    type: Function,
98
    default: () => null,
99
  },
100
  customClass: { type: null, default: undefined },
101
  defaultValue: { type: String, default: undefined },
102
  inputType: { type: String, default: 'text' },
16✔
103
  autoFocus: { type: String, default: 'ok' },
16✔
104
  reverseButtons: { type: Boolean, default: false },
105
});
106

16✔
107
const show = ref(true);
108
// eslint-disable-next-line vue/no-setup-props-destructure
109
const input = ref(props.defaultValue ?? '');
110
const dirty = ref(false);
111
const modal = ref(null);
112

113
const closeOnBackdropClick = computed(() =>
114
  isExist(props.backdrop) ? !!props.backdrop : props.type !== TYPES.ALERT
16✔
115
);
116
const inputError = computed(() => props.validator(input.value));
117
const inputNotValid = computed(() => dirty.value && inputError.value);
118
const okBtnText = computed(() => props.okText || t('uiv.modal.ok'));
31✔
119
const cancelBtnText = computed(() => props.cancelText || t('uiv.modal.cancel'));
120

121
function hide(msg) {
16✔
122
  modal.value?.hideModal(msg);
123
}
124

125
function validate() {
126
  dirty.value = true;
127
  if (!isExist(inputError.value)) {
128
    hide({ value: input.value });
16✔
129
  }
130
}
131
</script>
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc