[improvement] ContactList: tsx (#2794)
This commit is contained in:
@@ -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<ContactListProps>
|
||||
) {
|
||||
const List = props.list.map((item, index) => (
|
||||
<Cell
|
||||
key={item.id}
|
||||
@@ -50,14 +71,16 @@ function ContactList(h, props, slots, ctx) {
|
||||
type="danger"
|
||||
class={bem('add')}
|
||||
text={props.addText || t('addText')}
|
||||
onClick={ctx.listeners.add || noop}
|
||||
onClick={() => {
|
||||
emit(ctx, 'add');
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
ContactList.props = {
|
||||
value: null,
|
||||
value: null as any,
|
||||
list: Array,
|
||||
addText: String
|
||||
};
|
||||
Reference in New Issue
Block a user