parent
fe67088214
commit
cfd404dda1
@ -0,0 +1,31 @@ |
||||
.navigation { |
||||
position: sticky; |
||||
top: 0; |
||||
left: 0; |
||||
width: 750rpx; |
||||
padding-left: 20rpx; |
||||
z-index: 99999999999; |
||||
overflow: hidden; |
||||
background: #fff; |
||||
} |
||||
|
||||
.leftNode { |
||||
position: absolute; |
||||
display: flex; |
||||
align-items: center; |
||||
} |
||||
|
||||
.text { |
||||
position: absolute; |
||||
left: 0; |
||||
right: 0; |
||||
margin: auto; |
||||
display: flex; |
||||
justify-content: center; |
||||
align-items: center; |
||||
} |
||||
|
||||
.arrow { |
||||
width: 32px; |
||||
height: 32px; |
||||
} |
@ -0,0 +1,51 @@ |
||||
import {Image, View} from "@tarojs/components"; |
||||
import React, {FC, useMemo} from "react"; |
||||
import styles from './navigationBar.module.scss' |
||||
import Taro from "@tarojs/taro"; |
||||
import leftArrow from '@/static/img/leftArrow.png' |
||||
|
||||
interface Props { |
||||
// 文本
|
||||
text?: string | JSX.Element |
||||
children?: JSX.Element |
||||
// 左边节点
|
||||
leftNode?: string | JSX.Element |
||||
// 字体颜色
|
||||
color?: string |
||||
// 背景颜色
|
||||
backgroundColor?: string |
||||
// 取消返回按钮
|
||||
cancelBack?: boolean |
||||
// 跟随页面滚动
|
||||
inherit?: boolean |
||||
className?: string |
||||
} |
||||
|
||||
const NavigationBar: FC<Props> = (props) => { |
||||
const globalData = Taro.getApp().globalData |
||||
const navigationBarStyle = useMemo((): React.CSSProperties => ({ |
||||
background: props.backgroundColor, |
||||
position: props.inherit ? 'inherit' : "sticky", |
||||
paddingTop: globalData.statusBarHeight + 'px', |
||||
height: globalData.textBarHeight + 'px', |
||||
}), [props]) |
||||
|
||||
|
||||
const navigationTextStyle = useMemo((): React.CSSProperties => ({ |
||||
color: props.color, |
||||
height: globalData.textBarHeight + 'px', |
||||
}), [props]) |
||||
|
||||
|
||||
return ( |
||||
<View className={`${props.className} ${styles.navigation}`} style={navigationBarStyle}> |
||||
<View style={navigationTextStyle} className={styles.leftNode}> |
||||
{!props.cancelBack && <Image src={leftArrow} mode='aspectFill' className={styles.arrow}/>} |
||||
{props.leftNode} |
||||
</View> |
||||
<View style={navigationTextStyle} className={styles.text}>{props.children || props.text}</View> |
||||
</View> |
||||
) |
||||
} |
||||
|
||||
export default NavigationBar |
Loading…
Reference in new issue