import React, { FunctionComponent, MouseEvent } from 'react' import classNames from 'classnames' import Icon from '@/packages/icon/index.taro' import Overlay from '@/packages/overlay/index.taro' import bem from '@/utils/bem' import { useConfig } from '@/packages/configprovider/configprovider.taro' type Direction = 'right' | 'left' type Position = { top?: string bottom?: string } export interface FixedNavProps { fixednavClass: string visible: boolean overlay: boolean navList: Array activeText: string unActiveText: string position: Position type: Direction onChange: (v: any) => void onSelected: (item: any, e: any) => void slotList: React.ReactNode slotBtn: React.ReactNode } const defaultProps = { fixednavClass: 'nut-fixednav', activeText: '', unActiveText: '', type: 'right', position: { top: 'auto', bottom: 'auto', }, } as FixedNavProps export const FixedNav: FunctionComponent< Partial & React.HTMLAttributes > = (props) => { const { locale } = useConfig() const { fixednavClass, overlay, visible, navList, activeText, unActiveText, position, onChange, onSelected, type, slotList, slotBtn, ...rest } = { ...defaultProps, ...props } const b = bem('fixednav') const classes = classNames( { active: visible, }, type, fixednavClass, b('') ) const onSelectCb = (event: MouseEvent, item: any): void => { onSelected(item, event) } const onUpdateValue = (value = !visible): void => { onChange(value) } // const [classNames, setClassNames] = useState('') // const classes = () => { // return `${fixednavClass} ${type} ${visible ? 'active' : ''}` // } // useEffect(() => { // setClassNames(classes()) // }, [visible]) return (
{overlay && ( onUpdateValue(false)} /> )}
{slotList || (
{navList.map((item: any, index) => { return (
onSelectCb(event, item)} key={item.id || index} >
{item.text}
{item.num &&
{item.num}
}
) })}
)}
onUpdateValue()}> {slotBtn || ( <>
{visible ? activeText || locale.fixednav.activeText : unActiveText || locale.fixednav.unActiveText}
)}
) } FixedNav.defaultProps = defaultProps FixedNav.displayName = 'NutFixedNav'