import { computed, defineComponent, type PropType, ref, Teleport } from 'vue'; import { DefaultComponentProps } from '../_default'; import BCMSIcon from '../icon'; import { useTranslation } from '../../translations'; const component = defineComponent({ props: { ...DefaultComponentProps, position: { type: String as PropType<'left' | 'right'>, default: 'left', }, optionsWidth: { type: Number, required: false, }, orientation: { type: String as PropType<'vertical' | 'horizontal'>, default: 'vertical', }, title: { type: String, default: '', }, }, setup(props, ctx) { const translations = computed(() => { return useTranslation(); }); const listRef = ref(null); const menuContainer = ref(null); const show = ref(false); const toggler = ref(null); function calcPosition() { if (listRef.value && menuContainer.value) { const parent = menuContainer.value; const parentBB = parent.getBoundingClientRect(); const el = listRef.value; const style: string[] = []; if (parentBB.top + el.offsetHeight > window.innerHeight) { style.push( `top: ${ parentBB.top - el.offsetHeight + document.body.scrollTop }px !important;`, ); } else { style.push( `top: ${ parentBB.bottom + 15 + document.body.scrollTop }px !important;`, ); } if (parentBB.left + el.offsetWidth > window.innerWidth) { style.push( `left: ${ parentBB.left - el.offsetWidth + parent.offsetWidth }px !important;`, ); } else { style.push(`left: ${parentBB.left}px !important;`); } if (props.optionsWidth) { style.push(`width: ${props.optionsWidth}px !important;`); } el.setAttribute('style', style.join(' ')); } } function handleClick() { if (!show.value) { show.value = true; setTimeout(() => { calcPosition(); }, 20); } else { show.value = false; } } return () => { return (
); }; }, }); export default component;