forked from youzan/vant
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.tsx
More file actions
87 lines (73 loc) · 1.8 KB
/
index.tsx
File metadata and controls
87 lines (73 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import { createNamespace } from '../utils';
import { inherit, emit } from '../utils/functional';
import { BORDER_SURROUND } from '../utils/constant';
import Icon from '../icon';
// Types
import { CreateElement, RenderContext } from 'vue/types';
import { DefaultSlots } from '../utils/types';
export type TagType = 'default' | 'primary' | 'success' | 'danger';
export type TagSize = 'large' | 'medium';
export type TagProps = {
type: TagType;
size?: TagSize;
mark?: boolean;
color?: string;
plain?: boolean;
round?: boolean;
textColor?: string;
closeable?: boolean;
};
const [createComponent, bem] = createNamespace('tag');
function Tag(
h: CreateElement,
props: TagProps,
slots: DefaultSlots,
ctx: RenderContext<TagProps>
) {
const { type, mark, plain, color, round, size } = props;
const key = plain ? 'color' : 'backgroundColor';
const style = { [key]: color };
if (props.textColor) {
style.color = props.textColor;
}
const classes: { [key: string]: any } = { mark, plain, round };
if (size) {
classes[size] = size;
}
const Content = (
<span
style={style}
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 = {
size: String,
mark: Boolean,
color: String,
plain: Boolean,
round: Boolean,
textColor: String,
closeable: Boolean,
type: {
type: String,
default: 'default'
}
};
export default createComponent<TagProps>(Tag);