From 8c6ab91f6d84e891ad8325fb269cecd3334e7454 Mon Sep 17 00:00:00 2001 From: neverland Date: Tue, 19 Feb 2019 14:30:30 +0800 Subject: [PATCH] [improvement] ContactList: tsx (#2794) --- packages/cell/index.tsx | 13 ++++---- packages/contact-card/zh-CN.md | 3 +- packages/contact-list/{index.js => index.tsx} | 31 ++++++++++++++++--- packages/utils/use/sfc.ts | 21 ++++++------- 4 files changed, 44 insertions(+), 24 deletions(-) rename packages/contact-list/{index.js => index.tsx} (71%) diff --git a/packages/cell/index.tsx b/packages/cell/index.tsx index 40c1ffaf0..00e911d8b 100644 --- a/packages/cell/index.tsx +++ b/packages/cell/index.tsx @@ -9,11 +9,12 @@ import { CreateElement, RenderContext } from 'vue/types'; import { ScopedSlot, DefaultSlots } from '../utils/use/sfc'; import { Mods } from '../utils/use/bem'; -export type CellProps = RouteProps & SharedCellProps & { - size?: string; - clickable?: boolean; - arrowDirection?: string; -}; +export type CellProps = RouteProps & + SharedCellProps & { + size?: string; + clickable?: boolean; + arrowDirection?: string; + }; export type CellSlots = DefaultSlots & { icon?: ScopedSlot; @@ -106,4 +107,4 @@ Cell.props = { arrowDirection: String }; -export default sfc(Cell); +export default sfc(Cell); diff --git a/packages/contact-card/zh-CN.md b/packages/contact-card/zh-CN.md index 8304a96bd..7be7c2617 100644 --- a/packages/contact-card/zh-CN.md +++ b/packages/contact-card/zh-CN.md @@ -130,7 +130,6 @@ export default { /> ``` - ### ContactCard API | 参数 | 说明 | 类型 | 默认值 | 版本 | @@ -187,4 +186,4 @@ export default { |------|------|------| | id | 每位联系人的唯一标识 | `String | Number` | | name | 联系人姓名 | `String` | -| tel | 联系人手机号 | `String` | +| tel | 联系人手机号 | `String | Number` | diff --git a/packages/contact-list/index.js b/packages/contact-list/index.tsx similarity index 71% rename from packages/contact-list/index.js rename to packages/contact-list/index.tsx index 83a579b33..5f57e71cd 100644 --- a/packages/contact-list/index.js +++ b/packages/contact-list/index.tsx @@ -1,4 +1,4 @@ -import { use, noop } from '../utils'; +import { use } from '../utils'; import { emit, inherit } from '../utils/functional'; import Icon from '../icon'; import Cell from '../cell'; @@ -6,9 +6,30 @@ import Button from '../button'; import Radio from '../radio'; import RadioGroup from '../radio-group'; +// Types +import { CreateElement, RenderContext } from 'vue/types'; +import { DefaultSlots } from '../utils/use/sfc'; + +export type ContactListItem = { + id: string | number; + tel: string | number; + name: string; +}; + +export type ContactListProps = { + value?: any; + list: ContactListItem[]; + addText?: string; +}; + const [sfc, bem, t] = use('contact-list'); -function ContactList(h, props, slots, ctx) { +function ContactList( + h: CreateElement, + props: ContactListProps, + slots: DefaultSlots, + ctx: RenderContext +) { const List = props.list.map((item, index) => ( { + emit(ctx, 'add'); + }} /> ); } ContactList.props = { - value: null, + value: null as any, list: Array, addText: String }; diff --git a/packages/utils/use/sfc.ts b/packages/utils/use/sfc.ts index c258544d3..6f4996177 100644 --- a/packages/utils/use/sfc.ts +++ b/packages/utils/use/sfc.ts @@ -13,7 +13,7 @@ import Vue, { import { VNode } from 'vue/types/vnode'; import { InjectOptions, PropsDefinition } from 'vue/types/options'; -export type ScopedSlot = (props?: Props) => VNode[] | undefined; +export type ScopedSlot = (props?: Props) => VNode[] | VNode | undefined; export type DefaultSlots = { default?: ScopedSlot; @@ -35,8 +35,6 @@ export interface VantComponentOptions extends ComponentOptions { export type DefaultProps = Record; -export type DefaultEvents = {}; - export type FunctionalComponent< Props = DefaultProps, PropDefs = PropsDefinition @@ -52,18 +50,17 @@ export type FunctionalComponent< inject?: InjectOptions; }; -export type TsxBaseProps = { +export type TsxBaseProps = { key: string | number; // hack for jsx prop spread props: any; class: any; - style: { - [key: string]: string | number; - }; + style: object[] | object; + scopedSlots: Slots; }; -export type TsxComponent = ( - props: Partial +export type TsxComponent = ( + props: Partial> ) => VNode; const arrayProp = { @@ -120,9 +117,9 @@ function transformFunctionalComponent( }; } -export default (name: string) => ( +export default (name: string) => ( sfc: VantComponentOptions | FunctionalComponent -): TsxComponent => { +): TsxComponent => { if (typeof sfc === 'function') { sfc = transformFunctionalComponent(sfc); } @@ -139,5 +136,5 @@ export default (name: string) => ( sfc.name = name; sfc.install = install; - return sfc as TsxComponent; + return sfc as TsxComponent; };