AmAlert.vue
238 lines
| 1 | <template> |
| 2 | <div class="am-alert-wrapper" :class="props.customClass" :style="cssVars"> |
| 3 | <el-alert |
| 4 | ref="amAlert" |
| 5 | :title="props.title" |
| 6 | :type="props.type" |
| 7 | :description="props.description" |
| 8 | :closable="props.closable" |
| 9 | :center="props.center" |
| 10 | :close-text="props.closeText" |
| 11 | :show-icon="props.showIcon" |
| 12 | :effect="props.effect" |
| 13 | class="am-alert" |
| 14 | :class="{ 'am-border': showBorder }" |
| 15 | :style="cssVars" |
| 16 | @close="() => $emit('close')" |
| 17 | > |
| 18 | <template v-if="slots.title" #title> |
| 19 | <slot name="title"></slot> |
| 20 | </template> |
| 21 | <template v-if="slots.default" #default> |
| 22 | <slot name="default"></slot> |
| 23 | </template> |
| 24 | </el-alert> |
| 25 | </div> |
| 26 | </template> |
| 27 | |
| 28 | <script setup> |
| 29 | // * Import from Vue |
| 30 | import { computed, inject, ref, useSlots } from 'vue' |
| 31 | import { useColorTransparency } from '../../../assets/js/common/colorManipulation' |
| 32 | |
| 33 | const slots = useSlots() |
| 34 | |
| 35 | /** |
| 36 | * Component Props |
| 37 | */ |
| 38 | const props = defineProps({ |
| 39 | title: { |
| 40 | type: String, |
| 41 | default: '', |
| 42 | }, |
| 43 | type: { |
| 44 | type: String, |
| 45 | default: 'info', |
| 46 | validator(value) { |
| 47 | return ['success', 'warning', 'info', 'error'].includes(value) |
| 48 | }, |
| 49 | }, |
| 50 | description: { |
| 51 | type: String, |
| 52 | default: '', |
| 53 | }, |
| 54 | closable: { |
| 55 | type: Boolean, |
| 56 | default: true, |
| 57 | }, |
| 58 | center: { |
| 59 | type: Boolean, |
| 60 | default: false, |
| 61 | }, |
| 62 | closeText: { |
| 63 | type: String, |
| 64 | default: '', |
| 65 | }, |
| 66 | showIcon: { |
| 67 | type: Boolean, |
| 68 | default: false, |
| 69 | }, |
| 70 | effect: { |
| 71 | type: String, |
| 72 | default: 'light', |
| 73 | }, |
| 74 | showBorder: { |
| 75 | type: Boolean, |
| 76 | default: false, |
| 77 | }, |
| 78 | customClass: { |
| 79 | type: String, |
| 80 | default: '', |
| 81 | }, |
| 82 | closeAfter: { |
| 83 | type: Number, |
| 84 | default: 0, |
| 85 | }, |
| 86 | }) |
| 87 | |
| 88 | /** |
| 89 | * Component Emits |
| 90 | * */ |
| 91 | const emits = defineEmits(['close', 'trigger-close']) |
| 92 | |
| 93 | /** |
| 94 | * Component reference |
| 95 | */ |
| 96 | const amAlert = ref() |
| 97 | |
| 98 | if (props.closeAfter) { |
| 99 | setTimeout(() => { |
| 100 | emits('trigger-close') |
| 101 | }, props.closeAfter) |
| 102 | } |
| 103 | |
| 104 | // * Color Vars |
| 105 | let amColors = inject('amColors', { |
| 106 | amColors: { |
| 107 | value: { |
| 108 | colorInpText: '#1A2C37', |
| 109 | }, |
| 110 | }, |
| 111 | }) |
| 112 | |
| 113 | // * Css Variables |
| 114 | let cssVars = computed(() => { |
| 115 | // alerts - alert success |
| 116 | // alerti - alert info |
| 117 | // alertw - alert warning |
| 118 | // alerte - alert error |
| 119 | return { |
| 120 | '--am-c-alert-text': amColors.value.colorMainText, |
| 121 | // success |
| 122 | '--am-c-alerts-bgr': amColors.value.colorSuccess, |
| 123 | '--am-c-alerts-bgr-op10': useColorTransparency(amColors.value.colorSuccess, 0.1), |
| 124 | '--am-c-alerts-bgr-op60': useColorTransparency(amColors.value.colorSuccess, 0.6), |
| 125 | // info |
| 126 | '--am-c-alerti-bgr': amColors.value.colorPrimary, |
| 127 | '--am-c-alerti-bgr-op10': useColorTransparency(amColors.value.colorPrimary, 0.1), |
| 128 | '--am-c-alerti-bgr-op60': useColorTransparency(amColors.value.colorPrimary, 0.6), |
| 129 | // warning |
| 130 | '--am-c-alertw-bgr': amColors.value.colorWarning, |
| 131 | '--am-c-alertw-bgr-op10': useColorTransparency(amColors.value.colorWarning, 0.1), |
| 132 | '--am-c-alertw-bgr-op60': useColorTransparency(amColors.value.colorWarning, 0.6), |
| 133 | // error |
| 134 | '--am-c-alerte-bgr': amColors.value.colorError, |
| 135 | '--am-c-alerte-bgr-op10': useColorTransparency(amColors.value.colorError, 0.1), |
| 136 | '--am-c-alerte-bgr-op60': useColorTransparency(amColors.value.colorError, 0.6), |
| 137 | } |
| 138 | }) |
| 139 | </script> |
| 140 | |
| 141 | <style lang="scss"> |
| 142 | @mixin am-alert-block { |
| 143 | .am-alert-wrapper { |
| 144 | // -c- color |
| 145 | // -rad- border radius |
| 146 | // -h- height |
| 147 | // -fs- font size |
| 148 | // -padd- padding |
| 149 | // -bgr- background |
| 150 | |
| 151 | .el-alert { |
| 152 | padding: 8px 12px; |
| 153 | border-radius: 6px; |
| 154 | box-sizing: border-box; |
| 155 | |
| 156 | &.am-border { |
| 157 | background-color: transparent; |
| 158 | border-width: 1px 1px 4px 1px; |
| 159 | } |
| 160 | |
| 161 | &--success { |
| 162 | background-color: var(--am-c-alerts-bgr-op10); |
| 163 | border: 1px solid var(--am-c-alerts-bgr-op60); |
| 164 | box-shadow: 0 2px 3px var(--am-c-alerts-bgr-op10); |
| 165 | |
| 166 | &.am-border { |
| 167 | border-color: var(--am-c-alerts-bgr); |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | &--info { |
| 172 | background-color: var(--am-c-alerti-bgr-op10); |
| 173 | border: 1px solid var(--am-c-alerti-bgr-op60); |
| 174 | box-shadow: 0 2px 3px var(--am-c-alerti-bgr-op10); |
| 175 | |
| 176 | &.am-border { |
| 177 | border-color: var(--am-c-alerti-bgr); |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | &--error { |
| 182 | background-color: var(--am-c-alerte-bgr-op10); |
| 183 | border: 1px solid var(--am-c-alerte-bgr-op60); |
| 184 | box-shadow: 0 2px 3px var(--am-c-alerte-bgr-op10); |
| 185 | |
| 186 | &.am-border { |
| 187 | border-color: var(--am-c-alerte-bgr); |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | &--warning { |
| 192 | background-color: var(--am-c-alertw-bgr-op10); |
| 193 | border: 1px solid var(--am-c-alertw-bgr-op60); |
| 194 | box-shadow: 0 2px 3px var(--am-c-alertw-bgr-op10); |
| 195 | |
| 196 | &.am-border { |
| 197 | border-color: var(--am-c-alertw-bgr); |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | &__title { |
| 202 | font-weight: 500; |
| 203 | font-size: 14px; |
| 204 | line-height: 24px; |
| 205 | /* $shade-900 */ |
| 206 | color: var(--am-c-alert-text); |
| 207 | } |
| 208 | |
| 209 | &__description { |
| 210 | font-weight: 400; |
| 211 | font-size: 13px; |
| 212 | line-height: 20px; |
| 213 | /* $shade-900 */ |
| 214 | color: var(--am-c-alert-text); |
| 215 | } |
| 216 | |
| 217 | &__icon { |
| 218 | margin-right: 11px; |
| 219 | } |
| 220 | |
| 221 | &__closebtn { |
| 222 | color: var(--am-c-alert-text); |
| 223 | } |
| 224 | } |
| 225 | } |
| 226 | } |
| 227 | |
| 228 | // public |
| 229 | .amelia-v2-booking #amelia-container { |
| 230 | @include am-alert-block; |
| 231 | } |
| 232 | |
| 233 | // admin |
| 234 | #amelia-app-backend-new { |
| 235 | @include am-alert-block; |
| 236 | } |
| 237 | </style> |
| 238 |