Skip to content

Commit

Permalink
refactor: BubbleProps
Browse files Browse the repository at this point in the history
  • Loading branch information
YumoImer committed Jan 7, 2025
1 parent bf011dd commit 140b1b3
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
8 changes: 6 additions & 2 deletions components/bubble/Bubble.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import useXComponentConfig from '../_util/hooks/use-x-component-config';
import { useXProviderContext } from '../x-provider';
import useTypedEffect from './hooks/useTypedEffect';
import useTypingConfig from './hooks/useTypingConfig';
import type { BubbleProps } from './interface';
import type { BubbleContentType, BubbleProps } from './interface';
import Loading from './loading';
import useStyle from './style';

Expand Down Expand Up @@ -213,10 +213,14 @@ const Bubble: React.ForwardRefRenderFunction<BubbleRef, BubbleProps> = (props, r
);
};

type ForwardBubbleType = <T extends BubbleContentType = BubbleContentType>(
props: BubbleProps<T> & { ref?: React.Ref<BubbleRef> },
) => React.ReactElement;

const ForwardBubble = React.forwardRef(Bubble);

if (process.env.NODE_ENV !== 'production') {
ForwardBubble.displayName = 'Bubble';
}

export default ForwardBubble;
export default ForwardBubble as ForwardBubbleType;
4 changes: 3 additions & 1 deletion components/bubble/demo/gpt-vis.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ Here’s a visualization of Haidilao's food delivery revenue from 2013 to 2022.
\`\`\`
`;

const RenderMarkdown: BubbleProps['messageRender'] = (content) => <GPTVis>{content}</GPTVis>;
const RenderMarkdown: BubbleProps<string>['messageRender'] = (content) => (
<GPTVis>{content}</GPTVis>
);

const App = () => {
const [rerenderKey, setRerenderKey] = React.useState(0);
Expand Down
2 changes: 1 addition & 1 deletion components/bubble/demo/markdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const text = `
Link: [Ant Design X](https://x.ant.design)
`.trim();

const renderMarkdown: BubbleProps['messageRender'] = (content) => (
const renderMarkdown: BubbleProps<string>['messageRender'] = (content) => (
<Typography>
{/* biome-ignore lint/security/noDangerouslySetInnerHtml: used in demo */}
<div dangerouslySetInnerHTML={{ __html: md.render(content) }} />
Expand Down
10 changes: 6 additions & 4 deletions components/bubble/interface.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { AvatarProps } from 'antd';
import type { AnyObject } from '../_util/type';

export interface TypingOption {
/**
Expand All @@ -17,9 +18,10 @@ export interface TypingOption {

type SemanticType = 'avatar' | 'content' | 'header' | 'footer';

type BubbleContentType = React.ReactNode | object;
export type BubbleContentType = React.ReactNode | AnyObject;

export interface BubbleProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'content'> {
export interface BubbleProps<T extends BubbleContentType = BubbleContentType>
extends Omit<React.HTMLAttributes<HTMLDivElement>, 'content'> {
prefixCls?: string;
rootClassName?: string;
styles?: Partial<Record<SemanticType, React.CSSProperties>>;
Expand All @@ -28,8 +30,8 @@ export interface BubbleProps extends Omit<React.HTMLAttributes<HTMLDivElement>,
placement?: 'start' | 'end';
loading?: boolean;
typing?: boolean | TypingOption;
content?: BubbleContentType;
messageRender?: (content: BubbleContentType) => React.ReactNode;
content?: T;
messageRender?: (content: T) => React.ReactNode;
loadingRender?: () => React.ReactNode;
variant?: 'filled' | 'borderless' | 'outlined' | 'shadow';
shape?: 'round' | 'corner';
Expand Down

0 comments on commit 140b1b3

Please sign in to comment.