chore: compatibility api

This commit is contained in:
jialin
2025-03-31 16:21:40 +08:00
parent f9469a1ea3
commit bd6c689d91
24 changed files with 848 additions and 374 deletions
@@ -0,0 +1,72 @@
import AlertBlockInfo from '@/components/alert-info/block';
import { isArray } from 'lodash';
import React, { useMemo } from 'react';
import styled from 'styled-components';
interface CompatibilityAlertProps {
warningStatus: {
show: boolean;
title?: string;
isHtml?: boolean;
message: string | string[];
};
}
const DivWrapper = styled.div`
padding-inline: 12px;
`;
const MessageWrapper = styled.div`
display: flex;
flex-direction: column;
font-size: var(--font-size-small);
gap: 4px;
`;
const CompatibilityAlert: React.FC<CompatibilityAlertProps> = (props) => {
const { warningStatus } = props;
const { title, show, message, isHtml } = warningStatus;
const renderMessage = useMemo(() => {
if (!message || !show) {
return '';
}
if (isHtml) {
return (
<span
dangerouslySetInnerHTML={{
__html: message as string
}}
></span>
);
}
if (typeof message === 'string') {
return message;
}
if (isArray(message)) {
return (
<MessageWrapper>
{message.map((item, index) => (
<div key={index}>{item}</div>
))}
</MessageWrapper>
);
}
return '';
}, [message, show]);
return (
show && (
<DivWrapper>
<AlertBlockInfo
ellipsis={false}
message={renderMessage}
title={title}
type="warning"
></AlertBlockInfo>
</DivWrapper>
)
);
};
export default CompatibilityAlert;