import { createNamespace, isDef } from '../utils'; import { cellProps, SharedCellProps } from './shared'; import { emit, inherit } from '../utils/functional'; import { routeProps, RouteProps, functionalRoute } from '../utils/router'; import Icon from '../icon'; // Types import { CreateElement, RenderContext } from 'vue/types'; import { ScopedSlot, DefaultSlots } from '../utils/types'; import { Mods } from '../utils/create/bem'; export type CellProps = RouteProps & SharedCellProps; export type CellSlots = DefaultSlots & { icon?: ScopedSlot; title?: ScopedSlot; label?: ScopedSlot; extra?: ScopedSlot; 'right-icon'?: ScopedSlot; }; export type CellEvents = { onClick?(event: Event): void; }; const [createComponent, bem] = createNamespace('cell'); function Cell( h: CreateElement, props: CellProps, slots: CellSlots, ctx: RenderContext ) { const { icon, size, title, label, value, isLink } = props; const showTitle = slots.title || isDef(title); function Label() { const showLabel = slots.label || isDef(label); if (showLabel) { return (
{slots.label ? slots.label() : label}
); } } function Title() { if (showTitle) { return (
{slots.title ? slots.title() : {title}} {Label()}
); } } function Value() { const showValue = slots.default || isDef(value); if (showValue) { return (
{slots.default ? slots.default() : {value}}
); } } function LeftIcon() { if (slots.icon) { return slots.icon(); } if (icon) { return ; } } function RightIcon() { const rightIconSlot = slots['right-icon']; if (rightIconSlot) { return rightIconSlot(); } if (isLink) { const { arrowDirection } = props; return ( ); } } function onClick(event: Event) { emit(ctx, 'click', event); functionalRoute(ctx); } const clickable = isLink || props.clickable; const classes: Mods = { clickable, center: props.center, required: props.required, borderless: !props.border }; if (size) { classes[size] = size; } return (
{LeftIcon()} {Title()} {Value()} {RightIcon()} {slots.extra?.()}
); } Cell.props = { ...cellProps, ...routeProps }; export default createComponent(Cell);