-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
三少
committed
Oct 11, 2021
1 parent
e808f34
commit e5934bc
Showing
4 changed files
with
134 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import { View, Text } from '@tarojs/components' | ||
import { useEffect, useState } from 'react' | ||
import Icon from '../icon' | ||
import Button from '../button' | ||
import { SubmitBarProps } from '../../../types/submit-bar' | ||
|
||
export default function Index(props: SubmitBarProps) { | ||
const { | ||
tipIcon, | ||
tip, | ||
label, | ||
currency = '¥', | ||
suffixLabel, | ||
buttonType = 'danger', | ||
price, | ||
loading, | ||
disabled, | ||
buttonText, | ||
safeAreaInsetBottom = true, | ||
renderTop, | ||
renderTip, | ||
decimalLength, | ||
onSubmit, | ||
children, | ||
style, | ||
className, | ||
...others | ||
} = props | ||
const [state, setState] = useState({ | ||
hasTip: false, | ||
integerStr: '', | ||
decimalStr: '', | ||
hasPrice: false, | ||
}) | ||
const { hasTip, integerStr, decimalStr, hasPrice } = state | ||
useEffect( | ||
function () { | ||
setState((pre) => { | ||
return { ...pre, hasTip: typeof tip === 'string' } | ||
}) | ||
}, | ||
[tip], | ||
) | ||
useEffect( | ||
function () { | ||
const priceStrArr = | ||
typeof price === 'number' && | ||
(price / 100).toFixed(decimalLength).split('.') | ||
setState((pre: any) => { | ||
return { | ||
...pre, | ||
hasPrice: typeof price === 'number', | ||
integerStr: priceStrArr && priceStrArr[0], | ||
decimalStr: decimalLength && priceStrArr ? `.${priceStrArr[1]}` : '', | ||
} | ||
}) | ||
}, | ||
[decimalLength, price], | ||
) | ||
return ( | ||
<View | ||
className={`van-submit-bar custom-class ${className || ''}`} | ||
style={style} | ||
{...others} | ||
> | ||
{renderTop} | ||
<View className="van-submit-bar__tip"> | ||
{tipIcon && ( | ||
<Icon | ||
size="12px" | ||
name={tipIcon} | ||
className="van-submit-bar__tip-icon" | ||
></Icon> | ||
)} | ||
{hasTip && <View className="van-submit-bar__tip-text">{tip}</View>} | ||
{renderTip} | ||
</View> | ||
<View className="bar-class van-submit-bar__bar"> | ||
{children} | ||
{hasPrice && ( | ||
<View className="van-submit-bar__text"> | ||
<Text>{label || '合计:'}</Text> | ||
<Text className="van-submit-bar__price price-class"> | ||
<Text className="van-submit-bar__currency">{currency}</Text> | ||
<Text className="van-submit-bar__price-integer"> | ||
{integerStr} | ||
</Text> | ||
<Text>{decimalStr}</Text> | ||
</Text> | ||
<Text className="van-submit-bar__suffix-label">{suffixLabel}</Text> | ||
</View> | ||
)} | ||
<Button | ||
round | ||
type={buttonType} | ||
loading={loading} | ||
disabled={disabled} | ||
className="van-submit-bar__button button-class" | ||
onClick={onSubmit} | ||
> | ||
{loading ? '' : buttonText} | ||
</Button> | ||
</View> | ||
{safeAreaInsetBottom && <View className="van-submit-bar__safe"></View>} | ||
</View> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { ComponentClass, ReactNode } from 'react' | ||
import { StandardProps, ITouchEvent } from '@tarojs/components' | ||
|
||
export interface SubmitBarProps extends StandardProps { | ||
tip?: string | ||
tipIcon?: string | ||
price?: number | ||
label?: string | ||
loading?: boolean | ||
disabled?: boolean | ||
buttonText?: string | ||
currency?: string | ||
buttonType?: 'default' | 'primary' | 'info' | 'warning' | 'danger' | ||
decimalLength?: number | ||
suffixLabel?: string | ||
safeAreaInsetBottom?: boolean | ||
children?: ReactNode | ||
renderTop?: ReactNode | ||
renderTip?: ReactNode | ||
onSubmit?: (event: ITouchEvent) => void | ||
} | ||
|
||
declare const SubmitBar: ComponentClass<SubmitBarProps> | ||
|
||
export { SubmitBar } |