Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Xflow增加控制面板表单校验 #1620

Merged
merged 2 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions docs/xflow/best-practices.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
order: 1
title: '最佳实践'
mobile: false
group:
title: 最佳实践
order: 1
---

# 在项目中使用


<code src="./demo/best/basic/index.tsx"></code>



13 changes: 13 additions & 0 deletions docs/xflow/demo/best/basic/TextEllipsis/index.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.text-ellipsis {
display: inline-block;
max-width: 100%;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}

.paragraph-ellipsis {
display: block;
width: 100%;
word-break: break-all;
}
101 changes: 101 additions & 0 deletions docs/xflow/demo/best/basic/TextEllipsis/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import { Tooltip, TooltipProps } from 'antd';
import React, { FC, memo, useEffect, useState } from 'react';
import './index.less';

interface ITextEllipsisProps {
text: string;
style?: object;
className?: string;
toolTipProps?: TooltipProps;
type?: 'text' | 'paragraph';
rows?: number;
}
const TextEllipsis: FC<ITextEllipsisProps> = ({
text,
style,
toolTipProps,
type = 'text',
rows = 1,
className,
}) => {
const typographyRef = React.useRef<HTMLElement>(null);
const [isEllipse, setIsEllipse] = useState(false);

const component =
type === 'paragraph' ? (
<span
ref={typographyRef}
className={`paragraph-ellipsis ${className}`}
style={{
...style,
display: '-webkit-box',
overflow: 'hidden',
WebkitBoxOrient: 'vertical',
WebkitLineClamp: rows,
}}
>
{text}
</span>
) : (
<span
ref={typographyRef}
className={`text-ellipsis ${className}`}
style={style}
>
{text}
</span>
);

useEffect(() => {
if (text) {
if (type === 'paragraph') {
const { offsetHeight, scrollHeight, clientHeight } =
typographyRef.current;
setIsEllipse(scrollHeight > clientHeight);
} else {
const isEllipse = isEleEllipsis(typographyRef?.current);
setIsEllipse(isEllipse);
}
}
}, [text]);

const isEleEllipsis = (ele: HTMLElement): boolean => {
const childDiv = document.createElement('em');
ele.appendChild(childDiv);

const rect = ele.getBoundingClientRect();
const childRect = childDiv.getBoundingClientRect();

ele.removeChild(childDiv);

return (
rect.left > childRect.left ||
childRect.right > rect.right ||
rect.top > childRect.top ||
childRect.bottom > rect.bottom
);
};
if (isEllipse) {
return (
<Tooltip
title={text}
getPopupContainer={() =>
document.getElementById('xflow-container') as HTMLElement
}
color="#ffff"
overlayInnerStyle={{
color: '#354052',
fontSize: '12px',
borderRadius: '8px',
}}
placement="bottomRight"
{...toolTipProps}
>
{component}
</Tooltip>
);
}
return component;
};

export default memo(TextEllipsis);
Loading
Loading