Taro 封装箭头组件

170 阅读1分钟

Taro 封装箭头组件

参数说明类型默认值必填
color箭头的颜色string#000000
lineWidth箭头线的宽度number2
breadth箭头的大小number5
unfold是否展开(多用于下拉框)booleanfalse
fixedAngle固定角度(优先级大于unfold)number-
onClick点击后的回调函数(e: ITouchEvent) => void-
import { ITouchEvent, View } from "@tarojs/components"

export interface HArrowProps {
    color?: string,
    lineWidth?: number, // 线的宽度
    breadth?: number, // 箭头的大小
    unfold?: boolean,
    fixedAngle?: number,
    onClick?: (e: ITouchEvent) => void
}

const HArrow = (props: HArrowProps) => {
    const {
        color = '#000000',
        lineWidth = 2,
        breadth = 5,
        unfold = false,
        fixedAngle,
        onClick
    } = props

    return (
        <View
            style={{
                width: `${breadth}px`,
                height: `${breadth}px`,
                borderTop: `${lineWidth}px ${color} solid`,
                borderRight: `${lineWidth}px ${color} solid`,
                transform: `rotate(${fixedAngle || (unfold ? -45 : 135)}deg)`,
                transition: 'all 1s ease-out'
            }}
            onClick={(e: ITouchEvent) => onClick && onClick(e)}
        >
        </View>
    )
}