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