diff --git a/src/cell/index.js b/src/cell/index.js index dba2ff074..e7b7db6bd 100644 --- a/src/cell/index.js +++ b/src/cell/index.js @@ -14,107 +14,93 @@ export default createComponent({ ...routeProps, }, - emits: ['click'], + setup(props, { slots }) { + const renderLabel = () => { + const showLabel = slots.label || isDef(props.label); - setup(props, { slots, emit }) { - return function () { - const { icon, size, title, label, value, isLink } = props; - const titleSlot = slots.title?.(); - const showTitle = titleSlot || isDef(title); + if (showLabel) { + return ( +
+ {slots.label ? slots.label() : props.label} +
+ ); + } + }; - function Label() { - const showLabel = slots.label || isDef(label); + const renderTitle = () => { + if (slots.title || isDef(props.title)) { + return ( +
+ {slots.title ? slots.title() : {props.title}} + {renderLabel()} +
+ ); + } + }; - if (showLabel) { - return ( -
- {slots.label ? slots.label() : label} -
- ); - } + const renderValue = () => { + const hasTitle = slots.title || isDef(props.title); + const hasValue = slots.default || isDef(props.value); + + if (hasValue) { + return ( +
+ {slots.default ? slots.default() : {props.value}} +
+ ); + } + }; + + const renderLeftIcon = () => { + if (slots.icon) { + return slots.icon(); } - function Title() { - if (showTitle) { - return ( -
- {slots.title ? titleSlot : {title}} - {Label()} -
- ); - } + if (props.icon) { + return ( + + ); + } + }; + + const renderRightIcon = () => { + if (slots['right-icon']) { + return slots['right-icon'](); } - function Value() { - const showValue = slots.default || isDef(value); - - if (showValue) { - return ( -
- {slots.default ? slots.default() : {value}} -
- ); - } + if (props.isLink) { + const name = props.arrowDirection + ? `arrow-${props.arrowDirection}` + : 'arrow'; + return ; } + }; - 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 ( - - ); - } - } - - const onClick = (event) => { - emit('click', event); - route(this.$router, this); - }; - + return (vm) => { + const { size, center, border, isLink, required } = props; const clickable = isLink || props.clickable; const classes = { + center, + required, clickable, - center: props.center, - required: props.required, - borderless: !props.border, + borderless: !border, }; - if (size) { classes[size] = size; } + const onClick = () => { + route(vm.$router, vm); + }; + return (
- {LeftIcon()} - {Title()} - {Value()} - {RightIcon()} + {renderLeftIcon()} + {renderTitle()} + {renderValue()} + {renderRightIcon()} {slots.extra?.()}
);