import { use } from '../utils'; import { emit, inherit } from '../utils/functional'; import Button, { ButtonType } from '../button'; import Icon from '../icon'; // Types import { CreateElement, RenderContext } from 'vue/types'; import { ScopedSlot, DefaultSlots } from '../utils/use/sfc'; export type SubmitBarProps = { tip?: string; tipIcon?: string; label?: string; price?: number; loading?: boolean; currency: string; disabled?: boolean; buttonType: ButtonType; buttonText?: string; suffixLabel?: string; decimalLength: number; safeAreaInsetBottom?: boolean; }; export type SubmitBarSlots = DefaultSlots & { top?: ScopedSlot; tip?: ScopedSlot; }; const [sfc, bem, t] = use('submit-bar'); function SubmitBar( h: CreateElement, props: SubmitBarProps, slots: SubmitBarSlots, ctx: RenderContext ) { const { tip, price, tipIcon } = props; function Text() { if (typeof price === 'number') { const priceText = `${props.currency} ${(price / 100).toFixed(props.decimalLength)}`; return (
{props.label || t('label')} {priceText} {props.suffixLabel && ( {props.suffixLabel} )}
); } } function Tip() { if (slots.tip || tip) { return (
{tipIcon && } {tip && {tip}} {slots.tip && slots.tip()}
); } } return (
{slots.top && slots.top()} {Tip()}
{slots.default && slots.default()} {Text()}
); } SubmitBar.props = { tip: String, tipIcon: String, label: String, loading: Boolean, disabled: Boolean, buttonText: String, suffixLabel: String, safeAreaInsetBottom: Boolean, price: { type: Number, default: null }, decimalLength: { type: Number, default: 2 }, currency: { type: String, default: '¥' }, buttonType: { type: String, default: 'danger' } }; export default sfc(SubmitBar);