mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-26 03:16:35 +08:00
chore(Tag): use composition api
This commit is contained in:
parent
8f208f3d4f
commit
463174e735
@ -1,4 +1,4 @@
|
|||||||
import { Transition } from 'vue';
|
import { computed, Transition } from 'vue';
|
||||||
import { createNamespace } from '../utils';
|
import { createNamespace } from '../utils';
|
||||||
import Icon from '../icon';
|
import Icon from '../icon';
|
||||||
|
|
||||||
@ -26,36 +26,40 @@ export default createComponent({
|
|||||||
emits: ['close'],
|
emits: ['close'],
|
||||||
|
|
||||||
setup(props, { slots, emit }) {
|
setup(props, { slots, emit }) {
|
||||||
return function () {
|
const onClose = (event) => {
|
||||||
const { type, mark, plain, color, round, size } = props;
|
event.stopPropagation();
|
||||||
|
emit('close');
|
||||||
|
};
|
||||||
|
|
||||||
const key = plain ? 'color' : 'backgroundColor';
|
const style = computed(() => {
|
||||||
const style = { [key]: color };
|
const key = props.plain ? 'color' : 'backgroundColor';
|
||||||
|
const style = { [key]: props.color };
|
||||||
|
|
||||||
if (props.textColor) {
|
if (props.textColor) {
|
||||||
style.color = props.textColor;
|
style.color = props.textColor;
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
const { show, type, mark, plain, round, size, closeable } = props;
|
||||||
|
|
||||||
const classes = { mark, plain, round };
|
const classes = { mark, plain, round };
|
||||||
if (size) {
|
if (size) {
|
||||||
classes[size] = size;
|
classes[size] = size;
|
||||||
}
|
}
|
||||||
|
|
||||||
const CloseIcon = props.closeable && (
|
const CloseIcon = closeable && (
|
||||||
<Icon
|
<Icon name="cross" class={bem('close')} onClick={onClose} />
|
||||||
name="cross"
|
|
||||||
class={bem('close')}
|
|
||||||
onClick={(event) => {
|
|
||||||
event.stopPropagation();
|
|
||||||
emit('close');
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Transition name={props.closeable ? 'van-fade' : null}>
|
<Transition name={closeable ? 'van-fade' : null}>
|
||||||
{props.show ? (
|
{show ? (
|
||||||
<span key="content" style={style} class={bem([classes, type])}>
|
<span
|
||||||
|
key="content"
|
||||||
|
style={style.value}
|
||||||
|
class={bem([classes, type])}
|
||||||
|
>
|
||||||
{slots.default?.()}
|
{slots.default?.()}
|
||||||
{CloseIcon}
|
{CloseIcon}
|
||||||
</span>
|
</span>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user