/** * @Author: ?? * @Date: ?? */ import React, { useCallback } from "react" import { TabsProps, TabsPaneProps } from "./interface" import clsx from "clsx" import "./index.css" export const TabPane: React.FC = props => { const { children } = props return children } const TabPaneOverLoad = (props: any) => { const { tabKey, tab, active, orientation, onChange, className = "" } = props const classnames = clsx( "nts-tab-item", { ["nts-tab-item-horizontal"]: orientation === "horizontal", ["nts-tab-item-horizontal-active"]: active && orientation === "horizontal", ["nts-tab-item-vertical"]: orientation === "vertical", ["nts-tab-item-vertical-active"]: active && orientation === "vertical", ["nts-tab-item-active"]: active }, className ) const onTabChange = useCallback(() => onChange?.(tabKey), []) return (
{tab}
) } /** * ### 引用方法 * ```tsx * import { Tabs } from "@atomintl/exchange-ui"; * const TabPane = Tabs.TabPane; * ``` */ export const Tabs: React.FC & { TabPane: React.FC } = props => { const { children, defaultActiveKey, activeKey, orientation, classes, onChange, endTabComp } = props const classnames = clsx( { ["nts-tabs-horizontal"]: orientation === "horizontal", ["nts-tabs-vertical"]: orientation === "vertical" }, classes?.root ) return ( <>
{React.Children.map(children, child => { const _active = child?.key == (activeKey || defaultActiveKey) return ( ) })} {endTabComp}
{/*
*/} {React.Children.map(children, child => { if (child?.key == (activeKey || defaultActiveKey)) { if (!React.isValidElement(child)) return child return React.cloneElement(child, { ...(child.props as TabsPaneProps) }) } })} ) } Tabs.TabPane = TabPane Tabs.defaultProps = { orientation: "horizontal" } export type { TabsProps, TabsPaneProps } export default Tabs