| 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 |
// Default auto-close durations per type (ms) |
| 32 |
// Shorten success to ~1.5s to allow immediate interactions after save |
| 33 |
const defaultDurations = { |
| 34 |
success: 1000, |
| 35 |
info: 2000, |
| 36 |
warning: 2000, |
| 37 |
error: 3000, |
| 38 |
default: 1000, |
| 39 |
} as const |
| 40 |
|
| 41 |
const type = options?.type || 'default' |
| 42 |
const resolvedZIndex = options?.zIndex ?? 100000 |
| 43 |
|
| 44 |
const mergedOptions = { |
| 45 |
...options, |
| 46 |
class: 'ivyforms-message regular-14 ivyforms-pr-8', |
| 47 |
offset: 48, |
| 48 |
zIndex: resolvedZIndex, |
| 49 |
duration: options?.duration ?? defaultDurations[type] ?? defaultDurations.default, |
| 50 |
icon: h(IvyIcon, { |
| 51 |
name: iconNames[type] || 'sticker', |
| 52 |
size: 's', |
| 53 |
outerSize: '24px', |
| 54 |
type: 'fill-duo', |
| 55 |
color: 'var(--map-base-dusk-fill--4)', |
| 56 |
}), |
| 57 |
style: { |
| 58 |
backgroundColor: messageColors[type] || messageColors.default, |
| 59 |
borderColor: messageColors[type] || messageColors.default, |
| 60 |
}, |
| 61 |
} |
| 62 |
|
| 63 |
ElMessage(mergedOptions) |
| 64 |
|
| 65 |
const style = document.createElement('style') |
| 66 |
style.textContent = ` |
| 67 |
.ivyforms-message.el-message { |
| 68 |
z-index: ${resolvedZIndex} !important; |
| 69 |
} |
| 70 |
.ivyforms-message.el-message .el-message__content { |
| 71 |
color: ${messageTextColors[type]}; |
| 72 |
} |
| 73 |
.ivyforms-message .el-message__icon .ivyforms-icon svg { |
| 74 |
width: 24px; |
| 75 |
height: 24px; |
| 76 |
fill: ${messageTextColors[type]}; |
| 77 |
} |
| 78 |
` |
| 79 |
document.head.appendChild(style) |
| 80 |
} |
| 81 |
|
| 82 |
export default IvyMessage |
| 83 |
|