| 1 |
import { ElMessage } from 'element-plus' |
| 2 |
import 'element-plus/es/components/message/style/css' |
| 3 |
import { h } from 'vue' |
| 4 |
import IvyIcon from '@/views/_components/icon/IvyIcon.vue' |
| 5 |
|
| 6 |
const IvyMessage = (options) => { |
| 7 |
const messageColors = { |
| 8 |
success: 'var(--map-status-success-fill-0)', |
| 9 |
warning: 'var(--map-status-warning-fill-0)', |
| 10 |
error: 'var(--map-status-error-fill-0)', |
| 11 |
info: 'var(--map-base-purple-fill-0)', |
| 12 |
default: 'var(--map-base-dusk-fill-4)', |
| 13 |
} |
| 14 |
|
| 15 |
const messageTextColors = { |
| 16 |
success: 'var(--primitive-white)', |
| 17 |
warning: 'var(--primitive-white)', |
| 18 |
error: 'var(--primitive-white)', |
| 19 |
info: 'var(--primitive-white)', |
| 20 |
default: 'var(--map-base-dusk-fill--4)', |
| 21 |
} |
| 22 |
|
| 23 |
const iconNames = { |
| 24 |
success: 'check-circle', |
| 25 |
warning: 'danger', |
| 26 |
error: 'danger', |
| 27 |
info: 'danger', |
| 28 |
default: 'sticker', |
| 29 |
} |
| 30 |
|
| 31 |
const mergedOptions = { |
| 32 |
...options, |
| 33 |
class: 'ivyforms-message regular-14 ivyforms-pr-8', |
| 34 |
offset: 48, |
| 35 |
icon: h(IvyIcon, { |
| 36 |
name: iconNames[options.type] || 'sticker', |
| 37 |
size: 's', |
| 38 |
outerSize: '24px', |
| 39 |
type: 'fill-duo', |
| 40 |
color: 'var(--map-base-dusk-fill--4)', |
| 41 |
}), |
| 42 |
style: { |
| 43 |
backgroundColor: messageColors[options.type] || messageColors.default, |
| 44 |
borderColor: messageColors[options.type] || messageColors.default, |
| 45 |
}, |
| 46 |
} |
| 47 |
|
| 48 |
ElMessage(mergedOptions) |
| 49 |
|
| 50 |
const style = document.createElement('style') |
| 51 |
style.textContent = ` |
| 52 |
.ivyforms-message.el-message .el-message__content { |
| 53 |
color: ${messageTextColors[options.type]}; |
| 54 |
} |
| 55 |
.ivyforms-message .el-message__icon .ivyforms-icon svg { |
| 56 |
width: 24px; |
| 57 |
height: 24px; |
| 58 |
fill: ${messageTextColors[options.type]}; |
| 59 |
} |
| 60 |
` |
| 61 |
document.head.appendChild(style) |
| 62 |
} |
| 63 |
|
| 64 |
export default IvyMessage |
| 65 |
|