import React, { FunctionComponent, useState, useEffect, MouseEvent, HTMLProps } from 'react' import { Icon } from '../icon/icon' import bem from '@/utils/bem' import classNames from 'classnames' import { Overlay } from '../overlay/overlay' import './fixednav.scss' 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 change: Function selected: Function slotList: HTMLProps slotBtn: HTMLProps } 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 { fixednavClass, overlay, visible, navList, activeText, unActiveText, position, change, selected, 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 => { selected(item, event) } const onUpdateValue = (value: boolean = !visible): void => { change(value) } // const [classNames, setClassNames] = useState('') // const classes = () => { // return `${fixednavClass} ${type} ${visible ? 'active' : ''}` // } // useEffect(() => { // setClassNames(classes()) // }, [visible]) return (
{overlay && ( onUpdateValue(false)}> )}
{slotList ? ( slotList ) : (
{navList.map((item: any, index) => { return (
onSelectCb(event, item)} key={item.id || index} >
{item.text}
{item.num &&
{item.num}
}
) })}
)}
onUpdateValue()}> {slotBtn ? ( slotBtn ) : ( <>
{visible ? activeText : unActiveText}
)}
) } FixedNav.defaultProps = defaultProps FixedNav.displayName = 'NutFixedNav'