Skip to content

Commit

Permalink
feat: 新增文本未超出,不呼出功能
Browse files Browse the repository at this point in the history
  • Loading branch information
F-jianchao committed Nov 22, 2024
1 parent 35901fd commit c2be963
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 18 deletions.
6 changes: 6 additions & 0 deletions packages/amis-ui/scss/components/_popoverable.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@
.#{$ns}Field--popOverAble {
outline: none;
position: relative;

&--flex {
display: flex;
align-items: center;
}

.#{$ns}Field-popOverWrap {
&-ellipsis {
width: 200px;
Expand Down
5 changes: 0 additions & 5 deletions packages/amis-ui/scss/components/_table.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@
margin-bottom: var(--gap-sm);
}

.#{$ns}TableCell-ellipsis {
display: flex;
align-items: center;
}

&-fixedTop {
position: sticky;
top: var(--affix-offset-top);
Expand Down
30 changes: 24 additions & 6 deletions packages/amis/src/renderers/PopOver.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ export interface PopOverProps extends RendererProps {
popOver: boolean | SchemaPopOverObject;
onPopOverOpened: (popover: any) => void;
onPopOverClosed: (popover: any) => void;
textOverflow?: 'noWrap' | 'ellipsis' | 'default';
}

export interface PopOverState {
Expand All @@ -142,6 +143,7 @@ export const HocPopOver =
let lastOpenedInstance: PopOverComponent | null = null;
class PopOverComponent extends React.Component<PopOverProps, PopOverState> {
target: HTMLElement;
sonTarget: HTMLElement;
timer: ReturnType<typeof setTimeout>;
static ComposedComponent = Component;
constructor(props: PopOverProps) {
Expand All @@ -152,6 +154,7 @@ export const HocPopOver =
this.closePopOverLater = this.closePopOverLater.bind(this);
this.clearCloseTimer = this.clearCloseTimer.bind(this);
this.targetRef = this.targetRef.bind(this);
this.sonTargetRef = this.sonTargetRef.bind(this);
// this.handleClickOutside = this.handleClickOutside.bind(this);
this.state = {
isOpened: false
Expand All @@ -162,6 +165,10 @@ export const HocPopOver =
this.target = ref;
}

sonTargetRef(ref: any) {
this.sonTarget = ref;
}

openPopOver() {
const onPopOverOpened = this.props.onPopOverOpened;
lastOpenedInstance?.closePopOver();
Expand Down Expand Up @@ -355,7 +362,11 @@ export const HocPopOver =
render,
classPrefix: ns
} = this.props;

const e = this.sonTarget;
// 如果内容不超出,不需要弹出
if (e && e.offsetWidth >= e.scrollWidth) {
return null;
}
const content = render('popover-detail', {
type: 'panel',
body: `\${${name}}`
Expand Down Expand Up @@ -420,12 +431,13 @@ export const HocPopOver =
<Component
{...this.props}
className={cx(`Field--popOverAble`, className, {
in: this.state.isOpened
'in': this.state.isOpened,
'Field--popOverAble--flex':
width && selectClassName === 'ellipsis'
})}
ref={config.targetOutter ? this.targetRef : undefined}
>
{(popOver as SchemaPopOverObject)?.showIcon !== false &&
!selectClassName ? (
{(popOver as SchemaPopOverObject)?.showIcon !== false && popOver ? (
<>
<Component {...this.props} contentsOnly noHoc />
<span
Expand All @@ -449,12 +461,18 @@ export const HocPopOver =
)}
{...triggerProps}
style={{width: selectClassName && width}}
ref={config.targetOutter ? undefined : this.targetRef}
ref={
config.targetOutter
? selectClassName === 'ellipsis'
? this.sonTargetRef
: undefined
: this.targetRef
}
>
<Component {...this.props} contentsOnly noHoc />
</div>
{this.state.isOpened
? selectClassName === 'ellipsis'
? selectClassName === 'ellipsis' && !popOver
? this.renderTextOverflow()
: this.renderPopOver()
: null}
Expand Down
8 changes: 1 addition & 7 deletions packages/amis/src/renderers/Table/TableCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export interface TableCellProps extends RendererProps {
column: any;
contentsOnly?: boolean;
testIdBuilder?: TestIdBuilder;
textOverflow?: 'noWrap' | 'ellipsis' | 'default';
}

export class TableCell extends React.Component<TableCellProps> {
Expand Down Expand Up @@ -66,7 +65,6 @@ export class TableCell extends React.Component<TableCellProps> {
cellAffix,
isHead,
colIndex,
textOverflow,
row,
showBadge,
itemBadge,
Expand Down Expand Up @@ -190,11 +188,7 @@ export class TableCell extends React.Component<TableCellProps> {
/>
) : null}
{cellPrefix}
{textOverflow === 'ellipsis' ? (
<div className={cx('TableCell-ellipsis')}>{body}</div>
) : (
body
)}
{body}
{cellAffix}
</Component>
);
Expand Down

0 comments on commit c2be963

Please sign in to comment.