Skip to content

Commit

Permalink
refactor: ts
Browse files Browse the repository at this point in the history
  • Loading branch information
YumoImer committed Jan 7, 2025
1 parent 140b1b3 commit b77ecaa
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 13 deletions.
8 changes: 2 additions & 6 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 { BubbleContentType, BubbleProps } from './interface';
import type { BubbleProps } from './interface';
import Loading from './loading';
import useStyle from './style';

Expand Down Expand Up @@ -213,14 +213,10 @@ 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 as ForwardBubbleType;
export default ForwardBubble;
4 changes: 1 addition & 3 deletions components/bubble/demo/gpt-vis.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ Here’s a visualization of Haidilao's food delivery revenue from 2013 to 2022.
\`\`\`
`;

const RenderMarkdown: BubbleProps<string>['messageRender'] = (content) => (
<GPTVis>{content}</GPTVis>
);
const RenderMarkdown: BubbleProps['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<string>['messageRender'] = (content) => (
const renderMarkdown: BubbleProps['messageRender'] = (content) => (
<Typography>
{/* biome-ignore lint/security/noDangerouslySetInnerHtml: used in demo */}
<div dangerouslySetInnerHTML={{ __html: md.render(content) }} />
Expand Down
6 changes: 3 additions & 3 deletions components/bubble/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type SemanticType = 'avatar' | 'content' | 'header' | 'footer';

export type BubbleContentType = React.ReactNode | AnyObject;

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

0 comments on commit b77ecaa

Please sign in to comment.