// Utils
import { createNamespace, isDef } from '../utils';
import { routeProps } from '../utils/router';
import { cellProps } from './shared';
// Components
import Icon from '../icon';
const [createComponent, bem] = createNamespace('cell');
export default createComponent({
props: {
...cellProps,
...routeProps,
},
setup(props, { slots, emit }) {
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) {
emit('click', event);
// TODO
// functionalRoute(ctx);
}
const clickable = isLink || props.clickable;
const classes = {
clickable,
center: props.center,
required: props.required,
borderless: !props.border,
};
if (size) {
classes[size] = size;
}
return function () {
return (
{LeftIcon()}
{Title()}
{Value()}
{RightIcon()}
{slots.extra?.()}
);
};
},
});