mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-25 10:56:35 +08:00
[improvement] Tag: tsx (#2770)
This commit is contained in:
parent
82b29267a2
commit
890bd72268
@ -33,4 +33,4 @@ CellGroup.props = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export default sfc(CellGroup);
|
export default sfc<CellGroupProps>(CellGroup);
|
||||||
|
@ -26,4 +26,4 @@ Info.props = {
|
|||||||
info: [String, Number]
|
info: [String, Number]
|
||||||
};
|
};
|
||||||
|
|
||||||
export default sfc(Info);
|
export default sfc<InfoProps>(Info);
|
||||||
|
@ -2,18 +2,21 @@ import { use } from '../utils';
|
|||||||
import { inherit } from '../utils/functional';
|
import { inherit } from '../utils/functional';
|
||||||
import { RED, BLUE, GREEN, GRAY_DARK } from '../utils/color';
|
import { RED, BLUE, GREEN, GRAY_DARK } from '../utils/color';
|
||||||
|
|
||||||
|
// Types
|
||||||
|
import { FunctionalComponent } from '../utils/use/sfc';
|
||||||
|
|
||||||
const [sfc, bem] = use('tag');
|
const [sfc, bem] = use('tag');
|
||||||
|
|
||||||
const COLOR_MAP = {
|
const COLOR_MAP: { [key: string]: string } = {
|
||||||
danger: RED,
|
danger: RED,
|
||||||
primary: BLUE,
|
primary: BLUE,
|
||||||
success: GREEN
|
success: GREEN
|
||||||
};
|
};
|
||||||
|
|
||||||
function Tag(h, props, slots, ctx) {
|
const Tag: FunctionalComponent<TagProps> = function(h, props, slots, ctx) {
|
||||||
const { mark, plain, round, size } = ctx.props;
|
const { type, mark, plain, round, size } = ctx.props;
|
||||||
|
|
||||||
const color = props.color || COLOR_MAP[props.type] || GRAY_DARK;
|
const color = props.color || (type && COLOR_MAP[type]) || GRAY_DARK;
|
||||||
const key = plain ? 'color' : 'backgroundColor';
|
const key = plain ? 'color' : 'backgroundColor';
|
||||||
const style = { [key]: color };
|
const style = { [key]: color };
|
||||||
|
|
||||||
@ -21,11 +24,16 @@ function Tag(h, props, slots, ctx) {
|
|||||||
style.color = props.textColor;
|
style.color = props.textColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const classes: { [key: string]: any } = { mark, plain, round };
|
||||||
|
if (size) {
|
||||||
|
classes[size] = size;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<span
|
<span
|
||||||
style={style}
|
style={style}
|
||||||
class={[
|
class={[
|
||||||
bem({ mark, plain, round, [size]: size }),
|
bem(classes),
|
||||||
{
|
{
|
||||||
'van-hairline--surround': plain
|
'van-hairline--surround': plain
|
||||||
}
|
}
|
||||||
@ -35,7 +43,17 @@ function Tag(h, props, slots, ctx) {
|
|||||||
{slots.default && slots.default()}
|
{slots.default && slots.default()}
|
||||||
</span>
|
</span>
|
||||||
);
|
);
|
||||||
}
|
};
|
||||||
|
|
||||||
|
export type TagProps = {
|
||||||
|
size?: string;
|
||||||
|
type?: string;
|
||||||
|
mark?: boolean;
|
||||||
|
color?: string;
|
||||||
|
plain?: boolean;
|
||||||
|
round?: boolean;
|
||||||
|
textColor?: string;
|
||||||
|
};
|
||||||
|
|
||||||
Tag.props = {
|
Tag.props = {
|
||||||
size: String,
|
size: String,
|
||||||
@ -47,4 +65,4 @@ Tag.props = {
|
|||||||
textColor: String
|
textColor: String
|
||||||
};
|
};
|
||||||
|
|
||||||
export default sfc(Tag);
|
export default sfc<TagProps>(Tag);
|
Loading…
x
Reference in New Issue
Block a user