import React from "react"; import { cn } from "tailwind-variants"; import type { CommonProps } from "@/common/CommonProps"; // 别名<约束>=值 // 千万不要 C = As extend React.ElementType,这样子连等号,会切断推导 type AsProp = { as?: C }; type PropsToOmit = keyof (AsProp & P); export type PolymorphicProps = (P & AsProp) & Omit, PropsToOmit>; interface BoxProps extends CommonProps { as?: C; } const Box = ( props: PolymorphicProps>, ref?: React.ComponentPropsWithRef["ref"], ) => { const { as: Component = "div", children, className, ...rest } = props; const boxRootClass = cn( className); return ( {children} ); }; export type BoxComponent = ( props: PolymorphicProps> & { ref?: React.ComponentPropsWithRef["ref"]; }, ) => React.ReactElement | null; export default Box as BoxComponent;