diff --git a/packages/cell-group/index.tsx b/packages/cell-group/index.tsx index 7ecd8acbb..18a4f6f83 100644 --- a/packages/cell-group/index.tsx +++ b/packages/cell-group/index.tsx @@ -33,4 +33,4 @@ CellGroup.props = { } }; -export default sfc(CellGroup); +export default sfc(CellGroup); diff --git a/packages/info/index.tsx b/packages/info/index.tsx index db22bf748..d05413c1a 100644 --- a/packages/info/index.tsx +++ b/packages/info/index.tsx @@ -26,4 +26,4 @@ Info.props = { info: [String, Number] }; -export default sfc(Info); +export default sfc(Info); diff --git a/packages/tag/index.js b/packages/tag/index.tsx similarity index 53% rename from packages/tag/index.js rename to packages/tag/index.tsx index 7ba243da6..10b231326 100644 --- a/packages/tag/index.js +++ b/packages/tag/index.tsx @@ -2,18 +2,21 @@ import { use } from '../utils'; import { inherit } from '../utils/functional'; import { RED, BLUE, GREEN, GRAY_DARK } from '../utils/color'; +// Types +import { FunctionalComponent } from '../utils/use/sfc'; + const [sfc, bem] = use('tag'); -const COLOR_MAP = { +const COLOR_MAP: { [key: string]: string } = { danger: RED, primary: BLUE, success: GREEN }; -function Tag(h, props, slots, ctx) { - const { mark, plain, round, size } = ctx.props; +const Tag: FunctionalComponent = function(h, props, slots, ctx) { + 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 style = { [key]: color }; @@ -21,11 +24,16 @@ function Tag(h, props, slots, ctx) { style.color = props.textColor; } + const classes: { [key: string]: any } = { mark, plain, round }; + if (size) { + classes[size] = size; + } + return ( ); -} +}; + +export type TagProps = { + size?: string; + type?: string; + mark?: boolean; + color?: string; + plain?: boolean; + round?: boolean; + textColor?: string; +}; Tag.props = { size: String, @@ -47,4 +65,4 @@ Tag.props = { textColor: String }; -export default sfc(Tag); +export default sfc(Tag);