diff --git a/.dumi/components/SemanticPreview.tsx b/.dumi/components/SemanticPreview.tsx index 00efb5b7..5e0a95c3 100644 --- a/.dumi/components/SemanticPreview.tsx +++ b/.dumi/components/SemanticPreview.tsx @@ -67,7 +67,7 @@ const useStyle = createStyles(({ token }, markPos: [number, number, number, numb export interface SemanticPreviewProps { semantics: { name: string; desc: string; version?: string }[]; - children: React.ReactElement; + children: React.ReactElement | ((injectProps: any) => React.ReactElement); height?: number; } @@ -91,9 +91,14 @@ const SemanticPreview: React.FC = (props) => { return classNames; }, [semantics]); - const cloneNode = React.cloneElement(children, { + const injectProps = { classNames: semanticClassNames, - }); + }; + + const cloneNode = + typeof children === 'function' + ? children(injectProps) + : React.cloneElement(children, injectProps); // ======================== Hover ========================= const containerRef = React.useRef(null); diff --git a/components/sender/SenderHeader.tsx b/components/sender/SenderHeader.tsx new file mode 100644 index 00000000..604add33 --- /dev/null +++ b/components/sender/SenderHeader.tsx @@ -0,0 +1,115 @@ +import { CloseOutlined } from '@ant-design/icons'; +import { Button } from 'antd'; +import classNames from 'classnames'; +import CSSMotion, { type MotionEventHandler } from 'rc-motion'; +import * as React from 'react'; + +export interface SendHeaderContextProps { + prefixCls: string; +} + +export const SendHeaderContext = React.createContext({} as any); + +export type SemanticType = 'header' | 'content'; + +export interface SenderHeaderProps { + open?: boolean; + onOpenChange?: (open: boolean) => void; + title?: React.ReactNode; + children?: React.ReactNode; + className?: string; + style?: React.CSSProperties; + classNames?: Partial>; + styles?: Partial>; + closable?: boolean; +} + +const collapseHeight: MotionEventHandler = () => ({ + height: 0, +}); +const expandedHeight: MotionEventHandler = (ele) => ({ + height: ele.scrollHeight, +}); + +export default function SenderHeader(props: SenderHeaderProps) { + const { + title, + onOpenChange, + open, + children, + className, + style, + classNames: classes = {}, + styles = {}, + closable, + } = props; + + const { prefixCls } = React.useContext(SendHeaderContext); + + const headerCls = `${prefixCls}-header`; + + return ( + + {({ className: motionClassName, style: motionStyle }) => { + return ( +
+ {/* Header */} + {closable !== false && ( +
+
{title}
+
+
+
+ )} + + {/* Content */} + {children && ( +
+ {children} +
+ )} +
+ ); + }} +
+ ); +} diff --git a/components/sender/__tests__/__snapshots__/demo-extend.test.ts.snap b/components/sender/__tests__/__snapshots__/demo-extend.test.ts.snap index 0cbd7754..2188cd24 100644 --- a/components/sender/__tests__/__snapshots__/demo-extend.test.ts.snap +++ b/components/sender/__tests__/__snapshots__/demo-extend.test.ts.snap @@ -2,99 +2,103 @@ exports[`renders components/sender/demo/actions.tsx extend context correctly 1`] = `
-
+
- + +
-
+
- + + + + + + +
- + +
+
+ +
+
+
+ + + +`; + +exports[`renders components/sender/demo/basic.tsx extend context correctly 2`] = `[]`; + +exports[`renders components/sender/demo/header.tsx extend context correctly 1`] = ` +
+
+
+
- -
-
+
@@ -354,63 +469,67 @@ exports[`renders components/sender/demo/send-style.tsx extend context correctly
-
- -
-
+
@@ -419,44 +538,48 @@ exports[`renders components/sender/demo/send-style.tsx extend context correctly
-
- + +
@@ -472,78 +595,82 @@ exports[`renders components/sender/demo/speech.tsx extend context correctly 1`]
-
+
- + +
-
+
- + + + + + + +
- + +
+
+ +
+
+
+
+
+
+`; + +exports[`renders components/sender/demo/header.tsx correctly 1`] = ` +
+
+
+
- + +
-
- + +
-
- + +
@@ -421,77 +541,81 @@ exports[`renders components/sender/demo/speech.tsx correctly 1`] = `
-