import { PropType, CSSProperties, defineComponent } from 'vue'; // Utils import { createNamespace, extend, isDef, truthProp, unknownProp, } from '../utils'; // Composables import { useRoute, routeProps } from '../composables/use-route'; // Components import { Icon } from '../icon'; const [name, bem] = createNamespace('cell'); export type CellArrowDirection = 'up' | 'down' | 'left' | 'right'; export const cellProps = { icon: String, size: String as PropType<'large'>, title: [Number, String], value: [Number, String], label: [Number, String], center: Boolean, isLink: Boolean, border: truthProp, required: Boolean, iconPrefix: String, valueClass: unknownProp, labelClass: unknownProp, titleClass: unknownProp, titleStyle: (null as unknown) as PropType, arrowDirection: String as PropType, clickable: { type: Boolean as PropType, default: null, }, }; export default defineComponent({ name, props: extend({}, cellProps, routeProps), setup(props, { slots }) { const route = useRoute(); const renderLabel = () => { const showLabel = slots.label || isDef(props.label); if (showLabel) { return (
{slots.label ? slots.label() : props.label}
); } }; const renderTitle = () => { if (slots.title || isDef(props.title)) { return (
{slots.title ? slots.title() : {props.title}} {renderLabel()}
); } }; const renderValue = () => { const hasValue = slots.default || isDef(props.value); if (hasValue) { const hasTitle = slots.title || isDef(props.title); return (
{slots.default ? slots.default() : {props.value}}
); } }; const renderLeftIcon = () => { if (slots.icon) { return slots.icon(); } if (props.icon) { return ( ); } }; const renderRightIcon = () => { if (slots['right-icon']) { return slots['right-icon'](); } if (props.isLink) { const name = props.arrowDirection ? `arrow-${props.arrowDirection}` : 'arrow'; return ; } }; return () => { const { size, center, border, isLink, required } = props; const clickable = props.clickable ?? isLink; const classes: Record = { center, required, clickable, borderless: !border, }; if (size) { classes[size] = !!size; } return (
{renderLeftIcon()} {renderTitle()} {renderValue()} {renderRightIcon()} {slots.extra?.()}
); }; }, });