mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
[improvement] AddressList: tsx (#2792)
This commit is contained in:
parent
4e52510f85
commit
c55b33f447
@ -4,16 +4,43 @@ import Icon from '../icon';
|
|||||||
import Cell from '../cell';
|
import Cell from '../cell';
|
||||||
import Radio from '../radio';
|
import Radio from '../radio';
|
||||||
|
|
||||||
|
// Types
|
||||||
|
import { CreateElement, RenderContext } from 'vue/types';
|
||||||
|
import { DefaultSlots } from '../utils/use/sfc';
|
||||||
|
|
||||||
|
export type AddressItemData = {
|
||||||
|
id: string | number;
|
||||||
|
tel: string | number;
|
||||||
|
name: string;
|
||||||
|
address: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type AddressItemProps = {
|
||||||
|
data: AddressItemData;
|
||||||
|
disabled?: boolean;
|
||||||
|
switchable?: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type AddressItemEvents = {
|
||||||
|
onEdit(): void;
|
||||||
|
onSelect(): void;
|
||||||
|
};
|
||||||
|
|
||||||
const [sfc, bem] = use('address-item');
|
const [sfc, bem] = use('address-item');
|
||||||
|
|
||||||
function AddressItem(h, props, slots, ctx) {
|
function AddressItem(
|
||||||
|
h: CreateElement,
|
||||||
|
props: AddressItemProps,
|
||||||
|
slots: DefaultSlots,
|
||||||
|
ctx: RenderContext<AddressItemProps>
|
||||||
|
) {
|
||||||
const { disabled, switchable } = props;
|
const { disabled, switchable } = props;
|
||||||
|
|
||||||
const renderRightIcon = () => (
|
const renderRightIcon = () => (
|
||||||
<Icon
|
<Icon
|
||||||
name="edit"
|
name="edit"
|
||||||
class={bem('edit')}
|
class={bem('edit')}
|
||||||
onClick={event => {
|
onClick={(event: Event) => {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
emit(ctx, 'edit');
|
emit(ctx, 'edit');
|
||||||
}}
|
}}
|
||||||
@ -57,4 +84,4 @@ AddressItem.props = {
|
|||||||
switchable: Boolean
|
switchable: Boolean
|
||||||
};
|
};
|
||||||
|
|
||||||
export default sfc(AddressItem);
|
export default sfc<AddressItemProps, AddressItemEvents>(AddressItem);
|
@ -90,7 +90,7 @@ export default {
|
|||||||
|------|------|------|
|
|------|------|------|
|
||||||
| id | Id | `String | Number` |
|
| id | Id | `String | Number` |
|
||||||
| name | Name | `String` |
|
| name | Name | `String` |
|
||||||
| tel | Phone | `String` |
|
| tel | Phone | `String | Number` |
|
||||||
| address | Address | `String` |
|
| address | Address | `String` |
|
||||||
|
|
||||||
### Slot
|
### Slot
|
||||||
|
@ -2,12 +2,34 @@ import { use } from '../utils';
|
|||||||
import { emit, inherit } from '../utils/functional';
|
import { emit, inherit } from '../utils/functional';
|
||||||
import Button from '../button';
|
import Button from '../button';
|
||||||
import RadioGroup from '../radio-group';
|
import RadioGroup from '../radio-group';
|
||||||
import AddressItem from './Item';
|
import AddressItem, { AddressItemData } from './Item';
|
||||||
|
|
||||||
|
// Types
|
||||||
|
import { CreateElement, RenderContext } from 'vue/types';
|
||||||
|
import { ScopedSlot, DefaultSlots } from '../utils/use/sfc';
|
||||||
|
|
||||||
|
export type AddressListProps = {
|
||||||
|
value?: string | number;
|
||||||
|
switchable: boolean;
|
||||||
|
disabledText?: string;
|
||||||
|
addButtonText?: string;
|
||||||
|
list: AddressItemData[];
|
||||||
|
disabledList: AddressItemData[];
|
||||||
|
};
|
||||||
|
|
||||||
|
export type AddressListSlots = DefaultSlots & {
|
||||||
|
top?: ScopedSlot;
|
||||||
|
};
|
||||||
|
|
||||||
const [sfc, bem, t] = use('address-list');
|
const [sfc, bem, t] = use('address-list');
|
||||||
|
|
||||||
function AddressList(h, props, slots, ctx) {
|
function AddressList(
|
||||||
const getList = (list, disabled) =>
|
h: CreateElement,
|
||||||
|
props: AddressListProps,
|
||||||
|
slots: AddressListSlots,
|
||||||
|
ctx: RenderContext<AddressListProps>
|
||||||
|
) {
|
||||||
|
const getList = (list: AddressItemData[], disabled?: boolean) =>
|
||||||
list.map((item, index) => (
|
list.map((item, index) => (
|
||||||
<AddressItem
|
<AddressItem
|
||||||
data={item}
|
data={item}
|
||||||
@ -31,7 +53,7 @@ function AddressList(h, props, slots, ctx) {
|
|||||||
{slots.top && slots.top()}
|
{slots.top && slots.top()}
|
||||||
<RadioGroup
|
<RadioGroup
|
||||||
value={props.value}
|
value={props.value}
|
||||||
onInput={event => {
|
onInput={(event: Event) => {
|
||||||
emit(ctx, 'input', event);
|
emit(ctx, 'input', event);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
@ -68,4 +90,4 @@ AddressList.props = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export default sfc(AddressList);
|
export default sfc<AddressListProps>(AddressList);
|
@ -94,7 +94,7 @@ export default {
|
|||||||
|------|------|------|
|
|------|------|------|
|
||||||
| id | 每条地址的唯一标识 | `String | Number` |
|
| id | 每条地址的唯一标识 | `String | Number` |
|
||||||
| name | 收货人姓名 | `String` |
|
| name | 收货人姓名 | `String` |
|
||||||
| tel | 收货人手机号 | `String` |
|
| tel | 收货人手机号 | `String | Number` |
|
||||||
| address | 收货地址 | `String` |
|
| address | 收货地址 | `String` |
|
||||||
|
|
||||||
### Slot
|
### Slot
|
||||||
|
@ -53,11 +53,15 @@ export type FunctionalComponent<
|
|||||||
};
|
};
|
||||||
|
|
||||||
export type TsxBaseProps = {
|
export type TsxBaseProps = {
|
||||||
class: any;
|
key: string | number;
|
||||||
style: any;
|
|
||||||
// hack for jsx prop spread
|
// hack for jsx prop spread
|
||||||
props: any;
|
props: any;
|
||||||
|
class: any;
|
||||||
|
style: {
|
||||||
|
[key: string]: string | number;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export type TsxComponent<Props, Events> = (
|
export type TsxComponent<Props, Events> = (
|
||||||
props: Partial<Props & Events & TsxBaseProps>
|
props: Partial<Props & Events & TsxBaseProps>
|
||||||
) => VNode;
|
) => VNode;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user