import { View, Text } from '@tarojs/components'
import { useCallback, useEffect, useMemo, useRef, useState, memo } from 'react'
import styles from './index.module.scss'
import classnames from 'classnames'
import Iconfont, { IconNames } from '../iconfont/iconfont'
import Popup from '../popup'
import FilterButton from '../filterButton'
// 弹窗选择向上弹窗还是向下弹窗
type Direction = 'up' | 'down'
// 配置 菜单可选项
export type DropDownOptions = {
text: string
value: number
}
interface DropDownEvent {
change?: (value: DropDownOptions['value']) => void // value 变化时触发
}
interface PropsType extends DropDownEvent{
direction?: Direction
title: string // 已选中的菜单标题
options?: DropDownOptions[]
value?: number | string // 当前选中的值
children?: React.ReactNode
activeColor?: string
}
export default (props: PropsType) => {
const { children, direction = 'down', title, value, options, change, activeColor } = props
const [showPopup, setShowPopup] = useState(false)
const handleClickOption = (value: DropDownOptions['value']) => {
change?.(value)
}
const defaultOptions = useMemo(() => {
const currentValue = value
return options?.map(({text, value})=>{
return (
handleClickOption(value)}>
{text}
)
})
}, [value])
const getIconName = () => {
if(direction === 'up'){
return showPopup ? 'icon-zhankai1' : 'icon-shouqi1'
}
// down
return showPopup ? 'icon-shouqi1' : 'icon-zhankai1'
}
const handleClickTitle = () => {
setShowPopup(true)
}
const handleClosePopup = () => {
setShowPopup(false)
}
return (
{title}
{children ? children : defaultOptions}
)
}