mirror of
https://github.com/element-plus/element-plus.git
synced 2026-03-13 07:51:17 +08:00
* feat(components): [message] add `placement` option & method * fix: resolve test hanging issue caused by reactive circular dependency * test: add test * feat: add placement `top-left/top-right/bottom-left/bottom-right` * refactor: split large normalizeOptions function * docs: adjust description text * chore: remove unused height expose * refactor: simpify code * style: opt-in center style & simplified animations * style: replace :not(.center) with :is(.left,.right) for more explicit * feat: add `placement` to `config-provider` * fix: fix test warning when placement is undefined * refactor: remove useless style & simpify types * fix: avoid circular dependency * chore: types related * Update docs/examples/config-provider/message.vue Co-authored-by: Noblet Ouways <91417411+Dsaquel@users.noreply.github.com> * Update packages/components/config-provider/__tests__/config-provider.test.tsx Co-authored-by: Noblet Ouways <91417411+Dsaquel@users.noreply.github.com> * chore: make typecheck happy & format * style: add top/bottom transition * chore: format --------- Co-authored-by: zhixiaotong <947803089@qq.com> Co-authored-by: Noblet Ouways <91417411+Dsaquel@users.noreply.github.com> Co-authored-by: Dsaquel <291874700n@gmail.com>
55 lines
1.5 KiB
TypeScript
55 lines
1.5 KiB
TypeScript
import { shallowReactive } from 'vue'
|
|
|
|
import type { ComponentInternalInstance, VNode } from 'vue'
|
|
import type { Mutable } from '@element-plus/utils'
|
|
import type { MessageHandler, MessagePlacement, MessageProps } from './message'
|
|
|
|
export type MessageContext = {
|
|
id: string
|
|
vnode: VNode
|
|
handler: MessageHandler
|
|
vm: ComponentInternalInstance
|
|
props: Mutable<MessageProps>
|
|
}
|
|
|
|
export const placementInstances = shallowReactive(
|
|
{} as Record<MessagePlacement, MessageContext[]>
|
|
)
|
|
|
|
export const getOrCreatePlacementInstances = (placement: MessagePlacement) => {
|
|
if (!placementInstances[placement]) {
|
|
placementInstances[placement] = shallowReactive([])
|
|
}
|
|
return placementInstances[placement]
|
|
}
|
|
|
|
export const getInstance = (id: string, placement: MessagePlacement) => {
|
|
const instances = placementInstances[placement] || []
|
|
const idx = instances.findIndex((instance) => instance.id === id)
|
|
const current = instances[idx]
|
|
let prev: MessageContext | undefined
|
|
if (idx > 0) {
|
|
prev = instances[idx - 1]
|
|
}
|
|
return { current, prev }
|
|
}
|
|
|
|
export const getLastOffset = (
|
|
id: string,
|
|
placement: MessagePlacement
|
|
): number => {
|
|
const { prev } = getInstance(id, placement)
|
|
if (!prev) return 0
|
|
return prev.vm.exposed!.bottom.value
|
|
}
|
|
|
|
export const getOffsetOrSpace = (
|
|
id: string,
|
|
offset: number,
|
|
placement: MessagePlacement
|
|
) => {
|
|
const instances = placementInstances[placement] || []
|
|
const idx = instances.findIndex((instance) => instance.id === id)
|
|
return idx > 0 ? 16 : offset
|
|
}
|