mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-24 10:20:19 +08:00
chore(Cell): improve jsx segment
This commit is contained in:
parent
2b51ead3cb
commit
9c6ae2c28b
@ -31,44 +31,72 @@ function Cell(
|
|||||||
slots: CellSlots,
|
slots: CellSlots,
|
||||||
ctx: RenderContext<CellProps>
|
ctx: RenderContext<CellProps>
|
||||||
) {
|
) {
|
||||||
const { icon, size, title, label, value, isLink, arrowDirection } = props;
|
const { icon, size, title, label, value, isLink } = props;
|
||||||
|
|
||||||
const showTitle = slots.title || isDef(title);
|
const showTitle = slots.title || isDef(title);
|
||||||
const showValue = slots.default || isDef(value);
|
|
||||||
|
function Label() {
|
||||||
const showLabel = slots.label || isDef(label);
|
const showLabel = slots.label || isDef(label);
|
||||||
|
|
||||||
const Label = showLabel && (
|
if (showLabel) {
|
||||||
|
return (
|
||||||
<div class={[bem('label'), props.labelClass]}>
|
<div class={[bem('label'), props.labelClass]}>
|
||||||
{slots.label ? slots.label() : label}
|
{slots.label ? slots.label() : label}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const Title = showTitle && (
|
function Title() {
|
||||||
|
if (showTitle) {
|
||||||
|
return (
|
||||||
<div class={[bem('title'), props.titleClass]} style={props.titleStyle}>
|
<div class={[bem('title'), props.titleClass]} style={props.titleStyle}>
|
||||||
{slots.title ? slots.title() : <span>{title}</span>}
|
{slots.title ? slots.title() : <span>{title}</span>}
|
||||||
{Label}
|
{Label()}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const Value = showValue && (
|
function Value() {
|
||||||
<div class={[bem('value', { alone: !slots.title && !title }), props.valueClass]}>
|
const showValue = slots.default || isDef(value);
|
||||||
|
|
||||||
|
if (showValue) {
|
||||||
|
return (
|
||||||
|
<div class={[bem('value', { alone: !showTitle }), props.valueClass]}>
|
||||||
{slots.default ? slots.default() : <span>{value}</span>}
|
{slots.default ? slots.default() : <span>{value}</span>}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const LeftIcon = slots.icon
|
function LeftIcon() {
|
||||||
? slots.icon()
|
if (slots.icon) {
|
||||||
: icon && <Icon class={bem('left-icon')} name={icon} />;
|
return slots.icon();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (icon) {
|
||||||
|
return <Icon class={bem('left-icon')} name={icon} />;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function RightIcon() {
|
||||||
const rightIconSlot = slots['right-icon'];
|
const rightIconSlot = slots['right-icon'];
|
||||||
const RightIcon = rightIconSlot
|
|
||||||
? rightIconSlot()
|
if (rightIconSlot) {
|
||||||
: isLink && (
|
return rightIconSlot();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isLink) {
|
||||||
|
const { arrowDirection } = props;
|
||||||
|
|
||||||
|
return (
|
||||||
<Icon
|
<Icon
|
||||||
class={bem('right-icon')}
|
class={bem('right-icon')}
|
||||||
name={arrowDirection ? `arrow-${arrowDirection}` : 'arrow'}
|
name={arrowDirection ? `arrow-${arrowDirection}` : 'arrow'}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function onClick(event: Event) {
|
function onClick(event: Event) {
|
||||||
emit(ctx, 'click', event);
|
emit(ctx, 'click', event);
|
||||||
@ -76,6 +104,7 @@ function Cell(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const clickable = isLink || props.clickable;
|
const clickable = isLink || props.clickable;
|
||||||
|
|
||||||
const classes: Mods = {
|
const classes: Mods = {
|
||||||
clickable,
|
clickable,
|
||||||
center: props.center,
|
center: props.center,
|
||||||
@ -95,11 +124,11 @@ function Cell(
|
|||||||
onClick={onClick}
|
onClick={onClick}
|
||||||
{...inherit(ctx)}
|
{...inherit(ctx)}
|
||||||
>
|
>
|
||||||
{LeftIcon}
|
{LeftIcon()}
|
||||||
{Title}
|
{Title()}
|
||||||
{Value}
|
{Value()}
|
||||||
{RightIcon}
|
{RightIcon()}
|
||||||
{slots.extra && slots.extra()}
|
{slots.extra?.()}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user