From 467aee829f193b28e87a5a72cda0c8a85d02537b Mon Sep 17 00:00:00 2001 From: neverland Date: Tue, 19 Feb 2019 19:21:13 +0800 Subject: [PATCH] [improvement] SubmitBar: tsx (#2797) --- packages/submit-bar/{index.js => index.tsx} | 39 +++++++++++++++++---- 1 file changed, 33 insertions(+), 6 deletions(-) rename packages/submit-bar/{index.js => index.tsx} (60%) diff --git a/packages/submit-bar/index.js b/packages/submit-bar/index.tsx similarity index 60% rename from packages/submit-bar/index.js rename to packages/submit-bar/index.tsx index fbadd17b3..1b8bc9541 100644 --- a/packages/submit-bar/index.js +++ b/packages/submit-bar/index.tsx @@ -1,10 +1,35 @@ -import { use, noop } from '../utils'; -import { inherit } from '../utils/functional'; +import { use } from '../utils'; +import { emit, inherit } from '../utils/functional'; import Button from '../button'; +// Types +import { CreateElement, RenderContext } from 'vue/types'; +import { ScopedSlot, DefaultSlots } from '../utils/use/sfc'; + +export type SubmitBarProps = { + tip?: string; + label?: string; + price?: number; + loading?: boolean; + currency: string; + disabled?: boolean; + buttonType: string; + buttonText?: string; +}; + +export type SubmitBarSlots = DefaultSlots & { + top?: ScopedSlot; + tip?: ScopedSlot; +}; + const [sfc, bem, t] = use('submit-bar'); -function SubmitBar(h, props, slots, ctx) { +function SubmitBar( + h: CreateElement, + props: SubmitBarProps, + slots: SubmitBarSlots, + ctx: RenderContext +) { const { tip, price } = props; const hasPrice = typeof price === 'number'; @@ -23,7 +48,7 @@ function SubmitBar(h, props, slots, ctx) { {hasPrice && [ {props.label || t('label')}, {`${props.currency} ${( - price / 100 + (price as number) / 100 ).toFixed(2)}`} ]} @@ -34,7 +59,9 @@ function SubmitBar(h, props, slots, ctx) { loading={props.loading} disabled={props.disabled} text={props.loading ? '' : props.buttonText} - onClick={ctx.listeners.submit || noop} + onClick={() => { + emit(ctx, 'submit'); + }} /> @@ -61,4 +88,4 @@ SubmitBar.props = { } }; -export default sfc(SubmitBar); +export default sfc(SubmitBar);