import { ref, CSSProperties, defineComponent } from 'vue'; // Utils import { createNamespace, getZIndexStyle } from '../utils'; import { BORDER_BOTTOM } from '../utils/constant'; // Composables import { usePlaceholder } from '../composables/use-placeholder'; // Components import { Icon } from '../icon'; const [name, bem] = createNamespace('nav-bar'); export default defineComponent({ name, props: { title: String, fixed: Boolean, zIndex: [Number, String], leftText: String, rightText: String, leftArrow: Boolean, placeholder: Boolean, safeAreaInsetTop: Boolean, border: { type: Boolean, default: true, }, }, emits: ['click-left', 'click-right'], setup(props, { emit, slots }) { const navBarRef = ref(); const renderPlaceholder = usePlaceholder(navBarRef, bem); const onClickLeft = (event: MouseEvent) => emit('click-left', event); const onClickRight = (event: MouseEvent) => emit('click-right', event); const renderLeft = () => { if (slots.left) { return slots.left(); } return [ props.leftArrow && , props.leftText && {props.leftText}, ]; }; const renderRight = () => { if (slots.right) { return slots.right(); } return {props.rightText}; }; const renderNavBar = () => { const { title, fixed, border, zIndex } = props; const style: CSSProperties = getZIndexStyle(zIndex); const hasLeft = props.leftArrow || props.leftText || slots.left; const hasRight = props.rightText || slots.right; return (
{hasLeft && (
{renderLeft()}
)}
{slots.title ? slots.title() : title}
{hasRight && (
{renderRight()}
)}
); }; return () => { if (props.fixed && props.placeholder) { return renderPlaceholder(renderNavBar); } return renderNavBar(); }; }, });