[improvement] CouponCell: tsx (#2791)

This commit is contained in:
neverland
2019-02-19 11:38:42 +08:00
committed by GitHub
parent 52a4b7eec9
commit 4e52510f85
8 changed files with 46 additions and 13 deletions
@@ -2,9 +2,23 @@ import { use } from '../utils';
import { inherit } from '../utils/functional';
import Cell from '../cell';
// Types
import { CreateElement, RenderContext } from 'vue/types';
import { DefaultSlots } from '../utils/use/sfc';
import { Coupon } from '../coupon/shared';
export type CouponCellProps = {
title?: string;
border: boolean;
coupons: Coupon[];
currency: string;
editable: boolean;
chosenCoupon: number;
};
const [sfc, bem, t] = use('coupon-cell');
function formatValue(props) {
function formatValue(props: CouponCellProps) {
const { coupons, chosenCoupon, currency } = props;
const coupon = coupons[chosenCoupon];
@@ -16,8 +30,13 @@ function formatValue(props) {
return coupons.length === 0 ? t('tips') : t('count', coupons.length);
}
function CouponCell(h, props, slots, ctx) {
const valueClass = props[props.chosenCoupon]
function CouponCell(
h: CreateElement,
props: CouponCellProps,
slots: DefaultSlots,
ctx: RenderContext<CouponCellProps>
) {
const valueClass = props.coupons[props.chosenCoupon]
? 'van-coupon-cell--selected'
: '';
const value = formatValue(props);
@@ -60,4 +79,4 @@ CouponCell.props = {
}
};
export default sfc(CouponCell);
export default sfc<CouponCellProps>(CouponCell);