chore: migrate cell default slot (#8971)

This commit is contained in:
neverland 2021-07-02 16:29:19 +08:00 committed by GitHub
parent edb6ea8858
commit bc8bad0247
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 33 additions and 26 deletions

View File

@ -96,7 +96,7 @@ export default defineComponent({
<div class={bem({ disabled })} onClick={onClick}> <div class={bem({ disabled })} onClick={onClick}>
<Cell <Cell
v-slots={{ v-slots={{
default: renderContent, value: renderContent,
'right-icon': renderRightIcon, 'right-icon': renderRightIcon,
}} }}
border={false} border={false}

View File

@ -42,6 +42,7 @@ export default defineComponent({
return () => ( return () => (
<Cell <Cell
v-slots={{ value: renderContent }}
center center
icon={props.type === 'edit' ? 'contact' : 'add-square'} icon={props.type === 'edit' ? 'contact' : 'add-square'}
class={bem([props.type])} class={bem([props.type])}
@ -49,9 +50,7 @@ export default defineComponent({
isLink={props.editable} isLink={props.editable}
valueClass={bem('value')} valueClass={bem('value')}
onClick={onClick} onClick={onClick}
> />
{renderContent()}
</Cell>
); );
}, },
}); });

View File

@ -72,7 +72,7 @@ export default defineComponent({
<Cell <Cell
v-slots={{ v-slots={{
icon: renderEditIcon, icon: renderEditIcon,
default: renderContent, value: renderContent,
'right-icon': renderRightIcon, 'right-icon': renderRightIcon,
}} }}
key={item.id} key={item.id}

View File

@ -134,8 +134,17 @@ export default defineComponent({
} }
}; };
const renderIcon = () => {
if (active) {
return (
<Icon class={bem('icon')} color={activeColor} name="success" />
);
}
};
return ( return (
<Cell <Cell
v-slots={{ value: renderIcon }}
clickable clickable
key={option.value} key={option.value}
icon={option.icon} icon={option.icon}
@ -143,11 +152,7 @@ export default defineComponent({
class={bem('option', { active })} class={bem('option', { active })}
style={{ color: active ? activeColor : '' }} style={{ color: active ? activeColor : '' }}
onClick={onClick} onClick={onClick}
> ></Cell>
{active && (
<Icon class={bem('icon')} color={activeColor} name="success" />
)}
</Cell>
); );
}; };

View File

@ -486,6 +486,23 @@ export default defineComponent({
} }
}; };
const renderFieldBody = () => [
<div class={bem('body')}>
{renderInput()}
{showClear.value && (
<Icon
name={props.clearIcon}
class={bem('clear')}
onTouchstart={onClear}
/>
)}
{renderRightIcon()}
{slots.button && <div class={bem('button')}>{slots.button()}</div>}
</div>,
renderWordLimit(),
renderMessage(),
];
useExpose({ useExpose({
blur, blur,
focus, focus,
@ -526,6 +543,7 @@ export default defineComponent({
v-slots={{ v-slots={{
icon: LeftIcon ? () => LeftIcon : null, icon: LeftIcon ? () => LeftIcon : null,
title: Label ? () => Label : null, title: Label ? () => Label : null,
value: renderFieldBody,
extra: slots.extra, extra: slots.extra,
}} }}
size={props.size} size={props.size}
@ -545,22 +563,7 @@ export default defineComponent({
valueClass={bem('value')} valueClass={bem('value')}
titleClass={[bem('label', labelAlign), props.labelClass]} titleClass={[bem('label', labelAlign), props.labelClass]}
arrowDirection={props.arrowDirection} arrowDirection={props.arrowDirection}
> />
<div class={bem('body')}>
{renderInput()}
{showClear.value && (
<Icon
name={props.clearIcon}
class={bem('clear')}
onTouchstart={onClear}
/>
)}
{renderRightIcon()}
{slots.button && <div class={bem('button')}>{slots.button()}</div>}
</div>
{renderWordLimit()}
{renderMessage()}
</Cell>
); );
}; };
}, },