feat(Tag): add closeable prop (#4763)

This commit is contained in:
neverland
2019-10-17 20:55:24 +08:00
committed by GitHub
parent 8d55e737c6
commit 7999098060
7 changed files with 212 additions and 49 deletions
+21 -6
View File
@@ -1,6 +1,7 @@
import { createNamespace } from '../utils';
import { inherit } from '../utils/functional';
import { inherit, emit } from '../utils/functional';
import { BORDER_SURROUND } from '../utils/constant';
import Icon from '../icon';
// Types
import { CreateElement, RenderContext } from 'vue/types';
@@ -18,6 +19,7 @@ export type TagProps = {
plain?: boolean;
round?: boolean;
textColor?: string;
closeable?: boolean;
};
const [createComponent, bem] = createNamespace('tag');
@@ -42,18 +44,30 @@ function Tag(
classes[size] = size;
}
return (
const Content = (
<span
style={style}
class={[
bem([classes, type]),
{ [BORDER_SURROUND]: plain }
]}
class={[bem([classes, type]), { [BORDER_SURROUND]: plain }]}
{...inherit(ctx, true)}
>
{slots.default && slots.default()}
{props.closeable && (
<Icon
name="cross"
class={bem('close')}
onClick={() => {
emit(ctx, 'close');
}}
/>
)}
</span>
);
if (props.closeable) {
return <transition name="van-fade">{Content}</transition>;
}
return Content;
}
Tag.props = {
@@ -63,6 +77,7 @@ Tag.props = {
plain: Boolean,
round: Boolean,
textColor: String,
closeable: Boolean,
type: {
type: String,
default: 'default'