import { computed, defineComponent, toRefs } from 'vue'; import classNames from '../_util/classNames'; import { isFunction } from '../_util/util'; import CloseOutlined from '@ant-design/icons-vue/CloseOutlined'; import { tourStepProps } from './interface'; import type { TourBtnProps } from './interface'; import LocaleReceiver from '../locale/LocaleReceiver'; import Button from '../button'; import type { ButtonProps } from '../button'; import defaultLocale from '../locale/en_US'; import type { VueNode } from '../_util/type'; const panelRender = defineComponent({ name: 'ATourPanel', inheritAttrs: false, props: tourStepProps(), setup(props, { attrs, slots }) { const { current, total } = toRefs(props); const isLastStep = computed(() => current.value === total.value - 1); const prevBtnClick = e => { const prevButtonProps = props.prevButtonProps as TourBtnProps; props.onPrev?.(e); if (typeof prevButtonProps?.onClick === 'function') { prevButtonProps?.onClick(); } }; const nextBtnClick = e => { const nextButtonProps = props.nextButtonProps as TourBtnProps; if (isLastStep.value) { props.onFinish?.(e); } else { props.onNext?.(e); } if (typeof nextButtonProps?.onClick === 'function') { nextButtonProps?.onClick(); } }; return () => { const { prefixCls, title, onClose, cover, description, type: stepType, arrow } = props; const prevButtonProps = props.prevButtonProps as TourBtnProps; const nextButtonProps = props.nextButtonProps as TourBtnProps; let headerNode: VueNode; if (title) { headerNode = (
{title}
); } let descriptionNode: VueNode; if (description) { descriptionNode =
{description}
; } let coverNode: VueNode; if (cover) { coverNode =
{cover}
; } let mergeIndicatorNode: VueNode; if (slots.indicatorsRender) { mergeIndicatorNode = slots.indicatorsRender({ current: current.value, total }); } else { mergeIndicatorNode = [...Array.from({ length: total.value }).keys()].map( (stepItem, index) => ( ), ); } const mainBtnType = stepType === 'primary' ? 'default' : 'primary'; const secondaryBtnProps: ButtonProps = { type: 'default', ghost: stepType === 'primary', }; return ( {contextLocale => (
{arrow &&
}
{coverNode} {headerNode} {descriptionNode}
{total.value > 1 && (
{mergeIndicatorNode}
)}
{current.value !== 0 ? ( ) : null}
)} ); }; }, }); export default panelRender;